File indexing completed on 2024-05-12 05:22:32
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 "staticmappath.h" 0008 0009 using namespace KGAPI2; 0010 0011 class Q_DECL_HIDDEN StaticMapPath::Private 0012 { 0013 public: 0014 Private(); 0015 Private(const Private &other); 0016 0017 void init(const Private &other); 0018 0019 StaticMapPath::LocationType locationType; 0020 0021 QColor color = Qt::blue; 0022 QColor fillColor; 0023 quint8 weight = 5; 0024 0025 QStringList locationsString; 0026 KContacts::Address::List locationsAddress; 0027 QList<KContacts::Geo> locationsGeo; 0028 }; 0029 0030 StaticMapPath::Private::Private() 0031 { 0032 } 0033 0034 StaticMapPath::Private::Private(const Private &other) 0035 { 0036 init(other); 0037 } 0038 0039 void StaticMapPath::Private::init(const Private &other) 0040 { 0041 locationType = other.locationType; 0042 color = other.color; 0043 fillColor = other.fillColor; 0044 weight = other.weight; 0045 locationsString = other.locationsString; 0046 locationsAddress = other.locationsAddress; 0047 locationsGeo = other.locationsGeo; 0048 } 0049 0050 StaticMapPath::StaticMapPath() 0051 : d(new Private) 0052 { 0053 } 0054 0055 StaticMapPath::StaticMapPath(const StaticMapPath &other) 0056 : d(new Private(*(other.d))) 0057 { 0058 } 0059 0060 StaticMapPath::StaticMapPath(const QStringList &locations, const quint8 weight, const QColor &color, const QColor &fillColor) 0061 : d(new Private) 0062 { 0063 d->locationType = String; 0064 d->locationsString = locations; 0065 d->weight = weight; 0066 d->color = color; 0067 d->fillColor = fillColor; 0068 } 0069 0070 StaticMapPath::StaticMapPath(const KContacts::Address::List &locations, const quint8 weight, const QColor &color, const QColor &fillColor) 0071 : d(new Private) 0072 { 0073 d->locationType = KABCAddress; 0074 d->locationsAddress = locations; 0075 d->weight = weight; 0076 d->color = color; 0077 d->fillColor = fillColor; 0078 } 0079 0080 StaticMapPath::StaticMapPath(const QList<KContacts::Geo> &locations, const quint8 weight, const QColor &color, const QColor &fillColor) 0081 : d(new Private) 0082 { 0083 d->locationType = KABCGeo; 0084 d->locationsGeo = locations; 0085 d->weight = weight; 0086 d->color = color; 0087 d->fillColor = fillColor; 0088 } 0089 0090 StaticMapPath::~StaticMapPath() 0091 { 0092 delete d; 0093 } 0094 0095 StaticMapPath::LocationType StaticMapPath::locationType() const 0096 { 0097 return d->locationType; 0098 } 0099 0100 QColor StaticMapPath::color() const 0101 { 0102 return d->color; 0103 } 0104 0105 void StaticMapPath::setColor(const QColor &color) 0106 { 0107 d->color = color; 0108 } 0109 0110 bool StaticMapPath::isValid() const 0111 { 0112 return (d->locationType != Undefined); 0113 } 0114 0115 QColor StaticMapPath::fillColor() const 0116 { 0117 return d->fillColor; 0118 } 0119 0120 void StaticMapPath::setFillColor(const QColor &color) 0121 { 0122 d->fillColor = color; 0123 } 0124 0125 QStringList StaticMapPath::locationsString() const 0126 { 0127 return d->locationsString; 0128 } 0129 0130 void StaticMapPath::setLocations(const QStringList &locations) 0131 { 0132 d->locationType = String; 0133 d->locationsString = locations; 0134 d->locationsAddress.clear(); 0135 d->locationsGeo.clear(); 0136 } 0137 0138 KContacts::Address::List StaticMapPath::locationsAddress() const 0139 { 0140 return d->locationsAddress; 0141 } 0142 0143 void StaticMapPath::setLocations(const KContacts::Address::List &locations) 0144 { 0145 d->locationType = KABCAddress; 0146 d->locationsAddress = locations; 0147 d->locationsString.clear(); 0148 d->locationsGeo.clear(); 0149 } 0150 0151 QList<KContacts::Geo> StaticMapPath::locationsGeo() const 0152 { 0153 return d->locationsGeo; 0154 } 0155 0156 void StaticMapPath::setLocations(const QList<KContacts::Geo> &locations) 0157 { 0158 d->locationType = KABCGeo; 0159 d->locationsGeo = locations; 0160 d->locationsString.clear(); 0161 d->locationsAddress.clear(); 0162 } 0163 0164 QString StaticMapPath::toString() const 0165 { 0166 QString ret; 0167 0168 if (d->color != Qt::blue) { 0169 ret += QLatin1StringView("color:") + d->color.name().replace(QLatin1Char('#'), QLatin1StringView("0x")) + QLatin1Char('|'); 0170 } 0171 if (d->weight != 5) { 0172 ret += QLatin1StringView("weight:") + QString::number(d->weight) + QLatin1Char('|'); 0173 } 0174 if (d->fillColor.isValid()) { 0175 ret += QLatin1StringView("fillcolor:") + d->fillColor.name().replace(QLatin1Char('#'), QLatin1StringView("0x")) + QLatin1Char('|'); 0176 } 0177 0178 if (locationType() == String) { 0179 for (const QString &addr : std::as_const(d->locationsString)) { 0180 ret += addr + QLatin1Char('|'); 0181 } 0182 0183 } else if (locationType() == KABCAddress) { 0184 for (const KContacts::Address &addr : std::as_const(d->locationsAddress)) { 0185 ret += addr.formatted(KContacts::AddressFormatStyle::Postal) + QLatin1Char('|'); 0186 } 0187 0188 } else if (locationType() == KABCGeo) { 0189 for (const KContacts::Geo &addr : std::as_const(d->locationsGeo)) { 0190 ret += QString::number(addr.latitude()) + QLatin1StringView(",") + QString::number(addr.longitude()) + QLatin1Char('|'); 0191 } 0192 } 0193 0194 ret.replace(QLatin1StringView(", "), QLatin1StringView(",")); 0195 ret.replace(QLatin1StringView(". "), QLatin1StringView(".")); 0196 ret.replace(QLatin1Char(' '), QLatin1Char('+')); 0197 ret.replace(QLatin1Char('\n'), QLatin1Char(',')); 0198 ret.remove(ret.lastIndexOf(QLatin1Char('|')), 1); 0199 0200 return ret; 0201 } 0202 0203 quint8 StaticMapPath::weight() const 0204 { 0205 return d->weight; 0206 } 0207 0208 void StaticMapPath::setWeight(const quint8 weight) 0209 { 0210 d->weight = weight; 0211 } 0212 0213 StaticMapPath &StaticMapPath::operator=(const StaticMapPath &other) 0214 { 0215 if (&other == this) { 0216 return *this; 0217 } 0218 0219 d->init(*(other.d)); 0220 return *this; 0221 }