on xenial help sign in
Adapt to Qt 5.1.

QQuickVisualDataModel was moved and renamed to QQmlDelegateModel QQuickChangeSet was moved and renamed to QQmlChangeSet QQmlChangeSet deals with QObjects instead of QQuickItems V8 private include dir needed fixing

commitf10d0d4672b30c59eaa38359f706cd49742d00b0 authorMichał Sawicz <michal.sawicz@canonical.com> dateThu 11 Jul 2013, 20:20 (13 years ago) parent102d153
6 files changed+97−3
plugins/ListViewWithPageHeader/CMakeLists.txt+5−1 plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+44 plugins/ListViewWithPageHeader/listviewwithpageheader.h+18−1 tests/plugins/ListViewWithPageHeader/CMakeLists.txt+6−1 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+12 tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+12
plugins/ListViewWithPageHeader/CMakeLists.txt+5−1
@@ -4,7 +4,11 @@ include(Plugins)
44# There's no cmake var for v8 include path :-/
55# so create one
66LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
7−SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/../QtV8/${Qt5Core_VERSION_STRING}/QtV8)
7+if(${Qt5Core_VERSION_STRING} VERSION_LESS "5.1.0")
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()
812
913include_directories(
1014 ${CMAKE_CURRENT_SOURCE_DIR}
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+44
@@ -96,7 +96,11 @@
9696#include <qqmlengine.h>
9797#pragma GCC diagnostic push
9898#pragma GCC diagnostic ignored "-pedantic"
99+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
99100#include <private/qquickvisualdatamodel_p.h>
101+#else
102+#include <private/qqmldelegatemodel_p.h>
103+#endif
100104#include <private/qqmlglobal_p.h>
101105#include <private/qquickitem_p.h>
102106#include <private/qquickanimation_p.h>
@@ -183,10 +187,17 @@ void ListViewWithPageHeader::setModel(QAbstractItemModel *model)
183187 if (!m_delegateModel) {
184188 createDelegateModel();
185189 } else {
190+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
186191 disconnect(m_delegateModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)), this, SLOT(onModelUpdated(QQuickChangeSet,bool)));
187192 }
188193 m_delegateModel->setModel(QVariant::fromValue<QAbstractItemModel *>(model));
189194 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
190201 Q_EMIT modelChanged();
191202 // TODO?
192203// Q_EMIT contentHeightChanged();
@@ -446,8 +457,13 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
446457
447458void ListViewWithPageHeader::createDelegateModel()
448459{
460+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
449461 m_delegateModel = new QQuickVisualDataModel(qmlContext(this), this);
450462 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
451467 if (isComponentComplete())
452468 m_delegateModel->componentComplete();
453469 updateWatchedRoles();
@@ -528,8 +544,13 @@ bool ListViewWithPageHeader::addVisibleItems(qreal fillFrom, qreal fillTo, bool
528544void ListViewWithPageHeader::reallyReleaseItem(ListItem *listItem)
529545{
530546 QQuickItem *item = listItem->m_item;
547+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
531548 QQuickVisualModel::ReleaseFlags flags = m_delegateModel->release(item);
532549 if (flags & QQuickVisualModel::Destroyed) {
550+#else
551+ QQmlDelegateModel::ReleaseFlags flags = m_delegateModel->release(item);
552+ if (flags & QQmlDelegateModel::Destroyed) {
553+#endif
533554 item->setParentItem(nullptr);
534555 }
535556 delete listItem->m_sectionItem;
@@ -658,7 +679,11 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
658679 return nullptr;
659680
660681 m_asyncRequestedIndex = -1;
682+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
661683 QQuickItem *item = m_delegateModel->item(modelIndex, asynchronous);
684+#else
685+ QQuickItem *item = qobject_cast<QQuickItem *>(m_delegateModel->object(modelIndex, asynchronous));
686+#endif
662687 if (!item) {
663688 m_asyncRequestedIndex = modelIndex;
664689 return 0;
@@ -711,8 +736,14 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
711736 }
712737}
713738
739+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
714740void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
715741{
742+#else
743+void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
744+{
745+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
746+#endif
716747// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
717748
718749 item->setParentItem(m_clipItem);
@@ -747,13 +778,22 @@ void ListViewWithPageHeader::onHeightChanged()
747778 polish();
748779}
749780
781+
782+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
750783void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
784+#else
785+void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool /*reset*/)
786+#endif
751787{
752788 // TODO Do something with reset
753789// qDebug() << "ListViewWithPageHeader::onModelUpdated" << changeSet << reset;
754790 const auto oldFirstVisibleIndex = m_firstVisibleIndex;
755791
792+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
756793 Q_FOREACH(const QQuickChangeSet::Remove &remove, changeSet.removes()) {
794+#else
795+ Q_FOREACH(const QQmlChangeSet::Remove &remove, changeSet.removes()) {
796+#endif
757797// qDebug() << "ListViewWithPageHeader::onModelUpdated Remove" << remove.index << remove.count;
758798 if (remove.index + remove.count > m_firstVisibleIndex && remove.index < m_firstVisibleIndex + m_visibleItems.count()) {
759799 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
@@ -803,7 +843,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bo
803843 }
804844 }
805845
846+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
806847 Q_FOREACH(const QQuickChangeSet::Insert &insert, changeSet.inserts()) {
848+#else
849+ Q_FOREACH(const QQmlChangeSet::Insert &insert, changeSet.inserts()) {
850+#endif
807851// qDebug() << "ListViewWithPageHeader::onModelUpdated Insert" << insert.index << insert.count;
808852 const bool insertingInValidIndexes = insert.index > m_firstVisibleIndex && insert.index < m_firstVisibleIndex + m_visibleItems.count();
809853 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 @@
2424#pragma GCC diagnostic pop
2525
2626class QAbstractItemModel;
27−class QQuickChangeSet;
2827class QQuickNumberAnimation;
28+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
29+class QQuickChangeSet;
2930class QQuickVisualDataModel;
31+#else
32+class QQmlChangeSet;
33+class QQmlDelegateModel;
34+#endif
3035
3136
3237/**
@@ -100,11 +105,19 @@ protected:
100105 void updatePolish();
101106
102107private Q_SLOTS:
108+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
103109 void itemCreated(int modelIndex, QQuickItem *item);
110+#else
111+ void itemCreated(int modelIndex, QObject *object);
112+#endif
104113 void onContentHeightChanged();
105114 void onContentWidthChanged();
106115 void onHeightChanged();
116+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
107117 void onModelUpdated(const QQuickChangeSet &changeSet, bool reset);
118+#else
119+ void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
120+#endif
108121 void onShowHeaderAnimationFinished();
109122
110123private:
@@ -141,7 +154,11 @@ private:
141154 QQuickItem *getSectionItem(int modelIndex, bool alreadyInserted);
142155 QQuickItem *getSectionItem(const QString &sectionText);
143156
157+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
144158 QQuickVisualDataModel *m_delegateModel;
159+#else
160+ QQmlDelegateModel *m_delegateModel;
161+#endif
145162
146163 // Index we are waiting because we requested it asynchronously
147164 int m_asyncRequestedIndex;
tests/plugins/ListViewWithPageHeader/CMakeLists.txt+6−1
@@ -1,7 +1,12 @@
11# There's no cmake var for v8 include path :-/
22# so create one
33LIST(GET Qt5Core_INCLUDE_DIRS 0 QtCoreDir0)
4−SET(Qt5V8_PRIVATE_INCLUDE_DIR ${QtCoreDir0}/../QtV8/${Qt5Core_VERSION_STRING}/QtV8)
4+if(${Qt5Core_VERSION_STRING} VERSION_LESS "5.1.0")
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+
510
611include_directories(
712 ${Qt5Qml_PRIVATE_INCLUDE_DIRS}
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertest.cpp+12
@@ -22,7 +22,11 @@
2222#include <QtTestGui>
2323#pragma GCC diagnostic push
2424#pragma GCC diagnostic ignored "-pedantic"
25+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
2526#include <private/qquicklistmodel_p.h>
27+#else
28+#include <private/qqmllistmodel_p.h>
29+#endif
2630#include <private/qquickanimation_p.h>
2731#include <private/qquickitem_p.h>
2832#pragma GCC diagnostic pop
@@ -115,7 +119,11 @@ private Q_SLOTS:
115119 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
116120 view->setSource(QUrl::fromLocalFile(LISTVIEWWITHPAGEHEADER_FOLDER "/test.qml"));
117121 lvwph = dynamic_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
122+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
118123 model = view->rootObject()->findChild<QQuickListModel*>();
124+#else
125+ model = view->rootObject()->findChild<QQmlListModel*>();
126+#endif
119127 otherDelegate = view->rootObject()->findChild<QQmlComponent*>();
120128 QVERIFY(lvwph);
121129 QVERIFY(model);
@@ -1366,7 +1374,11 @@ private Q_SLOTS:
13661374private:
13671375 QQuickView *view;
13681376 ListViewWithPageHeader *lvwph;
1377+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
13691378 QQuickListModel *model;
1379+#else
1380+ QQmlListModel *model;
1381+#endif
13701382 QQmlComponent *otherDelegate;
13711383};
13721384
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+12
@@ -22,7 +22,11 @@
2222#include <QtTestGui>
2323#pragma GCC diagnostic push
2424#pragma GCC diagnostic ignored "-pedantic"
25+#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
2526#include <private/qquicklistmodel_p.h>
27+#else
28+#include <private/qqmllistmodel_p.h>
29+#endif
2630#include <private/qquickanimation_p.h>
2731#include <private/qquickitem_p.h>
2832#pragma GCC diagnostic pop
@@ -124,7 +128,11 @@ private Q_SLOTS:
124128 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
125129 view->setSource(QUrl::fromLocalFile(LISTVIEWWITHPAGEHEADER_FOLDER "/test_section.qml"));
126130 lvwph = dynamic_cast<ListViewWithPageHeader*>(view->rootObject()->findChild<QQuickFlickable*>());
131+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
127132 model = view->rootObject()->findChild<QQuickListModel*>();
133+#else
134+ model = view->rootObject()->findChild<QQmlListModel*>();
135+#endif
128136 otherDelegate = view->rootObject()->findChild<QQmlComponent*>();
129137 QVERIFY(lvwph);
130138 QVERIFY(model);
@@ -1618,7 +1626,11 @@ private Q_SLOTS:
16181626private:
16191627 QQuickView *view;
16201628 ListViewWithPageHeader *lvwph;
1629+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
16211630 QQuickListModel *model;
1631+#else
1632+ QQmlListModel *model;
1633+#endif
16221634 QQmlComponent *otherDelegate;
16231635};
16241636