Navit SVN

/work/compile/navit/src/navit/gui/qml/navitProxy.h

00001 #ifndef NAVIT_GUI_QML_NAVIT_H
00002 #define NAVIT_GUI_QML_NAVIT_H
00003 
00004 void __setNewPoint(struct gui_priv* this_,struct coord* c, NGQPointTypes type);
00005 
00006 class NGQProxyNavit : public NGQProxy {
00007     Q_OBJECT;
00008 
00009 public:
00010         NGQProxyNavit(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { };
00011 
00012 public slots:
00013         void quit() {
00014                 struct attr navit;
00015                 navit.type=attr_navit;
00016                 navit.u.navit=this->object->nav;
00017                 navit_destroy(navit.u.navit);
00018                 event_main_loop_quit();
00019         }
00020         void setObjectByName(const QString& attr_name,const QString& attr_value) {
00021                 if (attr_name=="layout") {
00022                         navit_set_layout_by_name(this->object->nav,attr_value.toStdString().c_str());
00023                 }
00024                 if (attr_name=="vehicle") {
00025                         navit_set_vehicle_by_name(this->object->nav,attr_value.toStdString().c_str());
00026                 }
00027                 return;
00028         }
00029         QString getAttrList(const QString &attr_name) {
00030                 struct attr attr;
00031                 struct attr_iter *iter;
00032                 int counter=0;
00033                 QString currentValue;
00034                 QDomDocument retDoc;
00035                 QDomElement entries;
00036 
00037                 entries=retDoc.createElement("attributes");
00038                 retDoc.appendChild(entries);
00039 
00040                 //Find current value
00041                 getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL) ;
00042                 if (attr.type==attr_layout) {
00043                         currentValue=attr.u.layout->name;
00044                 }
00045 
00046                 //Fill da list
00047                 iter=getIterFunc();
00048                 if (iter == NULL) {
00049                         return QString();
00050                 }
00051 
00052                 while (getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, iter) ) {
00053                         QStandardItem* curItem=new QStandardItem();
00054                         //Listed attributes are usualy have very complex structure      
00055                         if (attr.type==attr_layout) {
00056                                 curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
00057                                 curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemName);
00058                                 curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemValue);
00059                                 if (currentValue==attr.u.layout->name) {
00060                                         this->_itemId=counter;
00061                                 }
00062                         }
00063                         if (attr.type==attr_vehicle) {
00064                                 QStandardItem* curItem=new QStandardItem();
00065                                 QDomElement entry=retDoc.createElement("vehicle");
00066                                 entries.appendChild(entry);
00067 
00068                                 this->object->currVehicle=attr.u.vehicle;
00069                                 curItem->setData(QVariant(this->object->vehicleProxy->getAttr("name")),NGQStandardItemModel::ItemName);
00070                                 entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
00071                                 entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"), QString(this->object->vehicleProxy->getAttr("name"))));
00072 
00073                                 //Detecting current vehicle
00074                                 struct attr vehicle_attr;
00075                                 navit_get_attr(this->object->nav, attr_vehicle, &vehicle_attr, NULL);
00076                                 if (vehicle_attr.u.vehicle==attr.u.vehicle) {
00077                                         this->_itemId=counter;
00078                                 }
00079                         }
00080                         counter++;
00081                 }
00082 
00083                 dropIterFunc(iter);
00084 
00085                 dbg(0,QString::number(_itemId).toStdString().c_str());
00086 
00087                 return retDoc.toString();
00088         }
00089         QString getDestination() {
00090                 struct attr attr;
00091                 struct coord c;
00092 
00093                 if (getAttrFunc(attr_destination, &attr, NULL) ) {
00094                         c.x=attr.u.pcoord->x;
00095                         c.y=attr.u.pcoord->y;
00096                         __setNewPoint(this->object,&c,Destination);
00097                         return this->object->currentPoint->pointName();
00098                 }
00099                 return QString();
00100         }
00101         void setDestination() {
00102                 navit_set_destination(this->object->nav,this->object->currentPoint->pc(),this->object->currentPoint->coordString().toStdString().c_str(),1);
00103         }
00104         void stopNavigation() {
00105                 navit_set_destination(this->object->nav,NULL,NULL,0);
00106         }
00107         QString getPosition() {
00108                 struct attr attr;
00109                 struct pcoord pc;
00110                 struct coord c;
00111                 struct transformation *trans;
00112 
00113                 trans=navit_get_trans(this->object->nav);
00114 
00115                 getAttrFunc(attr_vehicle, &attr, NULL);
00116                 this->object->currVehicle=attr.u.vehicle;
00117 
00118                 if (vehicle_get_attr(this->object->currVehicle, attr_position_coord_geo, &attr, NULL)) {
00119                    pc.pro=transform_get_projection(trans);
00120                    transform_from_geo(pc.pro, attr.u.coord_geo, &c);
00121                    __setNewPoint(this->object,&c,Position);
00122                    return this->object->currentPoint->pointName();
00123                 }
00124                 return QString();
00125         }
00126         void setPosition() {
00127                 navit_set_position(this->object->nav,this->object->currentPoint->pc());
00128         }
00129         void setCenter() {
00130                 navit_set_center(this->object->nav,this->object->currentPoint->pc(),1);
00131         }
00132         void command(QString command) {
00133                 struct attr navit;
00134                 navit.type=attr_navit;
00135                 navit.u.navit=this->object->nav;
00136                 command_evaluate(&navit,command.toLocal8Bit().constData());
00137         }
00138 protected:
00139         int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return navit_get_attr(this->object->nav, type, attr, iter); }
00140         int setAttrFunc(struct attr* attr) {return navit_set_attr(this->object->nav,attr); }
00141         struct attr_iter* getIterFunc() { return navit_attr_iter_new(); };
00142         void dropIterFunc(struct attr_iter* iter) { navit_attr_iter_destroy(iter); };
00143 
00144 private:
00145 
00146 };
00147 
00148 #include "navitProxy.moc"
00149 
00150 #endif /* NAVIT_GUI_QML_NAVITPROXY_H */