From 040fd990c6b6fb56fd0da1afd97d330b9c20abb5 Mon Sep 17 00:00:00 2001 From: akashihi Date: Tue, 16 Mar 2010 10:44:02 +0000 Subject: [PATCH] Add:gui/qml:Added layout selection git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3020 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/gui/qml/gui_qml.cpp | 22 +++++++- navit/navit/gui/qml/proxy.h | 61 ++++++++++++++++++++++ navit/navit/gui/qml/skins/navit/ListSelector.qml | 30 +++-------- .../gui/qml/skins/navit/PageSettingsDisplay.qml | 32 +++++++----- 4 files changed, 109 insertions(+), 36 deletions(-) diff --git a/navit/navit/gui/qml/gui_qml.cpp b/navit/navit/gui/qml/gui_qml.cpp index 6274998..6ae47ae 100644 --- a/navit/navit/gui/qml/gui_qml.cpp +++ b/navit/navit/gui/qml/gui_qml.cpp @@ -9,6 +9,7 @@ #include "plugin.h" #include "item.h" #include "attr.h" +#include "color.h" #include "gui.h" #include "callback.h" #include "debug.h" @@ -17,8 +18,15 @@ #include "graphics.h" #include "event.h" #include "map.h" +#include "coord.h" -#include "proxy.h" +//WORKAOUND for the c/c++ compatibility issues. +//range is defined inside of struct attr so it is invisible in c++ +struct range { + short min, max; +} range; + +#include "layout.h" struct gui_priv { struct navit *nav; @@ -53,6 +61,8 @@ struct gui_priv { class NGQProxyNavit* navitProxy; }; +#include "proxy.h" + //Proxy classes class NGQProxyGui : public NGQProxy { Q_OBJECT; @@ -141,12 +151,20 @@ public slots: navit.u.navit=this->object->nav; navit_destroy(navit.u.navit); event_main_loop_quit(); - //this->gui->mainWindow->close(); + this->object->mainWindow->close(); + } + void setObjectByName(const QString& attr_name,const QString& attr_value) { + if (attr_name=="layout") { + navit_set_layout_by_name(this->object->nav,attr_value.toStdString().c_str()); + } + return; } protected: int getAttrFunc(enum attr_type type, struct attr* attr, struct attr_iter* iter) { return navit_get_attr(this->object->nav, type, attr, iter); } int setAttrFunc(struct attr* attr) {return navit_set_attr(this->object->nav,attr); } + struct attr_iter* getIterFunc() { return navit_attr_iter_new(); }; + void dropIterFunc(struct attr_iter* iter) { navit_attr_iter_destroy(iter); }; private: diff --git a/navit/navit/gui/qml/proxy.h b/navit/navit/gui/qml/proxy.h index c039def..b6e5f7d 100644 --- a/navit/navit/gui/qml/proxy.h +++ b/navit/navit/gui/qml/proxy.h @@ -1,6 +1,20 @@ #ifndef NAVIT_GUI_QML_PROXY_H #define NAVIT_GUI_QML_PROXY_H +class NGQStandardItemModel : public QStandardItemModel { +public: + NGQStandardItemModel(QObject* parent) : QStandardItemModel(parent) { + //Populate role list + roleNames.insert(NGQStandardItemModel::ItemId, "itemId"); + roleNames.insert(NGQStandardItemModel::ItemName, "itemName"); + this->setRoleNames(roleNames); + } + + enum listRoles {ItemId=Qt::UserRole+1,ItemName=Qt::UserRole+2}; +private: + QHash roleNames; +}; + class NGQProxy : public QObject { Q_OBJECT; @@ -14,6 +28,7 @@ public slots: QString getAttr(const QString &attr_name) { QString ret; struct attr attr; + getAttrFunc(attr_from_name(attr_name.toStdString().c_str()), &attr, NULL); if (ATTR_IS_INT(attr.type)) { ret.setNum(attr.u.num); @@ -24,8 +39,52 @@ public slots: if (ATTR_IS_STRING(attr.type)) { ret=attr.u.str; } + if (attr.type==attr_layout) { + ret=attr.u.layout->name; + } 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; @@ -62,6 +121,8 @@ protected: virtual int setAttrFunc(struct attr *attr)=0; virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter)=0; + virtual struct attr_iter* getIterFunc() { return NULL; }; + virtual void dropIterFunc(struct attr_iter*) { return; }; }; #include "proxy.moc" diff --git a/navit/navit/gui/qml/skins/navit/ListSelector.qml b/navit/navit/gui/qml/skins/navit/ListSelector.qml index 0b28522..378b7c4 100644 --- a/navit/navit/gui/qml/skins/navit/ListSelector.qml +++ b/navit/navit/gui/qml/skins/navit/ListSelector.qml @@ -12,25 +12,11 @@ Rectangle { property string itemId: "0" signal changed - ListModel { - id: contactModel - ListElement { - itemId: 0 - name: "Car" - } - ListElement { - itemId: 1 - name: "John Brown" - } - ListElement { - itemId: 2 - name: "Sam Wise" - } - ListElement { - itemId: 3 - name: "T@H" - } - } + function startup() { + console.log("model is: "+listModel); + } + Component.onCompleted: startup(); + Component { id: delegate Item { @@ -38,12 +24,12 @@ Rectangle { width: 180; height: 20 Column { x: 5; y: 5 - Text { text: name; color: "White" } + Text { text: itemName; color: "White" } } MouseRegion { id:delegateMouse anchors.fill: parent - onClicked: { list.currentIndex=itemId; listselector.value=name; listselector.changed() } + onClicked: { list.currentIndex=itemId; listselector.value=itemName; listselector.changed() } } } } @@ -67,7 +53,7 @@ Rectangle { width: 180; height: 60 anchors.top: labelTxt.bottom; anchors.left: listselector.left - model: contactModel + model: listModel delegate: delegate highlight: highlight focus: true diff --git a/navit/navit/gui/qml/skins/navit/PageSettingsDisplay.qml b/navit/navit/gui/qml/skins/navit/PageSettingsDisplay.qml index b0f6050..31c050a 100644 --- a/navit/navit/gui/qml/skins/navit/PageSettingsDisplay.qml +++ b/navit/navit/gui/qml/skins/navit/PageSettingsDisplay.qml @@ -41,20 +41,28 @@ Rectangle { } Grid { - columns: 1; rows: 3 - anchors.horizontalCenter: parent.horizontalCenter; + columns: 2; rows: 1 anchors.verticalCenter: parent.verticalCenter; - spacing: 64 - ToggleSwitch { - id: fullscreenSw; on: gui.getAttr("fullscreen"); text: "Fullscreen"; onChanged: gui.setAttr("fullscreen",fullscreenSw.on) - } - ToggleSwitch { - id: tripledSw; on: page.isTripleD(); text: "2D/3D"; onChanged: setTripleD(tripledSw.on) + anchors.left: parent.left; anchors.right: parent.right; + ListSelector { + id:layoutList; text: "Current layout"; itemId: navit.getAttrList("layout"); onChanged: navit.setObjectByName("layout",layoutList.value) + anchors.left: parent.left + } + Grid { + columns: 1; rows: 3 + anchors.right: parent.right; + spacing: 64 + ToggleSwitch { + id: fullscreenSw; on: gui.getAttr("fullscreen"); text: "Fullscreen"; onChanged: gui.setAttr("fullscreen",fullscreenSw.on) + } + ToggleSwitch { + id: tripledSw; on: page.isTripleD(); text: "2D/3D"; onChanged: setTripleD(tripledSw.on) + } + Slider { + id: pitchSlider; minValue: 5; maxValue: 90; value: navit.getAttr("pitch"); text: "Pitch"; onChanged: { navit.setAttr("pitch",pitchSlider.value); gui.setAttr("pitch",pitchSlider.value) } + opacity: 0 + } } - Slider { - id: pitchSlider; minValue: 5; maxValue: 90; value: navit.getAttr("pitch"); text: "Pitch"; onChanged: { navit.setAttr("pitch",pitchSlider.value); gui.setAttr("pitch",pitchSlider.value) } - opacity: 0 - } } Cellar {anchors.bottom: page.bottom; anchors.horizontalCenter: page.horizontalCenter; width: page.width } -- 2.7.4