diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-07-27 12:33:27 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-02 02:43:36 +0200 |
commit | f915ea135fe4bf74432ffa3e6041ea60d4268c67 (patch) | |
tree | eb10268a72d7e4494e7b02c215bc62d42fd82aa1 /src/quick/items/qquickvisualadaptormodel.cpp | |
parent | 8dabc28e4ea6fe7946ee7770ba39410c6d95bc1d (diff) |
Fix handling of changes to the root index of a VisualDataModel.
Store the root index as a QPersistentModelIndex so the index remains
valid as the model changes, and in the case the root index is
removed from the model invalidate the contents of the VisualDataModel
until a new root index or model is set.
Change-Id: I1cbc27f2068f99a02ff3d43373905dec7e35e900
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/quick/items/qquickvisualadaptormodel.cpp')
-rw-r--r-- | src/quick/items/qquickvisualadaptormodel.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/quick/items/qquickvisualadaptormodel.cpp b/src/quick/items/qquickvisualadaptormodel.cpp index b17ab26373..5076d84b81 100644 --- a/src/quick/items/qquickvisualadaptormodel.cpp +++ b/src/quick/items/qquickvisualadaptormodel.cpp @@ -459,6 +459,8 @@ public: if (aim && vdm) { QObject::disconnect(aim, SIGNAL(rowsInserted(QModelIndex,int,int)), vdm, SLOT(_q_rowsInserted(QModelIndex,int,int))); + QObject::disconnect(aim, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), + vdm, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); QObject::disconnect(aim, SIGNAL(rowsRemoved(QModelIndex,int,int)), vdm, SLOT(_q_rowsRemoved(QModelIndex,int,int))); QObject::disconnect(aim, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), @@ -898,6 +900,8 @@ void QQuickVisualAdaptorModel::setModel(const QVariant &variant, QQuickVisualDat vdm, QQuickVisualDataModel, SLOT(_q_rowsInserted(QModelIndex,int,int))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), vdm, QQuickVisualDataModel, SLOT(_q_rowsRemoved(QModelIndex,int,int))); + qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), + vdm, QQuickVisualDataModel, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), vdm, QQuickVisualDataModel, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), @@ -922,6 +926,19 @@ void QQuickVisualAdaptorModel::setModel(const QVariant &variant, QQuickVisualDat } } +void QQuickVisualAdaptorModel::invalidateModel(QQuickVisualDataModel *vdm) +{ + accessors->cleanup(*this, vdm); + accessors = &qt_vdm_null_accessors; + // Don't clear the model object as we still need the guard to clear the list variant if the + // object is destroyed. +} + +bool QQuickVisualAdaptorModel::isValid() const +{ + return accessors != &qt_vdm_null_accessors; +} + void QQuickVisualAdaptorModel::objectDestroyed(QObject *) { setModel(QVariant(), 0, 0); |