diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-01-30 20:59:59 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-03-11 12:10:54 +0000 |
commit | a52dae6a79c1c19ee2391037cfdc6d557381bb88 (patch) | |
tree | 0308df23ee4097132a8dc34a05ea326bb9adda58 /src/imports | |
parent | b1f6028c2aba51b898ce380f7b584ae603a06382 (diff) | |
download | qtlocation-a52dae6a79c1c19ee2391037cfdc6d557381bb88.tar.gz |
Introduce Qt.labs.location QtLocationLabs singleton type
This singleton is meant to offer tech-preview map-related API.
It starts with a mapObjectsAt invokable, that can be used to probe
MapObjects at a specific coordinate of a map.
Reference implementation for Q*ObjectQSG, based on QGeoShape::contains,
included.
Change-Id: Ief692eb5a43115ca02d4642c82023d1b2e217400
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/location/location.cpp | 1 | ||||
-rw-r--r-- | src/imports/locationlabs/locationlabs.cpp | 10 | ||||
-rw-r--r-- | src/imports/locationlabs/locationlabs.pro | 6 | ||||
-rw-r--r-- | src/imports/locationlabs/locationlabssingleton.cpp | 81 | ||||
-rw-r--r-- | src/imports/locationlabs/locationlabssingleton_p.h | 68 | ||||
-rw-r--r-- | src/imports/positioning/locationsingleton.h | 11 |
6 files changed, 175 insertions, 2 deletions
diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp index 049d52c0..5d1b6e23 100644 --- a/src/imports/location/location.cpp +++ b/src/imports/location/location.cpp @@ -176,6 +176,7 @@ public: // Register the 5.11 types minor = 11; + qmlRegisterType<QGeoMapObject>(); qmlRegisterType<QDeclarativeGeoManeuver, 11>(uri, major, minor, "RouteManeuver"); qmlRegisterType<QDeclarativeGeoMap, 11>(uri, major, minor, "Map"); qmlRegisterUncreatableType<QDeclarativeGeoMapItemBase, 11>(uri, major, minor, "GeoMapItemBase", diff --git a/src/imports/locationlabs/locationlabs.cpp b/src/imports/locationlabs/locationlabs.cpp index c90993eb..09fba284 100644 --- a/src/imports/locationlabs/locationlabs.cpp +++ b/src/imports/locationlabs/locationlabs.cpp @@ -43,13 +43,20 @@ #include <QtLocation/private/qdeclarativenavigator_p.h> #include <QtLocation/private/qdeclarativenavigator_p_p.h> #include <QtLocation/private/qnavigationmanagerengine_p.h> - #include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqml.h> #include <QtCore/QDebug> +#include "locationlabssingleton_p.h" QT_BEGIN_NAMESPACE +static QObject *singleton_type_factory(QQmlEngine *engine, QJSEngine *jsEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(jsEngine); + + return new LocationLabsSingleton; +} class QtLocationLabsDeclarativeModule: public QQmlExtensionPlugin { @@ -78,6 +85,7 @@ public: qmlRegisterType<QDeclarativeNavigationBasicDirections>(); qmlRegisterType<QDeclarativeNavigator>(uri, major, minor, "Navigator"); qmlRegisterType<QAbstractNavigator>(); + qmlRegisterSingletonType<LocationLabsSingleton>(uri, major, minor, "QtLocationLabs", singleton_type_factory); } else { qDebug() << "Unsupported URI given to load location QML plugin: " << QLatin1String(uri); } diff --git a/src/imports/locationlabs/locationlabs.pro b/src/imports/locationlabs/locationlabs.pro index 2fcc1adc..c55b09b8 100644 --- a/src/imports/locationlabs/locationlabs.pro +++ b/src/imports/locationlabs/locationlabs.pro @@ -5,8 +5,12 @@ CXX_MODULE = $$TARGET TARGETPATH = Qt/labs/location IMPORT_VERSION = 1.0 +HEADERS += \ + locationlabssingleton_p.h + SOURCES += \ - locationlabs.cpp + locationlabs.cpp \ + locationlabssingleton.cpp #CONFIG += no_cxx_module load(qml_plugin) diff --git a/src/imports/locationlabs/locationlabssingleton.cpp b/src/imports/locationlabs/locationlabssingleton.cpp new file mode 100644 index 00000000..c053da9e --- /dev/null +++ b/src/imports/locationlabs/locationlabssingleton.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtPositioning 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "locationlabssingleton_p.h" + +/*! + \qmltype QtLocationLabs + \instantiates LocationLabsSingleton + \inqmlmodule Qt.labs.location + \since 5.13 + + \brief The QtLocationLabs global object provides experimental, tech-preview functions for working with + location-based types in QML. + + \qml + import Qt.labs.location 1.0 + + Map { + id: map + MouseArea { + anchors.fill: parent + onClicked: { + var mapObjects = QtLocationLabs.mapObjectsAt(map.toCoordinate(Qt.point(mouseX,mouseY)), map) + } + } + } + \endqml +*/ + +LocationLabsSingleton::LocationLabsSingleton(QObject *parent) +: QObject(parent) +{ +} + +/*! + \qmlmethod coordinate ::QtLocationLabs::mapObjectsAt(coordinate, map) + + Returns the map objects in \a map covering \a coordinate. +*/ +QList<QObject *> LocationLabsSingleton::mapObjectsAt(const QGeoCoordinate &coordinate, QDeclarativeGeoMap *map) const +{ + if (!map) + return QList<QObject *>(); + return map->map()->mapObjectsAt(coordinate); +} diff --git a/src/imports/locationlabs/locationlabssingleton_p.h b/src/imports/locationlabs/locationlabssingleton_p.h new file mode 100644 index 00000000..42f4a21c --- /dev/null +++ b/src/imports/locationlabs/locationlabssingleton_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtPositioning 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LOCATIONLABSSINGLETON_P_H +#define LOCATIONLABSSINGLETON_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QObject> +#include <QtPositioning/QGeoCoordinate> +#include <QtLocation/private/qdeclarativegeomap_p.h> + +class LocationLabsSingleton : public QObject +{ + Q_OBJECT + +public: + explicit LocationLabsSingleton(QObject *parent = 0); + + Q_INVOKABLE QList<QObject *> mapObjectsAt(const QGeoCoordinate &coordinate, QDeclarativeGeoMap *map) const; +}; + +#endif // LOCATIONLABSSINGLETON_P_H diff --git a/src/imports/positioning/locationsingleton.h b/src/imports/positioning/locationsingleton.h index 9372b8f1..16d838e6 100644 --- a/src/imports/positioning/locationsingleton.h +++ b/src/imports/positioning/locationsingleton.h @@ -40,6 +40,17 @@ #ifndef LOCATIONSINGLETON_H #define LOCATIONSINGLETON_H +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + #include <QtCore/QObject> #include <QtCore/qnumeric.h> #include <QtPositioning/QGeoCoordinate> |