aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickcontainer.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-21 14:31:04 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-22 11:16:25 +0000
commit4149f666e3b4ba5f2aed4a185a9d524d4e8247d0 (patch)
treeb6162c132410a0cca0362c5d90cdb69242b86219 /src/templates/qquickcontainer.cpp
parentbc546e14688c7056ac36b6f478fde852b5afaf46 (diff)
Promote current index handling from SwipeView to Container
Change-Id: I845b0999aaf9c211447c83bed2103de898c30b3f Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickcontainer.cpp')
-rw-r--r--src/templates/qquickcontainer.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/templates/qquickcontainer.cpp b/src/templates/qquickcontainer.cpp
index 02d90016..945d1c32 100644
--- a/src/templates/qquickcontainer.cpp
+++ b/src/templates/qquickcontainer.cpp
@@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
\sa {Container Controls}
*/
-QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(Q_NULLPTR), currentIndex(-1)
+QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(Q_NULLPTR), currentIndex(-1), updatingCurrent(false)
{
}
@@ -108,8 +108,17 @@ void QQuickContainerPrivate::moveItem(int from, int to)
itemMoved(from, to);
}
-void QQuickContainerPrivate::itemMoved(int, int)
+void QQuickContainerPrivate::itemMoved(int from, int to)
{
+ Q_Q(QQuickContainer);
+ updatingCurrent = true;
+ if (from == currentIndex)
+ q->setCurrentIndex(to);
+ else if (from < currentIndex && to >= currentIndex)
+ q->setCurrentIndex(currentIndex - 1);
+ else if (from > currentIndex && to <= currentIndex)
+ q->setCurrentIndex(currentIndex + 1);
+ updatingCurrent = false;
}
void QQuickContainerPrivate::removeItem(int index, QQuickItem *item)
@@ -138,6 +147,13 @@ void QQuickContainerPrivate::itemRemoved(QQuickItem *)
{
}
+void QQuickContainerPrivate::_q_currentIndexChanged()
+{
+ Q_Q(QQuickContainer);
+ if (!updatingCurrent)
+ q->setCurrentIndex(contentItem ? contentItem->property("currentIndex").toInt() : -1);
+}
+
void QQuickContainerPrivate::itemChildAdded(QQuickItem *, QQuickItem *child)
{
// add dynamically reparented items (eg. by a Repeater)
@@ -439,10 +455,26 @@ void QQuickContainer::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem
{
Q_D(QQuickContainer);
QQuickControl::contentItemChange(newItem, oldItem);
- if (oldItem)
+
+ static const int slotIndex = metaObject()->indexOfSlot("_q_currentIndexChanged()");
+
+ if (oldItem) {
QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Children);
- if (newItem)
+
+ int signalIndex = oldItem->metaObject()->indexOfSignal("currentIndexChanged()");
+ if (signalIndex != -1)
+ QMetaObject::disconnect(oldItem, signalIndex, this, slotIndex);
+ }
+
+ if (newItem) {
QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children);
+
+ int signalIndex = newItem->metaObject()->indexOfSignal("currentIndexChanged()");
+ if (signalIndex != -1)
+ QMetaObject::connect(newItem, signalIndex, this, slotIndex);
+ }
}
QT_END_NAMESPACE
+
+#include "moc_qquickcontainer_p.cpp"