aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-06-06 15:53:16 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-06-09 16:58:13 +0000
commit7d55fb4029f4cc9bc5e5b4cef7ef5a456d42f83f (patch)
tree2be582752ffde4fa72dbe67c5528b963cd11b143 /src/qml
parent90fea15e0dfc62ecd668d1b0462d121dba5c1b7e (diff)
QQmlDelegateModelItem: move row and column up to the base class
Change 8c33c70 injected row and column (alongside index) into the QML context of a delegate when the view had a QAbstractItemModel as model. Rather than only inject those properties when using QAIM, this patch will move the code to the base class. This way, if a view uses e.g a javascript list as model, row and column is still be available. This is useful, since then the delegate can bind to both row and column regardless of what kind of model the view uses. In the case of a list model, the column property will always be 0. Change-Id: I1d9f11c0b7d7a5beb83198184ba12cc1e48cd100 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp23
-rw-r--r--src/qml/types/qqmldelegatemodel_p_p.h8
-rw-r--r--src/qml/util/qqmladaptormodel.cpp30
3 files changed, 30 insertions, 31 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 15d6bed2db..68bb185eaa 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -1960,6 +1960,8 @@ QQmlDelegateModelItem::QQmlDelegateModelItem(
, scriptRef(0)
, groups(0)
, index(modelIndex)
+ , row(QQmlDelegateModelPrivate::get(metaType->model)->m_adaptorModel.rowAt(modelIndex))
+ , column(QQmlDelegateModelPrivate::get(metaType->model)->m_adaptorModel.columnAt(modelIndex))
{
metaType->addref();
}
@@ -1994,6 +1996,27 @@ void QQmlDelegateModelItem::Dispose()
delete this;
}
+void QQmlDelegateModelItem::setModelIndex(int idx)
+{
+ if (idx == index)
+ return;
+
+ const int prevRow = row;
+ const int prevColumn = column;
+ const QQmlAdaptorModel &adaptorModel = QQmlDelegateModelPrivate::get(metaType->model)->m_adaptorModel;
+
+ index = idx;
+ row = adaptorModel.rowAt(idx);
+ column = adaptorModel.columnAt(idx);
+
+ Q_EMIT modelIndexChanged();
+
+ if (row != prevRow)
+ emit rowChanged();
+ if (column != prevColumn)
+ emit columnChanged();
+}
+
void QQmlDelegateModelItem::destroyObject()
{
Q_ASSERT(object);
diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h
index 2c0383a7e2..d5f79fab62 100644
--- a/src/qml/types/qqmldelegatemodel_p_p.h
+++ b/src/qml/types/qqmldelegatemodel_p_p.h
@@ -95,6 +95,8 @@ class QQmlDelegateModelItem : public QObject
{
Q_OBJECT
Q_PROPERTY(int index READ modelIndex NOTIFY modelIndexChanged)
+ Q_PROPERTY(int row MEMBER row NOTIFY rowChanged)
+ Q_PROPERTY(int column MEMBER column NOTIFY columnChanged)
Q_PROPERTY(QObject *model READ modelObject CONSTANT)
public:
QQmlDelegateModelItem(QQmlDelegateModelItemMetaType *metaType, int modelIndex);
@@ -121,7 +123,7 @@ public:
int groupIndex(Compositor::Group group);
int modelIndex() const { return index; }
- virtual void setModelIndex(int idx) { index = idx; Q_EMIT modelIndexChanged(); }
+ virtual void setModelIndex(int idx);
virtual QV4::ReturnedValue get() { return QV4::QObjectWrapper::wrap(v4, this); }
@@ -148,9 +150,13 @@ public:
Q_SIGNALS:
void modelIndexChanged();
+ void rowChanged();
+ void columnChanged();
protected:
void objectDestroyed(QObject *);
+ int row;
+ int column;
};
namespace QV4 {
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index 15844017aa..3016316e57 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -398,8 +398,6 @@ 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:
@@ -408,8 +406,6 @@ public:
VDMModelDelegateDataType *dataType,
int index)
: QQmlDMCachedModelData(metaType, dataType, index)
- , row(type->model->rowAt(index))
- , column(type->model->columnAt(index))
{
}
@@ -447,16 +443,6 @@ 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
@@ -577,22 +563,6 @@ 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
//-----------------------------------------------------------------