From f7143972419a45a75574d64f2f55f3ccf843f48b Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Wed, 9 Apr 2025 12:14:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=9E=E6=80=A7=E7=BC=96?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=AF=B9=E7=BC=96=E8=BE=91=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E8=BF=9B=E8=A1=8C=E5=8A=A0=E7=B2=97=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/attributeTableModel.h | 1 + source/attributeTableModel.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/attributeTableModel.h b/include/attributeTableModel.h index 44f8f64..0b180d8 100644 --- a/include/attributeTableModel.h +++ b/include/attributeTableModel.h @@ -95,6 +95,7 @@ private: { //QSqlRecord record; QVector values; + QHash cellModified; //记录单元格是否被修改 EditState state = Clean; }; diff --git a/source/attributeTableModel.cpp b/source/attributeTableModel.cpp index f79a742..1b92d4b 100644 --- a/source/attributeTableModel.cpp +++ b/source/attributeTableModel.cpp @@ -88,14 +88,20 @@ QVariant AttributeTableModel::data(const QModelIndex& index, int role) const const QString& dataTypeText = m_dataTypes.value(dataTypeID).type; if(!dataTypeText.isEmpty()) return dataTypeText; - else - return dataTypeID; + // else + // return dataTypeID; } else return rowData.values.value(dataCol); } else if (role == Qt::UserRole + AttributeEidt::EditStatus) //在相关代理Delegate类实现中同步进行处理(文字加粗等效果) - return (rowData.state != Clean); + { + //return (rowData.state != Clean); + if(rowData.state == New) //新增列,整行加粗 + return true; + else //其它情况只对修改单元格加粗 + return rowData.cellModified.value(dataCol, false); + } } return QVariant(); @@ -126,6 +132,7 @@ bool AttributeTableModel::setData(const QModelIndex &index, const QVariant &valu } else modifiedRow.values[dataCol] = value; + modifiedRow.cellModified[dataCol] = true; //标记单元格 modifiedRow.state = (modifiedRow.state == New) ? New : Modified; m_modifiedRows[globalRow] = modifiedRow; @@ -409,6 +416,7 @@ void AttributeTableModel::insertRecord(int row) RowData newRow; newRow.state = New; newRow.values.resize(m_displayField.count()); + //newRow.values[2] = 11; int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage + row; m_modifiedRows[globalRow] = newRow;