diff options
16 files changed, 318 insertions, 219 deletions
diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp index a067a60b..046f5ae2 100644 --- a/src/imports/location/location.cpp +++ b/src/imports/location/location.cpp @@ -60,7 +60,7 @@ #include "qdeclarativegeomaneuver_p.h" #include "qdeclarativegeomapflickable_p.h" #include "qdeclarativegeomappincharea_p.h" -#include "qdeclarativegeomapscreenitem_p.h" +#include "qdeclarativegeomapquickitem_p.h" #include "qdeclarativegeomapitemview_p.h" #include "qdeclarativegeomaptype_p.h" #include "qdeclarativerectanglemapitem_p.h" @@ -114,8 +114,9 @@ public: qmlRegisterType<QDeclarativeGeoServiceProvider>(uri, 5, 0, "Plugin"); qmlRegisterType<QDeclarativeGeoServiceProviderParameter>(uri, 5, 0, "PluginParameter"); qmlRegisterType<QDeclarativeGeoMap>(uri, 5, 0, "Map"); - qmlRegisterType<QDeclarativeGeoMapScreenItem>(uri, 5, 0, "MapScreenItem"); + qmlRegisterUncreatableType<QDeclarativeGeoMapItemBase>(uri, 5, 0, "GeoMapItemBase",QDeclarativeGeoMapItemBase::tr("GeoMapItemBase is not intended instantiable by developer.")); + qmlRegisterType<QDeclarativeGeoMapQuickItem>(uri, 5, 0, "MapQuickItem"); qmlRegisterType<QDeclarativeGeoMapItemView>(uri, 5, 0, "MapItemView"); qmlRegisterType<QDeclarativeGeoMapMouseArea>(uri, 5, 0, "MapMouseArea"); qmlRegisterType<QDeclarativeGeoMapMouseEvent>(uri, 5, 0, "MapMouseEvent"); @@ -140,8 +141,8 @@ public: qmlRegisterType<QDeclarativeReviewModel>(uri, 5, 0, "ReviewModel"); qmlRegisterType<QDeclarativeSupplier>(uri, 5, 0, "Supplier"); qmlRegisterType<QDeclarativePlaceUser>(uri, 5, 0, "User"); - qmlRegisterType<QDeclarativeRectangleMapItem>(uri, 5, 0, "RectangleMapItem"); - qmlRegisterType<QDeclarativeCircleMapItem>(uri, 5, 0, "CircleMapItem"); + qmlRegisterType<QDeclarativeRectangleMapItem>(uri, 5, 0, "MapRectangle"); + qmlRegisterType<QDeclarativeCircleMapItem>(uri, 5, 0, "MapCircle"); qmlRegisterType<QDeclarativeRecommendationModel>(uri, 5, 0, "PlaceRecommendationModel"); qmlRegisterType<QDeclarativeSupportedCategoriesModel>(uri, 5, 0, "CategoryModel"); diff --git a/src/imports/location/location.pro b/src/imports/location/location.pro index 5f18dc68..d07ae983 100644 --- a/src/imports/location/location.pro +++ b/src/imports/location/location.pro @@ -36,7 +36,8 @@ HEADERS += qdeclarativeposition_p.h \ qdeclarativegeomapflickable_p.h \ qdeclarativegeomappincharea_p.h \ qdeclarativegeomaptype_p.h \ - qdeclarativegeomapscreenitem_p.h \ + qdeclarativegeomapitembase_p.h \ + qdeclarativegeomapquickitem_p.h \ mapnode_p.h \ qdeclarativecirclemapitem_p.h \ qdeclarativerectanglemapitem_p.h @@ -63,7 +64,8 @@ SOURCES += qdeclarativeposition.cpp \ qdeclarativegeomapflickable.cpp \ qdeclarativegeomappincharea.cpp \ qdeclarativegeomaptype.cpp \ - qdeclarativegeomapscreenitem.cpp \ + qdeclarativegeomapitembase.cpp \ + qdeclarativegeomapquickitem.cpp \ mapnode.cpp \ qdeclarativecirclemapitem.cpp \ qdeclarativerectanglemapitem.cpp diff --git a/src/imports/location/qdeclarativecirclemapitem.cpp b/src/imports/location/qdeclarativecirclemapitem.cpp index 2b94acdb..8cf4a3f1 100644 --- a/src/imports/location/qdeclarativecirclemapitem.cpp +++ b/src/imports/location/qdeclarativecirclemapitem.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qdeclarativecirclemapitem_p.h" +#include "qdeclarativegeomapquickitem_p.h" #include "projection_p.h" #include <cmath> #include <QPen> @@ -103,8 +104,8 @@ static QPolygonF createPolygon(const Map& map, const QList<QGeoCoordinate> &path QDeclarativeCircleMapItem::QDeclarativeCircleMapItem(QQuickItem *parent): QDeclarativeGeoMapItemBase(parent), center_(0), - screenItem_(new QDeclarativeGeoMapScreenItem(this)), - circleMapPaintedItem_(new CircleMapPaintedItem(screenItem_)) + quickItem_(new QDeclarativeGeoMapQuickItem(this)), + circleMapPaintedItem_(new CircleMapPaintedItem(quickItem_)) { } @@ -187,14 +188,14 @@ void QDeclarativeCircleMapItem::update() if (!map()) return; - screenItem_->setCoordinate(new QDeclarativeCoordinate(circleMapPaintedItem_->screenItemCoordinate())); - screenItem_->setAnchorPoint(circleMapPaintedItem_->screenItemAnchorPoint()); + quickItem_->setCoordinate(new QDeclarativeCoordinate(circleMapPaintedItem_->quickItemCoordinate())); + quickItem_->setAnchorPoint(circleMapPaintedItem_->quickItemAnchorPoint()); - if (screenItem_->sourceItem() == 0) { + if (quickItem_->sourceItem() == 0) { connect(map(), SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData))); circleMapPaintedItem_->setMap(map()); - screenItem_->setMap(quickMap(), map()); - screenItem_->setSourceItem(circleMapPaintedItem_); + quickItem_->setMap(quickMap(), map()); + quickItem_->setSourceItem(circleMapPaintedItem_); } } @@ -272,8 +273,8 @@ void CircleMapPaintedItem::updateGeometry() setHeight(h); setContentsSize(QSize(w, h)); - screenItemCoordinate_ = centerCoord_; - screenItemAnchorPoint_ = QPointF(w, h) / 2; + quickItemCoordinate_ = centerCoord_; + quickItemAnchorPoint_ = QPointF(w, h) / 2; initialized_ = true; update(); @@ -380,12 +381,12 @@ qreal CircleMapPaintedItem::radius() const return radius_; } -QGeoCoordinate CircleMapPaintedItem::screenItemCoordinate() const +QGeoCoordinate CircleMapPaintedItem::quickItemCoordinate() const { - return screenItemCoordinate_; + return quickItemCoordinate_; } -QPointF CircleMapPaintedItem::screenItemAnchorPoint() const +QPointF CircleMapPaintedItem::quickItemAnchorPoint() const { - return screenItemAnchorPoint_; + return quickItemAnchorPoint_; } diff --git a/src/imports/location/qdeclarativecirclemapitem_p.h b/src/imports/location/qdeclarativecirclemapitem_p.h index edd022ed..4e3c8ab7 100644 --- a/src/imports/location/qdeclarativecirclemapitem_p.h +++ b/src/imports/location/qdeclarativecirclemapitem_p.h @@ -42,11 +42,12 @@ #ifndef QDECLARATIVECRICLEMAPITEM_H_ #define QDECLARATIVECRICLEMAPITEM_H_ -#include "qdeclarativegeomapscreenitem_p.h" +#include "qdeclarativegeomapitembase_p.h" #include <QPen> #include <QBrush> class CircleMapPaintedItem; +class QDeclarativeGeoMapQuickItem; class QDeclarativeCircleMapItem : public QDeclarativeGeoMapItemBase { @@ -83,7 +84,7 @@ private Q_SLOTS: private: QDeclarativeCoordinate *center_; - QDeclarativeGeoMapScreenItem *screenItem_; + QDeclarativeGeoMapQuickItem *quickItem_; CircleMapPaintedItem *circleMapPaintedItem_; QColor color_; }; @@ -115,8 +116,8 @@ public: QBrush brush() const; void setBrush(const QBrush &brush); - QGeoCoordinate screenItemCoordinate() const; - QPointF screenItemAnchorPoint() const; + QGeoCoordinate quickItemCoordinate() const; + QPointF quickItemAnchorPoint() const; private: void updateGeometry(); @@ -126,8 +127,8 @@ private: qreal zoomLevel_; QGeoCoordinate centerCoord_; qreal radius_; - QGeoCoordinate screenItemCoordinate_; - QPointF screenItemAnchorPoint_; + QGeoCoordinate quickItemCoordinate_; + QPointF quickItemAnchorPoint_; QPen pen_; QBrush brush_; QPolygonF polygon_; diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 70b41e26..c6bccf87 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -42,7 +42,7 @@ #include "qdeclarativegeomap_p.h" #include "qdeclarativegeomapmousearea_p.h" -#include "qdeclarativegeomapscreenitem_p.h" +#include "qdeclarativegeomapquickitem_p.h" #include "qdeclarativecoordinate_p.h" #include "qdeclarativegeoserviceprovider_p.h" #include <Qt3D/qglview.h> @@ -152,10 +152,10 @@ QDeclarativeGeoMap::~QDeclarativeGeoMap() // } // delete mapData_; // } - foreach (QDeclarativeGeoMapItemBase* item, mapScreenItems_) { + foreach (QDeclarativeGeoMapItemBase* item, mapItems_) { item->setMap(0,0); } - mapScreenItems_.clear(); + mapItems_.clear(); } void QDeclarativeGeoMap::componentComplete() @@ -224,9 +224,9 @@ void QDeclarativeGeoMap::populateMap() setupMapView(mapView); continue; } - QDeclarativeGeoMapItemBase* mapScreenItem = qobject_cast<QDeclarativeGeoMapItemBase*>(kids.at(i)); - if (mapScreenItem) { - addMapScreenItem(mapScreenItem); + QDeclarativeGeoMapItemBase* mapItem = qobject_cast<QDeclarativeGeoMapItemBase*>(kids.at(i)); + if (mapItem) { + addMapItem(mapItem); } } } @@ -779,37 +779,37 @@ void QDeclarativeGeoMap::wheelEvent(QWheelEvent *event) /*! \qmlmethod QtLocation5::Map::addMapItem(MapItem) - Adds the given MapOject to the Map. If the object already - is on the Map, it will not be added again. + Adds the given MapItem to the Map (e.g. MapQuickItem, MapCircle). If the object + already is on the Map, it will not be added again. As an example, consider you have a MapCircle presenting your current position: - \snippet doc/src/snippets/declarative/testpolyMapItems.qml Basic map position marker definition - You can add it to Map (alterntively it can be defined as a child element of the Map): + \snippet TODO + You can add it to Map (alternatively it can be defined as a child element of the Map): - \snippet doc/src/snippets/declarative/testpolyMapItems.qml Basic add MapItem + \snippet TODO Note: MapItemViews can not be added with this method. */ -void QDeclarativeGeoMap::addMapScreenItem(QDeclarativeGeoMapItemBase *item) +void QDeclarativeGeoMap::addMapItem(QDeclarativeGeoMapItemBase *item) { QLOC_TRACE0; - if (!item || mapScreenItems_.contains(item)) + if (!item || mapItems_.contains(item)) return; updateMutex_.lock(); item->setParentItem(this); item->setMap(this, map_); - mapScreenItems_.append(item); - connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(mapScreenItemDestroyed(QObject*))); + mapItems_.append(item); + connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(mapItemDestroyed(QObject*))); updateMutex_.unlock(); } -void QDeclarativeGeoMap::removeMapScreenItem(QDeclarativeGeoMapItemBase *item) +void QDeclarativeGeoMap::removeMapItem(QDeclarativeGeoMapItemBase *item) { QLOC_TRACE0; if (!item || !map_) return; - if (!mapScreenItems_.contains(item)) + if (!mapItems_.contains(item)) return; updateMutex_.lock(); item->setParentItem(0); @@ -817,24 +817,24 @@ void QDeclarativeGeoMap::removeMapScreenItem(QDeclarativeGeoMapItemBase *item) // stop listening to destroyed() item->disconnect(this); // these can be optmized for perf, as we already check the 'contains' above - mapScreenItems_.removeOne(item); + mapItems_.removeOne(item); updateMutex_.unlock(); } -void QDeclarativeGeoMap::clearMapScreenItems() +void QDeclarativeGeoMap::clearMapItems() { - if (mapScreenItems_.isEmpty()) + if (mapItems_.isEmpty()) return; updateMutex_.lock(); - mapScreenItems_.clear(); + mapItems_.clear(); updateMutex_.unlock(); } -void QDeclarativeGeoMap::mapScreenItemDestroyed(QObject* item) +void QDeclarativeGeoMap::mapItemDestroyed(QObject* item) { - QDeclarativeGeoMapItemBase* mapScreenItem = qobject_cast<QDeclarativeGeoMapItemBase*>(item); - if (mapScreenItem) - removeMapScreenItem(mapScreenItem); + QDeclarativeGeoMapItemBase* mapItem = qobject_cast<QDeclarativeGeoMapItemBase*>(item); + if (mapItem) + removeMapItem(mapItem); } void QDeclarativeGeoMap::setActiveMapType(QDeclarativeGeoMapType *mapType) @@ -856,11 +856,10 @@ QDeclarativeGeoMapType * QDeclarativeGeoMap::activeMapType() const exist, function does nothing. As an example, consider you have a MapCircle presenting your current position: - \snippet doc/src/snippets/declarative/testpolyMapItems.qml Basic map position marker definition + \snippet TODO You can remove it from the Map element: - \snippet doc/src/snippets/declarative/testpolyMapItems.qml Basic remove MapItem - + \snippet TODO */ diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index efe78b81..3b0939fd 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -151,9 +151,9 @@ public: // do we need this? //QDeclarativeListProperty<QDeclarativeGeoMapItemBase> items(); - Q_INVOKABLE void removeMapScreenItem(QDeclarativeGeoMapItemBase *item); - Q_INVOKABLE void addMapScreenItem(QDeclarativeGeoMapItemBase *item); - Q_INVOKABLE void clearMapScreenItems(); + Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item); + Q_INVOKABLE void addMapItem(QDeclarativeGeoMapItemBase *item); + Q_INVOKABLE void clearMapItems(); Q_INVOKABLE QDeclarativeCoordinate* toCoordinate(QPointF screenPosition) const; Q_INVOKABLE QPointF toScreenPosition(QDeclarativeCoordinate* coordinate) const; @@ -198,7 +198,7 @@ private Q_SLOTS: void centerLatitudeChanged(double latitude); void centerLongitudeChanged(double longitude); void centerAltitudeChanged(double altitude); - void mapScreenItemDestroyed(QObject* item); + void mapItemDestroyed(QObject* item); void mappingManagerInitialized(); void mapZoomLevelChanged(qreal zoom); void mapTiltChanged(qreal tilt); @@ -238,7 +238,7 @@ private: TileCache *tileCache_; Map *map_; - QList<QDeclarativeGeoMapItemBase*> mapScreenItems_; + QList<QDeclarativeGeoMapItemBase*> mapItems_; QMutex updateMutex_; friend class QDeclarativeGeoMapItem; diff --git a/src/imports/location/qdeclarativegeomapitembase.cpp b/src/imports/location/qdeclarativegeomapitembase.cpp new file mode 100644 index 00000000..33e01625 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapitembase.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativegeomapitembase_p.h" + +QT_BEGIN_NAMESPACE + +QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent) + : QQuickItem(parent), + quickMap_(0), + map_(0) +{ + setParentItem(parent); + setFlag(ItemHasContents, false); + setAcceptHoverEvents(false); +} + +QDeclarativeGeoMapItemBase::~QDeclarativeGeoMapItemBase() +{ +} + +void QDeclarativeGeoMapItemBase::componentComplete() +{ + componentComplete_ = true; +} + +bool QDeclarativeGeoMapItemBase::contains(QPoint point) +{ + return true; +} + +void QDeclarativeGeoMapItemBase::setMap(QDeclarativeGeoMap* quickMap, Map *map) +{ + QLOC_TRACE2(quickMap, quickMap_); + if (quickMap == quickMap_) + return; + if (quickMap && quickMap_) + return; // don't allow association to more than one map + quickMap_ = quickMap; + map_ = map; + this->update(); +} + +void QDeclarativeGeoMapItemBase::update() {} + +QDeclarativeGeoMap* QDeclarativeGeoMapItemBase::quickMap() +{ + return quickMap_; +} + +Map* QDeclarativeGeoMapItemBase::map() +{ + return map_; +} + +#include "moc_qdeclarativegeomapitembase_p.cpp" + +QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapitembase_p.h b/src/imports/location/qdeclarativegeomapitembase_p.h new file mode 100644 index 00000000..785fab09 --- /dev/null +++ b/src/imports/location/qdeclarativegeomapitembase_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEGEOMAPITEMBASE_H +#define QDECLARATIVEGEOMAPITEMBASE_H + +#include <QtDeclarative/qquickitem.h> + +#include "qdeclarativegeomap_p.h" + +QT_BEGIN_NAMESPACE + +class QDeclarativeGeoMapItemBase : public QQuickItem +{ + Q_OBJECT +public: + QDeclarativeGeoMapItemBase(QQuickItem *parent = 0); + ~QDeclarativeGeoMapItemBase(); + + void setMap(QDeclarativeGeoMap* quickMap, Map *map); + virtual void classBegin() {} + virtual void componentComplete(); + virtual bool contains(QPoint point); + QDeclarativeGeoMap* quickMap(); + +protected Q_SLOTS: + virtual void update(); + +protected: + Map* map(); + +private: + QDeclarativeGeoMap* quickMap_; + bool componentComplete_; + Map* map_; +}; + + +QT_END_NAMESPACE + +#endif diff --git a/src/imports/location/qdeclarativegeomapitemview.cpp b/src/imports/location/qdeclarativegeomapitemview.cpp index 0e146520..655f6b08 100644 --- a/src/imports/location/qdeclarativegeomapitemview.cpp +++ b/src/imports/location/qdeclarativegeomapitemview.cpp @@ -42,7 +42,7 @@ #include "qdeclarativegeomapitemview_p.h" #include "qdeclarativegeomapmousearea_p.h" #include "qdeclarativegeomap_p.h" -#include "qdeclarativegeomapscreenitem_p.h" +#include "qdeclarativegeomapitembase_p.h" #include <QDebug> #include <QDeclarativeParserStatus> @@ -126,17 +126,14 @@ void QDeclarativeGeoMapItemView::modelReset() void QDeclarativeGeoMapItemView::modelRowsInserted(QModelIndex, int start, int end) { if (!componentCompleted_ || !map_ || !delegate_ || !model_) { - QDeclarativeGeoMapScreenItem* mapItem; + QDeclarativeGeoMapItemBase* mapItem; for (int i = start; i <= end; ++i) { mapItem = createItem(i); if (!mapItem) { break; } mapItemList_.append(mapItem); - // TODO visibility factors need to be solved - //mapItem->setVisible(visible_); - map_->addMapScreenItem(mapItem); - // TODO mouse areas are omitted atm + map_->addMapItem(mapItem); } } } @@ -146,11 +143,11 @@ void QDeclarativeGeoMapItemView::modelRowsRemoved(QModelIndex, int start, int en if (!componentCompleted_ || !map_ || !delegate_ || !model_) return; for (int i = end; i >= start; --i) { - QDeclarativeGeoMapScreenItem *mapItem = mapItemList_.takeAt(i); + QDeclarativeGeoMapItemBase *mapItem = mapItemList_.takeAt(i); Q_ASSERT(mapItem); if (!mapItem) // bad break; - map_->removeMapScreenItem(mapItem); + map_->removeMapItem(mapItem); delete mapItem; } } @@ -192,7 +189,7 @@ void QDeclarativeGeoMapItemView::removeInstantiatedItems() if (!map_) return; for (int i = 0; i < mapItemList_.count(); ++ i) { - map_->removeMapScreenItem(mapItemList_.at(i)); + map_->removeMapItem(mapItemList_.at(i)); } qDeleteAll(mapItemList_); mapItemList_.clear(); @@ -210,15 +207,14 @@ void QDeclarativeGeoMapItemView::repopulate() // We could use more specialized landmark model calls here too, // but hopefully the support will be leveraged to a general model // level. - QDeclarativeGeoMapScreenItem* mapItem; + QDeclarativeGeoMapItemBase* mapItem; for (int i = 0; i < model_->rowCount(); ++i) { mapItem = createItem(i); Q_ASSERT(mapItem); if (!mapItem) // bad break; mapItemList_.append(mapItem); - // TODO what to do with visibility - map_->addMapScreenItem(mapItem); + map_->addMapItem(mapItem); } } @@ -226,13 +222,13 @@ void QDeclarativeGeoMapItemView::repopulate() // QObject* as data. Some day this may be leveraged to any user defined // model or e.g. XML model. //QDeclarativeGeoMapItem* QDeclarativeGeoMapItemView::createItem(int modelRow) -QDeclarativeGeoMapScreenItem* QDeclarativeGeoMapItemView::createItem(int modelRow) +QDeclarativeGeoMapItemBase* QDeclarativeGeoMapItemView::createItem(int modelRow) { if (!delegate_ || !model_) return NULL; QModelIndex index = model_->index(modelRow, 0); // column 0 if (!index.isValid()) { - qWarning() << "QDeclarativeGeoMapItem Index is not valid: " << modelRow; + qWarning() << "QDeclarativeGeoMapItemView Index is not valid: " << modelRow; return NULL; } QHashIterator<int, QByteArray> iterator(model_->roleNames()); @@ -259,13 +255,13 @@ QDeclarativeGeoMapScreenItem* QDeclarativeGeoMapItemView::createItem(int modelRo QObject* obj = delegate_->create(itemContext); if (!obj) { - qWarning() << "QDeclarativeGeoMapItem map item creation failed."; + qWarning() << "QDeclarativeGeoMapItemView map item creation failed."; delete itemContext; return 0; } - QDeclarativeGeoMapScreenItem *declMapObj = qobject_cast<QDeclarativeGeoMapScreenItem*>(obj); + QDeclarativeGeoMapItemBase *declMapObj = qobject_cast<QDeclarativeGeoMapItemBase*>(obj); if (!declMapObj) { - qWarning() << "QDeclarativeGeoMapItem map item delegate is of unsupported type."; + qWarning() << "QDeclarativeGeoMapItemView map item delegate is of unsupported type."; delete itemContext; return 0; } diff --git a/src/imports/location/qdeclarativegeomapitemview_p.h b/src/imports/location/qdeclarativegeomapitemview_p.h index a7d084a2..65735350 100644 --- a/src/imports/location/qdeclarativegeomapitemview_p.h +++ b/src/imports/location/qdeclarativegeomapitemview_p.h @@ -42,7 +42,6 @@ #ifndef QDECLARATIVEGEOMAPITEMVIEW_H #define QDECLARATIVEGEOMAPITEMVIEW_H -#include "qdeclarativegeomapmouseevent_p.h" #include "QModelIndex" #include <QtDeclarative/QQuickItem> @@ -51,10 +50,8 @@ QT_BEGIN_NAMESPACE class QAbstractItemModel; -class QDeclarativeGraphicsGeoMap; class QDeclarativeGeoMap; -class QDeclarativeGeoMapScreenItem; -class QDeclarativeGeoMapMouseArea; +class QDeclarativeGeoMapItemBase; class QDeclarativeGeoMapItemView : public QObject, public QDeclarativeParserStatus { @@ -87,7 +84,7 @@ public: void setVisible(bool visible); bool isVisible() const; - QDeclarativeGeoMapScreenItem* createItem(int modelRow); + QDeclarativeGeoMapItemBase* createItem(int modelRow); // From QDeclarativeParserStatus virtual void componentComplete(); void classBegin() {} @@ -110,7 +107,7 @@ private: QVariant modelVariant_; QAbstractItemModel* model_; QDeclarativeGeoMap *map_; - QList<QDeclarativeGeoMapScreenItem*> mapItemList_; + QList<QDeclarativeGeoMapItemBase*> mapItemList_; }; QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapmousearea.cpp b/src/imports/location/qdeclarativegeomapmousearea.cpp index 14249205..0cf1200c 100644 --- a/src/imports/location/qdeclarativegeomapmousearea.cpp +++ b/src/imports/location/qdeclarativegeomapmousearea.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qdeclarativegeomapmousearea_p.h" -#include "qdeclarativegeomapscreenitem_p.h" +#include "qdeclarativegeomapitembase_p.h" #include <QtDeclarative/qdeclarativeinfo.h> #include <QtDeclarative/QQuickCanvas> diff --git a/src/imports/location/qdeclarativegeomapscreenitem.cpp b/src/imports/location/qdeclarativegeomapquickitem.cpp index 5a02244d..12ad4ad5 100644 --- a/src/imports/location/qdeclarativegeomapscreenitem.cpp +++ b/src/imports/location/qdeclarativegeomapquickitem.cpp @@ -39,8 +39,7 @@ ** ****************************************************************************/ -#include "qdeclarativegeomapscreenitem_p.h" -#include "qdeclarativegeomapmousearea_p.h" +#include "qdeclarativegeomapquickitem_p.h" #include "qdeclarativecoordinate_p.h" #include <QtDeclarative/qdeclarativeinfo.h> @@ -49,63 +48,13 @@ QT_BEGIN_NAMESPACE -QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent) - : QQuickItem(parent), - quickMap_(0), - map_(0) -{ - setParentItem(parent); - setFlag(ItemHasContents, false); - setAcceptHoverEvents(false); -} - -QDeclarativeGeoMapItemBase::~QDeclarativeGeoMapItemBase() -{ - if (quickMap_) - quickMap_->removeMapScreenItem(this); -} - -void QDeclarativeGeoMapItemBase::componentComplete() -{ - componentComplete_ = true; -} - -bool QDeclarativeGeoMapItemBase::contains(QPoint point) -{ - return true; -} - -void QDeclarativeGeoMapItemBase::setMap(QDeclarativeGeoMap* quickMap, Map *map) -{ - QLOC_TRACE2(quickMap, quickMap_); - if (quickMap == quickMap_) - return; - if (quickMap && quickMap_) - return; // don't allow association to more than one map - quickMap_ = quickMap; - map_ = map; - this->update(); -} - -void QDeclarativeGeoMapItemBase::update() {} - -QDeclarativeGeoMap* QDeclarativeGeoMapItemBase::quickMap() -{ - return quickMap_; -} - -Map* QDeclarativeGeoMapItemBase::map() -{ - return map_; -} - /*! - \qmlclass MapScreenItem + \qmlclass MapQuickItem - The MapScreenItem element is part of the \bold{QtLocation 5.0} module. + The MapQuickItem element is part of the \bold{QtLocation 5.0} module. */ -QDeclarativeGeoMapScreenItem::QDeclarativeGeoMapScreenItem(QQuickItem *parent) +QDeclarativeGeoMapQuickItem::QDeclarativeGeoMapQuickItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), coordinate_(0), sourceItem_(0), @@ -113,9 +62,9 @@ QDeclarativeGeoMapScreenItem::QDeclarativeGeoMapScreenItem(QQuickItem *parent) inUpdate_(false), mapAndSourceItemSet_(false) {} -QDeclarativeGeoMapScreenItem::~QDeclarativeGeoMapScreenItem() {} +QDeclarativeGeoMapQuickItem::~QDeclarativeGeoMapQuickItem() {} -void QDeclarativeGeoMapScreenItem::setCoordinate(QDeclarativeCoordinate *coordinate) +void QDeclarativeGeoMapQuickItem::setCoordinate(QDeclarativeCoordinate *coordinate) { if (coordinate_ == coordinate) return; @@ -140,18 +89,18 @@ void QDeclarativeGeoMapScreenItem::setCoordinate(QDeclarativeCoordinate *coordin emit coordinateChanged(); } -void QDeclarativeGeoMapScreenItem::coordinateCoordinateChanged(double) +void QDeclarativeGeoMapQuickItem::coordinateCoordinateChanged(double) { update(); emit coordinateChanged(); } -QDeclarativeCoordinate* QDeclarativeGeoMapScreenItem::coordinate() +QDeclarativeCoordinate* QDeclarativeGeoMapQuickItem::coordinate() { return coordinate_; } -void QDeclarativeGeoMapScreenItem::setSourceItem(QQuickItem* sourceItem) +void QDeclarativeGeoMapQuickItem::setSourceItem(QQuickItem* sourceItem) { if (sourceItem == sourceItem_) return; @@ -160,12 +109,12 @@ void QDeclarativeGeoMapScreenItem::setSourceItem(QQuickItem* sourceItem) emit sourceItemChanged(); } -QQuickItem* QDeclarativeGeoMapScreenItem::sourceItem() +QQuickItem* QDeclarativeGeoMapQuickItem::sourceItem() { return sourceItem_; } -void QDeclarativeGeoMapScreenItem::setAnchorPoint(const QPointF &anchorPoint) +void QDeclarativeGeoMapQuickItem::setAnchorPoint(const QPointF &anchorPoint) { if (anchorPoint == anchorPoint_) return; @@ -174,12 +123,12 @@ void QDeclarativeGeoMapScreenItem::setAnchorPoint(const QPointF &anchorPoint) emit anchorPointChanged(); } -QPointF QDeclarativeGeoMapScreenItem::anchorPoint() const +QPointF QDeclarativeGeoMapQuickItem::anchorPoint() const { return anchorPoint_; } -void QDeclarativeGeoMapScreenItem::setZoomLevel(qreal zoomLevel) +void QDeclarativeGeoMapQuickItem::setZoomLevel(qreal zoomLevel) { if (zoomLevel == zoomLevel_) return; @@ -188,12 +137,12 @@ void QDeclarativeGeoMapScreenItem::setZoomLevel(qreal zoomLevel) emit zoomLevelChanged(); } -qreal QDeclarativeGeoMapScreenItem::zoomLevel() const +qreal QDeclarativeGeoMapQuickItem::zoomLevel() const { return zoomLevel_; } -void QDeclarativeGeoMapScreenItem::update() +void QDeclarativeGeoMapQuickItem::update() { if (inUpdate_) return; @@ -245,6 +194,6 @@ void QDeclarativeGeoMapScreenItem::update() inUpdate_ = false; } -#include "moc_qdeclarativegeomapscreenitem_p.cpp" +#include "moc_qdeclarativegeomapquickitem_p.cpp" QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomapscreenitem_p.h b/src/imports/location/qdeclarativegeomapquickitem_p.h index 00e5b585..c51f46c8 100644 --- a/src/imports/location/qdeclarativegeomapscreenitem_p.h +++ b/src/imports/location/qdeclarativegeomapquickitem_p.h @@ -39,45 +39,18 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVEGEOMAPSCREENITEM_H -#define QDECLARATIVEGEOMAPSCREENITEM_H +#ifndef QDECLARATIVEGEOMAPQUICKITEM_H +#define QDECLARATIVEGEOMAPQUICKITEM_H #include <QtDeclarative/qquickitem.h> -#include <QtCore/QCoreApplication> -#include "qdeclarativecoordinate_p.h" #include "qdeclarativegeomap_p.h" - -class QDeclarativeGeoMapMouseArea; +#include "qdeclarativecoordinate_p.h" +#include "qdeclarativegeomapitembase_p.h" QT_BEGIN_NAMESPACE -class QDeclarativeGeoMapItemBase : public QQuickItem -{ - Q_OBJECT -public: - QDeclarativeGeoMapItemBase(QQuickItem *parent = 0); - ~QDeclarativeGeoMapItemBase(); - - void setMap(QDeclarativeGeoMap* quickMap, Map *map); - virtual void classBegin() {} - virtual void componentComplete(); - virtual bool contains(QPoint point); - QDeclarativeGeoMap* quickMap(); - -protected Q_SLOTS: - virtual void update(); - -protected: - Map* map(); - -private: - QDeclarativeGeoMap* quickMap_; - bool componentComplete_; - Map* map_; -}; - -class QDeclarativeGeoMapScreenItem : public QDeclarativeGeoMapItemBase +class QDeclarativeGeoMapQuickItem : public QDeclarativeGeoMapItemBase { Q_OBJECT Q_PROPERTY(QDeclarativeCoordinate* coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) @@ -86,8 +59,8 @@ class QDeclarativeGeoMapScreenItem : public QDeclarativeGeoMapItemBase Q_PROPERTY(QQuickItem* sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged) public: - QDeclarativeGeoMapScreenItem(QQuickItem *parent = 0); - ~QDeclarativeGeoMapScreenItem(); + QDeclarativeGeoMapQuickItem(QQuickItem *parent = 0); + ~QDeclarativeGeoMapQuickItem(); void setCoordinate(QDeclarativeCoordinate *coordinate); QDeclarativeCoordinate* coordinate(); @@ -125,6 +98,6 @@ private: QT_END_NAMESPACE -QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeGeoMapScreenItem)); +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeGeoMapQuickItem)); #endif diff --git a/src/imports/location/qdeclarativerectanglemapitem.cpp b/src/imports/location/qdeclarativerectanglemapitem.cpp index 8b1eaa9d..36fa9d70 100644 --- a/src/imports/location/qdeclarativerectanglemapitem.cpp +++ b/src/imports/location/qdeclarativerectanglemapitem.cpp @@ -40,11 +40,12 @@ ****************************************************************************/ #include "qdeclarativerectanglemapitem_p.h" +#include "qdeclarativegeomapquickitem_p.h" #include <QPainter> QDeclarativeRectangleMapItem::QDeclarativeRectangleMapItem(QQuickItem *parent) -: QDeclarativeGeoMapItemBase(parent), screenItem_(new QDeclarativeGeoMapScreenItem(this)), - rectangleMapPaintedItem_(new RectangleMapPaintedItem(screenItem_)), topLeft_(0), +: QDeclarativeGeoMapItemBase(parent), quickItem_(new QDeclarativeGeoMapQuickItem(this)), + rectangleMapPaintedItem_(new RectangleMapPaintedItem(quickItem_)), topLeft_(0), bottomRight_(0) { } @@ -110,16 +111,16 @@ void QDeclarativeRectangleMapItem::update() if (!map()) return; - screenItem_->setCoordinate( - new QDeclarativeCoordinate(rectangleMapPaintedItem_->screenItemCoordinate())); - screenItem_->setAnchorPoint(rectangleMapPaintedItem_->screenItemAnchorPoint()); + quickItem_->setCoordinate( + new QDeclarativeCoordinate(rectangleMapPaintedItem_->quickItemCoordinate())); + quickItem_->setAnchorPoint(rectangleMapPaintedItem_->quickItemAnchorPoint()); - if (screenItem_->sourceItem() == 0) { + if (quickItem_->sourceItem() == 0) { QObject::connect(map(), SIGNAL(cameraDataChanged(CameraData)), this, SLOT(handleCameraDataChanged(CameraData))); rectangleMapPaintedItem_->setMap(map()); - screenItem_->setMap(quickMap(), map()); - screenItem_->setSourceItem(rectangleMapPaintedItem_); + quickItem_->setMap(quickMap(), map()); + quickItem_->setSourceItem(rectangleMapPaintedItem_); } } @@ -258,21 +259,21 @@ void RectangleMapPaintedItem::updateGeometry() rect_.setTopLeft(QPointF(0, 0)); rect_.setBottomRight(QPointF(w, h)); - screenItemCoordinate_ = topLeftCoord_; - screenItemAnchorPoint_ = rect_.topLeft(); + quickItemCoordinate_ = topLeftCoord_; + quickItemAnchorPoint_ = rect_.topLeft(); initialized_ = true; update(); } -QGeoCoordinate RectangleMapPaintedItem::screenItemCoordinate() const +QGeoCoordinate RectangleMapPaintedItem::quickItemCoordinate() const { - return screenItemCoordinate_; + return quickItemCoordinate_; } -QPointF RectangleMapPaintedItem::screenItemAnchorPoint() const +QPointF RectangleMapPaintedItem::quickItemAnchorPoint() const { - return screenItemAnchorPoint_; + return quickItemAnchorPoint_; } void RectangleMapPaintedItem::setBrush(const QBrush &brush) diff --git a/src/imports/location/qdeclarativerectanglemapitem_p.h b/src/imports/location/qdeclarativerectanglemapitem_p.h index 189d0282..0b69f927 100644 --- a/src/imports/location/qdeclarativerectanglemapitem_p.h +++ b/src/imports/location/qdeclarativerectanglemapitem_p.h @@ -42,7 +42,7 @@ #ifndef QDECLARATIVERECTANGLEMAPITEM_H_ #define QDECLARATIVERECTANGLEMAPITEM_H_ -#include "qdeclarativegeomapscreenitem_p.h" +#include "qdeclarativegeomapitembase_p.h" #include "qdeclarativecoordinate_p.h" #include "qdeclarativegeomap_p.h" #include <QPen> @@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE class RectangleMapPaintedItem; +class QDeclarativeGeoMapQuickItem; class QDeclarativeRectangleMapItem: public QDeclarativeGeoMapItemBase { @@ -88,7 +89,7 @@ private Q_SLOTS: void handleBottomRightCoordinateChanged(); private: - QDeclarativeGeoMapScreenItem *screenItem_; + QDeclarativeGeoMapQuickItem *quickItem_; RectangleMapPaintedItem *rectangleMapPaintedItem_; QDeclarativeCoordinate* topLeft_; QDeclarativeCoordinate* bottomRight_; @@ -124,8 +125,8 @@ public: QBrush brush() const; void setBrush(const QBrush &brush); - QGeoCoordinate screenItemCoordinate() const; - QPointF screenItemAnchorPoint() const; + QGeoCoordinate quickItemCoordinate() const; + QPointF quickItemAnchorPoint() const; private: void updateGeometry(); @@ -134,8 +135,8 @@ private: qreal zoomLevel_; QGeoCoordinate topLeftCoord_; QGeoCoordinate bottomRightCoord_; - QGeoCoordinate screenItemCoordinate_; - QPointF screenItemAnchorPoint_; + QGeoCoordinate quickItemCoordinate_; + QPointF quickItemAnchorPoint_; QPen pen_; QBrush brush_; QRectF rect_; diff --git a/tests/applications/declarative_map/map3d.qml b/tests/applications/declarative_map/map3d.qml index 8082ab88..cd075a33 100644 --- a/tests/applications/declarative_map/map3d.qml +++ b/tests/applications/declarative_map/map3d.qml @@ -71,7 +71,7 @@ Item { Text {text: "Crazy mode:\n" + testModel.crazyMode + "\nclick to\ntoggle."} MouseArea{ anchors.fill: parent; onClicked: testModel.crazyMode = !testModel.crazyMode - onDoubleClicked: map.removeMapScreenItem(mapItem1) + onDoubleClicked: map.removeMapItem(mapItem1) } } AnimatedImage { @@ -84,14 +84,14 @@ Item { Rectangle {color: "lightblue"; width: 80; height: 80; Text {text: "Click:\nadd item1\nDouble-click:\nrm item1"} MouseArea{ anchors.fill: parent; - onClicked: {console.log('----------------adding item 1'); map.addMapScreenItem(externalStaticMapItem1);} - onDoubleClicked: {console.log('+++++++++++++++ removing item 1'); map.removeMapScreenItem(externalStaticMapItem1);} + onClicked: {console.log('----------------adding item 1'); map.addMapItem(externalStaticMapItem1);} + onDoubleClicked: {console.log('+++++++++++++++ removing item 1'); map.removeMapItem(externalStaticMapItem1);} } } Rectangle {color: "lightblue"; width: 80; height: 80; Text {text: "Click:\nadd item2\nDouble-click:\nrm item2"} MouseArea{ anchors.fill: parent; - onClicked: {console.log('adding item 2'); map.addMapScreenItem(externalStaticMapItem2);} + onClicked: {console.log('adding item 2'); map.addMapItem(externalStaticMapItem2);} onDoubleClicked: {console.log('removing item 2'); map.removeMapItem(externalStaticMapItem2);} } } @@ -244,9 +244,14 @@ Item { } } */ + MapCircle { + center: londonCoordinate + radius: 1000 + color: 'red' + } - MapScreenItem { - objectName: "blinky screen item 1" + MapQuickItem { + objectName: "blinky quick item 1" coordinate: Coordinate { latitude: -19; longitude : 146 } sourceItem: AnimatedImage { width: 80 @@ -257,7 +262,7 @@ Item { } Coordinate {id: londonCoordinate; latitude: 51.5; longitude: -0.11} - MapScreenItem { + MapQuickItem { MapMouseArea { id: mapMouseAreaUpperPurple z: 100 @@ -305,7 +310,7 @@ Item { } - MapScreenItem { + MapQuickItem { z: 1 objectName: "mousetestrectanglelower" coordinate: londonCoordinate @@ -320,8 +325,8 @@ Item { /* - MapScreenItem { - objectName: "blinky screen item 2" + MapQuickItem { + objectName: "blinky quick item 2" coordinate: brisbaneCoordinate anchorPoint: Qt.point(40, 40) zoomLevel: 6.0 @@ -354,14 +359,13 @@ Item { } */ - /* MapItemView { id: theObjectView model: testModel delegate: Component { - MapScreenItem { -// objectName: 'one of many items from model' -// visible: true + MapQuickItem { + objectName: 'one of many items from model' + visible: true zoomLevel: 7 sourceItem: Rectangle { width: 300; height: 300; color: 'green' @@ -391,7 +395,6 @@ Item { } } } - */ // From location.test plugin PinchGenerator { |