diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-02-13 18:19:08 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-02-28 08:11:19 +0000 |
commit | 368a1d918a49d01a380131205da2f205fb267a26 (patch) | |
tree | a2e7784ba42736bb36d33e54f07cc2ac476c0e7a /src/qml/types/qqmltablemodel_p.h | |
parent | b4ee855eb10cf9bfa44ce8e5de8f9ee6c5917764 (diff) |
TableModel: support built-in QML model roles
For the display role, we'll return the first role in that column
if it wasn't explicitly specified. For every other role, we can just
return an invalid QVariant. As usual, roleDataProvider can be used
for any data that is missing.
Before this patch, the extra roles were missing from roleNames,
so they couldn't be used in delegates.
Change-Id: I53ac5b75526bcddec44baf834f6a093115a70993
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/qml/types/qqmltablemodel_p.h')
-rw-r--r-- | src/qml/types/qqmltablemodel_p.h | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/qml/types/qqmltablemodel_p.h b/src/qml/types/qqmltablemodel_p.h index 3bbaff4183..33b2189fcd 100644 --- a/src/qml/types/qqmltablemodel_p.h +++ b/src/qml/types/qqmltablemodel_p.h @@ -114,6 +114,14 @@ private: QString typeName; }; + struct ColumnProperties + { + QVector<ColumnPropertyInfo> infoForProperties; + // If there was a display role found in this column, it'll be stored here. + // The index is into infoForProperties. + int explicitDisplayRoleIndex = -1; + }; + enum NewRowOperationFlag { OtherOperation, // insert(), set(), etc. AppendOperation @@ -127,22 +135,19 @@ private: bool validateColumnPropertyType(const char *functionName, const QString &propertyName, const QVariant &propertyValue, const ColumnPropertyInfo &expectedPropertyFormat, int columnIndex) const; - ColumnPropertyInfo findColumnPropertyInfo(int columnIndex, const QString &columnPropertyName) const; + ColumnPropertyInfo findColumnPropertyInfo(int columnIndex, const QString &columnPropertyNameFromRole) const; + QString columnPropertyNameFromRole(int columnIndex, int role) const; void doInsert(int rowIndex, const QVariant &row); QVariantList mRows; int mRowCount = 0; int mColumnCount = 0; - QVector<QVector<ColumnPropertyInfo>> mColumnProperties; + // Each entry contains information about the properties of the column at that index. + QVector<ColumnProperties> mColumnProperties; // key = property index (0 to number of properties across all columns) // value = role name QHash<int, QByteArray> mRoleNames; - // Contains the role key to be used as the display role for each column - // when "display" isn't explicitly specified. - // key = column index - // value = index (key) into mRoleNames - QHash<int, int> mDefaultDisplayRoles; QJSValue mRoleDataProvider; }; |