Add:gui/qml:Added vehicle switch support
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 16 Mar 2010 16:00:16 +0000 (16:00 +0000)
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 16 Mar 2010 16:00:16 +0000 (16:00 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3023 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/gui/qml/gui_qml.cpp
navit/navit/gui/qml/proxy.h
navit/navit/gui/qml/skins/navit/PageSettings.qml
navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml [new file with mode: 0644]

index 6ae47ae..66f8be9 100644 (file)
@@ -19,6 +19,7 @@
 #include "event.h"
 #include "map.h"
 #include "coord.h"
+#include "vehicle.h"
 
 //WORKAOUND for the c/c++ compatibility issues.
 //range is defined inside of struct attr so it is invisible in c++
@@ -32,6 +33,7 @@ struct gui_priv {
        struct navit *nav;
        struct gui *gui;
        struct attr self;
+       struct vehicle* currVehicle;
        
        //configuration items
        int fullscreen;
@@ -59,6 +61,7 @@ struct gui_priv {
        //Proxy objects
        class NGQProxyGui* guiProxy;
        class NGQProxyNavit* navitProxy;
+       class NGQProxyVehicle* vehicleProxy;
 };
 
 #include "proxy.h"
@@ -138,6 +141,25 @@ private:
        QString source;
 };
 
+
+class NGQProxyVehicle : public NGQProxy {
+    Q_OBJECT;
+
+public:
+       NGQProxyVehicle(struct gui_priv* object, QObject* parent) : NGQProxy(object,parent) { };
+
+public slots:
+
+protected:
+       int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return vehicle_get_attr(this->object->currVehicle, type, attr, iter); }
+       int setAttrFunc(struct attr* attr) {return vehicle_set_attr(this->object->currVehicle,attr); }
+       struct attr_iter* getIterFunc() { return vehicle_attr_iter_new(); };
+       void dropIterFunc(struct attr_iter* iter) { vehicle_attr_iter_destroy(iter); };
+
+private:
+
+};
+
 class NGQProxyNavit : public NGQProxy {
     Q_OBJECT;
 
@@ -157,8 +179,58 @@ public slots:
                if (attr_name=="layout") {
                        navit_set_layout_by_name(this->object->nav,attr_value.toStdString().c_str());
                }
+               if (attr_name=="vehicle") {
+                       navit_set_vehicle_by_name(this->object->nav,attr_value.toStdString().c_str());
+               }
                return;
        }
+       QString getAttrList(const QString &attr_name) {
+               NGQStandardItemModel* ret=new NGQStandardItemModel(this);
+               struct attr attr;
+               struct attr_iter *iter;
+               int counter=0;
+               QString currentValue, retId;
+
+               //Find current value
+               getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL) ;
+               if (attr.type==attr_layout) {
+                       currentValue=attr.u.layout->name;
+               }
+
+               //Fill da list
+               iter=getIterFunc();
+               if (iter == NULL) {
+                       return retId;
+               }
+
+               while (getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, iter) ) {
+                       QStandardItem* curItem=new QStandardItem();
+                       //Listed attributes are usualy have very complex structure      
+                       if (attr.type==attr_layout) {
+                               curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
+                               curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemName);
+                               if (currentValue==attr.u.layout->name) {
+                                       retId.setNum(counter);
+                               }
+                       }
+                       if (attr.type==attr_vehicle) {
+                               this->object->currVehicle=attr.u.vehicle;
+                               curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
+                               curItem->setData(QVariant(this->object->vehicleProxy->getAttr("name")),NGQStandardItemModel::ItemName);
+                               retId.setNum(0);
+                       }
+                       counter++;
+                       ret->appendRow(curItem);
+               }
+
+               dropIterFunc(iter);
+
+               this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast<QObject*>(ret));
+
+               dbg(0,"retId %s \n",retId.toStdString().c_str());
+
+               return retId;
+       }
        
 protected:
        int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return navit_get_attr(this->object->nav, type, attr, iter); }
@@ -263,6 +335,8 @@ static int gui_qml_set_graphics(struct gui_priv *this_, struct graphics *gra)
        view->rootContext()->setContextProperty("gui",this_->guiProxy);
        this_->navitProxy = new NGQProxyNavit(this_,this_->mainWindow);
        view->rootContext()->setContextProperty("navit",this_->navitProxy);
