diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-11-05 19:13:36 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-11-06 18:36:43 +0000 |
commit | de8f22df824eb5259bb84ec878f077f959983d92 (patch) | |
tree | a9a0bf8c546ed5c5feb56a55dca83482067ca582 /src/templates/qquickcontainer.cpp | |
parent | 5cc36f74ef86e0fcc5a44c8ca32448a8efeaa8d3 (diff) |
Make tst_tabbar pass with a PathView
The upcoming universal style uses PathView as a content item for
TabBar. Compared to ListView, PathView has some differences in the
hanling of current index. For example, the current index of an empty
PathView is reseted to 0. This patch ensures that Container retains
the correct current index during insert/move/remove operations, no
matter which content item is used.
Change-Id: I385121d75a410e27d7bef9f5042a51948c7d7db3
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickcontainer.cpp')
-rw-r--r-- | src/templates/qquickcontainer.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/templates/qquickcontainer.cpp b/src/templates/qquickcontainer.cpp index 9a021aa3..90c46e14 100644 --- a/src/templates/qquickcontainer.cpp +++ b/src/templates/qquickcontainer.cpp @@ -101,6 +101,8 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item) return; contentData.append(item); + updatingCurrent = true; + item->setParentItem(effectiveContentItem(contentItem)); QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent); contentModel->insert(index, item); @@ -111,19 +113,25 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item) Q_Q(QQuickContainer); q->setCurrentIndex(index); } + + updatingCurrent = false; } void QQuickContainerPrivate::moveItem(int from, int to) { Q_Q(QQuickContainer); + int oldCurrent = currentIndex; contentModel->move(from, to); + updatingCurrent = true; - if (from == currentIndex) + + if (from == oldCurrent) q->setCurrentIndex(to); - else if (from < currentIndex && to >= currentIndex) - q->setCurrentIndex(currentIndex - 1); - else if (from > currentIndex && to <= currentIndex) - q->setCurrentIndex(currentIndex + 1); + else if (from < oldCurrent && to >= oldCurrent) + q->setCurrentIndex(oldCurrent - 1); + else if (from > oldCurrent && to <= oldCurrent) + q->setCurrentIndex(oldCurrent + 1); + updatingCurrent = false; } @@ -134,6 +142,8 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) return; contentData.removeOne(item); + updatingCurrent = true; + bool currentChanged = false; if (index == currentIndex) { q->setCurrentIndex(currentIndex - 1); @@ -150,6 +160,8 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) if (currentChanged) emit q->currentIndexChanged(); + + updatingCurrent = false; } void QQuickContainerPrivate::_q_currentIndexChanged() |