diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -7368,7 +7368,7 @@ void KMyMoneyApp::slotOnlineJobSave(onlineJob job) { MyMoneyFileTransaction fileTransaction; - if (job.id() == MyMoneyObject::emptyId()) + if (job.id().isEmpty()) MyMoneyFile::instance()->addOnlineJob(job); else MyMoneyFile::instance()->modifyOnlineJob(job); @@ -7379,7 +7379,7 @@ void KMyMoneyApp::slotOnlineJobSend(onlineJob job) { MyMoneyFileTransaction fileTransaction; - if (job.id() == MyMoneyObject::emptyId()) + if (job.id() == QString()) MyMoneyFile::instance()->addOnlineJob(job); else MyMoneyFile::instance()->modifyOnlineJob(job); @@ -7397,7 +7397,7 @@ // Sort jobs by online plugin & lock them foreach (onlineJob job, jobs) { - Q_ASSERT(job.id() != MyMoneyObject::emptyId()); + Q_ASSERT(!job.id().isEmpty()); // find the provider const MyMoneyAccount originAcc = job.responsibleMyMoneyAccount(); job.setLock(); diff --git a/kmymoney/mymoney/mymoneyaccount.h b/kmymoney/mymoney/mymoneyaccount.h --- a/kmymoney/mymoney/mymoneyaccount.h +++ b/kmymoney/mymoney/mymoneyaccount.h @@ -82,8 +82,7 @@ class MyMoneyAccountPrivate; class KMM_MYMONEY_EXPORT MyMoneyAccount : public MyMoneyObject, public MyMoneyKeyValueContainer /*, public MyMoneyPayeeIdentifierContainer */ { - Q_DECLARE_PRIVATE(MyMoneyAccount) - MyMoneyAccountPrivate* d_ptr; + Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneyAccount) KMM_MYMONEY_UNIT_TESTABLE @@ -574,8 +573,7 @@ inline void swap(MyMoneyAccount& first, MyMoneyAccount& second) // krazy:exclude=inline { using std::swap; - swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); + swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); } diff --git a/kmymoney/mymoney/mymoneyaccount.cpp b/kmymoney/mymoney/mymoneyaccount.cpp --- a/kmymoney/mymoney/mymoneyaccount.cpp +++ b/kmymoney/mymoney/mymoneyaccount.cpp @@ -54,16 +54,14 @@ using namespace Icons; MyMoneyAccount::MyMoneyAccount() : - MyMoneyObject(), - MyMoneyKeyValueContainer(), - d_ptr(new MyMoneyAccountPrivate) + MyMoneyObject(*new MyMoneyAccountPrivate), + MyMoneyKeyValueContainer() { } MyMoneyAccount::MyMoneyAccount(const QDomElement& node) : - MyMoneyObject(node), - MyMoneyKeyValueContainer(node.elementsByTagName(nodeNames[nnKeyValuePairs]).item(0).toElement()), - d_ptr(new MyMoneyAccountPrivate) + MyMoneyObject(*new MyMoneyAccountPrivate, node), + MyMoneyKeyValueContainer(node.elementsByTagName(nodeNames[nnKeyValuePairs]).item(0).toElement()) { if (nodeNames[nnAccount] != node.tagName()) throw MYMONEYEXCEPTION("Node was not ACCOUNT"); @@ -113,7 +111,7 @@ } setDescription(node.attribute(d->getAttrName(Account::Attribute::Description))); - m_id = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Account::Attribute::ID))); + d->m_id = MyMoneyUtils::QStringEmpty(node.attribute(d->getAttrName(Account::Attribute::ID))); // qDebug("Account %s has id of %s, type of %d, parent is %s.", acc.name().data(), id.data(), type, acc.parentAccountId().data()); // Process any Sub-Account information found inside the account entry. @@ -147,23 +145,19 @@ } MyMoneyAccount::MyMoneyAccount(const MyMoneyAccount& other) : - MyMoneyObject(other.id()), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneyAccountPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyAccountPrivate(*other.d_func()), other.id()), + MyMoneyKeyValueContainer(other) { } MyMoneyAccount::MyMoneyAccount(const QString& id, const MyMoneyAccount& other) : - MyMoneyObject(id), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneyAccountPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyAccountPrivate(*other.d_func()), id), + MyMoneyKeyValueContainer(other) { } MyMoneyAccount::~MyMoneyAccount() { - Q_D(MyMoneyAccount); - delete d; } void MyMoneyAccount::touch() @@ -434,11 +428,11 @@ void MyMoneyAccount::writeXML(QDomDocument& document, QDomElement& parent) const { - QDomElement el = document.createElement(nodeNames[nnAccount]); - - writeBaseXML(document, el); + auto el = document.createElement(nodeNames[nnAccount]); Q_D(const MyMoneyAccount); + d->writeBaseXML(document, el); + el.setAttribute(d->getAttrName(Account::Attribute::ParentAccount), parentAccountId()); el.setAttribute(d->getAttrName(Account::Attribute::LastReconciled), MyMoneyUtils::dateToString(lastReconciliationDate())); el.setAttribute(d->getAttrName(Account::Attribute::LastModified), MyMoneyUtils::dateToString(lastModified())); diff --git a/kmymoney/mymoney/mymoneyaccount_p.h b/kmymoney/mymoney/mymoneyaccount_p.h --- a/kmymoney/mymoney/mymoneyaccount_p.h +++ b/kmymoney/mymoney/mymoneyaccount_p.h @@ -33,6 +33,7 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneykeyvaluecontainer.h" #include "mymoneymoney.h" #include "mymoneyenums.h" @@ -70,8 +71,8 @@ } } -class MyMoneyAccountPrivate { - +class MyMoneyAccountPrivate : public MyMoneyObjectPrivate +{ public: MyMoneyAccountPrivate() : diff --git a/kmymoney/mymoney/mymoneybudget.h b/kmymoney/mymoney/mymoneybudget.h --- a/kmymoney/mymoney/mymoneybudget.h +++ b/kmymoney/mymoney/mymoneybudget.h @@ -56,7 +56,6 @@ class KMM_MYMONEY_EXPORT MyMoneyBudget: public MyMoneyObject { Q_DECLARE_PRIVATE(MyMoneyBudget) - MyMoneyBudgetPrivate* d_ptr; KMM_MYMONEY_UNIT_TESTABLE @@ -286,7 +285,6 @@ { using std::swap; swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); } inline MyMoneyBudget::MyMoneyBudget(MyMoneyBudget && other) : MyMoneyBudget() // krazy:exclude=inline diff --git a/kmymoney/mymoney/mymoneybudget.cpp b/kmymoney/mymoney/mymoneybudget.cpp --- a/kmymoney/mymoney/mymoneybudget.cpp +++ b/kmymoney/mymoney/mymoneybudget.cpp @@ -357,43 +357,38 @@ } MyMoneyBudget::MyMoneyBudget() : - d_ptr(new MyMoneyBudgetPrivate) + MyMoneyObject(*new MyMoneyBudgetPrivate) { Q_D(MyMoneyBudget); d->m_name = QLatin1Literal("Unconfigured Budget"); } MyMoneyBudget::MyMoneyBudget(const QString& name) : - d_ptr(new MyMoneyBudgetPrivate) + MyMoneyObject(*new MyMoneyBudgetPrivate) { Q_D(MyMoneyBudget); d->m_name = name; } MyMoneyBudget::MyMoneyBudget(const QDomElement& node) : - MyMoneyObject(node), - d_ptr(new MyMoneyBudgetPrivate) + MyMoneyObject(*new MyMoneyBudgetPrivate, node) { if (!read(node)) clearId(); } MyMoneyBudget::MyMoneyBudget(const QString& id, const MyMoneyBudget& other) : - MyMoneyObject(id), - d_ptr(new MyMoneyBudgetPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyBudgetPrivate(*other.d_func()), id) { } MyMoneyBudget::MyMoneyBudget(const MyMoneyBudget& other) : - MyMoneyObject(other.id()), - d_ptr(new MyMoneyBudgetPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyBudgetPrivate(*other.d_func()), other.id()) { } MyMoneyBudget::~MyMoneyBudget() { - Q_D(MyMoneyBudget); - delete d; } bool MyMoneyBudget::operator == (const MyMoneyBudget& right) const @@ -410,9 +405,9 @@ void MyMoneyBudget::write(QDomElement& e, QDomDocument *doc) const { - writeBaseXML(*doc, e); - 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); @@ -458,7 +453,7 @@ 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); - m_id = e.attribute(d->getAttrName(Budget::Attribute::ID)); + d->m_id = e.attribute(d->getAttrName(Budget::Attribute::ID)); QDomNode child = e.firstChild(); while (!child.isNull() && child.isElement()) { 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 @@ -32,6 +32,7 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneymoney.h" namespace Budget @@ -55,8 +56,8 @@ uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } } -class MyMoneyBudgetPrivate { - +class MyMoneyBudgetPrivate : public MyMoneyObjectPrivate +{ public: static QString getElName(const Budget::Element el) { diff --git a/kmymoney/mymoney/mymoneycostcenter.h b/kmymoney/mymoney/mymoneycostcenter.h --- a/kmymoney/mymoney/mymoneycostcenter.h +++ b/kmymoney/mymoney/mymoneycostcenter.h @@ -37,7 +37,6 @@ class KMM_MYMONEY_EXPORT MyMoneyCostCenter : public MyMoneyObject { Q_DECLARE_PRIVATE(MyMoneyCostCenter) - MyMoneyCostCenterPrivate* d_ptr; KMM_MYMONEY_UNIT_TESTABLE @@ -107,7 +106,6 @@ { using std::swap; swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); } inline MyMoneyCostCenter::MyMoneyCostCenter(MyMoneyCostCenter && other) : MyMoneyCostCenter() // krazy:exclude=inline diff --git a/kmymoney/mymoney/mymoneycostcenter.cpp b/kmymoney/mymoney/mymoneycostcenter.cpp --- a/kmymoney/mymoney/mymoneycostcenter.cpp +++ b/kmymoney/mymoney/mymoneycostcenter.cpp @@ -25,6 +25,7 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneyexception.h" #include "mymoneystoragenames.h" @@ -32,27 +33,26 @@ MyMoneyCostCenter MyMoneyCostCenter::null; -class MyMoneyCostCenterPrivate { - +class MyMoneyCostCenterPrivate : public MyMoneyObjectPrivate +{ public: QString m_name; }; MyMoneyCostCenter::MyMoneyCostCenter() : - d_ptr(new MyMoneyCostCenterPrivate) + MyMoneyObject(*new MyMoneyCostCenterPrivate) { } MyMoneyCostCenter::MyMoneyCostCenter(const QString& name) : - d_ptr(new MyMoneyCostCenterPrivate) + MyMoneyObject(*new MyMoneyCostCenterPrivate) { Q_D(MyMoneyCostCenter); d->m_name = name; } MyMoneyCostCenter::MyMoneyCostCenter(const QDomElement& node) : - MyMoneyObject(node), - d_ptr(new MyMoneyCostCenterPrivate) + MyMoneyObject(*new MyMoneyCostCenterPrivate, node) { if (nodeNames[nnCostCenter] != node.tagName()) throw MYMONEYEXCEPTION("Node was not COSTCENTER"); @@ -62,21 +62,17 @@ } MyMoneyCostCenter::MyMoneyCostCenter(const MyMoneyCostCenter& other) : - MyMoneyObject(other.id()), - d_ptr(new MyMoneyCostCenterPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyCostCenterPrivate(*other.d_func()), other.id()) { } MyMoneyCostCenter::MyMoneyCostCenter(const QString& id, const MyMoneyCostCenter& other) : - MyMoneyObject(id), - d_ptr(new MyMoneyCostCenterPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyCostCenterPrivate(*other.d_func()), id) { } MyMoneyCostCenter::~MyMoneyCostCenter() { - Q_D(MyMoneyCostCenter); - delete d; } bool MyMoneyCostCenter::operator == (const MyMoneyCostCenter& right) const @@ -99,9 +95,9 @@ { auto el = document.createElement(nodeNames[nnCostCenter]); - writeBaseXML(document, el); - Q_D(const MyMoneyCostCenter); + d->writeBaseXML(document, el); + el.setAttribute(getAttrName(Attribute::Name), d->m_name); parent.appendChild(el); } diff --git a/kmymoney/mymoney/mymoneyinstitution.h b/kmymoney/mymoney/mymoneyinstitution.h --- a/kmymoney/mymoney/mymoneyinstitution.h +++ b/kmymoney/mymoney/mymoneyinstitution.h @@ -43,8 +43,7 @@ class MyMoneyInstitutionPrivate; class KMM_MYMONEY_EXPORT MyMoneyInstitution : public MyMoneyObject, public MyMoneyKeyValueContainer { - Q_DECLARE_PRIVATE(MyMoneyInstitution) - MyMoneyInstitutionPrivate* d_ptr; + Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneyInstitution) KMM_MYMONEY_UNIT_TESTABLE @@ -173,8 +172,7 @@ inline void swap(MyMoneyInstitution& first, MyMoneyInstitution& second) // krazy:exclude=inline { using std::swap; - swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); + swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); } diff --git a/kmymoney/mymoney/mymoneyinstitution.cpp b/kmymoney/mymoney/mymoneyinstitution.cpp --- a/kmymoney/mymoney/mymoneyinstitution.cpp +++ b/kmymoney/mymoney/mymoneyinstitution.cpp @@ -42,9 +42,8 @@ using namespace Icons; MyMoneyInstitution::MyMoneyInstitution() : - MyMoneyObject(), - MyMoneyKeyValueContainer(), - d_ptr(new MyMoneyInstitutionPrivate) + MyMoneyObject(*new MyMoneyInstitutionPrivate), + MyMoneyKeyValueContainer() { } @@ -55,8 +54,8 @@ const QString& telephone, const QString& manager, const QString& sortcode) : - MyMoneyKeyValueContainer(), - d_ptr(new MyMoneyInstitutionPrivate) + MyMoneyObject(*new MyMoneyInstitutionPrivate), + MyMoneyKeyValueContainer() { Q_D(MyMoneyInstitution); clearId(); @@ -70,9 +69,8 @@ } MyMoneyInstitution::MyMoneyInstitution(const QDomElement& node) : - MyMoneyObject(node), - MyMoneyKeyValueContainer(node.elementsByTagName(nodeNames[nnKeyValuePairs]).item(0).toElement()), - d_ptr(new MyMoneyInstitutionPrivate) + MyMoneyObject(*new MyMoneyInstitutionPrivate, node), + MyMoneyKeyValueContainer(node.elementsByTagName(nodeNames[nnKeyValuePairs]).item(0).toElement()) { if (nodeNames[nnInstitution] != node.tagName()) throw MYMONEYEXCEPTION("Node was not INSTITUTION"); @@ -106,23 +104,19 @@ } MyMoneyInstitution::MyMoneyInstitution(const MyMoneyInstitution& other) : - MyMoneyObject(other.id()), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneyInstitutionPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyInstitutionPrivate(*other.d_func()), other.id()), + MyMoneyKeyValueContainer(other) { } MyMoneyInstitution::MyMoneyInstitution(const QString& id, const MyMoneyInstitution& other) : - MyMoneyObject(id), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneyInstitutionPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyInstitutionPrivate(*other.d_func()), id), + MyMoneyKeyValueContainer(other) { } MyMoneyInstitution::~MyMoneyInstitution() { - Q_D(MyMoneyInstitution); - delete d; } QString MyMoneyInstitution::manager() const @@ -284,11 +278,11 @@ void MyMoneyInstitution::writeXML(QDomDocument& document, QDomElement& parent) const { + Q_D(const MyMoneyInstitution); auto el = document.createElement(nodeNames[nnInstitution]); - writeBaseXML(document, el); + d->writeBaseXML(document, el); - Q_D(const MyMoneyInstitution); el.setAttribute(d->getAttrName(Institution::Attribute::Name), d->m_name); el.setAttribute(d->getAttrName(Institution::Attribute::Manager), d->m_manager); el.setAttribute(d->getAttrName(Institution::Attribute::SortCode), d->m_sortcode); diff --git a/kmymoney/mymoney/mymoneyinstitution_p.h b/kmymoney/mymoney/mymoneyinstitution_p.h --- a/kmymoney/mymoney/mymoneyinstitution_p.h +++ b/kmymoney/mymoney/mymoneyinstitution_p.h @@ -35,6 +35,8 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" + namespace Institution { enum class Element { AccountID, @@ -56,12 +58,12 @@ uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } } -class MyMoneyInstitutionPrivate { - +class MyMoneyInstitutionPrivate : public MyMoneyObjectPrivate +{ public: static QString getElName(const Institution::Element el) { - static const QMap elNames = { + static const QMap elNames { {Institution::Element::AccountID, QStringLiteral("ACCOUNTID")}, {Institution::Element::AccountIDS, QStringLiteral("ACCOUNTIDS")}, {Institution::Element::Address, QStringLiteral("ADDRESS")} @@ -71,7 +73,7 @@ static QString getAttrName(const Institution::Attribute attr) { - static const QHash attrNames = { + static const QHash attrNames { {Institution::Attribute::ID, QStringLiteral("id")}, {Institution::Attribute::Name, QStringLiteral("name")}, {Institution::Attribute::Manager, QStringLiteral("manager")}, diff --git a/kmymoney/mymoney/mymoneyobject.h b/kmymoney/mymoney/mymoneyobject.h --- a/kmymoney/mymoney/mymoneyobject.h +++ b/kmymoney/mymoney/mymoneyobject.h @@ -20,9 +20,7 @@ // ---------------------------------------------------------------------------- // QT Includes -#include -class QDomDocument; -class QDomElement; +#include // ---------------------------------------------------------------------------- // Project Includes @@ -30,6 +28,10 @@ #include "kmm_mymoney_export.h" #include "mymoneyunittestable.h" +class QString; +class QDomDocument; +class QDomElement; + /** * @author Thomas Baumgart */ @@ -37,15 +39,18 @@ /** * This class represents the base class of all MyMoney objects. */ +class MyMoneyObjectPrivate; class KMM_MYMONEY_EXPORT MyMoneyObject { + Q_DECLARE_PRIVATE(MyMoneyObject) + KMM_MYMONEY_UNIT_TESTABLE -public: - /** - * This is the constructor for the MyMoneyObject object - */ - MyMoneyObject(); + public: + /** + * This is the constructor for the MyMoneyObject object + */ + MyMoneyObject(); /** * This is the destructor for the MyMoneyObject object @@ -86,9 +91,15 @@ bool operator == (const MyMoneyObject& right) const; - static const QString& emptyId(); - protected: + MyMoneyObjectPrivate * d_ptr; + 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 * @@ -110,18 +121,7 @@ * used by objects, which are stored w/o id (eg. splits, * transactions within schedules) */ - MyMoneyObject(const QDomElement& node, const bool forceId = true); - - void setId(const QString& id); - - /** - * This method writes out the members contained in this object. - */ - void writeBaseXML(QDomDocument& document, QDomElement& el) const; - -protected: - QString m_id; - static const QString m_emptyId; + explicit MyMoneyObject(const QDomElement& node, bool forceId = true); }; #endif diff --git a/kmymoney/mymoney/mymoneyobject.cpp b/kmymoney/mymoney/mymoneyobject.cpp --- a/kmymoney/mymoney/mymoneyobject.cpp +++ b/kmymoney/mymoney/mymoneyobject.cpp @@ -15,68 +15,80 @@ ***************************************************************************/ #include "mymoneyobject.h" +#include "mymoneyobject_p.h" // ---------------------------------------------------------------------------- // QT Includes -#include -#include - // ---------------------------------------------------------------------------- // Project Includes #include "mymoneyexception.h" -const QString MyMoneyObject::m_emptyId; - -MyMoneyObject::MyMoneyObject(const QString& id) +MyMoneyObject::MyMoneyObject(const QString& id) : + d_ptr(new MyMoneyObjectPrivate) { - m_id = id; + Q_D(MyMoneyObject); + d->m_id = id; } -MyMoneyObject::MyMoneyObject(const QDomElement& el, const bool forceId) +MyMoneyObject::MyMoneyObject(const QDomElement& node, bool forceId) { - m_id = el.attribute("id"); - if (m_id.length() == 0 && forceId) + Q_D(MyMoneyObject); + d->m_id = node.attribute(QStringLiteral("id")); + if (d->m_id.length() == 0 && forceId) throw MYMONEYEXCEPTION("Node has no ID"); } -MyMoneyObject::MyMoneyObject() +MyMoneyObject::MyMoneyObject() : + d_ptr(new MyMoneyObjectPrivate) { } -MyMoneyObject::~MyMoneyObject() +MyMoneyObject::MyMoneyObject(MyMoneyObjectPrivate &dd) : + d_ptr(&dd) { } -QString MyMoneyObject::id() const +MyMoneyObject::MyMoneyObject(MyMoneyObjectPrivate &dd, + const QString& id) : + d_ptr(&dd) { - return m_id; + Q_D(MyMoneyObject); + d->m_id = id; } -void MyMoneyObject::setId(const QString& id) +MyMoneyObject::MyMoneyObject(MyMoneyObjectPrivate &dd, + const QDomElement& node, + bool forceId) : + d_ptr(&dd) { - m_id = id; + Q_D(MyMoneyObject); + d->m_id = node.attribute(QStringLiteral("id")); + if (d->m_id.length() == 0 && forceId) + throw MYMONEYEXCEPTION("Node has no ID"); } -bool MyMoneyObject::operator == (const MyMoneyObject& right) const +MyMoneyObject::~MyMoneyObject() { - return m_id == right.m_id; + Q_D(MyMoneyObject); + delete d; } -void MyMoneyObject::clearId() +QString MyMoneyObject::id() const { - m_id.clear(); + Q_D(const MyMoneyObject); + return d->m_id; } -const QString& MyMoneyObject::emptyId() +bool MyMoneyObject::operator == (const MyMoneyObject& right) const { - return m_emptyId; + Q_D(const MyMoneyObject); + return d->m_id == right.d_func()->m_id; } -void MyMoneyObject::writeBaseXML(QDomDocument& document, QDomElement& el) const +void MyMoneyObject::clearId() { - Q_UNUSED(document); - - el.setAttribute(QStringLiteral("id"), m_id); + Q_D(MyMoneyObject); + d->m_id.clear(); } diff --git a/kmymoney/mymoney/mymoneyobject_p.h b/kmymoney/mymoney/mymoneyobject_p.h new file mode 100644 --- /dev/null +++ b/kmymoney/mymoney/mymoneyobject_p.h @@ -0,0 +1,58 @@ +/*************************************************************************** + mymoneyobject_p.h + ------------------- + copyright : (C) 2005 by Thomas Baumagrt + email : ipwizard@users.sourceforge.net + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef MYMONEYOBJECT_P_H +#define MYMONEYOBJECT_P_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +class MyMoneyObjectPrivate +{ +public: + MyMoneyObjectPrivate() + { + } + + virtual ~MyMoneyObjectPrivate() + { + } + + void setId(const QString& id) + { + 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; +}; + +#endif diff --git a/kmymoney/mymoney/mymoneypayee.h b/kmymoney/mymoney/mymoneypayee.h --- a/kmymoney/mymoney/mymoneypayee.h +++ b/kmymoney/mymoney/mymoneypayee.h @@ -45,7 +45,6 @@ class KMM_MYMONEY_EXPORT MyMoneyPayee : public MyMoneyObject, public MyMoneyPayeeIdentifierContainer { Q_DECLARE_PRIVATE(MyMoneyPayee) - MyMoneyPayeePrivate* d_ptr; KMM_MYMONEY_UNIT_TESTABLE @@ -185,7 +184,6 @@ { using std::swap; swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); swap(first.m_payeeIdentifiers, second.m_payeeIdentifiers); } diff --git a/kmymoney/mymoney/mymoneypayee.cpp b/kmymoney/mymoney/mymoneypayee.cpp --- a/kmymoney/mymoney/mymoneypayee.cpp +++ b/kmymoney/mymoney/mymoneypayee.cpp @@ -38,7 +38,7 @@ MyMoneyPayee MyMoneyPayee::null; MyMoneyPayee::MyMoneyPayee() : - d_ptr(new MyMoneyPayeePrivate) + MyMoneyObject(*new MyMoneyPayeePrivate) { } @@ -49,7 +49,7 @@ const QString& postcode, const QString& telephone, const QString& email) : - d_ptr(new MyMoneyPayeePrivate) + MyMoneyObject(*new MyMoneyPayeePrivate) { Q_D(MyMoneyPayee); d->m_name = name; @@ -65,8 +65,7 @@ } MyMoneyPayee::MyMoneyPayee(const QDomElement& node) : - MyMoneyObject(node), - d_ptr(new MyMoneyPayeePrivate) + MyMoneyObject(*new MyMoneyPayeePrivate, node) { if (nodeNames[nnPayee] != node.tagName()) { throw MYMONEYEXCEPTION("Node was not PAYEE"); @@ -110,23 +109,19 @@ } MyMoneyPayee::MyMoneyPayee(const MyMoneyPayee& other) : - MyMoneyObject(other.id()), - MyMoneyPayeeIdentifierContainer(other), - d_ptr(new MyMoneyPayeePrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyPayeePrivate(*other.d_func()), other.id()), + MyMoneyPayeeIdentifierContainer(other) { } MyMoneyPayee::MyMoneyPayee(const QString& id, const MyMoneyPayee& other) : - MyMoneyObject(id), - MyMoneyPayeeIdentifierContainer(other), - d_ptr(new MyMoneyPayeePrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyPayeePrivate(*other.d_func()), id), + MyMoneyPayeeIdentifierContainer(other) { } MyMoneyPayee::~MyMoneyPayee() { - Q_D(MyMoneyPayee); - delete d; } bool MyMoneyPayee::operator == (const MyMoneyPayee& right) const @@ -166,9 +161,9 @@ { auto el = document.createElement(nodeNames[nnPayee]); - writeBaseXML(document, el); - Q_D(const MyMoneyPayee); + d->writeBaseXML(document, el); + el.setAttribute(d->getAttrName(Payee::Attribute::Name), d->m_name); el.setAttribute(d->getAttrName(Payee::Attribute::Reference), d->m_reference); el.setAttribute(d->getAttrName(Payee::Attribute::Email), d->m_email); diff --git a/kmymoney/mymoney/mymoneypayee_p.h b/kmymoney/mymoney/mymoneypayee_p.h --- a/kmymoney/mymoney/mymoneypayee_p.h +++ b/kmymoney/mymoney/mymoneypayee_p.h @@ -30,6 +30,8 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" + namespace Payee { enum class Element { Address }; @@ -56,8 +58,8 @@ uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } } -class MyMoneyPayeePrivate { - +class MyMoneyPayeePrivate : public MyMoneyObjectPrivate +{ public: MyMoneyPayeePrivate() : diff --git a/kmymoney/mymoney/mymoneyreport.h b/kmymoney/mymoney/mymoneyreport.h --- a/kmymoney/mymoney/mymoneyreport.h +++ b/kmymoney/mymoney/mymoneyreport.h @@ -64,8 +64,7 @@ class MyMoneyReportPrivate; class KMM_MYMONEY_EXPORT MyMoneyReport: public MyMoneyObject, public MyMoneyTransactionFilter { - Q_DECLARE_PRIVATE(MyMoneyReport) - MyMoneyReportPrivate* d_ptr; + Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneyReport) KMM_MYMONEY_UNIT_TESTABLE @@ -469,8 +468,7 @@ inline void swap(MyMoneyReport& first, MyMoneyReport& second) // krazy:exclude=inline { using std::swap; - swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); + swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); swap(first.MyMoneyTransactionFilter::d_ptr, second.MyMoneyTransactionFilter::d_ptr); } diff --git a/kmymoney/mymoney/mymoneyreport.cpp b/kmymoney/mymoney/mymoneyreport.cpp --- a/kmymoney/mymoney/mymoneyreport.cpp +++ b/kmymoney/mymoney/mymoneyreport.cpp @@ -63,7 +63,7 @@ const QStringList kAccountTypeText = QString("unknown,checkings,savings,cash,creditcard,loan,certificatedep,investment,moneymarket,asset,liability,currency,income,expense,assetloan,stock,equity,invalid").split(','); MyMoneyReport::MyMoneyReport() : - d_ptr(new MyMoneyReportPrivate) + MyMoneyObject(*new MyMoneyReportPrivate) { Q_D(MyMoneyReport); d->m_name = "Unconfigured Pivot Table Report"; @@ -120,7 +120,7 @@ EDetailLevel ss, const QString& name, const QString& comment) : - d_ptr(new MyMoneyReportPrivate) + MyMoneyObject(*new MyMoneyReportPrivate) { Q_D(MyMoneyReport); d->m_name = name; @@ -239,8 +239,7 @@ } MyMoneyReport::MyMoneyReport(const QDomElement& node) : - MyMoneyObject(node), - d_ptr(new MyMoneyReportPrivate) + MyMoneyObject(*new MyMoneyReportPrivate, node) { Q_D(MyMoneyReport); d->m_currentDateColumn = 0; @@ -251,16 +250,14 @@ } MyMoneyReport::MyMoneyReport(const MyMoneyReport& other) : - MyMoneyObject(other.id()), - MyMoneyTransactionFilter(other), - d_ptr(new MyMoneyReportPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyReportPrivate(*other.d_func()), other.id()), + MyMoneyTransactionFilter(other) { } MyMoneyReport::MyMoneyReport(const QString& id, const MyMoneyReport& other) : - MyMoneyObject(id), - MyMoneyTransactionFilter(other), - d_ptr(new MyMoneyReportPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyReportPrivate(*other.d_func()), id), + MyMoneyTransactionFilter(other) { Q_D(MyMoneyReport); d->m_movingAverageDays = 0; @@ -269,8 +266,6 @@ MyMoneyReport::~MyMoneyReport() { - Q_D(MyMoneyReport); - delete d; } MyMoneyReport::EReportType MyMoneyReport::reportType() const @@ -1073,11 +1068,11 @@ 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), m_id); + e.setAttribute(d->getAttrName(Report::Attribute::ID), d->m_id); // write general tab if (anonymous) { - e.setAttribute(d->getAttrName(Report::Attribute::Name), m_id); + 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); @@ -1374,7 +1369,7 @@ return false; d->m_group = e.attribute(d->getAttrName(Report::Attribute::Group)); - m_id = e.attribute(d->getAttrName(Report::Attribute::ID)); + d->m_id = e.attribute(d->getAttrName(Report::Attribute::ID)); clearTransactionFilter(); 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 @@ -35,6 +35,7 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneyenums.h" using namespace eMyMoney; @@ -79,8 +80,8 @@ uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } } -class MyMoneyReportPrivate { - +class MyMoneyReportPrivate : public MyMoneyObjectPrivate +{ public: static QString getElName(const Report::Element el) diff --git a/kmymoney/mymoney/mymoneyschedule.h b/kmymoney/mymoney/mymoneyschedule.h --- a/kmymoney/mymoney/mymoneyschedule.h +++ b/kmymoney/mymoney/mymoneyschedule.h @@ -60,7 +60,6 @@ class KMM_MYMONEY_EXPORT MyMoneySchedule : public MyMoneyObject { Q_DECLARE_PRIVATE(MyMoneySchedule) - MyMoneySchedulePrivate* d_ptr; friend class MyMoneyStorageANON; KMM_MYMONEY_UNIT_TESTABLE @@ -712,7 +711,6 @@ { using std::swap; swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); } inline MyMoneySchedule::MyMoneySchedule(MyMoneySchedule && other) : MyMoneySchedule() // krazy:exclude=inline diff --git a/kmymoney/mymoney/mymoneyschedule.cpp b/kmymoney/mymoney/mymoneyschedule.cpp --- a/kmymoney/mymoney/mymoneyschedule.cpp +++ b/kmymoney/mymoney/mymoneyschedule.cpp @@ -48,8 +48,7 @@ static IMyMoneyProcessingCalendar* processingCalendarPtr = 0; MyMoneySchedule::MyMoneySchedule() : - MyMoneyObject(), - d_ptr(new MyMoneySchedulePrivate) + MyMoneyObject(*new MyMoneySchedulePrivate) { } @@ -62,8 +61,7 @@ const QDate& endDate, bool fixed, bool autoEnter) : - MyMoneyObject(), - d_ptr(new MyMoneySchedulePrivate) + MyMoneyObject(*new MyMoneySchedulePrivate) { Q_D(MyMoneySchedule); // Set up the values possibly differeing from defaults @@ -79,8 +77,7 @@ } MyMoneySchedule::MyMoneySchedule(const QDomElement& node) : - MyMoneyObject(node), - d_ptr(new MyMoneySchedulePrivate) + MyMoneyObject(*new MyMoneySchedulePrivate, node) { if (nodeNames[nnScheduleTX] != node.tagName()) throw MYMONEYEXCEPTION("Node was not SCHEDULED_TX"); @@ -149,21 +146,17 @@ } MyMoneySchedule::MyMoneySchedule(const MyMoneySchedule& other) : - MyMoneyObject(other.id()), - d_ptr(new MyMoneySchedulePrivate(*other.d_func())) + MyMoneyObject(*new MyMoneySchedulePrivate(*other.d_func()), other.id()) { } MyMoneySchedule::MyMoneySchedule(const QString& id, const MyMoneySchedule& other) : - MyMoneyObject(id), - d_ptr(new MyMoneySchedulePrivate(*other.d_func())) + MyMoneyObject(*new MyMoneySchedulePrivate(*other.d_func()), id) { } MyMoneySchedule::~MyMoneySchedule() { - Q_D(MyMoneySchedule); - delete d; } Schedule::Occurrence MyMoneySchedule::occurrence() const @@ -453,10 +446,10 @@ * m_transaction * the transaction must contain at least one split (two is better ;-) ) */ - if (id_check && !m_id.isEmpty()) + Q_D(const MyMoneySchedule); + if (id_check && !d->m_id.isEmpty()) throw MYMONEYEXCEPTION("ID for schedule not empty when required"); - Q_D(const MyMoneySchedule); if (d->m_occurrence == Schedule::Occurrence::Any) throw MYMONEYEXCEPTION("Invalid occurrence type for schedule"); @@ -943,9 +936,9 @@ { auto el = document.createElement(nodeNames[nnScheduleTX]); - writeBaseXML(document, el); - Q_D(const MyMoneySchedule); + d->writeBaseXML(document, el); + el.setAttribute(d->getAttrName(Schedule::Attribute::Name), d->m_name); el.setAttribute(d->getAttrName(Schedule::Attribute::Type), (int)d->m_type); el.setAttribute(d->getAttrName(Schedule::Attribute::Occurrence), (int)d->m_occurrence); diff --git a/kmymoney/mymoney/mymoneyschedule_p.h b/kmymoney/mymoney/mymoneyschedule_p.h --- a/kmymoney/mymoney/mymoneyschedule_p.h +++ b/kmymoney/mymoney/mymoneyschedule_p.h @@ -30,6 +30,7 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneytransaction.h" #include "mymoneyenums.h" @@ -63,8 +64,8 @@ } } -class MyMoneySchedulePrivate { - +class MyMoneySchedulePrivate : public MyMoneyObjectPrivate +{ public: MyMoneySchedulePrivate() : m_occurrence(Schedule::Occurrence::Any) @@ -79,7 +80,7 @@ static QString getElName(const Schedule::Element el) { - static const QMap elNames = { + static const QMap elNames { {Schedule::Element::Payment, QStringLiteral("PAYMENT")}, {Schedule::Element::Payments, QStringLiteral("PAYMENTS")} }; @@ -88,7 +89,7 @@ static QString getAttrName(const Schedule::Attribute attr) { - static const QHash attrNames = { + static const QHash attrNames { {Schedule::Attribute::Name, QStringLiteral("name")}, {Schedule::Attribute::Type, QStringLiteral("type")}, {Schedule::Attribute::Occurrence, QStringLiteral("occurence")}, // krazy:exclude=spelling diff --git a/kmymoney/mymoney/mymoneysecurity.h b/kmymoney/mymoney/mymoneysecurity.h --- a/kmymoney/mymoney/mymoneysecurity.h +++ b/kmymoney/mymoney/mymoneysecurity.h @@ -58,8 +58,7 @@ class MyMoneySecurityPrivate; class KMM_MYMONEY_EXPORT MyMoneySecurity : public MyMoneyObject, public MyMoneyKeyValueContainer { - Q_DECLARE_PRIVATE(MyMoneySecurity) - MyMoneySecurityPrivate* d_ptr; + Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneySecurity) KMM_MYMONEY_UNIT_TESTABLE @@ -167,8 +166,7 @@ inline void swap(MyMoneySecurity& first, MyMoneySecurity& second) // krazy:exclude=inline { using std::swap; - swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); + swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); } diff --git a/kmymoney/mymoney/mymoneysecurity.cpp b/kmymoney/mymoney/mymoneysecurity.cpp --- a/kmymoney/mymoney/mymoneysecurity.cpp +++ b/kmymoney/mymoney/mymoneysecurity.cpp @@ -46,7 +46,7 @@ using namespace MyMoneyStorageNodes; MyMoneySecurity::MyMoneySecurity() : - d_ptr(new MyMoneySecurityPrivate) + MyMoneyObject(*new MyMoneySecurityPrivate) { } @@ -56,9 +56,8 @@ const int smallestCashFraction, const int smallestAccountFraction, const int pricePrecision) : - MyMoneyObject(id), - MyMoneyKeyValueContainer(), - d_ptr(new MyMoneySecurityPrivate) + MyMoneyObject(*new MyMoneySecurityPrivate, id), + MyMoneyKeyValueContainer() { Q_D(MyMoneySecurity); d->m_name = name; @@ -78,9 +77,8 @@ } MyMoneySecurity::MyMoneySecurity(const QDomElement& node) : - MyMoneyObject(node), - MyMoneyKeyValueContainer(node.elementsByTagName(nodeNames[nnKeyValuePairs]).item(0).toElement()), - d_ptr(new MyMoneySecurityPrivate) + MyMoneyObject(*new MyMoneySecurityPrivate, node), + MyMoneyKeyValueContainer(node.elementsByTagName(nodeNames[nnKeyValuePairs]).item(0).toElement()) { { const auto tag = node.tagName(); @@ -114,30 +112,26 @@ } MyMoneySecurity::MyMoneySecurity(const MyMoneySecurity& other) : - MyMoneyObject(other.id()), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneySecurityPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneySecurityPrivate(*other.d_func()), other.id()), + MyMoneyKeyValueContainer(other) { } MyMoneySecurity::MyMoneySecurity(const QString& id, const MyMoneySecurity& other) : - MyMoneyObject(id), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneySecurityPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneySecurityPrivate(*other.d_func()), id), + MyMoneyKeyValueContainer(other) { } MyMoneySecurity::~MyMoneySecurity() { - Q_D(MyMoneySecurity); - delete d; } bool MyMoneySecurity::operator == (const MyMoneySecurity& right) const { Q_D(const MyMoneySecurity); auto d2 = static_cast(right.d_func()); - return (m_id == right.m_id) + return (d->m_id == d2->m_id) && (d->m_name == d2->m_name) && (d->m_tradingSymbol == d2->m_tradingSymbol) && (d->m_tradingMarket == d2->m_tradingMarket) @@ -293,9 +287,9 @@ else el = document.createElement(nodeNames[nnSecurity]); - writeBaseXML(document, el); - Q_D(const MyMoneySecurity); + d->writeBaseXML(document, el); + el.setAttribute(d->getAttrName(Security::Attribute::Name), d->m_name); el.setAttribute(d->getAttrName(Security::Attribute::Symbol),d->m_tradingSymbol); el.setAttribute(d->getAttrName(Security::Attribute::Type), static_cast(d->m_securityType)); diff --git a/kmymoney/mymoney/mymoneysecurity_p.h b/kmymoney/mymoney/mymoneysecurity_p.h --- a/kmymoney/mymoney/mymoneysecurity_p.h +++ b/kmymoney/mymoney/mymoneysecurity_p.h @@ -35,6 +35,7 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include #include "mymoneyenums.h" @@ -60,8 +61,8 @@ } } -class MyMoneySecurityPrivate { - +class MyMoneySecurityPrivate : public MyMoneyObjectPrivate +{ public: MyMoneySecurityPrivate() : @@ -75,7 +76,7 @@ static QString getAttrName(const Security::Attribute attr) { - static const QHash attrNames = { + static const QHash attrNames { {Security::Attribute::Name, QStringLiteral("name")}, {Security::Attribute::Symbol, QStringLiteral("symbol")}, {Security::Attribute::Type, QStringLiteral("type")}, diff --git a/kmymoney/mymoney/mymoneysplit.h b/kmymoney/mymoney/mymoneysplit.h --- a/kmymoney/mymoney/mymoneysplit.h +++ b/kmymoney/mymoney/mymoneysplit.h @@ -60,8 +60,7 @@ class MyMoneySplitPrivate; class KMM_MYMONEY_EXPORT MyMoneySplit : public MyMoneyObject, public MyMoneyKeyValueContainer { - Q_DECLARE_PRIVATE(MyMoneySplit) - MyMoneySplitPrivate* d_ptr; + Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneySplit) KMM_MYMONEY_UNIT_TESTABLE @@ -239,8 +238,7 @@ inline void swap(MyMoneySplit& first, MyMoneySplit& second) // krazy:exclude=inline { using std::swap; - swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); + swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); } diff --git a/kmymoney/mymoney/mymoneysplit.cpp b/kmymoney/mymoney/mymoneysplit.cpp --- a/kmymoney/mymoney/mymoneysplit.cpp +++ b/kmymoney/mymoney/mymoneysplit.cpp @@ -57,16 +57,15 @@ const char MyMoneySplit::ActionInterestIncome[] = "IntIncome"; MyMoneySplit::MyMoneySplit() : -d_ptr(new MyMoneySplitPrivate) + MyMoneyObject(*new MyMoneySplitPrivate) { Q_D(MyMoneySplit); d->m_reconcileFlag = eMyMoney::Split::State::NotReconciled; } MyMoneySplit::MyMoneySplit(const QDomElement& node) : - MyMoneyObject(node, false), - MyMoneyKeyValueContainer(node.elementsByTagName(MyMoneySplitPrivate::getElName(Split::Element::KeyValuePairs)).item(0).toElement()), - d_ptr(new MyMoneySplitPrivate) + MyMoneyObject(*new MyMoneySplitPrivate, node, false), + MyMoneyKeyValueContainer(node.elementsByTagName(MyMoneySplitPrivate::getElName(Split::Element::KeyValuePairs)).item(0).toElement()) { Q_D(MyMoneySplit); if (d->getElName(Split::Element::Split) != node.tagName()) @@ -94,23 +93,19 @@ } MyMoneySplit::MyMoneySplit(const MyMoneySplit& other) : - MyMoneyObject(other.id()), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneySplitPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneySplitPrivate(*other.d_func()), other.id()), + MyMoneyKeyValueContainer(other) { } MyMoneySplit::MyMoneySplit(const QString& id, const MyMoneySplit& other) : - MyMoneyObject(id), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneySplitPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneySplitPrivate(*other.d_func()), id), + MyMoneyKeyValueContainer(other) { } MyMoneySplit::~MyMoneySplit() { - Q_D(MyMoneySplit); - delete d; } bool MyMoneySplit::operator == (const MyMoneySplit& right) const @@ -397,9 +392,9 @@ void MyMoneySplit::writeXML(QDomDocument& document, QDomElement& parent) const { Q_D(const MyMoneySplit); - QDomElement el = document.createElement(d->getElName(Split::Element::Split)); + auto el = document.createElement(d->getElName(Split::Element::Split)); - writeBaseXML(document, el); + d->writeBaseXML(document, el); el.setAttribute(d->getAttrName(Split::Attribute::Payee), d->m_payee); //el.setAttribute(getAttrName(Split::Attribute::Tag), m_tag); diff --git a/kmymoney/mymoney/mymoneysplit_p.h b/kmymoney/mymoney/mymoneysplit_p.h --- a/kmymoney/mymoney/mymoneysplit_p.h +++ b/kmymoney/mymoney/mymoneysplit_p.h @@ -38,41 +38,47 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneymoney.h" #include "mymoneyenums.h" - -namespace Split +namespace eMyMoney { - enum class Element { Split = 0, - Tag, - Match, - Container, - KeyValuePairs - }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { ID = 0, - BankID, - Account, - Payee, + namespace Split + { + enum class Element { Split = 0, Tag, - Number, - Action, - Value, - Shares, - Price, - Memo, - CostCenter, - ReconcileDate, - ReconcileFlag, - KMMatchedTx, - // insert new entries above this line - LastAttribute + Match, + Container, + KeyValuePairs }; - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } + uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } + + enum class Attribute { ID = 0, + BankID, + Account, + Payee, + Tag, + Number, + Action, + Value, + Shares, + Price, + Memo, + CostCenter, + ReconcileDate, + ReconcileFlag, + KMMatchedTx, + // insert new entries above this line + LastAttribute + }; + uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } + } } -class MyMoneySplitPrivate { +using namespace eMyMoney; + +class MyMoneySplitPrivate : public MyMoneyObjectPrivate +{ public: diff --git a/kmymoney/mymoney/mymoneytag.h b/kmymoney/mymoney/mymoneytag.h --- a/kmymoney/mymoney/mymoneytag.h +++ b/kmymoney/mymoney/mymoneytag.h @@ -40,7 +40,6 @@ class KMM_MYMONEY_EXPORT MyMoneyTag : public MyMoneyObject { Q_DECLARE_PRIVATE(MyMoneyTag) - MyMoneyTagPrivate* d_ptr; KMM_MYMONEY_UNIT_TESTABLE @@ -107,7 +106,6 @@ { using std::swap; swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); } inline MyMoneyTag::MyMoneyTag(MyMoneyTag && other) : MyMoneyTag() // krazy:exclude=inline diff --git a/kmymoney/mymoney/mymoneytag.cpp b/kmymoney/mymoney/mymoneytag.cpp --- a/kmymoney/mymoney/mymoneytag.cpp +++ b/kmymoney/mymoney/mymoneytag.cpp @@ -35,12 +35,12 @@ MyMoneyTag MyMoneyTag::null; MyMoneyTag::MyMoneyTag() : - d_ptr(new MyMoneyTagPrivate) + MyMoneyObject(*new MyMoneyTagPrivate) { } MyMoneyTag::MyMoneyTag(const QString& name) : - d_ptr(new MyMoneyTagPrivate) + MyMoneyObject(*new MyMoneyTagPrivate) { Q_D(MyMoneyTag); d->m_name = name; @@ -48,7 +48,7 @@ } MyMoneyTag::MyMoneyTag(const QString& name, const QColor& tabColor) : - d_ptr(new MyMoneyTagPrivate) + MyMoneyObject(*new MyMoneyTagPrivate) { Q_D(MyMoneyTag); d->m_name = name; @@ -56,8 +56,7 @@ } MyMoneyTag::MyMoneyTag(const QDomElement& node) : - MyMoneyObject(node), - d_ptr(new MyMoneyTagPrivate) + MyMoneyObject(*new MyMoneyTagPrivate, node) { if (nodeNames[nnTag] != node.tagName()) { throw MYMONEYEXCEPTION("Node was not TAG"); @@ -74,14 +73,12 @@ } MyMoneyTag::MyMoneyTag(const MyMoneyTag& other) : - MyMoneyObject(other.id()), - d_ptr(new MyMoneyTagPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyTagPrivate(*other.d_func()), other.id()) { } MyMoneyTag::MyMoneyTag(const QString& id, const MyMoneyTag& other) : - MyMoneyObject(id), - d_ptr(new MyMoneyTagPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyTagPrivate(*other.d_func()), id) { Q_D(MyMoneyTag); d->m_tag_color = QColor("black"); @@ -89,8 +86,6 @@ MyMoneyTag::~MyMoneyTag() { - Q_D(MyMoneyTag); - delete d; } QString MyMoneyTag::name() const @@ -162,9 +157,9 @@ { auto el = document.createElement(nodeNames[nnTag]); - writeBaseXML(document, el); - Q_D(const MyMoneyTag); + d->writeBaseXML(document, el); + el.setAttribute(d->getAttrName(Tag::Attribute::Name), d->m_name); el.setAttribute(d->getAttrName(Tag::Attribute::Closed), d->m_closed); if (d->m_tag_color.isValid()) diff --git a/kmymoney/mymoney/mymoneytag_p.h b/kmymoney/mymoney/mymoneytag_p.h --- a/kmymoney/mymoney/mymoneytag_p.h +++ b/kmymoney/mymoney/mymoneytag_p.h @@ -28,6 +28,8 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" + namespace Tag { enum class Attribute { @@ -42,7 +44,7 @@ uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } } -class MyMoneyTagPrivate +class MyMoneyTagPrivate : public MyMoneyObjectPrivate { public: diff --git a/kmymoney/mymoney/mymoneytransaction.h b/kmymoney/mymoney/mymoneytransaction.h --- a/kmymoney/mymoney/mymoneytransaction.h +++ b/kmymoney/mymoney/mymoneytransaction.h @@ -51,8 +51,7 @@ class MyMoneyTransactionPrivate; class KMM_MYMONEY_EXPORT MyMoneyTransaction : public MyMoneyObject, public MyMoneyKeyValueContainer { - Q_DECLARE_PRIVATE(MyMoneyTransaction) - MyMoneyTransactionPrivate* d_ptr; + Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneyTransaction) KMM_MYMONEY_UNIT_TESTABLE @@ -307,8 +306,7 @@ inline void swap(MyMoneyTransaction& first, MyMoneyTransaction& second) // krazy:exclude=inline { using std::swap; - swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); + swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr); swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr); } diff --git a/kmymoney/mymoney/mymoneytransaction.cpp b/kmymoney/mymoney/mymoneytransaction.cpp --- a/kmymoney/mymoney/mymoneytransaction.cpp +++ b/kmymoney/mymoney/mymoneytransaction.cpp @@ -36,8 +36,7 @@ using namespace MyMoneyStorageNodes; MyMoneyTransaction::MyMoneyTransaction() : - MyMoneyObject(), - d_ptr(new MyMoneyTransactionPrivate) + MyMoneyObject(*new MyMoneyTransactionPrivate) { Q_D(MyMoneyTransaction); d->m_nextSplitID = 1; @@ -46,8 +45,7 @@ } MyMoneyTransaction::MyMoneyTransaction(const QDomElement& node, const bool forceId) : - MyMoneyObject(node, forceId), - d_ptr(new MyMoneyTransactionPrivate) + MyMoneyObject(*new MyMoneyTransactionPrivate, node, forceId) { Q_D(MyMoneyTransaction); if (nodeNames[nnTransaction] != node.tagName()) @@ -89,16 +87,14 @@ } MyMoneyTransaction::MyMoneyTransaction(const MyMoneyTransaction& other) : - MyMoneyObject(other.id()), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneyTransactionPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyTransactionPrivate(*other.d_func()), other.id()), + MyMoneyKeyValueContainer(other) { } MyMoneyTransaction::MyMoneyTransaction(const QString& id, const MyMoneyTransaction& other) : - MyMoneyObject(id), - MyMoneyKeyValueContainer(other), - d_ptr(new MyMoneyTransactionPrivate(*other.d_func())) + MyMoneyObject(*new MyMoneyTransactionPrivate(*other.d_func()), id), + MyMoneyKeyValueContainer(other) { Q_D(MyMoneyTransaction); if (d->m_entryDate == QDate()) @@ -110,8 +106,6 @@ MyMoneyTransaction::~MyMoneyTransaction() { - Q_D(MyMoneyTransaction); - delete d; } QDate MyMoneyTransaction::entryDate() const @@ -435,7 +429,7 @@ Q_D(const MyMoneyTransaction); auto el = document.createElement(nodeNames[nnTransaction]); - writeBaseXML(document, el); + d->writeBaseXML(document, el); el.setAttribute(d->getAttrName(Transaction::Attribute::PostDate), MyMoneyUtils::dateToString(d->m_postDate)); el.setAttribute(d->getAttrName(Transaction::Attribute::Memo), d->m_memo); el.setAttribute(d->getAttrName(Transaction::Attribute::EntryDate), MyMoneyUtils::dateToString(d->m_entryDate)); @@ -497,12 +491,13 @@ QString MyMoneyTransaction::uniqueSortKey() const { + Q_D(const MyMoneyTransaction); QString year, month, day, key; - const QDate& postdate = postDate(); + const auto postdate = postDate(); year = year.setNum(postdate.year()).rightJustified(MyMoneyTransactionPrivate::YEAR_SIZE, '0'); month = month.setNum(postdate.month()).rightJustified(MyMoneyTransactionPrivate::MONTH_SIZE, '0'); day = day.setNum(postdate.day()).rightJustified(MyMoneyTransactionPrivate::DAY_SIZE, '0'); - key = QString(QLatin1String("%1-%2-%3-%4")).arg(year, month, day, m_id); + key = QString::fromLatin1("%1-%2-%3-%4").arg(year, month, day, d->m_id); return key; } diff --git a/kmymoney/mymoney/mymoneytransaction_p.h b/kmymoney/mymoney/mymoneytransaction_p.h --- a/kmymoney/mymoney/mymoneytransaction_p.h +++ b/kmymoney/mymoney/mymoneytransaction_p.h @@ -29,30 +29,35 @@ // ---------------------------------------------------------------------------- // Project Includes +#include "mymoneyobject_p.h" #include "mymoneysplit.h" - -namespace Transaction +namespace eMyMoney { - enum class Element { Split = 0, - Splits }; - uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } - - enum class Attribute { Name = 0, - Type, - PostDate, - Memo, - EntryDate, - Commodity, - BankID, - // insert new entries above this line - LastAttribute - }; - - uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } + namespace Transaction + { + enum class Element { Split = 0, + Splits }; + uint qHash(const Element key, uint seed) { return ::qHash(static_cast(key), seed); } + + enum class Attribute { Name = 0, + Type, + PostDate, + Memo, + EntryDate, + Commodity, + BankID, + // insert new entries above this line + LastAttribute + }; + + uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } + } } -class MyMoneyTransactionPrivate { +using namespace eMyMoney; +class MyMoneyTransactionPrivate : public MyMoneyObjectPrivate +{ public: static QString getElName(const Transaction::Element el) { diff --git a/kmymoney/mymoney/onlinejob.h b/kmymoney/mymoney/onlinejob.h --- a/kmymoney/mymoney/onlinejob.h +++ b/kmymoney/mymoney/onlinejob.h @@ -54,7 +54,6 @@ class KMM_MYMONEY_EXPORT onlineJob : public MyMoneyObject { Q_DECLARE_PRIVATE(onlineJob) - onlineJobPrivate* d_ptr; KMM_MYMONEY_UNIT_TESTABLE @@ -320,7 +319,6 @@ { using std::swap; swap(first.d_ptr, second.d_ptr); - swap(first.m_id, second.m_id); swap(first.m_task, second.m_task); } diff --git a/kmymoney/mymoney/onlinejob.cpp b/kmymoney/mymoney/onlinejob.cpp --- a/kmymoney/mymoney/onlinejob.cpp +++ b/kmymoney/mymoney/onlinejob.cpp @@ -32,8 +32,7 @@ using namespace MyMoneyStorageNodes; onlineJob::onlineJob() : - MyMoneyObject(), - d_ptr(new onlineJobPrivate), + MyMoneyObject(*new onlineJobPrivate), m_task(0) { Q_D(onlineJob); @@ -45,8 +44,7 @@ } onlineJob::onlineJob(onlineTask* task, const QString &id) : - MyMoneyObject(id), - d_ptr(new onlineJobPrivate), + MyMoneyObject(*new onlineJobPrivate, id), m_task(task) { Q_D(onlineJob); @@ -58,8 +56,7 @@ } onlineJob::onlineJob(onlineTask* task) : - MyMoneyObject(MyMoneyObject::m_emptyId), - d_ptr(new onlineJobPrivate), + MyMoneyObject(*new onlineJobPrivate, QString()), m_task(task) { Q_D(onlineJob); @@ -71,16 +68,14 @@ } onlineJob::onlineJob(onlineJob const& other) : - MyMoneyObject(other.id()), - d_ptr(new onlineJobPrivate(*other.d_func())), + MyMoneyObject(*new onlineJobPrivate(*other.d_func()), other.id()), m_task(0) { copyPointerFromOtherJob(other); } onlineJob::onlineJob(const QString &id, const onlineJob& other) : - MyMoneyObject(id), - d_ptr(new onlineJobPrivate(*other.d_func())), + MyMoneyObject(*new onlineJobPrivate(*other.d_func()), id), m_task() { Q_D(onlineJob); @@ -93,8 +88,7 @@ } onlineJob::onlineJob(const QDomElement& element) : - MyMoneyObject(element, true), - d_ptr(new onlineJobPrivate) + MyMoneyObject(*new onlineJobPrivate, element, true) { Q_D(onlineJob); d->m_messageList = QList(); @@ -135,8 +129,6 @@ onlineJob::~onlineJob() { - Q_D(onlineJob); - delete d; delete m_task; } @@ -280,11 +272,11 @@ /** @todo give life */ void onlineJob::writeXML(QDomDocument &document, QDomElement &parent) const { - QDomElement el = document.createElement(nodeNames[nnOnlineJob]); - writeBaseXML(document, el); - + auto el = document.createElement(nodeNames[nnOnlineJob]); Q_D(const onlineJob); + d->writeBaseXML(document, el); + if (!d->m_jobSend.isNull()) el.setAttribute(d->getAttrName(OnlineJob::Attribute::Send), d->m_jobSend.toString(Qt::ISODate)); if (!d->m_jobBankAnswerDate.isNull()) diff --git a/kmymoney/mymoney/onlinejob_p.h b/kmymoney/mymoney/onlinejob_p.h --- a/kmymoney/mymoney/onlinejob_p.h +++ b/kmymoney/mymoney/onlinejob_p.h @@ -25,6 +25,7 @@ #include #include +#include "mymoneyobject_p.h" #include "onlinejobmessage.h" namespace OnlineJob { @@ -45,12 +46,12 @@ uint qHash(const Attribute key, uint seed) { return ::qHash(static_cast(key), seed); } } -class onlineJobPrivate { - +class onlineJobPrivate : public MyMoneyObjectPrivate +{ public: static QString getElName(const OnlineJob::Element el) { - static const QMap elNames = { + static const QMap elNames { {OnlineJob::Element::OnlineTask, QStringLiteral("onlineTask")} }; return elNames[el]; @@ -58,7 +59,7 @@ static QString getAttrName(const OnlineJob::Attribute attr) { - static const QHash attrNames = { + static const QHash attrNames { {OnlineJob::Attribute::Send, QStringLiteral("send")}, {OnlineJob::Attribute::BankAnswerDate, QStringLiteral("bankAnswerDate")}, {OnlineJob::Attribute::BankAnswerState, QStringLiteral("bankAnswerState")}, diff --git a/kmymoney/mymoney/onlinejobadministration.h b/kmymoney/mymoney/onlinejobadministration.h --- a/kmymoney/mymoney/onlinejobadministration.h +++ b/kmymoney/mymoney/onlinejobadministration.h @@ -92,7 +92,7 @@ void clearCaches(); /** @brief Use onlineTask::name() to create a corresponding onlineJob */ - onlineJob createOnlineJob(const QString& name, const QString& id = MyMoneyObject::emptyId()) const; + onlineJob createOnlineJob(const QString& name, const QString& id = QString()) const; /** * @brief Return list of IonlineJobEdits diff --git a/kmymoney/mymoney/onlinejobtyped.h b/kmymoney/mymoney/onlinejobtyped.h --- a/kmymoney/mymoney/onlinejobtyped.h +++ b/kmymoney/mymoney/onlinejobtyped.h @@ -52,7 +52,7 @@ * * @throws emptyTask if task == 0 */ - explicit onlineJobTyped(T* task, const QString& id = MyMoneyObject::m_emptyId); + explicit onlineJobTyped(T* task, const QString& id = QString()); /** @brief Copy constructor */ onlineJobTyped(onlineJobTyped const& other); diff --git a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp b/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp --- a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp +++ b/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.cpp @@ -28,8 +28,10 @@ #include "mymoneytag.h" #include "mymoneypayee.h" #include "mymoneyschedule.h" +#include "mymoneyschedule_p.h" #include "mymoneyreport.h" #include "mymoneysplit.h" +#include "mymoneysplit_p.h" #include "mymoneytransaction.h" #include "mymoneybudget.h" @@ -668,7 +670,7 @@ QVERIFY(s.id().isEmpty()); t1.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.clearId(); // enable re-usage of split variable s.setAccountId("A000005"); // Salary s.setShares(MyMoneyMoney(-100000, 100)); s.setValue(MyMoneyMoney(-100000, 100)); @@ -696,28 +698,28 @@ try { // I spent some money, not so great - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000004"); // Grosseries s.setShares(MyMoneyMoney(10000, 100)); s.setValue(MyMoneyMoney(10000, 100)); QVERIFY(s.id().isEmpty()); t2.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000002"); // 16% sales tax s.setShares(MyMoneyMoney(1200, 100)); s.setValue(MyMoneyMoney(1200, 100)); QVERIFY(s.id().isEmpty()); t2.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000003"); // 7% sales tax s.setShares(MyMoneyMoney(400, 100)); s.setValue(MyMoneyMoney(400, 100)); QVERIFY(s.id().isEmpty()); t2.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000006"); // Checkings account s.setShares(MyMoneyMoney(-11600, 100)); s.setValue(MyMoneyMoney(-11600, 100)); @@ -904,7 +906,7 @@ QVERIFY(s.id().isEmpty()); t1.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000002"); s.setShares(MyMoneyMoney(400, 100)); s.setValue(MyMoneyMoney(400, 100)); @@ -1021,14 +1023,14 @@ // Create another transaction MyMoneyTransaction t1; try { - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000006"); // Checkings s.setShares(MyMoneyMoney(10000, 100)); s.setValue(MyMoneyMoney(10000, 100)); QVERIFY(s.id().isEmpty()); t1.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000005"); // Salary s.setShares(MyMoneyMoney(-10000, 100)); s.setValue(MyMoneyMoney(-10000, 100)); @@ -1856,7 +1858,7 @@ MyMoneySchedule sched; sched = m->schedule("SCH000001"); - sched.setId("SCH000002"); + sched.d_func()->setId("SCH000002"); try { m->modifySchedule(sched); QFAIL("Exception expected"); @@ -1888,7 +1890,7 @@ MyMoneySchedule sched; sched = m->schedule("SCH000001"); - sched.setId("SCH000002"); + sched.d_func()->setId("SCH000002"); try { m->removeSchedule(sched); QFAIL("Exception expected"); diff --git a/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp b/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp --- a/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp +++ b/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp @@ -28,8 +28,10 @@ #include "mymoneytag.h" #include "mymoneypayee.h" #include "mymoneyschedule.h" +#include "mymoneyschedule_p.h" #include "mymoneyreport.h" #include "mymoneysplit.h" +#include "mymoneysplit_p.h" #include "mymoneytransaction.h" #include "mymoneybudget.h" #include "mymoneyprice.h" @@ -523,7 +525,7 @@ QVERIFY(s.id().isEmpty()); t1.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000005"); // Salary s.setShares(MyMoneyMoney(-100000, 100)); s.setValue(MyMoneyMoney(-100000, 100)); @@ -550,28 +552,28 @@ try { // I spent some money, not so great - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000004"); // Grosseries s.setShares(MyMoneyMoney(10000, 100)); s.setValue(MyMoneyMoney(10000, 100)); QVERIFY(s.id().isEmpty()); t2.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000002"); // 16% sales tax s.setShares(MyMoneyMoney(1200, 100)); s.setValue(MyMoneyMoney(1200, 100)); QVERIFY(s.id().isEmpty()); t2.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000003"); // 7% sales tax s.setShares(MyMoneyMoney(400, 100)); s.setValue(MyMoneyMoney(400, 100)); QVERIFY(s.id().isEmpty()); t2.addSplit(s); - s.setId(QString()); // enable re-usage of split variable + s.d_func()->setId(QString()); // enable re-usage of split variable s.setAccountId("A000006"); // Checkings account s.setShares(MyMoneyMoney(-11600, 100)); s.setValue(MyMoneyMoney(-11600, 100)); @@ -1348,7 +1350,7 @@ MyMoneySchedule sched; sched = m->schedule("SCH000001"); - sched.setId("SCH000002"); + sched.d_func()->setId("SCH000002"); try { m->modifySchedule(sched); QFAIL("Exception expected"); @@ -1376,7 +1378,7 @@ MyMoneySchedule sched; sched = m->schedule("SCH000001"); - sched.setId("SCH000002"); + sched.d_func()->setId("SCH000002"); try { m->removeSchedule(sched); m->commitTransaction(); diff --git a/kmymoney/mymoney/tests/mymoneyaccount-test.cpp b/kmymoney/mymoney/tests/mymoneyaccount-test.cpp --- a/kmymoney/mymoney/tests/mymoneyaccount-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyaccount-test.cpp @@ -224,7 +224,7 @@ a.setLastReconciliationDate(QDate::currentDate()); a.setAccountType(eMyMoney::Account::Type::Asset); a.setParentAccountId("P-ID"); - a.setId("A-ID"); + a.d_func()->setId("A-ID"); a.setCurrencyId("C-ID"); a.setValue("Key", "Value"); @@ -269,7 +269,7 @@ QVERIFY(!(b == a)); b = a; - a.setId("A-noID"); + a.d_func()->setId("A-noID"); QVERIFY(!(b == a)); b = a; 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 @@ -20,21 +20,45 @@ #include #include +#include "mymoneyobject_p.h" #include "mymoneyexception.h" #include "mymoneyaccount.h" +class TestMyMoneyObjectPrivate : public MyMoneyObjectPrivate +{ +public: + TestMyMoneyObjectPrivate() + { + } +}; class TestMyMoneyObject : public MyMoneyObject { + Q_DECLARE_PRIVATE(TestMyMoneyObject) public: - TestMyMoneyObject() : MyMoneyObject() {} + 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(node, forceId) {} + MyMoneyObject(*new MyMoneyObjectPrivate, node, forceId) {} virtual bool hasReferenceTo(const QString&) const { return false; } virtual void writeXML(QDomDocument&, QDomElement&) const {} }; +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() diff --git a/kmymoney/mymoney/tests/mymoneypayee-test.cpp b/kmymoney/mymoney/tests/mymoneypayee-test.cpp --- a/kmymoney/mymoney/tests/mymoneypayee-test.cpp +++ b/kmymoney/mymoney/tests/mymoneypayee-test.cpp @@ -33,7 +33,7 @@ QDomElement parent = doc.createElement("Test"); doc.appendChild(parent); MyMoneyPayee payee1; - payee1.m_id = "some random id";//if the ID isn't set, w ethrow an exception + payee1.d_func()->m_id = "some random id";//if the ID isn't set, w ethrow an exception payee1.writeXML(doc, parent); QString temp1 = "Account1"; payee1.setDefaultAccountId(temp1); diff --git a/kmymoney/mymoney/tests/mymoneyschedule-test.cpp b/kmymoney/mymoney/tests/mymoneyschedule-test.cpp --- a/kmymoney/mymoney/tests/mymoneyschedule-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyschedule-test.cpp @@ -29,6 +29,7 @@ #include "mymoneyschedule_p.h" #include "mymoneyfile.h" #include "mymoneytransaction.h" +#include "mymoneytransaction_p.h" #include "storage/mymoneyseqaccessmgr.h" QTEST_GUILESS_MAIN(MyMoneyScheduleTest) @@ -81,7 +82,7 @@ { MyMoneySchedule s; - s.setId("SCHED001"); + s.d_func()->setId("SCHED001"); QCOMPARE(s.id(), QLatin1String("SCHED001")); s.setType(Schedule::Type::Bill); @@ -96,7 +97,7 @@ { MyMoneySchedule s; - s.setId("SCHED001"); + s.d_func()->setId("SCHED001"); s.setType(Schedule::Type::Bill); MyMoneySchedule s2(s); @@ -109,7 +110,7 @@ { MyMoneySchedule s; - s.setId("SCHED001"); + s.d_func()->setId("SCHED001"); s.setType(Schedule::Type::Bill); MyMoneySchedule s2 = s; @@ -720,12 +721,12 @@ sch.setLastPayment(QDate::currentDate()); sch.recordPayment(QDate::currentDate()); - sch.setId("SCH0001"); + sch.d_func()->setId("SCH0001"); MyMoneyTransaction t; t.setPostDate(QDate(2001, 12, 28)); t.setEntryDate(QDate(2003, 9, 29)); - t.setId("T000000000000000001"); + t.d_func()->setId("T000000000000000001"); t.setMemo("Wohnung:Miete"); t.setCommodity("EUR"); t.setValue("key", "value"); diff --git a/kmymoney/mymoney/tests/mymoneysplit-test.cpp b/kmymoney/mymoney/tests/mymoneysplit-test.cpp --- a/kmymoney/mymoney/tests/mymoneysplit-test.cpp +++ b/kmymoney/mymoney/tests/mymoneysplit-test.cpp @@ -63,7 +63,7 @@ m->setReconcileFlag(eMyMoney::Split::State::Cleared); m->setShares(MyMoneyMoney(1234, 100)); m->setValue(MyMoneyMoney(3456, 100)); - m->setId("MyID"); + m->d_func()->setId("MyID"); m->setPayeeId("Payee"); m->setCostCenterId("CostCenter"); QList tagIdList; @@ -156,7 +156,7 @@ QVERIFY(!(n == *m)); n = *m; - n.setId("Not My ID"); + n.d_func()->setId("Not My ID"); QVERIFY(!(n == *m)); n = *m; diff --git a/kmymoney/mymoney/tests/mymoneytag-test.cpp b/kmymoney/mymoney/tests/mymoneytag-test.cpp --- a/kmymoney/mymoney/tests/mymoneytag-test.cpp +++ b/kmymoney/mymoney/tests/mymoneytag-test.cpp @@ -33,7 +33,7 @@ QDomElement parent = doc.createElement("Test"); doc.appendChild(parent); MyMoneyTag tag1; - tag1.m_id = "some random id";//if the ID isn't set, w ethrow an exception + tag1.d_func()->m_id = "some random id";//if the ID isn't set, w ethrow an exception tag1.writeXML(doc, parent); QDomElement el = parent.firstChild().toElement(); QVERIFY(!el.isNull()); diff --git a/kmymoney/mymoney/tests/mymoneytransaction-test.cpp b/kmymoney/mymoney/tests/mymoneytransaction-test.cpp --- a/kmymoney/mymoney/tests/mymoneytransaction-test.cpp +++ b/kmymoney/mymoney/tests/mymoneytransaction-test.cpp @@ -25,6 +25,7 @@ #include "mymoneytestutils.h" #include "mymoneymoney.h" #include "mymoneysplit.h" +#include "mymoneysplit_p.h" #include "mymoneytransaction.h" #include "mymoneytransaction_p.h" #include "mymoneyenums.h" @@ -129,7 +130,7 @@ void MyMoneyTransactionTest::testAddSplits() { - m->setId("TestID"); + m->d_func()->setId("TestID"); MyMoneySplit split1, split2; split1.setAccountId("A000001"); split2.setAccountId("A000002"); @@ -175,7 +176,7 @@ split = m->splits()[0]; split.setAccountId("A000003"); - split.setId("S00000000"); + split.d_func()->setId("S00000000"); // this one should fail, because the ID is invalid try { @@ -185,7 +186,7 @@ } // set id to correct value, and check that it worked - split.setId("S0001"); + split.d_func()->setId("S0001"); try { m->modifySplit(split); QVERIFY(m->splitCount() == 2); @@ -218,7 +219,7 @@ QFAIL("Unexpected exception!"); } - split.setId("S00000000"); + split.d_func()->setId("S00000000"); // this one should fail, because the ID is invalid try { m->modifySplit(split); @@ -227,7 +228,7 @@ } // set id to correct value, and check that it worked - split.setId("S0002"); + split.d_func()->setId("S0002"); try { m->removeSplit(split); QVERIFY(m->splitCount() == 2); @@ -242,7 +243,7 @@ } // set id to the other correct value, and check that it worked - split.setId("S0003"); + split.d_func()->setId("S0003"); try { m->removeSplit(split); QVERIFY(m->splitCount() == 1); @@ -413,7 +414,7 @@ MyMoneyTransaction t; t.setPostDate(QDate(2001, 12, 28)); t.setEntryDate(QDate(2003, 9, 29)); - t.setId("T000000000000000001"); + t.d_func()->setId("T000000000000000001"); t.setMemo("Wohnung:Miete"); t.setCommodity("EUR"); t.setValue("key", "value"); @@ -613,7 +614,7 @@ MyMoneyTransaction t; t.setPostDate(QDate(2001, 12, 28)); t.setEntryDate(QDate(2003, 9, 29)); - t.setId("T000000000000000001"); + t.d_func()->setId("T000000000000000001"); t.setMemo("Wohnung:Miete"); t.setCommodity("EUR"); t.setValue("key", "value"); diff --git a/kmymoney/mymoney/tests/onlinejob-test.cpp b/kmymoney/mymoney/tests/onlinejob-test.cpp --- a/kmymoney/mymoney/tests/onlinejob-test.cpp +++ b/kmymoney/mymoney/tests/onlinejob-test.cpp @@ -32,7 +32,7 @@ void onlineJobTest::testDefaultConstructor() { const onlineJob job = onlineJob(); - QVERIFY(job.id() == MyMoneyObject::emptyId()); + QCOMPARE(job.id(), QString()); QVERIFY(job.isNull()); QVERIFY(job.sendDate().isNull()); QVERIFY(job.bankAnswerDate().isNull()); diff --git a/kmymoney/widgets/registeritem.h b/kmymoney/widgets/registeritem.h --- a/kmymoney/widgets/registeritem.h +++ b/kmymoney/widgets/registeritem.h @@ -137,7 +137,7 @@ virtual void paintRegisterCell(QPainter *painter, QStyleOptionViewItem &option, const QModelIndex &index) = 0; virtual void paintFormCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) = 0; - virtual const QString& id() const; + virtual QString id() const; /** * Sets the parent of this item to be the register @p parent diff --git a/kmymoney/widgets/registeritem.cpp b/kmymoney/widgets/registeritem.cpp --- a/kmymoney/widgets/registeritem.cpp +++ b/kmymoney/widgets/registeritem.cpp @@ -157,9 +157,9 @@ return d->m_startRow; } -const QString& RegisterItem::id() const +QString RegisterItem::id() const { - return MyMoneyObject::emptyId(); + return QString(); } void RegisterItem::setParent(Register* parent) diff --git a/kmymoney/widgets/transaction.h b/kmymoney/widgets/transaction.h --- a/kmymoney/widgets/transaction.h +++ b/kmymoney/widgets/transaction.h @@ -83,7 +83,7 @@ virtual eWidgets::eRegister::CashFlowDirection sortType() const override; virtual const QString& sortCategory() const override; virtual eMyMoney::Split::State sortReconcileState() const override; - virtual const QString& id() const override; + virtual QString id() const override; const MyMoneyTransaction& transaction() const; const MyMoneySplit& split() const; void setBalance(const MyMoneyMoney& balance); diff --git a/kmymoney/widgets/transaction.cpp b/kmymoney/widgets/transaction.cpp --- a/kmymoney/widgets/transaction.cpp +++ b/kmymoney/widgets/transaction.cpp @@ -307,7 +307,7 @@ return d->m_split.reconcileFlag(); } -const QString& Transaction::id() const +QString Transaction::id() const { Q_D(const Transaction); return d->m_uniqueId;