+       this_->vehicleProxy = new NGQProxyVehicle(this_,this_->mainWindow);
+       view->rootContext()->setContextProperty("vehicle",this_->vehicleProxy);
                
        //Check, if we have compatible graphics
        this_->graphicsWidget = (QWidget*)graphics_get_data(gra,"qt_widget");
index b6e5f7d..ba32c5b 100644 (file)
@@ -44,47 +44,6 @@ public slots:
                }
                return ret;
        }
-       QString getAttrList(const QString &attr_name) {
-               NGQStandardItemModel* ret=new NGQStandardItemModel(this);
-               struct attr attr;
-               struct attr_iter *iter;
-               int counter=0;
-               QString currentValue, retId;
-
-               //Find current value
-               getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL) ;
-               if (attr.type==attr_layout) {
-                       currentValue=attr.u.layout->name;
-               }
-
-               //Fill da list
-               iter=getIterFunc();
-               if (iter == NULL) {
-                       return retId;
-               }
-
-               while (getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, iter) ) {
-                       QStandardItem* curItem=new QStandardItem();
-                       //Listed attributes are usualy have very complex structure      
-                       if (attr.type==attr_layout) {
-                               curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
-                               curItem->setData(QVariant(attr.u.layout->name),NGQStandardItemModel::ItemName);
-                               if (currentValue==attr.u.layout->name) {
-                                       retId.setNum(counter);
-                               }
-                               counter++;
-                       }
-                       ret->appendRow(curItem);
-               }
-
-               dropIterFunc(iter);
-
-               this->object->guiWidget->rootContext()->setContextProperty("listModel",static_cast<QObject*>(ret));
-
-               dbg(0,"retId %s \n",retId.toStdString().c_str());
-
-               return retId;
-       }
        void setAttr(const QString &attr_name, const QString &attr_string) {
                        struct attr attr_value;
                        double *helper;
index e737df4..718ea02 100644 (file)
@@ -30,7 +30,7 @@ Rectangle {
             id: btnMap; text: "Map"; icon: "gui_maps.svg"; onClicked: console.log("Implement me!");\r
         }\r
         ButtonIcon {\r
-            id: btnVehicle; text: "Vehicle"; icon: "gui_vehicle.svg"; onClicked: console.log("Implement me!");\r
+            id: btnVehicle; text: "Vehicle"; icon: "gui_vehicle.svg"; onClicked: { gui.returnSource="PageSettings.qml"; gui.setPage("PageSettingsVehicle.qml") }
         }\r
     }\r
     Grid {\r
diff --git a/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml b/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml
new file mode 100644 (file)
index 0000000..31a2c6f
--- /dev/null
@@ -0,0 +1,34 @@
+import Qt 4.6
+
+Rectangle {
+    id: page
+
+    width: 800; height: 424
+    border.width: 1
+    color: "Black"
+    opacity: 0
+
+    function pageOpen() {
+        page.opacity = 1;
+    }
+    
+    Component.onCompleted: pageOpen();    
+    
+    opacity: Behavior {
+        NumberAnimation { id: opacityAnimation; duration: 300; alwaysRunToEnd: true }
+    }
+
+       ListSelector { 
+               id:vehicleList; text: "Current vehicle profile"; itemId: navit.getAttrList("vehicle"); onChanged: {navit.setObjectByName("vehicle",vehicleList.value) }
+               anchors.top: parent.top; anchors.topMargin: 48
+               anchors.horizontalCenter: parent.horizontalCenter;              
+       }
+
+       ButtonIcon {
+            id: btnVehicle; text: "Vehicle options"; icon: "gui_vehicle.svg"; onClicked: { gui.returnSource="PageSettingsVehicle.qml"; gui.setPage("PageSettingsVehicleOptions.qml") }
+           anchors.top: vehicleList.bottom; anchors.topMargin: 48
+           anchors.right: page.horizontalCenter;
+        }
+
+    Cellar {anchors.bottom: page.bottom; anchors.horizontalCenter: page.horizontalCenter; width: page.width }
+}