navit 0.5.3-trunk
Loading...
Searching...
No Matches
searchProxy.h
Go to the documentation of this file.
1#ifndef NAVIT_GUI_QML_SEARCHPROXY_H
2#define NAVIT_GUI_QML_SEARCHPROXY_H
3
4void __setNewPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type);
5
6class 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
25 this->search_context = "country";
26
27 country_attr = country_default();
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);
34 if (item && item_attr_get(item, attr_country_name, &country_name)) {
35 search_attr.type = attr_country_all;
36 dbg(lvl_debug, "country %s", 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 ;
42 if (item_attr_get(item, attr_country_iso2, &country_iso2)) {
43 this->country_iso2 = QString::fromLocal8Bit(country_iso2.u.str);
44 }
45 }
47 } else {
48 dbg(lvl_error, "warning: no default country found");
49 if (!this->country_iso2.isEmpty()) {
50 dbg(lvl_debug, "attempting to use country '%s'", this->country_iso2.toStdString().c_str());
51 search_attr.type = attr_country_iso2;
52 search_attr.u.str = (char *)this->country_iso2.toStdString().c_str();
53 search_list_search(this->sl, &search_attr, 0);
54 while ((res = search_list_get_result(this->sl)))
55 ;
56 }
57 }
58 }
62
63 signals:
64 void countryNameSignal(QString);
65 void countryISO2Signal(QString);
66 void townNameSignal(QString);
67 void streetNameSignal(QString);
68
69 public slots:
71 struct attr attr;
72 struct search_list_result *res;
73
74 if (this->street_name.length() > 0) {
75 attr.type = attr_street_name;
76 attr.u.str = this->street_name.toLocal8Bit().data();
77 } else if (this->town_name.length() > 0) {
78 attr.type = attr_town_or_district_name;
79 attr.u.str = this->town_name.toLocal8Bit().data();
80 } else if (this->country_name.length() > 0) {
81 attr.type = attr_country_name;
82 attr.u.str = this->country_name.toLocal8Bit().data();
83 }
84 search_list_search(this->sl, &attr, 0);
85 if ((res = search_list_get_result(this->sl))) {
86 __setNewPoint(this->object, res->c, PointOfInterest);
87 }
88 return;
89 }
90 QString searchXml() {
92 struct attr attr;
93 struct search_list_result *res;
94 int counter = 0;
95 QDomDocument retDoc;
96 QDomElement entries;
97
98 entries = retDoc.createElement("search");
99 retDoc.appendChild(entries);
100
101 if (this->search_context == "country") {
102 attr.type = attr_country_name;
103 attr.u.str = this->country_name.toLocal8Bit().data();
104 }
105 if (this->search_context == "town") {
106 if (this->town_name.length() < 3) {
107 return retDoc.toString();
108 }
109 attr.type = attr_town_or_district_name;
110 attr.u.str = this->town_name.toLocal8Bit().data();
111 }
112 if (this->search_context == "street") {
113 attr.type = attr_street_name;
114 attr.u.str = this->street_name.toLocal8Bit().data();
115 }
116
117 search_list_search(this->sl, &attr, 1);
118
119 while ((res = search_list_get_result(this->sl))) {
120 QStandardItem *curItem = new QStandardItem();
121 QDomElement entry = retDoc.createElement("item");
122 entries.appendChild(entry);
123 // Result processing depends on search type
124 if (this->search_context == "country") {
125 entry.appendChild(this->_fieldValueHelper(retDoc, QString("id"), QString::number(counter)));
126 entry.appendChild(
127 this->_fieldValueHelper(retDoc, QString("name"), QString::fromLocal8Bit(res->country->name)));
128 entry.appendChild(this->_fieldValueHelper(
129 retDoc, QString("icon"), QString("country_%1%2").arg(res->country->iso2).arg(".svgz")));
130 }
131 if (this->search_context == "town") {
132 entry.appendChild(this->_fieldValueHelper(retDoc, QString("id"), QString::number(counter)));
133 if (res->town->common.town_name) {
134 entry.appendChild(this->_fieldValueHelper(retDoc, QString("name"),
135 QString::fromLocal8Bit(res->town->common.town_name)));
136 }
137 if (res->town->common.district_name) {
138 entry.appendChild(this->_fieldValueHelper(retDoc, QString("name"),
139 QString::fromLocal8Bit(res->town->common.district_name)));
140 }
141 }
142 if (this->search_context == "street") {
143 entry.appendChild(this->_fieldValueHelper(retDoc, QString("id"), QString::number(counter)));
144 entry.appendChild(
145 this->_fieldValueHelper(retDoc, QString("name"), QString::fromLocal8Bit(res->street->name)));
146 }
147 counter++;
148 ret->appendRow(curItem);
149 }
150
151 return retDoc.toString();
152 }
153 QString countryName() {
154 return this->country_name;
155 }
158 struct attr attr;
159 struct search_list_result *res;
160
161 // We need to update ISO2
162 attr.type = attr_country_name;
163 attr.u.str = countryName.toLocal8Bit().data();
164 search_list_search(this->sl, &attr, 0);
165 while ((res = search_list_get_result(this->sl))) {
166 this->setCountryISO2(QString::fromLocal8Bit(res->country->iso2));
167 }
168 //...and current town
169 this->town_name = "";
170 this->street_name = "";
171
173 }
174 QString countryISO2() {
175 return this->country_iso2;
176 }
179 countryISO2Signal(countryISO2);
180 }
181 QString townName() {
182 return this->town_name;
183 }
184 void setTownName(QString townName) {
185 struct attr attr;
186
187 this->town_name = townName;
188
189 // Specialize search
190 attr.type = attr_town_or_district_name;
191 attr.u.str = townName.toLocal8Bit().data();
192 search_list_search(this->sl, &attr, 0);
193
194 //...and street
195 this->street_name = "";
196
198 }
199 QString streetName() {
200 return this->street_name;
201 }
202 void setStreetName(QString streetName) {
203 struct attr attr;
204
205 this->street_name = streetName;
206
207 // Specialize search
208 attr.type = attr_street_name;
209 attr.u.str = streetName.toLocal8Bit().data();
210 search_list_search(this->sl, &attr, 0);
211
213 }
214 QString searchContext() {
215 return this->search_context;
216 }
219 }
220
221 protected:
222 virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter) {
223 return 0;
224 }
225 virtual int setAttrFunc(struct attr *attr) {
226 return 0;
227 }
228
229 private:
233};
234
235#include "searchProxy.moc"
236
237#endif /* NAVIT_GUI_QML_SEARCHPROXY_H */
attr_type
Definition attr_type_def.h:11
Definition searchProxy.h:6
QString countryISO2()
Definition searchProxy.h:174
virtual int setAttrFunc(struct attr *attr)
Definition searchProxy.h:225
struct search_list * sl
Definition searchProxy.h:230
void setSearchContext(QString searchContext)
Definition searchProxy.h:217
QString countryName()
Definition searchProxy.h:153
QString townName
Definition searchProxy.h:11
QString town_name
Definition searchProxy.h:232
void setTownName(QString townName)
Definition searchProxy.h:184
void townNameSignal(QString)
void setCountryISO2(QString countryISO2)
Definition searchProxy.h:177
void countryISO2Signal(QString)
QString streetName()
Definition searchProxy.h:199
void setCountryName(QString countryName)
Definition searchProxy.h:156
QString searchContext
Definition searchProxy.h:14
void setStreetName(QString streetName)
Definition searchProxy.h:202
QString country_iso2
Definition searchProxy.h:232
void countryNameSignal(QString)
QString country_name
Definition searchProxy.h:232
~NGQProxySearch()
Definition searchProxy.h:59
QString search_context
Definition searchProxy.h:231
NGQProxySearch(struct gui_priv *this_, QObject *parent)
Definition searchProxy.h:17
void setPointToResult()
Definition searchProxy.h:70
QString street_name
Definition searchProxy.h:232
QString searchContext()
Definition searchProxy.h:214
virtual int getAttrFunc(enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition searchProxy.h:222
QString countryName
Definition searchProxy.h:9
QString searchXml()
Definition searchProxy.h:90
QString countryISO2
Definition searchProxy.h:10
void streetNameSignal(QString)
QString townName()
Definition searchProxy.h:181
QString streetName
Definition searchProxy.h:12
Definition proxy.h:28
struct gui_priv * object
Definition proxy.h:98
QDomElement _fieldValueHelper(QDomDocument doc, QString field, QString value)
Definition proxy.h:111
Definition proxy.h:4
struct item * country_search_get_item(struct country_search *this_)
Definition country.c:394
struct attr * country_default(void)
Definition country.c:414
struct country_search * country_search_new(struct attr *search, int partial)
Definition country.c:360
void country_search_destroy(struct country_search *this_)
Definition country.c:427
@ lvl_error
Definition debug.h:46
@ lvl_debug
Definition debug.h:52
#define dbg(level,...)
Definition debug.h:59
char type[3]
Definition garmin_img.c:2
struct mapset * navit_get_mapset(struct navit *this_)
Get the current mapset.
Definition navit.c:225
struct tracking * navit_get_tracking(struct navit *this_)
Definition navit.c:359
static GtkActionEntry entries[]
Definition gui_gtk_action.c:196
int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
Gets the next matching attribute from an item.
Definition item.c:414
NGQPointTypes
Definition ngqpoint.h:30
@ PointOfInterest
Definition ngqpoint.h:35
void __setNewPoint(struct gui_priv *this_, struct pcoord *pc, NGQPointTypes type)
Definition guiProxy.h:153
struct search_list_result * search_list_get_result(struct search_list *this_)
Get (next) result from a search.
Definition search.c:787
void search_list_destroy(struct search_list *this_)
Definition search.c:961
struct search_list * search_list_new(struct mapset *ms)
Create new instance of search_list to run a search.
Definition search.c:96
void search_list_search(struct search_list *this_, struct attr *search_attr, int partial)
Start a search.
Definition search.c:334
Definition config_.c:47
Definition attr.h:138
char * str
Definition attr.h:141
union attr::@0 u
enum attr_type type
Definition attr.h:139
Definition country.c:297
Definition graphics_win32.h:50
struct navit * nav
Definition graphics_win32.h:51
Represents an object on a map.
Definition item.h:122
Definition gpx2navit_txt.h:50
Definition coord.h:51
char * town_name
Definition search.h:38
char * district_name
Definition search.h:39
char * iso2
Definition search.h:49
char * name
Definition search.h:51
Definition search.h:72
struct pcoord * c
Definition search.h:74
struct search_list_country * country
Definition search.h:75
struct search_list_town * town
Definition search.h:76
struct search_list_street * street
Definition search.h:77
char * name
Definition search.h:63
struct search_list_common common
Definition search.h:56
Definition search.c:61
Definition mg.h:186
Definition track.c:84
int tracking_get_attr(struct tracking *_this, enum attr_type type, struct attr *attr, struct attr_iter *attr_iter)
Definition track.c:321