Kgapi

staticmapmarker.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Jan Grulich <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "staticmapmarker.h"
8 
9 using namespace KGAPI2;
10 
11 class Q_DECL_HIDDEN StaticMapMarker::Private
12 {
13 public:
14  Private();
15  Private(const Private &other);
16 
17  void init(const Private &other);
18 
19  LocationType locationType;
20  MarkerSize size;
21 
22  QColor color;
23  QChar label;
24 
25  QStringList locationsString;
26  KContacts::Address::List locationsAddress;
27  QList<KContacts::Geo> locationsGeo;
28 };
29 
30 StaticMapMarker::Private::Private():
31  locationType(StaticMapMarker::Undefined),
32  size(StaticMapMarker::Normal),
33  color(Qt::red)
34 { }
35 
36 StaticMapMarker::Private::Private(const Private & other)
37 {
38  init(other);
39 }
40 
41 void StaticMapMarker::Private::init(const Private &other)
42 {
43  locationType = other.locationType;
44  size = other.size;
45  color = other.color;
46  label = other.label;
47  locationsString = other.locationsString;
48  locationsAddress = other.locationsAddress;
49  locationsGeo = other.locationsGeo;
50 }
51 
53  d(new Private)
54 {
55 }
56 
57 StaticMapMarker::StaticMapMarker (const QString& address, const QChar& label, const MarkerSize size, const QColor& color):
58  d(new Private)
59 {
60  QStringList list;
61  list << address;
62  d->locationType = String;
63  d->locationsString = list;
64  d->label = label;
65  d->size = size;
66  d->color = color;
67 }
68 
69 StaticMapMarker::StaticMapMarker (const KContacts::Address& address, QChar label, const MarkerSize size, const QColor& color):
70  d(new Private)
71 {
73  list << address;
74  d->locationType = KABCAddress;
75  d->locationsAddress = list;
76  d->label = label;
77  d->size = size;
78  d->color = color;
79 }
80 
81 StaticMapMarker::StaticMapMarker (const KContacts::Geo& address, QChar label, const MarkerSize size, const QColor& color):
82  d(new Private)
83 {
85  list << address;
86  d->locationType = KABCGeo;
87  d->locationsGeo = list;
88  d->label = label;
89  d->size = size;
90  d->color = color;
91 }
92 
94  const MarkerSize size, const QColor& color):
95  d(new Private)
96 {
97  d->locationType = String;
98  d->locationsString = locations;
99  d->label = label;
100  d->size = size;
101  d->color = color;
102 }
103 
105  const MarkerSize size, const QColor& color):
106  d(new Private)
107 {
108  d->locationType = KABCAddress;
109  d->locationsAddress = locations;
110  d->label = label;
111  d->size = size;
112  d->color = color;
113 }
114 
116  const MarkerSize size, const QColor& color):
117  d(new Private)
118 {
119  d->locationType = KABCGeo;
120  d->locationsGeo = locations;
121  d->label = label;
122  d->size = size;
123  d->color = color;
124 }
125 
127  d(new Private(*(other.d)))
128 {
129 }
130 
132 {
133  delete d;
134 }
135 
136 StaticMapMarker::LocationType StaticMapMarker::locationType() const
137 {
138  return d->locationType;
139 }
140 
142 {
143  return d->color;
144 }
145 
147 {
148  d->color = color;
149 }
150 
152 {
153  return (d->locationType != Undefined);
154 }
155 
157 {
158  return d->label;
159 }
160 
162 {
163  d->label = label;
164 }
165 
167 {
168  return d->locationsString;
169 }
170 
172 {
173  d->locationType = String;
174  d->locationsString.clear();
175  d->locationsString << location;
176  d->locationsAddress.clear();
177  d->locationsGeo.clear();
178 }
179 
181 {
182  d->locationType = KABCAddress;
183  d->locationsString = locations;
184  d->locationsAddress.clear();
185  d->locationsGeo.clear();
186 }
187 
189 {
190  return d->locationsAddress;
191 }
192 
194 {
195  d->locationType = KABCAddress;
196  d->locationsAddress.clear();
197  d->locationsAddress << location;
198  d->locationsString.clear();
199  d->locationsGeo.clear();
200 }
201 
203 {
204  d->locationType = KABCAddress;
205  d->locationsAddress = locations;
206  d->locationsString.clear();
207  d->locationsGeo.clear();
208 }
209 
211 {
212  return d->locationsGeo;
213 }
214 
216 {
217  d->locationType = KABCGeo;
218  d->locationsGeo.clear();
219  d->locationsGeo << location;
220  d->locationsString.clear();
221  d->locationsAddress.clear();
222 }
223 
225 {
226  d->locationType = KABCGeo;
227  d->locationsGeo = locations;
228  d->locationsString.clear();
229  d->locationsAddress.clear();
230 }
231 
232 StaticMapMarker::MarkerSize StaticMapMarker::size() const
233 {
234  return d->size;
235 }
236 
237 void StaticMapMarker::setSize(const MarkerSize size)
238 {
239  d->size = size;
240 }
241 
243 {
244  QString ret;
245 
246  switch (d->size) {
247  case Tiny:
248  ret += QLatin1String("size:tiny|");
249  break;
250  case Small:
251  ret += QLatin1String("size:small|");
252  break;
253  case Middle:
254  ret += QLatin1String("size:mid|");
255  break;
256  case Normal:
257  break;
258  }
259 
260  if (d->color != Qt::red)
261  ret += QLatin1String("color:") + d->color.name().replace(QLatin1Char('#'), QLatin1String("0x")) + QLatin1Char('|');
262 
263  if (d->label.isLetterOrNumber() && d->size > 1)
264  ret += QLatin1String("label:") + d->label.toUpper() + QLatin1Char('|');
265 
266  if (d->locationType == String) {
267 
268  for (const QString & addr : qAsConst(d->locationsString)) {
269  ret += addr + QLatin1Char('|');
270  }
271 
272  } else if (d->locationType == KABCAddress) {
273 
274  for (const KContacts::Address & addr : qAsConst(d->locationsAddress)) {
275  ret += addr.formattedAddress() + QLatin1Char('|');
276  }
277 
278  } else if (d->locationType == KABCGeo) {
279 
280  for (const KContacts::Geo & addr : qAsConst(d->locationsGeo)) {
281  ret += QString::number(addr.latitude()) + QLatin1Char(',') +
282  QString::number(addr.longitude()) + QLatin1Char('|');
283  }
284 
285  }
286 
287  ret.replace(QLatin1String(", "), QLatin1String(","));
288  ret.replace(QLatin1String(". "), QLatin1String("."));
289  ret.replace(QLatin1Char(' '), QLatin1Char('+'));
290  ret.replace(QLatin1Char('\n'), QLatin1Char(','));
291  ret.remove(ret.lastIndexOf(QLatin1Char('|')), 1);
292 
293  return ret;
294 
295 }
296 
298 {
299  if (&other == this) {
300  return *this;
301  }
302 
303  d->init(*(other.d));
304  return *this;
305 }
StaticMapMarker()
Constructs an empty marker.
void setLocation(const QString &location)
Sets one location for marker.
void setColor(const QColor &color)
Sets color of marker.
QColor color() const
Returns color of marker.
QList< KContacts::Geo > locationsGeo() const
Returns locations in KContacts::Geo.
LocationType locationType() const
Returns in which format is location saved.
QString toString() const
Returns all locations and markers preferences in format to URL query.
QString & remove(int position, int n)
QChar label() const
Returns label of marker.
Represents marker with defined label, color, size and markers.
MarkerSize size() const
Returns size of marker.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
KContacts::Address::List locationsAddress() const
Returns locations in KContacts::Address.
QString number(int n, int base)
QString label(StandardShortcut id)
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
void setSize(const MarkerSize size)
Sets size of marker.
QStringList locationsString() const
Returns locations in QString.
QCA_EXPORT void init()
QString & replace(int position, int n, QChar after)
StaticMapMarker & operator=(const StaticMapMarker &other)
Assignment operator.
void setLabel(QChar label)
Sets label of marker.
bool isValid() const
Returns if marker is valid.
void setLocations(const QStringList &locations)
Sets locations for marker.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 23:09:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.