From f3436da860737f75362e33761d5995c7078bb2af Mon Sep 17 00:00:00 2001 From: akashihi Date: Tue, 16 Mar 2010 16:00:16 +0000 Subject: [PATCH] Add:gui/qml:Added vehicle switch support git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3023 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/gui/qml/gui_qml.cpp | 74 ++++++++++++++++++++++ navit/navit/gui/qml/proxy.h | 41 ------------ navit/navit/gui/qml/skins/navit/PageSettings.qml | 2 +- .../gui/qml/skins/navit/PageSettingsVehicle.qml | 34 ++++++++++ 4 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp index 6ae47ae..66f8be9 100644 --- a/navit/navit/gui/qml/gui_qml.cpp +++ b/navit/navit/gui/qml/gui_qml.cpp @@ -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(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"); diff --git a/navit/navit/gui/qml/proxy.h b/navit/navit/gui/qml/proxy.h index b6e5f7d..ba32c5b 100644 --- a/navit/navit/gui/qml/proxy.h +++ b/navit/navit/gui/qml/proxy.h @@ -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(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; diff --git a/navit/navit/gui/qml/skins/navit/PageSettings.qml b/navit/navit/gui/qml/skins/navit/PageSettings.qml index e737df4..718ea02 100644 --- a/navit/navit/gui/qml/skins/navit/PageSettings.qml +++ b/navit/navit/gui/qml/skins/navit/PageSettings.qml @@ -30,7 +30,7 @@ Rectangle { id: btnMap; text: "Map"; icon: "gui_maps.svg"; onClicked: console.log("Implement me!"); } ButtonIcon { - id: btnVehicle; text: "Vehicle"; icon: "gui_vehicle.svg"; onClicked: console.log("Implement me!"); + id: btnVehicle; text: "Vehicle"; icon: "gui_vehicle.svg"; onClicked: { gui.returnSource="PageSettings.qml"; gui.setPage("PageSettingsVehicle.qml") } } } Grid { diff --git a/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml b/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml new file mode 100644 index 0000000..31a2c6f --- /dev/null +++ b/navit/navit/gui/qml/skins/navit/PageSettingsVehicle.qml @@ -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 } +} -- 2.7.4