diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-02-02 14:17:37 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-02-09 11:01:59 +0000 |
commit | 8c33c7022cf427b64fbd2729d38d6abdbe33a6e1 (patch) | |
tree | 6127d735687dce4b724db00f6df203ca147561a1 /src/qml/util/qqmladaptormodel.cpp | |
parent | 59a9c7c3d9edeb9420bf17c5913484daaf5b1ff5 (diff) |
QQmlDMAbstractItemModelData: add support for row and column
This will give item view delegates access to which row and
column they belong to.
Change-Id: I5c008504d30695319e5b149987af750f860043dd
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/qml/util/qqmladaptormodel.cpp')
-rw-r--r-- | src/qml/util/qqmladaptormodel.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index d3167d24f3..104d655820 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -330,7 +330,7 @@ bool QQmlDMCachedModelData::resolveIndex(const QQmlAdaptorModel &, int idx) { if (index == -1) { Q_ASSERT(idx >= 0); - index = idx; + setModelIndex(idx); cachedData.clear(); emit modelIndexChanged(); const QMetaObject *meta = metaObject(); @@ -399,13 +399,18 @@ QV4::ReturnedValue QQmlDMCachedModelData::set_property(const QV4::FunctionObject class QQmlDMAbstractItemModelData : public QQmlDMCachedModelData { Q_OBJECT + Q_PROPERTY(int row MEMBER row NOTIFY rowChanged) + Q_PROPERTY(int column MEMBER column NOTIFY columnChanged) Q_PROPERTY(bool hasModelChildren READ hasModelChildren CONSTANT) + public: QQmlDMAbstractItemModelData( QQmlDelegateModelItemMetaType *metaType, VDMModelDelegateDataType *dataType, int index) : QQmlDMCachedModelData(metaType, dataType, index) + , row(type->model->rowAt(index)) + , column(type->model->columnAt(index)) { } @@ -413,7 +418,7 @@ public: { if (index >= 0 && *type->model) { const QAbstractItemModel * const model = type->model->aim(); - return model->hasChildren(model->index(index, 0, type->model->rootIndex)); + return model->hasChildren(model->index(row, column, type->model->rootIndex)); } else { return false; } @@ -421,13 +426,13 @@ public: QVariant value(int role) const override { - return type->model->aim()->index(index, 0, type->model->rootIndex).data(role); + return type->model->aim()->index(row, column, type->model->rootIndex).data(role); } void setValue(int role, const QVariant &value) override { type->model->aim()->setData( - type->model->aim()->index(index, 0, type->model->rootIndex), value, role); + type->model->aim()->index(row, column, type->model->rootIndex), value, role); } QV4::ReturnedValue get() override @@ -443,6 +448,16 @@ public: ++scriptRef; return o.asReturnedValue(); } + + void setModelIndex(int idx) override; + +Q_SIGNALS: + void rowChanged(); + void columnChanged(); + +private: + int row; + int column; }; class VDMAbstractItemModelDataType : public VDMModelDelegateDataType @@ -563,6 +578,22 @@ public: } }; +void QQmlDMAbstractItemModelData::setModelIndex(int idx) +{ + QQmlDMCachedModelData::setModelIndex(idx); + + int prevRow = row; + int prevColumn = column; + + row = type->model->rowAt(idx); + column = type->model->columnAt(idx); + + if (row != prevRow) + emit rowChanged(); + if (column != prevColumn) + emit columnChanged(); +} + //----------------------------------------------------------------- // QQmlListAccessor //----------------------------------------------------------------- |