digiKam
parsetagstring.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-05-12
7  * Description : Parses retrieved data into tag string.
8  *
9  * Copyright (C) 2010 by Michael G. Hansen <mike at mghansen dot de>
10  * Copyright (C) 2010 by Gabriel Voicu <ping dot gabi at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_PARSE_TAG_STRING_H
26 #define DIGIKAM_PARSE_TAG_STRING_H
27 
28 // local includes
29 
30 #include "digikam_debug.h"
31 #include "backend-rg.h"
32 
33 namespace Digikam
34 {
35 
36 QStringList makeTagString(const RGInfo& info,const QString& inputFormat,const QString& backendName)
37 {
38  QString auxReturnedFormat = inputFormat;
39  QString returnedAddress = inputFormat;
40  QString returnedFormat;
41 
42  QStringList returnedAddressElements;
43 
44  int indexFBracket = -1;
45 
46  while ((indexFBracket = returnedAddress.indexOf(QLatin1String("{"))) >= 0)
47  {
48  int indexLBracket = returnedAddress.indexOf(QLatin1String("}"));
49  QString humanTag = returnedAddress.mid(indexFBracket + 1, indexLBracket - indexFBracket - 1);
50  int indexFormatFBracket1 = auxReturnedFormat.indexOf(QLatin1String("{"));
51  auxReturnedFormat.replace(indexFormatFBracket1 - 1, humanTag.length() + 3, QLatin1String(""));
52  bool dataAdded = false;
53  QString result;
54 
55  if (backendName == QLatin1String("OSM"))
56  {
57  if (humanTag == QLatin1String("Country"))
58  {
59  if (!info.rgData[QLatin1String("country")].isEmpty())
60  {
61  result = info.rgData[QLatin1String("country")];
62  returnedFormat.append(QLatin1String("/{Country}"));
63  dataAdded = true;
64  }
65  }
66  else if (humanTag == QLatin1String("State district"))
67  {
68  if (!info.rgData[QLatin1String("state_district")].isEmpty())
69  {
70  result = info.rgData[QLatin1String("state_district")];
71  returnedFormat.append(QLatin1String("/{State district}"));
72  dataAdded = true;
73  }
74  }
75  else if (humanTag == QLatin1String("County"))
76  {
77  if (!info.rgData[QLatin1String("county")].isEmpty())
78  {
79  result = info.rgData[QLatin1String("county")];
80  returnedFormat.append(QLatin1String("/{County}"));
81  dataAdded = true;
82  }
83  }
84  else if (humanTag == QLatin1String("City"))
85  {
86  if (!info.rgData[QLatin1String("city")].isEmpty())
87  {
88  result = info.rgData[QLatin1String("city")];
89  returnedFormat.append(QLatin1String("/{City}"));
90  dataAdded = true;
91  }
92  }
93  else if (humanTag == QLatin1String("City district"))
94  {
95  if (!info.rgData[QLatin1String("city_district")].isEmpty())
96  {
97  result = info.rgData[QLatin1String("city_district")];
98  returnedFormat.append(QLatin1String("/{City district}"));
99  dataAdded = true;
100  }
101  }
102  else if (humanTag == QLatin1String("Suburb"))
103  {
104  if (!info.rgData[QLatin1String("suburb")].isEmpty())
105  {
106  result = info.rgData[QLatin1String("suburb")];
107  returnedFormat.append(QLatin1String("/{Suburb}"));
108  dataAdded = true;
109  }
110  }
111  else if (humanTag == QLatin1String("Street"))
112  {
113  if (!info.rgData[QLatin1String("road")].isEmpty())
114  {
115  result = info.rgData[QLatin1String("road")];
116  returnedFormat.append(QLatin1String("/{Street}"));
117  dataAdded = true;
118  }
119  }
120  else if (humanTag == QLatin1String("State"))
121  {
122  if (!info.rgData[QLatin1String("state")].isEmpty())
123  {
124  result = info.rgData[QLatin1String("state")];
125  returnedFormat.append(QLatin1String("/{State}"));
126  dataAdded = true;
127  }
128  }
129  else if (humanTag == QLatin1String("Town"))
130  {
131  if (!info.rgData[QLatin1String("town")].isEmpty())
132  {
133  result = info.rgData[QLatin1String("town")];
134  returnedFormat.append(QLatin1String("/{Town}"));
135  dataAdded = true;
136  }
137  }
138  else if (humanTag == QLatin1String("Village"))
139  {
140  if (!info.rgData[QLatin1String("village")].isEmpty())
141  {
142  result = info.rgData[QLatin1String("village")];
143  returnedFormat.append(QLatin1String("/{Village}"));
144  dataAdded = true;
145  }
146  }
147  else if (humanTag == QLatin1String("Hamlet"))
148  {
149  if (!info.rgData[QLatin1String("hamlet")].isEmpty())
150  {
151  result = info.rgData[QLatin1String("hamlet")];
152  returnedFormat.append(QLatin1String("/{Hamlet}"));
153  dataAdded = true;
154  }
155  }
156  else if (humanTag == QLatin1String("House number"))
157  {
158  if (!info.rgData[QLatin1String("house_number")].isEmpty())
159  {
160  result = info.rgData[QLatin1String("house_number")];
161  returnedFormat.append(QLatin1String("/{House number}"));
162  dataAdded = true;
163  }
164  }
165  else
166  {
167  returnedAddress.replace(indexFBracket - 1, indexLBracket - indexFBracket + 2, QLatin1String(""));
168 
169  int indexFormatFBracket2 = auxReturnedFormat.indexOf(QLatin1String("{"));
170  int indexFormatLBracket = auxReturnedFormat.indexOf(QLatin1String("}"));
171  auxReturnedFormat.replace(indexFormatFBracket2 - 1,
172  indexFormatLBracket - indexFormatFBracket2 + 2,
173  QLatin1String(""));
174  dataAdded = true;
175  }
176  }
177 
178  else if (backendName == QLatin1String("GeonamesUS"))
179  {
180 
181  if (humanTag.compare(QLatin1String("LAU2")) == 0)
182  {
183  if (!info.rgData[QLatin1String("adminName2")].isEmpty())
184  {
185  result = info.rgData[QLatin1String("adminName2")];
186  returnedFormat.append(QLatin1String("/{LAU2}"));
187  dataAdded = true;
188  }
189  }
190 
191  else if (humanTag == QLatin1String("LAU1"))
192  {
193  if (!info.rgData[QLatin1String("adminName1")].isEmpty())
194  {
195  result = info.rgData[QLatin1String("adminName1")];
196  returnedFormat.append(QLatin1String("/{LAU1}"));
197  dataAdded = true;
198  }
199  }
200 
201  else if (humanTag == QLatin1String("City"))
202  {
203  if (!info.rgData[QLatin1String("placename")].isEmpty())
204  {
205  result = info.rgData[QLatin1String("placename")];
206  returnedFormat.append(QLatin1String("/{City}"));
207  dataAdded = true;
208  }
209  }
210  else
211  {
212  returnedAddress.replace(indexFBracket - 1,
213  indexLBracket - indexFBracket + 2,
214  QLatin1String(""));
215 
216  int indexFormatFBracket3 = auxReturnedFormat.indexOf(QLatin1String("{"));
217  int indexFormatLBracket = auxReturnedFormat.indexOf(QLatin1String("}"));
218  auxReturnedFormat.replace(indexFormatFBracket3 - 1,
219  indexFormatLBracket - indexFormatFBracket3 + 2,
220  QLatin1String(""));
221  dataAdded = true;
222  }
223  }
224 
225  else if (backendName == QLatin1String("Geonames"))
226  {
227  if (humanTag.compare(QLatin1String("Country")) == 0)
228  {
229  if (!info.rgData[QLatin1String("countryName")].isEmpty())
230  {
231  result = info.rgData[QLatin1String("countryName")];
232  returnedFormat.append(QLatin1String("/{Country}"));
233  dataAdded = true;
234  }
235  }
236 
237  else if (humanTag == QLatin1String("Place"))
238  {
239  if (!info.rgData[QLatin1String("name")].isEmpty())
240  {
241  result = info.rgData[QLatin1String("name")];
242  returnedFormat.append(QLatin1String("/{Place}"));
243  dataAdded = true;
244  }
245  }
246  else
247  {
248  returnedAddress.replace(indexFBracket - 1,
249  indexLBracket - indexFBracket + 2,
250  QLatin1String(""));
251 
252  int indexFormatFBracket4 = auxReturnedFormat.indexOf(QLatin1String("{"));
253  int indexFormatLBracket = auxReturnedFormat.indexOf(QLatin1String("}"));
254  auxReturnedFormat.replace(indexFormatFBracket4 - 1,
255  indexFormatLBracket - indexFormatFBracket4 + 2,
256  QLatin1String(""));
257  dataAdded = true;
258  }
259  }
260 
261  if (!dataAdded)
262  {
263  returnedAddress.replace(indexFBracket - 1, humanTag.length() + 3, QLatin1String(""));
264  }
265  else
266  {
267  returnedAddress.replace(indexFBracket, humanTag.length() + 2, result);
268  }
269  }
270 
271  returnedAddressElements.append(returnedFormat);
272  returnedAddressElements.append(returnedAddress);
273 
274  return returnedAddressElements;
275 }
276 
277 } // namespace Digikam
278 
279 #endif // DIGIKAM_PARSE_TAG_STRING_H
This class contains data needed in reverse geocoding process.
Definition: rginfo.h:48
QMap< QString, QString > rgData
Definition: rginfo.h:76
Definition: datefolderview.cpp:43
QStringList makeTagString(const RGInfo &info, const QString &inputFormat, const QString &backendName)
Definition: parsetagstring.h:36