navit  0.5.1-trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups
ngqpoint.h
Go to the documentation of this file.
1 #ifndef NAVIT_GUI_QML_POINT_H
2 #define NAVIT_GUI_QML_POINT_H
3 
4 static void
5 get_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 
34 class 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);
41 public:
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;
63  this->c.pro = transform_get_projection(navit_get_trans(this->object->nav));
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;
93  this->c.pro = transform_get_projection(navit_get_trans(this->object->nav));
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; }
103 public 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  }
160  map_rect_destroy(mr);
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)) {
201  label=map_convert_string(m, attr.u.str);
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  }
216  map_convert_free(label);
217  } else
218  rs=item_to_name(item->type);
219  get_direction(dirbuf, transform_get_angle_delta(&center, &c, 0), 1);
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  }
247  map_selection_destroy(selm);
248  }
250  mapset_close(h);
251  dbg(lvl_info,"%s",retDoc.toString().toLocal8Bit().constData());
252  return retDoc.toString();
253  }
254 protected:
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;
308  sel.range=item_range_all;
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))) {
315  data=street_get_data(item);
316  if (transform_within_dist_item(&co, item->type, data->c, data->count, dist)) {
317  if (item_attr_get(item, attr_label, &attr)) {
318  label=map_convert_string(m, attr.u.str);
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  }
335  map_convert_free(label);
336  street_data_free(data);
337  map_rect_destroy(mr);
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  }
345  street_data_free(data);
346  }
347  map_rect_destroy(mr);
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  }
364 private:
365  struct gui_priv* object;
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 */
void map_convert_free(char *str)
Frees the memory allocated for a converted string.
Definition: map.c:266
QString coord
Definition: ngqpoint.h:376
QString getInformation()
Definition: ngqpoint.h:142
Definition: debug.h:50
struct gui * gui
Definition: gui_qml.cpp:40
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:327
struct coord co
Definition: ngqpoint.h:369
struct map * map
Definition: item.h:103
static void get_direction(char *buffer, int angle, int mode)
Definition: ngqpoint.h:5
Definition: gpx2navit_txt.h:51
Definition: ngqpoint.h:32
void transform_to_geo(enum projection pro, struct coord *c, struct coord_geo *g)
Definition: transform.c:283
int y
Definition: coord.h:36
void _setUrl(struct item *item)
Definition: ngqpoint.h:352
Definition: attr.c:47
QString getPOI(const QString &attr_name)
Definition: ngqpoint.h:164
void map_selection_destroy(struct map_selection *sel)
Destroys a map selection.
Definition: map.c:584
int transform_get_angle_delta(struct coord *c1, struct coord *c2, int dir)
Gets the bearing from one point to another.
Definition: transform.c:1463
struct coord_rect c_rect
Definition: map.h:60
Definition: item.h:99
enum projection pro
Definition: coord.h:41
NGQPoint(struct gui_priv *this_, struct point *p, NGQPointTypes type=MapPoint, QObject *parent=NULL)
Definition: ngqpoint.h:42
struct map * mapset_next(struct mapset_handle *msh, int active)
Gets the next map from a mapset handle.
Definition: mapset.c:203
A mapset.
Definition: mapset.c:44
int y
Definition: coord.h:43
QString name
Definition: ngqpoint.h:375
navit_float lng
Definition: coord.h:86
struct point p
Definition: ngqpoint.h:371
int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: gui.c:63
QString pointType()
Definition: ngqpoint.h:124
enum projection map_projection(struct map *this_)
Returns the projection of a map.
Definition: map.c:278
union map_selection::@8 u
char * map_convert_string(struct map *this_, char *str)
Converts a string from a map.
Definition: map.c:244
struct item_range range
Definition: map.h:64
enum item_type type
Definition: item.h:100
void street_data_free(struct street_data *sd)
Frees street data.
Definition: route.c:3169
static GValue value
Definition: datawindow.c:42
int x
Definition: point.h:24
Definition: ngqpoint.h:32
int x
Definition: coord.h:42
char * item_to_name(enum item_type item)
Definition: item.c:405
struct mapset * navit_get_mapset(struct navit *this_)
Definition: navit.c:216
Definition: graphics_win32.h:52
enum projection pro
Definition: transform.c:87
int transform_within_dist_item(struct coord *ref, enum item_type type, struct coord *c, int count, int dist)
Definition: transform.c:1592
int mode
Definition: graphics_win32.c:59
NGQPoint(struct gui_priv *this_, struct coord *c, QString name, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition: ngqpoint.h:87
struct coord lu
Definition: coord.h:47
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:374
Handle for a mapset in use.
Definition: mapset.c:167
#define dbg(level,...)
Definition: debug.h:59
NGQPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition: ngqpoint.h:72
QString pointName()
Definition: ngqpoint.h:118
QString _coordName()
Definition: ngqpoint.h:283
void mapset_close(struct mapset_handle *msh)
Closes a mapset handle after it is no longer used.
Definition: mapset.c:269
projection
Definition: projection.h:23
struct gui_priv * object
Definition: ngqpoint.h:365
struct coord c[0]
Definition: route.h:71
struct map_selection * next
Definition: map.h:58
struct pcoord c
Definition: ngqpoint.h:370
Describes a rectangular extract of a map.
Definition: map.c:72
Information about a street.
Definition: route.h:66
union attr::@0 u
NGQPoint(struct gui_priv *this_, struct coord *c, NGQPointTypes type=Bookmark, QObject *parent=NULL)
Definition: ngqpoint.h:57
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:498
long num
Definition: attr.h:161
void map_rect_destroy(struct map_rect *mr)
Destroys a map rect.
Definition: map.c:392
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:261
struct item item
Definition: ngqpoint.h:373
void transform_from_geo(enum projection pro, struct coord_geo *g, struct coord *c)
Definition: transform.c:312
struct navit * nav
Definition: graphics_win32.h:53
struct item * map_rect_get_item(struct map_rect *mr)
Gets the next item from a map rect.
Definition: map.c:353
struct pcoord * pc()
Definition: ngqpoint.h:102
char data
Definition: garmin_img.c:354
Definition: attr.h:156
struct mapset_handle * mapset_open(struct mapset *ms)
Returns a new handle for a mapset.
Definition: mapset.c:181
Used to select data from a map.
Definition: map.h:57
enum attr_type type
Definition: attr.h:157
struct map_rect * map_rect_new(struct map *m, struct map_selection *sel)
Creates a new map rect.
Definition: map.c:325
struct map_selection * map_selection_rect_new(struct pcoord *center, int distance, int order)
Creates a new rectangular map selection.
Definition: map.c:523
void setNewPoint(QString coord, NGQPointTypes type=PointOfInterest)
Definition: ngqpoint.h:104
Definition: ngqpoint.h:32
QUrl pointUrl()
Definition: ngqpoint.h:139
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition: ngqpoint.h:255
struct transformation * navit_get_trans(struct navit *this_)
Definition: navit.c:3387
Definition: point.h:23
int order
Definition: map.h:63
struct coord_geo g
Definition: ngqpoint.h:368
char * str
Definition: attr.h:159
Holds information about a map.
Definition: map.c:60
long long * num64
Definition: attr.h:209
Definition: ngqpoint.h:32
NGQPointTypes
Definition: ngqpoint.h:32
Definition: ngqpoint.h:32
NGQPointTypes type
Definition: ngqpoint.h:367
navit_float lat
Definition: coord.h:87
Definition: maptool.h:168
int coord_rect_contains(struct coord_rect *r, struct coord *c)
Definition: coord.c:120
int count
Definition: route.h:68
struct item_range item_range_all
Definition: item.c:34
Definition: ngqpoint.h:34
static GtkActionEntry entries[]
Definition: gui_gtk_action.c:224
struct coord rl
Definition: coord.h:48
struct label_data_offset label
Definition: garmin_img.c:409
enum projection transform_get_projection(struct transformation *this_)
Definition: transform.c:730
Definition: coord.h: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:547
QString _coordString()
Definition: ngqpoint.h:261
double transform_distance(enum projection pro, struct coord *c1, struct coord *c2)
Definition: transform.c:1100
Definition: coord.h:40
QUrl url
Definition: ngqpoint.h:377
A WGS84 coordinate.
Definition: coord.h:85
int y
Definition: point.h:25
QString coordString()
Definition: ngqpoint.h:121
static void street_get_data(struct street_priv *street, unsigned char **p)
Definition: street.c:379
The parameters needed to transform a map for display.
Definition: transform.c:64
int transform_reverse(struct transformation *t, struct point *p, struct coord *c)
Definition: transform.c:706
char * attr_to_name(enum attr_type attr)
Converts an attr_type to a string.
Definition: attr.c:123
int id_hi
Definition: item.h:101
int x
Definition: coord.h:35