/[zanavi_public1]/navit/navit/gui/qml/navitProxy.h
ZANavi

Contents of /navit/navit/gui/qml/navitProxy.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 4724 byte(s)
import files
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);
18 event_main_loop_quit();
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(0,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(); };
142 void dropIterFunc(struct attr_iter* iter) { navit_attr_iter_destroy(iter); };
143
144 private:
145
146 };
147
148 #include "navitProxy.moc"
149
150 #endif /* NAVIT_GUI_QML_NAVITPROXY_H */

   
Visit the ZANavi Wiki