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