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
5get_direction(char *buffer, int angle, int mode)
6{
7 angle=angle%360;
8 switch (mode) {
9 case 0:
10 sprintf(buffer,"%d",angle);
11 break;
12 case 1:
13 if (angle < 69 || angle > 291)
14 *buffer++='N';
15 if (angle > 111 && angle < 249)
16 *buffer++='S';
17 if (angle > 22 && angle < 158)
18 *buffer++='E';
19 if (angle > 202 && angle < 338)
20 *buffer++='W';
21 *buffer++='\0';
22 break;
23 case 2:
24 angle=(angle+15)/30;
25 if (! angle)
26 angle=12;
27 sprintf(buffer,"%d H", angle);
28 break;
29 }
30}
31
33
34class NGQPoint : public QObject {
35 Q_OBJECT;
36
37 Q_PROPERTY(QString coordString READ coordString CONSTANT);
38 Q_PROPERTY(QString pointName READ pointName CONSTANT);
39 Q_PROPERTY(QString pointType READ pointType CONSTANT);
40 Q_PROPERTY(QUrl pointUrl READ pointUrl CONSTANT);
41public:
42 NGQPoint(struct gui_priv* this_,struct point* p,NGQPointTypes type=MapPoint,QObject *parent=NULL) : QObject(parent) {
43 this->object=this_;
44 this->item.map=0;
48 c.x = co.x;
49 c.y = co.y;
50 this->p.x=p->x;
51 this->p.y=p->y;
52 this->type=type;
53
54 this->name=this->_coordName();
55 this->coord=this->_coordString();
56 }
57 NGQPoint(struct gui_priv* this_,struct coord* c,NGQPointTypes type=Bookmark,QObject *parent=NULL) : QObject(parent) {
58 this->object=this_;
59 this->item.map=0;
60 this->co.x=c->x;
61 this->co.y=c->y;
64 this->c.x = c->x;
65 this->c.y = c->y;
66 this->type=type;
67
68 this->name=this->_coordName();
69 this->coord=this->_coordString();
70 }
71
72 NGQPoint(struct gui_priv* this_,struct pcoord* pc,NGQPointTypes type=Bookmark,QObject *parent=NULL) : QObject(parent) {
73 this->object=this_;
74 this->item.map=0;
75 this->c.pro = pc->pro;
76 this->c.x = pc->x;
77 this->c.y = pc->y;
78 this->co.x=pc->x;
79 this->co.y=pc->y;
80 transform_to_geo(this->c.pro, &co, &g);
81 this->type=type;
82
83 this->name=this->_coordName();
84 this->coord=this->_coordString();
85 }
86
87 NGQPoint(struct gui_priv* this_,struct coord* c,QString name,NGQPointTypes type=Bookmark,QObject *parent=NULL) : QObject(parent) {
88 this->object=this_;
89 this->item.map=0;
90 this->co.x=c->x;
91 this->co.y=c->y;
94 this->c.x = c->x;
95 this->c.y = c->y;
96 this->type=type;
97
98 this->name=name;
99 this->coord=this->_coordString();
100 }
101
102 struct pcoord* pc() { return &c; }
103public slots:
105 this->item.map=0;
106 QStringList coordSplit=coord.split(" ",QString::SkipEmptyParts);
107 this->co.x=coordSplit[0].toInt();
108 this->co.y=coordSplit[1].toInt();
111 this->c.x = coordSplit[0].toInt();
112 this->c.y = coordSplit[1].toInt();
113 this->type=type;
114
115 this->name=this->_coordName();
116 this->coord=this->_coordString();
117 }
118 QString pointName() {
119 return this->name;
120 }
121 QString coordString() {
122 return this->coord;
123 }
124 QString pointType() {
125 switch(this->type) {
126 case MapPoint:
127 return QString("MapPoint");
128 case Bookmark:
129 return QString("Bookmark");
130 case Position:
131 return QString("Position");
132 case Destination:
133 return QString("Destination");
134 case PointOfInterest:
135 return QString("PointOfInterest");
136 }
137 return QString("");
138 }
139 QUrl pointUrl() {
140 return this->url;
141 }
142 QString getInformation() {
143 struct map_rect *mr;
144 struct item* item;
145 struct attr attr;
146
147 QDomDocument retDoc;
148 QDomElement entries;
149 entries=retDoc.createElement("point");
150 retDoc.appendChild(entries);
151
152 if (this->type!=Bookmark and this->item.map) {
153 mr=map_rect_new(this->item.map, NULL);
154 item = map_rect_get_item_byid(mr, this->item.id_hi, this->item.id_lo);
155 if (item) {
156 while(item_attr_get(item, attr_any, &attr)) {
157 entries.appendChild(this->_fieldValueHelper(retDoc,QString::fromLocal8Bit(attr_to_name(attr.type)), QString::fromLocal8Bit(attr_to_text(&attr,this->item.map, 1))));
158 }
159 }
161 }
162 return retDoc.toString();
163 }
164 QString getPOI(const QString &attr_name) {
165 struct attr attr;
166 struct item* item;
167 struct mapset_handle *h;
168 struct map_selection *sel,*selm;
169 struct map_rect *mr;
170 struct map *m;
171 int idist,dist;
172 struct coord center;
173 QDomDocument retDoc(attr_name);
174 QDomElement entries;
175 char dirbuf[32];
176
177 if (!gui_get_attr(this->object->gui,attr_radius,&attr,NULL)) {
178 return QString();
179 }
180
181 dist=attr.u.num*1000;
182
183 sel=map_selection_rect_new(&this->c, dist, 18);
184 center.x=this->c.x;
185 center.y=this->c.y;
187
188 entries=retDoc.createElement(attr_name);
189 retDoc.appendChild(entries);
190
191 while ((m=mapset_next(h, 1))) {
192 selm=map_selection_dup_pro(sel, this->c.pro, map_projection(m));
193 mr=map_rect_new(m, selm);
194 if (mr) {
195 while ((item=map_rect_get_item(mr))) {
196 struct coord c;
197 if ( item_coord_get_pro(item, &c, 1, this->c.pro) && coord_rect_contains(&sel->u.c_rect, &c) && (idist=transform_distance(this->c.pro, &center, &c)) < dist && item->type<type_line) {
198 char* label;
199 QString rs;
200 if (item_attr_get(item, attr_label, &attr)) {
202 if (QString(item_to_name(item->type)).startsWith(QString("poi_"))) {
203 rs=QString::fromLocal8Bit(item_to_name(item->type));
204 rs=rs.remove(QString("poi_"));
205 rs+=QString(" ")+QString::fromLocal8Bit(label);
206
207 } else if (QString(item_to_name(item->type)).startsWith(QString("poly_"))) {
208 rs=QString::fromLocal8Bit(item_to_name(item->type));
209 rs=rs.remove(QString("poly_"));
210 rs+=QString(" ")+QString::fromLocal8Bit(label);
211
212 } else if (QString(item_to_name(item->type)).startsWith(QString("street_"))) {
213 rs="Street ";
214 rs+=QString::fromLocal8Bit(label);
215 }
217 } else
220 if (rs.length()>0) {
221 QDomElement entry=retDoc.createElement("point");
222 QDomElement nameTag=retDoc.createElement("name");
223 QDomElement typeTag=retDoc.createElement("type");
224 QDomElement distTag=retDoc.createElement("distance");
225 QDomElement directTag=retDoc.createElement("direction");
226 QDomElement coordsTag=retDoc.createElement("coords");
227 QDomText nameT=retDoc.createTextNode(rs);
228 QDomText typeT=retDoc.createTextNode(QString(item_to_name(item->type)));
229 QDomText distT=retDoc.createTextNode(QString::number(idist/1000));
230 QDomText directT=retDoc.createTextNode(dirbuf);
231 QDomText coordsT=retDoc.createTextNode(QString("%1 %2").arg(c.x).arg(c.y));
232 nameTag.appendChild(nameT);
233 typeTag.appendChild(typeT);
234 distTag.appendChild(distT);
235 directTag.appendChild(directT);
236 coordsTag.appendChild(coordsT);
237 entry.appendChild(nameTag);
238 entry.appendChild(typeTag);
239 entry.appendChild(distTag);
240 entry.appendChild(directTag);
241 entry.appendChild(coordsTag);
242 entries.appendChild(entry);
243 }
244 }
245 }
246 }
248 }
250 mapset_close(h);
251 dbg(lvl_info,"%s",retDoc.toString().toLocal8Bit().constData());
252 return retDoc.toString();
253 }
254protected:
255 QDomElement _fieldValueHelper(QDomDocument doc, QString field,QString value) {
256 QDomElement fieldTag=doc.createElement(field);
257 QDomText valueText=doc.createTextNode(value);
258 fieldTag.appendChild(valueText);
259 return fieldTag;
260 }
261 QString _coordString() {
262 char latc='N',lngc='E';
263 int lat_deg,lat_min,lat_sec;
264 int lng_deg,lng_min,lng_sec;
265 struct coord_geo g=this->g;
266
267 if (g.lat < 0) {
268 g.lat=-g.lat;
269 latc='S';
270 }
271 if (g.lng < 0) {
272 g.lng=-g.lng;
273 lngc='W';
274 }
275 lat_deg=g.lat;
276 lat_min=fmod(g.lat*60,60);
277 lat_sec=fmod(g.lat*3600,60);
278 lng_deg=g.lng;
279 lng_min=fmod(g.lng*60,60);
280 lng_sec=fmod(g.lng*3600,60);
281 return QString(QString::fromLocal8Bit("%1°%2'%3\" %4%5%6°%7'%8\" %9")).arg(lat_deg).arg(lat_min).arg(lat_sec).arg(latc).arg(' ').arg(lng_deg).arg(lng_min).arg(lng_sec).arg(lngc);
282 }
283 QString _coordName() {
284 int dist=10;
285 struct mapset *ms;
286 struct mapset_handle *h;
287 struct map_rect *mr;
288 struct map *m;
289 struct item *item;
290 struct street_data *data;
291 struct map_selection sel;
292 struct transformation *trans;
293 enum projection pro;
294 struct attr attr;
295 char *label;
296 QString ret;
297
298 trans=navit_get_trans(this->object->nav);
299 pro=transform_get_projection(trans);
300 transform_from_geo(pro, &g, &co);
301 ms=navit_get_mapset(this->object->nav);
302 sel.next=NULL;
303 sel.u.c_rect.lu.x=c.x-dist;
304 sel.u.c_rect.lu.y=c.y+dist;
305 sel.u.c_rect.rl.x=c.x+dist;
306 sel.u.c_rect.rl.y=c.y-dist;
307 sel.order=18;
309 h=mapset_open(ms);
310 while ((m=mapset_next(h,1))) {
311 mr=map_rect_new(m, &sel);
312 if (! mr)
313 continue;
314 while ((item=map_rect_get_item(mr))) {
316 if (transform_within_dist_item(&co, item->type, data->c, data->count, dist)) {
317 if (item_attr_get(item, attr_label, &attr)) {
319 this->item=*item;
320 this->_setUrl(item);
321 if (QString(item_to_name(item->type)).startsWith(QString("poi_"))) {
322 ret=QString::fromLocal8Bit(item_to_name(item->type));
323 ret=ret.remove(QString("poi_"));
324 ret+=QString(" ")+QString::fromLocal8Bit(label);
325 }
326 if (QString(item_to_name(item->type)).startsWith(QString("poly_"))) {
327 ret=QString::fromLocal8Bit(item_to_name(item->type));
328 ret=ret.remove(QString("poly_"));
329 ret+=QString(" ")+QString::fromLocal8Bit(label);
330 }
331 if (QString(item_to_name(item->type)).startsWith(QString("street_"))) {
332 ret="Street ";
333 ret+=QString::fromLocal8Bit(label);
334 }
338 mapset_close(h);
339 return ret;
340 } else
341 this->item=*item;
342 this->_setUrl(item);
343 ret=item_to_name(item->type);
344 }
346 }
348 }
349 mapset_close(h);
350 return ret;
351 }
352 void _setUrl(struct item *item) {
353 struct attr attr;
354 if (item_attr_get(item,attr_osm_nodeid,&attr)) {
355 url.setUrl(QString("http://www.openstreetmap.org/browse/node/%1").arg(*attr.u.num64));
356 } else if (item_attr_get(item,attr_osm_wayid,&attr)) {
357 url.setUrl(QString("http://www.openstreetmap.org/browse/way/%1").arg(*attr.u.num64));
358 } else if (item_attr_get(item,attr_osm_relationid,&attr)) {
359 url.setUrl(QString("http://www.openstreetmap.org/browse/relation/%1").arg(*attr.u.num64));
360 } else {
361 url.clear();
362 }
363 }
364private:
366
368 struct coord_geo g;
369 struct coord co;
370 struct pcoord c;
371 struct point p;
372
373 struct item item;
374
375 QString name;
376 QString coord;
377 QUrl url;
378};
379
380#include "ngqpoint.moc"
381
382#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:34
QString coordString()
Definition ngqpoint.h:121
QString _coordName()
Definition ngqpoint.h:283
QString name
Definition ngqpoint.h:375
NGQPoint(struct gui_priv *this_, struct coord *c, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition ngqpoint.h:57
void _setUrl(struct item *item)
Definition ngqpoint.h:352
QString coord
Definition ngqpoint.h:376
struct point p
Definition ngqpoint.h:371
QString pointType()
Definition ngqpoint.h:124
NGQPoint(struct gui_priv *this_, struct point *p, NGQPointTypes type=MapPoint, QObject *parent=NULL)
Definition ngqpoint.h:42
struct pcoord * pc()
Definition ngqpoint.h:102
struct item item
Definition ngqpoint.h:373
NGQPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition ngqpoint.h:72
QString pointName
Definition ngqpoint.h:38
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition ngqpoint.h:255
struct coord_geo g
Definition ngqpoint.h:368
QString pointType
Definition ngqpoint.h:39
QUrl pointUrl()
Definition ngqpoint.h:139
QString _coordString()
Definition ngqpoint.h:261
QString getInformation()
Definition ngqpoint.h:142
NGQPointTypes type
Definition ngqpoint.h:367
void setNewPoint(QString coord, NGQPointTypes type=PointOfInterest)
Definition ngqpoint.h:104
QUrl url
Definition ngqpoint.h:377
NGQPoint(struct gui_priv *this_, struct coord *c, QString name, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition ngqpoint.h:87
struct pcoord c
Definition ngqpoint.h:370
struct gui_priv * object
Definition ngqpoint.h:365
QString coordString
Definition ngqpoint.h:37
QUrl pointUrl
Definition ngqpoint.h:40
QString getPOI(const QString &attr_name)
Definition ngqpoint.h:164
QString pointName()
Definition ngqpoint.h:118
struct coord co
Definition ngqpoint.h:369
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:5
NGQPointTypes
Definition ngqpoint.h:32
@ Position
Definition ngqpoint.h:32
@ Bookmark
Definition ngqpoint.h:32
@ Destination
Definition ngqpoint.h:32
@ MapPoint
Definition ngqpoint.h:32
@ PointOfInterest
Definition ngqpoint.h:32
projection
Definition projection.h:23
void street_data_free(struct street_data *sd)
Frees street data.
Definition route.c:3353
static void street_get_data(struct street_priv *street, unsigned char **p)
Definition street.c:355
Definition attr.c:48
Definition attr.h:136
long long * num64
Definition attr.h:191
char * str
Definition attr.h:139
union attr::@0 u
enum attr_type type
Definition attr.h:137
long num
Definition attr.h:141
Definition maptool.h:169
A WGS84 coordinate.
Definition coord.h:97
navit_float lat
Definition coord.h:99
navit_float lng
Definition coord.h:98
struct coord rl
Definition coord.h:60
struct coord lu
Definition coord.h:59
Definition coord.h:34
int y
Definition coord.h:36
int x
Definition coord.h:35
Definition graphics_win32.h:52
struct navit * nav
Definition graphics_win32.h:53
struct gui * gui
Definition gui_qml.cpp:40
Represents an object on a map.
Definition item.h:124
int id_hi
Definition item.h:126
enum item_type type
Definition item.h:125
struct map * map
Definition item.h:128
Definition map.c:62
Used to select data from a map.
Definition map.h:58
int order
Definition map.h:64
struct map_selection * next
Definition map.h:59
union map_selection::@4 u
struct item_range range
Definition map.h:65
struct coord_rect c_rect
Definition map.h:61
Definition map.c:55
Handle for a mapset in use.
Definition mapset.c:150
Definition mapset.c:39
Definition gpx2navit_txt.h:51
Definition coord.h:52
int y
Definition coord.h:55
enum projection pro
Definition coord.h:53
int x
Definition coord.h:54
Definition point.h:23
int y
Definition point.h:25
int x
Definition point.h:24
Information about a street.
Definition route.h:66
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