aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h2
-rw-r--r--src/qml/util/qqmladaptormodel.cpp39
2 files changed, 36 insertions, 5 deletions
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index aa2a3fcd42..b44979986f 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -119,7 +119,7 @@ public:
int groupIndex(Compositor::Group group);
int modelIndex() const { return index; }
- void setModelIndex(int idx) { index = idx; Q_EMIT modelIndexChanged(); }
+ virtual void setModelIndex(int idx) { index = idx; Q_EMIT modelIndexChanged(); }
virtual QV4::ReturnedValue get() { return QV4::QObjectWrapper::wrap(v4, this); }
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
//-----------------------------------------------------------------