diff --git a/kmymoney/mymoney/mymoneyaccount.h b/kmymoney/mymoney/mymoneyaccount.h --- a/kmymoney/mymoney/mymoneyaccount.h +++ b/kmymoney/mymoney/mymoneyaccount.h @@ -39,7 +39,6 @@ class QString; class QDate; class QPixmap; -class QDomElement; class MyMoneySecurity; class MyMoneyMoney; class MyMoneySplit; @@ -369,8 +368,6 @@ */ void setCurrencyId(const QString& id); - void writeXML(QDomDocument& document, QDomElement& parent) const override; - /** * This method checks if a reference to the given object exists. It returns, * a @p true if the object is referencing the one requested by the diff --git a/kmymoney/mymoney/mymoneyaccount.cpp b/kmymoney/mymoney/mymoneyaccount.cpp --- a/kmymoney/mymoney/mymoneyaccount.cpp +++ b/kmymoney/mymoney/mymoneyaccount.cpp @@ -355,61 +355,6 @@ } } -void MyMoneyAccount::writeXML(QDomDocument& document, QDomElement& parent) const -{ - auto el = document.createElement(nodeNames[nnAccount]); - - Q_D(const MyMoneyAccount); - d->writeBaseXML(document, el); - - el.setAttribute(d->getAttrName(Account::Attribute::ParentAccount), parentAccountId()); - el.setAttribute(d->getAttrName(Account::Attribute::LastReconciled), MyMoneyUtils::dateToString(lastReconciliationDate())); - el.setAttribute(d->getAttrName(Account::Attribute::LastModified), MyMoneyUtils::dateToString(lastModified())); - el.setAttribute(d->getAttrName(Account::Attribute::Institution), institutionId()); - el.setAttribute(d->getAttrName(Account::Attribute::Opened), MyMoneyUtils::dateToString(openingDate())); - el.setAttribute(d->getAttrName(Account::Attribute::Number), number()); - // el.setAttribute(getAttrName(anOpeningBalance), openingBalance().toString()); - el.setAttribute(d->getAttrName(Account::Attribute::Type), (int)accountType()); - el.setAttribute(d->getAttrName(Account::Attribute::Name), name()); - el.setAttribute(d->getAttrName(Account::Attribute::Description), description()); - if (!currencyId().isEmpty()) - el.setAttribute(d->getAttrName(Account::Attribute::Currency), currencyId()); - - //Add in subaccount information, if this account has subaccounts. - if (accountCount()) { - QDomElement subAccounts = document.createElement(d->getElName(Account::Element::SubAccounts)); - foreach (const auto accountID, accountList()) { - QDomElement temp = document.createElement(d->getElName(Account::Element::SubAccount)); - temp.setAttribute(d->getAttrName(Account::Attribute::ID), accountID); - subAccounts.appendChild(temp); - } - - el.appendChild(subAccounts); - } - - // Write online banking settings - if (d->m_onlineBankingSettings.pairs().count()) { - QDomElement onlinesettings = document.createElement(d->getElName(Account::Element::OnlineBanking)); - QMap::const_iterator it_key = d->m_onlineBankingSettings.pairs().constBegin(); - while (it_key != d->m_onlineBankingSettings.pairs().constEnd()) { - onlinesettings.setAttribute(it_key.key(), it_key.value()); - ++it_key; - } - el.appendChild(onlinesettings); - } - - // FIXME drop the lastStatementDate record from the KVP when it is - // not stored there after setLastReconciliationDate() has been changed - // See comment there when this will happen - // deletePair("lastStatementDate"); - - - //Add in Key-Value Pairs for accounts. - MyMoneyKeyValueContainer::writeXML(document, el); - - parent.appendChild(el); -} - bool MyMoneyAccount::hasReferenceTo(const QString& id) const { Q_D(const MyMoneyAccount); @@ -646,11 +591,13 @@ MyMoneyFile* file = MyMoneyFile::instance(); + const auto strIBAN = QStringLiteral("iban"); + const auto strBIC = QStringLiteral("bic"); // Iban & Bic - if (!value(d->getAttrName(Account::Attribute::IBAN)).isEmpty()) { + if (!value(strIBAN).isEmpty()) { payeeIdentifierTyped iban(new payeeIdentifiers::ibanBic); - iban->setIban(value(d->getAttrName(Account::Attribute::IBAN))); - iban->setBic(file->institution(institutionId()).value(d->getAttrName(Account::Attribute::BIC))); + iban->setIban(value(strIBAN)); + iban->setBic(file->institution(institutionId()).value(strBIC)); iban->setOwnerName(file->user().name()); list.append(iban); } diff --git a/kmymoney/mymoney/mymoneyaccount_p.h b/kmymoney/mymoney/mymoneyaccount_p.h --- a/kmymoney/mymoney/mymoneyaccount_p.h +++ b/kmymoney/mymoney/mymoneyaccount_p.h @@ -44,37 +44,6 @@ using namespace eMyMoney; -namespace eMyMoney -{ - namespace Account - { - enum class Element { SubAccount, - SubAccounts, - OnlineBanking - }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { ID = 0 , - Name, - Type, - ParentAccount, - LastReconciled, - LastModified, - Institution, - Opened, - Number, - Description, - Currency, - OpeningBalance, - IBAN, - BIC, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } - } -} - class MyMoneyAccountPrivate : public MyMoneyObjectPrivate { public: @@ -85,38 +54,6 @@ { } - static QString getElName(const Account::Element el) - { - static const QMap elNames = { - {Account::Element::SubAccount, QStringLiteral("SUBACCOUNT")}, - {Account::Element::SubAccounts, QStringLiteral("SUBACCOUNTS")}, - {Account::Element::OnlineBanking, QStringLiteral("ONLINEBANKING")} - }; - return elNames[el]; - } - - static QString getAttrName(const Account::Attribute attr) - { - static const QHash attrNames = { - {Account::Attribute::ID, QStringLiteral("id")}, - {Account::Attribute::Name, QStringLiteral("name")}, - {Account::Attribute::Type, QStringLiteral("type")}, - {Account::Attribute::ParentAccount, QStringLiteral("parentaccount")}, - {Account::Attribute::LastReconciled, QStringLiteral("lastreconciled")}, - {Account::Attribute::LastModified, QStringLiteral("lastmodified")}, - {Account::Attribute::Institution, QStringLiteral("institution")}, - {Account::Attribute::Opened, QStringLiteral("opened")}, - {Account::Attribute::Number, QStringLiteral("number")}, - {Account::Attribute::Type, QStringLiteral("type")}, - {Account::Attribute::Description, QStringLiteral("description")}, - {Account::Attribute::Currency, QStringLiteral("currency")}, - {Account::Attribute::OpeningBalance, QStringLiteral("openingbalance")}, - {Account::Attribute::IBAN, QStringLiteral("iban")}, - {Account::Attribute::BIC, QStringLiteral("bic")}, - }; - return attrNames[attr]; - } - /** * This member variable identifies the type of account */ diff --git a/kmymoney/mymoney/mymoneybudget.h b/kmymoney/mymoney/mymoneybudget.h --- a/kmymoney/mymoney/mymoneybudget.h +++ b/kmymoney/mymoney/mymoneybudget.h @@ -188,6 +188,8 @@ bool contains(const QString &id) const; QList getaccounts() const; + QMap accountsMap() const; + /** * This method writes this Budget to the DOM element @p e, * within the DOM document @p doc. diff --git a/kmymoney/mymoney/mymoneybudget.cpp b/kmymoney/mymoney/mymoneybudget.cpp --- a/kmymoney/mymoney/mymoneybudget.cpp +++ b/kmymoney/mymoney/mymoneybudget.cpp @@ -556,6 +556,12 @@ return d->m_accounts.values(); } +QMap MyMoneyBudget::accountsMap() const +{ + Q_D(const MyMoneyBudget); + return d->m_accounts; +} + QString MyMoneyBudget::name() const { Q_D(const MyMoneyBudget); diff --git a/kmymoney/mymoney/mymoneycostcenter.h b/kmymoney/mymoney/mymoneycostcenter.h --- a/kmymoney/mymoney/mymoneycostcenter.h +++ b/kmymoney/mymoney/mymoneycostcenter.h @@ -69,8 +69,6 @@ bool operator == (const MyMoneyCostCenter &) const; bool operator <(const MyMoneyCostCenter& right) const; - void writeXML(QDomDocument& document, QDomElement& parent) const override; - /** * This method checks if a reference to the given object exists. It returns, * a @p true if the object is referencing the one requested by the @@ -83,17 +81,8 @@ bool hasReferenceTo(const QString& id) const override; static MyMoneyCostCenter null; - -private: - enum class Attribute { Name }; - - static QString getAttrName(const Attribute attr); - - friend uint qHash(const Attribute, uint seed); }; -inline uint qHash(const MyMoneyCostCenter::Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } // krazy:exclude=inline - inline void swap(MyMoneyCostCenter& first, MyMoneyCostCenter& second) // krazy:exclude=inline { using std::swap; diff --git a/kmymoney/mymoney/mymoneycostcenter.cpp b/kmymoney/mymoney/mymoneycostcenter.cpp --- a/kmymoney/mymoney/mymoneycostcenter.cpp +++ b/kmymoney/mymoney/mymoneycostcenter.cpp @@ -20,7 +20,6 @@ // ---------------------------------------------------------------------------- // QT Includes -#include #include // ---------------------------------------------------------------------------- @@ -80,17 +79,6 @@ return col.compare(d->m_name, d2->m_name); } -void MyMoneyCostCenter::writeXML(QDomDocument& document, QDomElement& parent) const -{ - auto el = document.createElement(nodeNames[nnCostCenter]); - - Q_D(const MyMoneyCostCenter); - d->writeBaseXML(document, el); - - el.setAttribute(getAttrName(Attribute::Name), d->m_name); - parent.appendChild(el); -} - bool MyMoneyCostCenter::hasReferenceTo(const QString& /*id*/) const { return false; @@ -118,11 +106,3 @@ } return d->m_name; } - -QString MyMoneyCostCenter::getAttrName(const Attribute attr) -{ - static const QMap attrNames = { - {Attribute::Name, QStringLiteral("name")}, - }; - return attrNames[attr]; -} diff --git a/kmymoney/mymoney/mymoneyinstitution.h b/kmymoney/mymoney/mymoneyinstitution.h --- a/kmymoney/mymoney/mymoneyinstitution.h +++ b/kmymoney/mymoney/mymoneyinstitution.h @@ -149,8 +149,6 @@ bool operator == (const MyMoneyInstitution&) const; bool operator < (const MyMoneyInstitution& right) const; - void writeXML(QDomDocument& document, QDomElement& parent) const override; - /** * This method checks if a reference to the given object exists. It returns, * a @p true if the object is referencing the one requested by the diff --git a/kmymoney/mymoney/mymoneyinstitution.cpp b/kmymoney/mymoney/mymoneyinstitution.cpp --- a/kmymoney/mymoney/mymoneyinstitution.cpp +++ b/kmymoney/mymoney/mymoneyinstitution.cpp @@ -28,8 +28,6 @@ #include #include #include -#include -#include // ---------------------------------------------------------------------------- // KDE Includes @@ -250,38 +248,6 @@ return false; } -void MyMoneyInstitution::writeXML(QDomDocument& document, QDomElement& parent) const -{ - Q_D(const MyMoneyInstitution); - auto el = document.createElement(nodeNames[nnInstitution]); - - d->writeBaseXML(document, el); - - el.setAttribute(d->getAttrName(Institution::Attribute::Name), d->m_name); - el.setAttribute(d->getAttrName(Institution::Attribute::Manager), d->m_manager); - el.setAttribute(d->getAttrName(Institution::Attribute::SortCode), d->m_sortcode); - - auto address = document.createElement(d->getElName(Institution::Element::Address)); - address.setAttribute(d->getAttrName(Institution::Attribute::Street), d->m_street); - address.setAttribute(d->getAttrName(Institution::Attribute::City), d->m_town); - address.setAttribute(d->getAttrName(Institution::Attribute::Zip), d->m_postcode); - address.setAttribute(d->getAttrName(Institution::Attribute::Telephone), d->m_telephone); - el.appendChild(address); - - auto accounts = document.createElement(d->getElName(Institution::Element::AccountIDS)); - foreach (const auto accountID, accountList()) { - auto temp = document.createElement(d->getElName(Institution::Element::AccountID)); - temp.setAttribute(d->getAttrName(Institution::Attribute::ID), accountID); - accounts.appendChild(temp); - } - el.appendChild(accounts); - - //Add in Key-Value Pairs for institutions. - MyMoneyKeyValueContainer::writeXML(document, el); - - parent.appendChild(el); -} - bool MyMoneyInstitution::hasReferenceTo(const QString& /* id */) const { return false; diff --git a/kmymoney/mymoney/mymoneyinstitution_p.h b/kmymoney/mymoney/mymoneyinstitution_p.h --- a/kmymoney/mymoney/mymoneyinstitution_p.h +++ b/kmymoney/mymoney/mymoneyinstitution_p.h @@ -39,55 +39,9 @@ #include "mymoneyobject_p.h" -namespace Institution -{ - enum class Element { AccountID, - AccountIDS, - Address }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { ID = 0, - Name, - Manager, - SortCode, - Street, - City, - Zip, - Telephone, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - class MyMoneyInstitutionPrivate : public MyMoneyObjectPrivate { public: - static QString getElName(const Institution::Element el) - { - static const QMap elNames { - {Institution::Element::AccountID, QStringLiteral("ACCOUNTID")}, - {Institution::Element::AccountIDS, QStringLiteral("ACCOUNTIDS")}, - {Institution::Element::Address, QStringLiteral("ADDRESS")} - }; - return elNames[el]; - } - - static QString getAttrName(const Institution::Attribute attr) - { - static const QHash attrNames { - {Institution::Attribute::ID, QStringLiteral("id")}, - {Institution::Attribute::Name, QStringLiteral("name")}, - {Institution::Attribute::Manager, QStringLiteral("manager")}, - {Institution::Attribute::SortCode, QStringLiteral("sortcode")}, - {Institution::Attribute::Street, QStringLiteral("street")}, - {Institution::Attribute::City, QStringLiteral("city")}, - {Institution::Attribute::Zip, QStringLiteral("zip")}, - {Institution::Attribute::Telephone, QStringLiteral("telephone")} - }; - return attrNames[attr]; - } - /** * This member variable keeps the name of the institution */ diff --git a/kmymoney/mymoney/mymoneypayee.h b/kmymoney/mymoney/mymoneypayee.h --- a/kmymoney/mymoney/mymoneypayee.h +++ b/kmymoney/mymoney/mymoneypayee.h @@ -102,6 +102,11 @@ QString reference() const; void setReference(const QString& ref); + bool isMatchingEnabled() const; + bool isUsingMatchKey() const; + bool isMatchKeyIgnoreCase() const; + QString matchKey() const; + /** * Get all match data in one call * @@ -155,8 +160,6 @@ // bool operator == (const MyMoneyPayee& lhs, const QString& rhs) const; bool operator <(const MyMoneyPayee& right) const; - void writeXML(QDomDocument& document, QDomElement& parent) const override; - /** * This method checks if a reference to the given object exists. It returns, * a @p true if the object is referencing the one requested by the diff --git a/kmymoney/mymoney/mymoneypayee.cpp b/kmymoney/mymoney/mymoneypayee.cpp --- a/kmymoney/mymoney/mymoneypayee.cpp +++ b/kmymoney/mymoney/mymoneypayee.cpp @@ -27,7 +27,6 @@ #include #include -#include #include // ---------------------------------------------------------------------------- @@ -122,46 +121,6 @@ return d->m_name < d2->m_name; } -void MyMoneyPayee::writeXML(QDomDocument& document, QDomElement& parent) const -{ - auto el = document.createElement(nodeNames[nnPayee]); - - Q_D(const MyMoneyPayee); - d->writeBaseXML(document, el); - - el.setAttribute(d->getAttrName(Payee::Attribute::Name), d->m_name); - el.setAttribute(d->getAttrName(Payee::Attribute::Reference), d->m_reference); - el.setAttribute(d->getAttrName(Payee::Attribute::Email), d->m_email); - if (!d->m_notes.isEmpty()) - el.setAttribute(d->getAttrName(Payee::Attribute::Notes), d->m_notes); - - el.setAttribute(d->getAttrName(Payee::Attribute::MatchingEnabled), d->m_matchingEnabled); - if (d->m_matchingEnabled) { - el.setAttribute(d->getAttrName(Payee::Attribute::UsingMatchKey), d->m_usingMatchKey); - el.setAttribute(d->getAttrName(Payee::Attribute::MatchIgnoreCase), d->m_matchKeyIgnoreCase); - el.setAttribute(d->getAttrName(Payee::Attribute::MatchKey), d->m_matchKey); - } - - if (!d->m_defaultAccountId.isEmpty()) { - el.setAttribute(d->getAttrName(Payee::Attribute::DefaultAccountID), d->m_defaultAccountId); - } - - // Save address - QDomElement address = document.createElement(d->getElName(Payee::Element::Address)); - address.setAttribute(d->getAttrName(Payee::Attribute::Street), d->m_address); - address.setAttribute(d->getAttrName(Payee::Attribute::City), d->m_city); - address.setAttribute(d->getAttrName(Payee::Attribute::PostCode), d->m_postcode); - address.setAttribute(d->getAttrName(Payee::Attribute::State), d->m_state); - address.setAttribute(d->getAttrName(Payee::Attribute::Telephone), d->m_telephone); - - el.appendChild(address); - - // Save payeeIdentifiers (account numbers) - MyMoneyPayeeIdentifierContainer::writeXML(document, el); - - parent.appendChild(el); -} - bool MyMoneyPayee::hasReferenceTo(const QString& id) const { Q_D(const MyMoneyPayee); @@ -276,6 +235,30 @@ d->m_reference = ref; } +bool MyMoneyPayee::isMatchingEnabled() const +{ + Q_D(const MyMoneyPayee); + return d->m_matchingEnabled; +} + +bool MyMoneyPayee::isUsingMatchKey() const +{ + Q_D(const MyMoneyPayee); + return d->m_usingMatchKey; +} + +bool MyMoneyPayee::isMatchKeyIgnoreCase() const +{ + Q_D(const MyMoneyPayee); + return d->m_matchKeyIgnoreCase; +} + +QString MyMoneyPayee::matchKey() const +{ + Q_D(const MyMoneyPayee); + return d->m_matchKey; +} + eMyMoney::Payee::MatchType MyMoneyPayee::matchData(bool& ignorecase, QStringList& keys) const { auto type = eMyMoney::Payee::MatchType::Disabled; diff --git a/kmymoney/mymoney/mymoneypayee_p.h b/kmymoney/mymoney/mymoneypayee_p.h --- a/kmymoney/mymoney/mymoneypayee_p.h +++ b/kmymoney/mymoney/mymoneypayee_p.h @@ -35,32 +35,6 @@ #include "mymoneyobject_p.h" -namespace Payee -{ - enum class Element { Address }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { Name = 0, - Type, - Reference, - Notes, - MatchingEnabled, - UsingMatchKey, - MatchIgnoreCase, - MatchKey, - DefaultAccountID, - Street, - City, - PostCode, - Email, - State, - Telephone, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - class MyMoneyPayeePrivate : public MyMoneyObjectPrivate { public: @@ -72,36 +46,6 @@ { } - static QString getElName(const Payee::Element el) - { - static const QMap elNames { - {Payee::Element::Address, QStringLiteral("ADDRESS")} - }; - return elNames[el]; - } - - static QString getAttrName(const Payee::Attribute attr) - { - static const QHash attrNames { - {Payee::Attribute::Name, QStringLiteral("name")}, - {Payee::Attribute::Type, QStringLiteral("type")}, - {Payee::Attribute::Reference, QStringLiteral("reference")}, - {Payee::Attribute::Notes, QStringLiteral("notes")}, - {Payee::Attribute::MatchingEnabled, QStringLiteral("matchingenabled")}, - {Payee::Attribute::UsingMatchKey, QStringLiteral("usingmatchkey")}, - {Payee::Attribute::MatchIgnoreCase, QStringLiteral("matchignorecase")}, - {Payee::Attribute::MatchKey, QStringLiteral("matchkey")}, - {Payee::Attribute::DefaultAccountID, QStringLiteral("defaultaccountid")}, - {Payee::Attribute::Street, QStringLiteral("street")}, - {Payee::Attribute::City, QStringLiteral("city")}, - {Payee::Attribute::PostCode, QStringLiteral("postcode")}, - {Payee::Attribute::Email, QStringLiteral("email")}, - {Payee::Attribute::State, QStringLiteral("state")}, - {Payee::Attribute::Telephone, QStringLiteral("telephone")}, - }; - return attrNames[attr]; - } - // Simple fields QString m_name; QString m_address; diff --git a/kmymoney/mymoney/mymoneypayeeidentifiercontainer.h b/kmymoney/mymoney/mymoneypayeeidentifiercontainer.h --- a/kmymoney/mymoney/mymoneypayeeidentifiercontainer.h +++ b/kmymoney/mymoney/mymoneypayeeidentifiercontainer.h @@ -57,8 +57,9 @@ void resetPayeeIdentifiers(const QList< ::payeeIdentifier >& list = QList< ::payeeIdentifier >()); void loadXML(QDomElement node); -protected: void writeXML(QDomDocument document, QDomElement parent) const; + +protected: QList< ::payeeIdentifier > m_payeeIdentifiers; }; diff --git a/kmymoney/mymoney/mymoneyschedule_p.h b/kmymoney/mymoney/mymoneyschedule_p.h --- a/kmymoney/mymoney/mymoneyschedule_p.h +++ b/kmymoney/mymoney/mymoneyschedule_p.h @@ -38,34 +38,6 @@ using namespace eMyMoney; -namespace eMyMoney -{ - namespace Schedule - { - enum class Element { Payment, - Payments - }; - - enum class Attribute { Name = 0, - Type, - Occurrence, - OccurrenceMultiplier, - PaymentType, - Fixed, - AutoEnter, - LastPayment, - WeekendOption, - Date, - StartDate, - EndDate, - LastDayInMonth, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } - } -} - class MyMoneySchedulePrivate : public MyMoneyObjectPrivate { public: @@ -80,36 +52,6 @@ , m_weekendOption(Schedule::WeekendOption::MoveNothing) {} - static QString getElName(const Schedule::Element el) - { - static const QMap elNames { - {Schedule::Element::Payment, QStringLiteral("PAYMENT")}, - {Schedule::Element::Payments, QStringLiteral("PAYMENTS")} - }; - return elNames[el]; - } - - static QString getAttrName(const Schedule::Attribute attr) - { - static const QHash attrNames { - {Schedule::Attribute::Name, QStringLiteral("name")}, - {Schedule::Attribute::Type, QStringLiteral("type")}, - {Schedule::Attribute::Occurrence, QStringLiteral("occurence")}, // krazy:exclude=spelling - {Schedule::Attribute::OccurrenceMultiplier, QStringLiteral("occurenceMultiplier")}, // krazy:exclude=spelling - {Schedule::Attribute::PaymentType, QStringLiteral("paymentType")}, - {Schedule::Attribute::Fixed, QStringLiteral("fixed")}, - {Schedule::Attribute::AutoEnter, QStringLiteral("autoEnter")}, - {Schedule::Attribute::LastPayment, QStringLiteral("lastPayment")}, - {Schedule::Attribute::WeekendOption, QStringLiteral("weekendOption")}, - {Schedule::Attribute::Date, QStringLiteral("date")}, - {Schedule::Attribute::StartDate, QStringLiteral("startDate")}, - {Schedule::Attribute::EndDate, QStringLiteral("endDate")}, - {Schedule::Attribute::LastDayInMonth, QStringLiteral("lastDayInMonth")} - }; - return attrNames[attr]; - } - - /// Its occurrence eMyMoney::Schedule::Occurrence m_occurrence; diff --git a/kmymoney/mymoney/mymoneysecurity.h b/kmymoney/mymoney/mymoneysecurity.h --- a/kmymoney/mymoney/mymoneysecurity.h +++ b/kmymoney/mymoney/mymoneysecurity.h @@ -122,8 +122,6 @@ int pricePrecision() const; void setPricePrecision(const int pp); - void writeXML(QDomDocument& document, QDomElement& parent) const override; - /** * This method checks if a reference to the given object exists. It returns, * a @p true if the object is referencing the one requested by the diff --git a/kmymoney/mymoney/mymoneysecurity.cpp b/kmymoney/mymoney/mymoneysecurity.cpp --- a/kmymoney/mymoney/mymoneysecurity.cpp +++ b/kmymoney/mymoney/mymoneysecurity.cpp @@ -23,8 +23,6 @@ // QT Includes #include -#include -#include // ---------------------------------------------------------------------------- // KDE Includes @@ -244,36 +242,6 @@ return (id == d->m_tradingCurrency); } -void MyMoneySecurity::writeXML(QDomDocument& document, QDomElement& parent) const -{ - QDomElement el; - if (isCurrency()) - el = document.createElement(nodeNames[nnCurrency]); - else - el = document.createElement(nodeNames[nnSecurity]); - - Q_D(const MyMoneySecurity); - d->writeBaseXML(document, el); - - el.setAttribute(d->getAttrName(Security::Attribute::Name), d->m_name); - el.setAttribute(d->getAttrName(Security::Attribute::Symbol),d->m_tradingSymbol); - el.setAttribute(d->getAttrName(Security::Attribute::Type), static_cast(d->m_securityType)); - el.setAttribute(d->getAttrName(Security::Attribute::RoundingMethod), static_cast(d->m_roundingMethod)); - el.setAttribute(d->getAttrName(Security::Attribute::SAF), d->m_smallestAccountFraction); - el.setAttribute(d->getAttrName(Security::Attribute::PP), d->m_pricePrecision); - if (isCurrency()) - el.setAttribute(d->getAttrName(Security::Attribute::SCF), d->m_smallestCashFraction); - else { - el.setAttribute(d->getAttrName(Security::Attribute::TradingCurrency), d->m_tradingCurrency); - el.setAttribute(d->getAttrName(Security::Attribute::TradingMarket), d->m_tradingMarket); - } - - //Add in Key-Value Pairs for securities. - MyMoneyKeyValueContainer::writeXML(document, el); - - parent.appendChild(el); -} - QString MyMoneySecurity::securityTypeToString(const eMyMoney::Security::Type securityType) { switch (securityType) { diff --git a/kmymoney/mymoney/mymoneysecurity_p.h b/kmymoney/mymoney/mymoneysecurity_p.h --- a/kmymoney/mymoney/mymoneysecurity_p.h +++ b/kmymoney/mymoney/mymoneysecurity_p.h @@ -36,26 +36,6 @@ using namespace eMyMoney; -namespace eMyMoney -{ - namespace Security - { - enum class Attribute { Name = 0, - Symbol, - Type, - RoundingMethod, - SAF, - PP, - SCF, - TradingCurrency, - TradingMarket, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } - } -} - class MyMoneySecurityPrivate : public MyMoneyObjectPrivate { public: @@ -69,22 +49,6 @@ { } - static QString getAttrName(const Security::Attribute attr) - { - static const QHash attrNames { - {Security::Attribute::Name, QStringLiteral("name")}, - {Security::Attribute::Symbol, QStringLiteral("symbol")}, - {Security::Attribute::Type, QStringLiteral("type")}, - {Security::Attribute::RoundingMethod, QStringLiteral("rounding-method")}, - {Security::Attribute::SAF, QStringLiteral("saf")}, - {Security::Attribute::PP, QStringLiteral("pp")}, - {Security::Attribute::SCF, QStringLiteral("scf")}, - {Security::Attribute::TradingCurrency, QStringLiteral("trading-currency")}, - {Security::Attribute::TradingMarket, QStringLiteral("trading-market")} - }; - return attrNames[attr]; - } - QString m_name; QString m_tradingSymbol; QString m_tradingMarket; diff --git a/kmymoney/mymoney/mymoneysplit.h b/kmymoney/mymoney/mymoneysplit.h --- a/kmymoney/mymoney/mymoneysplit.h +++ b/kmymoney/mymoney/mymoneysplit.h @@ -67,7 +67,6 @@ MyMoneySplit(); explicit MyMoneySplit(const QString &id); - explicit MyMoneySplit(const QDomElement& node); MyMoneySplit(const QString& id, const MyMoneySplit& other); diff --git a/kmymoney/mymoney/mymoneysplit.cpp b/kmymoney/mymoney/mymoneysplit.cpp --- a/kmymoney/mymoney/mymoneysplit.cpp +++ b/kmymoney/mymoney/mymoneysplit.cpp @@ -46,35 +46,6 @@ d->m_reconcileFlag = eMyMoney::Split::State::NotReconciled; } -MyMoneySplit::MyMoneySplit(const QDomElement& node) : - MyMoneyObject(*new MyMoneySplitPrivate, node, false), - MyMoneyKeyValueContainer(node.elementsByTagName(MyMoneySplitPrivate::getElName(Split::Element::KeyValuePairs)).item(0).toElement()) -{ - Q_D(MyMoneySplit); - if (d->getElName(Split::Element::Split) != node.tagName()) - throw MYMONEYEXCEPTION_CSTRING("Node was not SPLIT"); - - clearId(); - - d->m_payee = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Payee))); - - QDomNodeList nodeList = node.elementsByTagName(d->getElName(Split::Element::Tag)); - for (int i = 0; i < nodeList.count(); i++) - d->m_tagList << MyMoneyUtils::QStringEmpty(nodeList.item(i).toElement().attribute(d->getAttrName(Split::Attribute::ID))); - - d->m_reconcileDate = MyMoneyUtils::stringToDate(MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::ReconcileDate)))); - d->m_action = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Action))); - d->m_reconcileFlag = static_cast(node.attribute(d->getAttrName(Split::Attribute::ReconcileFlag)).toInt()); - d->m_memo = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Memo))); - d->m_value = MyMoneyMoney(MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Value)))); - d->m_shares = MyMoneyMoney(MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Shares)))); - d->m_price = MyMoneyMoney(MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Price)))); - d->m_account = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Account))); - d->m_costCenter = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::CostCenter))); - d->m_number = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::Number))); - d->m_bankID = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Split::Attribute::BankID))); -} - MyMoneySplit::MyMoneySplit(const MyMoneySplit& other) : MyMoneyObject(*new MyMoneySplitPrivate(*other.d_func()), other.id()), MyMoneyKeyValueContainer(other) diff --git a/kmymoney/mymoney/mymoneysplit_p.h b/kmymoney/mymoney/mymoneysplit_p.h --- a/kmymoney/mymoney/mymoneysplit_p.h +++ b/kmymoney/mymoney/mymoneysplit_p.h @@ -40,40 +40,6 @@ #include "mymoneytransaction.h" #include "mymoneyenums.h" -namespace eMyMoney -{ - namespace Split - { - enum class Element { Split = 0, - Tag, - Match, - Container, - KeyValuePairs - }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { ID = 0, - BankID, - Account, - Payee, - Tag, - Number, - Action, - Value, - Shares, - Price, - Memo, - CostCenter, - ReconcileDate, - ReconcileFlag, - KMMatchedTx, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } - } -} - using namespace eMyMoney; class MyMoneySplitPrivate : public MyMoneyObjectPrivate @@ -86,40 +52,6 @@ { } - static QString getElName(const Split::Element el) - { - static const QHash elNames { - {Split::Element::Split, QStringLiteral("SPLIT")}, - {Split::Element::Tag, QStringLiteral("TAG")}, - {Split::Element::Match, QStringLiteral("MATCH")}, - {Split::Element::Container, QStringLiteral("CONTAINER")}, - {Split::Element::KeyValuePairs, QStringLiteral("KEYVALUEPAIRS")} - }; - return elNames[el]; - } - - static QString getAttrName(const Split::Attribute attr) - { - static const QHash attrNames { - {Split::Attribute::ID, QStringLiteral("id")}, - {Split::Attribute::BankID, QStringLiteral("bankid")}, - {Split::Attribute::Account, QStringLiteral("account")}, - {Split::Attribute::Payee, QStringLiteral("payee")}, - {Split::Attribute::Tag, QStringLiteral("tag")}, - {Split::Attribute::Number, QStringLiteral("number")}, - {Split::Attribute::Action, QStringLiteral("action")}, - {Split::Attribute::Value, QStringLiteral("value")}, - {Split::Attribute::Shares, QStringLiteral("shares")}, - {Split::Attribute::Price, QStringLiteral("price")}, - {Split::Attribute::Memo, QStringLiteral("memo")}, - {Split::Attribute::CostCenter, QStringLiteral("costcenter")}, - {Split::Attribute::ReconcileDate, QStringLiteral("reconciledate")}, - {Split::Attribute::ReconcileFlag, QStringLiteral("reconcileflag")}, - {Split::Attribute::KMMatchedTx, QStringLiteral("kmm-matched-tx")} - }; - return attrNames[attr]; - } - /** * This member contains the ID of the payee */ diff --git a/kmymoney/mymoney/mymoneytag.h b/kmymoney/mymoney/mymoneytag.h --- a/kmymoney/mymoney/mymoneytag.h +++ b/kmymoney/mymoney/mymoneytag.h @@ -32,7 +32,6 @@ class QString; class QColor; -class QDomDocument; /** * This class represents a tag within the MyMoney engine. @@ -79,8 +78,6 @@ bool operator == (const MyMoneyTag &) const; bool operator <(const MyMoneyTag& right) const; - void writeXML(QDomDocument& document, QDomElement& parent) const override; - /** * This method checks if a reference to the given object exists. It returns, * a @p true if the object is referencing the one requested by the diff --git a/kmymoney/mymoney/mymoneytag.cpp b/kmymoney/mymoney/mymoneytag.cpp --- a/kmymoney/mymoney/mymoneytag.cpp +++ b/kmymoney/mymoney/mymoneytag.cpp @@ -22,9 +22,6 @@ // ---------------------------------------------------------------------------- // QT Includes -#include -#include - // ---------------------------------------------------------------------------- // Project Includes @@ -140,22 +137,6 @@ return d->m_name < d2->m_name; } -void MyMoneyTag::writeXML(QDomDocument& document, QDomElement& parent) const -{ - auto el = document.createElement(nodeNames[nnTag]); - - Q_D(const MyMoneyTag); - d->writeBaseXML(document, el); - - el.setAttribute(d->getAttrName(Tag::Attribute::Name), d->m_name); - el.setAttribute(d->getAttrName(Tag::Attribute::Closed), d->m_closed); - if (d->m_tag_color.isValid()) - el.setAttribute(d->getAttrName(Tag::Attribute::TagColor), d->m_tag_color.name()); - if (!d->m_notes.isEmpty()) - el.setAttribute(d->getAttrName(Tag::Attribute::Notes), d->m_notes); - parent.appendChild(el); -} - bool MyMoneyTag::hasReferenceTo(const QString& /*id*/) const { return false; diff --git a/kmymoney/mymoney/mymoneytag_p.h b/kmymoney/mymoney/mymoneytag_p.h --- a/kmymoney/mymoney/mymoneytag_p.h +++ b/kmymoney/mymoney/mymoneytag_p.h @@ -31,20 +31,6 @@ #include "mymoneyobject_p.h" -namespace Tag -{ - enum class Attribute { - Name = 0 , - Type, - TagColor, - Closed, - Notes, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - class MyMoneyTagPrivate : public MyMoneyObjectPrivate { public: @@ -54,18 +40,6 @@ { } - static QString getAttrName(const Tag::Attribute attr) - { - static const QHash attrNames { - {Tag::Attribute::Name, QStringLiteral("name")}, - {Tag::Attribute::Type, QStringLiteral("type")}, - {Tag::Attribute::TagColor, QStringLiteral("tagcolor")}, - {Tag::Attribute::Closed, QStringLiteral("closed")}, - {Tag::Attribute::Notes, QStringLiteral("notes")}, - }; - return attrNames[attr]; - } - // Simple fields QString m_name; // Closed tags will not be shown in the selector inside a transaction, only in the Tag tab diff --git a/kmymoney/mymoney/mymoneytransaction_p.h b/kmymoney/mymoney/mymoneytransaction_p.h --- a/kmymoney/mymoney/mymoneytransaction_p.h +++ b/kmymoney/mymoney/mymoneytransaction_p.h @@ -36,57 +36,12 @@ #include "mymoneyobject_p.h" #include "mymoneysplit.h" -namespace eMyMoney -{ - namespace Transaction - { - enum class Element { Split = 0, - Splits }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { Name = 0, - Type, - PostDate, - Memo, - EntryDate, - Commodity, - BankID, - // insert new entries above this line - LastAttribute - }; - - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } - } -} using namespace eMyMoney; class MyMoneyTransactionPrivate : public MyMoneyObjectPrivate { public: - static QString getElName(const Transaction::Element el) - { - static const QHash elNames { - {Transaction::Element::Split, QStringLiteral("SPLIT")}, - {Transaction::Element::Splits, QStringLiteral("SPLITS")} - }; - return elNames[el]; - } - - static QString getAttrName(const Transaction::Attribute attr) - { - static const QHash attrNames { - {Transaction::Attribute::Name, QStringLiteral("name")}, - {Transaction::Attribute::Type, QStringLiteral("type")}, - {Transaction::Attribute::PostDate, QStringLiteral("postdate")}, - {Transaction::Attribute::Memo, QStringLiteral("memo")}, - {Transaction::Attribute::EntryDate, QStringLiteral("entrydate")}, - {Transaction::Attribute::Commodity, QStringLiteral("commodity")}, - {Transaction::Attribute::BankID, QStringLiteral("bankid")}, - }; - return attrNames[attr]; - } - /** * This method returns the next id to be used for a split */ diff --git a/kmymoney/mymoney/onlinejob.h b/kmymoney/mymoney/onlinejob.h --- a/kmymoney/mymoney/onlinejob.h +++ b/kmymoney/mymoney/onlinejob.h @@ -140,7 +140,6 @@ /** @todo implement */ bool hasReferenceTo(const QString &id) const override; - void writeXML(QDomDocument &document, QDomElement &parent) const override; /** * @brief Account this job is related to diff --git a/kmymoney/mymoney/onlinejob.cpp b/kmymoney/mymoney/onlinejob.cpp --- a/kmymoney/mymoney/onlinejob.cpp +++ b/kmymoney/mymoney/onlinejob.cpp @@ -18,9 +18,6 @@ #include "onlinejob.h" #include "onlinejob_p.h" -#include -#include - #include "mymoneyfile.h" #include "mymoneyaccount.h" @@ -261,39 +258,6 @@ d->m_messageList = QList(); } -/** @todo give life */ -void onlineJob::writeXML(QDomDocument &document, QDomElement &parent) const -{ - auto el = document.createElement(nodeNames[nnOnlineJob]); - - Q_D(const onlineJob); - d->writeBaseXML(document, el); - - if (!d->m_jobSend.isNull()) - el.setAttribute(d->getAttrName(OnlineJob::Attribute::Send), d->m_jobSend.toString(Qt::ISODate)); - if (!d->m_jobBankAnswerDate.isNull()) - el.setAttribute(d->getAttrName(OnlineJob::Attribute::BankAnswerDate), d->m_jobBankAnswerDate.toString(Qt::ISODate)); - - switch (d->m_jobBankAnswerState) { - case eMyMoney::OnlineJob::sendingState::abortedByUser: el.setAttribute(d->getAttrName(OnlineJob::Attribute::BankAnswerState), d->getAttrName(OnlineJob::Attribute::AbortedByUser)); break; - case eMyMoney::OnlineJob::sendingState::acceptedByBank: el.setAttribute(d->getAttrName(OnlineJob::Attribute::BankAnswerState), d->getAttrName(OnlineJob::Attribute::AcceptedByBank)); break; - case eMyMoney::OnlineJob::sendingState::rejectedByBank: el.setAttribute(d->getAttrName(OnlineJob::Attribute::BankAnswerState), d->getAttrName(OnlineJob::Attribute::RejectedByBank)); break; - case eMyMoney::OnlineJob::sendingState::sendingError: el.setAttribute(d->getAttrName(OnlineJob::Attribute::BankAnswerState), d->getAttrName(OnlineJob::Attribute::SendingError)); break; - case eMyMoney::OnlineJob::sendingState::noBankAnswer: - default: void(); - } - - QDomElement taskEl = document.createElement(d->getElName(OnlineJob::Element::OnlineTask)); - taskEl.setAttribute(d->getAttrName(OnlineJob::Attribute::IID), taskIid()); - try { - task()->writeXML(document, taskEl); // throws execption if there is no task - el.appendChild(taskEl); // only append child if there is something to append - } catch (const emptyTask&) { - } - - parent.appendChild(el); -} - bool onlineJob::isValid() const { if (m_task != 0) diff --git a/kmymoney/mymoney/onlinejob_p.h b/kmymoney/mymoney/onlinejob_p.h --- a/kmymoney/mymoney/onlinejob_p.h +++ b/kmymoney/mymoney/onlinejob_p.h @@ -30,50 +30,9 @@ namespace eMyMoney { namespace OnlineJob { enum class sendingState; } } -namespace OnlineJob { - enum class Element { OnlineTask }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { Send = 0, - BankAnswerDate, - BankAnswerState, - IID, - AbortedByUser, - AcceptedByBank, - RejectedByBank, - SendingError, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - class onlineJobPrivate : public MyMoneyObjectPrivate { public: - static QString getElName(const OnlineJob::Element el) - { - static const QMap elNames { - {OnlineJob::Element::OnlineTask, QStringLiteral("onlineTask")} - }; - return elNames[el]; - } - - static QString getAttrName(const OnlineJob::Attribute attr) - { - static const QHash attrNames { - {OnlineJob::Attribute::Send, QStringLiteral("send")}, - {OnlineJob::Attribute::BankAnswerDate, QStringLiteral("bankAnswerDate")}, - {OnlineJob::Attribute::BankAnswerState, QStringLiteral("bankAnswerState")}, - {OnlineJob::Attribute::IID, QStringLiteral("iid")}, - {OnlineJob::Attribute::AbortedByUser, QStringLiteral("abortedByUser")}, - {OnlineJob::Attribute::AcceptedByBank, QStringLiteral("acceptedByBank")}, - {OnlineJob::Attribute::RejectedByBank, QStringLiteral("rejectedByBank")}, - {OnlineJob::Attribute::SendingError, QStringLiteral("sendingError")}, - }; - return attrNames[attr]; - } - /** * @brief Date-time the job was sent to the bank * diff --git a/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransfer.h b/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransfer.h --- a/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransfer.h +++ b/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransfer.h @@ -121,11 +121,12 @@ virtual QSharedPointer getSettings() const = 0; + virtual void writeXML(QDomDocument& document, QDomElement& parent) const override = 0; + protected: virtual sepaOnlineTransfer* clone() const override = 0; virtual sepaOnlineTransfer* createFromXml(const QDomElement &element) const override = 0; - virtual void writeXML(QDomDocument& document, QDomElement& parent) const override = 0; }; diff --git a/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransferimpl.h b/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransferimpl.h --- a/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransferimpl.h +++ b/kmymoney/mymoney/onlinetasks/sepa/sepaonlinetransferimpl.h @@ -97,11 +97,12 @@ QSharedPointer getSettings() const final override; + void writeXML(QDomDocument& document, QDomElement& parent) const final override; + protected: sepaOnlineTransfer* clone() const final override; sepaOnlineTransfer* createFromXml(const QDomElement &element) const final override; - void writeXML(QDomDocument& document, QDomElement& parent) const final override; private: mutable QSharedPointer _settings; diff --git a/kmymoney/mymoney/onlinetasks/unavailabletask/tasks/unavailabletask.h b/kmymoney/mymoney/onlinetasks/unavailabletask/tasks/unavailabletask.h --- a/kmymoney/mymoney/onlinetasks/unavailabletask/tasks/unavailabletask.h +++ b/kmymoney/mymoney/onlinetasks/unavailabletask/tasks/unavailabletask.h @@ -38,10 +38,10 @@ bool isValid() const override; QString jobTypeName() const override; + void writeXML(QDomDocument& document, QDomElement& parent) const override; protected: QString responsibleAccount() const override; unavailableTask* createFromXml(const QDomElement& element) const override; - void writeXML(QDomDocument& document, QDomElement& parent) const override; bool hasReferenceTo(const QString& id) const override; unavailableTask* clone() const override; diff --git a/kmymoney/mymoney/tests/mymoneyaccount-test.h b/kmymoney/mymoney/tests/mymoneyaccount-test.h --- a/kmymoney/mymoney/tests/mymoneyaccount-test.h +++ b/kmymoney/mymoney/tests/mymoneyaccount-test.h @@ -40,7 +40,6 @@ void testAssignmentConstructor(); void testSubAccounts(); void testEquality(); - void testWriteXML(); void testHasReferenceTo(); void testAdjustBalance(); void testSetClosed(); diff --git a/kmymoney/mymoney/tests/mymoneyaccount-test.cpp b/kmymoney/mymoney/tests/mymoneyaccount-test.cpp --- a/kmymoney/mymoney/tests/mymoneyaccount-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyaccount-test.cpp @@ -19,8 +19,6 @@ #include "mymoneyaccount-test.h" #include -#include -#include #define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyAccountTest; @@ -289,88 +287,6 @@ } -void MyMoneyAccountTest::testWriteXML() -{ - QString id = "A000001"; - QString institutionid = "B000001"; - QString parent = "Parent"; - - MyMoneyAccount r; - r.setAccountType(eMyMoney::Account::Type::Asset); - r.setOpeningDate(QDate::currentDate()); - r.setLastModified(QDate::currentDate()); - r.setDescription("Desc"); - r.setName("AccountName"); - r.setNumber("465500"); - r.setParentAccountId(parent); - r.setInstitutionId(institutionid); - r.setValue(QString("key"), "value"); - r.addAccountId("A000002"); - r.addReconciliation(QDate(2011, 1, 1), MyMoneyMoney(123, 100)); - r.addReconciliation(QDate(2011, 2, 1), MyMoneyMoney(456, 100)); - - QCOMPARE(r.pairs().count(), 2); - QCOMPARE(r.value("key"), QLatin1String("value")); - QCOMPARE(r.value("reconciliationHistory"), QLatin1String("2011-01-01:123/100;2011-02-01:114/25")); - - MyMoneyAccount a(id, r); - - QDomDocument doc("TEST"); - QDomElement el = doc.createElement("ACCOUNT-CONTAINER"); - doc.appendChild(el); - a.writeXML(doc, el); - - QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); - QDomElement accountContainer = doc.documentElement(); - QVERIFY(accountContainer.isElement()); - QCOMPARE(accountContainer.tagName(), QLatin1String("ACCOUNT-CONTAINER")); - QVERIFY(accountContainer.childNodes().size() == 1); - QVERIFY(accountContainer.childNodes().at(0).isElement()); - - QDomElement account = accountContainer.childNodes().at(0).toElement(); - QCOMPARE(account.tagName(), QLatin1String("ACCOUNT")); - QCOMPARE(account.attribute("id"), QLatin1String("A000001")); - QCOMPARE(account.attribute("lastreconciled"), QString()); - QCOMPARE(account.attribute("institution"), QLatin1String("B000001")); - QCOMPARE(account.attribute("name"), QLatin1String("AccountName")); - QCOMPARE(account.attribute("number"), QLatin1String("465500")); - QCOMPARE(account.attribute("description"), QLatin1String("Desc")); - QCOMPARE(account.attribute("parentaccount"), QLatin1String("Parent")); - QCOMPARE(account.attribute("opened"), QDate::currentDate().toString(Qt::ISODate)); - QCOMPARE(account.attribute("type"), QLatin1String("9")); - QCOMPARE(account.attribute("lastmodified"), QDate::currentDate().toString(Qt::ISODate)); - QCOMPARE(account.attribute("id"), QLatin1String("A000001")); - QCOMPARE(account.childNodes().size(), 2); - - QVERIFY(account.childNodes().at(0).isElement()); - QDomElement subAccounts = account.childNodes().at(0).toElement(); - QCOMPARE(subAccounts.tagName(), QLatin1String("SUBACCOUNTS")); - QCOMPARE(subAccounts.childNodes().size(), 1); - QVERIFY(subAccounts.childNodes().at(0).isElement()); - QDomElement subAccount = subAccounts.childNodes().at(0).toElement(); - QCOMPARE(subAccount.tagName(), QLatin1String("SUBACCOUNT")); - QCOMPARE(subAccount.attribute("id"), QLatin1String("A000002")); - QCOMPARE(subAccount.childNodes().size(), 0); - - QDomElement keyValuePairs = account.childNodes().at(1).toElement(); - QCOMPARE(keyValuePairs.tagName(), QLatin1String("KEYVALUEPAIRS")); - QCOMPARE(keyValuePairs.childNodes().size(), 2); - - QVERIFY(keyValuePairs.childNodes().at(0).isElement()); - QDomElement keyValuePair1 = keyValuePairs.childNodes().at(0).toElement(); - QCOMPARE(keyValuePair1.tagName(), QLatin1String("PAIR")); - QCOMPARE(keyValuePair1.attribute("key"), QLatin1String("key")); - QCOMPARE(keyValuePair1.attribute("value"), QLatin1String("value")); - QCOMPARE(keyValuePair1.childNodes().size(), 0); - - QVERIFY(keyValuePairs.childNodes().at(1).isElement()); - QDomElement keyValuePair2 = keyValuePairs.childNodes().at(1).toElement(); - QCOMPARE(keyValuePair2.tagName(), QLatin1String("PAIR")); - QCOMPARE(keyValuePair2.attribute("key"), QLatin1String("reconciliationHistory")); - QCOMPARE(keyValuePair2.attribute("value"), QLatin1String("2011-01-01:123/100;2011-02-01:114/25")); - QCOMPARE(keyValuePair2.childNodes().size(), 0); -} - void MyMoneyAccountTest::testHasReferenceTo() { MyMoneyAccount a; diff --git a/kmymoney/mymoney/tests/mymoneyinstitution-test.h b/kmymoney/mymoney/tests/mymoneyinstitution-test.h --- a/kmymoney/mymoney/tests/mymoneyinstitution-test.h +++ b/kmymoney/mymoney/tests/mymoneyinstitution-test.h @@ -41,7 +41,6 @@ void testEquality(); void testInequality(); void testAccountIDList(); - void testWriteXML(); }; #endif diff --git a/kmymoney/mymoney/tests/mymoneyinstitution-test.cpp b/kmymoney/mymoney/tests/mymoneyinstitution-test.cpp --- a/kmymoney/mymoney/tests/mymoneyinstitution-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyinstitution-test.cpp @@ -200,73 +200,3 @@ QVERIFY(list.contains("A000002") == 1); } - -void MyMoneyInstitutionTest::testWriteXML() -{ - MyMoneyKeyValueContainer kvp; - - n->addAccountId("A000001"); - n->addAccountId("A000003"); - n->setValue(QString("key"), "value"); - - QDomDocument doc("TEST"); - QDomElement el = doc.createElement("INSTITUTION-CONTAINER"); - doc.appendChild(el); - - MyMoneyInstitution i("I00001", *n); - - i.writeXML(doc, el); - - QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); - QDomElement institutionContainer = doc.documentElement(); - QVERIFY(institutionContainer.isElement()); - QCOMPARE(institutionContainer.tagName(), QLatin1String("INSTITUTION-CONTAINER")); - QVERIFY(institutionContainer.childNodes().size() == 1); - QVERIFY(institutionContainer.elementsByTagName("INSTITUTION").at(0).isElement()); - - QDomElement institution = institutionContainer.elementsByTagName("INSTITUTION").at(0).toElement(); - QCOMPARE(institution.tagName(), QLatin1String("INSTITUTION")); - QCOMPARE(institution.attribute("id"), QLatin1String("I00001")); - QCOMPARE(institution.attribute("manager"), QLatin1String("manager")); - QCOMPARE(institution.attribute("name"), QLatin1String("name")); - QCOMPARE(institution.attribute("sortcode"), QLatin1String("sortcode")); - QCOMPARE(institution.childNodes().size(), 3); - - QVERIFY(institution.childNodes().at(0).isElement()); - QDomElement address = institution.childNodes().at(0).toElement(); - QCOMPARE(address.tagName(), QLatin1String("ADDRESS")); - QCOMPARE(address.attribute("street"), QLatin1String("street")); - QCOMPARE(address.attribute("telephone"), QLatin1String("telephone")); - QCOMPARE(address.attribute("zip"), QLatin1String("postcode")); - QCOMPARE(address.attribute("city"), QLatin1String("town")); - QCOMPARE(address.childNodes().size(), 0); - - QVERIFY(institution.childNodes().at(1).isElement()); - QDomElement accountIds = institution.childNodes().at(1).toElement(); - QCOMPARE(accountIds.tagName(), QLatin1String("ACCOUNTIDS")); - QCOMPARE(accountIds.childNodes().size(), 2); - - QVERIFY(accountIds.childNodes().at(0).isElement()); - QDomElement account1 = accountIds.childNodes().at(0).toElement(); - QCOMPARE(account1.tagName(), QLatin1String("ACCOUNTID")); - QCOMPARE(account1.attribute("id"), QLatin1String("A000001")); - QCOMPARE(account1.childNodes().size(), 0); - - QVERIFY(accountIds.childNodes().at(1).isElement()); - QDomElement account2 = accountIds.childNodes().at(1).toElement(); - QCOMPARE(account2.tagName(), QLatin1String("ACCOUNTID")); - QCOMPARE(account2.attribute("id"), QLatin1String("A000003")); - QCOMPARE(account2.childNodes().size(), 0); - - QVERIFY(institution.childNodes().at(2).isElement()); - QDomElement keyValuePairs = institution.childNodes().at(2).toElement(); - QCOMPARE(keyValuePairs.tagName(), QLatin1String("KEYVALUEPAIRS")); - QCOMPARE(keyValuePairs.childNodes().size(), 1); - - QVERIFY(keyValuePairs.childNodes().at(0).isElement()); - QDomElement keyValuePair1 = keyValuePairs.childNodes().at(0).toElement(); - QCOMPARE(keyValuePair1.tagName(), QLatin1String("PAIR")); - QCOMPARE(keyValuePair1.attribute("key"), QLatin1String("key")); - QCOMPARE(keyValuePair1.attribute("value"), QLatin1String("value")); - QCOMPARE(keyValuePair1.childNodes().size(), 0); -} diff --git a/kmymoney/mymoney/tests/mymoneypayee-test.cpp b/kmymoney/mymoney/tests/mymoneypayee-test.cpp --- a/kmymoney/mymoney/tests/mymoneypayee-test.cpp +++ b/kmymoney/mymoney/tests/mymoneypayee-test.cpp @@ -20,9 +20,6 @@ #include "mymoneypayee-test.h" -#include -#include - #include #define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyPayeeTest; diff --git a/kmymoney/mymoney/tests/mymoneysplit-test.cpp b/kmymoney/mymoney/tests/mymoneysplit-test.cpp --- a/kmymoney/mymoney/tests/mymoneysplit-test.cpp +++ b/kmymoney/mymoney/tests/mymoneysplit-test.cpp @@ -19,8 +19,6 @@ #include "mymoneysplit-test.h" #include -#include -#include #define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneySplitTest; diff --git a/kmymoney/mymoney/tests/mymoneytransaction-test.cpp b/kmymoney/mymoney/tests/mymoneytransaction-test.cpp --- a/kmymoney/mymoney/tests/mymoneytransaction-test.cpp +++ b/kmymoney/mymoney/tests/mymoneytransaction-test.cpp @@ -19,8 +19,6 @@ #include "mymoneytransaction-test.h" #include -#include -#include #include diff --git a/kmymoney/mymoney/tests/onlinejobtyped-test.cpp b/kmymoney/mymoney/tests/onlinejobtyped-test.cpp --- a/kmymoney/mymoney/tests/onlinejobtyped-test.cpp +++ b/kmymoney/mymoney/tests/onlinejobtyped-test.cpp @@ -40,15 +40,17 @@ return QLatin1String("Dummy credit transfer"); } + void writeXML(QDomDocument&, QDomElement&) const final override {} + protected: onlineTaskDummy3* clone() const final override { return (new onlineTaskDummy3); } bool hasReferenceTo(const QString&) const final override { return false; } - void writeXML(QDomDocument&, QDomElement&) const final override {} + onlineTaskDummy3* createFromXml(const QDomElement &) const final override { return (new onlineTaskDummy3); } diff --git a/kmymoney/plugins/onlinetasks/dummy/tasks/dummytask.h b/kmymoney/plugins/onlinetasks/dummy/tasks/dummytask.h --- a/kmymoney/plugins/onlinetasks/dummy/tasks/dummytask.h +++ b/kmymoney/plugins/onlinetasks/dummy/tasks/dummytask.h @@ -56,15 +56,17 @@ return m_testNumber; } + void writeXML(QDomDocument&, QDomElement&) const final override {} + protected: dummyTask* clone() const final override { return (new dummyTask(*this)); } bool hasReferenceTo(const QString &id) const final override { Q_UNUSED(id); return false; } - void writeXML(QDomDocument&, QDomElement&) const final override {} + dummyTask* createFromXml(const QDomElement&) const final override { return (new dummyTask); } diff --git a/kmymoney/plugins/onlinetasks/interfaces/tasks/onlinetask.h b/kmymoney/plugins/onlinetasks/interfaces/tasks/onlinetask.h --- a/kmymoney/plugins/onlinetasks/interfaces/tasks/onlinetask.h +++ b/kmymoney/plugins/onlinetasks/interfaces/tasks/onlinetask.h @@ -123,6 +123,9 @@ */ virtual QString jobTypeName() const = 0; + /** @see MyMoneyObject::writeXML() */ + virtual void writeXML(QDomDocument &document, QDomElement &parent) const = 0; + protected: onlineTask(const onlineTask& other); @@ -137,9 +140,6 @@ /** @see MyMoneyObject::hasReferenceTo() */ virtual bool hasReferenceTo(const QString &id) const = 0; - /** @see MyMoneyObject::writeXML() */ - virtual void writeXML(QDomDocument &document, QDomElement &parent) const = 0; - /** * @brief Create a new instance of this task based on xml data * diff --git a/kmymoney/plugins/xml/mymoneystoragenames.h b/kmymoney/plugins/xml/mymoneystoragenames.h --- a/kmymoney/plugins/xml/mymoneystoragenames.h +++ b/kmymoney/plugins/xml/mymoneystoragenames.h @@ -447,14 +447,19 @@ QString tagName(Tag tagID); QString nodeName(Node nodeID); +namespace eMyMoney { namespace Budget { enum class Level; } } + namespace eMyMoney { namespace Report { enum class RowType; } } namespace eMyMoney { namespace Report { enum class ColumnType; } } namespace eMyMoney { namespace Report { enum QueryColumn : int; } } namespace eMyMoney { namespace Report { enum class ChartType; } } namespace eMyMoney { namespace Report { enum class DataLock; } } namespace eMyMoney { namespace Report { enum class ReportType; } } namespace eMyMoney { namespace Report { enum class DetailLevel; } } +QHash budgetLevelsLUT(); +QString budgetLevels(eMyMoney::Budget::Level textID); + QHash rowTypesLUT(); QString reportNames(eMyMoney::Report::RowType textID); eMyMoney::Report::RowType stringToRowType(const QString &text); diff --git a/kmymoney/plugins/xml/mymoneystoragenames.cpp b/kmymoney/plugins/xml/mymoneystoragenames.cpp --- a/kmymoney/plugins/xml/mymoneystoragenames.cpp +++ b/kmymoney/plugins/xml/mymoneystoragenames.cpp @@ -503,6 +503,23 @@ return attributeNames.value(attributeID); } +QHash budgetLevelsLUT() +{ + static const QHash lut { + {eMyMoney::Budget::Level::None, QStringLiteral("none")}, + {eMyMoney::Budget::Level::Monthly, QStringLiteral("monthly")}, + {eMyMoney::Budget::Level::MonthByMonth, QStringLiteral("monthbymonth")}, + {eMyMoney::Budget::Level::Yearly, QStringLiteral("yearly")}, + {eMyMoney::Budget::Level::Max, QStringLiteral("invalid")}, + }; + return lut; +} + +QString budgetLevels(eMyMoney::Budget::Level textID) +{ + return budgetLevelsLUT().value(textID); +} + QHash rowTypesLUT() { static const QHash lut { diff --git a/kmymoney/plugins/xml/mymoneystoragexml.cpp b/kmymoney/plugins/xml/mymoneystoragexml.cpp --- a/kmymoney/plugins/xml/mymoneystoragexml.cpp +++ b/kmymoney/plugins/xml/mymoneystoragexml.cpp @@ -32,6 +32,7 @@ #include #include #include +#include // ---------------------------------------------------------------------------- // KDE Includes @@ -157,16 +158,24 @@ static MyMoneySplit readSplit(const QDomElement &node); static void writeSplit(const MyMoneySplit &_split, QDomDocument &document, QDomElement &parent); static MyMoneyAccount readAccount(const QDomElement &node); + static void writeAccount(const MyMoneyAccount &account, QDomDocument &document, QDomElement &parent); static MyMoneyPayee readPayee(const QDomElement &node); + static void writePayee(const MyMoneyPayee &payee, QDomDocument &document, QDomElement &parent); static MyMoneyTag readTag(const QDomElement &node); + static void writeTag(const MyMoneyTag &tag, QDomDocument &document, QDomElement &parent); static MyMoneySecurity readSecurity(const QDomElement &node); + static void writeSecurity(const MyMoneySecurity &security, QDomDocument &document, QDomElement &parent); static MyMoneyInstitution readInstitution(const QDomElement &node); + static void writeInstitution(const MyMoneyInstitution &institution, QDomDocument &document, QDomElement &parent); static MyMoneyReport readReport(const QDomElement &node); static MyMoneyBudget readBudget(const QDomElement &node); + static void writeBudget(const MyMoneyBudget &budget, QDomDocument &document, QDomElement &parent); static MyMoneySchedule readSchedule(const QDomElement &node); static void writeSchedule(const MyMoneySchedule &schedule, QDomDocument &document, QDomElement &parent); static onlineJob readOnlineJob(const QDomElement &node); + static void writeOnlineJob(const onlineJob &job, QDomDocument &document, QDomElement &parent); static MyMoneyCostCenter readCostCenter(const QDomElement &node); + static void writeCostCenter(const MyMoneyCostCenter &costCenter, QDomDocument &document, QDomElement &parent); }; MyMoneyXmlContentHandler::MyMoneyXmlContentHandler(MyMoneyStorageXML* reader) : @@ -555,7 +564,7 @@ } } else if (c.tagName() == nodeName(Node::KeyValuePairs)) { - addToKeyValueContainer(transaction, c.toElement()); + addToKeyValueContainer(transaction, c.toElement()); } child = child.nextSibling(); @@ -764,6 +773,61 @@ return acc; } +void MyMoneyXmlContentHandler::writeAccount(const MyMoneyAccount &account, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::Account)); + + writeBaseXML(account.id(), document, el); + + el.setAttribute(attributeName(Attribute::Account::ParentAccount), account.parentAccountId()); + el.setAttribute(attributeName(Attribute::Account::LastReconciled), MyMoneyUtils::dateToString(account.lastReconciliationDate())); + el.setAttribute(attributeName(Attribute::Account::LastModified), MyMoneyUtils::dateToString(account.lastModified())); + el.setAttribute(attributeName(Attribute::Account::Institution), account.institutionId()); + el.setAttribute(attributeName(Attribute::Account::Opened), MyMoneyUtils::dateToString(account.openingDate())); + el.setAttribute(attributeName(Attribute::Account::Number), account.number()); + // el.setAttribute(getAttrName(anOpeningBalance), account.openingBalance().toString()); + el.setAttribute(attributeName(Attribute::Account::Type), (int)account.accountType()); + el.setAttribute(attributeName(Attribute::Account::Name), account.name()); + el.setAttribute(attributeName(Attribute::Account::Description), account.description()); + if (!account.currencyId().isEmpty()) + el.setAttribute(attributeName(Attribute::Account::Currency), account.currencyId()); + + //Add in subaccount information, if this account has subaccounts. + if (account.accountCount()) { + QDomElement subAccounts = document.createElement(elementName(Element::Account::SubAccounts)); + foreach (const auto accountID, account.accountList()) { + QDomElement temp = document.createElement(elementName(Element::Account::SubAccount)); + temp.setAttribute(attributeName(Attribute::Account::ID), accountID); + subAccounts.appendChild(temp); + } + + el.appendChild(subAccounts); + } + + // Write online banking settings + auto onlineBankSettingsPairs = account.onlineBankingSettings().pairs(); + if (onlineBankSettingsPairs.count()) { + QDomElement onlinesettings = document.createElement(elementName(Element::Account::OnlineBanking)); + QMap::const_iterator it_key = onlineBankSettingsPairs.constBegin(); + while (it_key != onlineBankSettingsPairs.constEnd()) { + onlinesettings.setAttribute(it_key.key(), it_key.value()); + ++it_key; + } + el.appendChild(onlinesettings); + } + + // FIXME drop the lastStatementDate record from the KVP when it is + // not stored there after setLastReconciliationDate() has been changed + // See comment there when this will happen + // deletePair("lastStatementDate"); + + + //Add in Key-Value Pairs for accounts. + writeKeyValueContainer(account, document, el); + + parent.appendChild(el); +} + MyMoneyPayee MyMoneyXmlContentHandler::readPayee(const QDomElement &node) { if (nodeName(Node::Payee) != node.tagName()) @@ -806,6 +870,45 @@ return payee; } +void MyMoneyXmlContentHandler::writePayee(const MyMoneyPayee &payee, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::Payee)); + + writeBaseXML(payee.id(), document, el); + + el.setAttribute(attributeName(Attribute::Payee::Name), payee.name()); + el.setAttribute(attributeName(Attribute::Payee::Reference), payee.reference()); + el.setAttribute(attributeName(Attribute::Payee::Email), payee.email()); + if (!payee.notes().isEmpty()) + el.setAttribute(attributeName(Attribute::Payee::Notes), payee.notes()); + + el.setAttribute(attributeName(Attribute::Payee::MatchingEnabled), payee.isMatchingEnabled()); + if (payee.isMatchingEnabled()) { + el.setAttribute(attributeName(Attribute::Payee::UsingMatchKey), payee.isUsingMatchKey()); + el.setAttribute(attributeName(Attribute::Payee::MatchIgnoreCase), payee.isMatchKeyIgnoreCase()); + el.setAttribute(attributeName(Attribute::Payee::MatchKey), payee.matchKey()); + } + + if (!payee.defaultAccountId().isEmpty()) { + el.setAttribute(attributeName(Attribute::Payee::DefaultAccountID), payee.defaultAccountId()); + } + + // Save address + QDomElement address = document.createElement(elementName(Element::Payee::Address)); + address.setAttribute(attributeName(Attribute::Payee::Street), payee.address()); + address.setAttribute(attributeName(Attribute::Payee::City), payee.city()); + address.setAttribute(attributeName(Attribute::Payee::PostCode), payee.postcode()); + address.setAttribute(attributeName(Attribute::Payee::State), payee.state()); + address.setAttribute(attributeName(Attribute::Payee::Telephone), payee.telephone()); + + el.appendChild(address); + + // Save payeeIdentifiers (account numbers) + payee.MyMoneyPayeeIdentifierContainer::writeXML(document, el); + + parent.appendChild(el); +} + MyMoneyTag MyMoneyXmlContentHandler::readTag(const QDomElement &node) { if (nodeName(Node::Tag) != node.tagName()) @@ -825,6 +928,21 @@ return tag; } +void MyMoneyXmlContentHandler::writeTag(const MyMoneyTag &tag, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::Tag)); + + writeBaseXML(tag.id(), document, el); + + el.setAttribute(attributeName(Attribute::Tag::Name), tag.name()); + el.setAttribute(attributeName(Attribute::Tag::Closed), tag.isClosed()); + if (tag.tagColor().isValid()) + el.setAttribute(attributeName(Attribute::Tag::TagColor), tag.tagColor().name()); + if (!tag.notes().isEmpty()) + el.setAttribute(attributeName(Attribute::Tag::Notes), tag.notes()); + parent.appendChild(el); +} + MyMoneySecurity MyMoneyXmlContentHandler::readSecurity(const QDomElement &node) { const auto tag = node.tagName(); @@ -861,6 +979,35 @@ return security; } +void MyMoneyXmlContentHandler::writeSecurity(const MyMoneySecurity &security, QDomDocument &document, QDomElement &parent) +{ + QDomElement el; + if (security.isCurrency()) + el = document.createElement(nodeName(Node::Currency)); + else + el = document.createElement(nodeName(Node::Security)); + + writeBaseXML(security.id(), document, el); + + el.setAttribute(attributeName(Attribute::Security::Name), security.name()); + el.setAttribute(attributeName(Attribute::Security::Symbol),security.tradingSymbol()); + el.setAttribute(attributeName(Attribute::Security::Type), static_cast(security.securityType())); + el.setAttribute(attributeName(Attribute::Security::RoundingMethod), static_cast(security.roundingMethod())); + el.setAttribute(attributeName(Attribute::Security::SAF), security.smallestAccountFraction()); + el.setAttribute(attributeName(Attribute::Security::PP), security.pricePrecision()); + if (security.isCurrency()) + el.setAttribute(attributeName(Attribute::Security::SCF), security.smallestCashFraction()); + else { + el.setAttribute(attributeName(Attribute::Security::TradingCurrency), security.tradingCurrency()); + el.setAttribute(attributeName(Attribute::Security::TradingMarket), security.tradingMarket()); + } + + //Add in Key-Value Pairs for securities. + writeKeyValueContainer(security, document, el); + + parent.appendChild(el); +} + MyMoneyInstitution MyMoneyXmlContentHandler::readInstitution(const QDomElement &node) { if (nodeName(Node::Institution) != node.tagName()) @@ -894,6 +1041,37 @@ return institution; } +void MyMoneyXmlContentHandler::writeInstitution(const MyMoneyInstitution &institution, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::Institution)); + + writeBaseXML(institution.id(), document, el); + + el.setAttribute(attributeName(Attribute::Institution::Name), institution.name()); + el.setAttribute(attributeName(Attribute::Institution::Manager), institution.manager()); + el.setAttribute(attributeName(Attribute::Institution::SortCode), institution.sortcode()); + + auto address = document.createElement(elementName(Element::Institution::Address)); + address.setAttribute(attributeName(Attribute::Institution::Street), institution.street()); + address.setAttribute(attributeName(Attribute::Institution::City), institution.town()); + address.setAttribute(attributeName(Attribute::Institution::Zip), institution.postcode()); + address.setAttribute(attributeName(Attribute::Institution::Telephone), institution.telephone()); + el.appendChild(address); + + auto accounts = document.createElement(elementName(Element::Institution::AccountIDS)); + foreach (const auto accountID, institution.accountList()) { + auto temp = document.createElement(elementName(Element::Institution::AccountID)); + temp.setAttribute(attributeName(Attribute::Institution::ID), accountID); + accounts.appendChild(temp); + } + el.appendChild(accounts); + + //Add in Key-Value Pairs for institutions. + writeKeyValueContainer(institution, document, el); + + parent.appendChild(el); +} + MyMoneyReport MyMoneyXmlContentHandler::readReport(const QDomElement &node) { if (nodeName(Node::Report) != node.tagName()) @@ -1169,6 +1347,48 @@ return budget; } +const int BUDGET_VERSION = 2; + +void MyMoneyXmlContentHandler::writeBudget(const MyMoneyBudget &budget, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::Budget)); + + writeBaseXML(budget.id(), document, el); + + el.setAttribute(attributeName(Attribute::Budget::Name), budget.name()); + el.setAttribute(attributeName(Attribute::Budget::Start), budget.budgetStart().toString(Qt::ISODate)); + el.setAttribute(attributeName(Attribute::Budget::Version), BUDGET_VERSION); + + QMap::const_iterator it; + auto accounts = budget.accountsMap(); + for (it = accounts.cbegin(); it != accounts.cend(); ++it) { + // only add the account if there is a budget entered + // or it covers some sub accounts + if (!(*it).balance().isZero() || (*it).budgetSubaccounts()) { + QDomElement domAccount = document.createElement(elementName(Element::Budget::Account)); + domAccount.setAttribute(attributeName(Attribute::Budget::ID), it.key()); + domAccount.setAttribute(attributeName(Attribute::Budget::BudgetLevel), budgetLevels(it.value().budgetLevel())); + domAccount.setAttribute(attributeName(Attribute::Budget::BudgetSubAccounts), it.value().budgetSubaccounts()); + + const QMap periods = it.value().getPeriods(); + QMap::const_iterator it_per; + for (it_per = periods.begin(); it_per != periods.end(); ++it_per) { + if (!(*it_per).amount().isZero()) { + QDomElement domPeriod = document.createElement(elementName(Element::Budget::Period)); + + domPeriod.setAttribute(attributeName(Attribute::Budget::Amount), (*it_per).amount().toString()); + domPeriod.setAttribute(attributeName(Attribute::Budget::Start), (*it_per).startDate().toString(Qt::ISODate)); + domAccount.appendChild(domPeriod); + } + } + + el.appendChild(domAccount); + } + } + + parent.appendChild(el); +} + MyMoneySchedule MyMoneyXmlContentHandler::readSchedule(const QDomElement &node) { if (nodeName(Node::ScheduleTX) != node.tagName()) @@ -1309,6 +1529,37 @@ return oJob; } +void MyMoneyXmlContentHandler::writeOnlineJob(const onlineJob &job, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::OnlineJob)); + + writeBaseXML(job.id(), document, el); + + if (!job.sendDate().isNull()) + el.setAttribute(attributeName(Attribute::OnlineJob::Send), job.sendDate().toString(Qt::ISODate)); + if (!job.bankAnswerDate().isNull()) + el.setAttribute(attributeName(Attribute::OnlineJob::BankAnswerDate), job.bankAnswerDate().toString(Qt::ISODate)); + + switch (job.bankAnswerState()) { + case eMyMoney::OnlineJob::sendingState::abortedByUser: el.setAttribute(attributeName(Attribute::OnlineJob::BankAnswerState), attributeName(Attribute::OnlineJob::AbortedByUser)); break; + case eMyMoney::OnlineJob::sendingState::acceptedByBank: el.setAttribute(attributeName(Attribute::OnlineJob::BankAnswerState), attributeName(Attribute::OnlineJob::AcceptedByBank)); break; + case eMyMoney::OnlineJob::sendingState::rejectedByBank: el.setAttribute(attributeName(Attribute::OnlineJob::BankAnswerState), attributeName(Attribute::OnlineJob::RejectedByBank)); break; + case eMyMoney::OnlineJob::sendingState::sendingError: el.setAttribute(attributeName(Attribute::OnlineJob::BankAnswerState), attributeName(Attribute::OnlineJob::SendingError)); break; + case eMyMoney::OnlineJob::sendingState::noBankAnswer: + default: void(); + } + + QDomElement taskEl = document.createElement(elementName(Element::OnlineJob::OnlineTask)); + taskEl.setAttribute(attributeName(Attribute::OnlineJob::IID), job.taskIid()); + try { + job.task()->writeXML(document, taskEl); // throws execption if there is no task + el.appendChild(taskEl); // only append child if there is something to append + } catch (const onlineJob::emptyTask &) { + } + + parent.appendChild(el); +} + MyMoneyCostCenter MyMoneyXmlContentHandler::readCostCenter(const QDomElement &node) { if (nodeName(Node::CostCenter) != node.tagName()) @@ -1319,6 +1570,16 @@ return costCenter; } +void MyMoneyXmlContentHandler::writeCostCenter(const MyMoneyCostCenter &costCenter, QDomDocument &document, QDomElement &parent) +{ + auto el = document.createElement(nodeName(Node::CostCenter)); + + writeBaseXML(costCenter.id(), document, el); + + el.setAttribute(attributeName(Attribute::CostCenter::Name), costCenter.name()); + parent.appendChild(el); +} + @@ -1601,7 +1862,7 @@ void MyMoneyStorageXML::writeInstitution(QDomElement& institution, const MyMoneyInstitution& i) { - i.writeXML(*m_doc, institution); + MyMoneyXmlContentHandler::writeInstitution(i, *m_doc, institution); } void MyMoneyStorageXML::writePayees(QDomElement& payees) @@ -1616,7 +1877,7 @@ void MyMoneyStorageXML::writePayee(QDomElement& payee, const MyMoneyPayee& p) { - p.writeXML(*m_doc, payee); + MyMoneyXmlContentHandler::writePayee(p, *m_doc, payee); } void MyMoneyStorageXML::writeTags(QDomElement& tags) @@ -1631,7 +1892,7 @@ void MyMoneyStorageXML::writeTag(QDomElement& tag, const MyMoneyTag& ta) { - ta.writeXML(*m_doc, tag); + MyMoneyXmlContentHandler::writeTag(ta, *m_doc, tag); } void MyMoneyStorageXML::writeAccounts(QDomElement& accounts) @@ -1657,7 +1918,7 @@ void MyMoneyStorageXML::writeAccount(QDomElement& account, const MyMoneyAccount& p) { - p.writeXML(*m_doc, account); + MyMoneyXmlContentHandler::writeAccount(p, *m_doc, account); } void MyMoneyStorageXML::writeTransactions(QDomElement& transactions) @@ -1711,7 +1972,7 @@ void MyMoneyStorageXML::writeSecurity(QDomElement& securityElement, const MyMoneySecurity& security) { - security.writeXML(*m_doc, securityElement); + MyMoneyXmlContentHandler::writeSecurity(security, *m_doc, securityElement); } void MyMoneyStorageXML::writeCurrencies(QDomElement& currencies) @@ -1760,7 +2021,7 @@ void MyMoneyStorageXML::writeBudget(QDomElement& budget, const MyMoneyBudget& b) { - b.writeXML(*m_doc, budget); + MyMoneyXmlContentHandler::writeBudget(b, *m_doc, budget); } void MyMoneyStorageXML::writeOnlineJobs(QDomElement& parent) @@ -1778,7 +2039,7 @@ void MyMoneyStorageXML::writeOnlineJob(QDomElement& onlineJobs, const onlineJob& job) { - job.writeXML(*m_doc, onlineJobs); + MyMoneyXmlContentHandler::writeOnlineJob(job, *m_doc, onlineJobs); } void MyMoneyStorageXML::writeCostCenters(QDomElement& parent) @@ -1795,7 +2056,7 @@ void MyMoneyStorageXML::writeCostCenter(QDomElement& costCenters, const MyMoneyCostCenter& costCenter) { - costCenter.writeXML(*m_doc, costCenters); + MyMoneyXmlContentHandler::writeCostCenter(costCenter, *m_doc, costCenters); } QDomElement MyMoneyStorageXML::findChildElement(const QString& name, const QDomElement& root) diff --git a/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.cpp b/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.cpp --- a/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.cpp +++ b/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.cpp @@ -625,7 +625,7 @@ QDomDocument doc("TEST"); QDomElement el = doc.createElement("ACCOUNT-CONTAINER"); doc.appendChild(el); - a.writeXML(doc, el); + MyMoneyXmlContentHandler::writeAccount(a, doc, el); QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); QDomElement accountContainer = doc.documentElement(); @@ -684,15 +684,15 @@ QDomElement parent = doc.createElement("Test"); doc.appendChild(parent); MyMoneyPayee payee1("some random id"); //if the ID isn't set, w ethrow an exception - payee1.writeXML(doc, parent); + MyMoneyXmlContentHandler::writePayee(payee1, doc, parent); QString temp1 = "Account1"; payee1.setDefaultAccountId(temp1); - payee1.writeXML(doc, parent); + MyMoneyXmlContentHandler::writePayee(payee1, doc, parent); QString temp2 = "Account2"; payee1.setDefaultAccountId(temp2); - payee1.writeXML(doc, parent); + MyMoneyXmlContentHandler::writePayee(payee1, doc, parent); payee1.setDefaultAccountId(); - payee1.writeXML(doc, parent); + MyMoneyXmlContentHandler::writePayee(payee1, doc, parent); QDomElement el = parent.firstChild().toElement(); QVERIFY(!el.isNull()); auto payee2 = MyMoneyXmlContentHandler::readPayee(el); @@ -721,7 +721,7 @@ QDomElement parent = doc.createElement("Test"); doc.appendChild(parent); MyMoneyTag tag1("some random id"); //if the ID isn't set, w ethrow an exception - tag1.writeXML(doc, parent); + MyMoneyXmlContentHandler::writeTag(tag1, doc, parent); QDomElement el = parent.firstChild().toElement(); QVERIFY(!el.isNull()); auto tag2 = MyMoneyXmlContentHandler::readTag(el); @@ -807,8 +807,7 @@ doc.appendChild(el); MyMoneyInstitution i("I00001", n); - - i.writeXML(doc, el); + MyMoneyXmlContentHandler::writeInstitution(i, doc, el); QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); QDomElement institutionContainer = doc.documentElement();