File indexing completed on 2024-05-12 05:22:31
0001 /* 0002 SPDX-FileCopyrightText: 2012 Jan Grulich <grulja@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "staticmapmarker.h" 0008 0009 using namespace KGAPI2; 0010 0011 class Q_DECL_HIDDEN StaticMapMarker::Private 0012 { 0013 public: 0014 Private(); 0015 Private(const Private &other); 0016 0017 void init(const Private &other); 0018 0019 LocationType locationType = StaticMapMarker::Undefined; 0020 MarkerSize size = StaticMapMarker::Normal; 0021 0022 QColor color = Qt::red; 0023 QChar label; 0024 0025 QStringList locationsString; 0026 KContacts::Address::List locationsAddress; 0027 QList<KContacts::Geo> locationsGeo; 0028 }; 0029 0030 StaticMapMarker::Private::Private() 0031 { 0032 } 0033 0034 StaticMapMarker::Private::Private(const Private &other) 0035 { 0036 init(other); 0037 } 0038 0039 void StaticMapMarker::Private::init(const Private &other) 0040 { 0041 locationType = other.locationType; 0042 size = other.size; 0043 color = other.color; 0044 label = other.label; 0045 locationsString = other.locationsString; 0046 locationsAddress = other.locationsAddress; 0047 locationsGeo = other.locationsGeo; 0048 } 0049 0050 StaticMapMarker::StaticMapMarker() 0051 : d(new Private) 0052 { 0053 } 0054 0055 StaticMapMarker::StaticMapMarker(const QString &address, const QChar &label, const MarkerSize size, const QColor &color) 0056 : d(new Private) 0057 { 0058 QStringList list; 0059 list << address; 0060 d->locationType = String; 0061 d->locationsString = list; 0062 d->label = label; 0063 d->size = size; 0064 d->color = color; 0065 } 0066 0067 StaticMapMarker::StaticMapMarker(const KContacts::Address &address, QChar label, const MarkerSize size, const QColor &color) 0068 : d(new Private) 0069 { 0070 KContacts::Address::List list; 0071 list << address; 0072 d->locationType = KABCAddress; 0073 d->locationsAddress = list; 0074 d->label = label; 0075 d->size = size; 0076 d->color = color; 0077 } 0078 0079 StaticMapMarker::StaticMapMarker(const KContacts::Geo &address, QChar label, const MarkerSize size, const QColor &color) 0080 : d(new Private) 0081 { 0082 QList<KContacts::Geo> list; 0083 list << address; 0084 d->locationType = KABCGeo; 0085 d->locationsGeo = list; 0086 d->label = label; 0087 d->size = size; 0088 d->color = color; 0089 } 0090 0091 StaticMapMarker::StaticMapMarker(const QStringList &locations, QChar label, const MarkerSize size, const QColor &color) 0092 : d(new Private) 0093 { 0094 d->locationType = String; 0095 d->locationsString = locations; 0096 d->label = label; 0097 d->size = size; 0098 d->color = color; 0099 } 0100 0101 StaticMapMarker::StaticMapMarker(const KContacts::Address::List &locations, QChar label, const MarkerSize size, const QColor &color) 0102 : d(new Private) 0103 { 0104 d->locationType = KABCAddress; 0105 d->locationsAddress = locations; 0106 d->label = label; 0107 d->size = size; 0108 d->color = color; 0109 } 0110 0111 StaticMapMarker::StaticMapMarker(const QList<KContacts::Geo> &locations, QChar label, const MarkerSize size, const QColor &color) 0112 : d(new Private) 0113 { 0114 d->locationType = KABCGeo; 0115 d->locationsGeo = locations; 0116 d->label = label; 0117 d->size = size; 0118 d->color = color; 0119 } 0120 0121 StaticMapMarker::StaticMapMarker(const StaticMapMarker &other) 0122 : d(new Private(*(other.d))) 0123 { 0124 } 0125 0126 StaticMapMarker::~StaticMapMarker() 0127 { 0128 delete d; 0129 } 0130 0131 StaticMapMarker::LocationType StaticMapMarker::locationType() const 0132 { 0133 return d->locationType; 0134 } 0135 0136 QColor StaticMapMarker::color() const 0137 { 0138 return d->color; 0139 } 0140 0141 void StaticMapMarker::setColor(const QColor &color) 0142 { 0143 d->color = color; 0144 } 0145 0146 bool StaticMapMarker::isValid() const 0147 { 0148 return (d->locationType != Undefined); 0149 } 0150 0151 QChar StaticMapMarker::label() const 0152 { 0153 return d->label; 0154 } 0155 0156 void StaticMapMarker::setLabel(QChar label) 0157 { 0158 d->label = label; 0159 } 0160 0161 QStringList StaticMapMarker::locationsString() const 0162 { 0163 return d->locationsString; 0164 } 0165 0166 void StaticMapMarker::setLocation(const QString &location) 0167 { 0168 d->locationType = String; 0169 d->locationsString.clear(); 0170 d->locationsString << location; 0171 d->locationsAddress.clear(); 0172 d->locationsGeo.clear(); 0173 } 0174 0175 void StaticMapMarker::setLocations(const QStringList &locations) 0176 { 0177 d->locationType = KABCAddress; 0178 d->locationsString = locations; 0179 d->locationsAddress.clear(); 0180 d->locationsGeo.clear(); 0181 } 0182 0183 KContacts::Address::List StaticMapMarker::locationsAddress() const 0184 { 0185 return d->locationsAddress; 0186 } 0187 0188 void StaticMapMarker::setLocation(const KContacts::Address &location) 0189 { 0190 d->locationType = KABCAddress; 0191 d->locationsAddress.clear(); 0192 d->locationsAddress << location; 0193 d->locationsString.clear(); 0194 d->locationsGeo.clear(); 0195 } 0196 0197 void StaticMapMarker::setLocations(const KContacts::Address::List &locations) 0198 { 0199 d->locationType = KABCAddress; 0200 d->locationsAddress = locations; 0201 d->locationsString.clear(); 0202 d->locationsGeo.clear(); 0203 } 0204 0205 QList<KContacts::Geo> StaticMapMarker::locationsGeo() const 0206 { 0207 return d->locationsGeo; 0208 } 0209 0210 void StaticMapMarker::setLocation(const KContacts::Geo &location) 0211 { 0212 d->locationType = KABCGeo; 0213 d->locationsGeo.clear(); 0214 d->locationsGeo << location; 0215 d->locationsString.clear(); 0216 d->locationsAddress.clear(); 0217 } 0218 0219 void StaticMapMarker::setLocations(const QList<KContacts::Geo> &locations) 0220 { 0221 d->locationType = KABCGeo; 0222 d->locationsGeo = locations; 0223 d->locationsString.clear(); 0224 d->locationsAddress.clear(); 0225 } 0226 0227 StaticMapMarker::MarkerSize StaticMapMarker::size() const 0228 { 0229 return d->size; 0230 } 0231 0232 void StaticMapMarker::setSize(const MarkerSize size) 0233 { 0234 d->size = size; 0235 } 0236 0237 QString StaticMapMarker::toString() const 0238 { 0239 QString ret; 0240 0241 switch (d->size) { 0242 case Tiny: 0243 ret += QLatin1StringView("size:tiny|"); 0244 break; 0245 case Small: 0246 ret += QLatin1StringView("size:small|"); 0247 break; 0248 case Middle: 0249 ret += QLatin1StringView("size:mid|"); 0250 break; 0251 case Normal: 0252 break; 0253 } 0254 0255 if (d->color != Qt::red) { 0256 ret += QLatin1StringView("color:") + d->color.name().replace(QLatin1Char('#'), QLatin1StringView("0x")) + QLatin1Char('|'); 0257 } 0258 0259 if (d->label.isLetterOrNumber() && d->size > 1) { 0260 ret += QLatin1StringView("label:") + d->label.toUpper() + QLatin1Char('|'); 0261 } 0262 0263 if (d->locationType == String) { 0264 for (const QString &addr : std::as_const(d->locationsString)) { 0265 ret += addr + QLatin1Char('|'); 0266 } 0267 0268 } else if (d->locationType == KABCAddress) { 0269 for (const KContacts::Address &addr : std::as_const(d->locationsAddress)) { 0270 ret += addr.formatted(KContacts::AddressFormatStyle::Postal) + QLatin1Char('|'); 0271 } 0272 0273 } else if (d->locationType == KABCGeo) { 0274 for (const KContacts::Geo &addr : std::as_const(d->locationsGeo)) { 0275 ret += QString::number(addr.latitude()) + QLatin1Char(',') + QString::number(addr.longitude()) + QLatin1Char('|'); 0276 } 0277 } 0278 0279 ret.replace(QLatin1StringView(", "), QLatin1StringView(",")); 0280 ret.replace(QLatin1StringView(". "), QLatin1StringView(".")); 0281 ret.replace(QLatin1Char(' '), QLatin1Char('+')); 0282 ret.replace(QLatin1Char('\n'), QLatin1Char(',')); 0283 ret.remove(ret.lastIndexOf(QLatin1Char('|')), 1); 0284 0285 return ret; 0286 } 0287 0288 StaticMapMarker &StaticMapMarker::operator=(const StaticMapMarker &other) 0289 { 0290 if (&other == this) { 0291 return *this; 0292 } 0293 0294 d->init(*(other.d)); 0295 return *this; 0296 }