navit 0.5.3-trunk
Loading...
Searching...
No Matches
ngqpoint.h
Go to the documentation of this file.
1#ifndef NAVIT_GUI_QML_POINT_H
2#define NAVIT_GUI_QML_POINT_H
3
4static void get_direction(char *buffer, int angle, int mode) {
5 angle = angle % 360;
6 switch (mode) {
7 case 0:
8 sprintf(buffer, "%d", angle);
9 break;
10 case 1:
11 if (angle < 69 || angle > 291)
12 *buffer++ = 'N';
13 if (angle > 111 && angle < 249)
14 *buffer++ = 'S';
15 if (angle > 22 && angle < 158)
16 *buffer++ = 'E';
17 if (angle > 202 && angle < 338)
18 *buffer++ = 'W';
19 *buffer++ = '\0';
20 break;
21 case 2:
22 angle = (angle + 15) / 30;
23 if (!angle)
24 angle = 12;
25 sprintf(buffer, "%d H", angle);
26 break;
27 }
28}
29
37
38class NGQPoint : public QObject {
39 Q_OBJECT;
40
41 Q_PROPERTY(QString coordString READ coordString CONSTANT);
42 Q_PROPERTY(QString pointName READ pointName CONSTANT);
43 Q_PROPERTY(QString pointType READ pointType CONSTANT);
44 Q_PROPERTY(QUrl pointUrl READ pointUrl CONSTANT);
45
46 public:
47 NGQPoint(struct gui_priv *this_, struct point *p, NGQPointTypes type = MapPoint, QObject *parent = NULL)
48 : QObject(parent) {
49 this->object = this_;
50 this->item.map = 0;
54 c.x = co.x;
55 c.y = co.y;
56 this->p.x = p->x;
57 this->p.y = p->y;
58 this->type = type;
59
60 this->name = this->_coordName();
61 this->coord = this->_coordString();
62 }
63 NGQPoint(struct gui_priv *this_, struct coord *c, NGQPointTypes type = Bookmark, QObject *parent = NULL)
64 : QObject(parent) {
65 this->object = this_;
66 this->item.map = 0;
67 this->co.x = c->x;
68 this->co.y = c->y;
71 this->c.x = c->x;
72 this->c.y = c->y;
73 this->type = type;
74
75 this->name = this->_coordName();
76 this->coord = this->_coordString();
77 }
78
79 NGQPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type = Bookmark, QObject *parent = NULL)
80 : QObject(parent) {
81 this->object = this_;
82 this->item.map = 0;
83 this->c.pro = pc->pro;
84 this->c.x = pc->x;
85 this->c.y = pc->y;
86 this->co.x = pc->x;
87 this->co.y = pc->y;
88 transform_to_geo(this->c.pro, &co, &g);
89 this->type = type;
90
91 this->name = this->_coordName();
92 this->coord = this->_coordString();
93 }
94
95 NGQPoint(struct gui_priv *this_, struct coord *c, QString name, NGQPointTypes type = Bookmark,
96 QObject *parent = NULL)
97 : QObject(parent) {
98 this->object = this_;
99 this->item.map = 0;
100 this->co.x = c->x;
101 this->co.y = c->y;
103 this->c.pro = transform_get_projection(navit_get_trans(this->object->nav));
104 this->c.x = c->x;
105 this->c.y = c->y;
106 this->type = type;
107
108 this->name = name;
109 this->coord = this->_coordString();
110 }
111
112 struct pcoord *pc() {
113 return &c;
114 }
115 public slots:
117 this->item.map = 0;
118 QStringList coordSplit = coord.split(" ", QString::SkipEmptyParts);
119 this->co.x = coordSplit[0].toInt();
120 this->co.y = coordSplit[1].toInt();
123 this->c.x = coordSplit[0].toInt();
124 this->c.y = coordSplit[1].toInt();
125 this->type = type;
126
127 this->name = this->_coordName();
128 this->coord = this->_coordString();
129 }
130 QString pointName() {
131 return this->name;
132 }
133 QString coordString() {
134 return this->coord;
135 }
136 QString pointType() {
137 switch (this->type) {
138 case MapPoint:
139 return QString("MapPoint");
140 case Bookmark:
141 return QString("Bookmark");
142 case Position:
143 return QString("Position");
144 case Destination:
145 return QString("Destination");
146 case PointOfInterest:
147 return QString("PointOfInterest");
148 }
149 return QString("");
150 }
151 QUrl pointUrl() {
152 return this->url;
153 }
154 QString getInformation() {
155 struct map_rect *mr;
156 struct item *item;
157 struct attr attr;
158
159 QDomDocument retDoc;
160 QDomElement entries;
161 entries = retDoc.createElement("point");
162 retDoc.appendChild(entries);
163
164 if (this->type != Bookmark and this->item.map) {
165 mr = map_rect_new(this->item.map, NULL);
166 item = map_rect_get_item_byid(mr, this->item.id_hi, this->item.id_lo);
167 if (item) {
168 while (item_attr_get(item, attr_any, &attr)) {
169 entries.appendChild(
170 this->_fieldValueHelper(retDoc, QString::fromLocal8Bit(attr_to_name(attr.type)),
171 QString::fromLocal8Bit(attr_to_text(&attr, this->item.map, 1))));
172 }
173 }
175 }
176 return retDoc.toString();
177 }
178 QString getPOI(const QString &attr_name) {
179 struct attr attr;
180 struct item *item;
181 struct mapset_handle *h;
182 struct map_selection *sel, *selm;
183 struct map_rect *mr;
184 struct map *m;
185 int idist, dist;
186 struct coord center;
187 QDomDocument retDoc(attr_name);
188 QDomElement entries;
189 char dirbuf[32];
190
191 if (!gui_get_attr(this->object->gui, attr_radius, &attr, NULL)) {
192 return QString();
193 }
194
195 dist = attr.u.num * 1000;
196
197 sel = map_selection_rect_new(&this->c, dist, 18);
198 center.x = this->c.x;
199 center.y = this->c.y;
201
202 entries = retDoc.createElement(attr_name);
203 retDoc.appendChild(entries);
204
205 while ((m = mapset_next(h, 1))) {
206 selm = map_selection_dup_pro(sel, this->c.pro, map_projection(m));
207 mr = map_rect_new(m, selm);
208 if (mr) {
209 while ((item = map_rect_get_item(mr))) {
210 struct coord c;
211 if (item_coord_get_pro(item, &c, 1, this->c.pro) && coord_rect_contains(&sel->u.c_rect, &c)
212 && (idist = transform_distance(this->c.pro, &center, &c)) < dist && item->type < type_line) {
213 char *label;
214 QString rs;
215 if (item_attr_get(item, attr_label, &attr)) {
217 if (QString(item_to_name(item->type)).startsWith(QString("poi_"))) {
218 rs = QString::fromLocal8Bit(item_to_name(item->type));
219 rs = rs.remove(QString("poi_"));
220 rs += QString(" ") + QString::fromLocal8Bit(label);
221
222 } else if (QString(item_to_name(item->type)).startsWith(QString("poly_"))) {
223 rs = QString::fromLocal8Bit(item_to_name(item->type));
224 rs = rs.remove(QString("poly_"));
225 rs += QString(" ") + QString::fromLocal8Bit(label);
226
227 } else if (QString(item_to_name(item->type)).startsWith(QString("street_"))) {
228 rs = "Street ";
229 rs += QString::fromLocal8Bit(label);
230 }
232 } else
233 rs = item_to_name(item->type);
235 if (rs.length() > 0) {
236 QDomElement entry = retDoc.createElement("point");
237 QDomElement nameTag = retDoc.createElement("name");
238 QDomElement typeTag = retDoc.createElement("type");
239 QDomElement distTag = retDoc.createElement("distance");
240 QDomElement directTag = retDoc.createElement("direction");
241 QDomElement coordsTag = retDoc.createElement("coords");
242 QDomText nameT = retDoc.createTextNode(rs);
243 QDomText typeT = retDoc.createTextNode(QString(item_to_name(item->type)));
244 QDomText distT = retDoc.createTextNode(QString::number(idist / 1000));
245 QDomText directT = retDoc.createTextNode(dirbuf);
246 QDomText coordsT = retDoc.createTextNode(QString("%1 %2").arg(c.x).arg(c.y));
247 nameTag.appendChild(nameT);
248 typeTag.appendChild(typeT);
249 distTag.appendChild(distT);
250 directTag.appendChild(directT);
251 coordsTag.appendChild(coordsT);
252 entry.appendChild(nameTag);
253 entry.appendChild(typeTag);
254 entry.appendChild(distTag);
255 entry.appendChild(directTag);
256 entry.appendChild(coordsTag);
257 entries.appendChild(entry);
258 }
259 }
260 }
261 }
263 }
265 mapset_close(h);
266 dbg(lvl_info, "%s", retDoc.toString().toLocal8Bit().constData());
267 return retDoc.toString();
268 }
269
270 protected:
271 QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value) {
272 QDomElement fieldTag = doc.createElement(field);
273 QDomText valueText = doc.createTextNode(value);
274 fieldTag.appendChild(valueText);
275 return fieldTag;
276 }
277 QString _coordString() {
278 char latc = 'N', lngc = 'E';
279 int lat_deg, lat_min, lat_sec;
280 int lng_deg, lng_min, lng_sec;
281 struct coord_geo g = this->g;
282
283 if (g.lat < 0) {
284 g.lat = -g.lat;
285 latc = 'S';
286 }
287 if (g.lng < 0) {
288 g.lng = -g.lng;
289 lngc = 'W';
290 }
291 lat_deg = g.lat;
292 lat_min = fmod(g.lat * 60, 60);
293 lat_sec = fmod(g.lat * 3600, 60);
294 lng_deg = g.lng;
295 lng_min = fmod(g.lng * 60, 60);
296 lng_sec = fmod(g.lng * 3600, 60);
297 return QString(QString::fromLocal8Bit("%1°%2'%3\" %4%5%6°%7'%8\" %9"))
298 .arg(lat_deg)
299 .arg(lat_min)
300 .arg(lat_sec)
301 .arg(latc)
302 .arg(' ')
303 .arg(lng_deg)
304 .arg(lng_min)
305 .arg(lng_sec)
306 .arg(lngc);
307 }
308 QString _coordName() {
309 int dist = 10;
310 struct mapset *ms;
311 struct mapset_handle *h;
312 struct map_rect *mr;
313 struct map *m;
314 struct item *item;
315 struct street_data *data;
316 struct map_selection sel;
317 struct transformation *trans;
318 enum projection pro;
319 struct attr attr;
320 char *label;
321 QString ret;
322
323 trans = navit_get_trans(this->object->nav);
324 pro = transform_get_projection(trans);
325 transform_from_geo(pro, &g, &co);
326 ms = navit_get_mapset(this->object->nav);
327 sel.next = NULL;
328 sel.u.c_rect.lu.x = c.x - dist;
329 sel.u.c_rect.lu.y = c.y + dist;
330 sel.u.c_rect.rl.x = c.x + dist;
331 sel.u.c_rect.rl.y = c.y - dist;
332 sel.order = 18;
333 sel.range = item_range_all;
334 h = mapset_open(ms);
335 while ((m = mapset_next(h, 1))) {
336 mr = map_rect_new(m, &sel);
337 if (!mr)
338 continue;
339 while ((item = map_rect_get_item(mr))) {
341 if (transform_within_dist_item(&co, item->type, data->c, data->count, dist)) {
342 if (item_attr_get(item, attr_label, &attr)) {
344 this->item = *item;
345 this->_setUrl(item);
346 if (QString(item_to_name(item->type)).startsWith(QString("poi_"))) {
347 ret = QString::fromLocal8Bit(item_to_name(item->type));
348 ret = ret.remove(QString("poi_"));
349 ret += QString(" ") + QString::fromLocal8Bit(label);
350 }
351 if (QString(item_to_name(item->type)).startsWith(QString("poly_"))) {
352 ret = QString::fromLocal8Bit(item_to_name(item->type));
353 ret = ret.remove(QString("poly_"));
354 ret += QString(" ") + QString::fromLocal8Bit(label);
355 }
356 if (QString(item_to_name(item->type)).startsWith(QString("street_"))) {
357 ret = "Street ";
358 ret += QString::fromLocal8Bit(label);
359 }
363 mapset_close(h);
364 return ret;
365 } else
366 this->item = *item;
367 this->_setUrl(item);
368 ret = item_to_name(item->type);
369 }
371 }
373 }
374 mapset_close(h);
375 return ret;
376 }
377 void _setUrl(struct item *item) {
378 struct attr attr;
379 if (item_attr_get(item, attr_osm_nodeid, &attr)) {
380 url.setUrl(QString("http://www.openstreetmap.org/browse/node/%1").arg(*attr.u.num64));
381 } else if (item_attr_get(item, attr_osm_wayid, &attr)) {
382 url.setUrl(QString("http://www.openstreetmap.org/browse/way/%1").arg(*attr.u.num64));
383 } else if (item_attr_get(item, attr_osm_relationid, &attr)) {
384 url.setUrl(QString("http://www.openstreetmap.org/browse/relation/%1").arg(*attr.u.num64));
385 } else {
386 url.clear();
387 }
388 }
389
390 private:
392
394 struct coord_geo g;
395 struct coord co;
396 struct pcoord c;
397 struct point p;
398
399 struct item item;
400
401 QString name;
402 QString coord;
403 QUrl url;
404};
405
406#include "ngqpoint.moc"
407
408#endif /* NAVIT_GUI_QML_POINT_H */
char * attr_to_text(struct attr *attr, struct map *map, int pretty)
Converts an attribute to a string that can be displayed.
Definition attr.c:490
char * attr_to_name(enum attr_type attr)
Converts an attr_type to a string.
Definition attr.c:117
Definition ngqpoint.h:38
QString coordString()
Definition ngqpoint.h:133
QString _coordName()
Definition ngqpoint.h:308
QString name
Definition ngqpoint.h:401
NGQPoint(struct gui_priv *this_, struct coord *c, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition ngqpoint.h:63
void _setUrl(struct item *item)
Definition ngqpoint.h:377
QString coord
Definition ngqpoint.h:402
struct point p
Definition ngqpoint.h:397
QString pointType()
Definition ngqpoint.h:136
NGQPoint(struct gui_priv *this_, struct point *p, NGQPointTypes type=MapPoint, QObject *parent=NULL)
Definition ngqpoint.h:47
struct pcoord * pc()
Definition ngqpoint.h:112
struct item item
Definition ngqpoint.h:399
NGQPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition ngqpoint.h:79
QString pointName
Definition ngqpoint.h:42
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition ngqpoint.h:271
struct coord_geo g
Definition ngqpoint.h:394
QString pointType
Definition ngqpoint.h:43
QUrl pointUrl()
Definition ngqpoint.h:151
QString _coordString()
Definition ngqpoint.h:277
QString getInformation()
Definition ngqpoint.h:154
NGQPointTypes type
Definition ngqpoint.h:393
void setNewPoint(QString coord, NGQPointTypes type=PointOfInterest)
Definition ngqpoint.h:116
QUrl url
Definition ngqpoint.h:403
NGQPoint(struct gui_priv *this_, struct coord *c, QString name, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition ngqpoint.h:95
struct pcoord c
Definition ngqpoint.h:396
struct gui_priv * object
Definition ngqpoint.h:391
QString coordString
Definition ngqpoint.h:41
QUrl pointUrl
Definition ngqpoint.h:44
QString getPOI(const QString &attr_name)
Definition ngqpoint.h:178
QString pointName()
Definition ngqpoint.h:130
struct coord co
Definition ngqpoint.h:395
static GValue value
Definition datawindow.c:42
@ lvl_info
Definition debug.h:50
#define dbg(level,...)
Definition debug.h:59
struct tcoord center
Definition garmin_img.c:2
char data
Definition garmin_img.c:2
struct label_data_offset label
Definition garmin_img.c:1
int coord_rect_contains(struct coord_rect *r, struct coord *c)
Definition coord.c:106
struct transformation * navit_get_trans(struct navit *this_)
Definition navit.c:3524
struct mapset * navit_get_mapset(struct navit *this_)
Get the current mapset.
Definition navit.c:226
int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition gui.c:60
static GtkActionEntry entries[]
Definition gui_gtk_action.c:196
int item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to)
Gets the next coordinates from an item and reprojects them.
Definition item.c:347
int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
Gets the next matching attribute from an item.
Definition item.c:414
char * item_to_name(enum item_type item)
Definition item.c:483
struct item_range item_range_all
Definition item.c:34
struct map_selection * map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
Duplicates a map selection, transforming coordinates.
Definition map.c:506
void map_convert_free(char *str)
Frees the memory allocated for a converted string.
Definition map.c:238
void map_selection_destroy(struct map_selection *sel)
Destroys a map selection.
Definition map.c:540
struct item * map_rect_get_item(struct map_rect *mr)
Gets the next item from a map rect.
Definition map.c:317
char * map_convert_string(struct map *this_, char *str)
Converts a string from a map.
Definition map.c:220
struct map_rect * map_rect_new(struct map *m, struct map_selection *sel)
Creates a new map rect.
Definition map.c:290
struct item * map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
Returns the item specified by the ID.
Definition map.c:345
enum projection map_projection(struct map *this_)
Returns the projection of a map.
Definition map.c:248
struct map_selection * map_selection_rect_new(struct pcoord *center, int distance, int order)
Creates a new rectangular map selection.
Definition map.c:483
void map_rect_destroy(struct map_rect *mr)
Destroys a map rect.
Definition map.c:361
struct mapset_handle * mapset_open(struct mapset *ms)
Returns a new handle for a mapset.
Definition mapset.c:164
struct map * mapset_next(struct mapset_handle *msh, int active)
Gets the next map from a mapset handle.
Definition mapset.c:192
void mapset_close(struct mapset_handle *msh)
Closes a mapset handle after it is no longer used.
Definition mapset.c:255
static void get_direction(char *buffer, int angle, int mode)
Definition ngqpoint.h:4
NGQPointTypes
Definition ngqpoint.h:30
@ Position
Definition ngqpoint.h:33
@ Bookmark
Definition ngqpoint.h:32
@ Destination
Definition ngqpoint.h:34
@ MapPoint
Definition ngqpoint.h:31
@ PointOfInterest
Definition ngqpoint.h:35
projection
Definition projection.h:23
void street_data_free(struct street_data *sd)
Frees street data.
Definition route.c:3345
static void street_get_data(struct street_priv *street, unsigned char **p)
Definition street.c:355
Definition attr.c:48
Definition attr.h:138
long long * num64
Definition attr.h:193
char * str
Definition attr.h:141
union attr::@0 u
enum attr_type type
Definition attr.h:139
long num
Definition attr.h:143
Definition maptool.h:173
A WGS84 coordinate.
Definition coord.h:94
navit_float lat
Definition coord.h:96
navit_float lng
Definition coord.h:95
struct coord rl
Definition coord.h:59
struct coord lu
Definition coord.h:58
Definition coord.h:33
int y
Definition coord.h:35
int x
Definition coord.h:34
Definition graphics_win32.h:50
struct navit * nav
Definition graphics_win32.h:51
struct gui * gui
Definition gui_qml.cpp:40
Represents an object on a map.
Definition item.h:122
int id_hi
Definition item.h:124
enum item_type type
Definition item.h:123
struct map * map
Definition item.h:126
Definition map.c:62
Used to select data from a map.
Definition map.h:63
int order
Definition map.h:69
struct map_selection * next
Definition map.h:64
union map_selection::@4 u
struct item_range range
Definition map.h:70
struct coord_rect c_rect
Definition map.h:66
Definition map.c:55
Handle for a mapset in use.
Definition mapset.c:150
Definition mapset.c:39
Definition gpx2navit_txt.h:50
Definition coord.h:51
int y
Definition coord.h:54
enum projection pro
Definition coord.h:52
int x
Definition coord.h:53
Definition point.h:23
int y
Definition point.h:25
int x
Definition point.h:24
Information about a street.
Definition route.h:70
The parameters needed to transform a map for display.
Definition transform.c:64
enum projection transform_get_projection(struct transformation *this_)
Definition transform.c:706
void transform_to_geo(enum projection pro, const struct coord *c, struct coord_geo *g)
Transform the coordinates of a geographical point from a coord representation to a geographical (lat,...
Definition transform.c:273
void transform_from_geo(enum projection pro, const struct coord_geo *g, struct coord *c)
Transform the coordinates of a geographical point from a geographical (lat, long) representation to a...
Definition transform.c:309
int transform_reverse(struct transformation *t, struct point *p, struct coord *c)
Definition transform.c:686
int transform_get_angle_delta(struct coord *c1, struct coord *c2, int dir)
Gets the bearing from one point to another.
Definition transform.c:1373
double transform_distance(enum projection pro, struct coord *c1, struct coord *c2)
Calculates the distance between two points.
Definition transform.c:1037
int transform_within_dist_item(struct coord *ref, enum item_type type, struct coord *c, int count, int dist)
Definition transform.c:1490