| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QDECLARATIVEPOLYLINEMAPITEM |
| 38 | #define QDECLARATIVEPOLYLINEMAPITEM |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | // |
| 50 | |
| 51 | #include <QtLocation/private/qlocationglobal_p.h> |
| 52 | #include <QtLocation/private/qdeclarativegeomapitembase_p.h> |
| 53 | #include <QtLocation/private/qgeomapitemgeometry_p.h> |
| 54 | |
| 55 | #include <QtPositioning/QGeoPath> |
| 56 | #include <QtPositioning/private/qdoublevector2d_p.h> |
| 57 | #include <QSGGeometryNode> |
| 58 | #include <QSGFlatColorMaterial> |
| 59 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | class Q_LOCATION_PRIVATE_EXPORT QDeclarativeMapLineProperties : public QObject |
| 63 | { |
| 64 | Q_OBJECT |
| 65 | |
| 66 | Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged) |
| 67 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
| 68 | |
| 69 | public: |
| 70 | explicit QDeclarativeMapLineProperties(QObject *parent = 0); |
| 71 | |
| 72 | QColor color() const; |
| 73 | void setColor(const QColor &color); |
| 74 | |
| 75 | qreal width() const; |
| 76 | void setWidth(qreal width); |
| 77 | |
| 78 | Q_SIGNALS: |
| 79 | void widthChanged(qreal width); |
| 80 | void colorChanged(const QColor &color); |
| 81 | |
| 82 | private: |
| 83 | qreal width_; |
| 84 | QColor color_; |
| 85 | }; |
| 86 | |
| 87 | class QDeclarativePolylineMapItemPrivate; |
| 88 | class Q_LOCATION_PRIVATE_EXPORT QDeclarativePolylineMapItem : public QDeclarativeGeoMapItemBase |
| 89 | { |
| 90 | Q_OBJECT |
| 91 | Q_ENUMS(Backend) |
| 92 | |
| 93 | Q_PROPERTY(QJSValue path READ path WRITE setPath NOTIFY pathChanged) |
| 94 | Q_PROPERTY(QDeclarativeMapLineProperties *line READ line CONSTANT) |
| 95 | Q_PROPERTY(Backend backend READ backend WRITE setBackend NOTIFY backendChanged REVISION 15) |
| 96 | |
| 97 | public: |
| 98 | enum Backend { |
| 99 | Software = 0, |
| 100 | #if QT_CONFIG(opengl) |
| 101 | OpenGLLineStrip = 1, |
| 102 | OpenGLExtruded = 2, |
| 103 | #endif |
| 104 | }; |
| 105 | |
| 106 | explicit QDeclarativePolylineMapItem(QQuickItem *parent = 0); |
| 107 | ~QDeclarativePolylineMapItem(); |
| 108 | |
| 109 | virtual void setMap(QDeclarativeGeoMap *quickMap, QGeoMap *map) override; |
| 110 | //from QuickItem |
| 111 | virtual QSGNode *updateMapItemPaintNode(QSGNode *, UpdatePaintNodeData *) override; |
| 112 | |
| 113 | Q_INVOKABLE int pathLength() const; |
| 114 | Q_INVOKABLE void addCoordinate(const QGeoCoordinate &coordinate); |
| 115 | Q_INVOKABLE void insertCoordinate(int index, const QGeoCoordinate &coordinate); |
| 116 | Q_INVOKABLE void replaceCoordinate(int index, const QGeoCoordinate &coordinate); |
| 117 | Q_INVOKABLE QGeoCoordinate coordinateAt(int index) const; |
| 118 | Q_INVOKABLE bool containsCoordinate(const QGeoCoordinate &coordinate); |
| 119 | Q_INVOKABLE void removeCoordinate(const QGeoCoordinate &coordinate); |
| 120 | Q_INVOKABLE void removeCoordinate(int index); |
| 121 | |
| 122 | QJSValue path() const; |
| 123 | virtual void setPath(const QJSValue &value); |
| 124 | Q_INVOKABLE void setPath(const QGeoPath &path); |
| 125 | |
| 126 | bool contains(const QPointF &point) const override; |
| 127 | const QGeoShape &geoShape() const override; |
| 128 | void setGeoShape(const QGeoShape &shape) override; |
| 129 | |
| 130 | QDeclarativeMapLineProperties *line(); |
| 131 | |
| 132 | Backend backend() const; |
| 133 | void setBackend(Backend b); |
| 134 | |
| 135 | Q_SIGNALS: |
| 136 | void pathChanged(); |
| 137 | void backendChanged(); |
| 138 | |
| 139 | protected Q_SLOTS: |
| 140 | void markSourceDirtyAndUpdate(); |
| 141 | void updateAfterLinePropertiesChanged(); |
| 142 | virtual void afterViewportChanged(const QGeoMapViewportChangeEvent &event) override; |
| 143 | |
| 144 | protected: |
| 145 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 146 | void setPathFromGeoList(const QList<QGeoCoordinate> &path); |
| 147 | void updatePolish() override; |
| 148 | void componentComplete() override; |
| 149 | void updateLineStyleParameter(QGeoMapParameter *p, const char *propertyName); |
| 150 | void updateLineStyleParameter(QGeoMapParameter *p, const char *propertyName, bool update); |
| 151 | |
| 152 | #ifdef QT_LOCATION_DEBUG |
| 153 | public: |
| 154 | #endif |
| 155 | QGeoPath m_geopath; |
| 156 | QDeclarativeMapLineProperties m_line; |
| 157 | |
| 158 | Backend m_backend = Software; |
| 159 | bool m_dirtyMaterial; |
| 160 | bool m_updatingGeometry; |
| 161 | |
| 162 | QScopedPointer<QDeclarativePolylineMapItemPrivate> m_d; |
| 163 | |
| 164 | friend class QDeclarativePolylineMapItemPrivate; |
| 165 | friend class QDeclarativePolylineMapItemPrivateCPU; |
| 166 | friend class QDeclarativePolylineMapItemPrivateOpenGLLineStrip; |
| 167 | friend class QDeclarativePolylineMapItemPrivateOpenGLExtruded; |
| 168 | }; |
| 169 | |
| 170 | QT_END_NAMESPACE |
| 171 | |
| 172 | QML_DECLARE_TYPE(QDeclarativeMapLineProperties) |
| 173 | QML_DECLARE_TYPE(QDeclarativePolylineMapItem) |
| 174 | |
| 175 | #endif /* QDECLARATIVEPOLYLINEMAPITEM_H_ */ |
| 176 | |