Kgapi

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

KDE's Doxygen guidelines are available online.