summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-05-21 13:44:38 +0200
committerGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-05-22 09:35:08 +0000
commit473410b99b362d0f39017d3390d5c44e513b8b8c (patch)
treeadb6990e1066dbad8434843f03ea698c62b3f4a4
parenta1ec337d062986402927494de46ad99c5f7ffc42 (diff)
downloadqtquickcontrols-473410b99b362d0f39017d3390d5c44e513b8b8c.tar.gz
TreeView: Check that indexes belong to the current model
And warn the user about it. We omit printing anything else in case we would be holding an invalid reference to some model. Internally, we assert if, despite the guards, we still get the wrong model indexes. Change-Id: I8e7451375d19c2aa406257a9b0193d59f69b0355 Task-number: QTBUG-46214 Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com> Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--src/controls/Private/qquicktreemodeladaptor.cpp3
-rw-r--r--src/controls/TreeView.qml14
2 files changed, 15 insertions, 2 deletions
diff --git a/src/controls/Private/qquicktreemodeladaptor.cpp b/src/controls/Private/qquicktreemodeladaptor.cpp
index 6bfa737d..c9e31712 100644
--- a/src/controls/Private/qquicktreemodeladaptor.cpp
+++ b/src/controls/Private/qquicktreemodeladaptor.cpp
@@ -354,6 +354,7 @@ void QQuickTreeModelAdaptor::expand(const QModelIndex &idx)
ASSERT_CONSISTENCY();
if (!m_model)
return;
+ Q_ASSERT(!idx.isValid() || idx.model() == m_model);
if (!idx.isValid() || !m_model->hasChildren(idx))
return;
if (m_expandedItems.contains(idx))
@@ -374,6 +375,7 @@ void QQuickTreeModelAdaptor::collapse(const QModelIndex &idx)
ASSERT_CONSISTENCY();
if (!m_model)
return;
+ Q_ASSERT(!idx.isValid() || idx.model() == m_model);
if (!idx.isValid() || !m_model->hasChildren(idx))
return;
if (!m_expandedItems.contains(idx))
@@ -394,6 +396,7 @@ bool QQuickTreeModelAdaptor::isExpanded(const QModelIndex &index) const
ASSERT_CONSISTENCY();
if (!m_model)
return false;
+ Q_ASSERT(!index.isValid() || index.model() == m_model);
return !index.isValid() || m_expandedItems.contains(index);
}
diff --git a/src/controls/TreeView.qml b/src/controls/TreeView.qml
index 08f0da4d..84c30edd 100644
--- a/src/controls/TreeView.qml
+++ b/src/controls/TreeView.qml
@@ -56,15 +56,25 @@ BasicTableView {
signal collapsed(var index)
function isExpanded(index) {
+ if (index.valid && index.model !== model) {
+ console.warn("TreeView.isExpanded: model and index mismatch")
+ return false
+ }
return modelAdaptor.isExpanded(index)
}
function collapse(index) {
- modelAdaptor.collapse(index)
+ if (index.valid && index.model !== model)
+ console.warn("TreeView.collapse: model and index mismatch")
+ else
+ modelAdaptor.collapse(index)
}
function expand(index) {
- modelAdaptor.expand(index)
+ if (index.valid && index.model !== model)
+ console.warn("TreeView.expand: model and index mismatch")
+ else
+ modelAdaptor.expand(index)
}
function indexAt(x, y) {