diff --git a/kmymoney/mymoney/CMakeLists.txt b/kmymoney/mymoney/CMakeLists.txt --- a/kmymoney/mymoney/CMakeLists.txt +++ b/kmymoney/mymoney/CMakeLists.txt @@ -34,7 +34,6 @@ set(storage_a_SOURCES ./storage/imymoneystorageformat.cpp ./storage/mymoneystoragemgr.cpp - ./storage/mymoneystoragenames.cpp ) set(onlineTask_a_SOURCES diff --git a/kmymoney/mymoney/mymoneyaccount.h b/kmymoney/mymoney/mymoneyaccount.h --- a/kmymoney/mymoney/mymoneyaccount.h +++ b/kmymoney/mymoney/mymoneyaccount.h @@ -44,6 +44,7 @@ class MyMoneySplit; class payeeIdentifier; namespace eMyMoney { namespace Account { enum class Type; } } +namespace eMyMoney { namespace Account { enum class Standard; } } template class payeeIdentifierTyped; /** @@ -586,6 +587,8 @@ */ bool hasOnlineMapping() const; + static QString stdAccName(eMyMoney::Account::Standard stdAccID); + QDataStream &operator<<(const MyMoneyAccount &); QDataStream &operator>>(MyMoneyAccount &); }; diff --git a/kmymoney/mymoney/mymoneyaccount.cpp b/kmymoney/mymoney/mymoneyaccount.cpp --- a/kmymoney/mymoney/mymoneyaccount.cpp +++ b/kmymoney/mymoney/mymoneyaccount.cpp @@ -51,10 +51,8 @@ #include "payeeidentifier/payeeidentifiertyped.h" #include "payeeidentifier/ibanbic/ibanbic.h" #include "payeeidentifier/nationalaccount/nationalaccount.h" -#include "mymoneystoragenames.h" #include "icons/icons.h" -using namespace MyMoneyStorageNodes; using namespace Icons; MyMoneyAccount::MyMoneyAccount() : @@ -621,3 +619,15 @@ Q_D(const MyMoneyAccount); return !d->m_onlineBankingSettings.value(QLatin1String("provider")).isEmpty(); } + +QString MyMoneyAccount::stdAccName(eMyMoney::Account::Standard stdAccID) +{ + static const QHash stdAccNames { + {eMyMoney::Account::Standard::Liability, QStringLiteral("AStd::Liability")}, + {eMyMoney::Account::Standard::Asset, QStringLiteral("AStd::Asset")}, + {eMyMoney::Account::Standard::Expense, QStringLiteral("AStd::Expense")}, + {eMyMoney::Account::Standard::Income, QStringLiteral("AStd::Income")}, + {eMyMoney::Account::Standard::Equity, QStringLiteral("AStd::Equity")}, + }; + return stdAccNames.value(stdAccID); +} diff --git a/kmymoney/mymoney/mymoneybudget.h b/kmymoney/mymoney/mymoneybudget.h --- a/kmymoney/mymoney/mymoneybudget.h +++ b/kmymoney/mymoney/mymoneybudget.h @@ -34,8 +34,6 @@ class QString; class QDate; -class QDomElement; -class QDomDocument; class MyMoneyMoney; template class QList; @@ -65,13 +63,6 @@ MyMoneyBudget(); explicit MyMoneyBudget(const QString &id); - /** - * This constructor creates an object based on the data found in the - * QDomElement referenced by @p node. If problems arise, the @p id of - * the object is cleared (see MyMoneyObject::clearId()). - */ - explicit MyMoneyBudget(const QDomElement& node); - /** * This constructor creates an object based on the data found in the * MyMoneyBudget budget object. @@ -190,38 +181,6 @@ QMap accountsMap() const; - /** - * This method writes this Budget to the DOM element @p e, - * within the DOM document @p doc. - * - * @param e The element which should be populated with info from this Budget - * @param doc The document which we can use to create new sub-elements - * if needed - */ - void write(QDomElement& e, QDomDocument *doc) const; - - /** - * This method reads a Budget from the DOM element @p e, and - * populates this Budget with the results. - * - * @param e The element from which the Budget should be read - * - * @return bool True if a Budget was successfully loaded from the - * element @p e. If false is returned, the contents of this Budget - * object are undefined. - */ - bool read(const QDomElement& e); - - /** - * This method creates a QDomElement for the @p document - * under the parent node @p parent. (This version overwrites the - * MMObject base class.) - * - * @param document reference to QDomDocument - * @param parent reference to QDomElement parent node - */ - 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/mymoneybudget.cpp b/kmymoney/mymoney/mymoneybudget.cpp --- a/kmymoney/mymoney/mymoneybudget.cpp +++ b/kmymoney/mymoney/mymoneybudget.cpp @@ -24,8 +24,6 @@ // QT Includes #include -#include -#include // ---------------------------------------------------------------------------- // KDE Includes @@ -87,8 +85,6 @@ return (d->m_start == d2->m_start && d->m_amount == d2->m_amount); } -const int BUDGET_VERSION = 2; - class MyMoneyBudget::AccountGroupPrivate { public: @@ -370,13 +366,6 @@ d->m_name = QLatin1Literal("Unconfigured Budget"); } -MyMoneyBudget::MyMoneyBudget(const QDomElement& node) : - MyMoneyObject(*new MyMoneyBudgetPrivate, node) -{ - if (!read(node)) - clearId(); -} - MyMoneyBudget::MyMoneyBudget(const QString& id, const MyMoneyBudget& other) : MyMoneyObject(*new MyMoneyBudgetPrivate(*other.d_func()), id) { @@ -403,106 +392,6 @@ (d->m_start == d2->m_start)); } -void MyMoneyBudget::write(QDomElement& e, QDomDocument *doc) const -{ - Q_D(const MyMoneyBudget); - d->writeBaseXML(*doc, e); - - e.setAttribute(d->getAttrName(Budget::Attribute::Name), d->m_name); - e.setAttribute(d->getAttrName(Budget::Attribute::Start), d->m_start.toString(Qt::ISODate)); - e.setAttribute(d->getAttrName(Budget::Attribute::Version), BUDGET_VERSION); - - QMap::const_iterator it; - for (it = d->m_accounts.begin(); it != d->m_accounts.end(); ++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 = doc->createElement(d->getElName(Budget::Element::Account)); - domAccount.setAttribute(d->getAttrName(Budget::Attribute::ID), it.key()); - domAccount.setAttribute(d->getAttrName(Budget::Attribute::BudgetLevel), d->budgetNames(it.value().budgetLevel())); - domAccount.setAttribute(d->getAttrName(Budget::Attribute::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 = doc->createElement(d->getElName(Budget::Element::Period)); - - domPeriod.setAttribute(d->getAttrName(Budget::Attribute::Amount), (*it_per).amount().toString()); - domPeriod.setAttribute(d->getAttrName(Budget::Attribute::Start), (*it_per).startDate().toString(Qt::ISODate)); - domAccount.appendChild(domPeriod); - } - } - - e.appendChild(domAccount); - } - } -} - -bool MyMoneyBudget::read(const QDomElement& e) -{ - // The goal of this reading method is 100% backward AND 100% forward - // compatibility. Any Budget ever created with any version of KMyMoney - // should be able to be loaded by this method (as long as it's one of the - // Budget types supported in this version, of course) - - Q_D(MyMoneyBudget); - auto result = false; - - if (d->getElName(Budget::Element::Budget) == e.tagName()) { - result = true; - d->m_name = e.attribute(d->getAttrName(Budget::Attribute::Name)); - d->m_start = QDate::fromString(e.attribute(d->getAttrName(Budget::Attribute::Start)), Qt::ISODate); - d->m_id = e.attribute(d->getAttrName(Budget::Attribute::ID)); - - QDomNode child = e.firstChild(); - while (!child.isNull() && child.isElement()) { - QDomElement c = child.toElement(); - - AccountGroup account; - - if (d->getElName(Budget::Element::Account) == c.tagName()) { - if (c.hasAttribute(d->getAttrName(Budget::Attribute::ID))) - account.setId(c.attribute(d->getAttrName(Budget::Attribute::ID))); - - if (c.hasAttribute(d->getAttrName(Budget::Attribute::BudgetLevel))) - account.setBudgetLevel(d->stringToBudgetLevel(c.attribute(d->getAttrName(Budget::Attribute::BudgetLevel)))); - - if (c.hasAttribute(d->getAttrName(Budget::Attribute::BudgetSubAccounts))) - account.setBudgetSubaccounts(c.attribute(d->getAttrName(Budget::Attribute::BudgetSubAccounts)).toUInt()); - } - - QDomNode period = c.firstChild(); - while (!period.isNull() && period.isElement()) { - QDomElement per = period.toElement(); - PeriodGroup pGroup; - - if (d->getElName(Budget::Element::Period) == per.tagName() && per.hasAttribute(d->getAttrName(Budget::Attribute::Amount)) && per.hasAttribute(d->getAttrName(Budget::Attribute::Start))) { - pGroup.setAmount(MyMoneyMoney(per.attribute(d->getAttrName(Budget::Attribute::Amount)))); - pGroup.setStartDate(QDate::fromString(per.attribute(d->getAttrName(Budget::Attribute::Start)), Qt::ISODate)); - account.addPeriod(pGroup.startDate(), pGroup); - } - - period = period.nextSibling(); - } - - d->m_accounts[account.id()] = account; - - child = child.nextSibling(); - } - } - - return result; -} - -void MyMoneyBudget::writeXML(QDomDocument& document, QDomElement& parent) const -{ - Q_D(const MyMoneyBudget); - QDomElement el = document.createElement(d->getElName(Budget::Element::Budget)); - write(el, &document); - parent.appendChild(el); -} - bool MyMoneyBudget::hasReferenceTo(const QString& id) const { Q_D(const MyMoneyBudget); diff --git a/kmymoney/mymoney/mymoneybudget_p.h b/kmymoney/mymoney/mymoneybudget_p.h --- a/kmymoney/mymoney/mymoneybudget_p.h +++ b/kmymoney/mymoney/mymoneybudget_p.h @@ -37,76 +37,9 @@ #include "mymoneymoney.h" #include "mymoneyenums.h" -namespace Budget -{ - enum class Element { Budget = 0, - Account, - Period - }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { ID = 0, - Name, - Start, - Version, - BudgetLevel, - BudgetSubAccounts, - Amount, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - class MyMoneyBudgetPrivate : public MyMoneyObjectPrivate { public: - static QString getElName(const Budget::Element el) - { - static const QMap elNames { - {Budget::Element::Budget, "BUDGET"}, - {Budget::Element::Account, "ACCOUNT"}, - {Budget::Element::Period, "PERIOD"} - }; - return elNames[el]; - } - - static QString getAttrName(const Budget::Attribute attr) - { - static const QHash attrNames { - {Budget::Attribute::ID, QStringLiteral("id")}, - {Budget::Attribute::Name, QStringLiteral("name")}, - {Budget::Attribute::Start, QStringLiteral("start")}, - {Budget::Attribute::Version, QStringLiteral("version")}, - {Budget::Attribute::BudgetLevel, QStringLiteral("budgetlevel")}, - {Budget::Attribute::BudgetSubAccounts, QStringLiteral("budgetsubaccounts")}, - {Budget::Attribute::Amount, QStringLiteral("amount")} - }; - return attrNames[attr]; - } - - static QHash budgetLevelLUT() - { - 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; - } - - static QString budgetNames(eMyMoney::Budget::Level textID) - { - return budgetLevelLUT().value(textID); - } - - static eMyMoney::Budget::Level stringToBudgetLevel(const QString &text) - { - return budgetLevelLUT().key(text, eMyMoney::Budget::Level::Max); - } - /** * The user-assigned name of the Budget */ diff --git a/kmymoney/mymoney/mymoneycostcenter.cpp b/kmymoney/mymoney/mymoneycostcenter.cpp --- a/kmymoney/mymoney/mymoneycostcenter.cpp +++ b/kmymoney/mymoney/mymoneycostcenter.cpp @@ -27,9 +27,6 @@ #include "mymoneyobject_p.h" #include "mymoneyexception.h" -#include "mymoneystoragenames.h" - -using namespace MyMoneyStorageNodes; MyMoneyCostCenter MyMoneyCostCenter::null; diff --git a/kmymoney/mymoney/mymoneyenums.h b/kmymoney/mymoney/mymoneyenums.h --- a/kmymoney/mymoney/mymoneyenums.h +++ b/kmymoney/mymoney/mymoneyenums.h @@ -49,6 +49,16 @@ MaxAccountTypes /**< Denotes the number of different account types */ }; inline uint qHash(const Type key, uint seed) { return ::qHash(static_cast(key), seed); } + + enum class Standard { + Liability, + Asset, + Expense, + Income, + Equity + }; + + inline uint qHash(const Standard key, uint seed) { return ::qHash(static_cast(key), seed); } } namespace Payee { diff --git a/kmymoney/mymoney/mymoneyfile.cpp b/kmymoney/mymoney/mymoneyfile.cpp --- a/kmymoney/mymoney/mymoneyfile.cpp +++ b/kmymoney/mymoney/mymoneyfile.cpp @@ -61,14 +61,12 @@ #include "mymoneyexception.h" #include "onlinejob.h" #include "storageenums.h" -#include "mymoneystoragenames.h" #include "mymoneyenums.h" // include the following line to get a 'cout' for debug purposes // #include using namespace eMyMoney; -using namespace MyMoneyStandardAccounts; const QString MyMoneyFile::AccountSeparator = QChar(':'); @@ -1447,35 +1445,35 @@ { d->checkStorage(); - return account(stdAccNames[stdAccLiability]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability)); } MyMoneyAccount MyMoneyFile::asset() const { d->checkStorage(); - return account(stdAccNames[stdAccAsset]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)); } MyMoneyAccount MyMoneyFile::expense() const { d->checkStorage(); - return account(stdAccNames[stdAccExpense]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)); } MyMoneyAccount MyMoneyFile::income() const { d->checkStorage(); - return account(stdAccNames[stdAccIncome]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income)); } MyMoneyAccount MyMoneyFile::equity() const { d->checkStorage(); - return account(stdAccNames[stdAccEquity]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity)); } unsigned int MyMoneyFile::transactionCount(const QString& account) const diff --git a/kmymoney/mymoney/mymoneyinstitution.cpp b/kmymoney/mymoney/mymoneyinstitution.cpp --- a/kmymoney/mymoney/mymoneyinstitution.cpp +++ b/kmymoney/mymoney/mymoneyinstitution.cpp @@ -37,9 +37,7 @@ #include "icons.h" #include -#include "mymoneystoragenames.h" -using namespace MyMoneyStorageNodes; using namespace Icons; MyMoneyInstitution::MyMoneyInstitution() : diff --git a/kmymoney/mymoney/mymoneykeyvaluecontainer.h b/kmymoney/mymoney/mymoneykeyvaluecontainer.h --- a/kmymoney/mymoney/mymoneykeyvaluecontainer.h +++ b/kmymoney/mymoney/mymoneykeyvaluecontainer.h @@ -36,8 +36,6 @@ #include "mymoneyunittestable.h" class QString; -class QDomDocument; -class QDomElement; template class QMap; @@ -63,7 +61,6 @@ public: MyMoneyKeyValueContainer(); - explicit MyMoneyKeyValueContainer(const QDomElement& node); MyMoneyKeyValueContainer(const MyMoneyKeyValueContainer & other); MyMoneyKeyValueContainer(MyMoneyKeyValueContainer && other); @@ -133,15 +130,6 @@ QString operator[](const QString& k) const; QString& operator[](const QString& k); - - /** - * This method creates a QDomElement for the @p document - * under the parent node @p parent. - * - * @param document reference to QDomDocument - * @param parent reference to QDomElement parent node - */ - void writeXML(QDomDocument& document, QDomElement& parent) const; }; inline void swap(MyMoneyKeyValueContainer& first, MyMoneyKeyValueContainer& second) // krazy:exclude=inline diff --git a/kmymoney/mymoney/mymoneykeyvaluecontainer.cpp b/kmymoney/mymoney/mymoneykeyvaluecontainer.cpp --- a/kmymoney/mymoney/mymoneykeyvaluecontainer.cpp +++ b/kmymoney/mymoney/mymoneykeyvaluecontainer.cpp @@ -22,9 +22,6 @@ // ---------------------------------------------------------------------------- // QT Includes -#include -#include - // ---------------------------------------------------------------------------- // KDE Includes @@ -32,9 +29,6 @@ // Project Includes #include "mymoneyexception.h" -#include "mymoneystoragenames.h" - -using namespace MyMoneyStorageNodes; Q_GLOBAL_STATIC(QString, nullString) @@ -43,24 +37,6 @@ { } -MyMoneyKeyValueContainer::MyMoneyKeyValueContainer(const QDomElement& node) : - d_ptr(new MyMoneyKeyValueContainerPrivate) -{ - Q_D(MyMoneyKeyValueContainer); - if (!node.isNull()) { - if (nodeNames[nnKeyValuePairs] != node.tagName()) - throw MYMONEYEXCEPTION_CSTRING("Node was not KEYVALUEPAIRS"); - - d->m_kvp.clear(); - - QDomNodeList nodeList = node.elementsByTagName(d->getElName(Element::Pair)); - for (int i = 0; i < nodeList.count(); ++i) { - const QDomElement& el(nodeList.item(i).toElement()); - d->m_kvp[el.attribute(d->getAttrName(Attribute::Key))] = el.attribute(d->getAttrName(Attribute::Value)); - } - } -} - MyMoneyKeyValueContainer::MyMoneyKeyValueContainer(const MyMoneyKeyValueContainer& other) : d_ptr(new MyMoneyKeyValueContainerPrivate(*other.d_func())) { @@ -148,21 +124,3 @@ Q_D(MyMoneyKeyValueContainer); return d->m_kvp[k]; } - -void MyMoneyKeyValueContainer::writeXML(QDomDocument& document, QDomElement& parent) const -{ - Q_D(const MyMoneyKeyValueContainer); - if (d->m_kvp.count() != 0) { - QDomElement el = document.createElement(nodeNames[nnKeyValuePairs]); - - QMap::ConstIterator it; - for (it = d->m_kvp.begin(); it != d->m_kvp.end(); ++it) { - QDomElement pair = document.createElement(d->getElName(Element::Pair)); - pair.setAttribute(d->getAttrName(Attribute::Key), it.key()); - pair.setAttribute(d->getAttrName(Attribute::Value), it.value()); - el.appendChild(pair); - } - - parent.appendChild(el); - } -} diff --git a/kmymoney/mymoney/mymoneykeyvaluecontainer_p.h b/kmymoney/mymoney/mymoneykeyvaluecontainer_p.h --- a/kmymoney/mymoney/mymoneykeyvaluecontainer_p.h +++ b/kmymoney/mymoney/mymoneykeyvaluecontainer_p.h @@ -30,44 +30,9 @@ // ---------------------------------------------------------------------------- // Project Includes -namespace KVC -{ - enum class Element { Pair }; - - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { Key, - Value, - // insert new entries above this line - LastAttribute - }; - - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - -using namespace KVC; - class MyMoneyKeyValueContainerPrivate { public: - - static QString getElName(const Element el) - { - static const QMap elNames { - {Element::Pair, QStringLiteral("PAIR")} - }; - return elNames[el]; - } - - static QString getAttrName(const Attribute attr) - { - static const QMap attrNames { - {Attribute::Key, QStringLiteral("key")}, - {Attribute::Value, QStringLiteral("value")} - }; - return attrNames[attr]; - } - /** * This member variable represents the container of key/value pairs. */ diff --git a/kmymoney/mymoney/mymoneyobject.h b/kmymoney/mymoney/mymoneyobject.h --- a/kmymoney/mymoney/mymoneyobject.h +++ b/kmymoney/mymoney/mymoneyobject.h @@ -31,8 +31,6 @@ #include "mymoneyunittestable.h" class QString; -class QDomDocument; -class QDomElement; /** * @author Thomas Baumgart @@ -77,15 +75,6 @@ */ virtual bool hasReferenceTo(const QString& id) const = 0; - /** - * This method creates a QDomElement for the @p document - * under the parent node @p parent. - * - * @param document reference to QDomDocument - * @param parent reference to QDomElement parent node - */ - virtual void writeXML(QDomDocument &document, QDomElement &parent) const; - bool operator == (const MyMoneyObject& right) const; protected: @@ -93,16 +82,6 @@ MyMoneyObject(MyMoneyObjectPrivate &dd); MyMoneyObject(MyMoneyObjectPrivate &dd, const QString& id); - MyMoneyObject(MyMoneyObjectPrivate &dd, - const QDomElement& node, - bool forceId = true); - - /** - * This contructor assigns the id to the MyMoneyObject - * - * @param id ID of object - */ - MyMoneyObject(const QString& id); }; #endif diff --git a/kmymoney/mymoney/mymoneyobject.cpp b/kmymoney/mymoney/mymoneyobject.cpp --- a/kmymoney/mymoney/mymoneyobject.cpp +++ b/kmymoney/mymoney/mymoneyobject.cpp @@ -40,17 +40,6 @@ d->m_id = id; } -MyMoneyObject::MyMoneyObject(MyMoneyObjectPrivate &dd, - const QDomElement& node, - bool forceId) : - d_ptr(&dd) -{ - Q_D(MyMoneyObject); - d->m_id = node.attribute(QStringLiteral("id")); - if (d->m_id.length() == 0 && forceId) - throw MYMONEYEXCEPTION_CSTRING("Node has no ID"); -} - MyMoneyObject::~MyMoneyObject() { Q_D(MyMoneyObject); @@ -74,8 +63,3 @@ Q_D(MyMoneyObject); d->m_id.clear(); } - -void MyMoneyObject::writeXML(QDomDocument &, QDomElement &) const -{ - -} diff --git a/kmymoney/mymoney/mymoneyobject_p.h b/kmymoney/mymoney/mymoneyobject_p.h --- a/kmymoney/mymoney/mymoneyobject_p.h +++ b/kmymoney/mymoney/mymoneyobject_p.h @@ -44,16 +44,6 @@ m_id = id; } - /** - * This method writes out the members contained in this object. - */ - void writeBaseXML(QDomDocument& document, QDomElement& el) const - { - Q_UNUSED(document); - - el.setAttribute(QStringLiteral("id"), m_id); - } - QString m_id; }; diff --git a/kmymoney/mymoney/mymoneypayee.cpp b/kmymoney/mymoney/mymoneypayee.cpp --- a/kmymoney/mymoney/mymoneypayee.cpp +++ b/kmymoney/mymoney/mymoneypayee.cpp @@ -33,11 +33,8 @@ // Project Includes #include -#include "mymoneystoragenames.h" #include "mymoneyenums.h" -using namespace MyMoneyStorageNodes; - MyMoneyPayee MyMoneyPayee::null; MyMoneyPayee::MyMoneyPayee() : diff --git a/kmymoney/mymoney/mymoneyreport.h b/kmymoney/mymoney/mymoneyreport.h --- a/kmymoney/mymoney/mymoneyreport.h +++ b/kmymoney/mymoney/mymoneyreport.h @@ -32,8 +32,6 @@ #include "mymoneyunittestable.h" class QString; -class QDomElement; -class QDomDocument; class MyMoneyAccount; template class QList; @@ -370,40 +368,6 @@ */ bool includes(const MyMoneyAccount& acc) const; - /** - * This method writes this report to the DOM element @p e, - * within the DOM document @p doc. - * - * @param e The element which should be populated with info from this report - * @param doc The document which we can use to create new sub-elements - * if needed - * @param anonymous Whether the sensitive parts of the report should be - * masked - */ - void write(QDomElement& e, QDomDocument *doc, bool anonymous = false) const; - - /** - * This method reads a report from the DOM element @p e, and - * populates this report with the results. - * - * @param e The element from which the report should be read - * - * @return bool True if a report was successfully loaded from the - * element @p e. If false is returned, the contents of this report - * object are undefined. - */ - bool read(const QDomElement& e); - - /** - * This method creates a QDomElement for the @p document - * under the parent node @p parent. (This version overwrites the - * MMObject base class.) - * - * @param document reference to QDomDocument - * @param parent reference to QDomElement parent node - */ - 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/mymoneyreport.cpp b/kmymoney/mymoney/mymoneyreport.cpp --- a/kmymoney/mymoney/mymoneyreport.cpp +++ b/kmymoney/mymoney/mymoneyreport.cpp @@ -23,9 +23,6 @@ // ---------------------------------------------------------------------------- // QT Includes -#include -#include - // ---------------------------------------------------------------------------- // KDE Includes @@ -35,13 +32,10 @@ #include "mymoneymoney.h" #include "mymoneyfile.h" #include "mymoneyaccount.h" -#include "mymoneystoragenames.h" #include "mymoneytransaction.h" #include "mymoneytransactionfilter.h" #include "mymoneyexception.h" -using namespace MyMoneyStorageNodes; - MyMoneyReport::MyMoneyReport() : MyMoneyObject(*new MyMoneyReportPrivate) { @@ -942,520 +936,6 @@ return result; } -void MyMoneyReport::write(QDomElement& e, QDomDocument *doc, bool anonymous) const -{ - Q_D(const MyMoneyReport); - // No matter what changes, be sure to have a 'type' attribute. Only change - // the major type if it becomes impossible to maintain compatibility with - // older versions of the program as new features are added to the reports. - // Feel free to change the minor type every time a change is made here. - - // write report's internals - if (d->m_reportType == eMyMoney::Report::ReportType::PivotTable) - e.setAttribute(d->getAttrName(Report::Attribute::Type), "pivottable 1.15"); - else if (d->m_reportType == eMyMoney::Report::ReportType::QueryTable) - e.setAttribute(d->getAttrName(Report::Attribute::Type), "querytable 1.14"); - else if (d->m_reportType == eMyMoney::Report::ReportType::InfoTable) - e.setAttribute(d->getAttrName(Report::Attribute::Type), "infotable 1.0"); - - e.setAttribute(d->getAttrName(Report::Attribute::Group), d->m_group); - e.setAttribute(d->getAttrName(Report::Attribute::ID), d->m_id); - - // write general tab - if (anonymous) { - e.setAttribute(d->getAttrName(Report::Attribute::Name), d->m_id); - e.setAttribute(d->getAttrName(Report::Attribute::Comment), QString(d->m_comment).fill('x')); - } else { - e.setAttribute(d->getAttrName(Report::Attribute::Name), d->m_name); - e.setAttribute(d->getAttrName(Report::Attribute::Comment), d->m_comment); - } - e.setAttribute(d->getAttrName(Report::Attribute::ConvertCurrency), d->m_convertCurrency); - e.setAttribute(d->getAttrName(Report::Attribute::Favorite), d->m_favorite); - e.setAttribute(d->getAttrName(Report::Attribute::SkipZero), d->m_skipZero); - - e.setAttribute(d->getAttrName(Report::Attribute::DateLock), d->dateLockAttributeToString(static_cast(d->m_dateLock))); - - if (d->m_reportType == eMyMoney::Report::ReportType::PivotTable) { - // write report's internals - e.setAttribute(d->getAttrName(Report::Attribute::IncludesActuals), d->m_includeBudgetActuals); - e.setAttribute(d->getAttrName(Report::Attribute::IncludesForecast), d->m_includeForecast); - e.setAttribute(d->getAttrName(Report::Attribute::IncludesPrice), d->m_includePrice); - e.setAttribute(d->getAttrName(Report::Attribute::IncludesAveragePrice), d->m_includeAveragePrice); - e.setAttribute(d->getAttrName(Report::Attribute::MixedTime), d->m_mixedTime); - e.setAttribute(d->getAttrName(Report::Attribute::Investments), d->m_investments); // it's setable in rows/columns tab of querytable, but here it is internal setting - - // write rows/columns tab - if (!d->m_budgetId.isEmpty()) - e.setAttribute(d->getAttrName(Report::Attribute::Budget), d->m_budgetId); - - e.setAttribute(d->getAttrName(Report::Attribute::RowType), d->reportNames(d->m_rowType)); - e.setAttribute(d->getAttrName(Report::Attribute::ShowRowTotals), d->m_showRowTotals); - e.setAttribute(d->getAttrName(Report::Attribute::ShowColumnTotals), d->m_showColumnTotals); - e.setAttribute(d->getAttrName(Report::Attribute::Detail), d->reportNames(d->m_detailLevel)); - - e.setAttribute(d->getAttrName(Report::Attribute::IncludesMovingAverage), d->m_includeMovingAverage); - if (d->m_includeMovingAverage) - e.setAttribute(d->getAttrName(Report::Attribute::MovingAverageDays), d->m_movingAverageDays); - - e.setAttribute(d->getAttrName(Report::Attribute::IncludesSchedules), d->m_includeSchedules); - e.setAttribute(d->getAttrName(Report::Attribute::IncludesTransfers), d->m_includeTransfers); - e.setAttribute(d->getAttrName(Report::Attribute::IncludesUnused), d->m_includeUnusedAccounts); - e.setAttribute(d->getAttrName(Report::Attribute::ColumnsAreDays), d->m_columnsAreDays); - e.setAttribute(d->getAttrName(Report::Attribute::ChartType), d->reportNames(d->m_chartType)); - e.setAttribute(d->getAttrName(Report::Attribute::ChartCHGridLines), d->m_chartCHGridLines); - e.setAttribute(d->getAttrName(Report::Attribute::ChartSVGridLines), d->m_chartSVGridLines); - e.setAttribute(d->getAttrName(Report::Attribute::ChartDataLabels), d->m_chartDataLabels); - e.setAttribute(d->getAttrName(Report::Attribute::ChartByDefault), d->m_chartByDefault); - e.setAttribute(d->getAttrName(Report::Attribute::LogYAxis), d->m_logYaxis); - e.setAttribute(d->getAttrName(Report::Attribute::ChartLineWidth), d->m_chartLineWidth); - e.setAttribute(d->getAttrName(Report::Attribute::ColumnType), d->reportNames(d->m_columnType)); - e.setAttribute(d->getAttrName(Report::Attribute::DataLock), d->reportNames(d->m_dataLock)); - e.setAttribute(d->getAttrName(Report::Attribute::DataRangeStart), d->m_dataRangeStart); - e.setAttribute(d->getAttrName(Report::Attribute::DataRangeEnd), d->m_dataRangeEnd); - e.setAttribute(d->getAttrName(Report::Attribute::DataMajorTick), d->m_dataMajorTick); - e.setAttribute(d->getAttrName(Report::Attribute::DataMinorTick), d->m_dataMinorTick); - e.setAttribute(d->getAttrName(Report::Attribute::YLabelsPrecision), d->m_yLabelsPrecision); - } else if (d->m_reportType == eMyMoney::Report::ReportType::QueryTable) { - // write rows/columns tab - e.setAttribute(d->getAttrName(Report::Attribute::RowType), d->reportNames(d->m_rowType)); - QStringList columns; - unsigned qc = d->m_queryColumns; - unsigned it_qc = eMyMoney::Report::QueryColumn::Begin; - unsigned index = 1; - while (it_qc != eMyMoney::Report::QueryColumn::End) { - if (qc & it_qc) - columns += d->reportNamesForQC(static_cast(it_qc)); - it_qc *= 2; - index++; - } - e.setAttribute(d->getAttrName(Report::Attribute::QueryColumns), columns.join(",")); - - e.setAttribute(d->getAttrName(Report::Attribute::Tax), d->m_tax); - e.setAttribute(d->getAttrName(Report::Attribute::Investments), d->m_investments); - e.setAttribute(d->getAttrName(Report::Attribute::Loans), d->m_loans); - e.setAttribute(d->getAttrName(Report::Attribute::HideTransactions), d->m_hideTransactions); - e.setAttribute(d->getAttrName(Report::Attribute::ShowColumnTotals), d->m_showColumnTotals); - e.setAttribute(d->getAttrName(Report::Attribute::Detail), d->reportNames(d->m_detailLevel)); - - // write performance tab - if (d->m_queryColumns & eMyMoney::Report::QueryColumn::Performance || d->m_queryColumns & eMyMoney::Report::QueryColumn::CapitalGain) - e.setAttribute(d->getAttrName(Report::Attribute::InvestmentSum), static_cast(d->m_investmentSum)); - - // write capital gains tab - if (d->m_queryColumns & eMyMoney::Report::QueryColumn::CapitalGain) { - if (d->m_investmentSum == eMyMoney::Report::InvestmentSum::Sold) { - e.setAttribute(d->getAttrName(Report::Attribute::SettlementPeriod), d->m_settlementPeriod); - e.setAttribute(d->getAttrName(Report::Attribute::ShowSTLTCapitalGains), d->m_showSTLTCapitalGains); - e.setAttribute(d->getAttrName(Report::Attribute::TermsSeparator), d->m_tseparator.toString(Qt::ISODate)); - } - } - } else if (d->m_reportType == eMyMoney::Report::ReportType::InfoTable) - e.setAttribute(d->getAttrName(Report::Attribute::ShowRowTotals), d->m_showRowTotals); - - // - // Text Filter - // - - QRegExp textfilter; - if (textFilter(textfilter)) { - QDomElement f = doc->createElement(d->getElName(Report::Element::Text)); - f.setAttribute(d->getAttrName(Report::Attribute::Pattern), textfilter.pattern()); - f.setAttribute(d->getAttrName(Report::Attribute::CaseSensitive), (textfilter.caseSensitivity() == Qt::CaseSensitive) ? 1 : 0); - f.setAttribute(d->getAttrName(Report::Attribute::RegEx), (textfilter.patternSyntax() == QRegExp::Wildcard) ? 1 : 0); - f.setAttribute(d->getAttrName(Report::Attribute::InvertText), MyMoneyTransactionFilter::isInvertingText()); - e.appendChild(f); - } - - // - // Type & State Filters - // - QList typelist; - if (types(typelist) && ! typelist.empty()) { - // iterate over payees, and add each one - QList::const_iterator it_type = typelist.constBegin(); - while (it_type != typelist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Type)); - p.setAttribute(d->getAttrName(Report::Attribute::Type), d->typeAttributeToString(*it_type)); - e.appendChild(p); - - ++it_type; - } - } - - QList statelist; - if (states(statelist) && ! statelist.empty()) { - // iterate over payees, and add each one - QList::const_iterator it_state = statelist.constBegin(); - while (it_state != statelist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::State)); - p.setAttribute(d->getAttrName(Report::Attribute::State), d->stateAttributeToString(*it_state)); - e.appendChild(p); - - ++it_state; - } - } - // - // Number Filter - // - - QString nrFrom, nrTo; - if (numberFilter(nrFrom, nrTo)) { - QDomElement f = doc->createElement(d->getElName(Report::Element::Number)); - f.setAttribute(d->getAttrName(Report::Attribute::From), nrFrom); - f.setAttribute(d->getAttrName(Report::Attribute::To), nrTo); - e.appendChild(f); - } - - // - // Amount Filter - // - - MyMoneyMoney from, to; - if (amountFilter(from, to)) { // bool getAmountFilter(MyMoneyMoney&,MyMoneyMoney&); - QDomElement f = doc->createElement(d->getElName(Report::Element::Amount)); - f.setAttribute(d->getAttrName(Report::Attribute::From), from.toString()); - f.setAttribute(d->getAttrName(Report::Attribute::To), to.toString()); - e.appendChild(f); - } - - // - // Payees Filter - // - - QStringList payeelist; - if (payees(payeelist)) { - if (payeelist.empty()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Payee)); - e.appendChild(p); - } else { - // iterate over payees, and add each one - QStringList::const_iterator it_payee = payeelist.constBegin(); - while (it_payee != payeelist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Payee)); - p.setAttribute(d->getAttrName(Report::Attribute::ID), *it_payee); - e.appendChild(p); - - ++it_payee; - } - } - } - - // - // Tags Filter - // - - QStringList taglist; - if (tags(taglist)) { - if (taglist.empty()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Tag)); - e.appendChild(p); - } else { - // iterate over tags, and add each one - QStringList::const_iterator it_tag = taglist.constBegin(); - while (it_tag != taglist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Tag)); - p.setAttribute(d->getAttrName(Report::Attribute::ID), *it_tag); - e.appendChild(p); - - ++it_tag; - } - } - } - - // - // Account Groups Filter - // - - QList accountgrouplist; - if (accountGroups(accountgrouplist)) { - // iterate over accounts, and add each one - QList::const_iterator it_group = accountgrouplist.constBegin(); - while (it_group != accountgrouplist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::AccountGroup)); - p.setAttribute(d->getAttrName(Report::Attribute::Group), d->accountTypeAttributeToString(static_cast(*it_group))); - e.appendChild(p); - - ++it_group; - } - } - - // - // Accounts Filter - // - - QStringList accountlist; - if (accounts(accountlist)) { - // iterate over accounts, and add each one - QStringList::const_iterator it_account = accountlist.constBegin(); - while (it_account != accountlist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Account)); - p.setAttribute(d->getAttrName(Report::Attribute::ID), *it_account); - e.appendChild(p); - - ++it_account; - } - } - - // - // Categories Filter - // - - accountlist.clear(); - if (categories(accountlist)) { - // iterate over accounts, and add each one - QStringList::const_iterator it_account = accountlist.constBegin(); - while (it_account != accountlist.constEnd()) { - QDomElement p = doc->createElement(d->getElName(Report::Element::Category)); - p.setAttribute(d->getAttrName(Report::Attribute::ID), *it_account); - e.appendChild(p); - - ++it_account; - } - } - - // - // Date Filter - // - - if (d->m_dateLock == eMyMoney::TransactionFilter::Date::UserDefined) { - QDate dateFrom, dateTo; - if (dateFilter(dateFrom, dateTo)) { - QDomElement f = doc->createElement(d->getElName(Report::Element::Dates)); - if (dateFrom.isValid()) - f.setAttribute(d->getAttrName(Report::Attribute::From), dateFrom.toString(Qt::ISODate)); - if (dateTo.isValid()) - f.setAttribute(d->getAttrName(Report::Attribute::To), dateTo.toString(Qt::ISODate)); - e.appendChild(f); - } - } -} - -bool MyMoneyReport::read(const QDomElement& e) -{ - Q_D(MyMoneyReport); - // The goal of this reading method is 100% backward AND 100% forward - // compatibility. Any report ever created with any version of KMyMoney - // should be able to be loaded by this method (as long as it's one of the - // report types supported in this version, of course) - - if (e.tagName().compare(nodeNames[nnReport]) != 0) - return false; - - // read report's internals - QString type = e.attribute(d->getAttrName(Report::Attribute::Type)); - if (type.startsWith(QLatin1String("pivottable"))) - d->m_reportType = eMyMoney::Report::ReportType::PivotTable; - else if (type.startsWith(QLatin1String("querytable"))) - d->m_reportType = eMyMoney::Report::ReportType::QueryTable; - else if (type.startsWith(QLatin1String("infotable"))) - d->m_reportType = eMyMoney::Report::ReportType::InfoTable; - else - return false; - - d->m_group = e.attribute(d->getAttrName(Report::Attribute::Group)); - d->m_id = e.attribute(d->getAttrName(Report::Attribute::ID)); - - clearTransactionFilter(); - - // read date tab - QString datelockstr = e.attribute(d->getAttrName(Report::Attribute::DateLock), "userdefined"); - // Handle the pivot 1.2/query 1.1 case where the values were saved as - // numbers - bool ok = false; - int i = datelockstr.toUInt(&ok); - if (!ok) { - i = d->stringToDateLockAttribute(datelockstr); - if (i == -1) - i = (int)eMyMoney::TransactionFilter::Date::UserDefined; - } - setDateFilter(static_cast(i)); - - // read general tab - d->m_name = e.attribute(d->getAttrName(Report::Attribute::Name)); - d->m_comment = e.attribute(d->getAttrName(Report::Attribute::Comment), "Extremely old report"); - d->m_convertCurrency = e.attribute(d->getAttrName(Report::Attribute::ConvertCurrency), "1").toUInt(); - d->m_favorite = e.attribute(d->getAttrName(Report::Attribute::Favorite), "0").toUInt(); - d->m_skipZero = e.attribute(d->getAttrName(Report::Attribute::SkipZero), "0").toUInt(); - - if (d->m_reportType == eMyMoney::Report::ReportType::PivotTable) { - // read report's internals - d->m_includeBudgetActuals = e.attribute(d->getAttrName(Report::Attribute::IncludesActuals), "0").toUInt(); - d->m_includeForecast = e.attribute(d->getAttrName(Report::Attribute::IncludesForecast), "0").toUInt(); - d->m_includePrice = e.attribute(d->getAttrName(Report::Attribute::IncludesPrice), "0").toUInt(); - d->m_includeAveragePrice = e.attribute(d->getAttrName(Report::Attribute::IncludesAveragePrice), "0").toUInt(); - d->m_mixedTime = e.attribute(d->getAttrName(Report::Attribute::MixedTime), "0").toUInt(); - d->m_investments = e.attribute(d->getAttrName(Report::Attribute::Investments), "0").toUInt(); - - // read rows/columns tab - if (e.hasAttribute(d->getAttrName(Report::Attribute::Budget))) - d->m_budgetId = e.attribute(d->getAttrName(Report::Attribute::Budget)); - - const auto rowTypeFromXML = d->stringToRowType(e.attribute(d->getAttrName(Report::Attribute::RowType))); - if (rowTypeFromXML != eMyMoney::Report::RowType::Invalid) - setRowType(rowTypeFromXML); - else - setRowType(eMyMoney::Report::RowType::ExpenseIncome); - - if (e.hasAttribute(d->getAttrName(Report::Attribute::ShowRowTotals))) - d->m_showRowTotals = e.attribute(d->getAttrName(Report::Attribute::ShowRowTotals)).toUInt(); - else if (rowType() == eMyMoney::Report::RowType::ExpenseIncome) // for backward compatibility - d->m_showRowTotals = true; - d->m_showColumnTotals = e.attribute(d->getAttrName(Report::Attribute::ShowColumnTotals), "1").toUInt(); - - //check for reports with older settings which didn't have the detail attribute - const auto detailLevelFromXML = d->stringToDetailLevel(e.attribute(d->getAttrName(Report::Attribute::Detail))); - if (detailLevelFromXML != eMyMoney::Report::DetailLevel::End) - d->m_detailLevel = detailLevelFromXML; - else - d->m_detailLevel = eMyMoney::Report::DetailLevel::All; - - d->m_includeMovingAverage = e.attribute(d->getAttrName(Report::Attribute::IncludesMovingAverage), "0").toUInt(); - if (d->m_includeMovingAverage) - d->m_movingAverageDays = e.attribute(d->getAttrName(Report::Attribute::MovingAverageDays), "1").toUInt(); - d->m_includeSchedules = e.attribute(d->getAttrName(Report::Attribute::IncludesSchedules), "0").toUInt(); - d->m_includeTransfers = e.attribute(d->getAttrName(Report::Attribute::IncludesTransfers), "0").toUInt(); - d->m_includeUnusedAccounts = e.attribute(d->getAttrName(Report::Attribute::IncludesUnused), "0").toUInt(); - d->m_columnsAreDays = e.attribute(d->getAttrName(Report::Attribute::ColumnsAreDays), "0").toUInt(); - - // read chart tab - const auto chartTypeFromXML = d->stringToChartType(e.attribute(d->getAttrName(Report::Attribute::ChartType))); - if (chartTypeFromXML != eMyMoney::Report::ChartType::End) - d->m_chartType = chartTypeFromXML; - else - d->m_chartType = eMyMoney::Report::ChartType::None; - - d->m_chartCHGridLines = e.attribute(d->getAttrName(Report::Attribute::ChartCHGridLines), "1").toUInt(); - d->m_chartSVGridLines = e.attribute(d->getAttrName(Report::Attribute::ChartSVGridLines), "1").toUInt(); - d->m_chartDataLabels = e.attribute(d->getAttrName(Report::Attribute::ChartDataLabels), "1").toUInt(); - d->m_chartByDefault = e.attribute(d->getAttrName(Report::Attribute::ChartByDefault), "0").toUInt(); - d->m_logYaxis = e.attribute(d->getAttrName(Report::Attribute::LogYAxis), "0").toUInt(); - d->m_chartLineWidth = e.attribute(d->getAttrName(Report::Attribute::ChartLineWidth), QString(m_lineWidth)).toUInt(); - - // read range tab - const auto columnTypeFromXML = d->stringToColumnType(e.attribute(d->getAttrName(Report::Attribute::ColumnType))); - if (columnTypeFromXML != eMyMoney::Report::ColumnType::Invalid) - setColumnType(columnTypeFromXML); - else - setColumnType(eMyMoney::Report::ColumnType::Months); - - const auto dataLockFromXML = d->stringToDataLockAttribute(e.attribute(d->getAttrName(Report::Attribute::DataLock))); - if (dataLockFromXML != eMyMoney::Report::DataLock::DataOptionCount) - setDataFilter(dataLockFromXML); - else - setDataFilter(eMyMoney::Report::DataLock::Automatic); - - d->m_dataRangeStart = e.attribute(d->getAttrName(Report::Attribute::DataRangeStart), "0"); - d->m_dataRangeEnd= e.attribute(d->getAttrName(Report::Attribute::DataRangeEnd), "0"); - d->m_dataMajorTick = e.attribute(d->getAttrName(Report::Attribute::DataMajorTick), "0"); - d->m_dataMinorTick = e.attribute(d->getAttrName(Report::Attribute::DataMinorTick), "0"); - d->m_yLabelsPrecision = e.attribute(d->getAttrName(Report::Attribute::YLabelsPrecision), "2").toUInt(); - } else if (d->m_reportType == eMyMoney::Report::ReportType::QueryTable) { - // read rows/columns tab - const auto rowTypeFromXML = d->stringToRowType(e.attribute(d->getAttrName(Report::Attribute::RowType))); - if (rowTypeFromXML != eMyMoney::Report::RowType::Invalid) - setRowType(rowTypeFromXML); - else - setRowType(eMyMoney::Report::RowType::Account); - - unsigned qc = 0; - QStringList columns = e.attribute(d->getAttrName(Report::Attribute::QueryColumns), "none").split(','); - foreach (const auto column, columns) { - const int queryColumnFromXML = d->stringToQueryColumn(column); - i = d->stringToQueryColumn(column); - if (queryColumnFromXML != eMyMoney::Report::QueryColumn::End) - qc |= queryColumnFromXML; - } - setQueryColumns(static_cast(qc)); - - d->m_tax = e.attribute(d->getAttrName(Report::Attribute::Tax), "0").toUInt(); - d->m_investments = e.attribute(d->getAttrName(Report::Attribute::Investments), "0").toUInt(); - d->m_loans = e.attribute(d->getAttrName(Report::Attribute::Loans), "0").toUInt(); - d->m_hideTransactions = e.attribute(d->getAttrName(Report::Attribute::HideTransactions), "0").toUInt(); - d->m_showColumnTotals = e.attribute(d->getAttrName(Report::Attribute::ShowColumnTotals), "1").toUInt(); - const auto detailLevelFromXML = d->stringToDetailLevel(e.attribute(d->getAttrName(Report::Attribute::Detail), "none")); - if (detailLevelFromXML == eMyMoney::Report::DetailLevel::All) - d->m_detailLevel = detailLevelFromXML; - else - d->m_detailLevel = eMyMoney::Report::DetailLevel::None; - - // read performance or capital gains tab - if (d->m_queryColumns & eMyMoney::Report::QueryColumn::Performance) - d->m_investmentSum = static_cast(e.attribute(d->getAttrName(Report::Attribute::InvestmentSum), QString::number(static_cast(eMyMoney::Report::InvestmentSum::Period))).toInt()); - - // read capital gains tab - if (d->m_queryColumns & eMyMoney::Report::QueryColumn::CapitalGain) { - d->m_investmentSum = static_cast(e.attribute(d->getAttrName(Report::Attribute::InvestmentSum), QString::number(static_cast(eMyMoney::Report::InvestmentSum::Sold))).toInt()); - if (d->m_investmentSum == eMyMoney::Report::InvestmentSum::Sold) { - d->m_showSTLTCapitalGains = e.attribute(d->getAttrName(Report::Attribute::ShowSTLTCapitalGains), "0").toUInt(); - d->m_settlementPeriod = e.attribute(d->getAttrName(Report::Attribute::SettlementPeriod), "3").toUInt(); - d->m_tseparator = QDate::fromString(e.attribute(d->getAttrName(Report::Attribute::TermsSeparator), QDate::currentDate().addYears(-1).toString(Qt::ISODate)),Qt::ISODate); - } - } - } else if (d->m_reportType == eMyMoney::Report::ReportType::InfoTable) { - if (e.hasAttribute(d->getAttrName(Report::Attribute::ShowRowTotals))) - d->m_showRowTotals = e.attribute(d->getAttrName(Report::Attribute::ShowRowTotals)).toUInt(); - else - d->m_showRowTotals = true; - } - - QDomNode child = e.firstChild(); - while (!child.isNull() && child.isElement()) { - QDomElement c = child.toElement(); - if (d->getElName(Report::Element::Text) == c.tagName() && c.hasAttribute(d->getAttrName(Report::Attribute::Pattern))) { - setTextFilter(QRegExp(c.attribute(d->getAttrName(Report::Attribute::Pattern)), - c.attribute(d->getAttrName(Report::Attribute::CaseSensitive), "1").toUInt() - ? Qt::CaseSensitive : Qt::CaseInsensitive, - c.attribute(d->getAttrName(Report::Attribute::RegEx), "1").toUInt() - ? QRegExp::Wildcard : QRegExp::RegExp), - c.attribute(d->getAttrName(Report::Attribute::InvertText), "0").toUInt()); - } - if (d->getElName(Report::Element::Type) == c.tagName() && c.hasAttribute(d->getAttrName(Report::Attribute::Type))) { - i = d->stringToTypeAttribute(c.attribute(d->getAttrName(Report::Attribute::Type))); - if (i != -1) - addType(i); - } - if (d->getElName(Report::Element::State) == c.tagName() && c.hasAttribute(d->getAttrName(Report::Attribute::State))) { - i = d->stringToStateAttribute(c.attribute(d->getAttrName(Report::Attribute::State))); - if (i != -1) - addState(i); - } - if (d->getElName(Report::Element::Number) == c.tagName()) - setNumberFilter(c.attribute(d->getAttrName(Report::Attribute::From)), c.attribute(d->getAttrName(Report::Attribute::To))); - if (d->getElName(Report::Element::Amount) == c.tagName()) - setAmountFilter(MyMoneyMoney(c.attribute(d->getAttrName(Report::Attribute::From), "0/100")), MyMoneyMoney(c.attribute(d->getAttrName(Report::Attribute::To), "0/100"))); - if (d->getElName(Report::Element::Dates) == c.tagName()) { - QDate from, to; - if (c.hasAttribute(d->getAttrName(Report::Attribute::From))) - from = QDate::fromString(c.attribute(d->getAttrName(Report::Attribute::From)), Qt::ISODate); - if (c.hasAttribute(d->getAttrName(Report::Attribute::To))) - to = QDate::fromString(c.attribute(d->getAttrName(Report::Attribute::To)), Qt::ISODate); - MyMoneyTransactionFilter::setDateFilter(from, to); - } - if (d->getElName(Report::Element::Payee) == c.tagName()) - addPayee(c.attribute(d->getAttrName(Report::Attribute::ID))); - if (d->getElName(Report::Element::Tag) == c.tagName()) - addTag(c.attribute(d->getAttrName(Report::Attribute::ID))); - if (d->getElName(Report::Element::Category) == c.tagName() && c.hasAttribute(d->getAttrName(Report::Attribute::ID))) - addCategory(c.attribute(d->getAttrName(Report::Attribute::ID))); - if (d->getElName(Report::Element::Account) == c.tagName() && c.hasAttribute(d->getAttrName(Report::Attribute::ID))) - addAccount(c.attribute(d->getAttrName(Report::Attribute::ID))); - if (d->getElName(Report::Element::AccountGroup) == c.tagName() && c.hasAttribute(d->getAttrName(Report::Attribute::Group))) { - i = d->stringToAccountTypeAttribute(c.attribute(d->getAttrName(Report::Attribute::Group))); - if (i != -1) - addAccountGroup(static_cast(i)); - } - child = child.nextSibling(); - } - return true; -} - -void MyMoneyReport::writeXML(QDomDocument& document, QDomElement& parent) const -{ - QDomElement el = document.createElement(nodeNames[nnReport]); - write(el, &document, false); - parent.appendChild(el); -} - bool MyMoneyReport::hasReferenceTo(const QString& id) const { QStringList list; diff --git a/kmymoney/mymoney/mymoneyreport_p.h b/kmymoney/mymoney/mymoneyreport_p.h --- a/kmymoney/mymoney/mymoneyreport_p.h +++ b/kmymoney/mymoney/mymoneyreport_p.h @@ -40,46 +40,6 @@ #include "mymoneyobject_p.h" #include "mymoneyenums.h" -namespace Report -{ - enum class Element { Payee, - Tag, - Account, - Text, - Type, - State, - Number, - Amount, - Dates, - Category, - AccountGroup - }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { ID, Group, Type, Name, Comment, ConvertCurrency, Favorite, - SkipZero, DateLock, DataLock, MovingAverageDays, - IncludesActuals, IncludesForecast, IncludesPrice, - IncludesAveragePrice, IncludesMovingAverage, - IncludesSchedules, IncludesTransfers, IncludesUnused, - MixedTime, Investments, Budget, - ShowRowTotals, ShowColumnTotals, Detail, - ColumnsAreDays, ChartType, - ChartCHGridLines, ChartSVGridLines, - ChartDataLabels, ChartByDefault, - LogYAxis, ChartLineWidth, ColumnType, RowType, - DataRangeStart, DataRangeEnd, - DataMajorTick, DataMinorTick, - YLabelsPrecision, QueryColumns, - Tax, Loans, HideTransactions, InvestmentSum, - SettlementPeriod, ShowSTLTCapitalGains, TermsSeparator, - Pattern, CaseSensitive, RegEx, InvertText, State, - From, To, - // insert new entries above this line - LastAttribute - }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } -} - class MyMoneyReportPrivate : public MyMoneyObjectPrivate { public: @@ -133,378 +93,6 @@ { } - static QString getElName(const Report::Element el) - { - static const QHash elNames { - {Report::Element::Payee, QStringLiteral("PAYEE")}, - {Report::Element::Tag, QStringLiteral("TAG")}, - {Report::Element::Account, QStringLiteral("ACCOUNT")}, - {Report::Element::Text, QStringLiteral("TEXT")}, - {Report::Element::Type, QStringLiteral("TYPE")}, - {Report::Element::State, QStringLiteral("STATE")}, - {Report::Element::Number, QStringLiteral("NUMBER")}, - {Report::Element::Amount, QStringLiteral("AMOUNT")}, - {Report::Element::Dates, QStringLiteral("DATES")}, - {Report::Element::Category, QStringLiteral("CATEGORY")}, - {Report::Element::AccountGroup, QStringLiteral("ACCOUNTGROUP")} - }; - return elNames[el]; - } - - static QString getAttrName(const Report::Attribute attr) - { - static const QHash attrNames { - {Report::Attribute::ID, QStringLiteral("id")}, - {Report::Attribute::Group, QStringLiteral("group")}, - {Report::Attribute::Type, QStringLiteral("type")}, - {Report::Attribute::Name, QStringLiteral("name")}, - {Report::Attribute::Comment, QStringLiteral("comment")}, - {Report::Attribute::ConvertCurrency, QStringLiteral("convertcurrency")}, - {Report::Attribute::Favorite, QStringLiteral("favorite")}, - {Report::Attribute::SkipZero, QStringLiteral("skipZero")}, - {Report::Attribute::DateLock, QStringLiteral("datelock")}, - {Report::Attribute::DataLock, QStringLiteral("datalock")}, - {Report::Attribute::MovingAverageDays, QStringLiteral("movingaveragedays")}, - {Report::Attribute::IncludesActuals, QStringLiteral("includesactuals")}, - {Report::Attribute::IncludesForecast, QStringLiteral("includesforecast")}, - {Report::Attribute::IncludesPrice, QStringLiteral("includesprice")}, - {Report::Attribute::IncludesAveragePrice, QStringLiteral("includesaverageprice")}, - {Report::Attribute::IncludesMovingAverage, QStringLiteral("includesmovingaverage")}, - {Report::Attribute::IncludesSchedules, QStringLiteral("includeschedules")}, - {Report::Attribute::IncludesTransfers, QStringLiteral("includestransfers")}, - {Report::Attribute::IncludesUnused, QStringLiteral("includeunused")}, - {Report::Attribute::MixedTime, QStringLiteral("mixedtime")}, - {Report::Attribute::Investments, QStringLiteral("investments")}, - {Report::Attribute::Budget, QStringLiteral("budget")}, - {Report::Attribute::ShowRowTotals, QStringLiteral("showrowtotals")}, - {Report::Attribute::ShowColumnTotals, QStringLiteral("showcolumntotals")}, - {Report::Attribute::Detail, QStringLiteral("detail")}, - {Report::Attribute::ColumnsAreDays, QStringLiteral("columnsaredays")}, - {Report::Attribute::ChartType, QStringLiteral("charttype")}, - {Report::Attribute::ChartCHGridLines, QStringLiteral("chartchgridlines")}, - {Report::Attribute::ChartSVGridLines, QStringLiteral("chartsvgridlines")}, - {Report::Attribute::ChartDataLabels, QStringLiteral("chartdatalabels")}, - {Report::Attribute::ChartByDefault, QStringLiteral("chartbydefault")}, - {Report::Attribute::LogYAxis, QStringLiteral("logYaxis")}, - {Report::Attribute::ChartLineWidth, QStringLiteral("chartlinewidth")}, - {Report::Attribute::ColumnType, QStringLiteral("columntype")}, - {Report::Attribute::RowType, QStringLiteral("rowtype")}, - {Report::Attribute::DataRangeStart, QStringLiteral("dataRangeStart")}, - {Report::Attribute::DataRangeEnd, QStringLiteral("dataRangeEnd")}, - {Report::Attribute::DataMajorTick, QStringLiteral("dataMajorTick")}, - {Report::Attribute::DataMinorTick, QStringLiteral("dataMinorTick")}, - {Report::Attribute::YLabelsPrecision, QStringLiteral("yLabelsPrecision")}, - {Report::Attribute::QueryColumns, QStringLiteral("querycolumns")}, - {Report::Attribute::Tax, QStringLiteral("tax")}, - {Report::Attribute::Loans, QStringLiteral("loans")}, - {Report::Attribute::HideTransactions, QStringLiteral("hidetransactions")}, - {Report::Attribute::InvestmentSum, QStringLiteral("investmentsum")}, - {Report::Attribute::SettlementPeriod, QStringLiteral("settlementperiod")}, - {Report::Attribute::ShowSTLTCapitalGains, QStringLiteral("showSTLTCapitalGains")}, - {Report::Attribute::TermsSeparator, QStringLiteral("tseparator")}, - {Report::Attribute::Pattern, QStringLiteral("pattern")}, - {Report::Attribute::CaseSensitive, QStringLiteral("casesensitive")}, - {Report::Attribute::RegEx, QStringLiteral("regex")}, - {Report::Attribute::InvertText, QStringLiteral("inverttext")}, - {Report::Attribute::State, QStringLiteral("state")}, - {Report::Attribute::From, QStringLiteral("from")}, - {Report::Attribute::To, QStringLiteral("to")} - }; - return attrNames[attr]; - } - - static QHash rowTypesLUT() - { - static const QHash lut { - {eMyMoney::Report::RowType::NoRows, QStringLiteral("none")}, - {eMyMoney::Report::RowType::AssetLiability, QStringLiteral("assetliability")}, - {eMyMoney::Report::RowType::ExpenseIncome, QStringLiteral("expenseincome")}, - {eMyMoney::Report::RowType::Category, QStringLiteral("category")}, - {eMyMoney::Report::RowType::TopCategory, QStringLiteral("topcategory")}, - {eMyMoney::Report::RowType::Account, QStringLiteral("account")}, - {eMyMoney::Report::RowType::Tag, QStringLiteral("tag")}, - {eMyMoney::Report::RowType::Payee, QStringLiteral("payee")}, - {eMyMoney::Report::RowType::Month, QStringLiteral("month")}, - {eMyMoney::Report::RowType::Week, QStringLiteral("week")}, - {eMyMoney::Report::RowType::TopAccount, QStringLiteral("topaccount")}, - {eMyMoney::Report::RowType::AccountByTopAccount, QStringLiteral("topaccount-account")}, - {eMyMoney::Report::RowType::EquityType, QStringLiteral("equitytype")}, - {eMyMoney::Report::RowType::AccountType, QStringLiteral("accounttype")}, - {eMyMoney::Report::RowType::Institution, QStringLiteral("institution")}, - {eMyMoney::Report::RowType::Budget, QStringLiteral("budget")}, - {eMyMoney::Report::RowType::BudgetActual, QStringLiteral("budgetactual")}, - {eMyMoney::Report::RowType::Schedule, QStringLiteral("schedule")}, - {eMyMoney::Report::RowType::AccountInfo, QStringLiteral("accountinfo")}, - {eMyMoney::Report::RowType::AccountLoanInfo, QStringLiteral("accountloaninfo")}, - {eMyMoney::Report::RowType::AccountReconcile, QStringLiteral("accountreconcile")}, - {eMyMoney::Report::RowType::CashFlow, QStringLiteral("cashflow")}, - }; - return lut; - } - - static QString reportNames(eMyMoney::Report::RowType textID) - { - return rowTypesLUT().value(textID); - } - - static eMyMoney::Report::RowType stringToRowType(const QString &text) - { - return rowTypesLUT().key(text, eMyMoney::Report::RowType::Invalid); - } - - static QHash columTypesLUT() - { - static const QHash lut { - {eMyMoney::Report::ColumnType::NoColumns, QStringLiteral("none")}, - {eMyMoney::Report::ColumnType::Months, QStringLiteral("months")}, - {eMyMoney::Report::ColumnType::BiMonths, QStringLiteral("bimonths")}, - {eMyMoney::Report::ColumnType::Quarters, QStringLiteral("quarters")}, -// {eMyMoney::Report::ColumnType::, QStringLiteral("4")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("5")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("6")} - {eMyMoney::Report::ColumnType::Weeks, QStringLiteral("weeks")}, -// {eMyMoney::Report::ColumnType::, QStringLiteral("8")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("9")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("10")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("11")} - {eMyMoney::Report::ColumnType::Years, QStringLiteral("years")} - }; - return lut; - } - - static QString reportNames(eMyMoney::Report::ColumnType textID) - { - return columTypesLUT().value(textID); - } - - static eMyMoney::Report::ColumnType stringToColumnType(const QString &text) - { - return columTypesLUT().key(text, eMyMoney::Report::ColumnType::Invalid); - } - - static QHash queryColumnsLUT() - { - static const QHash lut { - {eMyMoney::Report::QueryColumn::None, QStringLiteral("none")}, - {eMyMoney::Report::QueryColumn::Number, QStringLiteral("number")}, - {eMyMoney::Report::QueryColumn::Payee, QStringLiteral("payee")}, - {eMyMoney::Report::QueryColumn::Category, QStringLiteral("category")}, - {eMyMoney::Report::QueryColumn::Tag, QStringLiteral("tag")}, - {eMyMoney::Report::QueryColumn::Memo, QStringLiteral("memo")}, - {eMyMoney::Report::QueryColumn::Account, QStringLiteral("account")}, - {eMyMoney::Report::QueryColumn::Reconciled, QStringLiteral("reconcileflag")}, - {eMyMoney::Report::QueryColumn::Action, QStringLiteral("action")}, - {eMyMoney::Report::QueryColumn::Shares, QStringLiteral("shares")}, - {eMyMoney::Report::QueryColumn::Price, QStringLiteral("price")}, - {eMyMoney::Report::QueryColumn::Performance, QStringLiteral("performance")}, - {eMyMoney::Report::QueryColumn::Loan, QStringLiteral("loan")}, - {eMyMoney::Report::QueryColumn::Balance, QStringLiteral("balance")}, - {eMyMoney::Report::QueryColumn::CapitalGain, QStringLiteral("capitalgain")} - }; - return lut; - } - - static QString reportNamesForQC(eMyMoney::Report::QueryColumn textID) - { - return queryColumnsLUT().value(textID); - } - - static eMyMoney::Report::QueryColumn stringToQueryColumn(const QString &text) - { - return queryColumnsLUT().key(text, eMyMoney::Report::QueryColumn::End); - } - - static QHash detailLevelLUT() - { - static const QHash lut { - {eMyMoney::Report::DetailLevel::None, QStringLiteral("none")}, - {eMyMoney::Report::DetailLevel::All, QStringLiteral("all")}, - {eMyMoney::Report::DetailLevel::Top, QStringLiteral("top")}, - {eMyMoney::Report::DetailLevel::Group, QStringLiteral("group")}, - {eMyMoney::Report::DetailLevel::Total, QStringLiteral("total")}, - {eMyMoney::Report::DetailLevel::End, QStringLiteral("invalid")} - }; - return lut; - } - - static QString reportNames(eMyMoney::Report::DetailLevel textID) - { - return detailLevelLUT().value(textID); - } - - static eMyMoney::Report::DetailLevel stringToDetailLevel(const QString &text) - { - return detailLevelLUT().key(text, eMyMoney::Report::DetailLevel::End); - } - - static QHash chartTypeLUT() - { - static const QHash lut { - {eMyMoney::Report::ChartType::None, QStringLiteral("none")}, - {eMyMoney::Report::ChartType::Line, QStringLiteral("line")}, - {eMyMoney::Report::ChartType::Bar, QStringLiteral("bar")}, - {eMyMoney::Report::ChartType::Pie, QStringLiteral("pie")}, - {eMyMoney::Report::ChartType::Ring, QStringLiteral("ring")}, - {eMyMoney::Report::ChartType::StackedBar, QStringLiteral("stackedbar")} - }; - return lut; - } - - static QString reportNames(eMyMoney::Report::ChartType textID) - { - return chartTypeLUT().value(textID); - } - - static eMyMoney::Report::ChartType stringToChartType(const QString &text) - { - return chartTypeLUT().key(text, eMyMoney::Report::ChartType::End); - } - - static QHash typeAttributeLUT() - { - static const QHash lut { - {0, QStringLiteral("all")}, - {1, QStringLiteral("payments")}, - {2, QStringLiteral("deposits")}, - {3, QStringLiteral("transfers")}, - {4, QStringLiteral("none")}, - }; - return lut; - } - - static QString typeAttributeToString(int textID) - { - return typeAttributeLUT().value(textID); - } - - static int stringToTypeAttribute(const QString &text) - { - return typeAttributeLUT().key(text, 4); - } - - static QHash stateAttributeLUT() - { - static const QHash lut { - {0, QStringLiteral("all")}, - {1, QStringLiteral("notreconciled")}, - {2, QStringLiteral("cleared")}, - {3, QStringLiteral("reconciled")}, - {4, QStringLiteral("frozen")}, - {5, QStringLiteral("none")} - }; - return lut; - } - - static QString stateAttributeToString(int textID) - { - return stateAttributeLUT().value(textID); - } - - static int stringToStateAttribute(const QString &text) - { - return stateAttributeLUT().key(text, 5); - } - - static QHash dateLockLUT() - { - static const QHash lut { - {0, QStringLiteral("alldates")}, - {1, QStringLiteral("untiltoday")}, - {2, QStringLiteral("currentmonth")}, - {3, QStringLiteral("currentyear")}, - {4, QStringLiteral("monthtodate")}, - {5, QStringLiteral("yeartodate")}, - {6, QStringLiteral("yeartomonth")}, - {7, QStringLiteral("lastmonth")}, - {8, QStringLiteral("lastyear")}, - {9, QStringLiteral("last7days")}, - {10, QStringLiteral("last30days")}, - {11, QStringLiteral("last3months")}, - {12, QStringLiteral("last6months")}, - {13, QStringLiteral("last12months")}, - {14, QStringLiteral("next7days")}, - {15, QStringLiteral("next30days")}, - {16, QStringLiteral("next3months")}, - {17, QStringLiteral("next6months")}, - {18, QStringLiteral("next12months")}, - {19, QStringLiteral("userdefined")}, - {20, QStringLiteral("last3tonext3months")}, - {21, QStringLiteral("last11Months")}, - {22, QStringLiteral("currentQuarter")}, - {23, QStringLiteral("lastQuarter")}, - {24, QStringLiteral("nextQuarter")}, - {25, QStringLiteral("currentFiscalYear")}, - {26, QStringLiteral("lastFiscalYear")}, - {27, QStringLiteral("today")}, - {28, QStringLiteral("next18months")} - }; - return lut; - } - - static QString dateLockAttributeToString(int textID) - { - return dateLockLUT().value(textID); - } - - static int stringToDateLockAttribute(const QString &text) - { - return dateLockLUT().key(text, 0); - } - - static QHash dataLockLUT() - { - static const QHash lut { - {eMyMoney::Report::DataLock::Automatic, QStringLiteral("automatic")}, - {eMyMoney::Report::DataLock::UserDefined, QStringLiteral("userdefined")} - }; - return lut; - } - - static QString reportNames(eMyMoney::Report::DataLock textID) - { - return dataLockLUT().value(textID); - } - - static eMyMoney::Report::DataLock stringToDataLockAttribute(const QString &text) - { - return dataLockLUT().key(text, eMyMoney::Report::DataLock::DataOptionCount); - } - - static QHash accountTypeAttributeLUT() - { - static const QHash lut { - {0, QStringLiteral("unknown")}, - {1, QStringLiteral("checkings")}, - {2, QStringLiteral("savings")}, - {3, QStringLiteral("cash")}, - {4, QStringLiteral("creditcard")}, - {5, QStringLiteral("loan")}, - {6, QStringLiteral("certificatedep")}, - {7, QStringLiteral("investment")}, - {8, QStringLiteral("moneymarket")}, - {10, QStringLiteral("asset")}, - {11, QStringLiteral("liability")}, - {12, QStringLiteral("currency")}, - {13, QStringLiteral("income")}, - {14, QStringLiteral("expense")}, - {15, QStringLiteral("assetloan")}, - {16, QStringLiteral("stock")}, - {17, QStringLiteral("equity")}, - {18, QStringLiteral("invalid")} - }; - return lut; - } - - static QString accountTypeAttributeToString(int textID) - { - return accountTypeAttributeLUT().value(textID); - } - - static int stringToAccountTypeAttribute(const QString &text) - { - return accountTypeAttributeLUT().key(text, 0); - } - static eMyMoney::Report::ReportType rowTypeToReportType(eMyMoney::Report::RowType rowType) { static const QHash reportTypes { diff --git a/kmymoney/mymoney/mymoneyschedule.cpp b/kmymoney/mymoney/mymoneyschedule.cpp --- a/kmymoney/mymoney/mymoneyschedule.cpp +++ b/kmymoney/mymoney/mymoneyschedule.cpp @@ -40,9 +40,7 @@ #include "mymoneyaccount.h" #include "mymoneysplit.h" #include "imymoneyprocessingcalendar.h" -#include "mymoneystoragenames.h" -using namespace MyMoneyStorageNodes; using namespace eMyMoney; static IMyMoneyProcessingCalendar* processingCalendarPtr = 0; diff --git a/kmymoney/mymoney/mymoneysecurity.cpp b/kmymoney/mymoney/mymoneysecurity.cpp --- a/kmymoney/mymoney/mymoneysecurity.cpp +++ b/kmymoney/mymoney/mymoneysecurity.cpp @@ -33,10 +33,8 @@ // Project Includes #include "mymoneyexception.h" -#include "mymoneystoragenames.h" using namespace eMyMoney; -using namespace MyMoneyStorageNodes; MyMoneySecurity::MyMoneySecurity() : MyMoneyObject(*new MyMoneySecurityPrivate) diff --git a/kmymoney/mymoney/mymoneytag.cpp b/kmymoney/mymoney/mymoneytag.cpp --- a/kmymoney/mymoney/mymoneytag.cpp +++ b/kmymoney/mymoney/mymoneytag.cpp @@ -26,9 +26,6 @@ // Project Includes #include "mymoneyexception.h" -#include "mymoneystoragenames.h" - -using namespace MyMoneyStorageNodes; MyMoneyTag MyMoneyTag::null; diff --git a/kmymoney/mymoney/mymoneytransaction.cpp b/kmymoney/mymoney/mymoneytransaction.cpp --- a/kmymoney/mymoney/mymoneytransaction.cpp +++ b/kmymoney/mymoney/mymoneytransaction.cpp @@ -32,14 +32,11 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "mymoneystoragenames.h" #include "mymoneyutils.h" #include "mymoneymoney.h" #include "mymoneyexception.h" #include "mymoneyenums.h" -using namespace MyMoneyStorageNodes; - MyMoneyTransaction::MyMoneyTransaction() : MyMoneyObject(*new MyMoneyTransactionPrivate) { diff --git a/kmymoney/mymoney/onlinejob.cpp b/kmymoney/mymoney/onlinejob.cpp --- a/kmymoney/mymoney/onlinejob.cpp +++ b/kmymoney/mymoney/onlinejob.cpp @@ -23,9 +23,6 @@ #include "tasks/onlinetask.h" #include "onlinejobadministration.h" -#include "mymoneystoragenames.h" - -using namespace MyMoneyStorageNodes; onlineJob::onlineJob() : MyMoneyObject(*new onlineJobPrivate), diff --git a/kmymoney/mymoney/storage/mymoneystoragemgr.h b/kmymoney/mymoney/storage/mymoneystoragemgr.h --- a/kmymoney/mymoney/storage/mymoneystoragemgr.h +++ b/kmymoney/mymoney/storage/mymoneystoragemgr.h @@ -149,11 +149,11 @@ * @param id QString reference to one of the standard accounts. Possible * values are: * - * @li stdAccNames[stdAccLiability] - * @li stdAccNames[stdAccAsset] - * @li stdAccNames[stdAccExpense] - * @li stdAccNames[stdAccIncome] - * @li stdAccNames[stdAccEquity] + * @li MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability) + * @li MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset) + * @li MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense) + * @li MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income) + * @li MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity) * * @param name QString reference to the name to be set * diff --git a/kmymoney/mymoney/storage/mymoneystoragemgr.cpp b/kmymoney/mymoney/storage/mymoneystoragemgr.cpp --- a/kmymoney/mymoney/storage/mymoneystoragemgr.cpp +++ b/kmymoney/mymoney/storage/mymoneystoragemgr.cpp @@ -105,11 +105,11 @@ bool MyMoneyStorageMgr::isStandardAccount(const QString& id) const { - return id == stdAccNames[stdAccLiability] - || id == stdAccNames[stdAccAsset] - || id == stdAccNames[stdAccExpense] - || id == stdAccNames[stdAccIncome] - || id == stdAccNames[stdAccEquity]; + return id == MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability) + || id == MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset) + || id == MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense) + || id == MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income) + || id == MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity); } void MyMoneyStorageMgr::setAccountName(const QString& id, const QString& name) @@ -970,23 +970,23 @@ } MyMoneyAccount MyMoneyStorageMgr::liability() const { - return account(stdAccNames[stdAccLiability]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability)); } MyMoneyAccount MyMoneyStorageMgr::asset() const { - return account(stdAccNames[stdAccAsset]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)); } MyMoneyAccount MyMoneyStorageMgr::expense() const { - return account(stdAccNames[stdAccExpense]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)); } MyMoneyAccount MyMoneyStorageMgr::income() const { - return account(stdAccNames[stdAccIncome]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income)); } MyMoneyAccount MyMoneyStorageMgr::equity() const { - return account(stdAccNames[stdAccEquity]); + return account(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity)); } void MyMoneyStorageMgr::loadAccounts(const QMap& map) diff --git a/kmymoney/mymoney/storage/mymoneystoragemgr_p.h b/kmymoney/mymoney/storage/mymoneystoragemgr_p.h --- a/kmymoney/mymoney/storage/mymoneystoragemgr_p.h +++ b/kmymoney/mymoney/storage/mymoneystoragemgr_p.h @@ -58,9 +58,7 @@ #include "mymoneymap.h" #include "onlinejob.h" #include "mymoneyenums.h" -#include "mymoneystoragenames.h" -using namespace MyMoneyStandardAccounts; using namespace eStorage; const int INSTITUTION_ID_SIZE = 6; @@ -113,34 +111,34 @@ MyMoneyAccount acc_l; acc_l.setAccountType(eMyMoney::Account::Type::Liability); acc_l.setName("Liability"); - MyMoneyAccount liability(stdAccNames[stdAccLiability], acc_l); + MyMoneyAccount liability(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability), acc_l); MyMoneyAccount acc_a; acc_a.setAccountType(eMyMoney::Account::Type::Asset); acc_a.setName("Asset"); - MyMoneyAccount asset(stdAccNames[stdAccAsset], acc_a); + MyMoneyAccount asset(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset), acc_a); MyMoneyAccount acc_e; acc_e.setAccountType(eMyMoney::Account::Type::Expense); acc_e.setName("Expense"); - MyMoneyAccount expense(stdAccNames[stdAccExpense], acc_e); + MyMoneyAccount expense(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense), acc_e); MyMoneyAccount acc_i; acc_i.setAccountType(eMyMoney::Account::Type::Income); acc_i.setName("Income"); - MyMoneyAccount income(stdAccNames[stdAccIncome], acc_i); + MyMoneyAccount income(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income), acc_i); MyMoneyAccount acc_q; acc_q.setAccountType(eMyMoney::Account::Type::Equity); acc_q.setName("Equity"); - MyMoneyAccount equity(stdAccNames[stdAccEquity], acc_q); + MyMoneyAccount equity(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity), acc_q); QMap map; - map[stdAccNames[stdAccAsset]] = asset; - map[stdAccNames[stdAccLiability]] = liability; - map[stdAccNames[stdAccIncome]] = income; - map[stdAccNames[stdAccExpense]] = expense; - map[stdAccNames[stdAccEquity]] = equity; + map[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)] = asset; + map[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability)] = liability; + map[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income)] = income; + map[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)] = expense; + map[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity)] = equity; // load account list with initial accounts m_accountList = map; diff --git a/kmymoney/mymoney/storage/mymoneystoragenames.h b/kmymoney/mymoney/storage/mymoneystoragenames.h deleted file mode 100644 --- a/kmymoney/mymoney/storage/mymoneystoragenames.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2017-2018 Łukasz Wojniłowicz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef MYMONEYSTORAGENAMES_H -#define MYMONEYSTORAGENAMES_H - -#include "kmm_mymoney_export.h" - -// ---------------------------------------------------------------------------- -// QT Includes - -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -namespace MyMoneyStorageTags { - -enum tagNameE { tnInstitutions, tnPayees, tnCostCenters, - tnTags, tnAccounts, tnTransactions, - tnSchedules, tnSecurities, tnCurrencies, - tnPrices, tnReports, tnBudgets, tnOnlineJobs, - tnKMMFile, tnFileInfo, tnUser - }; - -extern const QHash tagNames; -} - -namespace MyMoneyStorageNodes { - -enum ndNameE { nnInstitution, nnPayee, nnCostCenter, - nnTag, nnAccount, nnTransaction, - nnScheduleTX, nnSecurity, nnCurrency, - nnPrice, nnPricePair, nnReport, nnBudget, nnOnlineJob, - nnKeyValuePairs, nnEquity - }; - -extern const QHash nodeNames; -} - -namespace MyMoneyStorageAttributes { - -enum attrNameE { anID, anDate, anCount, anFrom, anTo, - anSource, anKey, anValue, anPrice, - anName, anEmail, anCountry, anCity, - anZipCode, anStreet, anTelephone - }; - -extern const QHash attrNames; -} - -namespace MyMoneyStandardAccounts { - -enum idNameE { stdAccLiability, stdAccAsset, stdAccExpense, stdAccIncome, stdAccEquity }; - -extern const KMM_MYMONEY_EXPORT QHash stdAccNames; -} - -#endif diff --git a/kmymoney/mymoney/storage/mymoneystoragenames.cpp b/kmymoney/mymoney/storage/mymoneystoragenames.cpp deleted file mode 100644 --- a/kmymoney/mymoney/storage/mymoneystoragenames.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2017-2018 Łukasz Wojniłowicz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "mymoneystoragenames.h" - -namespace MyMoneyStorageTags { - -const QHash tagNames = { - {tnInstitutions, QStringLiteral("INSTITUTIONS")}, - {tnPayees, QStringLiteral("PAYEES")}, - {tnCostCenters, QStringLiteral("COSTCENTERS")}, - {tnTags, QStringLiteral("TAGS")}, - {tnAccounts, QStringLiteral("ACCOUNTS")}, - {tnTransactions, QStringLiteral("TRANSACTIONS")}, - {tnSchedules, QStringLiteral("SCHEDULES")}, - {tnSecurities, QStringLiteral("SECURITIES")}, - {tnCurrencies, QStringLiteral("CURRENCIES")}, - {tnPrices, QStringLiteral("PRICES")}, - {tnReports, QStringLiteral("REPORTS")}, - {tnBudgets, QStringLiteral("BUDGETS")}, - {tnOnlineJobs, QStringLiteral("ONLINEJOBS")}, - {tnKMMFile, QStringLiteral("KMYMONEY-FILE")}, - {tnFileInfo, QStringLiteral("FILEINFO")}, - {tnUser, QStringLiteral("USER")} -}; - -} - -namespace MyMoneyStorageNodes { - -const QHash nodeNames = { - {nnInstitution, QStringLiteral("INSTITUTION")}, - {nnPayee, QStringLiteral("PAYEE")}, - {nnCostCenter, QStringLiteral("COSTCENTER")}, - {nnTag, QStringLiteral("TAG")}, - {nnAccount, QStringLiteral("ACCOUNT")}, - {nnTransaction, QStringLiteral("TRANSACTION")}, - {nnScheduleTX, QStringLiteral("SCHEDULED_TX")}, - {nnSecurity, QStringLiteral("SECURITY")}, - {nnCurrency, QStringLiteral("CURRENCY")}, - {nnPrice, QStringLiteral("PRICE")}, - {nnPricePair, QStringLiteral("PRICEPAIR")}, - {nnReport, QStringLiteral("REPORT")}, - {nnBudget, QStringLiteral("BUDGET")}, - {nnOnlineJob, QStringLiteral("ONLINEJOB")}, - {nnKeyValuePairs, QStringLiteral("KEYVALUEPAIRS")}, - {nnEquity, QStringLiteral("EQUITY")}, -}; - -} - -namespace MyMoneyStorageAttributes { - -const QHash attrNames = { - {anID, QStringLiteral("id")}, - {anDate, QStringLiteral("date")}, - {anCount, QStringLiteral("count")}, - {anFrom, QStringLiteral("from")}, - {anTo, QStringLiteral("to")}, - {anSource, QStringLiteral("source")}, - {anKey, QStringLiteral("key")}, - {anValue, QStringLiteral("value")}, - {anPrice, QStringLiteral("price")}, - {anName, QStringLiteral("name")}, - {anEmail, QStringLiteral("email")}, - {anCountry, QStringLiteral("county")}, - {anCity, QStringLiteral("city")}, - {anZipCode, QStringLiteral("zipcode")}, - {anStreet, QStringLiteral("street")}, - {anTelephone, QStringLiteral("telephone")} -}; - -} - -namespace MyMoneyStandardAccounts { - - // definitions for the ID's of the standard accounts - const QHash stdAccNames { - {stdAccLiability, QStringLiteral("AStd::Liability")}, - {stdAccAsset, QStringLiteral("AStd::Asset")}, - {stdAccExpense, QStringLiteral("AStd::Expense")}, - {stdAccIncome, QStringLiteral("AStd::Income")}, - {stdAccEquity, QStringLiteral("AStd::Equity")}, - }; - -} diff --git a/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp b/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp --- a/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp +++ b/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp @@ -43,10 +43,8 @@ #include "onlinetasks/dummy/tasks/dummytask.h" #include "mymoneyenums.h" -#include "mymoneystoragenames.h" using namespace eMyMoney; -using namespace MyMoneyStandardAccounts; QTEST_GUILESS_MAIN(MyMoneyStorageMgrTest) @@ -192,10 +190,10 @@ void MyMoneyStorageMgrTest::testIsStandardAccount() { - QCOMPARE(m->isStandardAccount(stdAccNames[stdAccLiability]), true); - QCOMPARE(m->isStandardAccount(stdAccNames[stdAccAsset]), true); - QCOMPARE(m->isStandardAccount(stdAccNames[stdAccExpense]), true); - QCOMPARE(m->isStandardAccount(stdAccNames[stdAccIncome]), true); + QCOMPARE(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability)), true); + QCOMPARE(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)), true); + QCOMPARE(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)), true); + QCOMPARE(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income)), true); QCOMPARE(m->isStandardAccount("A0002"), false); } @@ -276,13 +274,13 @@ // now try to add account 1 as sub-account to account 2 a = m->account("A000001"); try { - QCOMPARE(m->d_func()->m_accountList[stdAccNames[stdAccAsset]].accountList().count(), 0); + QCOMPARE(m->d_func()->m_accountList[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)].accountList().count(), 0); m->addAccount(b, a); m->commitTransaction(); m->startTransaction(); QCOMPARE(m->d_func()->m_accountList["A000002"].accountList()[0], QLatin1String("A000001")); QCOMPARE(m->d_func()->m_accountList["A000002"].accountList().count(), 1); - QCOMPARE(m->d_func()->m_accountList[stdAccNames[stdAccAsset]].accountList().count(), 0); + QCOMPARE(m->d_func()->m_accountList[MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)].accountList().count(), 0); QCOMPARE(m->dirty(), true); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); @@ -503,7 +501,7 @@ QCOMPARE(m->expense().accountCount(), 3); QCOMPARE(m->account(ex1.id()).accountCount(), 1); - QCOMPARE(ex3.parentAccountId(), stdAccNames[stdAccExpense]); + QCOMPARE(ex3.parentAccountId(), MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)); m->reparentAccount(ex3, ex1); QCOMPARE(m->expense().accountCount(), 2); @@ -914,22 +912,22 @@ void MyMoneyStorageMgrTest::testSetAccountName() { try { - m->setAccountName(stdAccNames[stdAccLiability], "Verbindlichkeiten"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability), "Verbindlichkeiten"); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } try { - m->setAccountName(stdAccNames[stdAccAsset], QString("Vermögen")); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset), QString("Vermögen")); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } try { - m->setAccountName(stdAccNames[stdAccExpense], "Ausgaben"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense), "Ausgaben"); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } try { - m->setAccountName(stdAccNames[stdAccIncome], "Einnahmen"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income), "Einnahmen"); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } diff --git a/kmymoney/mymoney/tests/mymoneyfile-test.cpp b/kmymoney/mymoney/tests/mymoneyfile-test.cpp --- a/kmymoney/mymoney/tests/mymoneyfile-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyfile-test.cpp @@ -43,9 +43,6 @@ #include "payeeidentifier/payeeidentifierloader.h" #include "payeeidentifiertyped.h" -#include "mymoneystoragenames.h" -using namespace MyMoneyStandardAccounts; - QTEST_GUILESS_MAIN(MyMoneyFileTest) MyMoneyFileTest::MyMoneyFileTest() : @@ -1373,7 +1370,7 @@ MyMoneyFileTransaction ft; clearObjectLists(); try { - m->setAccountName(stdAccNames[stdAccLiability], "Verbindlichkeiten"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability), "Verbindlichkeiten"); ft.commit(); QCOMPARE(m_objectsRemoved.count(), 0); QCOMPARE(m_objectsModified.count(), 1); @@ -1388,7 +1385,7 @@ ft.restart(); clearObjectLists(); try { - m->setAccountName(stdAccNames[stdAccAsset], QString::fromUtf8("Vermögen")); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset), QString::fromUtf8("Vermögen")); ft.commit(); QCOMPARE(m_objectsRemoved.count(), 0); QCOMPARE(m_objectsModified.count(), 1); @@ -1403,7 +1400,7 @@ ft.restart(); clearObjectLists(); try { - m->setAccountName(stdAccNames[stdAccExpense], "Ausgaben"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense), "Ausgaben"); ft.commit(); QCOMPARE(m_objectsRemoved.count(), 0); QCOMPARE(m_objectsModified.count(), 1); @@ -1418,7 +1415,7 @@ ft.restart(); clearObjectLists(); try { - m->setAccountName(stdAccNames[stdAccIncome], "Einnahmen"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income), "Einnahmen"); ft.commit(); QCOMPARE(m_objectsRemoved.count(), 0); QCOMPARE(m_objectsModified.count(), 1); @@ -1578,7 +1575,7 @@ split1.setAccountId("A000001"); split1.setShares(MyMoneyMoney(-1000, 100)); split1.setValue(MyMoneyMoney(-1000, 100)); - split2.setAccountId(stdAccNames[stdAccExpense]); + split2.setAccountId(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)); split2.setValue(MyMoneyMoney(1000, 100)); split2.setShares(MyMoneyMoney(1000, 100)); try { diff --git a/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.h b/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.h --- a/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.h +++ b/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.h @@ -40,10 +40,6 @@ void testLoadList(); void testArrayRead(); void testArrayWrite(); - void testWriteXML(); - void testReadXML(); - void testElementNames(); - void testAttributeNames(); }; #endif diff --git a/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.cpp b/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.cpp --- a/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.cpp +++ b/kmymoney/mymoney/tests/mymoneykeyvaluecontainer-test.cpp @@ -18,8 +18,6 @@ #include "mymoneykeyvaluecontainer-test.h" #include -#include -#include #define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyKeyValueContainerTest; @@ -107,96 +105,6 @@ QVERIFY(m->d_func()->m_kvp["key"] == "value"); } -void MyMoneyKeyValueContainerTest::testWriteXML() -{ - m->setValue("Key", "Value"); - m->setValue("key", "value"); - - QDomDocument doc("TEST"); - QDomElement el = doc.createElement("KVP-CONTAINER"); - doc.appendChild(el); - m->writeXML(doc, el); - - QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); - QDomElement kvpContainer = doc.documentElement(); - QCOMPARE(kvpContainer.tagName(), QLatin1String("KVP-CONTAINER")); - QCOMPARE(kvpContainer.childNodes().size(), 1); - - QVERIFY(kvpContainer.childNodes().at(0).isElement()); - QDomElement keyValuePairs = kvpContainer.childNodes().at(0).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("key")); - QCOMPARE(keyValuePair2.attribute("value"), QLatin1String("value")); - QCOMPARE(keyValuePair2.childNodes().size(), 0); -} - -void MyMoneyKeyValueContainerTest::testReadXML() -{ - m->setValue("Key", "Value"); - m->setValue("key", "value"); - - QString ref_ok( - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - "\n"); - - QString ref_false( - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - "\n"); - - - QDomDocument doc; - QDomElement node; - doc.setContent(ref_false); - node = doc.documentElement().firstChild().toElement(); - - // make sure, an empty node does not trigger an exception - try { - QDomElement e; - MyMoneyKeyValueContainer k(e); - } catch (const MyMoneyException &) { - QFAIL("Unexpected exception"); - } - - try { - MyMoneyKeyValueContainer k(node); - QFAIL("Missing expected exception"); - } catch (const MyMoneyException &) { - } - - doc.setContent(ref_ok); - node = doc.documentElement().firstChild().toElement(); - try { - MyMoneyKeyValueContainer k(node); - QVERIFY(k.d_func()->m_kvp.count() == 2); - QVERIFY(k.value("key") == "Value"); - QVERIFY(k.value("Key") == "value"); - } catch (const MyMoneyException &) { - QFAIL("Unexpected exception"); - } -} - void MyMoneyKeyValueContainerTest::testArrayRead() { MyMoneyKeyValueContainer kvp; @@ -215,23 +123,3 @@ QVERIFY(kvp.pairs().count() == 1); QVERIFY(kvp.value("Key") == "Value"); } - -void MyMoneyKeyValueContainerTest::testElementNames() -{ - for (auto i = (int)KVC::Element::Pair; i <= (int)KVC::Element::Pair; ++i) { - auto isEmpty = MyMoneyKeyValueContainerPrivate::getElName(static_cast(i)).isEmpty(); - if (isEmpty) - qWarning() << "Empty element's name " << i; - QVERIFY(!isEmpty); - } -} - -void MyMoneyKeyValueContainerTest::testAttributeNames() -{ - for (auto i = (int)KVC::Attribute::Key; i < (int)KVC::Attribute::LastAttribute; ++i) { - auto isEmpty = MyMoneyKeyValueContainerPrivate::getAttrName(static_cast(i)).isEmpty(); - if (isEmpty) - qWarning() << "Empty attribute's name " << i; - QVERIFY(!isEmpty); - } -} diff --git a/kmymoney/mymoney/tests/mymoneyobject-test.h b/kmymoney/mymoney/tests/mymoneyobject-test.h --- a/kmymoney/mymoney/tests/mymoneyobject-test.h +++ b/kmymoney/mymoney/tests/mymoneyobject-test.h @@ -32,7 +32,6 @@ void testCopyConstructor(); void testAssignmentConstructor(); void testEquality(); - void testReadXML(); }; #endif diff --git a/kmymoney/mymoney/tests/mymoneyobject-test.cpp b/kmymoney/mymoney/tests/mymoneyobject-test.cpp --- a/kmymoney/mymoney/tests/mymoneyobject-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyobject-test.cpp @@ -25,41 +25,6 @@ #include "mymoneyexception.h" #include "mymoneyaccount.h" -class TestMyMoneyObjectPrivate : public MyMoneyObjectPrivate -{ -public: - TestMyMoneyObjectPrivate() - { - } -}; -class TestMyMoneyObject : public MyMoneyObject -{ - Q_DECLARE_PRIVATE(TestMyMoneyObject) -public: - TestMyMoneyObject() : MyMoneyObject(*new MyMoneyObjectPrivate) {} - TestMyMoneyObject & operator=(TestMyMoneyObject other); - friend void swap(TestMyMoneyObject& first, TestMyMoneyObject& second); - ~TestMyMoneyObject(){} - TestMyMoneyObject(const QDomElement& node, const bool forceId = true) : - MyMoneyObject(*new MyMoneyObjectPrivate, node, forceId) {} - bool hasReferenceTo(const QString&) const final override { - return false; - } - void writeXML(QDomDocument&, QDomElement&) const final override {} -}; - -void swap(TestMyMoneyObject& first, TestMyMoneyObject& second) -{ - using std::swap; - swap(first.d_ptr, second.d_ptr); -} - -TestMyMoneyObject & TestMyMoneyObject::operator=(TestMyMoneyObject other) -{ - swap(*this, other); - return *this; -} - QTEST_GUILESS_MAIN(MyMoneyObjectTest) void MyMoneyObjectTest::testEmptyConstructor() @@ -110,77 +75,3 @@ QVERIFY(a.MyMoneyObject::operator==(b)); QVERIFY(!(a.MyMoneyObject::operator==(c))); } - -void MyMoneyObjectTest::testReadXML() -{ - TestMyMoneyObject t; - - QString ref_ok = QString( - "\n" - "\n" - " \n" - " \n" - "\n" - ); - - QString ref_false1 = QString( - "\n" - "\n" - " \n" - " \n" - "\n" - ); - - QString ref_false2 = QString( - "\n" - "\n" - " \n" - " \n" - "\n" - ); - - QDomDocument doc; - QDomElement node; - - // id="" but required - doc.setContent(ref_false1); - node = doc.documentElement().firstChild().toElement(); - - try { - t = TestMyMoneyObject(node); - QFAIL("Missing expected exception"); - } catch (const MyMoneyException &) { - } - - // id attribute missing but required - doc.setContent(ref_false2); - node = doc.documentElement().firstChild().toElement(); - - try { - t = TestMyMoneyObject(node); - QFAIL("Missing expected exception"); - } catch (const MyMoneyException &) { - } - - // id present - doc.setContent(ref_ok); - node = doc.documentElement().firstChild().toElement(); - - try { - t = TestMyMoneyObject(node); - QVERIFY(t.id() == "T000000000000000001"); - } catch (const MyMoneyException &) { - QFAIL("Unexpected exception"); - } - - // id="" but not required - doc.setContent(ref_false1); - node = doc.documentElement().firstChild().toElement(); - - try { - t = TestMyMoneyObject(node, false); - QVERIFY(t.id().isEmpty()); - } catch (const MyMoneyException &) { - QFAIL("Unexpected exception"); - } -} diff --git a/kmymoney/plugins/CMakeLists.txt b/kmymoney/plugins/CMakeLists.txt --- a/kmymoney/plugins/CMakeLists.txt +++ b/kmymoney/plugins/CMakeLists.txt @@ -9,6 +9,10 @@ add_subdirectory( checkprinting ) add_subdirectory( views ) +if(ENABLE_SQLSTORAGE OR ENABLE_XMLSTORAGE) + add_subdirectory(xmlhelper) +endif() + if(ENABLE_SQLSTORAGE) add_subdirectory(sql) endif() diff --git a/kmymoney/plugins/sql/CMakeLists.txt b/kmymoney/plugins/sql/CMakeLists.txt --- a/kmymoney/plugins/sql/CMakeLists.txt +++ b/kmymoney/plugins/sql/CMakeLists.txt @@ -32,6 +32,7 @@ PRIVATE Qt5::Sql kmm_utils_platformtools + xmlstoragehelper ) install(FILES sqlstorage.rc diff --git a/kmymoney/plugins/sql/mymoneystoragesql.cpp b/kmymoney/plugins/sql/mymoneystoragesql.cpp --- a/kmymoney/plugins/sql/mymoneystoragesql.cpp +++ b/kmymoney/plugins/sql/mymoneystoragesql.cpp @@ -2531,10 +2531,8 @@ QDomNode child = dom.firstChild(); child = child.firstChild(); - MyMoneyReport report; - - if (report.read(child.toElement())) - rList[report.id()] = report; + auto report = MyMoneyXmlContentHandler2::readReport(child.toElement()); + rList[report.id()] = report; d->signalProgress(++progress, 0); } @@ -2573,7 +2571,7 @@ QDomNode child = dom.firstChild(); child = child.firstChild(); - MyMoneyBudget budget(child.toElement()); + auto budget = MyMoneyXmlContentHandler2::readBudget(child.toElement()); budgets.insert(budget.id(), budget); d->signalProgress(++progress, 0); } diff --git a/kmymoney/plugins/sql/mymoneystoragesql_p.h b/kmymoney/plugins/sql/mymoneystoragesql_p.h --- a/kmymoney/plugins/sql/mymoneystoragesql_p.h +++ b/kmymoney/plugins/sql/mymoneystoragesql_p.h @@ -84,11 +84,10 @@ #include "payeeidentifier/ibanbic/ibanbic.h" #include "payeeidentifier/nationalaccount/nationalaccount.h" #include "onlinetasks/sepa/sepaonlinetransferimpl.h" +#include "xmlstoragehelper.h" #include "mymoneyenums.h" -#include "mymoneystoragenames.h" using namespace eMyMoney; -using namespace MyMoneyStandardAccounts; class FilterFail { @@ -438,27 +437,27 @@ MyMoneyAccount acc_l; acc_l.setAccountType(Account::Type::Liability); acc_l.setName("Liability"); - MyMoneyAccount liability(stdAccNames[stdAccLiability], acc_l); + MyMoneyAccount liability(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability), acc_l); MyMoneyAccount acc_a; acc_a.setAccountType(Account::Type::Asset); acc_a.setName("Asset"); - MyMoneyAccount asset(stdAccNames[stdAccAsset], acc_a); + MyMoneyAccount asset(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset), acc_a); MyMoneyAccount acc_e; acc_e.setAccountType(Account::Type::Expense); acc_e.setName("Expense"); - MyMoneyAccount expense(stdAccNames[stdAccExpense], acc_e); + MyMoneyAccount expense(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense), acc_e); MyMoneyAccount acc_i; acc_i.setAccountType(Account::Type::Income); acc_i.setName("Income"); - MyMoneyAccount income(stdAccNames[stdAccIncome], acc_i); + MyMoneyAccount income(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income), acc_i); MyMoneyAccount acc_q; acc_q.setAccountType(Account::Type::Equity); acc_q.setName("Equity"); - MyMoneyAccount equity(stdAccNames[stdAccEquity], acc_q); + MyMoneyAccount equity(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity), acc_q); QList stdList; stdList << asset; @@ -1454,7 +1453,7 @@ QDomDocument d; // create a dummy XML document QDomElement e = d.createElement("REPORTS"); d.appendChild(e); - rep.writeXML(d, e); // write the XML to document + MyMoneyXmlContentHandler2::writeReport(rep, d, e); // write the XML to document query.bindValue(":id", rep.id()); query.bindValue(":name", rep.name()); query.bindValue(":XML", d.toString()); @@ -1466,7 +1465,7 @@ QDomDocument d; // create a dummy XML document QDomElement e = d.createElement("BUDGETS"); d.appendChild(e); - bud.writeXML(d, e); // write the XML to document + MyMoneyXmlContentHandler2::writeBudget(bud, d, e); // write the XML to document query.bindValue(":id", bud.id()); query.bindValue(":name", bud.name()); query.bindValue(":start", bud.budgetStart()); diff --git a/kmymoney/plugins/sql/tests/CMakeLists.txt b/kmymoney/plugins/sql/tests/CMakeLists.txt --- a/kmymoney/plugins/sql/tests/CMakeLists.txt +++ b/kmymoney/plugins/sql/tests/CMakeLists.txt @@ -17,6 +17,7 @@ kmm_widgets kmm_utils_platformtools onlinetask_interfaces + xmlstoragehelper ) file(GLOB tests_sources "*-test.cpp") @@ -29,4 +30,5 @@ kmm_widgets kmm_utils_platformtools kmm_mymoney + xmlstoragehelper ) diff --git a/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp --- a/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp +++ b/kmymoney/plugins/sql/tests/mymoneydatabasemgr-test.cpp @@ -316,11 +316,11 @@ if (!m_canOpen) QSKIP("Database test skipped because no database could be opened.", SkipAll); - QVERIFY(m->isStandardAccount(stdAccNames[stdAccLiability]) == true); - QVERIFY(m->isStandardAccount(stdAccNames[stdAccAsset]) == true); - QVERIFY(m->isStandardAccount(stdAccNames[stdAccExpense]) == true); - QVERIFY(m->isStandardAccount(stdAccNames[stdAccIncome]) == true); - QVERIFY(m->isStandardAccount(stdAccNames[stdAccEquity]) == true); + QVERIFY(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability)) == true); + QVERIFY(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset)) == true); + QVERIFY(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)) == true); + QVERIFY(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income)) == true); + QVERIFY(m->isStandardAccount(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Equity)) == true); QVERIFY(m->isStandardAccount("A0002") == false); } @@ -683,7 +683,7 @@ // MyMoneyFile::instance()->preloadCache(); QVERIFY(m->expense().accountCount() == 3); QVERIFY(m->account(ex1.id()).accountCount() == 1); - QVERIFY(ex3.parentAccountId() == stdAccNames[stdAccExpense]); + QVERIFY(ex3.parentAccountId() == MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense)); //for (int i = 0; i < 100; ++i) { ft.restart(); @@ -1414,28 +1414,28 @@ try { MyMoneyFileTransaction ft; - m->setAccountName(stdAccNames[stdAccLiability], "Verbindlichkeiten"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Liability), "Verbindlichkeiten"); ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } try { MyMoneyFileTransaction ft; - m->setAccountName(stdAccNames[stdAccAsset], "Verm�gen"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Asset), "Verm�gen"); ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } try { MyMoneyFileTransaction ft; - m->setAccountName(stdAccNames[stdAccExpense], "Ausgaben"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Expense), "Ausgaben"); ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } try { MyMoneyFileTransaction ft; - m->setAccountName(stdAccNames[stdAccIncome], "Einnahmen"); + m->setAccountName(MyMoneyAccount::stdAccName(eMyMoney::Account::Standard::Income), "Einnahmen"); ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); diff --git a/kmymoney/plugins/xml/CMakeLists.txt b/kmymoney/plugins/xml/CMakeLists.txt --- a/kmymoney/plugins/xml/CMakeLists.txt +++ b/kmymoney/plugins/xml/CMakeLists.txt @@ -32,6 +32,7 @@ KF5::CoreAddons kgpgfile kmymoney_common + xmlstoragehelper ) # install(FILES kmymoney-xmlstorageplugin.desktop 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 @@ -26,56 +26,6 @@ // ---------------------------------------------------------------------------- // Project Includes -namespace MyMoneyStorageTags { - -enum tagNameE { tnInstitutions, tnPayees, tnCostCenters, - tnTags, tnAccounts, tnTransactions, - tnSchedules, tnSecurities, tnCurrencies, - tnPrices, tnReports, tnBudgets, tnOnlineJobs, - tnKMMFile, tnFileInfo, tnUser - }; - -extern const QHash tagNames; -} - -namespace MyMoneyStorageNodes { - -enum ndNameE { nnInstitution, nnPayee, nnCostCenter, - nnTag, nnAccount, nnTransaction, - nnScheduleTX, nnSecurity, nnCurrency, - nnPrice, nnPricePair, nnReport, nnBudget, nnOnlineJob, - nnKeyValuePairs, nnEquity - }; - -extern const QHash nodeNames; -} - -namespace MyMoneyStorageAttributes { - -enum attrNameE { anID, anDate, anCount, anFrom, anTo, - anSource, anKey, anValue, anPrice, - anName, anEmail, anCountry, anCity, - anZipCode, anStreet, anTelephone - }; - -extern const QHash attrNames; -} - -namespace MyMoneyStandardAccounts { - -enum idNameE { stdAccLiability, stdAccAsset, stdAccExpense, stdAccIncome, stdAccEquity }; - -extern const QHash stdAccNames; -} - -enum class StdAccName { - Liability, - Asset, - Expense, - Income, - Equity -}; - enum class Tag { Institutions, Payees, @@ -158,26 +108,6 @@ Address }; - enum class Report { - Payee, - Tag, - Account, - Text, - Type, - State, - Number, - Amount, - Dates, - Category, - AccountGroup - }; - - enum class Budget { - Budget = 0, - Account, - Period - }; - enum class Schedule { Payment, Payments @@ -328,41 +258,6 @@ LastAttribute }; - enum class Report { - ID = 0, Group, Type, Name, Comment, ConvertCurrency, Favorite, - SkipZero, DateLock, DataLock, MovingAverageDays, - IncludesActuals, IncludesForecast, IncludesPrice, - IncludesAveragePrice, IncludesMovingAverage, - IncludesSchedules, IncludesTransfers, IncludesUnused, - MixedTime, Investments, Budget, - ShowRowTotals, ShowColumnTotals, Detail, - ColumnsAreDays, ChartType, - ChartCHGridLines, ChartSVGridLines, - ChartDataLabels, ChartByDefault, - LogYAxis, ChartLineWidth, ColumnType, RowType, - DataRangeStart, DataRangeEnd, - DataMajorTick, DataMinorTick, - YLabelsPrecision, QueryColumns, - Tax, Loans, HideTransactions, InvestmentSum, - SettlementPeriod, ShowSTLTCapitalGains, TermsSeparator, - Pattern, CaseSensitive, RegEx, InvertText, State, - From, To, - // insert new entries above this line - LastAttribute - }; - - enum class Budget { - ID = 0, - Name, - Start, - Version, - BudgetLevel, - BudgetSubAccounts, - Amount, - // insert new entries above this line - LastAttribute - }; - enum class Schedule { ID = 0, Name, @@ -429,12 +324,6 @@ QString elementName(Element::Institution elementID); QString attributeName(Attribute::Institution attributeID); -QString elementName(Element::Report elementID); -QString attributeName(Attribute::Report attributeID); - -QString elementName(Element::Budget elementID); -QString attributeName(Attribute::Budget attributeID); - QString elementName(Element::Schedule elementID); QString attributeName(Attribute::Schedule attributeID); @@ -443,59 +332,7 @@ QString attributeName(Attribute::CostCenter attributeID); -QString stdAccName(StdAccName stdAccID); 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); -QHash columTypesLUT(); -QString reportNames(eMyMoney::Report::ColumnType textID); -eMyMoney::Report::ColumnType stringToColumnType(const QString &text); -QHash queryColumnsLUT(); -QString reportNamesForQC(eMyMoney::Report::QueryColumn textID); -eMyMoney::Report::QueryColumn stringToQueryColumn(const QString &text); -QHash detailLevelLUT(); -QString reportNames(eMyMoney::Report::DetailLevel textID); -eMyMoney::Report::DetailLevel stringToDetailLevel(const QString &text); -QHash chartTypeLUT(); -QString reportNames(eMyMoney::Report::ChartType textID); -eMyMoney::Report::ChartType stringToChartType(const QString &text); -QHash typeAttributeLUT(); -QString typeAttributeToString(int textID); -int stringToTypeAttribute(const QString &text); -QHash stateAttributeLUT(); -QString stateAttributeToString(int textID); -int stringToStateAttribute(const QString &text); -QHash dateLockLUT(); -QString dateLockAttributeToString(int textID); -int stringToDateLockAttribute(const QString &text); -QHash dataLockLUT(); -QString reportNames(eMyMoney::Report::DataLock textID); -eMyMoney::Report::DataLock stringToDataLockAttribute(const QString &text); -QHash accountTypeAttributeLUT(); -QString accountTypeAttributeToString(int textID); -int stringToAccountTypeAttribute(const QString &text); -eMyMoney::Report::ReportType rowTypeToReportType(eMyMoney::Report::RowType rowType); - -namespace eMyMoney { namespace Budget { enum class Level; } } - -QHash budgetLevelLUT(); -QString budgetNames(eMyMoney::Budget::Level textID); -eMyMoney::Budget::Level stringToBudgetLevel(const QString &text); - #endif 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 @@ -21,20 +21,6 @@ #include "mymoneyenums.h" -QString stdAccName(StdAccName stdAccID) -{ - static const QHash stdAccNames { - {StdAccName::Liability, QStringLiteral("AStd::Liability")}, - {StdAccName::Asset, QStringLiteral("AStd::Asset")}, - {StdAccName::Expense, QStringLiteral("AStd::Expense")}, - {StdAccName::Income, QStringLiteral("AStd::Income")}, - {StdAccName::Equity, QStringLiteral("AStd::Equity")}, - }; - return stdAccNames.value(stdAccID); -} - -uint qHash(const StdAccName key, uint seed) { return ::qHash(static_cast(key), seed); } - QString tagName(Tag tagID) { static const QHash tagNames { @@ -93,8 +79,6 @@ uint qHash(const Payee key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const KVP key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const Institution key, uint seed) { return ::qHash(static_cast(key), seed); } - uint qHash(const Report key, uint seed) { return ::qHash(static_cast(key), seed); } - uint qHash(const Budget key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const Schedule key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const OnlineJob key, uint seed) { return ::qHash(static_cast(key), seed); } } @@ -108,8 +92,6 @@ uint qHash(const Security key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const KVP key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const Institution key, uint seed) { return ::qHash(static_cast(key), seed); } - uint qHash(const Report key, uint seed) { return ::qHash(static_cast(key), seed); } - uint qHash(const Budget key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const Schedule key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const OnlineJob key, uint seed) { return ::qHash(static_cast(key), seed); } } @@ -339,110 +321,6 @@ return attributeNames.value(attributeID); } -QString elementName(Element::Report elementID) -{ - static const QMap elementNames { - {Element::Report::Payee, QStringLiteral("PAYEE")}, - {Element::Report::Tag, QStringLiteral("TAG")}, - {Element::Report::Account, QStringLiteral("ACCOUNT")}, - {Element::Report::Text, QStringLiteral("TEXT")}, - {Element::Report::Type, QStringLiteral("TYPE")}, - {Element::Report::State, QStringLiteral("STATE")}, - {Element::Report::Number, QStringLiteral("NUMBER")}, - {Element::Report::Amount, QStringLiteral("AMOUNT")}, - {Element::Report::Dates, QStringLiteral("DATES")}, - {Element::Report::Category, QStringLiteral("CATEGORY")}, - {Element::Report::AccountGroup, QStringLiteral("ACCOUNTGROUP")} - }; - return elementNames.value(elementID); -} - -QString attributeName(Attribute::Report attributeID) -{ - static const QMap attributeNames { - {Attribute::Report::ID, QStringLiteral("id")}, - {Attribute::Report::Group, QStringLiteral("group")}, - {Attribute::Report::Type, QStringLiteral("type")}, - {Attribute::Report::Name, QStringLiteral("name")}, - {Attribute::Report::Comment, QStringLiteral("comment")}, - {Attribute::Report::ConvertCurrency, QStringLiteral("convertcurrency")}, - {Attribute::Report::Favorite, QStringLiteral("favorite")}, - {Attribute::Report::SkipZero, QStringLiteral("skipZero")}, - {Attribute::Report::DateLock, QStringLiteral("datelock")}, - {Attribute::Report::DataLock, QStringLiteral("datalock")}, - {Attribute::Report::MovingAverageDays, QStringLiteral("movingaveragedays")}, - {Attribute::Report::IncludesActuals, QStringLiteral("includesactuals")}, - {Attribute::Report::IncludesForecast, QStringLiteral("includesforecast")}, - {Attribute::Report::IncludesPrice, QStringLiteral("includesprice")}, - {Attribute::Report::IncludesAveragePrice, QStringLiteral("includesaverageprice")}, - {Attribute::Report::IncludesMovingAverage, QStringLiteral("includesmovingaverage")}, - {Attribute::Report::IncludesSchedules, QStringLiteral("includeschedules")}, - {Attribute::Report::IncludesTransfers, QStringLiteral("includestransfers")}, - {Attribute::Report::IncludesUnused, QStringLiteral("includeunused")}, - {Attribute::Report::MixedTime, QStringLiteral("mixedtime")}, - {Attribute::Report::Investments, QStringLiteral("investments")}, - {Attribute::Report::Budget, QStringLiteral("budget")}, - {Attribute::Report::ShowRowTotals, QStringLiteral("showrowtotals")}, - {Attribute::Report::ShowColumnTotals, QStringLiteral("showcolumntotals")}, - {Attribute::Report::Detail, QStringLiteral("detail")}, - {Attribute::Report::ColumnsAreDays, QStringLiteral("columnsaredays")}, - {Attribute::Report::ChartType, QStringLiteral("charttype")}, - {Attribute::Report::ChartCHGridLines, QStringLiteral("chartchgridlines")}, - {Attribute::Report::ChartSVGridLines, QStringLiteral("chartsvgridlines")}, - {Attribute::Report::ChartDataLabels, QStringLiteral("chartdatalabels")}, - {Attribute::Report::ChartByDefault, QStringLiteral("chartbydefault")}, - {Attribute::Report::LogYAxis, QStringLiteral("logYaxis")}, - {Attribute::Report::ChartLineWidth, QStringLiteral("chartlinewidth")}, - {Attribute::Report::ColumnType, QStringLiteral("columntype")}, - {Attribute::Report::RowType, QStringLiteral("rowtype")}, - {Attribute::Report::DataRangeStart, QStringLiteral("dataRangeStart")}, - {Attribute::Report::DataRangeEnd, QStringLiteral("dataRangeEnd")}, - {Attribute::Report::DataMajorTick, QStringLiteral("dataMajorTick")}, - {Attribute::Report::DataMinorTick, QStringLiteral("dataMinorTick")}, - {Attribute::Report::YLabelsPrecision, QStringLiteral("yLabelsPrecision")}, - {Attribute::Report::QueryColumns, QStringLiteral("querycolumns")}, - {Attribute::Report::Tax, QStringLiteral("tax")}, - {Attribute::Report::Loans, QStringLiteral("loans")}, - {Attribute::Report::HideTransactions, QStringLiteral("hidetransactions")}, - {Attribute::Report::InvestmentSum, QStringLiteral("investmentsum")}, - {Attribute::Report::SettlementPeriod, QStringLiteral("settlementperiod")}, - {Attribute::Report::ShowSTLTCapitalGains, QStringLiteral("showSTLTCapitalGains")}, - {Attribute::Report::TermsSeparator, QStringLiteral("tseparator")}, - {Attribute::Report::Pattern, QStringLiteral("pattern")}, - {Attribute::Report::CaseSensitive, QStringLiteral("casesensitive")}, - {Attribute::Report::RegEx, QStringLiteral("regex")}, - {Attribute::Report::InvertText, QStringLiteral("inverttext")}, - {Attribute::Report::State, QStringLiteral("state")}, - {Attribute::Report::From, QStringLiteral("from")}, - {Attribute::Report::To, QStringLiteral("to")} - }; - return attributeNames.value(attributeID); -} - -QString elementName(Element::Budget elementID) -{ - static const QMap elementNames { - {Element::Budget::Budget, QStringLiteral("BUDGET")}, - {Element::Budget::Account, QStringLiteral("ACCOUNT")}, - {Element::Budget::Period, QStringLiteral("PERIOD")} - }; - return elementNames.value(elementID); -} - -QString attributeName(Attribute::Budget attributeID) -{ - static const QMap attributeNames { - {Attribute::Budget::ID, QStringLiteral("id")}, - {Attribute::Budget::Name, QStringLiteral("name")}, - {Attribute::Budget::Start, QStringLiteral("start")}, - {Attribute::Budget::Version, QStringLiteral("version")}, - {Attribute::Budget::BudgetLevel, QStringLiteral("budgetlevel")}, - {Attribute::Budget::BudgetSubAccounts, QStringLiteral("budgetsubaccounts")}, - {Attribute::Budget::Amount, QStringLiteral("amount")} - }; - return attributeNames.value(attributeID); -} - QString elementName(Element::Schedule elementID) { static const QMap elementNames { @@ -502,363 +380,3 @@ }; 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 { - {eMyMoney::Report::RowType::NoRows, QStringLiteral("none")}, - {eMyMoney::Report::RowType::AssetLiability, QStringLiteral("assetliability")}, - {eMyMoney::Report::RowType::ExpenseIncome, QStringLiteral("expenseincome")}, - {eMyMoney::Report::RowType::Category, QStringLiteral("category")}, - {eMyMoney::Report::RowType::TopCategory, QStringLiteral("topcategory")}, - {eMyMoney::Report::RowType::Account, QStringLiteral("account")}, - {eMyMoney::Report::RowType::Tag, QStringLiteral("tag")}, - {eMyMoney::Report::RowType::Payee, QStringLiteral("payee")}, - {eMyMoney::Report::RowType::Month, QStringLiteral("month")}, - {eMyMoney::Report::RowType::Week, QStringLiteral("week")}, - {eMyMoney::Report::RowType::TopAccount, QStringLiteral("topaccount")}, - {eMyMoney::Report::RowType::AccountByTopAccount, QStringLiteral("topaccount-account")}, - {eMyMoney::Report::RowType::EquityType, QStringLiteral("equitytype")}, - {eMyMoney::Report::RowType::AccountType, QStringLiteral("accounttype")}, - {eMyMoney::Report::RowType::Institution, QStringLiteral("institution")}, - {eMyMoney::Report::RowType::Budget, QStringLiteral("budget")}, - {eMyMoney::Report::RowType::BudgetActual, QStringLiteral("budgetactual")}, - {eMyMoney::Report::RowType::Schedule, QStringLiteral("schedule")}, - {eMyMoney::Report::RowType::AccountInfo, QStringLiteral("accountinfo")}, - {eMyMoney::Report::RowType::AccountLoanInfo, QStringLiteral("accountloaninfo")}, - {eMyMoney::Report::RowType::AccountReconcile, QStringLiteral("accountreconcile")}, - {eMyMoney::Report::RowType::CashFlow, QStringLiteral("cashflow")}, - }; - return lut; -} - -QString reportNames(eMyMoney::Report::RowType textID) -{ - return rowTypesLUT().value(textID); -} - -eMyMoney::Report::RowType stringToRowType(const QString &text) -{ - return rowTypesLUT().key(text, eMyMoney::Report::RowType::Invalid); -} - -QHash columTypesLUT() -{ - static const QHash lut { - {eMyMoney::Report::ColumnType::NoColumns, QStringLiteral("none")}, - {eMyMoney::Report::ColumnType::Months, QStringLiteral("months")}, - {eMyMoney::Report::ColumnType::BiMonths, QStringLiteral("bimonths")}, - {eMyMoney::Report::ColumnType::Quarters, QStringLiteral("quarters")}, -// {eMyMoney::Report::ColumnType::, QStringLiteral("4")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("5")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("6")} - {eMyMoney::Report::ColumnType::Weeks, QStringLiteral("weeks")}, -// {eMyMoney::Report::ColumnType::, QStringLiteral("8")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("9")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("10")} -// {eMyMoney::Report::ColumnType::, QStringLiteral("11")} - {eMyMoney::Report::ColumnType::Years, QStringLiteral("years")} - }; - return lut; -} - -QString reportNames(eMyMoney::Report::ColumnType textID) -{ - return columTypesLUT().value(textID); -} - -eMyMoney::Report::ColumnType stringToColumnType(const QString &text) -{ - return columTypesLUT().key(text, eMyMoney::Report::ColumnType::Invalid); -} - -QHash queryColumnsLUT() -{ - static const QHash lut { - {eMyMoney::Report::QueryColumn::None, QStringLiteral("none")}, - {eMyMoney::Report::QueryColumn::Number, QStringLiteral("number")}, - {eMyMoney::Report::QueryColumn::Payee, QStringLiteral("payee")}, - {eMyMoney::Report::QueryColumn::Category, QStringLiteral("category")}, - {eMyMoney::Report::QueryColumn::Tag, QStringLiteral("tag")}, - {eMyMoney::Report::QueryColumn::Memo, QStringLiteral("memo")}, - {eMyMoney::Report::QueryColumn::Account, QStringLiteral("account")}, - {eMyMoney::Report::QueryColumn::Reconciled, QStringLiteral("reconcileflag")}, - {eMyMoney::Report::QueryColumn::Action, QStringLiteral("action")}, - {eMyMoney::Report::QueryColumn::Shares, QStringLiteral("shares")}, - {eMyMoney::Report::QueryColumn::Price, QStringLiteral("price")}, - {eMyMoney::Report::QueryColumn::Performance, QStringLiteral("performance")}, - {eMyMoney::Report::QueryColumn::Loan, QStringLiteral("loan")}, - {eMyMoney::Report::QueryColumn::Balance, QStringLiteral("balance")}, - {eMyMoney::Report::QueryColumn::CapitalGain, QStringLiteral("capitalgain")} - }; - return lut; -} - -QString reportNamesForQC(eMyMoney::Report::QueryColumn textID) -{ - return queryColumnsLUT().value(textID); -} - -eMyMoney::Report::QueryColumn stringToQueryColumn(const QString &text) -{ - return queryColumnsLUT().key(text, eMyMoney::Report::QueryColumn::End); -} - -QHash detailLevelLUT() -{ - static const QHash lut { - {eMyMoney::Report::DetailLevel::None, QStringLiteral("none")}, - {eMyMoney::Report::DetailLevel::All, QStringLiteral("all")}, - {eMyMoney::Report::DetailLevel::Top, QStringLiteral("top")}, - {eMyMoney::Report::DetailLevel::Group, QStringLiteral("group")}, - {eMyMoney::Report::DetailLevel::Total, QStringLiteral("total")}, - {eMyMoney::Report::DetailLevel::End, QStringLiteral("invalid")} - }; - return lut; -} - -QString reportNames(eMyMoney::Report::DetailLevel textID) -{ - return detailLevelLUT().value(textID); -} - -eMyMoney::Report::DetailLevel stringToDetailLevel(const QString &text) -{ - return detailLevelLUT().key(text, eMyMoney::Report::DetailLevel::End); -} - -QHash chartTypeLUT() -{ - static const QHash lut { - {eMyMoney::Report::ChartType::None, QStringLiteral("none")}, - {eMyMoney::Report::ChartType::Line, QStringLiteral("line")}, - {eMyMoney::Report::ChartType::Bar, QStringLiteral("bar")}, - {eMyMoney::Report::ChartType::Pie, QStringLiteral("pie")}, - {eMyMoney::Report::ChartType::Ring, QStringLiteral("ring")}, - {eMyMoney::Report::ChartType::StackedBar, QStringLiteral("stackedbar")} - }; - return lut; -} - -QString reportNames(eMyMoney::Report::ChartType textID) -{ - return chartTypeLUT().value(textID); -} - -eMyMoney::Report::ChartType stringToChartType(const QString &text) -{ - return chartTypeLUT().key(text, eMyMoney::Report::ChartType::End); -} - -QHash typeAttributeLUT() -{ - static const QHash lut { - {0, QStringLiteral("all")}, - {1, QStringLiteral("payments")}, - {2, QStringLiteral("deposits")}, - {3, QStringLiteral("transfers")}, - {4, QStringLiteral("none")}, - }; - return lut; -} - -QString typeAttributeToString(int textID) -{ - return typeAttributeLUT().value(textID); -} - -int stringToTypeAttribute(const QString &text) -{ - return typeAttributeLUT().key(text, 4); -} - -QHash stateAttributeLUT() -{ - static const QHash lut { - {0, QStringLiteral("all")}, - {1, QStringLiteral("notreconciled")}, - {2, QStringLiteral("cleared")}, - {3, QStringLiteral("reconciled")}, - {4, QStringLiteral("frozen")}, - {5, QStringLiteral("none")} - }; - return lut; -} - -QString stateAttributeToString(int textID) -{ - return stateAttributeLUT().value(textID); -} - -int stringToStateAttribute(const QString &text) -{ - return stateAttributeLUT().key(text, 5); -} - -QHash dateLockLUT() -{ - static const QHash lut { - {0, QStringLiteral("alldates")}, - {1, QStringLiteral("untiltoday")}, - {2, QStringLiteral("currentmonth")}, - {3, QStringLiteral("currentyear")}, - {4, QStringLiteral("monthtodate")}, - {5, QStringLiteral("yeartodate")}, - {6, QStringLiteral("yeartomonth")}, - {7, QStringLiteral("lastmonth")}, - {8, QStringLiteral("lastyear")}, - {9, QStringLiteral("last7days")}, - {10, QStringLiteral("last30days")}, - {11, QStringLiteral("last3months")}, - {12, QStringLiteral("last6months")}, - {13, QStringLiteral("last12months")}, - {14, QStringLiteral("next7days")}, - {15, QStringLiteral("next30days")}, - {16, QStringLiteral("next3months")}, - {17, QStringLiteral("next6months")}, - {18, QStringLiteral("next12months")}, - {19, QStringLiteral("userdefined")}, - {20, QStringLiteral("last3tonext3months")}, - {21, QStringLiteral("last11Months")}, - {22, QStringLiteral("currentQuarter")}, - {23, QStringLiteral("lastQuarter")}, - {24, QStringLiteral("nextQuarter")}, - {25, QStringLiteral("currentFiscalYear")}, - {26, QStringLiteral("lastFiscalYear")}, - {27, QStringLiteral("today")}, - {28, QStringLiteral("next18months")} - }; - return lut; -} - -QString dateLockAttributeToString(int textID) -{ - return dateLockLUT().value(textID); -} - -int stringToDateLockAttribute(const QString &text) -{ - return dateLockLUT().key(text, 0); -} - -QHash dataLockLUT() -{ - static const QHash lut { - {eMyMoney::Report::DataLock::Automatic, QStringLiteral("automatic")}, - {eMyMoney::Report::DataLock::UserDefined, QStringLiteral("userdefined")} - }; - return lut; -} - -QString reportNames(eMyMoney::Report::DataLock textID) -{ - return dataLockLUT().value(textID); -} - -eMyMoney::Report::DataLock stringToDataLockAttribute(const QString &text) -{ - return dataLockLUT().key(text, eMyMoney::Report::DataLock::DataOptionCount); -} - -QHash accountTypeAttributeLUT() -{ - static const QHash lut { - {0, QStringLiteral("unknown")}, - {1, QStringLiteral("checkings")}, - {2, QStringLiteral("savings")}, - {3, QStringLiteral("cash")}, - {4, QStringLiteral("creditcard")}, - {5, QStringLiteral("loan")}, - {6, QStringLiteral("certificatedep")}, - {7, QStringLiteral("investment")}, - {8, QStringLiteral("moneymarket")}, - {10, QStringLiteral("asset")}, - {11, QStringLiteral("liability")}, - {12, QStringLiteral("currency")}, - {13, QStringLiteral("income")}, - {14, QStringLiteral("expense")}, - {15, QStringLiteral("assetloan")}, - {16, QStringLiteral("stock")}, - {17, QStringLiteral("equity")}, - {18, QStringLiteral("invalid")} - }; - return lut; -} - -QString accountTypeAttributeToString(int textID) -{ - return accountTypeAttributeLUT().value(textID); -} - -int stringToAccountTypeAttribute(const QString &text) -{ - return accountTypeAttributeLUT().key(text, 0); -} - -eMyMoney::Report::ReportType rowTypeToReportType(eMyMoney::Report::RowType rowType) -{ - static const QHash reportTypes { - {eMyMoney::Report::RowType::NoRows, eMyMoney::Report::ReportType::NoReport}, - {eMyMoney::Report::RowType::AssetLiability, eMyMoney::Report::ReportType::PivotTable}, - {eMyMoney::Report::RowType::ExpenseIncome, eMyMoney::Report::ReportType::PivotTable}, - {eMyMoney::Report::RowType::Category, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::TopCategory, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Account, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Tag, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Payee, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Month, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Week, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::TopAccount, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::AccountByTopAccount, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::EquityType, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::AccountType, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Institution, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::Budget, eMyMoney::Report::ReportType::PivotTable}, - {eMyMoney::Report::RowType::BudgetActual, eMyMoney::Report::ReportType::PivotTable}, - {eMyMoney::Report::RowType::Schedule, eMyMoney::Report::ReportType::InfoTable}, - {eMyMoney::Report::RowType::AccountInfo, eMyMoney::Report::ReportType::InfoTable}, - {eMyMoney::Report::RowType::AccountLoanInfo, eMyMoney::Report::ReportType::InfoTable}, - {eMyMoney::Report::RowType::AccountReconcile, eMyMoney::Report::ReportType::QueryTable}, - {eMyMoney::Report::RowType::CashFlow, eMyMoney::Report::ReportType::QueryTable}, - }; - return reportTypes.value(rowType, eMyMoney::Report::ReportType::Invalid); -} - -QHash budgetLevelLUT() -{ - 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 budgetNames(eMyMoney::Budget::Level textID) -{ - return budgetLevelLUT().value(textID); -} - -eMyMoney::Budget::Level stringToBudgetLevel(const QString &text) -{ - return budgetLevelLUT().key(text, eMyMoney::Budget::Level::Max); -} 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 @@ -62,11 +62,9 @@ #include "mymoneysplit.h" #include "onlinejob.h" #include "onlinejobadministration.h" +#include "plugins/xmlhelper/xmlstoragehelper.h" #include "mymoneyenums.h" -using namespace MyMoneyStorageTags; -using namespace MyMoneyStorageNodes; -using namespace MyMoneyStorageAttributes; using namespace eMyMoney; unsigned int MyMoneyStorageXML::fileVersionRead = 0; @@ -167,9 +165,6 @@ 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); @@ -349,20 +344,17 @@ m_reader->signalProgress(++m_elementCount, 0); } else if (s == nodeName(Node::KeyValuePairs)) { addToKeyValueContainer(*m_reader->m_storage, m_baseNode); - MyMoneyKeyValueContainer kvp(m_baseNode); - if (!(kvp.pairs() == m_reader->m_storage->pairs())) - qDebug() << "KVP is not equal."; } else if (s == nodeName(Node::Institution)) { auto i = readInstitution(m_baseNode); if (!i.id().isEmpty()) m_reader->d->iList[i.id()] = i; } else if (s == nodeName(Node::Report)) { - auto r = readReport(m_baseNode); + auto r = MyMoneyXmlContentHandler2::readReport(m_baseNode); if (!r.id().isEmpty()) m_reader->d->rList[r.id()] = r; m_reader->signalProgress(++m_elementCount, 0); } else if (s == nodeName(Node::Budget)) { - auto b = readBudget(m_baseNode); + auto b = MyMoneyXmlContentHandler2::readBudget(m_baseNode); if (!b.id().isEmpty()) m_reader->d->bList[b.id()] = b; } else if (s == tagName(Tag::FileInfo)) { @@ -711,7 +703,8 @@ // // Since we want to get rid of the lastStatementDate record anyway, this seems // to be ok for now. (ipwizard - 2008-08-14) - QString txt = MyMoneyKeyValueContainer(node.elementsByTagName(nodeName(Node::KeyValuePairs)).item(0).toElement()).value("lastStatementDate"); + + auto txt = acc.value(QStringLiteral("lastStatementDate")); if (!txt.isEmpty()) { acc.setLastReconciliationDate(QDate::fromString(txt, Qt::ISODate)); } @@ -1072,323 +1065,6 @@ parent.appendChild(el); } -MyMoneyReport MyMoneyXmlContentHandler::readReport(const QDomElement &node) -{ - if (nodeName(Node::Report) != node.tagName()) - throw MYMONEYEXCEPTION_CSTRING("Node was not REPORT"); - - MyMoneyReport report(node.attribute(attributeName(Attribute::Report::ID))); - - // The goal of this reading method is 100% backward AND 100% forward - // compatibility. Any report ever created with any version of KMyMoney - // should be able to be loaded by this method (as long as it's one of the - // report types supported in this version, of course) - - - // read report's internals - QString type = node.attribute(attributeName(Attribute::Report::Type)); - if (type.startsWith(QLatin1String("pivottable"))) - report.setReportType(eMyMoney::Report::ReportType::PivotTable); - else if (type.startsWith(QLatin1String("querytable"))) - report.setReportType(eMyMoney::Report::ReportType::QueryTable); - else if (type.startsWith(QLatin1String("infotable"))) - report.setReportType(eMyMoney::Report::ReportType::InfoTable); - else - throw MYMONEYEXCEPTION_CSTRING("Unknown report type"); - - report.setGroup(node.attribute(attributeName(Attribute::Report::Group))); - - report.clearTransactionFilter(); - - // read date tab - QString datelockstr = node.attribute(attributeName(Attribute::Report::DateLock), "userdefined"); - // Handle the pivot 1.2/query 1.1 case where the values were saved as - // numbers - bool ok = false; - int i = datelockstr.toUInt(&ok); - if (!ok) { - i = stringToDateLockAttribute(datelockstr); - if (i == -1) - i = (int)eMyMoney::TransactionFilter::Date::UserDefined; - } - report.setDateFilter(static_cast(i)); - - // read general tab - report.setName(node.attribute(attributeName(Attribute::Report::Name))); - report.setComment(node.attribute(attributeName(Attribute::Report::Comment), "Extremely old report")); - report.setConvertCurrency(node.attribute(attributeName(Attribute::Report::ConvertCurrency), "1").toUInt()); - report.setFavorite(node.attribute(attributeName(Attribute::Report::Favorite), "0").toUInt()); - report.setSkipZero(node.attribute(attributeName(Attribute::Report::SkipZero), "0").toUInt()); - - if (report.reportType() == eMyMoney::Report::ReportType::PivotTable) { - // read report's internals - report.setIncludingBudgetActuals(node.attribute(attributeName(Attribute::Report::IncludesActuals), "0").toUInt()); - report.setIncludingForecast(node.attribute(attributeName(Attribute::Report::IncludesForecast), "0").toUInt()); - report.setIncludingPrice(node.attribute(attributeName(Attribute::Report::IncludesPrice), "0").toUInt()); - report.setIncludingAveragePrice(node.attribute(attributeName(Attribute::Report::IncludesAveragePrice), "0").toUInt()); - report.setMixedTime(node.attribute(attributeName(Attribute::Report::MixedTime), "0").toUInt()); - report.setInvestmentsOnly(node.attribute(attributeName(Attribute::Report::Investments), "0").toUInt()); - - // read rows/columns tab - if (node.hasAttribute(attributeName(Attribute::Report::Budget))) - report.setBudget(node.attribute(attributeName(Attribute::Report::Budget))); - - const auto rowTypeFromXML = stringToRowType(node.attribute(attributeName(Attribute::Report::RowType))); - if (rowTypeFromXML != eMyMoney::Report::RowType::Invalid) - report.setRowType(rowTypeFromXML); - else - report.setRowType(eMyMoney::Report::RowType::ExpenseIncome); - - if (node.hasAttribute(attributeName(Attribute::Report::ShowRowTotals))) - report.setShowingRowTotals(node.attribute(attributeName(Attribute::Report::ShowRowTotals)).toUInt()); - else if (report.rowType() == eMyMoney::Report::RowType::ExpenseIncome) // for backward compatibility - report.setShowingRowTotals(true); - report.setShowingColumnTotals(node.attribute(attributeName(Attribute::Report::ShowColumnTotals), "1").toUInt()); - - //check for reports with older settings which didn't have the detail attribute - const auto detailLevelFromXML = stringToDetailLevel(node.attribute(attributeName(Attribute::Report::Detail))); - if (detailLevelFromXML != eMyMoney::Report::DetailLevel::End) - report.setDetailLevel(detailLevelFromXML); - else - report.setDetailLevel(eMyMoney::Report::DetailLevel::All); - - report.setIncludingMovingAverage(node.attribute(attributeName(Attribute::Report::IncludesMovingAverage), "0").toUInt()); - if (report.isIncludingMovingAverage()) - report.setMovingAverageDays(node.attribute(attributeName(Attribute::Report::MovingAverageDays), "1").toUInt()); - report.setIncludingSchedules(node.attribute(attributeName(Attribute::Report::IncludesSchedules), "0").toUInt()); - report.setIncludingTransfers(node.attribute(attributeName(Attribute::Report::IncludesTransfers), "0").toUInt()); - report.setIncludingUnusedAccounts(node.attribute(attributeName(Attribute::Report::IncludesUnused), "0").toUInt()); - report.setColumnsAreDays(node.attribute(attributeName(Attribute::Report::ColumnsAreDays), "0").toUInt()); - - // read chart tab - const auto chartTypeFromXML = stringToChartType(node.attribute(attributeName(Attribute::Report::ChartType))); - if (chartTypeFromXML != eMyMoney::Report::ChartType::End) - report.setChartType(chartTypeFromXML); - else - report.setChartType(eMyMoney::Report::ChartType::None); - - report.setChartCHGridLines(node.attribute(attributeName(Attribute::Report::ChartCHGridLines), "1").toUInt()); - report.setChartSVGridLines(node.attribute(attributeName(Attribute::Report::ChartSVGridLines), "1").toUInt()); - report.setChartDataLabels(node.attribute(attributeName(Attribute::Report::ChartDataLabels), "1").toUInt()); - report.setChartByDefault(node.attribute(attributeName(Attribute::Report::ChartByDefault), "0").toUInt()); - report.setLogYAxis(node.attribute(attributeName(Attribute::Report::LogYAxis), "0").toUInt()); - report.setChartLineWidth(node.attribute(attributeName(Attribute::Report::ChartLineWidth), QString(MyMoneyReport::m_lineWidth)).toUInt()); - - // read range tab - const auto columnTypeFromXML = stringToColumnType(node.attribute(attributeName(Attribute::Report::ColumnType))); - if (columnTypeFromXML != eMyMoney::Report::ColumnType::Invalid) - report.setColumnType(columnTypeFromXML); - else - report.setColumnType(eMyMoney::Report::ColumnType::Months); - - const auto dataLockFromXML = stringToDataLockAttribute(node.attribute(attributeName(Attribute::Report::DataLock))); - if (dataLockFromXML != eMyMoney::Report::DataLock::DataOptionCount) - report.setDataFilter(dataLockFromXML); - else - report.setDataFilter(eMyMoney::Report::DataLock::Automatic); - - report.setDataRangeStart(node.attribute(attributeName(Attribute::Report::DataRangeStart), "0")); - report.setDataRangeEnd(node.attribute(attributeName(Attribute::Report::DataRangeEnd), "0")); - report.setDataMajorTick(node.attribute(attributeName(Attribute::Report::DataMajorTick), "0")); - report.setDataMinorTick(node.attribute(attributeName(Attribute::Report::DataMinorTick), "0")); - report.setYLabelsPrecision(node.attribute(attributeName(Attribute::Report::YLabelsPrecision), "2").toUInt()); - } else if (report.reportType() == eMyMoney::Report::ReportType::QueryTable) { - // read rows/columns tab - const auto rowTypeFromXML = stringToRowType(node.attribute(attributeName(Attribute::Report::RowType))); - if (rowTypeFromXML != eMyMoney::Report::RowType::Invalid) - report.setRowType(rowTypeFromXML); - else - report.setRowType(eMyMoney::Report::RowType::Account); - - unsigned qc = 0; - QStringList columns = node.attribute(attributeName(Attribute::Report::QueryColumns), "none").split(','); - foreach (const auto column, columns) { - const int queryColumnFromXML = stringToQueryColumn(column); - i = stringToQueryColumn(column); - if (queryColumnFromXML != eMyMoney::Report::QueryColumn::End) - qc |= queryColumnFromXML; - } - report.setQueryColumns(static_cast(qc)); - - report.setTax(node.attribute(attributeName(Attribute::Report::Tax), "0").toUInt()); - report.setInvestmentsOnly(node.attribute(attributeName(Attribute::Report::Investments), "0").toUInt()); - report.setLoansOnly(node.attribute(attributeName(Attribute::Report::Loans), "0").toUInt()); - report.setHideTransactions(node.attribute(attributeName(Attribute::Report::HideTransactions), "0").toUInt()); - report.setShowingColumnTotals(node.attribute(attributeName(Attribute::Report::ShowColumnTotals), "1").toUInt()); - const auto detailLevelFromXML = stringToDetailLevel(node.attribute(attributeName(Attribute::Report::Detail), "none")); - if (detailLevelFromXML == eMyMoney::Report::DetailLevel::All) - report.setDetailLevel(detailLevelFromXML); - else - report.setDetailLevel(eMyMoney::Report::DetailLevel::None); - - // read performance or capital gains tab - if (report.queryColumns() & eMyMoney::Report::QueryColumn::Performance) - report.setInvestmentSum(static_cast(node.attribute(attributeName(Attribute::Report::InvestmentSum), QString::number(static_cast(eMyMoney::Report::InvestmentSum::Period))).toInt())); - - // read capital gains tab - if (report.queryColumns() & eMyMoney::Report::QueryColumn::CapitalGain) { - report.setInvestmentSum(static_cast(node.attribute(attributeName(Attribute::Report::InvestmentSum), QString::number(static_cast(eMyMoney::Report::InvestmentSum::Sold))).toInt())); - if (report.investmentSum() == eMyMoney::Report::InvestmentSum::Sold) { - report.setShowSTLTCapitalGains(node.attribute(attributeName(Attribute::Report::ShowSTLTCapitalGains), "0").toUInt()); - report.setSettlementPeriod(node.attribute(attributeName(Attribute::Report::SettlementPeriod), "3").toUInt()); - report.setTermSeparator(QDate::fromString(node.attribute(attributeName(Attribute::Report::TermsSeparator), QDate::currentDate().addYears(-1).toString(Qt::ISODate)),Qt::ISODate)); - } - } - } else if (report.reportType() == eMyMoney::Report::ReportType::InfoTable) { - if (node.hasAttribute(attributeName(Attribute::Report::ShowRowTotals))) - report.setShowingRowTotals(node.attribute(attributeName(Attribute::Report::ShowRowTotals)).toUInt()); - else - report.setShowingRowTotals(true); - } - - QDomNode child = node.firstChild(); - while (!child.isNull() && child.isElement()) { - QDomElement c = child.toElement(); - if (elementName(Element::Report::Text) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Pattern))) { - report.setTextFilter(QRegExp(c.attribute(attributeName(Attribute::Report::Pattern)), - c.attribute(attributeName(Attribute::Report::CaseSensitive), "1").toUInt() - ? Qt::CaseSensitive : Qt::CaseInsensitive, - c.attribute(attributeName(Attribute::Report::RegEx), "1").toUInt() - ? QRegExp::Wildcard : QRegExp::RegExp), - c.attribute(attributeName(Attribute::Report::InvertText), "0").toUInt()); - } - if (elementName(Element::Report::Type) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Type))) { - i = stringToTypeAttribute(c.attribute(attributeName(Attribute::Report::Type))); - if (i != -1) - report.addType(i); - } - if (elementName(Element::Report::State) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::State))) { - i = stringToStateAttribute(c.attribute(attributeName(Attribute::Report::State))); - if (i != -1) - report.addState(i); - } - if (elementName(Element::Report::Number) == c.tagName()) - report.setNumberFilter(c.attribute(attributeName(Attribute::Report::From)), c.attribute(attributeName(Attribute::Report::To))); - if (elementName(Element::Report::Amount) == c.tagName()) - report.setAmountFilter(MyMoneyMoney(c.attribute(attributeName(Attribute::Report::From), "0/100")), MyMoneyMoney(c.attribute(attributeName(Attribute::Report::To), "0/100"))); - if (elementName(Element::Report::Dates) == c.tagName()) { - QDate from, to; - if (c.hasAttribute(attributeName(Attribute::Report::From))) - from = QDate::fromString(c.attribute(attributeName(Attribute::Report::From)), Qt::ISODate); - if (c.hasAttribute(attributeName(Attribute::Report::To))) - to = QDate::fromString(c.attribute(attributeName(Attribute::Report::To)), Qt::ISODate); - report.setDateFilter(from, to); - } - if (elementName(Element::Report::Payee) == c.tagName()) - report.addPayee(c.attribute(attributeName(Attribute::Report::ID))); - if (elementName(Element::Report::Tag) == c.tagName()) - report.addTag(c.attribute(attributeName(Attribute::Report::ID))); - if (elementName(Element::Report::Category) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::ID))) - report.addCategory(c.attribute(attributeName(Attribute::Report::ID))); - if (elementName(Element::Report::Account) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::ID))) - report.addAccount(c.attribute(attributeName(Attribute::Report::ID))); - if (elementName(Element::Report::AccountGroup) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Group))) { - i = stringToAccountTypeAttribute(c.attribute(attributeName(Attribute::Report::Group))); - if (i != -1) - report.addAccountGroup(static_cast(i)); - } - child = child.nextSibling(); - } - - - return report; -} - -MyMoneyBudget MyMoneyXmlContentHandler::readBudget(const QDomElement &node) -{ - if (nodeName(Node::Budget) != node.tagName()) - throw MYMONEYEXCEPTION_CSTRING("Node was not BUDGET"); - - MyMoneyBudget budget(node.attribute(attributeName(Attribute::Account::ID))); - // The goal of this reading method is 100% backward AND 100% forward - // compatibility. Any Budget ever created with any version of KMyMoney - // should be able to be loaded by this method (as long as it's one of the - // Budget types supported in this version, of course) - - budget.setName(node.attribute(attributeName(Attribute::Budget::Name))); - budget.setBudgetStart(QDate::fromString(node.attribute(attributeName(Attribute::Budget::Start)), Qt::ISODate)); - - QDomNode child = node.firstChild(); - while (!child.isNull() && child.isElement()) { - QDomElement c = child.toElement(); - - MyMoneyBudget::AccountGroup account; - - if (elementName(Element::Budget::Account) == c.tagName()) { - if (c.hasAttribute(attributeName(Attribute::Budget::ID))) - account.setId(c.attribute(attributeName(Attribute::Budget::ID))); - - if (c.hasAttribute(attributeName(Attribute::Budget::BudgetLevel))) - account.setBudgetLevel(stringToBudgetLevel(c.attribute(attributeName(Attribute::Budget::BudgetLevel)))); - - if (c.hasAttribute(attributeName(Attribute::Budget::BudgetSubAccounts))) - account.setBudgetSubaccounts(c.attribute(attributeName(Attribute::Budget::BudgetSubAccounts)).toUInt()); - } - - QDomNode period = c.firstChild(); - while (!period.isNull() && period.isElement()) { - QDomElement per = period.toElement(); - MyMoneyBudget::PeriodGroup pGroup; - - if (elementName(Element::Budget::Period) == per.tagName() && per.hasAttribute(attributeName(Attribute::Budget::Amount)) && per.hasAttribute(attributeName(Attribute::Budget::Start))) { - pGroup.setAmount(MyMoneyMoney(per.attribute(attributeName(Attribute::Budget::Amount)))); - pGroup.setStartDate(QDate::fromString(per.attribute(attributeName(Attribute::Budget::Start)), Qt::ISODate)); - account.addPeriod(pGroup.startDate(), pGroup); - } - - period = period.nextSibling(); - } - budget.setAccount(account, account.id()); - - child = child.nextSibling(); - } - - - 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()) @@ -2002,7 +1678,7 @@ void MyMoneyStorageXML::writeReport(QDomElement& report, const MyMoneyReport& r) { - r.writeXML(*m_doc, report); + MyMoneyXmlContentHandler2::writeReport(r, *m_doc, report); } void MyMoneyStorageXML::writeBudgets(QDomElement& parent) @@ -2021,7 +1697,7 @@ void MyMoneyStorageXML::writeBudget(QDomElement& budget, const MyMoneyBudget& b) { - MyMoneyXmlContentHandler::writeBudget(b, *m_doc, budget); + MyMoneyXmlContentHandler2::writeBudget(b, *m_doc, budget); } void MyMoneyStorageXML::writeOnlineJobs(QDomElement& parent) diff --git a/kmymoney/plugins/xml/tests/CMakeLists.txt b/kmymoney/plugins/xml/tests/CMakeLists.txt --- a/kmymoney/plugins/xml/tests/CMakeLists.txt +++ b/kmymoney/plugins/xml/tests/CMakeLists.txt @@ -11,6 +11,8 @@ Qt5::Xml KF5::I18n kmm_mymoney + PRIVATE + xmlstoragehelper ) file(GLOB tests_sources "*-test.cpp") diff --git a/kmymoney/plugins/xml/tests/mymoneystoragenames-test.cpp b/kmymoney/plugins/xml/tests/mymoneystoragenames-test.cpp --- a/kmymoney/plugins/xml/tests/mymoneystoragenames-test.cpp +++ b/kmymoney/plugins/xml/tests/mymoneystoragenames-test.cpp @@ -19,6 +19,8 @@ #include #include "../mymoneystoragenames.cpp" +#include "plugins/xmlhelper/xmlstoragehelper.h" +#include "plugins/xmlhelper/xmlstoragehelper.cpp" QTEST_GUILESS_MAIN(MyMoneyStorageNamesTest) @@ -166,7 +168,7 @@ void MyMoneyStorageNamesTest::reportElementNames() { for (auto i = (int)Element::Report::Payee; i <= (int)Element::Report::AccountGroup; ++i) { - auto isEmpty = elementName(static_cast(i)).isEmpty(); + auto isEmpty = MyMoneyXmlContentHandler2::elementName(static_cast(i)).isEmpty(); if (isEmpty) qWarning() << "Empty element's name " << i; QVERIFY(!isEmpty); @@ -176,7 +178,7 @@ void MyMoneyStorageNamesTest::reportAttributeNames() { for (auto i = (int)Attribute::Report::ID; i < (int)Attribute::Report::LastAttribute; ++i) { - auto isEmpty = attributeName(static_cast(i)).isEmpty(); + auto isEmpty = MyMoneyXmlContentHandler2::attributeName(static_cast(i)).isEmpty(); if (isEmpty) qWarning() << "Empty attribute's name " << i; QVERIFY(!isEmpty); @@ -186,7 +188,7 @@ void MyMoneyStorageNamesTest::budgetElementNames() { for (auto i = (int)Element::Budget::Budget; i <= (int)Element::Budget::Period; ++i) { - auto isEmpty = elementName(static_cast(i)).isEmpty(); + auto isEmpty = MyMoneyXmlContentHandler2::elementName(static_cast(i)).isEmpty(); if (isEmpty) qWarning() << "Empty element's name " << i; QVERIFY(!isEmpty); @@ -196,7 +198,7 @@ void MyMoneyStorageNamesTest::budgetAttributeNames() { for (auto i = (int)Attribute::Budget::ID; i < (int)Attribute::Budget::LastAttribute; ++i) { - auto isEmpty = attributeName(static_cast(i)).isEmpty(); + auto isEmpty = MyMoneyXmlContentHandler2::attributeName(static_cast(i)).isEmpty(); if (isEmpty) qWarning() << "Empty attribute's name " << i; QVERIFY(!isEmpty); diff --git a/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.h b/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.h --- a/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.h +++ b/kmymoney/plugins/xml/tests/mymoneyxmlcontenthandler-test.h @@ -32,6 +32,7 @@ Q_OBJECT private Q_SLOTS: + void readMyMoneyObject(); void readKeyValueContainer(); void writeKeyValueContainer(); void readTransaction(); 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 @@ -26,9 +26,127 @@ #include #include "../mymoneystoragexml.cpp" +#include "mymoneyobject_p.h" +#include "mymoneyobject.h" QTEST_GUILESS_MAIN(MyMoneyXmlContentHandlerTest) +class TestMyMoneyObjectPrivate : public MyMoneyObjectPrivate +{ +public: + TestMyMoneyObjectPrivate() + { + } +}; +class TestMyMoneyObject : public MyMoneyObject +{ + Q_DECLARE_PRIVATE(TestMyMoneyObject) +public: + TestMyMoneyObject() : MyMoneyObject(*new MyMoneyObjectPrivate) {} + TestMyMoneyObject(const QString &id) : MyMoneyObject(*new MyMoneyObjectPrivate, id) { } + TestMyMoneyObject & operator=(TestMyMoneyObject other); + friend void swap(TestMyMoneyObject& first, TestMyMoneyObject& second); + ~TestMyMoneyObject(){} + bool hasReferenceTo(const QString&) const final override { + return false; + } + + static TestMyMoneyObject readBaseXML(const QDomElement &node, bool forceId = true) + { + TestMyMoneyObject obj(node.attribute(QStringLiteral("id"))); + if (obj.id() == 0 && forceId) + throw MYMONEYEXCEPTION_CSTRING("Node has no ID"); + return obj; + } +}; + +void swap(TestMyMoneyObject& first, TestMyMoneyObject& second) +{ + using std::swap; + swap(first.d_ptr, second.d_ptr); +} + +TestMyMoneyObject & TestMyMoneyObject::operator=(TestMyMoneyObject other) +{ + swap(*this, other); + return *this; +} + + +void MyMoneyXmlContentHandlerTest::readMyMoneyObject() +{ + TestMyMoneyObject t; + + QString ref_ok = QString( + "\n" + "\n" + " \n" + " \n" + "\n" + ); + + QString ref_false1 = QString( + "\n" + "\n" + " \n" + " \n" + "\n" + ); + + QString ref_false2 = QString( + "\n" + "\n" + " \n" + " \n" + "\n" + ); + + QDomDocument doc; + QDomElement node; + + // id="" but required + doc.setContent(ref_false1); + node = doc.documentElement().firstChild().toElement(); + + try { + t = TestMyMoneyObject::readBaseXML(node); + QFAIL("Missing expected exception"); + } catch (const MyMoneyException &) { + } + + // id attribute missing but required + doc.setContent(ref_false2); + node = doc.documentElement().firstChild().toElement(); + + try { + t = TestMyMoneyObject::readBaseXML(node); + QFAIL("Missing expected exception"); + } catch (const MyMoneyException &) { + } + + // id present + doc.setContent(ref_ok); + node = doc.documentElement().firstChild().toElement(); + + try { + t = TestMyMoneyObject::readBaseXML(node); + QVERIFY(t.id() == "T000000000000000001"); + } catch (const MyMoneyException &) { + QFAIL("Unexpected exception"); + } + + // id="" but not required + doc.setContent(ref_false1); + node = doc.documentElement().firstChild().toElement(); + + try { + t = TestMyMoneyObject::readBaseXML(node, false); + QVERIFY(t.id().isEmpty()); + } catch (const MyMoneyException &) { + QFAIL("Unexpected exception"); + } +} + void MyMoneyXmlContentHandlerTest::readKeyValueContainer() { MyMoneyKeyValueContainer kvp; @@ -97,7 +215,7 @@ QDomDocument doc("TEST"); QDomElement el = doc.createElement("KVP-CONTAINER"); doc.appendChild(el); - kvp.writeXML(doc, el); + MyMoneyXmlContentHandler::writeKeyValueContainer(kvp, doc, el); QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); QDomElement kvpContainer = doc.documentElement(); diff --git a/kmymoney/plugins/xmlhelper/CMakeLists.txt b/kmymoney/plugins/xmlhelper/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/xmlhelper/CMakeLists.txt @@ -0,0 +1,11 @@ +set(xmlstoragehelper_SOURCES + xmlstoragehelper.cpp + ) + +add_library(xmlstoragehelper STATIC ${xmlstoragehelper_SOURCES}) + +target_link_libraries(xmlstoragehelper + PRIVATE + Qt5::Xml + kmm_mymoney +) diff --git a/kmymoney/plugins/xmlhelper/xmlstoragehelper.h b/kmymoney/plugins/xmlhelper/xmlstoragehelper.h new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/xmlhelper/xmlstoragehelper.h @@ -0,0 +1,47 @@ +/* + * Copyright 2004-2006 Ace Jones + * Copyright 2006 Darren Gould + * Copyright 2007-2010 Alvaro Soliverez + * Copyright 2017-2018 Łukasz Wojniłowicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMLSTORAGEHELPER_H +#define XMLSTORAGEHELPER_H + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +class MyMoneyReport; +class MyMoneyBudget; + +class QDomDocument; +class QDomElement; + +namespace MyMoneyXmlContentHandler2 { + MyMoneyReport readReport(const QDomElement &node); + void writeReport(const MyMoneyReport &report, QDomDocument &document, QDomElement &parent); + + MyMoneyBudget readBudget(const QDomElement &node); + void writeBudget(const MyMoneyBudget &budget, QDomDocument &document, QDomElement &parent); +} + +#endif diff --git a/kmymoney/plugins/xmlhelper/xmlstoragehelper.cpp b/kmymoney/plugins/xmlhelper/xmlstoragehelper.cpp new file mode 100644 --- /dev/null +++ b/kmymoney/plugins/xmlhelper/xmlstoragehelper.cpp @@ -0,0 +1,1204 @@ +/* + * Copyright 2004-2006 Ace Jones + * Copyright 2006 Darren Gould + * Copyright 2007-2010 Alvaro Soliverez + * Copyright 2017-2018 Łukasz Wojniłowicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "xmlstoragehelper.h" + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "mymoneymoney.h" +#include "mymoneybudget.h" +#include "mymoneyreport.h" +#include "mymoneytransactionfilter.h" +#include "mymoneyenums.h" +#include "mymoneyexception.h" + +namespace Element { + + enum class Report { + Payee, + Tag, + Account, + Text, + Type, + State, + Number, + Amount, + Dates, + Category, + AccountGroup + }; + + enum class Budget { + Budget = 0, + Account, + Period + }; +} + +namespace Attribute { + + enum class Report { + ID = 0, Group, Type, Name, Comment, ConvertCurrency, Favorite, + SkipZero, DateLock, DataLock, MovingAverageDays, + IncludesActuals, IncludesForecast, IncludesPrice, + IncludesAveragePrice, IncludesMovingAverage, + IncludesSchedules, IncludesTransfers, IncludesUnused, + MixedTime, Investments, Budget, + ShowRowTotals, ShowColumnTotals, Detail, + ColumnsAreDays, ChartType, + ChartCHGridLines, ChartSVGridLines, + ChartDataLabels, ChartByDefault, + LogYAxis, ChartLineWidth, ColumnType, RowType, + DataRangeStart, DataRangeEnd, + DataMajorTick, DataMinorTick, + YLabelsPrecision, QueryColumns, + Tax, Loans, HideTransactions, InvestmentSum, + SettlementPeriod, ShowSTLTCapitalGains, TermsSeparator, + Pattern, CaseSensitive, RegEx, InvertText, State, + From, To, + // insert new entries above this line + LastAttribute + }; + + enum class Budget { + ID = 0, + Name, + Start, + Version, + BudgetLevel, + BudgetSubAccounts, + Amount, + // insert new entries above this line + LastAttribute + }; + +} + +namespace MyMoneyXmlContentHandler2 { + + enum class Node { + Report, + Budget + }; + + QString nodeName(Node nodeID) + { + static const QHash nodeNames { + {Node::Report, QStringLiteral("REPORT")}, + {Node::Budget, QStringLiteral("BUDGET")} + }; + return nodeNames.value(nodeID); + } + + uint qHash(const Node key, uint seed) { return ::qHash(static_cast(key), seed); } + + QString elementName(Element::Report elementID) + { + static const QMap elementNames { + {Element::Report::Payee, QStringLiteral("PAYEE")}, + {Element::Report::Tag, QStringLiteral("TAG")}, + {Element::Report::Account, QStringLiteral("ACCOUNT")}, + {Element::Report::Text, QStringLiteral("TEXT")}, + {Element::Report::Type, QStringLiteral("TYPE")}, + {Element::Report::State, QStringLiteral("STATE")}, + {Element::Report::Number, QStringLiteral("NUMBER")}, + {Element::Report::Amount, QStringLiteral("AMOUNT")}, + {Element::Report::Dates, QStringLiteral("DATES")}, + {Element::Report::Category, QStringLiteral("CATEGORY")}, + {Element::Report::AccountGroup, QStringLiteral("ACCOUNTGROUP")} + }; + return elementNames.value(elementID); + } + + QString attributeName(Attribute::Report attributeID) + { + static const QMap attributeNames { + {Attribute::Report::ID, QStringLiteral("id")}, + {Attribute::Report::Group, QStringLiteral("group")}, + {Attribute::Report::Type, QStringLiteral("type")}, + {Attribute::Report::Name, QStringLiteral("name")}, + {Attribute::Report::Comment, QStringLiteral("comment")}, + {Attribute::Report::ConvertCurrency, QStringLiteral("convertcurrency")}, + {Attribute::Report::Favorite, QStringLiteral("favorite")}, + {Attribute::Report::SkipZero, QStringLiteral("skipZero")}, + {Attribute::Report::DateLock, QStringLiteral("datelock")}, + {Attribute::Report::DataLock, QStringLiteral("datalock")}, + {Attribute::Report::MovingAverageDays, QStringLiteral("movingaveragedays")}, + {Attribute::Report::IncludesActuals, QStringLiteral("includesactuals")}, + {Attribute::Report::IncludesForecast, QStringLiteral("includesforecast")}, + {Attribute::Report::IncludesPrice, QStringLiteral("includesprice")}, + {Attribute::Report::IncludesAveragePrice, QStringLiteral("includesaverageprice")}, + {Attribute::Report::IncludesMovingAverage, QStringLiteral("includesmovingaverage")}, + {Attribute::Report::IncludesSchedules, QStringLiteral("includeschedules")}, + {Attribute::Report::IncludesTransfers, QStringLiteral("includestransfers")}, + {Attribute::Report::IncludesUnused, QStringLiteral("includeunused")}, + {Attribute::Report::MixedTime, QStringLiteral("mixedtime")}, + {Attribute::Report::Investments, QStringLiteral("investments")}, + {Attribute::Report::Budget, QStringLiteral("budget")}, + {Attribute::Report::ShowRowTotals, QStringLiteral("showrowtotals")}, + {Attribute::Report::ShowColumnTotals, QStringLiteral("showcolumntotals")}, + {Attribute::Report::Detail, QStringLiteral("detail")}, + {Attribute::Report::ColumnsAreDays, QStringLiteral("columnsaredays")}, + {Attribute::Report::ChartType, QStringLiteral("charttype")}, + {Attribute::Report::ChartCHGridLines, QStringLiteral("chartchgridlines")}, + {Attribute::Report::ChartSVGridLines, QStringLiteral("chartsvgridlines")}, + {Attribute::Report::ChartDataLabels, QStringLiteral("chartdatalabels")}, + {Attribute::Report::ChartByDefault, QStringLiteral("chartbydefault")}, + {Attribute::Report::LogYAxis, QStringLiteral("logYaxis")}, + {Attribute::Report::ChartLineWidth, QStringLiteral("chartlinewidth")}, + {Attribute::Report::ColumnType, QStringLiteral("columntype")}, + {Attribute::Report::RowType, QStringLiteral("rowtype")}, + {Attribute::Report::DataRangeStart, QStringLiteral("dataRangeStart")}, + {Attribute::Report::DataRangeEnd, QStringLiteral("dataRangeEnd")}, + {Attribute::Report::DataMajorTick, QStringLiteral("dataMajorTick")}, + {Attribute::Report::DataMinorTick, QStringLiteral("dataMinorTick")}, + {Attribute::Report::YLabelsPrecision, QStringLiteral("yLabelsPrecision")}, + {Attribute::Report::QueryColumns, QStringLiteral("querycolumns")}, + {Attribute::Report::Tax, QStringLiteral("tax")}, + {Attribute::Report::Loans, QStringLiteral("loans")}, + {Attribute::Report::HideTransactions, QStringLiteral("hidetransactions")}, + {Attribute::Report::InvestmentSum, QStringLiteral("investmentsum")}, + {Attribute::Report::SettlementPeriod, QStringLiteral("settlementperiod")}, + {Attribute::Report::ShowSTLTCapitalGains, QStringLiteral("showSTLTCapitalGains")}, + {Attribute::Report::TermsSeparator, QStringLiteral("tseparator")}, + {Attribute::Report::Pattern, QStringLiteral("pattern")}, + {Attribute::Report::CaseSensitive, QStringLiteral("casesensitive")}, + {Attribute::Report::RegEx, QStringLiteral("regex")}, + {Attribute::Report::InvertText, QStringLiteral("inverttext")}, + {Attribute::Report::State, QStringLiteral("state")}, + {Attribute::Report::From, QStringLiteral("from")}, + {Attribute::Report::To, QStringLiteral("to")} + }; + return attributeNames.value(attributeID); + } + + QString elementName(Element::Budget elementID) + { + static const QMap elementNames { + {Element::Budget::Budget, QStringLiteral("BUDGET")}, + {Element::Budget::Account, QStringLiteral("ACCOUNT")}, + {Element::Budget::Period, QStringLiteral("PERIOD")} + }; + return elementNames.value(elementID); + } + + QString attributeName(Attribute::Budget attributeID) + { + static const QMap attributeNames { + {Attribute::Budget::ID, QStringLiteral("id")}, + {Attribute::Budget::Name, QStringLiteral("name")}, + {Attribute::Budget::Start, QStringLiteral("start")}, + {Attribute::Budget::Version, QStringLiteral("version")}, + {Attribute::Budget::BudgetLevel, QStringLiteral("budgetlevel")}, + {Attribute::Budget::BudgetSubAccounts, QStringLiteral("budgetsubaccounts")}, + {Attribute::Budget::Amount, QStringLiteral("amount")} + }; + return attributeNames.value(attributeID); + } + + QHash rowTypesLUT() + { + static const QHash lut { + {eMyMoney::Report::RowType::NoRows, QStringLiteral("none")}, + {eMyMoney::Report::RowType::AssetLiability, QStringLiteral("assetliability")}, + {eMyMoney::Report::RowType::ExpenseIncome, QStringLiteral("expenseincome")}, + {eMyMoney::Report::RowType::Category, QStringLiteral("category")}, + {eMyMoney::Report::RowType::TopCategory, QStringLiteral("topcategory")}, + {eMyMoney::Report::RowType::Account, QStringLiteral("account")}, + {eMyMoney::Report::RowType::Tag, QStringLiteral("tag")}, + {eMyMoney::Report::RowType::Payee, QStringLiteral("payee")}, + {eMyMoney::Report::RowType::Month, QStringLiteral("month")}, + {eMyMoney::Report::RowType::Week, QStringLiteral("week")}, + {eMyMoney::Report::RowType::TopAccount, QStringLiteral("topaccount")}, + {eMyMoney::Report::RowType::AccountByTopAccount, QStringLiteral("topaccount-account")}, + {eMyMoney::Report::RowType::EquityType, QStringLiteral("equitytype")}, + {eMyMoney::Report::RowType::AccountType, QStringLiteral("accounttype")}, + {eMyMoney::Report::RowType::Institution, QStringLiteral("institution")}, + {eMyMoney::Report::RowType::Budget, QStringLiteral("budget")}, + {eMyMoney::Report::RowType::BudgetActual, QStringLiteral("budgetactual")}, + {eMyMoney::Report::RowType::Schedule, QStringLiteral("schedule")}, + {eMyMoney::Report::RowType::AccountInfo, QStringLiteral("accountinfo")}, + {eMyMoney::Report::RowType::AccountLoanInfo, QStringLiteral("accountloaninfo")}, + {eMyMoney::Report::RowType::AccountReconcile, QStringLiteral("accountreconcile")}, + {eMyMoney::Report::RowType::CashFlow, QStringLiteral("cashflow")}, + }; + return lut; + } + + QString reportNames(eMyMoney::Report::RowType textID) + { + return rowTypesLUT().value(textID); + } + + eMyMoney::Report::RowType stringToRowType(const QString &text) + { + return rowTypesLUT().key(text, eMyMoney::Report::RowType::Invalid); + } + + QHash columTypesLUT() + { + static const QHash lut { + {eMyMoney::Report::ColumnType::NoColumns, QStringLiteral("none")}, + {eMyMoney::Report::ColumnType::Months, QStringLiteral("months")}, + {eMyMoney::Report::ColumnType::BiMonths, QStringLiteral("bimonths")}, + {eMyMoney::Report::ColumnType::Quarters, QStringLiteral("quarters")}, + // {eMyMoney::Report::ColumnType::, QStringLiteral("4")} + // {eMyMoney::Report::ColumnType::, QStringLiteral("5")} + // {eMyMoney::Report::ColumnType::, QStringLiteral("6")} + {eMyMoney::Report::ColumnType::Weeks, QStringLiteral("weeks")}, + // {eMyMoney::Report::ColumnType::, QStringLiteral("8")} + // {eMyMoney::Report::ColumnType::, QStringLiteral("9")} + // {eMyMoney::Report::ColumnType::, QStringLiteral("10")} + // {eMyMoney::Report::ColumnType::, QStringLiteral("11")} + {eMyMoney::Report::ColumnType::Years, QStringLiteral("years")} + }; + return lut; + } + + QString reportNames(eMyMoney::Report::ColumnType textID) + { + return columTypesLUT().value(textID); + } + + eMyMoney::Report::ColumnType stringToColumnType(const QString &text) + { + return columTypesLUT().key(text, eMyMoney::Report::ColumnType::Invalid); + } + + QHash queryColumnsLUT() + { + static const QHash lut { + {eMyMoney::Report::QueryColumn::None, QStringLiteral("none")}, + {eMyMoney::Report::QueryColumn::Number, QStringLiteral("number")}, + {eMyMoney::Report::QueryColumn::Payee, QStringLiteral("payee")}, + {eMyMoney::Report::QueryColumn::Category, QStringLiteral("category")}, + {eMyMoney::Report::QueryColumn::Tag, QStringLiteral("tag")}, + {eMyMoney::Report::QueryColumn::Memo, QStringLiteral("memo")}, + {eMyMoney::Report::QueryColumn::Account, QStringLiteral("account")}, + {eMyMoney::Report::QueryColumn::Reconciled, QStringLiteral("reconcileflag")}, + {eMyMoney::Report::QueryColumn::Action, QStringLiteral("action")}, + {eMyMoney::Report::QueryColumn::Shares, QStringLiteral("shares")}, + {eMyMoney::Report::QueryColumn::Price, QStringLiteral("price")}, + {eMyMoney::Report::QueryColumn::Performance, QStringLiteral("performance")}, + {eMyMoney::Report::QueryColumn::Loan, QStringLiteral("loan")}, + {eMyMoney::Report::QueryColumn::Balance, QStringLiteral("balance")}, + {eMyMoney::Report::QueryColumn::CapitalGain, QStringLiteral("capitalgain")} + }; + return lut; + } + + QString reportNamesForQC(eMyMoney::Report::QueryColumn textID) + { + return queryColumnsLUT().value(textID); + } + + eMyMoney::Report::QueryColumn stringToQueryColumn(const QString &text) + { + return queryColumnsLUT().key(text, eMyMoney::Report::QueryColumn::End); + } + + QHash detailLevelLUT() + { + static const QHash lut { + {eMyMoney::Report::DetailLevel::None, QStringLiteral("none")}, + {eMyMoney::Report::DetailLevel::All, QStringLiteral("all")}, + {eMyMoney::Report::DetailLevel::Top, QStringLiteral("top")}, + {eMyMoney::Report::DetailLevel::Group, QStringLiteral("group")}, + {eMyMoney::Report::DetailLevel::Total, QStringLiteral("total")}, + {eMyMoney::Report::DetailLevel::End, QStringLiteral("invalid")} + }; + return lut; + } + + QString reportNames(eMyMoney::Report::DetailLevel textID) + { + return detailLevelLUT().value(textID); + } + + eMyMoney::Report::DetailLevel stringToDetailLevel(const QString &text) + { + return detailLevelLUT().key(text, eMyMoney::Report::DetailLevel::End); + } + + QHash chartTypeLUT() + { + static const QHash lut { + {eMyMoney::Report::ChartType::None, QStringLiteral("none")}, + {eMyMoney::Report::ChartType::Line, QStringLiteral("line")}, + {eMyMoney::Report::ChartType::Bar, QStringLiteral("bar")}, + {eMyMoney::Report::ChartType::Pie, QStringLiteral("pie")}, + {eMyMoney::Report::ChartType::Ring, QStringLiteral("ring")}, + {eMyMoney::Report::ChartType::StackedBar, QStringLiteral("stackedbar")} + }; + return lut; + } + + QString reportNames(eMyMoney::Report::ChartType textID) + { + return chartTypeLUT().value(textID); + } + + eMyMoney::Report::ChartType stringToChartType(const QString &text) + { + return chartTypeLUT().key(text, eMyMoney::Report::ChartType::End); + } + + QHash typeAttributeLUT() + { + static const QHash lut { + {0, QStringLiteral("all")}, + {1, QStringLiteral("payments")}, + {2, QStringLiteral("deposits")}, + {3, QStringLiteral("transfers")}, + {4, QStringLiteral("none")}, + }; + return lut; + } + + QString typeAttributeToString(int textID) + { + return typeAttributeLUT().value(textID); + } + + int stringToTypeAttribute(const QString &text) + { + return typeAttributeLUT().key(text, 4); + } + + QHash stateAttributeLUT() + { + static const QHash lut { + {0, QStringLiteral("all")}, + {1, QStringLiteral("notreconciled")}, + {2, QStringLiteral("cleared")}, + {3, QStringLiteral("reconciled")}, + {4, QStringLiteral("frozen")}, + {5, QStringLiteral("none")} + }; + return lut; + } + + QString stateAttributeToString(int textID) + { + return stateAttributeLUT().value(textID); + } + + int stringToStateAttribute(const QString &text) + { + return stateAttributeLUT().key(text, 5); + } + + QHash dateLockLUT() + { + static const QHash lut { + {0, QStringLiteral("alldates")}, + {1, QStringLiteral("untiltoday")}, + {2, QStringLiteral("currentmonth")}, + {3, QStringLiteral("currentyear")}, + {4, QStringLiteral("monthtodate")}, + {5, QStringLiteral("yeartodate")}, + {6, QStringLiteral("yeartomonth")}, + {7, QStringLiteral("lastmonth")}, + {8, QStringLiteral("lastyear")}, + {9, QStringLiteral("last7days")}, + {10, QStringLiteral("last30days")}, + {11, QStringLiteral("last3months")}, + {12, QStringLiteral("last6months")}, + {13, QStringLiteral("last12months")}, + {14, QStringLiteral("next7days")}, + {15, QStringLiteral("next30days")}, + {16, QStringLiteral("next3months")}, + {17, QStringLiteral("next6months")}, + {18, QStringLiteral("next12months")}, + {19, QStringLiteral("userdefined")}, + {20, QStringLiteral("last3tonext3months")}, + {21, QStringLiteral("last11Months")}, + {22, QStringLiteral("currentQuarter")}, + {23, QStringLiteral("lastQuarter")}, + {24, QStringLiteral("nextQuarter")}, + {25, QStringLiteral("currentFiscalYear")}, + {26, QStringLiteral("lastFiscalYear")}, + {27, QStringLiteral("today")}, + {28, QStringLiteral("next18months")} + }; + return lut; + } + + QString dateLockAttributeToString(int textID) + { + return dateLockLUT().value(textID); + } + + int stringToDateLockAttribute(const QString &text) + { + return dateLockLUT().key(text, 0); + } + + QHash dataLockLUT() + { + static const QHash lut { + {eMyMoney::Report::DataLock::Automatic, QStringLiteral("automatic")}, + {eMyMoney::Report::DataLock::UserDefined, QStringLiteral("userdefined")} + }; + return lut; + } + + QString reportNames(eMyMoney::Report::DataLock textID) + { + return dataLockLUT().value(textID); + } + + eMyMoney::Report::DataLock stringToDataLockAttribute(const QString &text) + { + return dataLockLUT().key(text, eMyMoney::Report::DataLock::DataOptionCount); + } + + QHash accountTypeAttributeLUT() + { + static const QHash lut { + {0, QStringLiteral("unknown")}, + {1, QStringLiteral("checkings")}, + {2, QStringLiteral("savings")}, + {3, QStringLiteral("cash")}, + {4, QStringLiteral("creditcard")}, + {5, QStringLiteral("loan")}, + {6, QStringLiteral("certificatedep")}, + {7, QStringLiteral("investment")}, + {8, QStringLiteral("moneymarket")}, + {10, QStringLiteral("asset")}, + {11, QStringLiteral("liability")}, + {12, QStringLiteral("currency")}, + {13, QStringLiteral("income")}, + {14, QStringLiteral("expense")}, + {15, QStringLiteral("assetloan")}, + {16, QStringLiteral("stock")}, + {17, QStringLiteral("equity")}, + {18, QStringLiteral("invalid")} + }; + return lut; + } + + QString accountTypeAttributeToString(int textID) + { + return accountTypeAttributeLUT().value(textID); + } + + int stringToAccountTypeAttribute(const QString &text) + { + return accountTypeAttributeLUT().key(text, 0); + } + + eMyMoney::Report::ReportType rowTypeToReportType(eMyMoney::Report::RowType rowType) + { + static const QHash reportTypes { + {eMyMoney::Report::RowType::NoRows, eMyMoney::Report::ReportType::NoReport}, + {eMyMoney::Report::RowType::AssetLiability, eMyMoney::Report::ReportType::PivotTable}, + {eMyMoney::Report::RowType::ExpenseIncome, eMyMoney::Report::ReportType::PivotTable}, + {eMyMoney::Report::RowType::Category, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::TopCategory, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Account, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Tag, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Payee, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Month, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Week, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::TopAccount, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::AccountByTopAccount, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::EquityType, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::AccountType, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Institution, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::Budget, eMyMoney::Report::ReportType::PivotTable}, + {eMyMoney::Report::RowType::BudgetActual, eMyMoney::Report::ReportType::PivotTable}, + {eMyMoney::Report::RowType::Schedule, eMyMoney::Report::ReportType::InfoTable}, + {eMyMoney::Report::RowType::AccountInfo, eMyMoney::Report::ReportType::InfoTable}, + {eMyMoney::Report::RowType::AccountLoanInfo, eMyMoney::Report::ReportType::InfoTable}, + {eMyMoney::Report::RowType::AccountReconcile, eMyMoney::Report::ReportType::QueryTable}, + {eMyMoney::Report::RowType::CashFlow, eMyMoney::Report::ReportType::QueryTable}, + }; + return reportTypes.value(rowType, eMyMoney::Report::ReportType::Invalid); + } + + QHash budgetLevelLUT() + { + 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 budgetNames(eMyMoney::Budget::Level textID) + { + return budgetLevelLUT().value(textID); + } + + eMyMoney::Budget::Level stringToBudgetLevel(const QString &text) + { + return budgetLevelLUT().key(text, eMyMoney::Budget::Level::Max); + } + + 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); + } + + void writeBaseXML(const QString &id, QDomDocument &document, QDomElement &el) + { + Q_UNUSED(document); + + el.setAttribute(QStringLiteral("id"), id); + } + + MyMoneyReport readReport(const QDomElement &node) + { + if (nodeName(Node::Report) != node.tagName()) + throw MYMONEYEXCEPTION_CSTRING("Node was not REPORT"); + + MyMoneyReport report(node.attribute(attributeName(Attribute::Report::ID))); + + // The goal of this reading method is 100% backward AND 100% forward + // compatibility. Any report ever created with any version of KMyMoney + // should be able to be loaded by this method (as long as it's one of the + // report types supported in this version, of course) + + + // read report's internals + QString type = node.attribute(attributeName(Attribute::Report::Type)); + if (type.startsWith(QLatin1String("pivottable"))) + report.setReportType(eMyMoney::Report::ReportType::PivotTable); + else if (type.startsWith(QLatin1String("querytable"))) + report.setReportType(eMyMoney::Report::ReportType::QueryTable); + else if (type.startsWith(QLatin1String("infotable"))) + report.setReportType(eMyMoney::Report::ReportType::InfoTable); + else + throw MYMONEYEXCEPTION_CSTRING("Unknown report type"); + + report.setGroup(node.attribute(attributeName(Attribute::Report::Group))); + + report.clearTransactionFilter(); + + // read date tab + QString datelockstr = node.attribute(attributeName(Attribute::Report::DateLock), "userdefined"); + // Handle the pivot 1.2/query 1.1 case where the values were saved as + // numbers + bool ok = false; + int i = datelockstr.toUInt(&ok); + if (!ok) { + i = stringToDateLockAttribute(datelockstr); + if (i == -1) + i = (int)eMyMoney::TransactionFilter::Date::UserDefined; + } + report.setDateFilter(static_cast(i)); + + // read general tab + report.setName(node.attribute(attributeName(Attribute::Report::Name))); + report.setComment(node.attribute(attributeName(Attribute::Report::Comment), "Extremely old report")); + report.setConvertCurrency(node.attribute(attributeName(Attribute::Report::ConvertCurrency), "1").toUInt()); + report.setFavorite(node.attribute(attributeName(Attribute::Report::Favorite), "0").toUInt()); + report.setSkipZero(node.attribute(attributeName(Attribute::Report::SkipZero), "0").toUInt()); + + if (report.reportType() == eMyMoney::Report::ReportType::PivotTable) { + // read report's internals + report.setIncludingBudgetActuals(node.attribute(attributeName(Attribute::Report::IncludesActuals), "0").toUInt()); + report.setIncludingForecast(node.attribute(attributeName(Attribute::Report::IncludesForecast), "0").toUInt()); + report.setIncludingPrice(node.attribute(attributeName(Attribute::Report::IncludesPrice), "0").toUInt()); + report.setIncludingAveragePrice(node.attribute(attributeName(Attribute::Report::IncludesAveragePrice), "0").toUInt()); + report.setMixedTime(node.attribute(attributeName(Attribute::Report::MixedTime), "0").toUInt()); + report.setInvestmentsOnly(node.attribute(attributeName(Attribute::Report::Investments), "0").toUInt()); + + // read rows/columns tab + if (node.hasAttribute(attributeName(Attribute::Report::Budget))) + report.setBudget(node.attribute(attributeName(Attribute::Report::Budget))); + + const auto rowTypeFromXML = stringToRowType(node.attribute(attributeName(Attribute::Report::RowType))); + if (rowTypeFromXML != eMyMoney::Report::RowType::Invalid) + report.setRowType(rowTypeFromXML); + else + report.setRowType(eMyMoney::Report::RowType::ExpenseIncome); + + if (node.hasAttribute(attributeName(Attribute::Report::ShowRowTotals))) + report.setShowingRowTotals(node.attribute(attributeName(Attribute::Report::ShowRowTotals)).toUInt()); + else if (report.rowType() == eMyMoney::Report::RowType::ExpenseIncome) // for backward compatibility + report.setShowingRowTotals(true); + report.setShowingColumnTotals(node.attribute(attributeName(Attribute::Report::ShowColumnTotals), "1").toUInt()); + + //check for reports with older settings which didn't have the detail attribute + const auto detailLevelFromXML = stringToDetailLevel(node.attribute(attributeName(Attribute::Report::Detail))); + if (detailLevelFromXML != eMyMoney::Report::DetailLevel::End) + report.setDetailLevel(detailLevelFromXML); + else + report.setDetailLevel(eMyMoney::Report::DetailLevel::All); + + report.setIncludingMovingAverage(node.attribute(attributeName(Attribute::Report::IncludesMovingAverage), "0").toUInt()); + if (report.isIncludingMovingAverage()) + report.setMovingAverageDays(node.attribute(attributeName(Attribute::Report::MovingAverageDays), "1").toUInt()); + report.setIncludingSchedules(node.attribute(attributeName(Attribute::Report::IncludesSchedules), "0").toUInt()); + report.setIncludingTransfers(node.attribute(attributeName(Attribute::Report::IncludesTransfers), "0").toUInt()); + report.setIncludingUnusedAccounts(node.attribute(attributeName(Attribute::Report::IncludesUnused), "0").toUInt()); + report.setColumnsAreDays(node.attribute(attributeName(Attribute::Report::ColumnsAreDays), "0").toUInt()); + + // read chart tab + const auto chartTypeFromXML = stringToChartType(node.attribute(attributeName(Attribute::Report::ChartType))); + if (chartTypeFromXML != eMyMoney::Report::ChartType::End) + report.setChartType(chartTypeFromXML); + else + report.setChartType(eMyMoney::Report::ChartType::None); + + report.setChartCHGridLines(node.attribute(attributeName(Attribute::Report::ChartCHGridLines), "1").toUInt()); + report.setChartSVGridLines(node.attribute(attributeName(Attribute::Report::ChartSVGridLines), "1").toUInt()); + report.setChartDataLabels(node.attribute(attributeName(Attribute::Report::ChartDataLabels), "1").toUInt()); + report.setChartByDefault(node.attribute(attributeName(Attribute::Report::ChartByDefault), "0").toUInt()); + report.setLogYAxis(node.attribute(attributeName(Attribute::Report::LogYAxis), "0").toUInt()); + report.setChartLineWidth(node.attribute(attributeName(Attribute::Report::ChartLineWidth), QString(MyMoneyReport::m_lineWidth)).toUInt()); + + // read range tab + const auto columnTypeFromXML = stringToColumnType(node.attribute(attributeName(Attribute::Report::ColumnType))); + if (columnTypeFromXML != eMyMoney::Report::ColumnType::Invalid) + report.setColumnType(columnTypeFromXML); + else + report.setColumnType(eMyMoney::Report::ColumnType::Months); + + const auto dataLockFromXML = stringToDataLockAttribute(node.attribute(attributeName(Attribute::Report::DataLock))); + if (dataLockFromXML != eMyMoney::Report::DataLock::DataOptionCount) + report.setDataFilter(dataLockFromXML); + else + report.setDataFilter(eMyMoney::Report::DataLock::Automatic); + + report.setDataRangeStart(node.attribute(attributeName(Attribute::Report::DataRangeStart), "0")); + report.setDataRangeEnd(node.attribute(attributeName(Attribute::Report::DataRangeEnd), "0")); + report.setDataMajorTick(node.attribute(attributeName(Attribute::Report::DataMajorTick), "0")); + report.setDataMinorTick(node.attribute(attributeName(Attribute::Report::DataMinorTick), "0")); + report.setYLabelsPrecision(node.attribute(attributeName(Attribute::Report::YLabelsPrecision), "2").toUInt()); + } else if (report.reportType() == eMyMoney::Report::ReportType::QueryTable) { + // read rows/columns tab + const auto rowTypeFromXML = stringToRowType(node.attribute(attributeName(Attribute::Report::RowType))); + if (rowTypeFromXML != eMyMoney::Report::RowType::Invalid) + report.setRowType(rowTypeFromXML); + else + report.setRowType(eMyMoney::Report::RowType::Account); + + unsigned qc = 0; + QStringList columns = node.attribute(attributeName(Attribute::Report::QueryColumns), "none").split(','); + foreach (const auto column, columns) { + const int queryColumnFromXML = stringToQueryColumn(column); + i = stringToQueryColumn(column); + if (queryColumnFromXML != eMyMoney::Report::QueryColumn::End) + qc |= queryColumnFromXML; + } + report.setQueryColumns(static_cast(qc)); + + report.setTax(node.attribute(attributeName(Attribute::Report::Tax), "0").toUInt()); + report.setInvestmentsOnly(node.attribute(attributeName(Attribute::Report::Investments), "0").toUInt()); + report.setLoansOnly(node.attribute(attributeName(Attribute::Report::Loans), "0").toUInt()); + report.setHideTransactions(node.attribute(attributeName(Attribute::Report::HideTransactions), "0").toUInt()); + report.setShowingColumnTotals(node.attribute(attributeName(Attribute::Report::ShowColumnTotals), "1").toUInt()); + const auto detailLevelFromXML = stringToDetailLevel(node.attribute(attributeName(Attribute::Report::Detail), "none")); + if (detailLevelFromXML == eMyMoney::Report::DetailLevel::All) + report.setDetailLevel(detailLevelFromXML); + else + report.setDetailLevel(eMyMoney::Report::DetailLevel::None); + + // read performance or capital gains tab + if (report.queryColumns() & eMyMoney::Report::QueryColumn::Performance) + report.setInvestmentSum(static_cast(node.attribute(attributeName(Attribute::Report::InvestmentSum), QString::number(static_cast(eMyMoney::Report::InvestmentSum::Period))).toInt())); + + // read capital gains tab + if (report.queryColumns() & eMyMoney::Report::QueryColumn::CapitalGain) { + report.setInvestmentSum(static_cast(node.attribute(attributeName(Attribute::Report::InvestmentSum), QString::number(static_cast(eMyMoney::Report::InvestmentSum::Sold))).toInt())); + if (report.investmentSum() == eMyMoney::Report::InvestmentSum::Sold) { + report.setShowSTLTCapitalGains(node.attribute(attributeName(Attribute::Report::ShowSTLTCapitalGains), "0").toUInt()); + report.setSettlementPeriod(node.attribute(attributeName(Attribute::Report::SettlementPeriod), "3").toUInt()); + report.setTermSeparator(QDate::fromString(node.attribute(attributeName(Attribute::Report::TermsSeparator), QDate::currentDate().addYears(-1).toString(Qt::ISODate)),Qt::ISODate)); + } + } + } else if (report.reportType() == eMyMoney::Report::ReportType::InfoTable) { + if (node.hasAttribute(attributeName(Attribute::Report::ShowRowTotals))) + report.setShowingRowTotals(node.attribute(attributeName(Attribute::Report::ShowRowTotals)).toUInt()); + else + report.setShowingRowTotals(true); + } + + QDomNode child = node.firstChild(); + while (!child.isNull() && child.isElement()) { + QDomElement c = child.toElement(); + if (elementName(Element::Report::Text) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Pattern))) { + report.setTextFilter(QRegExp(c.attribute(attributeName(Attribute::Report::Pattern)), + c.attribute(attributeName(Attribute::Report::CaseSensitive), "1").toUInt() + ? Qt::CaseSensitive : Qt::CaseInsensitive, + c.attribute(attributeName(Attribute::Report::RegEx), "1").toUInt() + ? QRegExp::Wildcard : QRegExp::RegExp), + c.attribute(attributeName(Attribute::Report::InvertText), "0").toUInt()); + } + if (elementName(Element::Report::Type) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Type))) { + i = stringToTypeAttribute(c.attribute(attributeName(Attribute::Report::Type))); + if (i != -1) + report.addType(i); + } + if (elementName(Element::Report::State) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::State))) { + i = stringToStateAttribute(c.attribute(attributeName(Attribute::Report::State))); + if (i != -1) + report.addState(i); + } + if (elementName(Element::Report::Number) == c.tagName()) + report.setNumberFilter(c.attribute(attributeName(Attribute::Report::From)), c.attribute(attributeName(Attribute::Report::To))); + if (elementName(Element::Report::Amount) == c.tagName()) + report.setAmountFilter(MyMoneyMoney(c.attribute(attributeName(Attribute::Report::From), "0/100")), MyMoneyMoney(c.attribute(attributeName(Attribute::Report::To), "0/100"))); + if (elementName(Element::Report::Dates) == c.tagName()) { + QDate from, to; + if (c.hasAttribute(attributeName(Attribute::Report::From))) + from = QDate::fromString(c.attribute(attributeName(Attribute::Report::From)), Qt::ISODate); + if (c.hasAttribute(attributeName(Attribute::Report::To))) + to = QDate::fromString(c.attribute(attributeName(Attribute::Report::To)), Qt::ISODate); + report.setDateFilter(from, to); + } + if (elementName(Element::Report::Payee) == c.tagName()) + report.addPayee(c.attribute(attributeName(Attribute::Report::ID))); + if (elementName(Element::Report::Tag) == c.tagName()) + report.addTag(c.attribute(attributeName(Attribute::Report::ID))); + if (elementName(Element::Report::Category) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::ID))) + report.addCategory(c.attribute(attributeName(Attribute::Report::ID))); + if (elementName(Element::Report::Account) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::ID))) + report.addAccount(c.attribute(attributeName(Attribute::Report::ID))); + if (elementName(Element::Report::AccountGroup) == c.tagName() && c.hasAttribute(attributeName(Attribute::Report::Group))) { + i = stringToAccountTypeAttribute(c.attribute(attributeName(Attribute::Report::Group))); + if (i != -1) + report.addAccountGroup(static_cast(i)); + } + child = child.nextSibling(); + } + + return report; + } + + void writeReport(const MyMoneyReport &report, QDomDocument &document, QDomElement &parent) + { + auto el = document.createElement(nodeName(Node::Report)); + + // No matter what changes, be sure to have a 'type' attribute. Only change + // the major type if it becomes impossible to maintain compatibility with + // older versions of the program as new features are added to the reports. + // Feel free to change the minor type every time a change is made here. + + // write report's internals + if (report.reportType() == eMyMoney::Report::ReportType::PivotTable) + el.setAttribute(attributeName(Attribute::Report::Type), "pivottable 1.15"); + else if (report.reportType() == eMyMoney::Report::ReportType::QueryTable) + el.setAttribute(attributeName(Attribute::Report::Type), "querytable 1.14"); + else if (report.reportType() == eMyMoney::Report::ReportType::InfoTable) + el.setAttribute(attributeName(Attribute::Report::Type), "infotable 1.0"); + + el.setAttribute(attributeName(Attribute::Report::Group), report.group()); + el.setAttribute(attributeName(Attribute::Report::ID), report.id()); + + // write general tab + auto anonymous = false; + if (anonymous) { + el.setAttribute(attributeName(Attribute::Report::Name), report.id()); + el.setAttribute(attributeName(Attribute::Report::Comment), QString(report.comment()).fill('x')); + } else { + el.setAttribute(attributeName(Attribute::Report::Name), report.name()); + el.setAttribute(attributeName(Attribute::Report::Comment), report.comment()); + } + el.setAttribute(attributeName(Attribute::Report::ConvertCurrency), report.isConvertCurrency()); + el.setAttribute(attributeName(Attribute::Report::Favorite), report.isFavorite()); + el.setAttribute(attributeName(Attribute::Report::SkipZero), report.isSkippingZero()); + + el.setAttribute(attributeName(Attribute::Report::DateLock), dateLockAttributeToString(static_cast(report.dateRange()))); + + if (report.reportType() == eMyMoney::Report::ReportType::PivotTable) { + // write report's internals + el.setAttribute(attributeName(Attribute::Report::IncludesActuals), report.isIncludingBudgetActuals()); + el.setAttribute(attributeName(Attribute::Report::IncludesForecast), report.isIncludingForecast()); + el.setAttribute(attributeName(Attribute::Report::IncludesPrice), report.isIncludingPrice()); + el.setAttribute(attributeName(Attribute::Report::IncludesAveragePrice), report.isIncludingAveragePrice()); + el.setAttribute(attributeName(Attribute::Report::MixedTime), report.isMixedTime()); + el.setAttribute(attributeName(Attribute::Report::Investments), report.isInvestmentsOnly()); // it's setable in rows/columns tab of querytable, but here it is internal setting + + // write rows/columns tab + if (!report.budget().isEmpty()) + el.setAttribute(attributeName(Attribute::Report::Budget), report.budget()); + + el.setAttribute(attributeName(Attribute::Report::RowType), reportNames(report.rowType())); + el.setAttribute(attributeName(Attribute::Report::ShowRowTotals), report.isShowingRowTotals()); + el.setAttribute(attributeName(Attribute::Report::ShowColumnTotals), report.isShowingColumnTotals()); + el.setAttribute(attributeName(Attribute::Report::Detail), reportNames(report.detailLevel())); + + el.setAttribute(attributeName(Attribute::Report::IncludesMovingAverage), report.isIncludingMovingAverage()); + if (report.isIncludingMovingAverage()) + el.setAttribute(attributeName(Attribute::Report::MovingAverageDays), report.movingAverageDays()); + + el.setAttribute(attributeName(Attribute::Report::IncludesSchedules), report.isIncludingSchedules()); + el.setAttribute(attributeName(Attribute::Report::IncludesTransfers), report.isIncludingTransfers()); + el.setAttribute(attributeName(Attribute::Report::IncludesUnused), report.isIncludingUnusedAccounts()); + el.setAttribute(attributeName(Attribute::Report::ColumnsAreDays), report.isColumnsAreDays()); + el.setAttribute(attributeName(Attribute::Report::ChartType), reportNames(report.chartType())); + el.setAttribute(attributeName(Attribute::Report::ChartCHGridLines), report.isChartCHGridLines()); + el.setAttribute(attributeName(Attribute::Report::ChartSVGridLines), report.isChartSVGridLines()); + el.setAttribute(attributeName(Attribute::Report::ChartDataLabels), report.isChartDataLabels()); + el.setAttribute(attributeName(Attribute::Report::ChartByDefault), report.isChartByDefault()); + el.setAttribute(attributeName(Attribute::Report::LogYAxis), report.isLogYAxis()); + el.setAttribute(attributeName(Attribute::Report::ChartLineWidth), report.chartLineWidth()); + el.setAttribute(attributeName(Attribute::Report::ColumnType), reportNames(report.columnType())); + el.setAttribute(attributeName(Attribute::Report::DataLock), reportNames(report.dataFilter())); + el.setAttribute(attributeName(Attribute::Report::DataRangeStart), report.dataRangeStart()); + el.setAttribute(attributeName(Attribute::Report::DataRangeEnd), report.dataRangeEnd()); + el.setAttribute(attributeName(Attribute::Report::DataMajorTick), report.dataMajorTick()); + el.setAttribute(attributeName(Attribute::Report::DataMinorTick), report.dataMinorTick()); + el.setAttribute(attributeName(Attribute::Report::YLabelsPrecision), report.yLabelsPrecision()); + } else if (report.reportType() == eMyMoney::Report::ReportType::QueryTable) { + // write rows/columns tab + el.setAttribute(attributeName(Attribute::Report::RowType), reportNames(report.rowType())); + QStringList columns; + unsigned qc = report.queryColumns(); + unsigned it_qc = eMyMoney::Report::QueryColumn::Begin; + unsigned index = 1; + while (it_qc != eMyMoney::Report::QueryColumn::End) { + if (qc & it_qc) + columns += reportNamesForQC(static_cast(it_qc)); + it_qc *= 2; + index++; + } + el.setAttribute(attributeName(Attribute::Report::QueryColumns), columns.join(",")); + + el.setAttribute(attributeName(Attribute::Report::Tax), report.isTax()); + el.setAttribute(attributeName(Attribute::Report::Investments), report.isInvestmentsOnly()); + el.setAttribute(attributeName(Attribute::Report::Loans), report.isLoansOnly()); + el.setAttribute(attributeName(Attribute::Report::HideTransactions), report.isHideTransactions()); + el.setAttribute(attributeName(Attribute::Report::ShowColumnTotals), report.isShowingColumnTotals()); + el.setAttribute(attributeName(Attribute::Report::Detail), reportNames(report.detailLevel())); + + // write performance tab + if (report.queryColumns() & eMyMoney::Report::QueryColumn::Performance || report.queryColumns() & eMyMoney::Report::QueryColumn::CapitalGain) + el.setAttribute(attributeName(Attribute::Report::InvestmentSum), static_cast(report.investmentSum())); + + // write capital gains tab + if (report.queryColumns() & eMyMoney::Report::QueryColumn::CapitalGain) { + if (report.investmentSum() == eMyMoney::Report::InvestmentSum::Sold) { + el.setAttribute(attributeName(Attribute::Report::SettlementPeriod), report.settlementPeriod()); + el.setAttribute(attributeName(Attribute::Report::ShowSTLTCapitalGains), report.isShowingSTLTCapitalGains()); + el.setAttribute(attributeName(Attribute::Report::TermsSeparator), report.termSeparator().toString(Qt::ISODate)); + } + } + } else if (report.reportType() == eMyMoney::Report::ReportType::InfoTable) + el.setAttribute(attributeName(Attribute::Report::ShowRowTotals), report.isShowingRowTotals()); + + // + // Text Filter + // + + QRegExp textfilter; + if (report.textFilter(textfilter)) { + QDomElement f = document.createElement(elementName(Element::Report::Text)); + f.setAttribute(attributeName(Attribute::Report::Pattern), textfilter.pattern()); + f.setAttribute(attributeName(Attribute::Report::CaseSensitive), (textfilter.caseSensitivity() == Qt::CaseSensitive) ? 1 : 0); + f.setAttribute(attributeName(Attribute::Report::RegEx), (textfilter.patternSyntax() == QRegExp::Wildcard) ? 1 : 0); + f.setAttribute(attributeName(Attribute::Report::InvertText), report.MyMoneyTransactionFilter::isInvertingText()); + el.appendChild(f); + } + + // + // Type & State Filters + // + QList typelist; + if (report.types(typelist) && ! typelist.empty()) { + // iterate over payees, and add each one + QList::const_iterator it_type = typelist.constBegin(); + while (it_type != typelist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::Type)); + p.setAttribute(attributeName(Attribute::Report::Type), typeAttributeToString(*it_type)); + el.appendChild(p); + + ++it_type; + } + } + + QList statelist; + if (report.states(statelist) && ! statelist.empty()) { + // iterate over payees, and add each one + QList::const_iterator it_state = statelist.constBegin(); + while (it_state != statelist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::State)); + p.setAttribute(attributeName(Attribute::Report::State), stateAttributeToString(*it_state)); + el.appendChild(p); + + ++it_state; + } + } + // + // Number Filter + // + + QString nrFrom, nrTo; + if (report.numberFilter(nrFrom, nrTo)) { + QDomElement f = document.createElement(elementName(Element::Report::Number)); + f.setAttribute(attributeName(Attribute::Report::From), nrFrom); + f.setAttribute(attributeName(Attribute::Report::To), nrTo); + el.appendChild(f); + } + + // + // Amount Filter + // + + MyMoneyMoney from, to; + if (report.amountFilter(from, to)) { // bool getAmountFilter(MyMoneyMoney&,MyMoneyMoney&); + QDomElement f = document.createElement(elementName(Element::Report::Amount)); + f.setAttribute(attributeName(Attribute::Report::From), from.toString()); + f.setAttribute(attributeName(Attribute::Report::To), to.toString()); + el.appendChild(f); + } + + // + // Payees Filter + // + + QStringList payeelist; + if (report.payees(payeelist)) { + if (payeelist.empty()) { + QDomElement p = document.createElement(elementName(Element::Report::Payee)); + el.appendChild(p); + } else { + // iterate over payees, and add each one + QStringList::const_iterator it_payee = payeelist.constBegin(); + while (it_payee != payeelist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::Payee)); + p.setAttribute(attributeName(Attribute::Report::ID), *it_payee); + el.appendChild(p); + + ++it_payee; + } + } + } + + // + // Tags Filter + // + + QStringList taglist; + if (report.tags(taglist)) { + if (taglist.empty()) { + QDomElement p = document.createElement(elementName(Element::Report::Tag)); + el.appendChild(p); + } else { + // iterate over tags, and add each one + QStringList::const_iterator it_tag = taglist.constBegin(); + while (it_tag != taglist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::Tag)); + p.setAttribute(attributeName(Attribute::Report::ID), *it_tag); + el.appendChild(p); + + ++it_tag; + } + } + } + + // + // Account Groups Filter + // + + QList accountgrouplist; + if (report.accountGroups(accountgrouplist)) { + // iterate over accounts, and add each one + QList::const_iterator it_group = accountgrouplist.constBegin(); + while (it_group != accountgrouplist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::AccountGroup)); + p.setAttribute(attributeName(Attribute::Report::Group), accountTypeAttributeToString(static_cast(*it_group))); + el.appendChild(p); + + ++it_group; + } + } + + // + // Accounts Filter + // + + QStringList accountlist; + if (report.accounts(accountlist)) { + // iterate over accounts, and add each one + QStringList::const_iterator it_account = accountlist.constBegin(); + while (it_account != accountlist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::Account)); + p.setAttribute(attributeName(Attribute::Report::ID), *it_account); + el.appendChild(p); + + ++it_account; + } + } + + // + // Categories Filter + // + + accountlist.clear(); + if (report.categories(accountlist)) { + // iterate over accounts, and add each one + QStringList::const_iterator it_account = accountlist.constBegin(); + while (it_account != accountlist.constEnd()) { + QDomElement p = document.createElement(elementName(Element::Report::Category)); + p.setAttribute(attributeName(Attribute::Report::ID), *it_account); + el.appendChild(p); + + ++it_account; + } + } + + // + // Date Filter + // + + if (report.dateRange() == eMyMoney::TransactionFilter::Date::UserDefined) { + QDate dateFrom, dateTo; + if (report.dateFilter(dateFrom, dateTo)) { + QDomElement f = document.createElement(elementName(Element::Report::Dates)); + if (dateFrom.isValid()) + f.setAttribute(attributeName(Attribute::Report::From), dateFrom.toString(Qt::ISODate)); + if (dateTo.isValid()) + f.setAttribute(attributeName(Attribute::Report::To), dateTo.toString(Qt::ISODate)); + el.appendChild(f); + } + } + + + parent.appendChild(el); + } + + MyMoneyBudget readBudget(const QDomElement &node) + { + if (nodeName(Node::Budget) != node.tagName()) + throw MYMONEYEXCEPTION_CSTRING("Node was not BUDGET"); + + MyMoneyBudget budget(node.attribute(QStringLiteral("id"))); + // The goal of this reading method is 100% backward AND 100% forward + // compatibility. Any Budget ever created with any version of KMyMoney + // should be able to be loaded by this method (as long as it's one of the + // Budget types supported in this version, of course) + + budget.setName(node.attribute(attributeName(Attribute::Budget::Name))); + budget.setBudgetStart(QDate::fromString(node.attribute(attributeName(Attribute::Budget::Start)), Qt::ISODate)); + + QDomNode child = node.firstChild(); + while (!child.isNull() && child.isElement()) { + QDomElement c = child.toElement(); + + MyMoneyBudget::AccountGroup account; + + if (elementName(Element::Budget::Account) == c.tagName()) { + if (c.hasAttribute(attributeName(Attribute::Budget::ID))) + account.setId(c.attribute(attributeName(Attribute::Budget::ID))); + + if (c.hasAttribute(attributeName(Attribute::Budget::BudgetLevel))) + account.setBudgetLevel(stringToBudgetLevel(c.attribute(attributeName(Attribute::Budget::BudgetLevel)))); + + if (c.hasAttribute(attributeName(Attribute::Budget::BudgetSubAccounts))) + account.setBudgetSubaccounts(c.attribute(attributeName(Attribute::Budget::BudgetSubAccounts)).toUInt()); + } + + QDomNode period = c.firstChild(); + while (!period.isNull() && period.isElement()) { + QDomElement per = period.toElement(); + MyMoneyBudget::PeriodGroup pGroup; + + if (elementName(Element::Budget::Period) == per.tagName() && per.hasAttribute(attributeName(Attribute::Budget::Amount)) && per.hasAttribute(attributeName(Attribute::Budget::Start))) { + pGroup.setAmount(MyMoneyMoney(per.attribute(attributeName(Attribute::Budget::Amount)))); + pGroup.setStartDate(QDate::fromString(per.attribute(attributeName(Attribute::Budget::Start)), Qt::ISODate)); + account.addPeriod(pGroup.startDate(), pGroup); + } + + period = period.nextSibling(); + } + budget.setAccount(account, account.id()); + + child = child.nextSibling(); + } + + + return budget; + } + + const int BUDGET_VERSION = 2; + + void 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); + } +} + diff --git a/kmymoney/tests/CMakeLists.txt b/kmymoney/tests/CMakeLists.txt --- a/kmymoney/tests/CMakeLists.txt +++ b/kmymoney/tests/CMakeLists.txt @@ -18,4 +18,5 @@ Qt5::Core PRIVATE mymoneystoragexml + xmlstoragehelper ) diff --git a/kmymoney/tests/testutilities.cpp b/kmymoney/tests/testutilities.cpp --- a/kmymoney/tests/testutilities.cpp +++ b/kmymoney/tests/testutilities.cpp @@ -36,6 +36,7 @@ #include "mymoneypayee.h" #include "mymoneystatement.h" #include "../mymoneystoragexml.cpp" +#include "plugins/xmlhelper/xmlstoragehelper.h" namespace test { @@ -321,10 +322,7 @@ QDomElement reports = doc->createElement("REPORTS"); root.appendChild(reports); - QDomElement report = doc->createElement("REPORT"); - filter.write(report, doc); - reports.appendChild(report); - + MyMoneyXmlContentHandler2::writeReport(filter, *doc, reports); } void writeRCFtoXML(const MyMoneyReport& filter, const QString& _filename) @@ -365,7 +363,7 @@ result = true; QDomNode subchild = child.firstChild(); while (!subchild.isNull() && subchild.isElement()) { - auto filter = MyMoneyXmlContentHandler::readReport(subchild.toElement()); + auto filter = MyMoneyXmlContentHandler2::readReport(subchild.toElement()); list += filter; subchild = subchild.nextSibling(); }