File indexing completed on 2024-05-19 05:07:20
0001 /* 0002 SPDX-FileCopyrightText: 2000-2001 Michael Edwardes <mte@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2002-2019 Thomas Baumgart <tbaumgart@kde.org> 0004 SPDX-FileCopyrightText: 2003 Kevin Tambascio <ktambascio@users.sourceforge.net> 0005 SPDX-FileCopyrightText: 2006 Ace Jones <acejones@users.sourceforge.net> 0006 SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "mymoneypayee.h" 0011 #include "mymoneypayee_p.h" 0012 0013 // ---------------------------------------------------------------------------- 0014 // QT Includes 0015 0016 #include <QRegularExpression> 0017 #include <QSet> 0018 #include <QString> 0019 #include <QStringList> 0020 0021 // ---------------------------------------------------------------------------- 0022 // Project Includes 0023 0024 #include "mymoneyexception.h" 0025 #include "mymoneyenums.h" 0026 0027 /// @todo remove and replace that one occurrence with MyMoneyPayee() 0028 MyMoneyPayee MyMoneyPayee::null; 0029 0030 MyMoneyPayee::MyMoneyPayee() : 0031 MyMoneyObject(*new MyMoneyPayeePrivate) 0032 { 0033 } 0034 0035 MyMoneyPayee::MyMoneyPayee(const QString &id): 0036 MyMoneyObject(*new MyMoneyPayeePrivate, id) 0037 { 0038 } 0039 0040 MyMoneyPayee::MyMoneyPayee(const MyMoneyPayee& other) : 0041 MyMoneyObject(*new MyMoneyPayeePrivate(*other.d_func()), other.id()), 0042 MyMoneyPayeeIdentifierContainer(other) 0043 { 0044 } 0045 0046 MyMoneyPayee::MyMoneyPayee(const QString& id, const MyMoneyPayee& other) : 0047 MyMoneyObject(*new MyMoneyPayeePrivate(*other.d_func()), id), 0048 MyMoneyPayeeIdentifierContainer(other) 0049 { 0050 } 0051 0052 MyMoneyPayee::~MyMoneyPayee() 0053 { 0054 } 0055 0056 bool MyMoneyPayee::operator == (const MyMoneyPayee& right) const 0057 { 0058 Q_D(const MyMoneyPayee); 0059 auto d2 = static_cast<const MyMoneyPayeePrivate *>(right.d_func()); 0060 return (MyMoneyObject::operator==(right) // 0061 && ((d->m_name.length() == 0 && d2->m_name.length() == 0) || (d->m_name == d2->m_name)) && 0062 ((d->m_address.length() == 0 && d2->m_address.length() == 0) || (d->m_address == d2->m_address)) && 0063 ((d->m_city.length() == 0 && d2->m_city.length() == 0) || (d->m_city == d2->m_city)) && 0064 ((d->m_state.length() == 0 && d2->m_state.length() == 0) || (d->m_state == d2->m_state)) && 0065 ((d->m_postcode.length() == 0 && d2->m_postcode.length() == 0) || (d->m_postcode == d2->m_postcode)) && 0066 ((d->m_telephone.length() == 0 && d2->m_telephone.length() == 0) || (d->m_telephone == d2->m_telephone)) && 0067 ((d->m_email.length() == 0 && d2->m_email.length() == 0) || (d->m_email == d2->m_email)) && 0068 (d->m_matchingEnabled == d2->m_matchingEnabled) && 0069 (d->m_usingMatchKey == d2->m_usingMatchKey) && 0070 (d->m_matchKeyIgnoreCase == d2->m_matchKeyIgnoreCase) && 0071 ((d->m_matchKey.length() == 0 && d2->m_matchKey.length() == 0) || d->m_matchKey == d2->m_matchKey) && 0072 ((d->m_reference.length() == 0 && d2->m_reference.length() == 0) || (d->m_reference == d2->m_reference)) && 0073 ((d->m_defaultAccountId.length() == 0 && d2->m_defaultAccountId.length() == 0) || d->m_defaultAccountId == d2->m_defaultAccountId)); 0074 } 0075 0076 bool MyMoneyPayee::operator < (const MyMoneyPayee& right) const 0077 { 0078 Q_D(const MyMoneyPayee); 0079 auto d2 = static_cast<const MyMoneyPayeePrivate *>(right.d_func()); 0080 return d->m_name < d2->m_name; 0081 } 0082 0083 QString MyMoneyPayee::name() const 0084 { 0085 Q_D(const MyMoneyPayee); 0086 return d->m_name; 0087 } 0088 0089 void MyMoneyPayee::setName(const QString& val) 0090 { 0091 Q_D(MyMoneyPayee); 0092 d->m_name = val; 0093 } 0094 0095 QString MyMoneyPayee::address() const 0096 { 0097 Q_D(const MyMoneyPayee); 0098 return d->m_address; 0099 } 0100 0101 void MyMoneyPayee::setAddress(const QString& val) 0102 { 0103 Q_D(MyMoneyPayee); 0104 d->m_address = val; 0105 } 0106 0107 QString MyMoneyPayee::city() const 0108 { 0109 Q_D(const MyMoneyPayee); 0110 return d->m_city; 0111 } 0112 0113 void MyMoneyPayee::setCity(const QString& val) 0114 { 0115 Q_D(MyMoneyPayee); 0116 d->m_city = val; 0117 } 0118 0119 QString MyMoneyPayee::state() const 0120 { 0121 Q_D(const MyMoneyPayee); 0122 return d->m_state; 0123 } 0124 0125 void MyMoneyPayee::setState(const QString& val) 0126 { 0127 Q_D(MyMoneyPayee); 0128 d->m_state = val; 0129 } 0130 0131 QString MyMoneyPayee::postcode() const 0132 { 0133 Q_D(const MyMoneyPayee); 0134 return d->m_postcode; 0135 } 0136 0137 void MyMoneyPayee::setPostcode(const QString& val) 0138 { 0139 Q_D(MyMoneyPayee); 0140 d->m_postcode = val; 0141 } 0142 0143 QString MyMoneyPayee::telephone() const 0144 { 0145 Q_D(const MyMoneyPayee); 0146 return d->m_telephone; 0147 } 0148 0149 void MyMoneyPayee::setTelephone(const QString& val) 0150 { 0151 Q_D(MyMoneyPayee); 0152 d->m_telephone = val; 0153 } 0154 0155 QString MyMoneyPayee::email() const 0156 { 0157 Q_D(const MyMoneyPayee); 0158 return d->m_email; 0159 } 0160 0161 void MyMoneyPayee::setEmail(const QString& val) 0162 { 0163 Q_D(MyMoneyPayee); 0164 d->m_email = val; 0165 } 0166 0167 QString MyMoneyPayee::notes() const 0168 { 0169 Q_D(const MyMoneyPayee); 0170 return d->m_notes; 0171 } 0172 0173 void MyMoneyPayee::setNotes(const QString& val) 0174 { 0175 Q_D(MyMoneyPayee); 0176 d->m_notes = val; 0177 } 0178 0179 QString MyMoneyPayee::reference() const 0180 { 0181 Q_D(const MyMoneyPayee); 0182 return d->m_reference; 0183 } 0184 0185 void MyMoneyPayee::setReference(const QString& ref) 0186 { 0187 Q_D(MyMoneyPayee); 0188 d->m_reference = ref; 0189 } 0190 0191 bool MyMoneyPayee::isMatchingEnabled() const 0192 { 0193 Q_D(const MyMoneyPayee); 0194 return d->m_matchingEnabled; 0195 } 0196 0197 bool MyMoneyPayee::isUsingMatchKey() const 0198 { 0199 Q_D(const MyMoneyPayee); 0200 return d->m_usingMatchKey; 0201 } 0202 0203 bool MyMoneyPayee::isMatchKeyIgnoreCase() const 0204 { 0205 Q_D(const MyMoneyPayee); 0206 return d->m_matchKeyIgnoreCase; 0207 } 0208 0209 QString MyMoneyPayee::matchKey() const 0210 { 0211 Q_D(const MyMoneyPayee); 0212 return d->m_matchKey; 0213 } 0214 0215 eMyMoney::Payee::MatchType MyMoneyPayee::matchData(bool& ignorecase, QStringList& keys) const 0216 { 0217 auto type = eMyMoney::Payee::MatchType::Disabled; 0218 keys.clear(); 0219 0220 Q_D(const MyMoneyPayee); 0221 ignorecase = d->m_matchKeyIgnoreCase; 0222 0223 if (d->m_matchingEnabled) { 0224 type = d->m_usingMatchKey ? eMyMoney::Payee::MatchType::Key : eMyMoney::Payee::MatchType::Name; 0225 if (type == eMyMoney::Payee::MatchType::Key) { 0226 if (d->m_matchKey.contains(QLatin1Char('\n'))) 0227 keys = d->m_matchKey.split(QLatin1Char('\n')); 0228 else 0229 keys = d->m_matchKey.split(QLatin1Char(';')); // for compatibility with 4.8.0 0230 } else if (d->m_matchKey.compare(QLatin1String("^$")) == 0) { 0231 type = eMyMoney::Payee::MatchType::NameExact; 0232 } 0233 } 0234 0235 return type; 0236 } 0237 0238 eMyMoney::Payee::MatchType MyMoneyPayee::matchData(bool& ignorecase, QString& keyString) const 0239 { 0240 QStringList keys; 0241 auto type = matchData(ignorecase, keys); 0242 keyString = keys.join(QLatin1Char('\n')); 0243 return type; 0244 } 0245 0246 void MyMoneyPayee::setMatchData(eMyMoney::Payee::MatchType type, bool ignorecase, const QStringList& keys) 0247 { 0248 Q_D(MyMoneyPayee); 0249 d->m_matchingEnabled = (type != eMyMoney::Payee::MatchType::Disabled); 0250 d->m_matchKeyIgnoreCase = ignorecase; 0251 d->m_matchKey.clear(); 0252 0253 if (d->m_matchingEnabled) { 0254 d->m_usingMatchKey = (type == eMyMoney::Payee::MatchType::Key); 0255 if (d->m_usingMatchKey) { 0256 const QRegularExpression validKeyRegExp(QLatin1String("[^ ]")); 0257 const auto filteredKeys = keys.filter(validKeyRegExp); 0258 d->m_matchKey = filteredKeys.join(QLatin1Char('\n')); 0259 } else if ((type == eMyMoney::Payee::MatchType::Name) && (keys.count() == 1) && (keys.at(0) == QLatin1String("^$"))) { 0260 d->m_matchKey = QLatin1String("^$"); 0261 } else if (type == eMyMoney::Payee::MatchType::NameExact) { 0262 d->m_matchKey = QLatin1String("^$"); 0263 } 0264 } 0265 } 0266 0267 void MyMoneyPayee::setMatchData(eMyMoney::Payee::MatchType type, bool ignorecase, const QString& keys) 0268 { 0269 if (keys.contains(QLatin1Char('\n'))) 0270 setMatchData(type, ignorecase, keys.split(QLatin1Char('\n'))); 0271 else 0272 setMatchData(type, ignorecase, keys.split(QLatin1Char(';'))); // for compatibility with 4.8.0 0273 } 0274 0275 QString MyMoneyPayee::defaultAccountId() const 0276 { 0277 Q_D(const MyMoneyPayee); 0278 return d->m_defaultAccountId; 0279 } 0280 0281 void MyMoneyPayee::setDefaultAccountId(const QString& id) 0282 { 0283 Q_D(MyMoneyPayee); 0284 d->m_defaultAccountId = id; 0285 d->clearReferences(); 0286 } 0287 0288 // vim:cin:si:ai:et:ts=2:sw=2: