aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates
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
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')
-rw-r--r--src/templates/qquickcontainer.cpp40
-rw-r--r--src/templates/qquickcontainer_p.h1
-rw-r--r--src/templates/qquickcontainer_p_p.h3
-rw-r--r--src/templates/qquickswipeview.cpp38
-rw-r--r--src/templates/qquickswipeview_p.h3
5 files changed, 40 insertions, 45 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"
diff --git a/src/templates/qquickcontainer_p.h b/src/templates/qquickcontainer_p.h
index 51b3ab19..52bc631c 100644
--- a/src/templates/qquickcontainer_p.h
+++ b/src/templates/qquickcontainer_p.h
@@ -102,6 +102,7 @@ protected:
private:
Q_DISABLE_COPY(QQuickContainer)
Q_DECLARE_PRIVATE(QQuickContainer)
+ Q_PRIVATE_SLOT(d_func(), void _q_currentIndexChanged())
};
Q_DECLARE_TYPEINFO(QQuickContainer, Q_COMPLEX_TYPE);
diff --git a/src/templates/qquickcontainer_p_p.h b/src/templates/qquickcontainer_p_p.h
index 1011a331..49b3a7d3 100644
--- a/src/templates/qquickcontainer_p_p.h
+++ b/src/templates/qquickcontainer_p_p.h
@@ -72,6 +72,8 @@ public:
void removeItem(int index, QQuickItem *item);
virtual void itemRemoved(QQuickItem *item);
+ void _q_currentIndexChanged();
+
void itemChildAdded(QQuickItem *item, QQuickItem *child) Q_DECL_OVERRIDE;
void itemSiblingOrderChanged(QQuickItem *item) Q_DECL_OVERRIDE;
void itemParentChanged(QQuickItem *item, QQuickItem *parent) Q_DECL_OVERRIDE;
@@ -90,6 +92,7 @@ public:
QObjectList contentData;
QQmlObjectModel *contentModel;
int currentIndex;
+ bool updatingCurrent;
};
Q_DECLARE_TYPEINFO(QQuickContainerPrivate, Q_COMPLEX_TYPE);
diff --git a/src/templates/qquickswipeview.cpp b/src/templates/qquickswipeview.cpp
index 083ee617..381f064d 100644
--- a/src/templates/qquickswipeview.cpp
+++ b/src/templates/qquickswipeview.cpp
@@ -75,18 +75,12 @@ class QQuickSwipeViewPrivate : public QQuickContainerPrivate
Q_DECLARE_PUBLIC(QQuickSwipeView)
public:
- QQuickSwipeViewPrivate() : updatingCurrent(false) { }
-
void resizeItem(QQuickItem *item);
void resizeItems();
- void _q_updateCurrent();
void itemInserted(int index, QQuickItem *item) Q_DECL_OVERRIDE;
- void itemMoved(int from, int to) Q_DECL_OVERRIDE;
static QQuickSwipeViewPrivate *get(QQuickSwipeView *view);
-
- bool updatingCurrent;
};
void QQuickSwipeViewPrivate::resizeItems()
@@ -100,13 +94,6 @@ void QQuickSwipeViewPrivate::resizeItems()
}
}
-void QQuickSwipeViewPrivate::_q_updateCurrent()
-{
- Q_Q(QQuickSwipeView);
- if (!updatingCurrent)
- q->setCurrentIndex(contentItem ? contentItem->property("currentIndex").toInt() : -1);
-}
-
void QQuickSwipeViewPrivate::itemInserted(int, QQuickItem *item)
{
Q_Q(QQuickSwipeView);
@@ -114,20 +101,6 @@ void QQuickSwipeViewPrivate::itemInserted(int, QQuickItem *item)
item->setSize(QSizeF(contentItem->width(), contentItem->height()));
}
-void QQuickSwipeViewPrivate::itemMoved(int from, int to)
-{
- Q_Q(QQuickSwipeView);
- 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;
-}
-
-
QQuickSwipeViewPrivate *QQuickSwipeViewPrivate::get(QQuickSwipeView *view)
{
return view->d_func();
@@ -158,15 +131,6 @@ void QQuickSwipeView::geometryChanged(const QRectF &newGeometry, const QRectF &o
d->resizeItems();
}
-void QQuickSwipeView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
-{
- QQuickContainer::contentItemChange(newItem, oldItem);
- if (oldItem)
- disconnect(oldItem, SIGNAL(currentIndexChanged()), this, SLOT(_q_updateCurrent()));
- if (newItem)
- connect(newItem, SIGNAL(currentIndexChanged()), this, SLOT(_q_updateCurrent()));
-}
-
/*!
\qmlattachedproperty int Qt.labs.controls::SwipeView::index
@@ -361,5 +325,3 @@ bool QQuickSwipeViewAttached::isCurrentItem() const
}
QT_END_NAMESPACE
-
-#include "moc_qquickswipeview_p.cpp"
diff --git a/src/templates/qquickswipeview_p.h b/src/templates/qquickswipeview_p.h
index 24bd6972..6dbdcf09 100644
--- a/src/templates/qquickswipeview_p.h
+++ b/src/templates/qquickswipeview_p.h
@@ -65,14 +65,11 @@ public:
static QQuickSwipeViewAttached *qmlAttachedProperties(QObject *object);
protected:
- void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(QQuickSwipeView)
Q_DECLARE_PRIVATE(QQuickSwipeView)
-
- Q_PRIVATE_SLOT(d_func(), void _q_updateCurrent())
};
class QQuickSwipeViewAttachedPrivate;