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;