summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@jollamobile.com>2015-08-18 14:30:32 +1000
committerAaron McCarthy <mccarthy.aaron@gmail.com>2015-09-09 01:04:14 +0000
commitf72a9398e5699b6aa417540e04bf5a0a911b7d0a (patch)
tree9c47c26d94941ad2f92d8fcb683a8e384498c7f9 /src
parentd6108626faa614348dc872633434f4d8a7dde734 (diff)
downloadqtlocation-f72a9398e5699b6aa417540e04bf5a0a911b7d0a.tar.gz
Make use of incubator to asynchronously instantiate delegates
This has the side effect that map items instantiated by the view are no longer be added to the map in a deterministic order. Change-Id: I5933136e8d9dbf0e698353370b9bfc0affe146ac Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/imports/location/location.pro6
-rw-r--r--src/imports/location/mapitemviewdelegateincubator.cpp57
-rw-r--r--src/imports/location/mapitemviewdelegateincubator.h65
-rw-r--r--src/imports/location/qdeclarativegeomapitemview.cpp81
-rw-r--r--src/imports/location/qdeclarativegeomapitemview_p.h12
5 files changed, 188 insertions, 33 deletions
diff --git a/src/imports/location/location.pro b/src/imports/location/location.pro
index 254802e4..7441fab3 100644
--- a/src/imports/location/location.pro
+++ b/src/imports/location/location.pro
@@ -28,7 +28,8 @@ HEADERS += \
error_messages.h \
locationvaluetypehelper_p.h\
qquickgeomapgesturearea_p.h\
- ../positioning/qquickgeocoordinateanimation_p.h
+ ../positioning/qquickgeocoordinateanimation_p.h \
+ mapitemviewdelegateincubator.h
SOURCES += \
location.cpp \
@@ -53,7 +54,8 @@ SOURCES += \
error_messages.cpp \
locationvaluetypehelper.cpp \
qquickgeomapgesturearea.cpp \
- ../positioning/qquickgeocoordinateanimation.cpp
+ ../positioning/qquickgeocoordinateanimation.cpp \
+ mapitemviewdelegateincubator.cpp
include(declarativeplaces/declarativeplaces.pri)
diff --git a/src/imports/location/mapitemviewdelegateincubator.cpp b/src/imports/location/mapitemviewdelegateincubator.cpp
new file mode 100644
index 00000000..2c4ba823
--- /dev/null
+++ b/src/imports/location/mapitemviewdelegateincubator.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Jolla Ltd, author: Aaron McCarthy <aaron.mccarthy@jollamobile.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mapitemviewdelegateincubator.h"
+#include "qdeclarativegeomapitemview_p.h"
+
+QT_BEGIN_NAMESPACE
+
+MapItemViewDelegateIncubator::MapItemViewDelegateIncubator(QDeclarativeGeoMapItemView *view)
+: m_view(view)
+{
+}
+
+void MapItemViewDelegateIncubator::statusChanged(QQmlIncubator::Status status)
+{
+ m_view->incubatorStatusChanged(this, status);
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/location/mapitemviewdelegateincubator.h b/src/imports/location/mapitemviewdelegateincubator.h
new file mode 100644
index 00000000..7e0813c0
--- /dev/null
+++ b/src/imports/location/mapitemviewdelegateincubator.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Jolla Ltd, author: Aaron McCarthy <aaron.mccarthy@jollamobile.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAPITEMVIEWDELEGATEINCUBATOR_H
+#define MAPITEMVIEWDELEGATEINCUBATOR_H
+
+#include <QtQml/QQmlIncubator>
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeGeoMapItemView;
+
+class MapItemViewDelegateIncubator : public QQmlIncubator
+{
+public:
+ MapItemViewDelegateIncubator(QDeclarativeGeoMapItemView *view);
+
+protected:
+ void statusChanged(Status status) Q_DECL_OVERRIDE;
+
+private:
+ QDeclarativeGeoMapItemView *m_view;
+};
+
+QT_END_NAMESPACE
+
+#endif // MAPITEMVIEWDELEGATEINCUBATOR_H
diff --git a/src/imports/location/qdeclarativegeomapitemview.cpp b/src/imports/location/qdeclarativegeomapitemview.cpp
index 624d2983..eff03b17 100644
--- a/src/imports/location/qdeclarativegeomapitemview.cpp
+++ b/src/imports/location/qdeclarativegeomapitemview.cpp
@@ -39,9 +39,11 @@
#include "qdeclarativegeomapitemview_p.h"
#include "qdeclarativegeomap_p.h"
#include "qdeclarativegeomapitembase_p.h"
+#include "mapitemviewdelegateincubator.h"
#include <QtCore/QAbstractItemModel>
#include <QtQml/QQmlContext>
+#include <QtQml/QQmlIncubator>
#include <QtQml/private/qqmlopenmetaobject_p.h>
QT_BEGIN_NAMESPACE
@@ -92,6 +94,49 @@ void QDeclarativeGeoMapItemView::componentComplete()
componentCompleted_ = true;
}
+void QDeclarativeGeoMapItemView::incubatorStatusChanged(MapItemViewDelegateIncubator *incubator,
+ QQmlIncubator::Status status)
+{
+ if (status == QQmlIncubator::Loading)
+ return;
+
+ for (int i = 0; i < m_itemData.length(); ++i) {
+ ItemData *itemData = m_itemData.at(i);
+ if (itemData->incubator != incubator)
+ continue;
+
+ switch (status) {
+ case QQmlIncubator::Ready:
+ itemData->item = qobject_cast<QDeclarativeGeoMapItemBase *>(incubator->object());
+ if (!itemData->item) {
+ qWarning() << "QDeclarativeGeoMapItemView map item delegate is of unsupported type.";
+ delete incubator->object();
+ } else {
+ map_->addMapItem(itemData->item);
+ if (fitViewport_)
+ fitViewport();
+ }
+ delete itemData->incubator;
+ itemData->incubator = 0;
+ break;
+ case QQmlIncubator::Null:
+ // Should never get here
+ delete itemData->incubator;
+ itemData->incubator = 0;
+ break;
+ case QQmlIncubator::Error:
+ qWarning() << "QDeclarativeGeoMapItemView map item creation failed.";
+ delete itemData->incubator;
+ itemData->incubator = 0;
+ break;
+ default:
+ ;
+ }
+
+ break;
+ }
+}
+
/*!
\qmlproperty model QtLocation::MapItemView::model
@@ -169,12 +214,7 @@ void QDeclarativeGeoMapItemView::itemModelRowsInserted(const QModelIndex &index,
for (int i = start; i <= end; ++i) {
const QModelIndex insertedIndex = itemModel_->index(i, 0, index);
- ItemData *itemData = createItemForIndex(insertedIndex);
- if (!itemData)
- break;
-
- m_itemData.insert(i, itemData);
- map_->addMapItem(itemData->item);
+ createItemForIndex(insertedIndex);
}
if (fitViewport_)
@@ -335,12 +375,7 @@ void QDeclarativeGeoMapItemView::instantiateAllItems()
for (int i = 0; i < itemModel_->rowCount(); ++i) {
const QModelIndex index = itemModel_->index(i, 0);
- ItemData *itemData = createItemForIndex(index);
- if (!itemData)
- break;
-
- m_itemData.append(itemData);
- map_->addMapItem(itemData->item);
+ createItemForIndex(index);
}
if (fitViewport_)
@@ -360,7 +395,7 @@ void QDeclarativeGeoMapItemView::repopulate()
/*!
\internal
*/
-QDeclarativeGeoMapItemView::ItemData *QDeclarativeGeoMapItemView::createItemForIndex(const QModelIndex &index)
+void QDeclarativeGeoMapItemView::createItemForIndex(const QModelIndex &index)
{
// Expected to be already tested by caller.
Q_ASSERT(delegate_);
@@ -389,27 +424,15 @@ QDeclarativeGeoMapItemView::ItemData *QDeclarativeGeoMapItemView::createItemForI
itemData->context->setContextProperty(QLatin1String("model"), itemData->modelData);
itemData->context->setContextProperty(QLatin1String("index"), index.row());
- QObject *object = delegate_->create(itemData->context);
-
- if (!object) {
- qWarning() << "QDeclarativeGeoMapItemView map item creation failed.";
- delete itemData;
- return 0;
- }
-
- itemData->item = qobject_cast<QDeclarativeGeoMapItemBase *>(object);
- if (!itemData->item) {
- qWarning() << "QDeclarativeGeoMapItemView map item delegate is of unsupported type.";
- delete object;
- delete itemData;
- return 0;
- }
+ itemData->incubator = new MapItemViewDelegateIncubator(this);
+ delegate_->create(*itemData->incubator, itemData->context);
- return itemData;
+ m_itemData.insert(index.row(), itemData);
}
QDeclarativeGeoMapItemView::ItemData::~ItemData()
{
+ delete incubator;
delete item;
delete context;
delete modelData;
diff --git a/src/imports/location/qdeclarativegeomapitemview_p.h b/src/imports/location/qdeclarativegeomapitemview_p.h
index fa91e3ad..29675295 100644
--- a/src/imports/location/qdeclarativegeomapitemview_p.h
+++ b/src/imports/location/qdeclarativegeomapitemview_p.h
@@ -41,6 +41,7 @@
#include <QtCore/QModelIndex>
#include <QtQml/QQmlParserStatus>
+#include <QtQml/QQmlIncubator>
#include <QtQml/qqml.h>
QT_BEGIN_NAMESPACE
@@ -52,6 +53,7 @@ class QDeclarativeGeoMap;
class QDeclarativeGeoMapItemBase;
class QQmlOpenMetaObject;
class QQmlOpenMetaObjectType;
+class MapItemViewDelegateIncubator;
class QDeclarativeGeoMapItemView : public QObject, public QQmlParserStatus
{
@@ -93,6 +95,10 @@ Q_SIGNALS:
void delegateChanged();
void autoFitViewportChanged();
+protected:
+ void incubatorStatusChanged(MapItemViewDelegateIncubator *incubator,
+ QQmlIncubator::Status status);
+
private Q_SLOTS:
void itemModelReset();
void itemModelRowsInserted(const QModelIndex &index, int start, int end);
@@ -105,19 +111,20 @@ private Q_SLOTS:
private:
struct ItemData {
ItemData()
- : item(0), context(0), modelData(0), modelDataMeta(0)
+ : incubator(0), item(0), context(0), modelData(0), modelDataMeta(0)
{
}
~ItemData();
+ MapItemViewDelegateIncubator *incubator;
QDeclarativeGeoMapItemBase *item;
QQmlContext *context;
QObject *modelData;
QQmlOpenMetaObject *modelDataMeta;
};
- ItemData *createItemForIndex(const QModelIndex &index);
+ void createItemForIndex(const QModelIndex &index);
void fitViewport();
bool componentCompleted_;
@@ -130,6 +137,7 @@ private:
QQmlOpenMetaObjectType *m_metaObjectType;
friend class QTypeInfo<ItemData>;
+ friend class MapItemViewDelegateIncubator;
};
Q_DECLARE_TYPEINFO(QDeclarativeGeoMapItemView::ItemData, Q_MOVABLE_TYPE);