on xenial help sign in
Adapt to Qt 5.1.
f10d0d4Michał Sawicz
plugins/ListViewWithPageHeader/CMakeLists.txt+5−1
@@ -4,7 +4,11 @@ include(Plugins)
4# There's no cmake var for v8 include path :-/
4# There's no cmake var for v8 include path :-/
5# so create one
5# so create one
6LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
6LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
7+if(${Qt5Core_VERSION_STRING} VERSION_LESS "5.1.0")
7−SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/../QtV8/${Qt5Core_VERSION_STRING}/QtV8)
8+ SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/../QtV8/${Qt5Core_VERSION_STRING}/QtV8)
9+else()
10+ SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/QtV8/${Qt5Core_VERSION_STRING}/QtV8)
11+endif()
8
12
9include_directories(
13include_directories(
10 ${CMAKE_CURRENT_SOURCE_DIR}
14 ${CMAKE_CURRENT_SOURCE_DIR}
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+44
@@ -96,7 +96,11 @@
96#include <qqmlengine.h>
96#include <qqmlengine.h>
97#pragma GCC diagnostic push
97#pragma GCC diagnostic push
98#pragma GCC diagnostic ignored "-pedantic"
98#pragma GCC diagnostic ignored "-pedantic"
99+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
99#include <private/qquickvisualdatamodel_p.h>
100#include <private/qquickvisualdatamodel_p.h>
101+#else
102+#include <private/qqmldelegatemodel_p.h>
103+#endif
100#include <private/qqmlglobal_p.h>
104#include <private/qqmlglobal_p.h>
101#include <private/qquickitem_p.h>
105#include <private/qquickitem_p.h>
102#include <private/qquickanimation_p.h>
106#include <private/qquickanimation_p.h>
@@ -183,10 +187,17 @@ void ListViewWithPageHeader::setModel(QAbstractItemModel *model)
183 if (!m_delegateModel) {
187 if (!m_delegateModel) {
184 createDelegateModel();
188 createDelegateModel();
185 } else {
189 } else {
190+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
186 disconnect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
191 disconnect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
187 }
192 }
188 m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
193 m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
189 connect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
194 connect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
195+#else
196+ disconnect(m_delegateModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), this, SLOT(onModelUpdated(QQmlChangeSet,bool)));
197+ }
198+ m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
199+ connect(m_delegateModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), this, SLOT(onModelUpdated(QQmlChangeSet,bool)));
200+#endif
190 Q_EMIT modelChanged();
201 Q_EMIT modelChanged();
191 // TODO?
202 // TODO?
192// Q_EMIT contentHeightChanged();
203// Q_EMIT contentHeightChanged();
@@ -446,8 +457,13 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
446
457
447void ListViewWithPageHeader::createDelegateModel()
458void ListViewWithPageHeader::createDelegateModel()
448{
459{
460+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
449 m_delegateModel = new QQuickVisualDataModel(qmlContext(this), this);
461 m_delegateModel = new QQuickVisualDataModel(qmlContext(this), this);
450 connect(m_delegateModel, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(itemCreated(int,QQuickItem*)));
462 connect(m_delegateModel, SIGNAL(createdItem(int,QQuickItem*)), this, SLOT(itemCreated(int,QQuickItem*)));
463+#else
464+ m_delegateModel = new QQmlDelegateModel(qmlContext(this), this);
465+ connect(m_delegateModel, SIGNAL(createdItem(int,QObject*)), this, SLOT(itemCreated(int,QObject*)));
466+#endif
451 if (isComponentComplete())
467 if (isComponentComplete())
452 m_delegateModel->componentComplete();
468 m_delegateModel->componentComplete();
453 updateWatchedRoles();
469 updateWatchedRoles();
@@ -528,8 +544,13 @@ bool ListViewWithPageHeader::addVisibleItems(qreal fillFrom, qreal fillTo, bool
528void ListViewWithPageHeader::reallyReleaseItem(ListItem *listItem)
544void ListViewWithPageHeader::reallyReleaseItem(ListItem *listItem)
529{
545{
530 QQuickItem *item = listItem->m_item;
546 QQuickItem *item = listItem->m_item;
547+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
531 QQuickVisualModel::ReleaseFlags flags = m_delegateModel->release(item);
548 QQuickVisualModel::ReleaseFlags flags = m_delegateModel->release(item);
532 if (flags & QQuickVisualModel::Destroyed) {
549 if (flags & QQuickVisualModel::Destroyed) {
550+#else
551+ QQmlDelegateModel::ReleaseFlags flags = m_delegateModel->release(item);
552+ if (flags & QQmlDelegateModel::Destroyed) {
553+#endif
533 item->setParentItem(nullptr);
554 item->setParentItem(nullptr);
534 }
555 }
535 delete listItem->m_sectionItem;
556 delete listItem->m_sectionItem;
@@ -658,7 +679,11 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
658 return nullptr;
679 return nullptr;
659
680
660 m_asyncRequestedIndex = -1;
681 m_asyncRequestedIndex = -1;
682+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
661 QQuickItem *item = m_delegateModel->item(modelIndex, asynchronous);
683 QQuickItem *item = m_delegateModel->item(modelIndex, asynchronous);
684+#else
685+ QQuickItem *item = qobject_cast<QQuickItem *>(m_delegateModel->object(modelIndex, asynchronous));
686+#endif
662 if (!item) {
687 if (!item) {
663 m_asyncRequestedIndex = modelIndex;
688 m_asyncRequestedIndex = modelIndex;
664 return 0;
689 return 0;
@@ -711,8 +736,14 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
711 }
736 }
712}
737}
713
738
739+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
714void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
740void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
715{
741{
742+#else
743+void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
744+{
745+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
746+#endif
716// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
747// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
717
748
718 item->setParentItem(m_clipItem);
749 item->setParentItem(m_clipItem);
@@ -747,13 +778,22 @@ void ListViewWithPageHeader::onHeightChanged()
747 polish();
778 polish();
748}
779}
749
780
781+
782+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
750void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
783void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
784+#else
785+void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool /*reset*/)
786+#endif
751{
787{
752 // TODO Do something with reset
788 // TODO Do something with reset
753// qDebug() << "ListViewWithPageHeader::onModelUpdated" << changeSet << reset;
789// qDebug() << "ListViewWithPageHeader::onModelUpdated" << changeSet << reset;
754 const auto oldFirstVisibleIndex = m_firstVisibleIndex;
790 const auto oldFirstVisibleIndex = m_firstVisibleIndex;
755
791
792+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
756 Q_FOREACH(const QQuickChangeSet::Remove &remove, changeSet.removes()) {
793 Q_FOREACH(const QQuickChangeSet::Remove &remove, changeSet.removes()) {
794+#else
795+ Q_FOREACH(const QQmlChangeSet::Remove &remove, changeSet.removes()) {
796+#endif
757// qDebug() << "ListViewWithPageHeader::onModelUpdated Remove" << remove.index << remove.count;
797// qDebug() << "ListViewWithPageHeader::onModelUpdated Remove" << remove.index << remove.count;
758 if (remove.index + remove.count > m_firstVisibleIndex && remove.index < m_firstVisibleIndex + m_visibleItems.count()) {
798 if (remove.index + remove.count > m_firstVisibleIndex && remove.index < m_firstVisibleIndex + m_visibleItems.count()) {
759 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
799 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
@@ -803,7 +843,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bo
803 }
843 }
804 }
844 }
805
845
846+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
806 Q_FOREACH(const QQuickChangeSet::Insert &insert, changeSet.inserts()) {
847 Q_FOREACH(const QQuickChangeSet::Insert &insert, changeSet.inserts()) {
848+#else
849+ Q_FOREACH(const QQmlChangeSet::Insert &insert, changeSet.inserts()) {
850+#endif
807// qDebug() << "ListViewWithPageHeader::onModelUpdated Insert" << insert.index << insert.count;
851// qDebug() << "ListViewWithPageHeader::onModelUpdated Insert" << insert.index << insert.count;
808 const bool insertingInValidIndexes = insert.index > m_firstVisibleIndex && insert.index < m_firstVisibleIndex + m_visibleItems.count();
852 const bool insertingInValidIndexes = insert.index > m_firstVisibleIndex && insert.index < m_firstVisibleIndex + m_visibleItems.count();
809 const bool firstItemWithViewOnTop = insert.index == 0 && m_firstVisibleIndex == 0 && m_visibleItems.first()->y() + m_clipItem->y() > contentY();
853 const bool firstItemWithViewOnTop = insert.index == 0 && m_firstVisibleIndex == 0 && m_visibleItems.first()->y() + m_clipItem->y() > contentY();
plugins/ListViewWithPageHeader/listviewwithpageheader.h+18−1
@@ -24,9 +24,14 @@
24#pragma GCC diagnostic pop
24#pragma GCC diagnostic pop
25
25
26class QAbstractItemModel;
26class QAbstractItemModel;
27−class QQuickChangeSet;
28class QQuickNumberAnimation;
27class QQuickNumberAnimation;
28+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
29+class QQuickChangeSet;
29class QQuickVisualDataModel;
30class QQuickVisualDataModel;
31+#else
32+class QQmlChangeSet;
33+class QQmlDelegateModel;
34+#endif
30
35
31
36
32/**
37/**
@@ -100,11 +105,19 @@ protected:
100 void updatePolish();
105 void updatePolish();
101
106
102private Q_SLOTS:
107private Q_SLOTS:
108+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
103 void itemCreated(int modelIndex, QQuickItem *item);
109 void itemCreated(int modelIndex, QQuickItem *item);
110+#else
111+ void itemCreated(int modelIndex, QObject *object);
112+#endif
104 void onContentHeightChanged();
113 void onContentHeightChanged();
105 void onContentWidthChanged();
114 void onContentWidthChanged();
106 void onHeightChanged();
115 void onHeightChanged();
116+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
107 void onModelUpdated(const QQuickChangeSet &changeSet, bool reset);
117 void onModelUpdated(const QQuickChangeSet &changeSet, bool reset);
118+#else
119+ void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
120+#endif
108 void onShowHeaderAnimationFinished();
121 void onShowHeaderAnimationFinished();
109
122
110private:
123private:
@@ -141,7 +154,11 @@ private:
141 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
154 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
142 QQuickItem *getSectionItem(const QString &sectionText);
155 QQuickItem *getSectionItem(const QString &sectionText);
143
156
157+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
144 QQuickVisualDataModel *m_delegateModel;
158 QQuickVisualDataModel *m_delegateModel;
159+#else
160+ QQmlDelegateModel *m_delegateModel;
161+#endif
145
162
146 // Index we are waiting because we requested it asynchronously
163 // Index we are waiting because we requested it asynchronously
147 int m_asyncRequestedIndex;
164 int m_asyncRequestedIndex;
tests/plugins/ListViewWithPageHeader/CMakeLists.txt+6−1
@@ -1,7 +1,12 @@
1# There's no cmake var for v8 include path :-/
1# There's no cmake var for v8 include path :-/
2# so create one
2# so create one
3LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
3LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
4+if(${Qt5Core_VERSION_STRING} VERSION_LESS "5.1.0")
4−SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/../QtV8/${Qt5Core_VERSION_STRING}/QtV8)
5+ SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/../QtV8/${Qt5Core_VERSION_STRING}/QtV8)
6+else()
7+ SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/QtV8/${Qt5Core_VERSION_STRING}/QtV8)
8+endif()
9+
5
10
6include_directories(
11include_directories(
7 ${Qt5Qml_PRIVATE_INCLUDE_DIRS}
12 ${Qt5Qml_PRIVATE_INCLUDE_DIRS}
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+12
@@ -22,7 +22,11 @@
22#include <QtTestGui>
22#include <QtTestGui>
23#pragma GCC diagnostic push
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-pedantic"
24#pragma GCC diagnostic ignored "-pedantic"
25+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
25#include <private/qquicklistmodel_p.h>
26#include <private/qquicklistmodel_p.h>
27+#else
28+#include <private/qqmllistmodel_p.h>
29+#endif
26#include <private/qquickanimation_p.h>
30#include <private/qquickanimation_p.h>
27#include <private/qquickitem_p.h>
31#include <private/qquickitem_p.h>
28#pragma GCC diagnostic pop
32#pragma GCC diagnostic pop
@@ -115,7 +119,11 @@ private Q_SLOTS:
115 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
119 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
116 view->setSource(QUrl::fromLocalFile(LISTVIEWWITHPAGEHEADER_FOLDER "/test.qml"));
120 view->setSource(QUrl::fromLocalFile(LISTVIEWWITHPAGEHEADER_FOLDER "/test.qml"));
117 lvwph = dynamic_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
121 lvwph = dynamic_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
122+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
118 model = view->rootObject()->findChild<QQuickListModel*>();
123 model = view->rootObject()->findChild<QQuickListModel*>();
124+#else
125+ model = view->rootObject()->findChild<QQmlListModel*>();
126+#endif
119 otherDelegate = view->rootObject()->findChild<QQmlComponent*>();
127 otherDelegate = view->rootObject()->findChild<QQmlComponent*>();
120 QVERIFY(lvwph);
128 QVERIFY(lvwph);
121 QVERIFY(model);
129 QVERIFY(model);
@@ -1366,7 +1374,11 @@ private Q_SLOTS:
1366private:
1374private:
1367 QQuickView *view;
1375 QQuickView *view;
1368 ListViewWithPageHeader *lvwph;
1376 ListViewWithPageHeader *lvwph;
1377+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
1369 QQuickListModel *model;
1378 QQuickListModel *model;
1379+#else
1380+ QQmlListModel *model;
1381+#endif
1370 QQmlComponent *otherDelegate;
1382 QQmlComponent *otherDelegate;
1371};
1383};
1372
1384
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+12
@@ -22,7 +22,11 @@
22#include <QtTestGui>
22#include <QtTestGui>
23#pragma GCC diagnostic push
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-pedantic"
24#pragma GCC diagnostic ignored "-pedantic"
25+#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
25#include <private/qquicklistmodel_p.h>
26#include <private/qquicklistmodel_p.h>
27+#else
28+#include <private/qqmllistmodel_p.h>
29+#endif
26#include <private/qquickanimation_p.h>
30#include <private/qquickanimation_p.h>
27#include <private/qquickitem_p.h>
31#include <private/qquickitem_p.h>
28#pragma GCC diagnostic pop
32#pragma GCC diagnostic pop
@@ -124,7 +128,11 @@ private Q_SLOTS:
124 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
128 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
125 view->setSource(QUrl::fromLocalFile(LISTVIEWWITHPAGEHEADER_FOLDER "/test_section.qml"));
129 view->setSource(QUrl::fromLocalFile(LISTVIEWWITHPAGEHEADER_FOLDER "/test_section.qml"));
126 lvwph = dynamic_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
130 lvwph = dynamic_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
131+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
127 model = view->rootObject()->findChild<QQuickListModel*>();
132 model = view->rootObject()->findChild<QQuickListModel*>();
133+#else
134+ model = view->rootObject()->findChild<QQmlListModel*>();
135+#endif
128 otherDelegate = view->rootObject()->findChild<QQmlComponent*>();
136 otherDelegate = view->rootObject()->findChild<QQmlComponent*>();
129 QVERIFY(lvwph);
137 QVERIFY(lvwph);
130 QVERIFY(model);
138 QVERIFY(model);
@@ -1618,7 +1626,11 @@ private Q_SLOTS:
1618private:
1626private:
1619 QQuickView *view;
1627 QQuickView *view;
1620 ListViewWithPageHeader *lvwph;
1628 ListViewWithPageHeader *lvwph;
1629+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
1621 QQuickListModel *model;
1630 QQuickListModel *model;
1631+#else
1632+ QQmlListModel *model;
1633+#endif
1622 QQmlComponent *otherDelegate;
1634 QQmlComponent *otherDelegate;
1623};
1635};
1624
1636