on xenial help sign in
Adapt to Qt 5.1.

Approved by PS Jenkins bot, Michael Zanetti.

commita7c3d52707e95494e36a8210cce877eab9f8e391 authorAlbert Astals <albert.astals@canonical.com> dateMon 29 Jul 2013, 14:18 (13 years ago) parentba5eb2fe0ff3c2
11 files changed+120−8
plugins/ListViewWithPageHeader/CMakeLists.txt+5−1 plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+62 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 tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp+1−1 tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp+1−1 tests/plugins/Unity/Indicators/menucontentactivatortest.cpp+1−1 tests/plugins/Utils/qlimitproxymodeltest.cpp+1−1 tests/plugins/Utils/qsortfilterproxymodeltest.cpp+1−1
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+62
@@ -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,9 +679,27 @@ 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+ QObject* object = m_delegateModel->object(modelIndex, asynchronous);
686+ QQuickItem *item = qmlobject_cast<QQuickItem*>(object);
687+#endif
662688 if (!item) {
689+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
663690 m_asyncRequestedIndex = modelIndex;
691+#else
692+ if (object) {
693+ m_delegateModel->release(object);
694+ if (!m_delegateValidated) {
695+ m_delegateValidated = true;
696+ QObject* delegateObj = delegate();
697+ qmlInfo(delegateObj ? delegateObj : this) << "Delegate must be of Item type";
698+ }
699+ } else {
700+ m_asyncRequestedIndex = modelIndex;
701+ }
702+#endif
664703 return 0;
665704 } else {
666705// qDebug() << "ListViewWithPageHeader::createItem::We have the item" << modelIndex << item;
@@ -711,8 +750,18 @@ ListViewWithPageHeader::ListItem *ListViewWithPageHeader::createItem(int modelIn
711750 }
712751}
713752
753+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
714754void ListViewWithPageHeader::itemCreated(int modelIndex, QQuickItem *item)
715755{
756+#else
757+void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
758+{
759+ QQuickItem *item = qmlobject_cast<QQuickItem*>(object);
760+ if (!item) {
761+ qWarning() << "ListViewWithPageHeader::itemCreated got a non item for index" << modelIndex;
762+ return;
763+ }
764+#endif
716765// qDebug() << "ListViewWithPageHeader::itemCreated" << modelIndex << item;
717766
718767 item->setParentItem(m_clipItem);
@@ -747,13 +796,22 @@ void ListViewWithPageHeader::onHeightChanged()
747796 polish();
748797}
749798
799+
800+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
750801void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bool /*reset*/)
802+#else
803+void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool /*reset*/)
804+#endif
751805{
752806 // TODO Do something with reset
753807// qDebug() << "ListViewWithPageHeader::onModelUpdated" << changeSet << reset;
754808 const auto oldFirstVisibleIndex = m_firstVisibleIndex;
755809
810+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
756811 Q_FOREACH(const QQuickChangeSet::Remove &remove, changeSet.removes()) {
812+#else
813+ Q_FOREACH(const QQmlChangeSet::Remove &remove, changeSet.removes()) {
814+#endif
757815// qDebug() << "ListViewWithPageHeader::onModelUpdated Remove" << remove.index << remove.count;
758816 if (remove.index + remove.count > m_firstVisibleIndex && remove.index < m_firstVisibleIndex + m_visibleItems.count()) {
759817 const qreal oldFirstValidIndexPos = m_visibleItems.first()->y();
@@ -807,7 +865,11 @@ void ListViewWithPageHeader::onModelUpdated(const QQuickChangeSet &changeSet, bo
807865 }
808866 }
809867
868+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
810869 Q_FOREACH(const QQuickChangeSet::Insert &insert, changeSet.inserts()) {
870+#else
871+ Q_FOREACH(const QQmlChangeSet::Insert &insert, changeSet.inserts()) {
872+#endif
811873// qDebug() << "ListViewWithPageHeader::onModelUpdated Insert" << insert.index << insert.count;
812874 const bool insertingInValidIndexes = insert.index > m_firstVisibleIndex && insert.index < m_firstVisibleIndex + m_visibleItems.count();
813875 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);
@@ -1385,7 +1393,11 @@ private Q_SLOTS:
13851393private:
13861394 QQuickView *view;
13871395 ListViewWithPageHeader *lvwph;
1396+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
13881397 QQuickListModel *model;
1398+#else
1399+ QQmlListModel *model;
1400+#endif
13891401 QQmlComponent *otherDelegate;
13901402};
13911403
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);
@@ -1637,7 +1645,11 @@ private Q_SLOTS:
16371645private:
16381646 QQuickView *view;
16391647 ListViewWithPageHeader *lvwph;
1648+#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
16401649 QQuickListModel *model;
1650+#else
1651+ QQmlListModel *model;
1652+#endif
16411653 QQmlComponent *otherDelegate;
16421654};
16431655
tests/plugins/Unity/Indicators/indicatorsmanagertest.cpp+1−1
@@ -134,5 +134,5 @@ private Q_SLOTS:
134134 }
135135};
136136
137−QTEST_MAIN(IndicatorsManagerTest)
137+QTEST_GUILESS_MAIN(IndicatorsManagerTest)
138138#include "indicatorsmanagertest.moc"
tests/plugins/Unity/Indicators/indicatorsmodeltest.cpp+1−1
@@ -97,6 +97,6 @@ private Q_SLOTS:
9797 }
9898};
9999
100−QTEST_MAIN(IndicatorsModelTest)
100+QTEST_GUILESS_MAIN(IndicatorsModelTest)
101101
102102#include "indicatorsmodeltest.moc"
tests/plugins/Unity/Indicators/menucontentactivatortest.cpp+1−1
@@ -299,5 +299,5 @@ private:
299299 QList<int> m_deltas;
300300};
301301
302−QTEST_MAIN(MenuConentActivatorTest)
302+QTEST_GUILESS_MAIN(MenuConentActivatorTest)
303303#include "menucontentactivatortest.moc"
tests/plugins/Utils/qlimitproxymodeltest.cpp+1−1
@@ -481,6 +481,6 @@ private Q_SLOTS:
481481 }
482482};
483483
484−QTEST_MAIN(QLimitProxyModelTest)
484+QTEST_GUILESS_MAIN(QLimitProxyModelTest)
485485
486486#include "qlimitproxymodeltest.moc"
tests/plugins/Utils/qsortfilterproxymodeltest.cpp+1−1
@@ -285,6 +285,6 @@ private Q_SLOTS:
285285 }
286286};
287287
288−QTEST_MAIN(QSortFilterProxyModelTest)
288+QTEST_GUILESS_MAIN(QSortFilterProxyModelTest)
289289
290290#include "qsortfilterproxymodeltest.moc"