navit  0.5.1-trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups
navitProxy.h
Go to the documentation of this file.
1 #ifndef NAVIT_GUI_QML_NAVIT_H
2 #define NAVIT_GUI_QML_NAVIT_H
3 
4 void __setNewPoint(struct gui_priv* this_,struct coord* c, NGQPointTypes type);
5 
6 class NGQProxyNavit : public NGQProxy {
7  Q_OBJECT;
8 
9 public:
10  NGQProxyNavit(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { };
11 
12 public slots:
13  void quit() {
14  struct attr navit;
15  navit.type=attr_navit;
16  navit.u.navit=this->object->nav;
17  navit_destroy(navit.u.navit);
19  }
20  void setObjectByName(const QString& attr_name,const QString& attr_value) {
21  if (attr_name=="layout") {
22  navit_set_layout_by_name(this->object->nav,attr_value.toStdString().c_str());
23  }
24  if (attr_name=="vehicle") {
25  navit_set_vehicle_by_name(this->object->nav,attr_value.toStdString().c_str());
26  }
27  return;
28  }
29  QString getAttrList(const QString &attr_name) {
30  struct attr attr;
31  struct attr_iter *iter;
32  int counter=0;
33  QString currentValue;
34  QDomDocument retDoc;
35  QDomElement entries;
36 
37  entries=retDoc.createElement("attributes");
38  retDoc.appendChild(entries);
39 
40  //Find current value
41  getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL) ;
42  if (attr.type==attr_layout) {
43  currentValue=attr.u.layout->name;
44  }
45 
46  //Fill da list
47  iter=getIterFunc();
48  if (iter == NULL) {
49  return QString();
50  }
51 
52  while (getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, iter) ) {
53  QStandardItem* curItem=new QStandardItem();
54  //Listed attributes are usualy have very complex structure
55  if (attr.type==attr_layout) {
56  curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
57  curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemName);
58  curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemValue);
59  if (currentValue==attr.u.layout->name) {
60  this->_itemId=counter;
61  }
62  }
63  if (attr.type==attr_vehicle) {
64  QStandardItem* curItem=new QStandardItem();
65  QDomElement entry=retDoc.createElement("vehicle");
66  entries.appendChild(entry);
67 
68  this->object->currVehicle=attr.u.vehicle;
69  curItem->setData(QVariant(this->object->vehicleProxy->getAttr("name")),NGQStandardItemModel::ItemName);
70  entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
71  entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"), QString(this->object->vehicleProxy->getAttr("name"))));
72 
73  //Detecting current vehicle
74  struct attr vehicle_attr;
75  navit_get_attr(this->object->nav, attr_vehicle, &vehicle_attr, NULL);
76  if (vehicle_attr.u.vehicle==attr.u.vehicle) {
77  this->_itemId=counter;
78  }
79  }
80  counter++;
81  }
82 
83  dropIterFunc(iter);
84 
85  dbg(lvl_debug,QString::number(_itemId).toStdString().c_str());
86 
87  return retDoc.toString();
88  }
89  QString getDestination() {
90  struct attr attr;
91  struct coord c;
92 
93  if (getAttrFunc(attr_destination, &attr, NULL) ) {
94  c.x=attr.u.pcoord->x;
95  c.y=attr.u.pcoord->y;
96  __setNewPoint(this->object,&c,Destination);
97  return this->object->currentPoint->pointName();
98  }
99  return QString();
100  }
101  void setDestination() {
102  navit_set_destination(this->object->nav,this->object->currentPoint->pc(),this->object->currentPoint->coordString().toStdString().c_str(),1);
103  }
104  void stopNavigation() {
105  navit_set_destination(this->object->nav,NULL,NULL,0);
106  }
107  QString getPosition() {
108  struct attr attr;
109  struct pcoord pc;
110  struct coord c;
111  struct transformation *trans;
112 
113  trans=navit_get_trans(this->object->nav);
114 
115  getAttrFunc(attr_vehicle, &attr, NULL);
116  this->object->currVehicle=attr.u.vehicle;
117 
118  if (vehicle_get_attr(this->object->currVehicle, attr_position_coord_geo, &attr, NULL)) {
119  pc.pro=transform_get_projection(trans);
120  transform_from_geo(pc.pro, attr.u.coord_geo, &c);
121  __setNewPoint(this->object,&c,Position);
122  return this->object->currentPoint->pointName();
123  }
124  return QString();
125  }
126  void setPosition() {
127  navit_set_position(this->object->nav,this->object->currentPoint->pc());
128  }
129  void setCenter() {
130  navit_set_center(this->object->nav,this->object->currentPoint->pc(),1);
131  }
132  void command(QString command) {
133  struct attr navit;
134  navit.type=attr_navit;
135  navit.u.navit=this->object->nav;
136  command_evaluate(&navit,command.toLocal8Bit().constData());
137  }
138 protected:
139  int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return navit_get_attr(this->object->nav, type, attr, iter); }
140  int setAttrFunc(struct attr* attr) {return navit_set_attr(this->object->nav,attr); }
141  struct attr_iter* getIterFunc() { return navit_attr_iter_new(); };
143 
144 private:
145 
146 };
147 
148 #include "navitProxy.moc"
149 
150 #endif /* NAVIT_GUI_QML_NAVITPROXY_H */
attr_type
Definition: attr.h:34
Definition: proxy.h:16
struct coord_geo * coord_geo
Definition: attr.h:167
tuple iter
Definition: eval.py:8
Definition: gpx2navit_txt.h:51
int y
Definition: coord.h:36
int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: navit.c:2736
Definition: attr.c:47
int _itemId
Definition: proxy.h:91
void event_main_loop_quit(void)
Definition: event.c:53
enum projection pro
Definition: coord.h:41
int vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: vehicle.c:215
void navit_attr_iter_destroy(struct attr_iter *iter)
Definition: navit.c:3062
Definition: navitProxy.h:6
int y
Definition: coord.h:43
Definition: proxy.h:16
struct pcoord * pcoord
Definition: attr.h:180
QString getAttr(const QString &attr_name)
Definition: proxy.h:35
NGQProxyNavit(struct gui_priv *object, QObject *parent)
Definition: navitProxy.h:10
int navit_set_layout_by_name(struct navit *n, const char *name)
Definition: navit.c:3585
struct vehicle * currVehicle
Definition: gui_qml.cpp:42
int x
Definition: coord.h:42
void navit_set_position(struct navit *this_, struct pcoord *c)
Definition: navit.c:3272
Definition: graphics_win32.h:52
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition: proxy.h:98
struct navit * navit
Definition: attr.h:168
void setPosition()
Definition: navitProxy.h:126
#define dbg(level,...)
Definition: debug.h:59
Definition: debug.h:52
void command(QString command)
Definition: navitProxy.h:132
void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
Definition: navit.c:1578
QString getPosition()
Definition: navitProxy.h:107
Definition: config_.c:48
union attr::@0 u
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
Definition: attr.h:156
void dropIterFunc(struct attr_iter *iter)
Definition: navitProxy.h:142
int navit_set_vehicle_by_name(struct navit *n, const char *name)
Definition: navit.c:3561
enum attr_type type
Definition: attr.h:157
QString getAttrList(const QString &attr_name)
Definition: navitProxy.h:29
void command_evaluate(struct attr *attr, const char *expr)
Definition: command.c:1553
void setDestination()
Definition: navitProxy.h:101
Definition: ngqpoint.h:32
void setCenter()
Definition: navitProxy.h:129
void navit_destroy(struct navit *this_)
Definition: navit.c:3669
struct transformation * navit_get_trans(struct navit *this_)
Definition: navit.c:3387
int setAttrFunc(struct attr *attr)
Definition: navitProxy.h:140
struct attr_iter * navit_attr_iter_new(void)
Definition: navit.c:3056
NGQPointTypes
Definition: ngqpoint.h:32
Definition: ngqpoint.h:32
int navit_set_attr(struct navit *this_, struct attr *attr)
Definition: navit.c:2730
class NGQProxyVehicle * vehicleProxy
Definition: gui_qml.cpp:76
void navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
Definition: navit.c:2293
Definition: proxy.h:16
struct layout * layout
Definition: attr.h:172
struct gui_priv * object
Definition: proxy.h:89
QString getDestination()
Definition: navitProxy.h:89
static GtkActionEntry entries[]
Definition: gui_gtk_action.c:224
struct vehicle * vehicle
Definition: attr.h:171
enum projection transform_get_projection(struct transformation *this_)
Definition: transform.c:730
char type[3]
Definition: garmin_img.c:130
Definition: coord.h:34
Definition: coord.h:40
int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: navitProxy.h:139
Definition: proxy.h:21
struct attr_iter * getIterFunc()
Definition: navitProxy.h:141
The parameters needed to transform a map for display.
Definition: transform.c:64
void quit()
Definition: navitProxy.h:13
void setObjectByName(const QString &attr_name, const QString &attr_value)
Definition: navitProxy.h:20
enum attr_type attr_from_name(const char *name)
Converts a string to an attr_type.
Definition: attr.c:96
void stopNavigation()
Definition: navitProxy.h:104
int x
Definition: coord.h:35
char * name
Definition: layout.h:98