Kgapi

staticmappath.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 "staticmappath.h"
8
9using namespace KGAPI2;
10
11class Q_DECL_HIDDEN StaticMapPath::Private
12{
13public:
14 Private();
15 Private(const Private &other);
16
17 void init(const Private &other);
18
19 StaticMapPath::LocationType locationType;
20
21 QColor color = Qt::blue;
22 QColor fillColor;
23 quint8 weight = 5;
24
25 QStringList locationsString;
26 KContacts::Address::List locationsAddress;
27 QList<KContacts::Geo> locationsGeo;
28};
29
30StaticMapPath::Private::Private()
31{
32}
33
34StaticMapPath::Private::Private(const Private &other)
35{
36 init(other);
37}
38
39void StaticMapPath::Private::init(const Private &other)
40{
41 locationType = other.locationType;
42 color = other.color;
43 fillColor = other.fillColor;
44 weight = other.weight;
45 locationsString = other.locationsString;
46 locationsAddress = other.locationsAddress;
47 locationsGeo = other.locationsGeo;
48}
49
51 : d(new Private)
52{
53}
54
56 : d(new Private(*(other.d)))
57{
58}
59
60StaticMapPath::StaticMapPath(const QStringList &locations, const quint8 weight, const QColor &color, const QColor &fillColor)
61 : d(new Private)
62{
63 d->locationType = String;
64 d->locationsString = locations;
65 d->weight = weight;
66 d->color = color;
67 d->fillColor = fillColor;
68}
69
70StaticMapPath::StaticMapPath(const KContacts::Address::List &locations, const quint8 weight, const QColor &color, const QColor &fillColor)
71 : d(new Private)
72{
73 d->locationType = KABCAddress;
74 d->locationsAddress = locations;
75 d->weight = weight;
76 d->color = color;
77 d->fillColor = fillColor;
78}
79
80StaticMapPath::StaticMapPath(const QList<KContacts::Geo> &locations, const quint8 weight, const QColor &color, const QColor &fillColor)
81 : d(new Private)
82{
83 d->locationType = KABCGeo;
84 d->locationsGeo = locations;
85 d->weight = weight;
86 d->color = color;
87 d->fillColor = fillColor;
88}
89
91{
92 delete d;
93}
94
95StaticMapPath::LocationType StaticMapPath::locationType() const
96{
97 return d->locationType;
98}
99
101{
102 return d->color;
103}
104
106{
107 d->color = color;
108}
109
111{
112 return (d->locationType != Undefined);
113}
114
116{
117 return d->fillColor;
118}
119
121{
122 d->fillColor = color;
123}
124
126{
127 return d->locationsString;
128}
129
131{
132 d->locationType = String;
133 d->locationsString = locations;
134 d->locationsAddress.clear();
135 d->locationsGeo.clear();
136}
137
139{
140 return d->locationsAddress;
141}
142
144{
145 d->locationType = KABCAddress;
146 d->locationsAddress = locations;
147 d->locationsString.clear();
148 d->locationsGeo.clear();
149}
150
152{
153 return d->locationsGeo;
154}
155
157{
158 d->locationType = KABCGeo;
159 d->locationsGeo = locations;
160 d->locationsString.clear();
161 d->locationsAddress.clear();
162}
163
165{
166 QString ret;
167
168 if (d->color != Qt::blue) {
169 ret += QLatin1StringView("color:") + d->color.name().replace(QLatin1Char('#'), QLatin1StringView("0x")) + QLatin1Char('|');
170 }
171 if (d->weight != 5) {
172 ret += QLatin1StringView("weight:") + QString::number(d->weight) + QLatin1Char('|');
173 }
174 if (d->fillColor.isValid()) {
175 ret += QLatin1StringView("fillcolor:") + d->fillColor.name().replace(QLatin1Char('#'), QLatin1StringView("0x")) + QLatin1Char('|');
176 }
177
178 if (locationType() == String) {
179 for (const QString &addr : std::as_const(d->locationsString)) {
180 ret += addr + QLatin1Char('|');
181 }
182
183 } else if (locationType() == KABCAddress) {
184 for (const KContacts::Address &addr : std::as_const(d->locationsAddress)) {
185 ret += addr.formatted(KContacts::AddressFormatStyle::Postal) + QLatin1Char('|');
186 }
187
188 } else if (locationType() == KABCGeo) {
189 for (const KContacts::Geo &addr : std::as_const(d->locationsGeo)) {
190 ret += QString::number(addr.latitude()) + QLatin1StringView(",") + QString::number(addr.longitude()) + QLatin1Char('|');
191 }
192 }
193
196 ret.replace(QLatin1Char(' '), QLatin1Char('+'));
197 ret.replace(QLatin1Char('\n'), QLatin1Char(','));
198 ret.remove(ret.lastIndexOf(QLatin1Char('|')), 1);
199
200 return ret;
201}
202
204{
205 return d->weight;
206}
207
208void StaticMapPath::setWeight(const quint8 weight)
209{
210 d->weight = weight;
211}
212
214{
215 if (&other == this) {
216 return *this;
217 }
218
219 d->init(*(other.d));
220 return *this;
221}
Represents path with defined locations, weight, color and color for filled area.
QColor color() const
Returns the color of path.
QColor fillColor() const
Returns the color of filled area.
~StaticMapPath()
Destructor.
KContacts::Address::List locationsAddress() const
Returns locations in KContacts::Address.
quint8 weight() const
Returns weight of the path.
void setColor(const QColor &color)
Sets color of the path.
void setWeight(const quint8 weight)
Sets weight of the path.
QString toString() const
Returns all locations and path preferences in format to URL query.
StaticMapPath & operator=(const StaticMapPath &other)
Assignment operator.
void setFillColor(const QColor &color)
Sets color for filled area in path.
bool isValid() const
Returns whether the path is valid.
QList< KContacts::Geo > locationsGeo() const
Returns locations in KContacts::Geo.
QStringList locationsString() const
Returns locations in QString.
StaticMapPath()
Constructs an empty path.
void setLocations(const QStringList &locations)
Sets locations for path.
LocationType locationType() const
Location type.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
bool isValid() const const
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 Mon Nov 4 2024 16:36:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.