summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomapitembase.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-04-05 10:54:07 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-01-26 14:46:08 +0000
commitd83f23e1ef19fe524c50b827ee408523dbb74bdc (patch)
treec04e66302e67c61c2909330ddf0e414a718f67ec /src/location/declarativemaps/qdeclarativegeomapitembase.cpp
parentc062403a894a270101ae821fd73fa848f918ac54 (diff)
downloadqtlocation-d83f23e1ef19fe524c50b827ee408523dbb74bdc.tar.gz
Moving location qml implementation to location/declarative*
QtLocation quick classes and headers are moved out of the import directory. The location quick classes are now in a subdirectory inside the main qtlocation module. This is necessary in order to privately export certain classes, such as Map Items classes, and create an API to inject these objects into QGeoMap to let plugins render the Map Items directly Change-Id: Ia6ba5f07c4eddd3c4c2ce54bf34f1afcd42c2558 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomapitembase.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitembase.cpp271
1 files changed, 271 insertions, 0 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomapitembase.cpp b/src/location/declarativemaps/qdeclarativegeomapitembase.cpp
new file mode 100644
index 00000000..93d07386
--- /dev/null
+++ b/src/location/declarativemaps/qdeclarativegeomapitembase.cpp
@@ -0,0 +1,271 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later 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 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdeclarativegeomapitembase_p.h"
+#include "qgeocameradata_p.h"
+#include <QtLocation/private/qgeomap_p.h>
+#include <QtQml/QQmlInfo>
+#include <QtQuick/QSGOpacityNode>
+#include <QtQuick/private/qquickmousearea_p.h>
+#include <QtQuick/private/qquickitem_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QGeoMapViewportChangeEvent::QGeoMapViewportChangeEvent()
+ : zoomLevelChanged(false),
+ centerChanged(false),
+ mapSizeChanged(false),
+ tiltChanged(false),
+ bearingChanged(false),
+ rollChanged(false)
+{
+}
+
+QGeoMapViewportChangeEvent::QGeoMapViewportChangeEvent(const QGeoMapViewportChangeEvent &other)
+{
+ this->operator=(other);
+}
+
+QGeoMapViewportChangeEvent &QGeoMapViewportChangeEvent::operator=(const QGeoMapViewportChangeEvent &other)
+{
+ if (this == &other)
+ return (*this);
+
+ cameraData = other.cameraData;
+ mapSize = other.mapSize;
+ zoomLevelChanged = other.zoomLevelChanged;
+ centerChanged = other.centerChanged;
+ mapSizeChanged = other.mapSizeChanged;
+ tiltChanged = other.tiltChanged;
+ bearingChanged = other.bearingChanged;
+ rollChanged = other.rollChanged;
+
+ return (*this);
+}
+
+QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent)
+: QQuickItem(parent), map_(0), quickMap_(0)
+{
+ setFiltersChildMouseEvents(true);
+ connect(this, SIGNAL(childrenChanged()),
+ this, SLOT(afterChildrenChanged()));
+}
+
+QDeclarativeGeoMapItemBase::~QDeclarativeGeoMapItemBase()
+{
+ disconnect(this, SLOT(afterChildrenChanged()));
+ if (quickMap_)
+ quickMap_->removeMapItem(this);
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMapItemBase::afterChildrenChanged()
+{
+ QList<QQuickItem *> kids = childItems();
+ if (kids.size() > 0) {
+ bool printedWarning = false;
+ foreach (QQuickItem *i, kids) {
+ if (i->flags() & QQuickItem::ItemHasContents
+ && !qobject_cast<QQuickMouseArea *>(i)) {
+ if (!printedWarning) {
+ qmlWarning(this) << "Geographic map items do not support child items";
+ printedWarning = true;
+ }
+
+ qmlWarning(i) << "deleting this child";
+ i->deleteLater();
+ }
+ }
+ }
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMapItemBase::setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map)
+{
+ if (quickMap == quickMap_)
+ return;
+ if (quickMap && quickMap_)
+ return; // don't allow association to more than one map
+ if (quickMap_)
+ quickMap_->disconnect(this);
+ if (map_)
+ map_->disconnect(this);
+
+ quickMap_ = quickMap;
+ map_ = map;
+
+ if (map_ && quickMap_) {
+ connect(map_, SIGNAL(cameraDataChanged(QGeoCameraData)),
+ this, SLOT(baseCameraDataChanged(QGeoCameraData)));
+ connect(quickMap, SIGNAL(heightChanged()), this, SLOT(polishAndUpdate()));
+ connect(quickMap, SIGNAL(widthChanged()), this, SLOT(polishAndUpdate()));
+ lastSize_ = QSizeF(quickMap_->width(), quickMap_->height());
+ lastCameraData_ = map_->cameraData();
+ }
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMapItemBase::baseCameraDataChanged(const QGeoCameraData &cameraData)
+{
+ QGeoMapViewportChangeEvent evt;
+ evt.cameraData = cameraData;
+ evt.mapSize = QSizeF(quickMap_->width(), quickMap_->height());
+
+ if (evt.mapSize != lastSize_)
+ evt.mapSizeChanged = true;
+
+ if (cameraData.bearing() != lastCameraData_.bearing())
+ evt.bearingChanged = true;
+ if (cameraData.center() != lastCameraData_.center())
+ evt.centerChanged = true;
+ if (cameraData.roll() != lastCameraData_.roll())
+ evt.rollChanged = true;
+ if (cameraData.tilt() != lastCameraData_.tilt())
+ evt.tiltChanged = true;
+ if (cameraData.zoomLevel() != lastCameraData_.zoomLevel())
+ evt.zoomLevelChanged = true;
+
+ lastSize_ = evt.mapSize;
+ lastCameraData_ = cameraData;
+
+ afterViewportChanged(evt);
+}
+
+/*!
+ \internal
+*/
+void QDeclarativeGeoMapItemBase::setPositionOnMap(const QGeoCoordinate &coordinate, const QPointF &offset)
+{
+ if (!map_ || !quickMap_)
+ return;
+
+ QDoubleVector2D wrappedProjection = map_->geoProjection().geoToWrappedMapProjection(coordinate);
+ if (! map_->geoProjection().isProjectable(wrappedProjection))
+ return;
+
+ QDoubleVector2D pos = map_->geoProjection().wrappedMapProjectionToItemPosition(wrappedProjection);
+ QPointF topLeft = pos.toPointF() - offset;
+
+ setPosition(topLeft);
+}
+
+static const double opacityRampMin = 1.5;
+static const double opacityRampMax = 2.5;
+/*!
+ \internal
+*/
+float QDeclarativeGeoMapItemBase::zoomLevelOpacity() const
+{
+ if (quickMap_->zoomLevel() > opacityRampMax)
+ return 1.0;
+ else if (quickMap_->zoomLevel() > opacityRampMin)
+ return quickMap_->zoomLevel() - opacityRampMin;
+ else
+ return 0.0;
+}
+
+bool QDeclarativeGeoMapItemBase::childMouseEventFilter(QQuickItem *item, QEvent *event)
+{
+ Q_UNUSED(item)
+ if (event->type() == QEvent::MouseButtonPress && !contains(static_cast<QMouseEvent*>(event)->pos())) {
+ // This is an evil hack: in case of items that are not rectangles, we never accept the event.
+ // Instead the events are now delivered to QDeclarativeGeoMapItemBase which doesn't to anything with them.
+ // The map below it still works since it filters events and steals the events at some point.
+ event->setAccepted(false);
+ return true;
+ }
+ return false;
+}
+
+/*!
+ \internal
+*/
+QSGNode *QDeclarativeGeoMapItemBase::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *pd)
+{
+ if (!map_ || !quickMap_) {
+ delete oldNode;
+ return 0;
+ }
+
+ QSGOpacityNode *opn = static_cast<QSGOpacityNode *>(oldNode);
+ if (!opn)
+ opn = new QSGOpacityNode();
+
+ opn->setOpacity(zoomLevelOpacity());
+
+ QSGNode *oldN = opn->childCount() ? opn->firstChild() : 0;
+ opn->removeAllChildNodes();
+ if (opn->opacity() > 0.0) {
+ QSGNode *n = this->updateMapItemPaintNode(oldN, pd);
+ if (n)
+ opn->appendChildNode(n);
+ } else {
+ delete oldN;
+ }
+
+ return opn;
+}
+
+/*!
+ \internal
+*/
+QSGNode *QDeclarativeGeoMapItemBase::updateMapItemPaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+{
+ delete oldNode;
+ return 0;
+}
+
+bool QDeclarativeGeoMapItemBase::isPolishScheduled() const
+{
+ return QQuickItemPrivate::get(this)->polishScheduled;
+}
+
+void QDeclarativeGeoMapItemBase::polishAndUpdate()
+{
+ polish();
+ update();
+}
+
+
+#include "moc_qdeclarativegeomapitembase_p.cpp"
+
+QT_END_NAMESPACE