diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-07-29 12:50:33 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-07-29 12:50:33 +0200 |
commit | 5dddfc5121cac154023569fe69b417054ba53188 (patch) | |
tree | 47fffd0231e5b4d10fa41db18dc48b2e653f95dc | |
parent | 347daef6fbf084711fcec0df4421780f6c8a0bb0 (diff) | |
parent | d771c5dd31b46d76a8b9b9043263b754df81467d (diff) | |
download | qtlocation-5dddfc5121cac154023569fe69b417054ba53188.tar.gz |
Merge remote-tracking branch 'origin/5.3' into dev
Change-Id: I8768dd3f81a7f53020771f60332b1ed144b4ed07
3 files changed, 47 insertions, 53 deletions
diff --git a/src/imports/location/qdeclarativegeomapitemview.cpp b/src/imports/location/qdeclarativegeomapitemview.cpp index ea24d052..c51f09c1 100644 --- a/src/imports/location/qdeclarativegeomapitemview.cpp +++ b/src/imports/location/qdeclarativegeomapitemview.cpp @@ -44,7 +44,6 @@ #include "qdeclarativegeomapitembase_p.h" #include <QtCore/QAbstractItemModel> -#include <QtQml/QQmlParserStatus> #include <QtQml/QQmlContext> #include <QtQml/private/qqmlopenmetaobject_p.h> @@ -56,7 +55,7 @@ QT_BEGIN_NAMESPACE \inqmlmodule QtLocation \ingroup qml-QtLocation5-maps \since Qt Location 5.0 - \inherits QQuickItem + \inherits QObject \brief The MapItemView is used to populate Map from a model. @@ -83,8 +82,7 @@ QDeclarativeGeoMapItemView::QDeclarativeGeoMapItemView(QQuickItem *parent) QDeclarativeGeoMapItemView::~QDeclarativeGeoMapItemView() { - if (map_) - removeInstantiatedItems(); + removeInstantiatedItems(); } /*! @@ -98,33 +96,39 @@ void QDeclarativeGeoMapItemView::componentComplete() /*! \qmlproperty model QtLocation::MapItemView::model - This property holds the model that provides data used for - creating the map item defined by the delegate. + This property holds the model that provides data used for creating the map items defined by the + delegate. Only QAbstractItemModel based models are supported. */ QVariant QDeclarativeGeoMapItemView::model() const { - return modelVariant_; + return QVariant::fromValue(itemModel_); } void QDeclarativeGeoMapItemView::setModel(const QVariant &model) { - if (!model.isValid() || model == modelVariant_) + QAbstractItemModel *itemModel = model.value<QAbstractItemModel *>(); + if (itemModel == itemModel_) return; - QAbstractItemModel *itemModel = 0; - if (QObject *object = qvariant_cast<QObject *>(model)) - itemModel = qobject_cast<QAbstractItemModel *>(object); - if (!itemModel) - return; + if (itemModel_) { + disconnect(itemModel_, SIGNAL(modelReset()), this, SLOT(itemModelReset())); + disconnect(itemModel_, SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(itemModelRowsRemoved(QModelIndex,int,int))); + disconnect(itemModel_, SIGNAL(rowsInserted(QModelIndex,int,int)), + this, SLOT(itemModelRowsInserted(QModelIndex,int,int))); + + itemModel_ = 0; + } + + if (itemModel) { + itemModel_ = itemModel; + connect(itemModel_, SIGNAL(modelReset()), this, SLOT(itemModelReset())); + connect(itemModel_, SIGNAL(rowsRemoved(QModelIndex,int,int)), + this, SLOT(itemModelRowsRemoved(QModelIndex,int,int))); + connect(itemModel_, SIGNAL(rowsInserted(QModelIndex,int,int)), + this, SLOT(itemModelRowsInserted(QModelIndex,int,int))); + } - modelVariant_ = model; - itemModel_ = itemModel; - QObject::connect(itemModel_, SIGNAL(modelReset()), - this, SLOT(itemModelReset())); - QObject::connect(itemModel_, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(itemModelRowsRemoved(QModelIndex,int,int))); - QObject::connect(itemModel_, SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(itemModelRowsInserted(QModelIndex,int,int))); repopulate(); emit modelChanged(); } @@ -140,14 +144,16 @@ void QDeclarativeGeoMapItemView::itemModelReset() /*! \internal */ -void QDeclarativeGeoMapItemView::itemModelRowsInserted(QModelIndex, int start, int end) +void QDeclarativeGeoMapItemView::itemModelRowsInserted(const QModelIndex &index, int start, int end) { + Q_UNUSED(index) + if (!componentCompleted_ || !map_ || !delegate_ || !itemModel_) return; QDeclarativeGeoMapItemBase *mapItem; for (int i = start; i <= end; ++i) { - mapItem = createItem(i); + mapItem = createItemFromItemModel(i); if (!mapItem) { break; } @@ -161,8 +167,10 @@ void QDeclarativeGeoMapItemView::itemModelRowsInserted(QModelIndex, int start, i /*! \internal */ -void QDeclarativeGeoMapItemView::itemModelRowsRemoved(QModelIndex, int start, int end) +void QDeclarativeGeoMapItemView::itemModelRowsRemoved(const QModelIndex &index, int start, int end) { + Q_UNUSED(index) + if (!componentCompleted_ || !map_ || !delegate_ || !itemModel_) return; @@ -184,7 +192,6 @@ void QDeclarativeGeoMapItemView::itemModelRowsRemoved(QModelIndex, int start, in This property holds the delegate which defines how each item in the model should be displayed. The Component must contain exactly one MapItem -derived object as the root object. - */ QQmlComponent *QDeclarativeGeoMapItemView::delegate() const { @@ -193,8 +200,9 @@ QQmlComponent *QDeclarativeGeoMapItemView::delegate() const void QDeclarativeGeoMapItemView::setDelegate(QQmlComponent *delegate) { - if (!delegate) + if (delegate_ == delegate) return; + delegate_ = delegate; repopulate(); @@ -208,7 +216,6 @@ void QDeclarativeGeoMapItemView::setDelegate(QQmlComponent *delegate) to display all map items when items are added or removed. Defaults to false. - */ bool QDeclarativeGeoMapItemView::autoFitViewport() const { @@ -265,15 +272,15 @@ void QDeclarativeGeoMapItemView::removeInstantiatedItems() */ void QDeclarativeGeoMapItemView::repopulate() { - if (!componentCompleted_ || !map_ || !delegate_ || !itemModel_) - return; // Free any earlier instances removeInstantiatedItems(); + if (!componentCompleted_ || !map_ || !delegate_ || !itemModel_) + return; + // Iterate model data and instantiate delegates. - QDeclarativeGeoMapItemBase *mapItem; for (int i = 0; i < itemModel_->rowCount(); ++i) { - mapItem = createItem(i); + QDeclarativeGeoMapItemBase *mapItem = createItemFromItemModel(i); Q_ASSERT(mapItem); if (!mapItem) // bad break; @@ -284,14 +291,6 @@ void QDeclarativeGeoMapItemView::repopulate() fitViewport(); } -QDeclarativeGeoMapItemBase *QDeclarativeGeoMapItemView::createItem(int modelRow) -{ - if (itemModel_) - return createItemFromItemModel(modelRow); - return 0; -} - - /*! \internal */ diff --git a/src/imports/location/qdeclarativegeomapitemview_p.h b/src/imports/location/qdeclarativegeomapitemview_p.h index 385fceca..fc384fb8 100644 --- a/src/imports/location/qdeclarativegeomapitemview_p.h +++ b/src/imports/location/qdeclarativegeomapitemview_p.h @@ -42,15 +42,15 @@ #ifndef QDECLARATIVEGEOMAPITEMVIEW_H #define QDECLARATIVEGEOMAPITEMVIEW_H -#include "QModelIndex" - -#include <QtQuick/QQuickItem> +#include <QtCore/QModelIndex> #include <QtQml/QQmlParserStatus> -#include <QtCore/QPointer> +#include <QtQml/qqml.h> QT_BEGIN_NAMESPACE class QAbstractItemModel; +class QQmlComponent; +class QQuickItem; class QDeclarativeGeoMap; class QDeclarativeGeoMapItemBase; @@ -84,9 +84,6 @@ public: qreal zValue(); void setZValue(qreal zValue); - bool isVisible() const; - - QDeclarativeGeoMapItemBase *createItem(int modelRow); // From QQmlParserStatus virtual void componentComplete(); void classBegin() {} @@ -103,14 +100,12 @@ private: private Q_SLOTS: void itemModelReset(); - void itemModelRowsInserted(QModelIndex, int start, int end); - void itemModelRowsRemoved(QModelIndex, int start, int end); + void itemModelRowsInserted(const QModelIndex &index, int start, int end); + void itemModelRowsRemoved(const QModelIndex &index, int start, int end); private: - bool visible_; bool componentCompleted_; QQmlComponent *delegate_; - QVariant modelVariant_; QAbstractItemModel *itemModel_; QDeclarativeGeoMap *map_; QList<QDeclarativeGeoMapItemBase *> mapItemList_; diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm index 47ceb6b6..65848f7d 100644 --- a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm +++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm @@ -46,13 +46,13 @@ #define MINIMUM_UPDATE_INTERVAL 1000 -@interface locationDelegate : NSObject <CLLocationManagerDelegate> +@interface PositionLocationDelegate : NSObject <CLLocationManagerDelegate> { QGeoPositionInfoSourceCL *m_positionInfoSource; } @end -@implementation locationDelegate +@implementation PositionLocationDelegate - (id)initWithInfoSource:(QGeoPositionInfoSourceCL*) positionInfoSource { self = [super init]; @@ -132,7 +132,7 @@ bool QGeoPositionInfoSourceCL::enableLocationManager() if (!m_locationManager) { m_locationManager = [[CLLocationManager alloc] init]; m_locationManager.desiredAccuracy = kCLLocationAccuracyBest; - m_locationManager.delegate = [[locationDelegate alloc] initWithInfoSource:this]; + m_locationManager.delegate = [[PositionLocationDelegate alloc] initWithInfoSource:this]; } return (m_locationManager != 0); |