/[zanavi_public1]/navit/navit/gui/qml/searchProxy.h
ZANavi

Contents of /navit/navit/gui/qml/searchProxy.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 7330 byte(s)
import files
1 #ifndef NAVIT_GUI_QML_SEARCHPROXY_H
2 #define NAVIT_GUI_QML_SEARCHPROXY_H
3
4 void __setNewPoint(struct gui_priv* this_,struct pcoord* pc, NGQPointTypes type);
5
6 class NGQProxySearch : public NGQProxy {
7 Q_OBJECT;
8
9 Q_PROPERTY(QString countryName READ countryName WRITE setCountryName NOTIFY countryNameSignal);
10 Q_PROPERTY(QString countryISO2 READ countryISO2 WRITE setCountryISO2 NOTIFY countryISO2Signal);
11 Q_PROPERTY(QString townName READ townName WRITE setTownName NOTIFY townNameSignal);
12 Q_PROPERTY(QString streetName READ streetName WRITE setStreetName NOTIFY streetNameSignal);
13
14 Q_PROPERTY(QString searchContext READ searchContext WRITE setSearchContext);
15
16 public:
17 NGQProxySearch(struct gui_priv* this_,QObject* parent) : NGQProxy(this_,parent) {
18 struct attr search_attr, country_name, country_iso2, *country_attr;
19 struct item *item;
20 struct country_search *cs;
21 struct tracking *tracking;
22 struct search_list_result *res;
23
24 this->sl=search_list_new(navit_get_mapset(this->object->nav));
25 this->search_context="country";
26
27 country_attr=country_default();
28 tracking=navit_get_tracking(this->object->nav);
29 if (tracking && tracking_get_attr(tracking, attr_country_id, &search_attr, NULL))
30 country_attr=&search_attr;
31 if (country_attr) {
32 cs=country_search_new(country_attr, 0);
33 item=country_search_get_item(cs);
34 if (item && item_attr_get(item, attr_country_name, &country_name)) {
35 search_attr.type=attr_country_all;
36 dbg(0,"country %s\n", country_name.u.str);
37 this->country_name=QString::fromLocal8Bit(country_name.u.str);
38 search_attr.u.str=country_name.u.str;
39 search_list_search(this->sl, &search_attr, 0);
40 while((res=search_list_get_result(this->sl)));
41 if (item_attr_get(item, attr_country_iso2, &country_iso2)) {
42 this->country_iso2=QString::fromLocal8Bit(country_iso2.u.str);
43 }
44 }
45 country_search_destroy(cs);
46 } else {
47 dbg(0,"warning: no default country found\n");
48 if (!this->country_iso2.isEmpty()) {
49 dbg(0,"attempting to use country '%s'\n",this->country_iso2.toStdString().c_str());
50 search_attr.type=attr_country_iso2;
51 search_attr.u.str=(char*)this->country_iso2.toStdString().c_str();
52 search_list_search(this->sl, &search_attr, 0);
53 while((res=search_list_get_result(this->sl)));
54 }
55 }
56 }
57 ~NGQProxySearch() {
58 search_list_destroy(this->sl);
59 }
60
61 signals:
62 void countryNameSignal(QString);
63 void countryISO2Signal(QString);
64 void townNameSignal(QString);
65 void streetNameSignal(QString);
66
67 public slots:
68 void setPointToResult() {
69 struct attr attr;
70 struct search_list_result *res;
71
72 if (this->street_name.length()>0) {
73 attr.type=attr_street_name;
74 attr.u.str=this->street_name.toLocal8Bit().data();
75 } else if (this->town_name.length()>0) {
76 attr.type=attr_town_or_district_name;
77 attr.u.str=this->town_name.toLocal8Bit().data();
78 } else if (this->country_name.length()>0) {
79 attr.type=attr_country_name;
80 attr.u.str=this->country_name.toLocal8Bit().data();
81 }
82 search_list_search(this->sl,&attr,0);
83 if ((res=search_list_get_result(this->sl))) {
84 __setNewPoint(this->object,res->c,PointOfInterest);
85 }
86 return;
87 }
88 QString searchXml() {
89 NGQStandardItemModel* ret=new NGQStandardItemModel(this);
90 struct attr attr;
91 struct search_list_result *res;
92 int counter=0;
93 QDomDocument retDoc;
94 QDomElement entries;
95
96 entries=retDoc.createElement("search");
97 retDoc.appendChild(entries);
98
99 if (this->search_context=="country") {
100 attr.type=attr_country_name;
101 attr.u.str=this->country_name.toLocal8Bit().data();
102 }
103 if (this->search_context=="town") {
104 if (this->town_name.length()<3) {
105 return retDoc.toString();
106 }
107 attr.type=attr_town_or_district_name;
108 attr.u.str=this->town_name.toLocal8Bit().data();
109 }
110 if (this->search_context=="street") {
111 attr.type=attr_street_name;
112 attr.u.str=this->street_name.toLocal8Bit().data();
113 }
114
115 search_list_search(this->sl,&attr,1);
116
117 while ((res=search_list_get_result(this->sl))) {
118 QStandardItem* curItem=new QStandardItem();
119 QDomElement entry=retDoc.createElement("item");
120 entries.appendChild(entry);
121 //Result processing depends on search type
122 if (this->search_context=="country") {
123 entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
124 entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"), QString::fromLocal8Bit(res->country->name)));
125 entry.appendChild(this->_fieldValueHelper(retDoc,QString("icon"), QString("country_%1%2").arg(res->country->iso2).arg(".svgz")));
126 }
127 if (this->search_context=="town") {
128 entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
129 if (res->town->common.town_name) {
130 entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"),QString::fromLocal8Bit(res->town->common.town_name)));
131 }
132 if (res->town->common.district_name) {
133 entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"), QString::fromLocal8Bit(res->town->common.district_name)));
134 }
135 }
136 if (this->search_context=="street") {
137 entry.appendChild(this->_fieldValueHelper(retDoc,QString("id"), QString::number(counter)));
138 entry.appendChild(this->_fieldValueHelper(retDoc,QString("name"),QString::fromLocal8Bit(res->street->name)));
139 }
140 counter++;
141 ret->appendRow(curItem);
142 }
143
144 return retDoc.toString();
145 }
146 QString countryName() {
147 return this->country_name;
148 }
149 void setCountryName(QString countryName) {
150 this->country_name=countryName;
151 struct attr attr;
152 struct search_list_result *res;
153
154 //We need to update ISO2
155 attr.type=attr_country_name;
156 attr.u.str=countryName.toLocal8Bit().data();
157 search_list_search(this->sl,&attr,0);
158 while ((res=search_list_get_result(this->sl))) {
159 this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2));
160 }
161 //...and current town
162 this->town_name="";
163 this->street_name="";
164
165 countryNameSignal(countryName);
166 }
167 QString countryISO2() {
168 return this->country_iso2;
169 }
170 void setCountryISO2(QString countryISO2) {
171 this->country_iso2=countryISO2;
172 countryISO2Signal(countryISO2);
173 }
174 QString townName() {
175 return this->town_name;
176 }
177 void setTownName(QString townName) {
178 struct attr attr;
179
180 this->town_name=townName;
181
182 //Specialize search
183 attr.type=attr_town_or_district_name;
184 attr.u.str=townName.toLocal8Bit().data();
185 search_list_search(this->sl,&attr,0);
186
187 //...and street
188 this->street_name="";
189
190 townNameSignal(townName);
191 }
192 QString streetName() {
193 return this->street_name;
194 }
195 void setStreetName(QString streetName) {
196 struct attr attr;
197
198 this->street_name=streetName;
199
200 //Specialize search
201 attr.type=attr_street_name;
202 attr.u.str=streetName.toLocal8Bit().data();
203 search_list_search(this->sl,&attr,0);
204
205 streetNameSignal(streetName);
206 }
207 QString searchContext() {
208 return this->search_context;
209 }
210 void setSearchContext(QString searchContext) {
211 this->search_context=searchContext;
212 }
213
214 protected:
215 virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) {
216 return 0;
217 }
218 virtual int setAttrFunc(struct attr *attr) {
219 return 0;
220 }
221 private:
222 struct search_list *sl;
223 QString search_context;
224 QString country_iso2,country_name,town_name,street_name;
225 };
226
227 #include "searchProxy.moc"
228
229 #endif /* NAVIT_GUI_QML_SEARCHPROXY_H */

   
Visit the ZANavi Wiki