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 QGEOMAPITEMGEOMETRY_H
38 #define QGEOMAPITEMGEOMETRY_H
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 
53 #include <QPainterPath>
54 #include <QPointF>
55 #include <QRectF>
56 #include <QVector>
57 #include <QGeoCoordinate>
58 #include <QVector2D>
59 #include <QList>
60 
61 QT_BEGIN_NAMESPACE
62 
63 class QSGGeometry;
64 class QGeoMap;
65 
66 class Q_LOCATION_PRIVATE_EXPORT QGeoMapItemGeometry
67 {
68 public:
69     QGeoMapItemGeometry();
70     virtual ~QGeoMapItemGeometry();
71 
isSourceDirty()72     inline bool isSourceDirty() const { return sourceDirty_; }
isScreenDirty()73     inline bool isScreenDirty() const { return screenDirty_; }
markSourceDirty()74     inline void markSourceDirty() { sourceDirty_ = true; screenDirty_ = true; }
markScreenDirty()75     inline void markScreenDirty() { screenDirty_ = true; clipToViewport_ = true; }
markFullScreenDirty()76     inline void markFullScreenDirty() { screenDirty_ = true; clipToViewport_ = false;}
markClean()77     inline void markClean() { screenDirty_ = (sourceDirty_ = false); clipToViewport_ = true;}
clearScreen()78     inline void clearScreen() { screenDirty_ = false; }
79 
80     inline void setPreserveGeometry(bool value, const QGeoCoordinate &geoLeftBound = QGeoCoordinate())
81     {
82         preserveGeometry_ = value;
83         if (preserveGeometry_)
84             geoLeftBound_ = geoLeftBound;
85     }
geoLeftBound()86     inline QGeoCoordinate geoLeftBound() { return geoLeftBound_; }
87 
sourceBoundingBox()88     inline QRectF sourceBoundingBox() const { return sourceBounds_; }
screenBoundingBox()89     inline QRectF screenBoundingBox() const { return screenBounds_; }
clearBounds()90     inline void clearBounds() { sourceBounds_ = screenBounds_ = QRectF(); firstPointOffset_ = QPointF(); }
91 
firstPointOffset()92     inline QPointF firstPointOffset() const { return firstPointOffset_; }
93     void translate(const QPointF &offset);
94 
origin()95     inline const QGeoCoordinate &origin() const { return srcOrigin_; }
96 
screenOutline()97     QPainterPath screenOutline() const {
98         return screenOutline_;
99     }
100 
contains(const QPointF & screenPoint)101     virtual bool contains(const QPointF &screenPoint) const {
102         return screenOutline_.contains(screenPoint);
103     }
104 
vertex(quint32 index)105     inline QVector2D vertex(quint32 index) const {
106         return QVector2D(screenVertices_[index]);
107     }
108 
vertices()109     inline QVector<QPointF> vertices() const { return screenVertices_; }
indices()110     inline QVector<quint32> indices() const { return screenIndices_; }
111 
isIndexed()112     inline bool isIndexed() const { return (!screenIndices_.isEmpty()); }
113 
114     /* Size is # of triangles */
size()115     inline quint32 size() const
116     {
117         if (isIndexed())
118             return screenIndices_.size() / 3;
119         else
120             return screenVertices_.size() / 3;
121     }
122 
clear()123     inline void clear() { firstPointOffset_ = QPointF(0,0);
124                           screenVertices_.clear(); screenIndices_.clear(); }
125 
126     void allocateAndFill(QSGGeometry *geom) const;
127 
128     double geoDistanceToScreenWidth(const QGeoMap &map,
129                                            const QGeoCoordinate &fromCoord,
130                                            const QGeoCoordinate &toCoord);
131 
132     static QRectF translateToCommonOrigin(const QList<QGeoMapItemGeometry *> &geoms);
133 
134     mutable bool m_dataChanged = false;
135 
136 private:
137     QGeoMapItemGeometry(const QGeoMapItemGeometry &other); // Or else it may crash on copy
138     QGeoMapItemGeometry &operator= (const QGeoMapItemGeometry & other); // Or else it may crash on copy
139 
140 protected:
141     bool sourceDirty_;
142     bool screenDirty_;
143     bool clipToViewport_;
144     bool preserveGeometry_;
145     QGeoCoordinate geoLeftBound_;
146 
147     QPointF firstPointOffset_;
148 
149     QPainterPath screenOutline_;
150 
151     QRectF sourceBounds_;
152     QRectF screenBounds_;
153 
154     QGeoCoordinate srcOrigin_;
155 
156     QVector<QPointF> screenVertices_;
157     QVector<quint32> screenIndices_;
158 };
159 
160 QT_END_NAMESPACE
161 
162 #endif // QGEOMAPITEMGEOMETRY_H
163