diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-02-22 16:30:23 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-03-23 08:43:33 +0000 |
commit | 2f100373feff003b3a9f43c9314ea239f38b97b3 (patch) | |
tree | c8a1c1bdf206185591f3579046f1aac1eb362997 /src/location/labs | |
parent | 8f0d2a042458195cebe28f3e80fe9522945b1a14 (diff) | |
download | qtlocation-2f100373feff003b3a9f43c9314ea239f38b97b3.tar.gz |
Move locationlabs code into location
The labs feature will still be controlled by location-labs-plugin
config option. They will simply come from the QtLocation module, and
be exposed to QML via the additional qml plugin in
imports/locationlabs.
Change-Id: I133d625708e78ba5d8121a95e45142aae5ec274b
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/labs')
-rw-r--r-- | src/location/labs/labs.pri | 4 | ||||
-rw-r--r-- | src/location/labs/qmapcircleobject.cpp | 243 | ||||
-rw-r--r-- | src/location/labs/qmapcircleobject_p.h | 93 | ||||
-rw-r--r-- | src/location/labs/qmapcircleobject_p_p.h | 117 | ||||
-rw-r--r-- | src/location/labs/qmapiconobject.cpp | 205 | ||||
-rw-r--r-- | src/location/labs/qmapiconobject_p.h | 88 | ||||
-rw-r--r-- | src/location/labs/qmapiconobject_p_p.h | 105 | ||||
-rw-r--r-- | src/location/labs/qmapobjectview.cpp | 355 | ||||
-rw-r--r-- | src/location/labs/qmapobjectview_p.h | 116 | ||||
-rw-r--r-- | src/location/labs/qmapobjectview_p_p.h | 86 | ||||
-rw-r--r-- | src/location/labs/qmappolygonobject.cpp | 217 | ||||
-rw-r--r-- | src/location/labs/qmappolygonobject_p.h | 90 | ||||
-rw-r--r-- | src/location/labs/qmappolygonobject_p_p.h | 112 | ||||
-rw-r--r-- | src/location/labs/qmappolylineobject.cpp | 186 | ||||
-rw-r--r-- | src/location/labs/qmappolylineobject_p.h | 85 | ||||
-rw-r--r-- | src/location/labs/qmappolylineobject_p_p.h | 107 | ||||
-rw-r--r-- | src/location/labs/qmaprouteobject.cpp | 161 | ||||
-rw-r--r-- | src/location/labs/qmaprouteobject_p.h | 90 | ||||
-rw-r--r-- | src/location/labs/qmaprouteobject_p_p.h | 79 |
19 files changed, 2539 insertions, 0 deletions
diff --git a/src/location/labs/labs.pri b/src/location/labs/labs.pri new file mode 100644 index 00000000..de2fd820 --- /dev/null +++ b/src/location/labs/labs.pri @@ -0,0 +1,4 @@ +INCLUDEPATH += labs + +PRIVATE_HEADERS += $$files($$PWD/*.h) +SOURCES += $$files($$PWD/*.cpp) diff --git a/src/location/labs/qmapcircleobject.cpp b/src/location/labs/qmapcircleobject.cpp new file mode 100644 index 00000000..9d8b14c0 --- /dev/null +++ b/src/location/labs/qmapcircleobject.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 "qmapcircleobject_p.h" +#include "qmapcircleobject_p_p.h" +#include <QExplicitlySharedDataPointer> + +QT_BEGIN_NAMESPACE + +QMapCircleObjectPrivate::QMapCircleObjectPrivate(QGeoMapObject *q) : QGeoMapObjectPrivate(q) +{ + +} + +QMapCircleObjectPrivate::~QMapCircleObjectPrivate() +{ + +} + +QGeoMapObject::Type QMapCircleObjectPrivate::type() const +{ + return QGeoMapObject::CircleType; +} + + + +// +// QMapCircleObjectPrivate default implementation +// + +QMapCircleObjectPrivateDefault::QMapCircleObjectPrivateDefault(QGeoMapObject *q) : QMapCircleObjectPrivate(q) +{ + +} + +QMapCircleObjectPrivateDefault::QMapCircleObjectPrivateDefault(const QMapCircleObjectPrivate &other) : QMapCircleObjectPrivate(other.q) +{ + m_center = other.center(); + m_radius = other.radius(); + m_fillColor = other.color(); + m_borderColor = other.borderColor(); + m_borderWidth = other.borderWidth(); +} + +QMapCircleObjectPrivateDefault::~QMapCircleObjectPrivateDefault() +{ + +} + +QGeoCoordinate QMapCircleObjectPrivateDefault::center() const +{ + return m_center; +} + +void QMapCircleObjectPrivateDefault::setCenter(const QGeoCoordinate ¢er) +{ + m_center = center; +} + +qreal QMapCircleObjectPrivateDefault::radius() const +{ + return m_radius; +} + +void QMapCircleObjectPrivateDefault::setRadius(qreal radius) +{ + m_radius = radius; +} + +QColor QMapCircleObjectPrivateDefault::color() const +{ + return m_fillColor; +} + +void QMapCircleObjectPrivateDefault::setColor(const QColor &color) +{ + m_fillColor = color; +} + +QColor QMapCircleObjectPrivateDefault::borderColor() const +{ + return m_borderColor; +} + +void QMapCircleObjectPrivateDefault::setBorderColor(const QColor &color) +{ + m_borderColor = color; +} + +qreal QMapCircleObjectPrivateDefault::borderWidth() const +{ + return m_borderWidth; +} + +void QMapCircleObjectPrivateDefault::setBorderWidth(qreal width) +{ + m_borderWidth = width; +} + +bool QMapCircleObjectPrivate::equals(const QGeoMapObjectPrivate &other) const +{ + if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used + return false; + + const QMapCircleObjectPrivate &o = static_cast<const QMapCircleObjectPrivate &>(other); + return (QGeoMapObjectPrivate::equals(o) + && center() == o.center() + && radius() == o.radius() + && color() == o.color() + && borderColor() == o.borderColor() + && borderWidth() == o.borderWidth()); +} + +QGeoMapObjectPrivate *QMapCircleObjectPrivateDefault::clone() +{ + return new QMapCircleObjectPrivateDefault(static_cast<QMapCircleObjectPrivate &>(*this)); +} + + + +QMapCircleObject::QMapCircleObject(QObject *parent) + : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapCircleObjectPrivateDefault(this)), parent) + +{ + QMapCircleObjectPrivate *d = static_cast<QMapCircleObjectPrivate*>(d_ptr.data()); + d->setBorderColor(QColor(Qt::black)); // These are QDeclarativeMapLineProperties defaults + d->setBorderWidth(1.0); +} + +QMapCircleObject::~QMapCircleObject() +{ + +} + + +QGeoCoordinate QMapCircleObject::center() const +{ + return static_cast<const QMapCircleObjectPrivate*>(d_ptr.data())->center(); +} + +qreal QMapCircleObject::radius() const +{ + return static_cast<const QMapCircleObjectPrivate*>(d_ptr.data())->radius(); +} + +QColor QMapCircleObject::color() const +{ + return static_cast<const QMapCircleObjectPrivate*>(d_ptr.data())->color(); +} + +QDeclarativeMapLineProperties *QMapCircleObject::border() +{ + if (!m_border) { + m_border = new QDeclarativeMapLineProperties; + connect(m_border, &QDeclarativeMapLineProperties::colorChanged, this, [this](const QColor &color){ + static_cast<QMapCircleObjectPrivate*>(d_ptr.data())->setBorderColor(color); + }); + connect(m_border, &QDeclarativeMapLineProperties::widthChanged, this, [this](qreal width){ + static_cast<QMapCircleObjectPrivate*>(d_ptr.data())->setBorderWidth(width); + }); + } + return m_border; +} + +void QMapCircleObject::setCenter(const QGeoCoordinate ¢er) +{ + auto ptr = static_cast<QMapCircleObjectPrivate*>(d_ptr.data()); + if (ptr->center() == center) + return; + + ptr->setCenter(center); + emit centerChanged(); +} + +void QMapCircleObject::setRadius(qreal radius) +{ + auto d = static_cast<QMapCircleObjectPrivate*>(d_ptr.data()); + if (d->radius() == radius) + return; + + d->setRadius(radius); + emit radiusChanged(); +} + +void QMapCircleObject::setColor(const QColor &color) +{ + auto d = static_cast<QMapCircleObjectPrivate*>(d_ptr.data()); + if (d->color() == color) + return; + + d->setColor(color); + emit colorChanged(); +} + +void QMapCircleObject::setMap(QGeoMap *map) +{ + QMapCircleObjectPrivate *d = static_cast<QMapCircleObjectPrivate *>(d_ptr.data()); + if (d->m_map == map) + return; + + QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected + + if (!map) { + // Map was set, now it has ben re-set to NULL + d_ptr = new QMapCircleObjectPrivateDefault(*d); + // Old pimpl deleted implicitly by QExplicitlySharedDataPointer + } +} + +QT_END_NAMESPACE diff --git a/src/location/labs/qmapcircleobject_p.h b/src/location/labs/qmapcircleobject_p.h new file mode 100644 index 00000000..9393047e --- /dev/null +++ b/src/location/labs/qmapcircleobject_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QMAPCIRCLEOBJECT_P_H +#define QMAPCIRCLEOBJECT_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p.h> +#include <QtLocation/private/qdeclarativepolylinemapitem_p.h> +#include <QtCore/QUrl> +#include <QGeoCoordinate> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapCircleObject : public QGeoMapObject +{ + Q_OBJECT + Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QDeclarativeMapLineProperties *border READ border CONSTANT) + +public: + QMapCircleObject(QObject *parent = nullptr); + ~QMapCircleObject() override; + + QGeoCoordinate center() const; + qreal radius() const; + QColor color() const; + + void setCenter(const QGeoCoordinate ¢er); + void setRadius(qreal radius); + void setColor(const QColor &color); + + QDeclarativeMapLineProperties * border(); + void setMap(QGeoMap *map) override; + +signals: + void centerChanged(); + void radiusChanged(); + void colorChanged(); + +protected: + QDeclarativeMapLineProperties *m_border = nullptr; +}; + +QT_END_NAMESPACE + +#endif // QMAPCIRCLEOBJECT_P_H diff --git a/src/location/labs/qmapcircleobject_p_p.h b/src/location/labs/qmapcircleobject_p_p.h new file mode 100644 index 00000000..b3353b62 --- /dev/null +++ b/src/location/labs/qmapcircleobject_p_p.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QMAPCIRCLEOBJECT_P_P_H +#define QMAPCIRCLEOBJECT_P_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p_p.h> +#include <QGeoCoordinate> +#include <QColor> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapCircleObjectPrivate : public QGeoMapObjectPrivate +{ +public: + QMapCircleObjectPrivate(QGeoMapObject *q); + ~QMapCircleObjectPrivate() override; + + virtual QGeoMapObject::Type type() const override final; + + virtual QGeoCoordinate center() const = 0; + virtual void setCenter(const QGeoCoordinate ¢er) = 0; + virtual qreal radius() const = 0; + virtual void setRadius(qreal radius) = 0; + virtual QColor color() const = 0; + virtual void setColor(const QColor &color) = 0; + virtual QColor borderColor() const = 0; + virtual void setBorderColor(const QColor &color) = 0; + virtual qreal borderWidth() const = 0; + virtual void setBorderWidth(qreal width) = 0; + + // QGeoMapObjectPrivate interface + bool equals(const QGeoMapObjectPrivate &other) const override; +}; + + +class Q_LOCATION_PRIVATE_EXPORT QMapCircleObjectPrivateDefault : public QMapCircleObjectPrivate +{ +public: + QMapCircleObjectPrivateDefault(QGeoMapObject *q); + QMapCircleObjectPrivateDefault(const QMapCircleObjectPrivate &other); + ~QMapCircleObjectPrivateDefault() override; + + // QMapCircleObjectPrivate interface + QGeoCoordinate center() const override; + void setCenter(const QGeoCoordinate ¢er) override; + qreal radius() const override; + void setRadius(qreal radius) override; + QColor color() const override; + void setColor(const QColor &color) override; + QColor borderColor() const override; + void setBorderColor(const QColor &color) override; + qreal borderWidth() const override; + void setBorderWidth(qreal width) override; + + // QGeoMapObjectPrivate interface + QGeoMapObjectPrivate *clone() override; + +public: + QGeoCoordinate m_center; + qreal m_radius = 0; + QColor m_fillColor = Qt::transparent; + QColor m_borderColor; + qreal m_borderWidth = 1.0; + +private: + QMapCircleObjectPrivateDefault(const QMapCircleObjectPrivateDefault &other) = delete; +}; + +QT_END_NAMESPACE + +#endif // QMAPCIRCLEOBJECT_P_P_H diff --git a/src/location/labs/qmapiconobject.cpp b/src/location/labs/qmapiconobject.cpp new file mode 100644 index 00000000..7a3a1a75 --- /dev/null +++ b/src/location/labs/qmapiconobject.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** 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 "qmapiconobject_p.h" +#include "qmapiconobject_p_p.h" +#include <QExplicitlySharedDataPointer> + +QT_BEGIN_NAMESPACE + +QMapIconObjectPrivate::~QMapIconObjectPrivate() +{ + +} + +QMapIconObjectPrivate::QMapIconObjectPrivate(QGeoMapObject *q) : QGeoMapObjectPrivate(q) +{ + +} + +QGeoMapObject::Type QMapIconObjectPrivate::type() const +{ + return QGeoMapObject::IconType; +} + +bool QMapIconObjectPrivate::equals(const QGeoMapObjectPrivate &other) const +{ + if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used + return false; + + const QMapIconObjectPrivate &o = static_cast<const QMapIconObjectPrivate &>(other); + return (QGeoMapObjectPrivate::equals(o) + && content() == o.content() + && coordinate() == o.coordinate()); +} + +// +// QGeoMapIconPrivate default implementation +// + +QMapIconObjectPrivateDefault::QMapIconObjectPrivateDefault(QGeoMapObject *q) : QMapIconObjectPrivate(q) +{ + +} +QMapIconObjectPrivateDefault::QMapIconObjectPrivateDefault(const QMapIconObjectPrivate &other) : QMapIconObjectPrivate(other.q) +{ + m_coordinate = other.coordinate(); + m_content = other.content(); + m_size = other.size(); +} + +QMapIconObjectPrivateDefault::~QMapIconObjectPrivateDefault() +{ + +} + +QGeoCoordinate QMapIconObjectPrivateDefault::coordinate() const +{ + return m_coordinate; +} + +void QMapIconObjectPrivateDefault::setCoordinate(const QGeoCoordinate ¢er) +{ + m_coordinate = center; +} + +QVariant QMapIconObjectPrivateDefault::content() const +{ + return m_content; +} + +void QMapIconObjectPrivateDefault::setContent(const QVariant &content) +{ + m_content = content; +} + +QSizeF QMapIconObjectPrivateDefault::size() const +{ + return m_size; +} + +void QMapIconObjectPrivateDefault::setSize(const QSizeF &size) +{ + m_size = size; +} + +QGeoMapObjectPrivate *QMapIconObjectPrivateDefault::clone() +{ + return new QMapIconObjectPrivateDefault(static_cast<QMapIconObjectPrivate &>(*this)); +} + + +/* + + QGeoMapIconPrivate default implementation + +*/ + + +QMapIconObject::QMapIconObject(QObject *parent) + : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapIconObjectPrivateDefault(this)), parent) +{} + +QMapIconObject::~QMapIconObject() +{ + +} + +QVariant QMapIconObject::content() const +{ + const QMapIconObjectPrivate *d = static_cast<const QMapIconObjectPrivate *>(d_ptr.data()); + return d->content(); +} + +QGeoCoordinate QMapIconObject::coordinate() const +{ + const QMapIconObjectPrivate *d = static_cast<const QMapIconObjectPrivate *>(d_ptr.data()); + return d->coordinate(); +} + +void QMapIconObject::setContent(QVariant content) +{ + QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate *>(d_ptr.data()); + if (d->content() == content) + return; + + d->setContent(content); + emit contentChanged(content); +} + +void QMapIconObject::setCoordinate(const QGeoCoordinate ¢er) +{ + QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate*>(d_ptr.data()); + if (d->coordinate() == center) + return; + + d->setCoordinate(center); + emit coordinateChanged(center); +} + +QSizeF QMapIconObject::size() const +{ + const QMapIconObjectPrivate *d = static_cast<const QMapIconObjectPrivate *>(d_ptr.data()); + return d->size(); +} + + +void QMapIconObject::setSize(const QSizeF &size) +{ + QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate*>(d_ptr.data()); + if (d->size() == size) + return; + + d->setSize(size); + emit sizeChanged(); +} + +void QMapIconObject::setMap(QGeoMap *map) +{ + QMapIconObjectPrivate *d = static_cast<QMapIconObjectPrivate *>(d_ptr.data()); + if (d->m_map == map) + return; + + QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected + + if (!map) { + // Map was set, now it has ben re-set to NULL + d_ptr = new QMapIconObjectPrivateDefault(*d); + // Old pimpl deleted implicitly by QExplicitlySharedDataPointer + } +} + +QT_END_NAMESPACE diff --git a/src/location/labs/qmapiconobject_p.h b/src/location/labs/qmapiconobject_p.h new file mode 100644 index 00000000..16b00d04 --- /dev/null +++ b/src/location/labs/qmapiconobject_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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$ +** +****************************************************************************/ + +#ifndef QGEOMAPICON_P_H +#define QGEOMAPICON_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p.h> +#include <QtCore/QUrl> +#include <QGeoCoordinate> +#include <QtCore/qsize.h> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapIconObject : public QGeoMapObject +{ + Q_OBJECT + Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) + Q_PROPERTY(QVariant content READ content WRITE setContent NOTIFY contentChanged) + Q_PROPERTY(QSizeF size READ size WRITE setSize NOTIFY sizeChanged) + +public: + QMapIconObject(QObject *parent = nullptr); + ~QMapIconObject() override; + + QVariant content() const; + QGeoCoordinate coordinate() const; + QSizeF size() const; + + void setContent(QVariant content); + void setCoordinate(const QGeoCoordinate &coordinate); + void setSize(const QSizeF &size); + + void setMap(QGeoMap *map) override; + +signals: + void contentChanged(QVariant content); + void coordinateChanged(QGeoCoordinate coordinate); + void sizeChanged(); +}; + +QT_END_NAMESPACE + +#endif // QGEOMAPICON_P_H diff --git a/src/location/labs/qmapiconobject_p_p.h b/src/location/labs/qmapiconobject_p_p.h new file mode 100644 index 00000000..08a1a893 --- /dev/null +++ b/src/location/labs/qmapiconobject_p_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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$ +** +****************************************************************************/ + +#ifndef QGEOMAPICON_P_P_H +#define QGEOMAPICON_P_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p_p.h> +#include <QGeoCoordinate> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapIconObjectPrivate : public QGeoMapObjectPrivate +{ +public: + QMapIconObjectPrivate(QGeoMapObject *q); + ~QMapIconObjectPrivate() override; + + virtual QGeoMapObject::Type type() const override final; + + virtual QGeoCoordinate coordinate() const = 0; + virtual void setCoordinate(const QGeoCoordinate &coordinate) = 0; + virtual QVariant content() const = 0; + virtual void setContent(const QVariant &content) = 0; + virtual QSizeF size() const = 0; + virtual void setSize(const QSizeF &size) = 0; + + // QGeoMapObjectPrivate interface + bool equals(const QGeoMapObjectPrivate &other) const override; +}; + +class Q_LOCATION_PRIVATE_EXPORT QMapIconObjectPrivateDefault : public QMapIconObjectPrivate +{ +public: + QMapIconObjectPrivateDefault(QGeoMapObject *q); + QMapIconObjectPrivateDefault(const QMapIconObjectPrivate &other); + ~QMapIconObjectPrivateDefault() override; + + // QGeoMapIconPrivate interface + QGeoCoordinate coordinate() const override; + void setCoordinate(const QGeoCoordinate &coordinate) override; + QVariant content() const override; + void setContent(const QVariant &content) override; + virtual QSizeF size() const override; + virtual void setSize(const QSizeF &size) override; + + // QMapIconObjectPrivate interface + QGeoMapObjectPrivate *clone() override; + +public: + QVariant m_content; + QGeoCoordinate m_coordinate; + QSizeF m_size; + +private: + QMapIconObjectPrivateDefault(const QMapIconObjectPrivateDefault &other) = delete; +}; + +QT_END_NAMESPACE + +#endif // QGEOMAPICON_P_P_H diff --git a/src/location/labs/qmapobjectview.cpp b/src/location/labs/qmapobjectview.cpp new file mode 100644 index 00000000..310775a1 --- /dev/null +++ b/src/location/labs/qmapobjectview.cpp @@ -0,0 +1,355 @@ +/**************************************************************************** +** +** 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 "qmapobjectview_p.h" +#include "qmapobjectview_p_p.h" +#include <QtQml/private/qqmldelegatemodel_p.h> +#include <QtLocation/private/qgeomap_p.h> + +QT_BEGIN_NAMESPACE + +/* + + QGeoMapLayerPrivate + +*/ + +static const QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::Asynchronous; + +QMapObjectViewPrivate::QMapObjectViewPrivate(QGeoMapObject *q) + : QGeoMapObjectPrivate(q) +{ +} + +QMapObjectViewPrivate::~QMapObjectViewPrivate() +{ + +} + +QGeoMapObject::Type QMapObjectViewPrivate::type() const +{ + return QGeoMapObject::ViewType; +} + + +/* + + QGeoMapLayerPrivateDefault + +*/ + + +QMapObjectViewPrivateDefault::QMapObjectViewPrivateDefault(const QMapObjectViewPrivate &other) : QMapObjectViewPrivate(other.q) +{ +} + +QMapObjectViewPrivateDefault::~QMapObjectViewPrivateDefault() +{ + +} + +QMapObjectViewPrivateDefault::QMapObjectViewPrivateDefault(QGeoMapObject *q) : QMapObjectViewPrivate(q) +{ + +} + +QGeoMapObjectPrivate *QMapObjectViewPrivateDefault::clone() +{ + return new QMapObjectViewPrivateDefault(*this); +} + +/* + + QMapObjectView + +*/ + + +QMapObjectView::QMapObjectView(QObject *parent) + : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapObjectViewPrivateDefault(this)), parent) +{ + +} + +QMapObjectView::~QMapObjectView() +{ + flushDelegateModel(); + flushUserAddedMapObjects(); +} + +QList<QGeoMapObject *> QMapObjectView::geoMapObjectChildren() const +{ + auto kids = QGeoMapObject::geoMapObjectChildren(); + auto size = m_instantiatedMapObjects.count(); + for (int i = 0; i < size; ++i) { + auto obj = qobject_cast<QGeoMapObject*>(m_instantiatedMapObjects[i]); + if (obj) + kids << obj; + } + for (int i = 0; i < m_userAddedMapObjects.size(); ++i) { + auto obj = m_userAddedMapObjects.at(i); + if (obj) + kids << obj; + } + return kids; +} + +void QMapObjectView::setMap(QGeoMap *map) +{ + QMapObjectViewPrivate *d = static_cast<QMapObjectViewPrivate *>(d_ptr.data()); + if (d->m_map == map) + return; + + QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected + + for (int i = 0; i < m_userAddedMapObjects.size(); ++i) { + auto obj = m_userAddedMapObjects.at(i); + if (obj && obj->map() != map) + obj->setMap(map); + } + + if (!map) { + // Map was set, now it has ben re-set to NULL + flushDelegateModel(); + flushUserAddedMapObjects(); + d_ptr = new QMapObjectViewPrivateDefault(*d); + } else if (d->m_componentCompleted) { + // Map was null, now it's set AND delegateModel is already complete. + // some delegates may have been incubated but not added to the map. + for (int i = 0; i < m_pendingMapObjects.size(); ++i) { + auto obj = m_pendingMapObjects.at(i); + if (obj && obj->map() != map) + obj->setMap(map); + } + m_pendingMapObjects.clear(); + } +} + +void QMapObjectView::classBegin() +{ + QQmlContext *ctx = qmlContext(this); + m_delegateModel = new QQmlDelegateModel(ctx, this); + m_delegateModel->classBegin(); + + QQmlInstanceModel *model = m_delegateModel; + connect(model, &QQmlInstanceModel::modelUpdated, this, &QMapObjectView::modelUpdated); + connect(model, &QQmlInstanceModel::createdItem, this, &QMapObjectView::createdItem); + connect(model, &QQmlInstanceModel::destroyingItem, this, &QMapObjectView::destroyingItem); + connect(model, &QQmlInstanceModel::initItem, this, &QMapObjectView::initItem); +} + +void QMapObjectView::componentComplete() +{ + QGeoMapObject::componentComplete(); + if (m_delegate) + m_delegateModel->setDelegate(m_delegate); + if (m_model.isValid()) + m_delegateModel->setModel(m_model); + m_delegateModel->componentComplete(); +} + +QVariant QMapObjectView::model() const +{ + return m_model; +} + +QQmlComponent *QMapObjectView::delegate() const +{ + return m_delegate; +} + +void QMapObjectView::setModel(QVariant model) +{ + if (m_model == model) + return; + m_model = model; + + if (d_ptr->m_componentCompleted) + m_delegateModel->setModel(model); + + emit modelChanged(model); +} + +void QMapObjectView::setDelegate(QQmlComponent *delegate) +{ + if (m_delegate == delegate) + return; + m_delegate = delegate; + + if (d_ptr->m_componentCompleted) + m_delegateModel->setDelegate(delegate); + + emit delegateChanged(delegate); +} + +/*! + \qmlmethod void Qt.labs.location::MapObjectView::addMapObject(MapObject object) + + Adds the given \a object to the MapObjectView (for example MapIconObject, MapRouteObject), and, + indirectly, to the underlying map. If the object already is on the MapObjectView, it will not be added again. + + \sa removeMapObject +*/ +void QMapObjectView::addMapObject(QGeoMapObject *object) +{ + if (m_userAddedMapObjects.indexOf(object) < 0) + m_userAddedMapObjects.append(object); + if (map() && object->map() != map()) + object->setMap(map()); +} + +/*! + \qmlmethod void Qt.labs.location::MapObjectView::removeMapObject(MapObject object) + + Removes the given \a object from the MapObjectView (for example MapIconObject, MapRouteObject), and, + indirectly, from the underlying map. + + \sa addMapObject +*/ +void QMapObjectView::removeMapObject(QGeoMapObject *object) +{ + int idx = m_userAddedMapObjects.indexOf(object); + if ( idx >= 0) { + object->setMap(nullptr); + m_userAddedMapObjects.remove(idx); + } +} + +void QMapObjectView::destroyingItem(QObject * /*object*/) +{ + +} + +void QMapObjectView::initItem(int /*index*/, QObject * /*object*/) +{ + +} + +void QMapObjectView::modelUpdated(const QQmlChangeSet &changeSet, bool reset) +{ + // move changes are expressed as one remove + one insert, with the same moveId. + // For simplicity, they will be treated as remove + insert. + // Changes will be also ignored, as they represent only data changes, not layout changes + if (reset) { // Assuming this means "remove everything already instantiated" + flushDelegateModel(); + } else { + // Remove map objects from the back to the front to retain the mapping to what is received from the changesets + const QVector<QQmlChangeSet::Change> &removes = changeSet.removes(); + std::map<int, int> mapRemoves; + for (int i = 0; i < removes.size(); i++) + mapRemoves.insert(std::pair<int, int>(removes.at(i).start(), i)); + + for (auto rit = mapRemoves.rbegin(); rit != mapRemoves.rend(); ++rit) { + const QQmlChangeSet::Change &c = removes.at(rit->second); + for (int idx = c.end() - 1; idx >= c.start(); --idx) + removeMapObjectFromMap(idx); + } + } + + for (const QQmlChangeSet::Change &c: changeSet.inserts()) { + for (int idx = c.start(); idx < c.end(); idx++) { + m_instantiatedMapObjects.insert(idx, nullptr); + QGeoMapObject *mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(idx, incubationMode)); + if (mo) // if not, a createdItem signal will be emitted. + addMapObjectToMap(mo, idx); + } + } +} + +void QMapObjectView::addMapObjectToMap(QGeoMapObject *object, int index) +{ + if (!object) + return; + + m_instantiatedMapObjects[index] = object; + if (map()) + object->setMap(map()); + else + m_pendingMapObjects << object; + + // ToDo: + // Figure out the proper way to replace "mo->setVisible(visible());". Options: + // - simply leave it to the user to set up a property binding + // - set up a property binding automatically + // - add a viewVisibility member to QGeoMapObject that gets combined at all times, + // and a connection for it. +} + +void QMapObjectView::removeMapObjectFromMap(int index) +{ + if (index >= 0 && index < m_instantiatedMapObjects.size()) { + QGeoMapObject *mo = m_instantiatedMapObjects.takeAt(index); + if (!mo) + return; + mo->setMap(nullptr); + m_delegateModel->release(mo); + } +} + +// See QObject *QQmlDelegateModel::object(int index, QQmlIncubator::IncubationMode incubationMode) doc +// for explanation on when createdItem is emitted. +void QMapObjectView::createdItem(int index, QObject * /*object*/) +{ + if (m_instantiatedMapObjects.at(index)) + return; // The first call to object() apparently returned a valid item. Don't call it again. + + // If here, according to the documentation above, object() should be called again for index, + // or else, it will be destroyed exiting this scope + QGeoMapObject *mo = nullptr; + mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(index, incubationMode)); + if (mo) + addMapObjectToMap(mo, index); +} + + +void QMapObjectView::flushDelegateModel() +{ + // Backward as removeItemFromMap modifies m_instantiatedItems + for (int i = m_instantiatedMapObjects.size() -1; i >= 0 ; i--) + removeMapObjectFromMap(i); +} + +void QMapObjectView::flushUserAddedMapObjects() +{ + for (int i = 0; i < m_userAddedMapObjects.size(); ++i) { + auto obj = m_userAddedMapObjects.at(i); + if (obj) + obj->setMap(nullptr); // obj parent might not be this. If so, it would not be destroyed by destroying this view. + } +} + +QT_END_NAMESPACE + diff --git a/src/location/labs/qmapobjectview_p.h b/src/location/labs/qmapobjectview_p.h new file mode 100644 index 00000000..49b80883 --- /dev/null +++ b/src/location/labs/qmapobjectview_p.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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$ +** +****************************************************************************/ + +#ifndef QMAPOBJECTVIEW_P_H +#define QMAPOBJECTVIEW_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p.h> +#include <QQmlComponent> +#include <QVector> + +QT_BEGIN_NAMESPACE + +class QQmlDelegateModel; +class QMapObjectViewPrivate; +class QQmlChangeSet; +class Q_LOCATION_PRIVATE_EXPORT QMapObjectView : public QGeoMapObject +{ + Q_OBJECT + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) + Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) + Q_INTERFACES(QQmlParserStatus) +public: + QMapObjectView(QObject *parent = nullptr); + ~QMapObjectView() override; + + // QGeoMapObject interface + QList<QGeoMapObject *> geoMapObjectChildren() const override; + void setMap(QGeoMap *map) override; + + // QQmlParserStatus interface + void classBegin() override; + void componentComplete() override; + + QVariant model() const; + void setModel(QVariant model); + + QQmlComponent *delegate() const; + void setDelegate(QQmlComponent * delegate); + +public Q_SLOTS: + // The dynamic API that matches Map.add/remove MapItem + void addMapObject(QGeoMapObject *object); + void removeMapObject(QGeoMapObject *object); + +signals: + void modelChanged(QVariant model); + void delegateChanged(QQmlComponent * delegate); + +protected Q_SLOTS: + void destroyingItem(QObject *object); + void initItem(int index, QObject *object); + void createdItem(int index, QObject *object); + void modelUpdated(const QQmlChangeSet &changeSet, bool reset); + +protected: + void addMapObjectToMap(QGeoMapObject *object, int index); + void removeMapObjectFromMap(int index); + void flushDelegateModel(); + void flushUserAddedMapObjects(); + + QVariant m_model; + QQmlComponent *m_delegate = nullptr; + QQmlDelegateModel *m_delegateModel = nullptr; + QVector<QPointer<QGeoMapObject>> m_instantiatedMapObjects; + QVector<QPointer<QGeoMapObject>> m_pendingMapObjects; + QVector<QPointer<QGeoMapObject>> m_userAddedMapObjects; // A third list containing the objects dynamically added through addMapObject +}; + +QT_END_NAMESPACE + +#endif // QMAPOBJECTVIEW_P_H diff --git a/src/location/labs/qmapobjectview_p_p.h b/src/location/labs/qmapobjectview_p_p.h new file mode 100644 index 00000000..7550e209 --- /dev/null +++ b/src/location/labs/qmapobjectview_p_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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$ +** +****************************************************************************/ + +#ifndef QMAPOBJECTVIEW_P_P_H +#define QMAPOBJECTVIEW_P_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p_p.h> +#include <QPointer> +#include <QVector> +#include <QQmlComponent> + +QT_BEGIN_NAMESPACE + +class QQmlDelegateModel; +class QGeoMap; +class Q_LOCATION_PRIVATE_EXPORT QMapObjectViewPrivate : public QGeoMapObjectPrivate +{ +public: + QMapObjectViewPrivate(QGeoMapObject *q); + ~QMapObjectViewPrivate() override; + + virtual QGeoMapObject::Type type() const override final; +}; + +class Q_LOCATION_PRIVATE_EXPORT QMapObjectViewPrivateDefault : public QMapObjectViewPrivate +{ +public: + QMapObjectViewPrivateDefault(QGeoMapObject *q); + QMapObjectViewPrivateDefault(const QMapObjectViewPrivate &other); + ~QMapObjectViewPrivateDefault() override; + + + // QGeoMapObjectPrivate interface +public: + QGeoMapObjectPrivate *clone() override; +}; + +QT_END_NAMESPACE + +#endif // QMAPOBJECTVIEW_P_P_H diff --git a/src/location/labs/qmappolygonobject.cpp b/src/location/labs/qmappolygonobject.cpp new file mode 100644 index 00000000..fd4c660a --- /dev/null +++ b/src/location/labs/qmappolygonobject.cpp @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 "qmappolygonobject_p.h" +#include "qmappolygonobject_p_p.h" +#include <QtLocation/private/locationvaluetypehelper_p.h> + +QT_BEGIN_NAMESPACE + +QMapPolygonObjectPrivate::QMapPolygonObjectPrivate(QGeoMapObject *q) : QGeoMapObjectPrivate(q) +{ + +} + +QMapPolygonObjectPrivate::~QMapPolygonObjectPrivate() +{ + +} + +QMapPolygonObjectPrivateDefault::QMapPolygonObjectPrivateDefault(QGeoMapObject *q) : QMapPolygonObjectPrivate(q) +{ + +} + +QMapPolygonObjectPrivateDefault::QMapPolygonObjectPrivateDefault(const QMapPolygonObjectPrivate &other) : QMapPolygonObjectPrivate(other.q) +{ + m_path = other.path(); + m_borderColor = other.borderColor(); + m_fillColor = other.fillColor(); + m_borderWidth = other.borderWidth(); +} + +QMapPolygonObjectPrivateDefault::~QMapPolygonObjectPrivateDefault() +{ + +} + +QGeoMapObject::Type QMapPolygonObjectPrivate::type() const +{ + return QGeoMapObject::PolygonType; +} + +QList<QGeoCoordinate> QMapPolygonObjectPrivateDefault::path() const +{ + return m_path; +} + +void QMapPolygonObjectPrivateDefault::setPath(const QList<QGeoCoordinate> &path) +{ + m_path = path; +} + +QColor QMapPolygonObjectPrivateDefault::fillColor() const +{ + return m_fillColor; +} + +void QMapPolygonObjectPrivateDefault::setFillColor(const QColor &color) +{ + m_fillColor = color; +} + +QColor QMapPolygonObjectPrivateDefault::borderColor() const +{ + return m_borderColor; +} + +void QMapPolygonObjectPrivateDefault::setBorderColor(const QColor &color) +{ + m_borderColor = color; +} + +qreal QMapPolygonObjectPrivateDefault::borderWidth() const +{ + return m_borderWidth; +} + +void QMapPolygonObjectPrivateDefault::setBorderWidth(qreal width) +{ + m_borderWidth = width; +} + +QGeoMapObjectPrivate *QMapPolygonObjectPrivateDefault::clone() +{ + return new QMapPolygonObjectPrivateDefault(static_cast<QMapPolygonObjectPrivate &>(*this)); +} + +bool QMapPolygonObjectPrivate::equals(const QGeoMapObjectPrivate &other) const +{ + if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used + return false; + + const QMapPolygonObjectPrivate &o = static_cast<const QMapPolygonObjectPrivate &>(other); + return (QGeoMapObjectPrivate::equals(o) + && path() == o.path() + && borderColor() == o.borderColor() + && fillColor() == o.fillColor() + && borderWidth() == o.borderWidth()); +} + + + + +QMapPolygonObject::QMapPolygonObject(QObject *parent) + : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapPolygonObjectPrivateDefault(this)), parent) +{ + QMapPolygonObjectPrivate *d = static_cast<QMapPolygonObjectPrivate*>(d_ptr.data()); + d->setBorderColor(QColor(Qt::black)); // These are QDeclarativeMapLineProperties defaults + d->setBorderWidth(1.0); +} + +QMapPolygonObject::~QMapPolygonObject() +{} + +QVariantList QMapPolygonObject::path() const +{ + QVariantList p; + for (const QGeoCoordinate &c: static_cast<const QMapPolygonObjectPrivate *>(d_ptr.data())->path()) + p << QVariant::fromValue(c); + return p; +} + +void QMapPolygonObject::setPath(const QVariantList &path) +{ + QList<QGeoCoordinate> p; + bool ok = false; + for (const auto &c: path) { + const QGeoCoordinate coord = parseCoordinate(c, &ok); + if (ok) + p << coord; + } + auto pimpl = static_cast<QMapPolygonObjectPrivate *>(d_ptr.data()); + if (p != pimpl->path()) { + pimpl->setPath(p); + emit pathChanged(); + } +} + +QColor QMapPolygonObject::color() const +{ + return static_cast<const QMapPolygonObjectPrivate*>(d_ptr.data())->fillColor(); +} + +QDeclarativeMapLineProperties *QMapPolygonObject::border() +{ + if (!m_border) { + m_border = new QDeclarativeMapLineProperties; + connect(m_border, &QDeclarativeMapLineProperties::colorChanged, this, [this](const QColor &color){ + static_cast<QMapPolygonObjectPrivate*>(d_ptr.data())->setBorderColor(color); + }); + connect(m_border, &QDeclarativeMapLineProperties::widthChanged, this, [this](qreal width){ + static_cast<QMapPolygonObjectPrivate*>(d_ptr.data())->setBorderWidth(width); + }); + } + return m_border; +} + +void QMapPolygonObject::setColor(const QColor &fillColor) +{ + auto ptr = static_cast<QMapPolygonObjectPrivate*>(d_ptr.data()); + + if (ptr->fillColor() == fillColor) + return; + + ptr->setFillColor(fillColor); + emit colorChanged(); +} + +void QMapPolygonObject::setMap(QGeoMap *map) +{ + QMapPolygonObjectPrivate *d = static_cast<QMapPolygonObjectPrivate *>(d_ptr.data()); + if (d->m_map == map) + return; + + QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected + + if (!map) { + // Map was set, now it has ben re-set to NULL + d_ptr = new QMapPolygonObjectPrivateDefault(*d); + // Old pimpl deleted implicitly by QExplicitlySharedDataPointer + } +} + +QT_END_NAMESPACE diff --git a/src/location/labs/qmappolygonobject_p.h b/src/location/labs/qmappolygonobject_p.h new file mode 100644 index 00000000..03eef587 --- /dev/null +++ b/src/location/labs/qmappolygonobject_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QMAPPOLYGONOBJECT_P_H +#define QMAPPOLYGONOBJECT_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p.h> +#include <QtLocation/private/qdeclarativepolylinemapitem_p.h> + +#include <QJSValue> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapPolygonObject : public QGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QVariantList path READ path WRITE setPath NOTIFY pathChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QDeclarativeMapLineProperties *border READ border CONSTANT) + +public: + QMapPolygonObject(QObject *parent = nullptr); + ~QMapPolygonObject() override; + + QVariantList path() const; + void setPath(const QVariantList &path); + + QColor color() const; + void setColor(const QColor &color); + + QDeclarativeMapLineProperties *border(); + void setMap(QGeoMap *map) override; + +signals: + void pathChanged(); + void colorChanged(); + +protected: + QDeclarativeMapLineProperties *m_border; +}; + +QT_END_NAMESPACE + +#endif // QMAPPOLYGONOBJECT_P_H diff --git a/src/location/labs/qmappolygonobject_p_p.h b/src/location/labs/qmappolygonobject_p_p.h new file mode 100644 index 00000000..d7e95d49 --- /dev/null +++ b/src/location/labs/qmappolygonobject_p_p.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QMAPPOLYGONOBJECT_P_P_H +#define QMAPPOLYGONOBJECT_P_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p_p.h> +#include <QGeoCoordinate> +#include <QColor> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapPolygonObjectPrivate : public QGeoMapObjectPrivate +{ +public: + QMapPolygonObjectPrivate(QGeoMapObject *q); + ~QMapPolygonObjectPrivate() override; + + virtual QGeoMapObject::Type type() const override final; + + virtual QList<QGeoCoordinate> path() const = 0; + virtual void setPath(const QList<QGeoCoordinate> &path) = 0; + virtual QColor fillColor() const = 0; + virtual void setFillColor(const QColor &color) = 0; + virtual QColor borderColor() const = 0; + virtual void setBorderColor(const QColor &color) = 0; + virtual qreal borderWidth() const = 0; + virtual void setBorderWidth(qreal width) = 0; + + // QGeoMapObjectPrivate interface + bool equals(const QGeoMapObjectPrivate &other) const override; +}; + +class Q_LOCATION_PRIVATE_EXPORT QMapPolygonObjectPrivateDefault : public QMapPolygonObjectPrivate +{ +public: + QMapPolygonObjectPrivateDefault(QGeoMapObject *q); + QMapPolygonObjectPrivateDefault(const QMapPolygonObjectPrivate &other); + ~QMapPolygonObjectPrivateDefault() override; + + // QMapPolygonObjectPrivate interface + QList<QGeoCoordinate> path() const override; + void setPath(const QList<QGeoCoordinate> &path) override; + QColor fillColor() const override; + void setFillColor(const QColor &color) override; + QColor borderColor() const override; + void setBorderColor(const QColor &color) override; + qreal borderWidth() const override; + void setBorderWidth(qreal width) override; + + // QGeoMapObjectPrivate interface + QGeoMapObjectPrivate *clone() override; + +public: + QList<QGeoCoordinate> m_path; + QColor m_borderColor; + QColor m_fillColor = Qt::transparent; + qreal m_borderWidth = 0; + +private: + QMapPolygonObjectPrivateDefault(const QMapPolygonObjectPrivateDefault &other) = delete; +}; + +QT_END_NAMESPACE + + +#endif // QMAPPOLYGONOBJECT_P_P_H diff --git a/src/location/labs/qmappolylineobject.cpp b/src/location/labs/qmappolylineobject.cpp new file mode 100644 index 00000000..1e625c1f --- /dev/null +++ b/src/location/labs/qmappolylineobject.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 "qmappolylineobject_p.h" +#include "qmappolylineobject_p_p.h" +#include <QtLocation/private/locationvaluetypehelper_p.h> + +QT_BEGIN_NAMESPACE + +QMapPolylineObjectPrivate::QMapPolylineObjectPrivate(QGeoMapObject *q) : QGeoMapObjectPrivate(q) +{ + +} + +QMapPolylineObjectPrivate::~QMapPolylineObjectPrivate() +{ + +} + +QGeoMapObject::Type QMapPolylineObjectPrivate::type() const +{ + return QGeoMapObject::PolylineType; +} + +QMapPolylineObjectPrivateDefault::QMapPolylineObjectPrivateDefault(QGeoMapObject *q) : QMapPolylineObjectPrivate(q) +{ + +} + +QMapPolylineObjectPrivateDefault::QMapPolylineObjectPrivateDefault(const QMapPolylineObjectPrivate &other) : QMapPolylineObjectPrivate(other.q) +{ + m_path = other.path(); + m_color = other.color(); + m_width = other.width(); +} + +QMapPolylineObjectPrivateDefault::~QMapPolylineObjectPrivateDefault() +{ + +} + +QList<QGeoCoordinate> QMapPolylineObjectPrivateDefault::path() const +{ + return m_path; +} + +void QMapPolylineObjectPrivateDefault::setPath(const QList<QGeoCoordinate> &path) +{ + m_path = path; +} + +QColor QMapPolylineObjectPrivateDefault::color() const +{ + return m_color; +} + +void QMapPolylineObjectPrivateDefault::setColor(const QColor &color) +{ + m_color = color; +} + +qreal QMapPolylineObjectPrivateDefault::width() const +{ + return m_width; +} + +void QMapPolylineObjectPrivateDefault::setWidth(qreal width) +{ + m_width = width; +} + +bool QMapPolylineObjectPrivate::equals(const QGeoMapObjectPrivate &other) const +{ + if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used + return false; + + const QMapPolylineObjectPrivate &o = static_cast<const QMapPolylineObjectPrivate &>(other); + return (QGeoMapObjectPrivate::equals(o) + && path() == o.path() + && color() == o.color() + && width() == o.width()); +} + +QGeoMapObjectPrivate *QMapPolylineObjectPrivateDefault::clone() +{ + return new QMapPolylineObjectPrivateDefault(static_cast<QMapPolylineObjectPrivate &>(*this)); +} + +QMapPolylineObject::QMapPolylineObject(QObject *parent) + : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapPolylineObjectPrivateDefault(this)), parent) +{ + QMapPolylineObjectPrivate *d = static_cast<QMapPolylineObjectPrivate*>(d_ptr.data()); + d->setColor(QColor(Qt::black)); // These are QDeclarativeMapLineProperties defaults + d->setWidth(1.0); +} + +QMapPolylineObject::~QMapPolylineObject() +{} + +QVariantList QMapPolylineObject::path() const +{ + QVariantList p; + for (const QGeoCoordinate &c: static_cast<const QMapPolylineObjectPrivate*>(d_ptr.data())->path()) + p << QVariant::fromValue(c); + return p; +} + +QDeclarativeMapLineProperties *QMapPolylineObject::border() +{ + if (!m_border) { + m_border = new QDeclarativeMapLineProperties; + connect(m_border, &QDeclarativeMapLineProperties::colorChanged, this, [this](const QColor &color){ + static_cast<QMapPolylineObjectPrivate*>(d_ptr.data())->setColor(color); + }); + connect(m_border, &QDeclarativeMapLineProperties::widthChanged, this, [this](qreal width){ + static_cast<QMapPolylineObjectPrivate*>(d_ptr.data())->setWidth(width); + }); + } + return m_border; +} + +void QMapPolylineObject::setPath(const QVariantList &path) +{ + QList<QGeoCoordinate> p; + bool ok = false; + for (const auto &c: path) { + const QGeoCoordinate coord = parseCoordinate(c, &ok); + if (ok) + p << coord; + } + auto pimpl = static_cast<QMapPolylineObjectPrivate *>(d_ptr.data()); + if (p != pimpl->path()) { + pimpl->setPath(p); + emit pathChanged(); + } +} + +void QMapPolylineObject::setMap(QGeoMap *map) +{ + QMapPolylineObjectPrivate *d = static_cast<QMapPolylineObjectPrivate *>(d_ptr.data()); + if (d->m_map == map) + return; + + QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected + + if (!map) { + // Map was set, now it has ben re-set to NULL + d_ptr = new QMapPolylineObjectPrivateDefault(*d); + // Old pimpl deleted implicitly by QExplicitlySharedDataPointer + } +} + +QT_END_NAMESPACE diff --git a/src/location/labs/qmappolylineobject_p.h b/src/location/labs/qmappolylineobject_p.h new file mode 100644 index 00000000..68312fb8 --- /dev/null +++ b/src/location/labs/qmappolylineobject_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QMAPPOLYLINEOBJECT_P_H +#define QMAPPOLYLINEOBJECT_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p.h> +#include <QtLocation/private/qdeclarativepolylinemapitem_p.h> + +#include <QJSValue> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapPolylineObject : public QGeoMapObject +{ + Q_OBJECT + + Q_PROPERTY(QVariantList path READ path WRITE setPath NOTIFY pathChanged) + Q_PROPERTY(QDeclarativeMapLineProperties *line READ border CONSTANT) + +public: + QMapPolylineObject(QObject *parent = nullptr); + ~QMapPolylineObject() override; + + QVariantList path() const; + void setPath(const QVariantList &path); + + QDeclarativeMapLineProperties *border(); + void setMap(QGeoMap *map) override; + +signals: + void pathChanged(); + +protected: + QDeclarativeMapLineProperties *m_border = nullptr; +}; + +QT_END_NAMESPACE + +#endif // QMAPPOLYLINEOBJECT_P_H diff --git a/src/location/labs/qmappolylineobject_p_p.h b/src/location/labs/qmappolylineobject_p_p.h new file mode 100644 index 00000000..1d5919d2 --- /dev/null +++ b/src/location/labs/qmappolylineobject_p_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QMAPPOLYLINEOBJECT_P_P_H +#define QMAPPOLYLINEOBJECT_P_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p_p.h> +#include <QGeoCoordinate> +#include <QColor> + +QT_BEGIN_NAMESPACE + +class Q_LOCATION_PRIVATE_EXPORT QMapPolylineObjectPrivate : public QGeoMapObjectPrivate +{ +public: + QMapPolylineObjectPrivate(QGeoMapObject *q); + ~QMapPolylineObjectPrivate() override; + + virtual QGeoMapObject::Type type() const override final; + + virtual QList<QGeoCoordinate> path() const = 0; + virtual void setPath(const QList<QGeoCoordinate> &path) = 0; + virtual QColor color() const = 0; + virtual void setColor(const QColor &color) = 0; + virtual qreal width() const = 0; + virtual void setWidth(qreal width) = 0; + + // QGeoMapObjectPrivate interface + bool equals(const QGeoMapObjectPrivate &other) const override; +}; + +class Q_LOCATION_PRIVATE_EXPORT QMapPolylineObjectPrivateDefault : public QMapPolylineObjectPrivate +{ +public: + QMapPolylineObjectPrivateDefault(QGeoMapObject *q); + QMapPolylineObjectPrivateDefault(const QMapPolylineObjectPrivate &other); + ~QMapPolylineObjectPrivateDefault() override; + + // QGeoMapPolylinePrivate interface + QList<QGeoCoordinate> path() const override; + void setPath(const QList<QGeoCoordinate> &path) override; + QColor color() const override; + void setColor(const QColor &color) override; + qreal width() const override; + void setWidth(qreal width) override; + + // QGeoMapObjectPrivate interface + QGeoMapObjectPrivate *clone() override; + +public: + QList<QGeoCoordinate> m_path; + QColor m_color; + qreal m_width = 0; + +private: + QMapPolylineObjectPrivateDefault(const QMapPolylineObjectPrivateDefault &other) = delete; +}; + +QT_END_NAMESPACE + + +#endif // QMAPPOLYLINEOBJECT_P_P_H diff --git a/src/location/labs/qmaprouteobject.cpp b/src/location/labs/qmaprouteobject.cpp new file mode 100644 index 00000000..724bdb73 --- /dev/null +++ b/src/location/labs/qmaprouteobject.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 <QtLocation/private/qdeclarativegeoroute_p.h> +#include "qmaprouteobject_p.h" +#include "qmaprouteobject_p_p.h" + +QT_BEGIN_NAMESPACE + +/* + + QGeoMapRoutePrivate + +*/ + +QMapRouteObjectPrivate::QMapRouteObjectPrivate(QGeoMapObject *q) : QGeoMapObjectPrivate(q) +{ + +} + +QMapRouteObjectPrivate::QMapRouteObjectPrivate(const QMapRouteObjectPrivate &other) : QGeoMapObjectPrivate(other) +{ + // QGeoMapRoutePrivate doesn't contain anything because QGeoRoute has already everything necessary. +} + +QMapRouteObjectPrivate::~QMapRouteObjectPrivate() +{ + +} + +QGeoMapObject::Type QMapRouteObjectPrivate::type() const +{ + return QGeoMapObject::RouteType; +} + +QDeclarativeGeoRoute *QMapRouteObjectPrivate::declarativeGeoRoute() const +{ + const QMapRouteObject *r = static_cast<QMapRouteObject *>(q); + return r->m_route; +} + +QGeoRoute QMapRouteObjectPrivate::route() const +{ + const QDeclarativeGeoRoute *r = declarativeGeoRoute(); + if (r) + return r->route(); + return {}; +} + +void QMapRouteObjectPrivate::setRoute(const QDeclarativeGeoRoute *route) +{ + Q_UNUSED(route) +} + +bool QMapRouteObjectPrivate::equals(const QGeoMapObjectPrivate &other) const +{ + if (other.type() != type()) // This check might be unnecessary, depending on how equals gets used + return false; + + const QMapRouteObjectPrivate &o = static_cast<const QMapRouteObjectPrivate &>(other); + return (QGeoMapObjectPrivate::equals(o) + && route() == o.route()); // Could also be done shallow, comparing declarativeGeoRoute() +} + +QGeoMapObjectPrivate *QMapRouteObjectPrivate::clone() +{ + return new QMapRouteObjectPrivate(*this); +} + + +/* + + QGeoMapRoute + +*/ + +QMapRouteObject::QMapRouteObject(QObject *parent) + : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapRouteObjectPrivate(this)), parent) +{ + +} + +QMapRouteObject::~QMapRouteObject() +{ + +} + +QDeclarativeGeoRoute *QMapRouteObject::route() const +{ + return m_route; +} + +QGeoRoute QMapRouteObject::geoRoute() const +{ + if (m_route) + return m_route->route(); + return {}; +} + +void QMapRouteObject::setRoute(QDeclarativeGeoRoute *route) +{ + if (route == m_route) + return; +// if ((!m_route && !route) || (m_route && route && m_route->route() == route->route())) +// return; + + m_route = route; + QMapRouteObjectPrivate *d = static_cast<QMapRouteObjectPrivate *>(d_ptr.data()); + d->setRoute(route); + emit routeChanged(route); +} + +void QMapRouteObject::setMap(QGeoMap *map) +{ + QMapRouteObjectPrivate *d = static_cast<QMapRouteObjectPrivate *>(d_ptr.data()); + if (d->m_map == map) + return; + + QGeoMapObject::setMap(map); // This is where the specialized pimpl gets created and injected + + if (!map) { + // Map was set, now it has ben re-set to NULL + d_ptr = new QMapRouteObjectPrivate(*d); + // Old pimpl deleted implicitly by QExplicitlySharedDataPointer + } +} + +QT_END_NAMESPACE diff --git a/src/location/labs/qmaprouteobject_p.h b/src/location/labs/qmaprouteobject_p.h new file mode 100644 index 00000000..dcc35807 --- /dev/null +++ b/src/location/labs/qmaprouteobject_p.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEMAPROUTEDELEGATE_P_H +#define QDECLARATIVEMAPROUTEDELEGATE_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtQml/qqml.h> + +#include <QtLocation/private/qgeomapobject_p.h> +#include <QtLocation/private/qparameterizableobject_p.h> + +QT_BEGIN_NAMESPACE + +class QDeclarativeGeoRoute; +class QGeoRoute; +class QMapRouteObjectPrivate; +class Q_LOCATION_PRIVATE_EXPORT QMapRouteObject : public QGeoMapObject +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeGeoRoute *route READ route WRITE setRoute NOTIFY routeChanged) + +public: + explicit QMapRouteObject(QObject *parent = nullptr); + ~QMapRouteObject() override; + + QDeclarativeGeoRoute *route() const; + QGeoRoute geoRoute() const; + + void setMap(QGeoMap *map) override; + void setRoute(QDeclarativeGeoRoute * route); + +signals: + void routeChanged(QDeclarativeGeoRoute * route); + +protected: + QDeclarativeGeoRoute *m_route = nullptr; + + friend class QMapRouteObjectPrivate; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QMapRouteObject) + +#endif // QDECLARATIVEMAPROUTEDELEGATE_P_H diff --git a/src/location/labs/qmaprouteobject_p_p.h b/src/location/labs/qmaprouteobject_p_p.h new file mode 100644 index 00000000..e01b1cc6 --- /dev/null +++ b/src/location/labs/qmaprouteobject_p_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef QGEOMAPROUTE_P_P_H +#define QGEOMAPROUTE_P_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 <QtLocation/private/qlocationglobal_p.h> +#include <QtLocation/private/qgeomapobject_p_p.h> +#include <QtLocation/private/qdeclarativegeoroute_p.h> +QT_BEGIN_NAMESPACE + +class QGeoRoute; + +class Q_LOCATION_PRIVATE_EXPORT QMapRouteObjectPrivate : public QGeoMapObjectPrivate +{ +public: + QMapRouteObjectPrivate(QGeoMapObject *q); + QMapRouteObjectPrivate(const QMapRouteObjectPrivate &other); + ~QMapRouteObjectPrivate() override; + + virtual QGeoMapObject::Type type() const override final; + + QDeclarativeGeoRoute *declarativeGeoRoute() const; + + virtual QGeoRoute route() const; + virtual void setRoute(const QDeclarativeGeoRoute *route); + + // QGeoMapObjectPrivate interface + bool equals(const QGeoMapObjectPrivate &other) const override; + QGeoMapObjectPrivate *clone() override; +}; + +QT_END_NAMESPACE + +#endif // QGEOMAPROUTE_P_P_H |