libosmscout  1.1.1
OverlayObject.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_OVERLAYOBJECT_H
2 #define OSMSCOUT_CLIENT_QT_OVERLAYOBJECT_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6 
7  Copyright (C) 2017 Lukáš Karas
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #include <QObject>
25 #include <QMutex>
26 #include <QMutexLocker>
27 
28 #include <osmscout/Way.h>
29 #include <osmscout/Area.h>
30 #include <osmscout/Node.h>
31 #include <osmscout/util/GeoBox.h>
33 #include <osmscout/LocationEntry.h>
34 
35 #include <optional>
36 
37 namespace osmscout {
38 
45 class OSMSCOUT_CLIENT_QT_API OverlayObject : public QObject
46 {
47  Q_OBJECT
48  Q_PROPERTY(QString type READ getTypeName WRITE setTypeName)
49  Q_PROPERTY(int size READ getSize)
50  Q_PROPERTY(QString objectType READ getObjectTypeStr)
51  Q_PROPERTY(qint8 layer READ getLayer WRITE setLayer)
52  Q_PROPERTY(QString name READ getName WRITE setName)
53  Q_PROPERTY(QString color READ getColor WRITE setColor)
54  Q_PROPERTY(LocationEntry *boundingBox READ getBBoxAsLocation NOTIFY bboxChanged)
55 
56 protected:
57  QString typeName;
58  std::vector<osmscout::Point> nodes;
59  mutable std::vector<SegmentGeoBox> segmentsBoxes;
60  mutable osmscout::GeoBox box;
61  int8_t layer{std::numeric_limits<int8_t>::max()};
62  QString name;
63  QString color;
64  mutable QMutex lock;
65  std::optional<osmscout::Color> colorValue;
66 
67 public slots:
68  void clear();
69  void addPoint(double lat, double lon);
70 
71 signals:
72  void bboxChanged();
73 
74 public:
75  OverlayObject(QObject *parent=Q_NULLPTR);
76 
77  explicit OverlayObject(const std::vector<osmscout::Point> &nodes,
78  QString typeName="_route",
79  QObject *parent=Q_NULLPTR);
80 
81  OverlayObject(const OverlayObject &o);
82 
83  ~OverlayObject() override;
84 
87  }
88 
89  QString getObjectTypeStr() const {
90  switch (getObjectType()){
92  return "area";
94  return "way";
96  return "node";
97  default:
98  return "none";
99  }
100  }
101 
102  inline QString getTypeName() const
103  {
104  QMutexLocker locker(&lock);
105  return typeName;
106  }
107 
108  inline void setTypeName(const QString &name){
109  QMutexLocker locker(&lock);
110  typeName=name;
111  }
112 
113  inline size_t getSize(){
114  QMutexLocker locker(&lock);
115  return nodes.size();
116  }
117 
118  inline qint8 getLayer() const
119  {
120  QMutexLocker locker(&lock);
121  return layer;
122  }
123 
124  inline void setLayer(qint8 l)
125  {
126  QMutexLocker locker(&lock);
127  layer = l;
128  }
129 
130  inline QString getName() const
131  {
132  QMutexLocker locker(&lock);
133  return name;
134  }
135 
136  inline void setName(const QString &n)
137  {
138  QMutexLocker locker(&lock);
139  name = n;
140  }
141 
142  inline QString getColor() const
143  {
144  QMutexLocker locker(&lock);
145  return color;
146  }
147 
148  void setColor(const QString &c);
149  void setColorValue(Color &c);
150 
151  LocationEntry* getBBoxAsLocation() const;
152  osmscout::GeoBox boundingBox() const;
153  std::vector<osmscout::GeoCoord> getCoords() const;
154  std::vector<osmscout::Point> getPoints() const;
155 
156 protected:
157  void setupFeatures(const osmscout::TypeInfoRef &type,
158  osmscout::FeatureValueBuffer &features) const;
159 
160  // internal, lock have to be acquired
161  osmscout::GeoBox boundingBoxInternal() const;
162 
163  // internal, lock have to be acquired
164  std::vector<SegmentGeoBox> segments() const;
165 };
166 
167 
169 {
170 Q_OBJECT
171 
172 public:
173  OverlayArea(QObject *parent=Q_NULLPTR);
174 
175  explicit OverlayArea(const std::vector<osmscout::Point> &nodes,
176  QString typeName="_route",
177  QObject *parent=Q_NULLPTR);
178 
179  ~OverlayArea() override;
180 
183  }
184 
185  bool toArea(osmscout::AreaRef &area,
186  const osmscout::TypeConfig &typeConfig) const;
187 };
188 
190 {
191 Q_OBJECT
192 
193 public:
194  OverlayWay(QObject *parent=Q_NULLPTR);
195 
196  explicit OverlayWay(const std::vector<osmscout::Point> &nodes,
197  QString typeName="_route",
198  QObject *parent=Q_NULLPTR);
199 
200  ~OverlayWay() override;
201 
204  }
205 
206  bool toWay(osmscout::WayRef &way,
207  const osmscout::TypeConfig &typeConfig) const;
208 };
209 
211 {
212 Q_OBJECT
213 
214 public:
215  OverlayNode(QObject *parent=Q_NULLPTR);
216 
217  explicit OverlayNode(const std::vector<osmscout::Point> &nodes,
218  QString typeName="_route",
219  QObject *parent=Q_NULLPTR);
220 
221  ~OverlayNode() override;
222 
225  }
226 
227  bool toNode(osmscout::NodeRef &node,
228  const osmscout::TypeConfig &typeConfig) const;
229 };
230 
231 
232 using OverlayObjectRef = std::shared_ptr<OverlayObject>;
233 
234 }
235 
236 #endif /* OSMSCOUT_CLIENT_QT_OVERLAYOBJECT_H */
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
Definition: OverlayObject.h:168
std::shared_ptr< Node > NodeRef
Definition: Node.h:124
virtual osmscout::RefType getObjectType() const
Definition: OverlayObject.h:85
QString getTypeName() const
Definition: OverlayObject.h:102
STL namespace.
osmscout::RefType getObjectType() const override
Definition: OverlayObject.h:181
Definition: ObjectRef.h:135
QString getObjectTypeStr() const
Definition: OverlayObject.h:89
std::shared_ptr< Way > WayRef
Definition: Way.h:202
qint8 getLayer() const
Definition: OverlayObject.h:118
Definition: OverlayObject.h:189
Definition: ObjectRef.h:133
RefType
Definition: ObjectRef.h:131
QMutex lock
Definition: OverlayObject.h:64
Definition: Area.h:38
QString getName() const
Definition: OverlayObject.h:130
std::shared_ptr< OverlayObject > OverlayObjectRef
Definition: OverlayObject.h:232
std::shared_ptr< Area > AreaRef
Definition: Area.h:358
Definition: OverlayObject.h:210
Definition: ObjectRef.h:134
Definition: OverlayObject.h:45
Definition: LocationEntry.h:42
void setLayer(qint8 l)
Definition: OverlayObject.h:124
osmscout::RefType getObjectType() const override
Definition: OverlayObject.h:202
std::shared_ptr< TypeInfo > TypeInfoRef
Definition: TypeConfig.h:58
Definition: Geometry.h:1173
void setName(const QString &n)
Definition: OverlayObject.h:136
Definition: ObjectRef.h:136
QString getColor() const
Definition: OverlayObject.h:142
osmscout::RefType getObjectType() const override
Definition: OverlayObject.h:223
void setTypeName(const QString &name)
Definition: OverlayObject.h:108
size_t getSize()
Definition: OverlayObject.h:113
std::optional< osmscout::Color > colorValue
Definition: OverlayObject.h:65