Add:gui/qml:Added town selector
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 23 Mar 2010 14:54:38 +0000 (14:54 +0000)
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 23 Mar 2010 14:54:38 +0000 (14:54 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3077 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/gui/qml/gui_qml.cpp
navit/navit/gui/qml/skins/navit/PageSearch.qml
navit/navit/gui/qml/skins/navit/PageSearchSelector.qml

index 508a581..0b198a5 100644 (file)
@@ -83,6 +83,7 @@ class NGQProxySearch : public NGQProxy {
 
        Q_PROPERTY(QString countryName READ countryName WRITE setCountryName NOTIFY countryNameSignal);
        Q_PROPERTY(QString countryISO2 READ countryISO2 WRITE setCountryISO2 NOTIFY countryISO2Signal);
+       Q_PROPERTY(QString townName READ townName WRITE setTownName NOTIFY townNameSignal);
 
        Q_PROPERTY(QString searchContext READ searchContext WRITE setSearchContext);
 
@@ -96,6 +97,7 @@ public:
 
                this->sl=search_list_new(navit_get_mapset(this->object->nav));
                this->search_context="country";
+               this->town_name="Select a town";
 
                country_attr=country_default();
                tracking=navit_get_tracking(this->object->nav);
@@ -127,10 +129,14 @@ public:
                        }
                }               
        }
+       ~NGQProxySearch() {
+               search_list_destroy(this->sl);
+       }
 
 signals:
        void countryNameSignal(QString);
        void countryISO2Signal(QString);
+       void townNameSignal(QString);
 
 public slots:
        QString getAttrList(const QString &attr_name) {
@@ -150,6 +156,11 @@ public slots:
                        attr.type=attr_town_or_district_name;
                        attr.u.str="";
                }
+               if (this->search_context=="street") {
+                       currentValue=this->street_name;
+                       attr.type=attr_street_name;
+                       attr.u.str="";
+               }
 
                search_list_search(this->sl,&attr,1);
 
@@ -164,6 +175,25 @@ public slots:
                                        retId.setNum(counter);
                                }
                        }
+                       if (this->search_context=="town") {
+                               curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
+                               if (res->town->common.town_name) {
+                                       curItem->setData(QString::fromLocal8Bit(res->town->common.town_name),NGQStandardItemModel::ItemName);
+                               }
+                               if (res->town->common.district_name) {
+                                       curItem->setData(QString::fromLocal8Bit(res->town->common.district_name),NGQStandardItemModel::ItemName);
+                               } 
+                               if (this->town_name==QString::fromLocal8Bit(res->town->common.town_name) || this->town_name==QString::fromLocal8Bit(res->town->common.district_name)) {
+                                       retId.setNum(counter);
+                               }
+                       }
+                       if (this->search_context=="street") {
+                               curItem->setData(QVariant(counter),NGQStandardItemModel::ItemId);
+                               curItem->setData(QString::fromLocal8Bit(res->street->name),NGQStandardItemModel::ItemName);
+                               if (this->street_name==QString::fromLocal8Bit(res->street->name)) {
+                                       retId.setNum(counter);
+                               }
+                       }
                        counter++;
                        ret->appendRow(curItem);
                }
@@ -187,6 +217,8 @@ public slots:
                while ((res=search_list_get_result(this->sl))) {
                                this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2));
                }
+               //...and current town
+               this->town_name="Select a town";
 
                countryNameSignal(countryName);
        }
@@ -197,6 +229,22 @@ public slots:
                this->country_iso2=countryISO2;
                countryISO2Signal(countryISO2);
        }
+       QString townName() {
+               return this->town_name;
+       }
+       void setTownName(QString townName) {
+               struct attr attr;
+               struct search_list_result *res;
+
+               this->town_name=townName;
+
+               //Specialize search
+               attr.type=attr_town_or_district_name;
+               attr.u.str=townName.toLocal8Bit().data();
+               search_list_search(this->sl,&attr,0);
+
+               townNameSignal(townName);
+       }
        QString searchContext() {
                return this->search_context;
        }
@@ -214,7 +262,7 @@ protected:
 private:
        struct search_list *sl;
        QString search_context;
-       QString country_iso2,country_name,town_name;
+       QString country_iso2,country_name,town_name,street_name;
 };
 
 class NGQProxyGui : public NGQProxy {
index 80e0283..1050936 100644 (file)
@@ -26,7 +26,7 @@ Rectangle {
             id: btnCountry; text: search.countryName; icon: "country_"+search.countryISO2+".svgz"; onClicked: { search.searchContext="country"; gui.setPage("PageSearchSelector.qml"); }
         }
         ButtonIcon {
-            id: btnCity; text: "City"; icon: "gui_bookmark.svg"; onClicked: { search.searchContext="town"; gui.setPage("PageSearchSelector.qml"); }
+            id: btnCity; text: search.townName; icon: "gui_bookmark.svg"; onClicked: { search.searchContext="town"; gui.setPage("PageSearchSelector.qml"); }
         }
     }
 
@@ -36,7 +36,7 @@ Rectangle {
         anchors.top: parent.verticalCenter; anchors.topMargin: gui.height/16;
         spacing: gui.width/12
         ButtonIcon {
-            id: btnStreet; text: "Street"; icon: "gui_town.svg"; onClicked: console.log("Implement me!");
+            id: btnStreet; text: "Street"; icon: "gui_town.svg"; onClicked: { search.searchContext="street"; gui.setPage("PageSearchSelector.qml"); }
         }
         ButtonIcon {
             id: btnAddress; text: "Address"; icon: "attraction.svg"; onClicked: console.log("Implement me!");
index dd7319f..9346e76 100644 (file)
@@ -13,6 +13,10 @@ Rectangle {
            search.countryName=layoutList.value;
            gui.backToPrevPage();
        }
+        if (search.searchContext=="town") {
+           search.townName=layoutList.value;
+           gui.backToPrevPage();
+       }
     }
 
     function pageOpen() {