diff --git a/kmymoney/converter/tests/converter-test.h b/kmymoney/converter/tests/converter-test.h --- a/kmymoney/converter/tests/converter-test.h +++ b/kmymoney/converter/tests/converter-test.h @@ -21,14 +21,14 @@ #include #include "mymoneyfile.h" -#include "storage/mymoneyseqaccessmgr.h" +#include "storage/mymoneystoragemgr.h" class ConverterTest : public QObject { Q_OBJECT private: - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; private Q_SLOTS: diff --git a/kmymoney/converter/tests/converter-test.cpp b/kmymoney/converter/tests/converter-test.cpp --- a/kmymoney/converter/tests/converter-test.cpp +++ b/kmymoney/converter/tests/converter-test.cpp @@ -41,7 +41,7 @@ void ConverterTest::init() { - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file = MyMoneyFile::instance(); file->attachStorage(storage); diff --git a/kmymoney/converter/tests/matchfinder-test.h b/kmymoney/converter/tests/matchfinder-test.h --- a/kmymoney/converter/tests/matchfinder-test.h +++ b/kmymoney/converter/tests/matchfinder-test.h @@ -22,7 +22,7 @@ #include "mymoneyaccount.h" #include "mymoneypayee.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" #include "existingtransactionmatchfinder.h" #include "scheduledtransactionmatchfinder.h" @@ -36,7 +36,7 @@ MyMoneyFile * file; QScopedPointer account; QScopedPointer otherAccount; - QScopedPointer storage; + QScopedPointer storage; MyMoneyPayee payee; MyMoneyPayee otherPayee; static const int MATCH_WINDOW = 4; diff --git a/kmymoney/converter/tests/matchfinder-test.cpp b/kmymoney/converter/tests/matchfinder-test.cpp --- a/kmymoney/converter/tests/matchfinder-test.cpp +++ b/kmymoney/converter/tests/matchfinder-test.cpp @@ -50,7 +50,7 @@ void MatchFinderTest::setupStorage() { - storage.reset(new MyMoneySeqAccessMgr); + storage.reset(new MyMoneyStorageMgr); file->attachStorage(storage.data()); } diff --git a/kmymoney/dialogs/kgeneratesqldlg.cpp b/kmymoney/dialogs/kgeneratesqldlg.cpp --- a/kmymoney/dialogs/kgeneratesqldlg.cpp +++ b/kmymoney/dialogs/kgeneratesqldlg.cpp @@ -50,7 +50,7 @@ #include "mymoneyexception.h" #include "mymoneyfile.h" -#include "storage/mymoneyseqaccessmgr.h" +#include "storage/mymoneystoragemgr.h" #include "kguiutils.h" #include "misc/platformtools.h" #include "mymoneydbdriver.h" @@ -133,7 +133,7 @@ bool m_sqliteSelected; QExplicitlySharedDataPointer m_dbDriver; QString m_dbName; - MyMoneySeqAccessMgr* m_storage; + MyMoneyStorageMgr* m_storage; bool m_mustDetachStorage; }; @@ -315,7 +315,7 @@ d->ui->textSQL->setEnabled(true); // check if we have a storage; if not, create a skeleton one // we need a storage for MyMoneyDbDef to generate standard accounts - d->m_storage = new MyMoneySeqAccessMgr; + d->m_storage = new MyMoneyStorageMgr; d->m_mustDetachStorage = true; try { MyMoneyFile::instance()->attachStorage(d->m_storage); diff --git a/kmymoney/dialogs/kmymoneyfileinfodlg.cpp b/kmymoney/dialogs/kmymoneyfileinfodlg.cpp --- a/kmymoney/dialogs/kmymoneyfileinfodlg.cpp +++ b/kmymoney/dialogs/kmymoneyfileinfodlg.cpp @@ -33,7 +33,7 @@ #include "ui_kmymoneyfileinfodlg.h" -#include +#include "mymoneystoragemgr.h" #include "mymoneyfile.h" #include "mymoneyinstitution.h" #include "mymoneyaccount.h" diff --git a/kmymoney/kmymoney.h b/kmymoney/kmymoney.h --- a/kmymoney/kmymoney.h +++ b/kmymoney/kmymoney.h @@ -127,11 +127,6 @@ */ void slotEnableMessages(); - /** - * Called when the user asks for file information. - */ - void slotFileFileInfo(); - /** * Called to run performance test. */ @@ -143,6 +138,11 @@ void slotGenerateSql(); #ifdef KMM_DEBUG + /** + * Called when the user asks for file information. + */ + void slotFileFileInfo(); + /** * Debugging only: turn on/off traces */ @@ -529,7 +529,7 @@ */ void slotEquityPriceUpdate(); - void slotOnlineAccountRequested(const MyMoneyAccount& acc, eMenu::Action action); + void slotOnlineAccountRequested(const MyMoneyAccount& acc, eMenu::Action action); /** * This slot reparents account @p src to be a child of account @p dest diff --git a/kmymoney/kmymoney.cpp b/kmymoney/kmymoney.cpp --- a/kmymoney/kmymoney.cpp +++ b/kmymoney/kmymoney.cpp @@ -130,8 +130,6 @@ #include "mymoney/mymoneysplit.h" #include "mymoney/mymoneyutils.h" #include "mymoney/mymoneystatement.h" -#include "mymoney/storage/mymoneystoragedump.h" -#include "mymoney/storage/imymoneystorage.h" #include "mymoney/mymoneyforecast.h" #include "mymoney/mymoneytransactionfilter.h" @@ -153,7 +151,7 @@ #include "misc/webconnect.h" -#include "storage/imymoneyserialize.h" +#include "storage/mymoneystoragemgr.h" #include "storage/mymoneystoragesql.h" #include @@ -179,6 +177,7 @@ #include "widgets_config.h" #ifdef KMM_DEBUG +#include "mymoney/storage/mymoneystoragedump.h" #include "mymoneytracer.h" #endif @@ -1011,8 +1010,8 @@ return saved; } } - if (d->m_myMoneyView->isDatabase()) - slotFileClose(); // close off the database +// if (d->m_myMoneyView->isDatabase()) +// slotFileClose(); // close off the database saveOptions(); return true; } @@ -1403,11 +1402,11 @@ d->consistencyCheck(false); - /*if (myMoneyView->isDatabase()) { - rc = myMoneyView->saveDatabase(m_fileName); - // the 'save' function is no longer relevant for a database*/ setEnabled(false); - rc = d->m_myMoneyView->saveFile(d->m_fileName, MyMoneyFile::instance()->value("kmm-encryption-key")); + if (d->m_myMoneyView->isDatabase()) + rc = d->m_myMoneyView->saveDatabase(d->m_fileName); + else + rc = d->m_myMoneyView->saveFile(d->m_fileName, MyMoneyFile::instance()->value("kmm-encryption-key")); setEnabled(true); d->m_autoSaveTimer->stop(); @@ -1453,9 +1452,6 @@ bool KMyMoneyApp::slotFileSaveAs() { bool rc = false; - // in event of it being a database, ensure that all data is read into storage for saveas - if (d->m_myMoneyView->isDatabase()) - dynamic_cast(MyMoneyFile::instance()->storage())->fillStorage(); KMSTATUS(i18n("Saving file with a new filename...")); // fill the additional key list with the default @@ -1581,10 +1577,9 @@ bool rc = false; QUrl oldUrl; // in event of it being a database, ensure that all data is read into storage for saveas - if (d->m_myMoneyView->isDatabase()) { - dynamic_cast(MyMoneyFile::instance()->storage())->fillStorage(); + if (d->m_myMoneyView->isDatabase()) oldUrl = d->m_fileName.isEmpty() ? lastOpenedURL() : d->m_fileName; - } + KMSTATUS(i18n("Saving file to database...")); QPointer dialog = new KSelectDatabaseDlg(QIODevice::WriteOnly); QUrl url = oldUrl; @@ -1710,6 +1705,21 @@ } #ifdef KMM_DEBUG +void KMyMoneyApp::slotFileFileInfo() +{ + if (!d->m_myMoneyView->fileOpen()) { + KMessageBox::information(this, i18n("No KMyMoneyFile open")); + return; + } + + QFile g("kmymoney.dump"); + g.open(QIODevice::WriteOnly); + QDataStream st(&g); + MyMoneyStorageDump dumper; + dumper.writeStream(st, MyMoneyFile::instance()->storage()); + g.close(); +} + void KMyMoneyApp::slotToggleTraces() { MyMoneyTracer::onOff(pActions[Action::DebugTraces]->isChecked() ? 1 : 0); @@ -1825,21 +1835,6 @@ delete editPersonalDataDlg; } -void KMyMoneyApp::slotFileFileInfo() -{ - if (!d->m_myMoneyView->fileOpen()) { - KMessageBox::information(this, i18n("No KMyMoneyFile open")); - return; - } - - QFile g("kmymoney.dump"); - g.open(QIODevice::WriteOnly); - QDataStream st(&g); - MyMoneyStorageDump dumper; - dumper.writeStream(st, dynamic_cast(MyMoneyFile::instance()->storage())); - g.close(); -} - void KMyMoneyApp::slotLoadAccountTemplates() { KMSTATUS(i18n("Importing account templates.")); @@ -2652,7 +2647,7 @@ // ************* // Disabling standard actions based on conditions // ************* - aC->action(QString::fromLatin1(KStandardAction::name(KStandardAction::Save)))->setEnabled(modified && !d->m_myMoneyView->isDatabase()); + aC->action(QString::fromLatin1(KStandardAction::name(KStandardAction::Save)))->setEnabled(modified /*&& !d->m_myMoneyView->isDatabase()*/); aC->action(QString::fromLatin1(KStandardAction::name(KStandardAction::SaveAs)))->setEnabled(fileOpen); aC->action(QString::fromLatin1(KStandardAction::name(KStandardAction::Close)))->setEnabled(fileOpen); aC->action(QString::fromLatin1(KStandardAction::name(KStandardAction::Print)))->setEnabled(fileOpen && d->m_myMoneyView->canPrint()); diff --git a/kmymoney/mymoney/mymoneyfile.h b/kmymoney/mymoney/mymoneyfile.h --- a/kmymoney/mymoney/mymoneyfile.h +++ b/kmymoney/mymoney/mymoneyfile.h @@ -53,13 +53,13 @@ * As the MyMoneyFile object represents the business logic, a storage * manager must be attached to it. This mechanism allows to use different * access methods to store the objects. The interface to access such an - * storage manager is defined in the class IMyMoneyStorage. The methods + * storage manager is defined in the class MyMoneyStorageMgr. The methods * attachStorage() and detachStorage() are used to attach/detach a * storage manager object. The following code can be used to create a * functional MyMoneyFile instance: * * @code - * IMyMoneyStorage *storage = .... + * MyMoneyStorageMgr *storage = .... * MyMoneyFile *file = MyMoneyFile::instance(); * file->attachStorage(storage); * @endcode @@ -121,7 +121,7 @@ class QString; class QStringList; class QBitArray; -class IMyMoneyStorage; +class MyMoneyStorageMgr; class MyMoneyCostCenter; class MyMoneyAccount; class MyMoneyInstitution; @@ -173,10 +173,10 @@ * @deprecated This is a convenience constructor. Do not use it anymore. * It will be deprecated in a future version of the engine. * - * @param storage pointer to object that implements the IMyMoneyStorage + * @param storage pointer to object that implements the MyMoneyStorageMgr * interface. */ - explicit MyMoneyFile(IMyMoneyStorage *storage); + explicit MyMoneyFile(MyMoneyStorageMgr *storage); // general get functions MyMoneyPayee user() const; @@ -198,24 +198,24 @@ * - there is no other @a storage object attached (use detachStorage() * to revert the attachStorage() operation. * - * @param storage pointer to object that implements the IMyMoneyStorage + * @param storage pointer to object that implements the MyMoneyStorageMgr * interface. * * @sa detachStorage() */ - void attachStorage(IMyMoneyStorage* const storage); + void attachStorage(MyMoneyStorageMgr* const storage); /** * This method is used to detach a previously attached storage * object from the MyMoneyFile object. If no storage object * is attached to the engine, this is a NOP. * - * @param storage pointer to object that implements the IMyMoneyStorage + * @param storage pointer to object that implements the MyMoneyStorageMgr * interface. * * @sa attachStorage() */ - void detachStorage(IMyMoneyStorage* const storage = 0); + void detachStorage(MyMoneyStorageMgr* const storage = 0); /** * This method returns whether a storage is currently attached to @@ -231,7 +231,7 @@ * @return const pointer to the current attached storage object. * If no object is attached, returns 0. */ - IMyMoneyStorage* storage() const; + MyMoneyStorageMgr* storage() const; /** * This method must be called before any single change or a series of changes diff --git a/kmymoney/mymoney/mymoneyfile.cpp b/kmymoney/mymoney/mymoneyfile.cpp --- a/kmymoney/mymoney/mymoneyfile.cpp +++ b/kmymoney/mymoney/mymoneyfile.cpp @@ -36,7 +36,8 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "imymoneystorage.h" + +#include "mymoneystoragemgr.h" #include "mymoneyinstitution.h" #include "mymoneyaccount.h" #include "mymoneyaccountloan.h" @@ -254,7 +255,7 @@ /** * This member points to the storage strategy */ - IMyMoneyStorage *m_storage; + MyMoneyStorageMgr *m_storage; bool m_inTransaction; @@ -341,7 +342,7 @@ delete d; } -MyMoneyFile::MyMoneyFile(IMyMoneyStorage *storage) : +MyMoneyFile::MyMoneyFile(MyMoneyStorageMgr *storage) : d(new Private) { attachStorage(storage); @@ -352,7 +353,7 @@ return &file; } -void MyMoneyFile::attachStorage(IMyMoneyStorage* const storage) +void MyMoneyFile::attachStorage(MyMoneyStorageMgr* const storage) { if (d->m_storage != 0) throw MYMONEYEXCEPTION("Storage already attached"); @@ -377,7 +378,7 @@ emit endChangeNotification(); } -void MyMoneyFile::detachStorage(IMyMoneyStorage* const /* storage */) +void MyMoneyFile::detachStorage(MyMoneyStorageMgr* const /* storage */) { d->m_balanceCache.clear(); d->m_cache.clear(); @@ -385,7 +386,7 @@ d->m_storage = 0; } -IMyMoneyStorage* MyMoneyFile::storage() const +MyMoneyStorageMgr* MyMoneyFile::storage() const { return d->m_storage; } diff --git a/kmymoney/mymoney/mymoneyobjectcontainer.h b/kmymoney/mymoney/mymoneyobjectcontainer.h --- a/kmymoney/mymoney/mymoneyobjectcontainer.h +++ b/kmymoney/mymoney/mymoneyobjectcontainer.h @@ -36,7 +36,7 @@ /** * This class represents a generic container for all MyMoneyObject derived objects. */ -class IMyMoneyStorage; +class MyMoneyStorageMgr; class MyMoneyObject; class MyMoneyInstitution; class MyMoneyAccount; @@ -85,7 +85,7 @@ void preloadOnlineJob(const onlineJob& job); void clear(const QString& id); - void clear(IMyMoneyStorage* storage = 0); + void clear(MyMoneyStorageMgr* storage = 0); MyMoneyAccount accountByName(const QString& name) const; diff --git a/kmymoney/mymoney/mymoneyobjectcontainer.cpp b/kmymoney/mymoney/mymoneyobjectcontainer.cpp --- a/kmymoney/mymoney/mymoneyobjectcontainer.cpp +++ b/kmymoney/mymoney/mymoneyobjectcontainer.cpp @@ -24,7 +24,7 @@ #include "mymoney/onlinejob.h" -#include "imymoneystorage.h" +#include "mymoneystoragemgr.h" #include "mymoneyinstitution.h" #include "mymoneyaccount.h" #include "mymoneysecurity.h" @@ -133,7 +133,7 @@ QHash onlineJobCache; QHash costCenterCache; - IMyMoneyStorage* storage; + MyMoneyStorageMgr* storage; MyMoneyObjectContainer *pub; }; @@ -147,7 +147,7 @@ delete d; } -void MyMoneyObjectContainer::clear(IMyMoneyStorage* storage) +void MyMoneyObjectContainer::clear(MyMoneyStorageMgr* storage) { d->clearCache(d->accountCache); d->clearCache(d->payeeCache); @@ -254,19 +254,19 @@ if (id.isEmpty()) return; - if (d->refreshObject(id, d->accountCache, &IMyMoneyStorage::account)) + if (d->refreshObject(id, d->accountCache, &MyMoneyStorageMgr::account)) return; - if (d->refreshObject(id, d->payeeCache, &IMyMoneyStorage::payee)) + if (d->refreshObject(id, d->payeeCache, &MyMoneyStorageMgr::payee)) return; - if (d->refreshObject(id, d->tagCache, &IMyMoneyStorage::tag)) + if (d->refreshObject(id, d->tagCache, &MyMoneyStorageMgr::tag)) return; - if (d->refreshObject(id, d->institutionCache, &IMyMoneyStorage::institution)) + if (d->refreshObject(id, d->institutionCache, &MyMoneyStorageMgr::institution)) return; - if (d->refreshObject(id, d->scheduleCache, &IMyMoneyStorage::schedule)) + if (d->refreshObject(id, d->scheduleCache, &MyMoneyStorageMgr::schedule)) return; - if (d->refreshObject(id, d->onlineJobCache, &IMyMoneyStorage::getOnlineJob)) + if (d->refreshObject(id, d->onlineJobCache, &MyMoneyStorageMgr::getOnlineJob)) return; - if (d->refreshObject(id, d->costCenterCache, &IMyMoneyStorage::costCenter)) + if (d->refreshObject(id, d->costCenterCache, &MyMoneyStorageMgr::costCenter)) return; // special handling of securities @@ -288,27 +288,27 @@ MyMoneyPayee MyMoneyObjectContainer::payee(const QString& id) { - return d->objectAccessMethodImpl(id, d->payeeCache, &IMyMoneyStorage::payee); + return d->objectAccessMethodImpl(id, d->payeeCache, &MyMoneyStorageMgr::payee); } MyMoneyTag MyMoneyObjectContainer::tag(const QString& id) { - return d->objectAccessMethodImpl(id, d->tagCache, &IMyMoneyStorage::tag); + return d->objectAccessMethodImpl(id, d->tagCache, &MyMoneyStorageMgr::tag); } MyMoneySecurity MyMoneyObjectContainer::security(const QString& id) { - return d->objectAccessMethodImpl(id, d->securityCache, &IMyMoneyStorage::security); + return d->objectAccessMethodImpl(id, d->securityCache, &MyMoneyStorageMgr::security); } MyMoneyInstitution MyMoneyObjectContainer::institution(const QString& id) { - return d->objectAccessMethodImpl(id, d->institutionCache, &IMyMoneyStorage::institution); + return d->objectAccessMethodImpl(id, d->institutionCache, &MyMoneyStorageMgr::institution); } MyMoneySchedule MyMoneyObjectContainer::schedule(const QString& id) { - return d->objectAccessMethodImpl(id, d->scheduleCache, &IMyMoneyStorage::schedule); + return d->objectAccessMethodImpl(id, d->scheduleCache, &MyMoneyStorageMgr::schedule); } void MyMoneyObjectContainer::preloadAccount(const QList& list) diff --git a/kmymoney/mymoney/storage/CMakeLists.txt b/kmymoney/mymoney/storage/CMakeLists.txt --- a/kmymoney/mymoney/storage/CMakeLists.txt +++ b/kmymoney/mymoney/storage/CMakeLists.txt @@ -3,23 +3,28 @@ endif() set(storage_HEADERS - imymoneystorage.h imymoneyserialize.h imymoneystorageformat.h + imymoneystorageformat.h + mymoneystoragemgr.h kmymoneystorageplugin.h databasestoreableobject.h ) set(storage_a_SOURCES - imymoneystorageformat.cpp mymoneystoragexml.cpp mymoneystoragedump.cpp - mymoneyseqaccessmgr.cpp + imymoneystorageformat.cpp + mymoneystoragexml.cpp + mymoneystoragemgr.cpp mymoneystorageanon.cpp mymoneystoragesql.cpp - mymoneydatabasemgr.cpp mymoneydbdef.cpp mymoneydbdriver.cpp kmymoneystorageplugin.cpp mymoneystoragenames.cpp ) +if(KMM_DEBUG) + list(APPEND storage_a_SOURCES mymoneystoragedump.cpp) +endif() + # This library is actually not needed. It is built just for # convenience, and then linked into kmm_mymoney. add_library( kmm_storage STATIC ${storage_a_SOURCES} ) diff --git a/kmymoney/mymoney/storage/imymoneyserialize.h b/kmymoney/mymoney/storage/imymoneyserialize.h deleted file mode 100644 --- a/kmymoney/mymoney/storage/imymoneyserialize.h +++ /dev/null @@ -1,435 +0,0 @@ -/*************************************************************************** - imymoneyserialize.h - description - ------------------- - begin : Fri May 10 2002 - copyright : (C) 2000-2002 by Michael Edwardes - email : mte@users.sourceforge.net - Javier Campos Morales - Felix Rodriguez - John C - Thomas Baumgart - Kevin Tambascio - (C) 2017 by Ł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. * - * * - ***************************************************************************/ - -#ifndef IMYMONEYSERIALIZE_H -#define IMYMONEYSERIALIZE_H - -// ---------------------------------------------------------------------------- -// QT Includes - -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -class QUrl; -class QDate; -class QString; -class QStringList; - -class MyMoneyAccount; -class MyMoneyBudget; -class MyMoneyCostCenter; -class MyMoneyInstitution; -class MyMoneyReport; -class MyMoneySecurity; -class MyMoneyPayee; -class MyMoneyPrice; -class MyMoneySchedule; -class MyMoneyStorageSql; -class MyMoneyTag; -class MyMoneyPrice; -class MyMoneyTransaction; -class MyMoneyTransactionFilter; -class onlineJob; - -template class QExplicitlySharedDataPointer; -template class QMap; -template class QList; -template struct QPair; - -typedef QPair MyMoneySecurityPair; -typedef QMap MyMoneyPriceEntries; -typedef QMap MyMoneyPriceList; - -namespace eMyMoney { namespace Schedule { enum class Type; } } -namespace eMyMoney { namespace Schedule { enum class Occurrence; } } -namespace eMyMoney { namespace Schedule { enum class PaymentType; } } - -/** - * @author Thomas Baumgart - * @author Łukasz Wojniłowicz - */ - -/** - * This class represents the interface to serialize a MyMoneyStorage object - */ -class IMyMoneySerialize -{ -public: - virtual ~IMyMoneySerialize() = default; - - // general get functions - virtual MyMoneyPayee user() const = 0; - virtual QDate creationDate() const = 0; - virtual QDate lastModificationDate() const = 0; - virtual uint currentFixVersion() const = 0; - virtual uint fileFixVersion() const = 0; - - // general set functions - virtual void setUser(const MyMoneyPayee& val) = 0; - virtual void setCreationDate(const QDate& val) = 0; - virtual void setFileFixVersion(uint v) = 0; - /** - * This method is used to get a SQL reader for subsequent database access - */ - virtual QExplicitlySharedDataPointer connectToDatabase - (const QUrl &url) = 0; - /** - * This method is used when a database file is open, and the data is to - * be saved in a different file or format. It will ensure that all data - * from the database is available in memory to enable it to be written. - */ - virtual void fillStorage() = 0; - - /** - * This method is used to set the last modification date of - * the storage object. It also clears the dirty flag and should - * therefor be called as last operation when loading from a - * file. - * - * @param val QDate of last modification - */ - virtual void setLastModificationDate(const QDate& val) = 0; - - /** - * This method returns a list of accounts inside the storage object. - * - * @param list reference to QList receiving the account objects - * - * @note The standard accounts will not be returned - */ - virtual void accountList(QList& list) const = 0; - - /** - * This method returns a list of the institutions - * inside a MyMoneyStorage object - * - * @return QMap containing the institution information - */ - virtual QList institutionList() const = 0; - - /** - * This method is used to pull a list of transactions from the file - * global transaction pool. It returns all those transactions - * that match the filter passed as argument. If the filter is empty, - * the whole journal will be returned. - * - * @param list reference to QList receiving - * the set of transactions - * @param filter MyMoneyTransactionFilter object with the match criteria - */ - virtual void transactionList(QList& list, MyMoneyTransactionFilter& filter) const = 0; - - - /** - * This method returns whether a given transaction is already in memory, to avoid - * reloading it from the database - */ - virtual bool isDuplicateTransaction(const QString&) const = 0; - /** - * This method returns a list of the payees - * inside a MyMoneyStorage object - * - * @return QList containing the payee information - */ - virtual QList payeeList() const = 0; - - /** - * This method returns a list of the tags - * inside a MyMoneyStorage object - * - * @return QList containing the tag information - */ - virtual QList tagList() const = 0; - - /** - * This method returns a list of the scheduled transactions - * inside a MyMoneyStorage object. In order to retrieve a complete - * list of the transactions, all arguments should be used with their - * default arguments. - */ - virtual QList scheduleList(const QString&, - eMyMoney::Schedule::Type, - eMyMoney::Schedule::Occurrence, - eMyMoney::Schedule::PaymentType, - const QDate&, - const QDate&, - bool) const = 0; - - /** - * This method returns a list of security objects that the engine has - * knowledge of. - */ - virtual QList securityList() const = 0; - - /** - * This method returns a list of onlineJobs the engine has - */ - virtual QList onlineJobList() const = 0; - - /** - * This method returns a list of cost center objects the engine knows about - */ - virtual QList costCenterList() const = 0; - - /** - * This method is used to return the standard liability account - * @return MyMoneyAccount liability account(group) - */ - virtual MyMoneyAccount liability() const = 0; - - /** - * This method is used to return the standard asset account - * @return MyMoneyAccount asset account(group) - */ - virtual MyMoneyAccount asset() const = 0; - - /** - * This method is used to return the standard expense account - * @return MyMoneyAccount expense account(group) - */ - virtual MyMoneyAccount expense() const = 0; - - /** - * This method is used to return the standard income account - * @return MyMoneyAccount income account(group) - */ - virtual MyMoneyAccount income() const = 0; - - /** - * This method is used to return the standard equity account - * @return MyMoneyAccount equity account(group) - */ - virtual MyMoneyAccount equity() const = 0; - - /** - * This method is used to create a new account - * - * An exception will be thrown upon error conditions. - * - * @param account MyMoneyAccount filled with data - */ - virtual void addAccount(MyMoneyAccount& account) = 0; - - /** - * This method is used to add one account as sub-ordinate to another - * (parent) account. The objects that are passed will be modified - * accordingly. - * - * An exception will be thrown upon error conditions. - * - * @param parent parent account the account should be added to - * @param account the account to be added - * - * @deprecated This method is only provided as long as we provide - * the version 0.4 binary reader. As soon as we deprecate - * this compatibility mode this method will disappear from - * this interface! - */ - virtual void addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) = 0; - - /** - * This method is used to create a new payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - * - * @deprecated This method is only provided as long as we provide - * the version 0.4 binary reader. As soon as we deprecate - * this compatibility mode this method will disappear from - * this interface! - * - */ - virtual void addPayee(MyMoneyPayee& payee) = 0; - - /** - * Adds an institution to the storage. A - * respective institution-ID will be generated within this record. - * The ID is stored as QString in the object passed as argument. - * - * An exception will be thrown upon error conditions. - * - * @param institution The complete institution information in a - * MyMoneyInstitution object - * - * @deprecated This method is only provided as long as we provide - * the version 0.4 binary reader. As soon as we deprecate - * this compatibility mode this method will disappear from - * this interface! - */ - virtual void addInstitution(MyMoneyInstitution& institution) = 0; - - /** - * Adds a transaction to the file-global transaction pool. A respective - * transaction-ID will be generated within this record. The ID is stored - * as QString with the object. - * - * An exception will be thrown upon error conditions. - * - * @param transaction reference to the transaction - * @param skipAccountUpdate if set, the transaction lists of the accounts - * referenced in the splits are not updated. This is used for - * bulk loading a lot of transactions but not during normal operation. - * Refreshing the account's transaction list can be done using - * refreshAllAccountTransactionList(). - * - * @deprecated This method is only provided as long as we provide - * the version 0.4 binary reader. As soon as we deprecate - * this compatibility mode this method will disappear from - * this interface! - */ - virtual void addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate = false) = 0; - - virtual void loadAccounts(const QMap& map) = 0; - virtual void loadTransactions(const QMap& map) = 0; - virtual void loadInstitutions(const QMap& map) = 0; - virtual void loadPayees(const QMap& map) = 0; - virtual void loadTags(const QMap& map) = 0; - virtual void loadSchedules(const QMap& map) = 0; - virtual void loadSecurities(const QMap& map) = 0; - virtual void loadCurrencies(const QMap& map) = 0; - virtual void loadReports(const QMap& reports) = 0; - virtual void loadBudgets(const QMap& budgets) = 0; - virtual void loadPrices(const MyMoneyPriceList& list) = 0; - virtual void loadOnlineJobs(const QMap& onlineJobs) = 0; - virtual void loadCostCenters(const QMap& costCenters) = 0; - - virtual ulong accountId() const = 0; - virtual ulong transactionId() const = 0; - virtual ulong payeeId() const = 0; - virtual ulong tagId() const = 0; - virtual ulong institutionId() const = 0; - virtual ulong scheduleId() const = 0; - virtual ulong securityId() const = 0; - virtual ulong reportId() const = 0; - virtual ulong budgetId() const = 0; - virtual ulong onlineJobId() const = 0; - virtual ulong costCenterId() const = 0; - - virtual void loadAccountId(ulong id) = 0; - virtual void loadTransactionId(ulong id) = 0; - virtual void loadPayeeId(ulong id) = 0; - virtual void loadTagId(ulong id) = 0; - virtual void loadInstitutionId(ulong id) = 0; - virtual void loadScheduleId(ulong id) = 0; - virtual void loadSecurityId(ulong id) = 0; - virtual void loadReportId(ulong id) = 0; - virtual void loadBudgetId(ulong id) = 0; - virtual void loadOnlineJobId(ulong id) = 0; - virtual void loadCostCenterId(ulong id) = 0; - - /** - * This method is used to retrieve the whole set of key/value pairs - * from the container. It is meant to be used for permanent storage - * functionality. See MyMoneyKeyValueContainer::pairs() for details. - * - * @return QMap containing all key/value pairs of - * this container. - */ - virtual QMap pairs() const = 0; - - /** - * This method is used to initially store a set of key/value pairs - * in the container. It is meant to be used for loading functionality - * from permanent storage. See MyMoneyKeyValueContainer::setPairs() - * for details - * - * @param list const QMap containing the set of - * key/value pairs to be loaded into the container. - * - * @note All existing key/value pairs in the container will be deleted. - */ - virtual void setPairs(const QMap& list) = 0; - - virtual QList scheduleListEx(int scheduleTypes, - int scheduleOcurrences, - int schedulePaymentTypes, - QDate startDate, - const QStringList& accounts) const = 0; - - /** - * This method is used to retrieve the list of all currencies - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneySecurity objects representing a currency. - */ - virtual QList currencyList() const = 0; - - /** - * This method is used to retrieve the list of all reports - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneyReport objects. - */ - virtual QList reportList() const = 0; - - /** - * This method is used to retrieve the list of all budgets - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneyBudget objects. - */ - virtual QList budgetList() const = 0; - - - /** - * This method adds a price entry to the price list. - */ - virtual void addPrice(const MyMoneyPrice& price) = 0; - - /** - * This method returns a list of all prices. - * - * @return MyMoneyPriceList of all MyMoneyPrice objects. - */ - virtual MyMoneyPriceList priceList() const = 0; - - /** - * This method recalculates the balances of all accounts - * based on the transactions stored in the engine. - */ - virtual void rebuildAccountBalances() = 0; - -protected: - virtual QString nextAccountID() = 0; - virtual QString nextTransactionID() = 0; - virtual QString nextPayeeID() = 0; - virtual QString nextTagID() = 0; - virtual QString nextInstitutionID() = 0; - virtual QString nextScheduleID() = 0; - virtual QString nextSecurityID() = 0; - virtual QString nextReportID() = 0; - virtual QString nextBudgetID() = 0; - virtual QString nextOnlineJobID() = 0; - virtual QString nextCostCenterID() = 0; -}; - -#endif diff --git a/kmymoney/mymoney/storage/imymoneystorage.h b/kmymoney/mymoney/storage/imymoneystorage.h deleted file mode 100644 --- a/kmymoney/mymoney/storage/imymoneystorage.h +++ /dev/null @@ -1,961 +0,0 @@ -/*************************************************************************** - imymoneystorage.h - description - ------------------- - begin : Sun May 5 2002 - copyright : (C) 2000-2002 by Michael Edwardes - email : mte@users.sourceforge.net - Javier Campos Morales - Felix Rodriguez - John C - Thomas Baumgart - Kevin Tambascio - (C) 2017 by Ł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. * - * * - ***************************************************************************/ - -#ifndef IMYMONEYSTORAGE_H -#define IMYMONEYSTORAGE_H - -// ---------------------------------------------------------------------------- -// QT Includes - -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -class QString; -class QDate; -class QStringList; -class QBitArray; - -class MyMoneyObject; -class MyMoneyMoney; -class MyMoneyInstitution; -class MyMoneyAccount; -class MyMoneySecurity; -class MyMoneyPayee; -class MyMoneyTag; -class MyMoneyPrice; -class MyMoneyReport; -class MyMoneySchedule; -class MyMoneyBudget; -class MyMoneySplit; -class MyMoneyTransaction; -class MyMoneyTransactionFilter; -class MyMoneyCostCenter; -class onlineJob; - -template class QMap; -template class QList; -template struct QPair; - -typedef QPair MyMoneySecurityPair; -typedef QMap MyMoneyPriceEntries; -typedef QMap MyMoneyPriceList; - -namespace eMyMoney { namespace Schedule { enum class Type; } } -namespace eMyMoney { namespace Schedule { enum class Occurrence; } } -namespace eMyMoney { namespace Schedule { enum class PaymentType; } } - -/** - * @author Thomas Baumgart - * @author Łukasz Wojniłowicz - */ - -/** - * The IMyMoneyStorage class describes the interface between the MyMoneyFile class - * and the real storage manager. - * - * @see MyMoneySeqAccessMgr - */ -class IMyMoneyStorage -{ -public: - virtual ~IMyMoneyStorage() = default; - - // general get functions - virtual MyMoneyPayee user() const = 0; - virtual QDate creationDate() const = 0; - virtual QDate lastModificationDate() const = 0; - virtual uint currentFixVersion() const = 0; - virtual uint fileFixVersion() const = 0; - - // general set functions - virtual void setUser(const MyMoneyPayee& user) = 0; - virtual void setFileFixVersion(const uint v) = 0; - - // methods provided by MyMoneyKeyValueContainer - virtual void setValue(const QString& key, const QString& value) = 0; - virtual QString value(const QString& key) const = 0; - virtual void deletePair(const QString& key) = 0; - - /** - * This method is used to duplicate an IMyMoneyStorage object and return - * a pointer to the newly created copy. The caller of this method is the - * new owner of the object and must destroy it. - */ -// virtual IMyMoneyStorage const * duplicate() = 0; - - /** - * This method is used to create a new account - * - * An exception will be thrown upon error conditions. - * - * @param account MyMoneyAccount filled with data - */ - virtual void addAccount(MyMoneyAccount& account) = 0; - - /** - * This method is used to add one account as sub-ordinate to another - * (parent) account. The objects that are passed will be modified - * accordingly. - * - * An exception will be thrown upon error conditions. - * - * @param parent parent account the account should be added to - * @param account the account to be added - */ - virtual void addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) = 0; - - /** - * This method is used to create a new payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - */ - virtual void addPayee(MyMoneyPayee& payee) = 0; - - /** - * This method is used to retrieve information about a payee - * An exception will be thrown upon error conditions. - * - * @param id QString reference to id of payee - * - * @return MyMoneyPayee object of payee - */ - virtual MyMoneyPayee payee(const QString& id) const = 0; - - /** - * This method is used to retrieve the id to a corresponding - * name of a payee/receiver. - * An exception will be thrown upon error conditions. - * - * @param payee QString reference to name of payee - * - * @return MyMoneyPayee object of payee - */ - virtual MyMoneyPayee payeeByName(const QString& payee) const = 0; - - /** - * This method is used to modify an existing payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - */ - virtual void modifyPayee(const MyMoneyPayee& payee) = 0; - - /** - * This method is used to remove an existing payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - */ - virtual void removePayee(const MyMoneyPayee& payee) = 0; - - /** - * This method returns a list of the payees - * inside a MyMoneyStorage object - * - * @return QList containing the payee information - */ - virtual QList payeeList() const = 0; - - /** - * This method is used to create a new tag - * - * An exception will be thrown upon error conditions - * - * @param tag MyMoneyTag reference to tag information - */ - virtual void addTag(MyMoneyTag& tag) = 0; - - /** - * This method is used to retrieve information about a tag - * An exception will be thrown upon error conditions. - * - * @param id QString reference to id of tag - * - * @return MyMoneyTag object of tag - */ - virtual MyMoneyTag tag(const QString& id) const = 0; - - /** - * This method is used to retrieve the id to a corresponding - * name of a tag. - * An exception will be thrown upon error conditions. - * - * @param tag QString reference to name of tag - * - * @return MyMoneyTag object of tag - */ - virtual MyMoneyTag tagByName(const QString& tag) const = 0; - - /** - * This method is used to modify an existing tag - * - * An exception will be thrown upon error conditions - * - * @param tag MyMoneyTag reference to tag information - */ - virtual void modifyTag(const MyMoneyTag& tag) = 0; - - /** - * This method is used to remove an existing tag - * - * An exception will be thrown upon error conditions - * - * @param tag MyMoneyTag reference to tag information - */ - virtual void removeTag(const MyMoneyTag& tag) = 0; - - /** - * This method returns a list of the tags - * inside a MyMoneyStorage object - * - * @return QList containing the tag information - */ - virtual QList tagList() const = 0; - - /** - * Returns the account addressed by it's id. - * - * An exception will be thrown upon error conditions. - * - * @param id id of the account to locate. - * @return reference to MyMoneyAccount object. An exception is thrown - * if the id is unknown - */ - virtual MyMoneyAccount account(const QString& id) const = 0; - - /** - * This method is used to check whether a given - * account id references one of the standard accounts or not. - * - * An exception will be thrown upon error conditions. - * - * @param id account id - * @return true if account-id is one of the standards, false otherwise - */ - virtual bool isStandardAccount(const QString& id) const = 0; - - /** - * This method is used to set the name for the specified standard account - * within the storage area. An exception will be thrown, if an error - * occurs - * - * @param id QString reference to one of the standard accounts. - * @param name QString reference to the name to be set - * - */ - virtual void setAccountName(const QString& id, const QString& name) = 0; - - /** - * Adds an institution to the storage. A - * respective institution-ID will be generated within this record. - * The ID is stored as QString in the object passed as argument. - * - * An exception will be thrown upon error conditions. - * - * @param institution The complete institution information in a - * MyMoneyInstitution object - */ - virtual void addInstitution(MyMoneyInstitution& institution) = 0; - - /** - * Adds a transaction to the file-global transaction pool. A respective - * transaction-ID will be generated within this record. The ID is stored - * QString with the object. - * - * An exception will be thrown upon error conditions. - * - * @param transaction reference to the transaction - * @param skipAccountUpdate if set, the transaction lists of the accounts - * referenced in the splits are not updated. This is used for - * bulk loading a lot of transactions but not during normal operation - */ - virtual void addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate = false) = 0; - - /** - * This method is used to determince, if the account with the - * given ID is referenced by any split in m_transactionList. - * - * An exception will be thrown upon error conditions. - * - * @param id id of the account to be checked for - * @return true if account is referenced, false otherwise - */ - virtual bool hasActiveSplits(const QString& id) const = 0; - - /** - * This method is used to return the actual balance of an account - * without it's sub-ordinate accounts. If a @p date is presented, - * the balance at the beginning of this date (not including any - * transaction on this date) is returned. Otherwise all recorded - * transactions are included in the balance. - * - * @param id id of the account in question - * @param date return balance for specific date - * @return balance of the account as MyMoneyMoney object - */ - virtual MyMoneyMoney balance(const QString& id, const QDate& date) const = 0; - - /** - * This method is used to return the actual balance of an account - * including it's sub-ordinate accounts. If a @p date is presented, - * the balance at the beginning of this date (not including any - * transaction on this date) is returned. Otherwise all recorded - * transactions are included in the balance. - * - * @param id id of the account in question - * @param date return balance for specific date - * @return balance of the account as MyMoneyMoney object - */ - virtual MyMoneyMoney totalBalance(const QString& id, const QDate& date) const = 0; - - /** - * Returns the institution of a given ID - * - * @param id id of the institution to locate - * @return MyMoneyInstitution object filled with data. If the institution - * could not be found, an exception will be thrown - */ - virtual MyMoneyInstitution institution(const QString& id) const = 0; - - /** - * This method returns an indicator if the storage object has been - * changed after it has last been saved to permanent storage. - * - * @return true if changed, false if not - */ - virtual bool dirty() const = 0; - - /** - * This method can be used by an external object to force the - * storage object to be dirty. This is used e.g. when an upload - * to an external destination failed but the previous storage - * to a local disk was ok. - */ - virtual void setDirty() = 0; - - /** - * This method returns the number of accounts currently known to this storage - * in the range 0..MAXUINT - * - * @return number of accounts currently known inside a MyMoneyFile object - */ - virtual uint accountCount() const = 0; - - /** - * This method returns a list of the institutions - * inside a MyMoneyStorage object - * - * @return QList containing the - * institution information - */ - virtual QList institutionList() const = 0; - - /** - * Modifies an already existing account in the file global account pool. - * - * An exception will be thrown upon error conditions. - * - * @param account reference to the new account information - * @param skipCheck allows to skip the builtin consistency checks - */ - virtual void modifyAccount(const MyMoneyAccount& account, bool skipCheck = false) = 0; - - /** - * Modifies an already existing institution in the file global - * institution pool. - * - * An exception will be thrown upon error conditions. - * - * @param institution The complete new institution information - */ - virtual void modifyInstitution(const MyMoneyInstitution& institution) = 0; - - /** - * This method is used to update a specific transaction in the - * transaction pool of the MyMoneyFile object - * - * An exception will be thrown upon error conditions. - * - * @param transaction reference to transaction to be changed - */ - virtual void modifyTransaction(const MyMoneyTransaction& transaction) = 0; - - /** - * This method re-parents an existing account - * - * An exception will be thrown upon error conditions. - * - * @param account MyMoneyAccount reference to account to be re-parented - * @param parent MyMoneyAccount reference to new parent account - */ - virtual void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent) = 0; - - /** - * This method is used to remove a transaction from the transaction - * pool (journal). - * - * An exception will be thrown upon error conditions. - * - * @param transaction const reference to transaction to be deleted - */ - virtual void removeTransaction(const MyMoneyTransaction& transaction) = 0; - - /** - * This method returns the number of transactions currently known to file - * in the range 0..MAXUINT - * - * @param account QString reference to account id. If account is empty - + all transactions (the journal) will be counted. If account - * is not empty it returns the number of transactions - * that have splits in this account. - * - * @return number of transactions in journal/account - */ - virtual uint transactionCount(const QString& account) const = 0; - - /** - * This method returns a QMap filled with the number of transactions - * per account. The account id serves as index into the map. If one - * needs to have all transactionCounts() for many accounts, this method - * is faster than calling transactionCount(const QString& account) many - * times. - * - * @return QMap with numbers of transactions per account - */ - virtual QMap transactionCountMap() const = 0; - - /** - * This method is used to pull a list of transactions from the file - * global transaction pool. It returns all those transactions - * that match the filter passed as argument. If the filter is empty, - * the whole journal will be returned. - * The list returned is sorted according to the transactions posting date. - * If more than one transaction exists for the same date, the order among - * them is undefined. - * - * @param filter MyMoneyTransactionFilter object with the match criteria - * - * @return set of transactions in form of a QList - */ - virtual QList transactionList(MyMoneyTransactionFilter& filter) const = 0; - - virtual void transactionList(QList& list, MyMoneyTransactionFilter& filter) const = 0; - - virtual void transactionList(QList >& list, MyMoneyTransactionFilter& filter) const = 0; - - /** - * Deletes an existing account from the file global account pool - * This method only allows to remove accounts that are not - * referenced by any split. Use moveSplits() to move splits - * to another account. An exception is thrown in case of a - * problem. - * - * @param account reference to the account to be deleted. - */ - virtual void removeAccount(const MyMoneyAccount& account) = 0; - - /** - * Deletes an existing institution from the file global institution pool - * Also modifies the accounts that reference this institution as - * their institution. - * - * An exception will be thrown upon error conditions. - * - * @param institution institution to be deleted. - */ - virtual void removeInstitution(const MyMoneyInstitution& institution) = 0; - - /** - * This method is used to extract a transaction from the file global - * transaction pool through an id. In case of an invalid id, an - * exception will be thrown. - * - * @param id id of transaction as QString. - * @return reference to the requested transaction - */ - virtual MyMoneyTransaction transaction(const QString& id) const = 0; - - /** - * This method is used to extract a transaction from the file global - * transaction pool through an index into an account. - * - * @param account id of the account as QString - * @param idx number of transaction in this account - * @return reference to MyMoneyTransaction object - */ - virtual MyMoneyTransaction transaction(const QString& account, const int idx) const = 0; - - /** - * This method returns the number of institutions currently known to file - * in the range 0..MAXUINT - * - * @return number of institutions known to file - */ - virtual uint institutionCount() const = 0; - - /** - * This method returns a list of accounts inside the storage object. - * - * @param list reference to QList receiving the account objects - * - * @note The standard accounts will not be returned - */ - virtual void accountList(QList& list) const = 0; - - /** - * This method is used to return the standard liability account - * @return MyMoneyAccount liability account(group) - */ - virtual MyMoneyAccount liability() const = 0; - - /** - * This method is used to return the standard asset account - * @return MyMoneyAccount asset account(group) - */ - virtual MyMoneyAccount asset() const = 0; - - /** - * This method is used to return the standard expense account - * @return MyMoneyAccount expense account(group) - */ - virtual MyMoneyAccount expense() const = 0; - - /** - * This method is used to return the standard income account - * @return MyMoneyAccount income account(group) - */ - virtual MyMoneyAccount income() const = 0; - - /** - * This method is used to return the standard equity account - * @return MyMoneyAccount equity account(group) - */ - virtual MyMoneyAccount equity() const = 0; - - /** - * This method is used to create a new security object. The ID will be created - * automatically. The object passed with the parameter @p security is modified - * to contain the assigned id. - * - * An exception will be thrown upon error conditions. - * - * @param security MyMoneySecurity filled with data - */ - virtual void addSecurity(MyMoneySecurity& security) = 0; - - /** - * This method is used to modify an existing MyMoneySecurity - * object. - * - * An exception will be thrown upon erroneous situations. - * - * @param security reference to the MyMoneySecurity object to be updated - */ - virtual void modifySecurity(const MyMoneySecurity& security) = 0; - - /** - * This method is used to remove an existing MyMoneySecurity object - * from the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @param security reference to the MyMoneySecurity object to be removed - */ - virtual void removeSecurity(const MyMoneySecurity& security) = 0; - - /** - * This method is used to retrieve a single MyMoneySecurity object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneySecurity object - * @return MyMoneySecurity object - */ - virtual MyMoneySecurity security(const QString& id) const = 0; - - /** - * This method returns a list of the security objects - * inside a MyMoneyStorage object - * - * @return QList containing objects - */ - virtual QList securityList() const = 0; - - virtual void addPrice(const MyMoneyPrice& price) = 0; - virtual void removePrice(const MyMoneyPrice& price) = 0; - virtual MyMoneyPrice price(const QString& fromId, const QString& toId, const QDate& date, bool exactDate) const = 0; - - /** - * This method returns a list of all prices. - * - * @return MyMoneyPriceList of all MyMoneyPrice objects. - */ - virtual MyMoneyPriceList priceList() const = 0; - - /** - * This method is used to add a scheduled transaction to the engine. - * It must be sure, that the id of the object is not filled. When the - * method returns to the caller, the id will be filled with the - * newly created object id value. - * - * An exception will be thrown upon erroneous situations. - * - * @param sched reference to the MyMoneySchedule object - */ - virtual void addSchedule(MyMoneySchedule& sched) = 0; - - /** - * This method is used to modify an existing MyMoneySchedule - * object. Therefor, the id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param sched const reference to the MyMoneySchedule object to be updated - */ - virtual void modifySchedule(const MyMoneySchedule& sched) = 0; - - /** - * This method is used to remove an existing MyMoneySchedule object - * from the engine. The id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param sched const reference to the MyMoneySchedule object to be updated - */ - virtual void removeSchedule(const MyMoneySchedule& sched) = 0; - - /** - * This method is used to retrieve a single MyMoneySchedule object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneySchedule object - * @return MyMoneySchedule object - */ - virtual MyMoneySchedule schedule(const QString& id) const = 0; - - /** - * This method is used to extract a list of scheduled transactions - * according to the filter criteria passed as arguments. - * - * @param accountId only search for scheduled transactions that reference - * accound @p accountId. If accountId is the empty string, - * this filter is off. Default is @p QString(). - * @param type only schedules of type @p type are searched for. - * See eMyMoney::Schedule::Type for details. - * Default is eMyMoney::Schedule::Type::Any - * @param occurrence only schedules of occurrence type @p occurrence are searched for. - * See eMyMoney::Schedule::Occurrence for details. - * Default is eMyMoney::Schedule::Occurrence::Any - * @param paymentType only schedules of payment method @p paymentType - * are searched for. - * See eMyMoney::Schedule::PaymentType for details. - * Default is eMyMoney::Schedule::PaymentType::Any - * @param startDate only schedules with payment dates after @p startDate - * are searched for. Default is all dates (QDate()). - * @param endDate only schedules with payment dates ending prior to @p endDate - * are searched for. Default is all dates (QDate()). - * @param overdue if true, only those schedules that are overdue are - * searched for. Default is false (all schedules will be returned). - * - * @return QList list of schedule objects. - */ - virtual QList scheduleList(const QString& accountId, - eMyMoney::Schedule::Type type, - eMyMoney::Schedule::Occurrence occurrence, - eMyMoney::Schedule::PaymentType paymentType, - const QDate& startDate, - const QDate& endDate, - bool overdue) const = 0; - - virtual QList scheduleListEx(int scheduleTypes, - int scheduleOcurrences, - int schedulePaymentTypes, - QDate startDate, - const QStringList& accounts) const = 0; - - /** - * This method is used to add a new currency object to the engine. - * The ID of the object is the trading symbol, so there is no need for an additional - * ID since the symbol is guaranteed to be unique. - * - * An exception will be thrown upon erroneous situations. - * - * @param currency reference to the MyMoneySecurity object - */ - virtual void addCurrency(const MyMoneySecurity& currency) = 0; - - /** - * This method is used to modify an existing MyMoneySecurity - * object. - * - * An exception will be thrown upon erroneous situations. - * - * @param currency reference to the MyMoneyCurrency object - */ - virtual void modifyCurrency(const MyMoneySecurity& currency) = 0; - - /** - * This method is used to remove an existing MyMoneySecurity object - * from the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @param currency reference to the MyMoneySecurity object - */ - virtual void removeCurrency(const MyMoneySecurity& currency) = 0; - - /** - * This method is used to retrieve a single MyMoneySecurity object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneySecurity object - * @return MyMoneyCurrency object - */ - virtual MyMoneySecurity currency(const QString& id) const = 0; - - /** - * This method is used to retrieve the list of all currencies - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneySecurity objects representing a currency. - */ - virtual QList currencyList() const = 0; - - /** - * This method is used to retrieve the list of all reports - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneyReport objects. - */ - virtual QList reportList() const = 0; - - /** - * This method is used to add a new report to the engine. - * It must be sure, that the id of the object is not filled. When the - * method returns to the caller, the id will be filled with the - * newly created object id value. - * - * An exception will be thrown upon erroneous situations. - * - * @param report reference to the MyMoneyReport object - */ - virtual void addReport(MyMoneyReport& report) = 0; - - /** - * This method is used to modify an existing MyMoneyReport - * object. Therefor, the id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param report const reference to the MyMoneyReport object to be updated - */ - virtual void modifyReport(const MyMoneyReport& report) = 0; - - /** - * This method returns the number of reports currently known to file - * in the range 0..MAXUINT - * - * @return number of reports known to file - */ - virtual uint countReports() const = 0; - - /** - * This method is used to retrieve a single MyMoneyReport object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneyReport object - * @return MyMoneyReport object - */ - virtual MyMoneyReport report(const QString& id) const = 0; - - /** - * This method is used to remove an existing MyMoneyReport object - * from the engine. The id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param report const reference to the MyMoneyReport object to be updated - */ - virtual void removeReport(const MyMoneyReport& report) = 0; - - /** - * This method is used to retrieve the list of all budgets - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneyBudget objects. - */ - virtual QList budgetList() const = 0; - - /** - * This method is used to add a new budget to the engine. - * It must be sure, that the id of the object is not filled. When the - * method returns to the caller, the id will be filled with the - * newly created object id value. - * - * An exception will be thrown upon erroneous situations. - * - * @param budget reference to the MyMoneyBudget object - */ - virtual void addBudget(MyMoneyBudget& budget) = 0; - - /** - * This method is used to retrieve the id to a corresponding - * name of a budget - * An exception will be thrown upon error conditions. - * - * @param budget QString reference to name of budget - * - * @return MyMoneyBudget object of budget - */ - virtual MyMoneyBudget budgetByName(const QString& budget) const = 0; - - /** - * This method is used to modify an existing MyMoneyBudget - * object. Therefor, the id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param budget const reference to the MyMoneyBudget object to be updated - */ - virtual void modifyBudget(const MyMoneyBudget& budget) = 0; - - /** - * This method returns the number of budgets currently known to file - * in the range 0..MAXUINT - * - * @return number of budgets known to file - */ - virtual uint countBudgets() const = 0; - - /** - * This method is used to retrieve a single MyMoneyBudget object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneyBudget object - * @return MyMoneyBudget object - */ - virtual MyMoneyBudget budget(const QString& id) const = 0; - - /** - * This method is used to remove an existing MyMoneyBudget object - * from the engine. The id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param budget const reference to the MyMoneyBudget object to be updated - */ - virtual void removeBudget(const MyMoneyBudget& budget) = 0; - - - /** - * This method is used to add a new onlineJob. The id will be - * overwritten. - * - * An exception will be thrown upon erronous situations. - * - * @param job The onlineJob, caller remains owner of it. Id might be updated. - */ - virtual void addOnlineJob(onlineJob& job) = 0; - - /** - * @brief Saves a onlineJob - * @param job - */ - virtual void modifyOnlineJob(const onlineJob& job) = 0; - - /** - * @brief Get onlineJob by id - * - * @return onlineJob you are not the owner nor allowed to delete it. - * @throw MyMoneyException if jobId was not found - */ - virtual onlineJob getOnlineJob(const QString& jobId) const = 0; - - /** - * @brief Return all onlineJobs - */ - virtual QList onlineJobList() const = 0; - - /** - * @brief Remove an onlineJobs - */ - virtual void removeOnlineJob(const onlineJob&) = 0; - - /** - * @brief Returns a cost center by id - */ - virtual MyMoneyCostCenter costCenter(const QString& id) const = 0; - - /** - * @brief Retruns a list of all costcenters - */ - virtual QList costCenterList() const = 0; - - /** - * This method checks, if the given @p object is referenced - * by another engine object. - * - * @param obj const reference to object to be checked - * @param skipCheck QBitArray with eStorage::Reference bits set for which - * the check should be skipped - * - * @retval false @p object is not referenced - * @retval true @p institution is referenced - */ - virtual bool isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const = 0; - - /** - * This method is provided to allow closing of the database before logoff - */ - virtual void close() = 0; - - /** - * These methods have to be provided to allow transaction safe data handling. - */ - virtual void startTransaction() = 0; - virtual bool commitTransaction() = 0; - virtual void rollbackTransaction() = 0; -}; - -#endif diff --git a/kmymoney/mymoney/storage/imymoneystorageformat.h b/kmymoney/mymoney/storage/imymoneystorageformat.h --- a/kmymoney/mymoney/storage/imymoneystorageformat.h +++ b/kmymoney/mymoney/storage/imymoneystorageformat.h @@ -37,25 +37,24 @@ // ---------------------------------------------------------------------------- // Project Includes -class IMyMoneySerialize; +class MyMoneyStorageMgr; - -class IMyMoneyStorageFormat +class IMyMoneyOperationsFormat { public: - IMyMoneyStorageFormat(); - virtual ~IMyMoneyStorageFormat(); + IMyMoneyOperationsFormat(); + virtual ~IMyMoneyOperationsFormat(); enum fileVersionDirectionType { Reading = 0, /**< version of file to be read */ Writing = 1 /**< version to be used when writing a file */ }; - virtual void readFile(QIODevice* qf, IMyMoneySerialize* storage) = 0; - // virtual void readStream(QDataStream& s, IMyMoneySerialize* storage) = 0; + virtual void readFile(QIODevice* qf, MyMoneyStorageMgr* storage) = 0; + // virtual void readStream(QDataStream& s, IMyMoneySerialization* storage) = 0; - virtual void writeFile(QIODevice* qf, IMyMoneySerialize* storage) = 0; - //virtual void writeStream(QDataStream& s, IMyMoneySerialize* storage) = 0; + virtual void writeFile(QIODevice* qf, MyMoneyStorageMgr* storage) = 0; + //virtual void writeStream(QDataStream& s, IMyMoneySerialization* storage) = 0; virtual void setProgressCallback(void(*callback)(int, int, const QString&)) = 0; /** diff --git a/kmymoney/mymoney/storage/imymoneystorageformat.cpp b/kmymoney/mymoney/storage/imymoneystorageformat.cpp --- a/kmymoney/mymoney/storage/imymoneystorageformat.cpp +++ b/kmymoney/mymoney/storage/imymoneystorageformat.cpp @@ -22,10 +22,10 @@ #include "imymoneystorageformat.h" -IMyMoneyStorageFormat::IMyMoneyStorageFormat() +IMyMoneyOperationsFormat::IMyMoneyOperationsFormat() { } -IMyMoneyStorageFormat::~IMyMoneyStorageFormat() +IMyMoneyOperationsFormat::~IMyMoneyOperationsFormat() { } diff --git a/kmymoney/mymoney/storage/mymoneydatabasemgr.h b/kmymoney/mymoney/storage/mymoneydatabasemgr.h deleted file mode 100644 --- a/kmymoney/mymoney/storage/mymoneydatabasemgr.h +++ /dev/null @@ -1,1095 +0,0 @@ -/*************************************************************************** - mymoneydatabasemgr.h - description - ------------------- - begin : June 5 2007 - copyright : (C) 2007 by Fernando Vilas - email : Fernando Vilas - 2017 by Ł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. * - * * - ***************************************************************************/ - -#ifndef MYMONEYDATABASEMGR_H -#define MYMONEYDATABASEMGR_H - -// ---------------------------------------------------------------------------- -// QT Includes - -// ---------------------------------------------------------------------------- -// Project Includes - -#include "imymoneyserialize.h" -#include "imymoneystorage.h" -#include "mymoneykeyvaluecontainer.h" - -class MyMoneyStorageSql; - -/** - * The MyMoneyDatabaseMgr class represents the storage engine for databases. - * The actual connection and internal storage is handled through the - * MyMoneyStorageSql interface. - * - * The MyMoneyDatabaseMgr must have a MyMoneyStorageSql connected to a - * database to be useful. Once connected, data will be loaded from/sent to the - * database synchronously. The method dirty() will always return false. Making - * this many trips to the database is not very fast, so when possible, the - * data cache in MyMoneyFile is used. - * - */ -class MyMoneyDatabaseMgrPrivate; -class MyMoneyDatabaseMgr : public IMyMoneyStorage, public IMyMoneySerialize, - public MyMoneyKeyValueContainer -{ - Q_DISABLE_COPY(MyMoneyDatabaseMgr) - KMM_MYMONEY_UNIT_TESTABLE - -public: - MyMoneyDatabaseMgr(); - ~MyMoneyDatabaseMgr(); - - // general get functions - MyMoneyPayee user() const override; - QDate creationDate() const override; - QDate lastModificationDate() const override; - uint currentFixVersion() const override; - uint fileFixVersion() const override; - - // general set functions - void setUser(const MyMoneyPayee& user) override; - void setFileFixVersion(uint v) override; - - // methods provided by MyMoneyKeyValueContainer - void setValue(const QString& key, const QString& value) override; - QString value(const QString& key) const override; - void deletePair(const QString& key) override; - - /** - * This method is used to duplicate an IMyMoneyStorage object and return - * a pointer to the newly created copy. The caller of this method is the - * new owner of the object and must destroy it. - */ -// MyMoneyDatabaseMgr const * duplicate() override; - - /** - * This method is used to create a new account - * - * An exception will be thrown upon error conditions. - * - * @param account MyMoneyAccount filled with data - */ - void addAccount(MyMoneyAccount& account) override; - - /** - * This method is used to add one account as sub-ordinate to another - * (parent) account. The objects that are passed will be modified - * accordingly. - * - * An exception will be thrown upon error conditions. - * - * @param parent parent account the account should be added to - * @param account the account to be added - */ - void addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) override; - - /** - * This method is used to create a new payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - */ - void addPayee(MyMoneyPayee& payee) override; - - /** - * This method is used to retrieve information about a payee - * An exception will be thrown upon error conditions. - * - * @param id QString reference to id of payee - * - * @return MyMoneyPayee object of payee - */ - MyMoneyPayee payee(const QString& id) const override; - - /** - * This method is used to retrieve the id to a corresponding - * name of a payee/receiver. - * An exception will be thrown upon error conditions. - * - * @param payee QString reference to name of payee - * - * @return MyMoneyPayee object of payee - */ - MyMoneyPayee payeeByName(const QString& payee) const override; - - /** - * This method is used to modify an existing payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - */ - void modifyPayee(const MyMoneyPayee& payee) override; - - /** - * This method is used to remove an existing payee - * - * An exception will be thrown upon error conditions - * - * @param payee MyMoneyPayee reference to payee information - */ - void removePayee(const MyMoneyPayee& payee) override; - - /** - * This method returns a list of the payees - * inside a MyMoneyStorage object - * - * @return QList containing the payee information - */ - QList payeeList() const override; - - /** - * This method is used to create a new tag - * - * An exception will be thrown upon error conditions - * - * @param tag MyMoneyTag reference to tag information - */ - void addTag(MyMoneyTag& tag) override; - - /** - * This method is used to retrieve information about a tag - * An exception will be thrown upon error conditions. - * - * @param id QString reference to id of tag - * - * @return MyMoneyTag object of tag - */ - MyMoneyTag tag(const QString& id) const override; - - /** - * This method is used to retrieve the id to a corresponding - * name of a tag. - * An exception will be thrown upon error conditions. - * - * @param tag QString reference to name of tag - * - * @return MyMoneyTag object of tag - */ - MyMoneyTag tagByName(const QString& tag) const override; - - /** - * This method is used to modify an existing tag - * - * An exception will be thrown upon error conditions - * - * @param tag MyMoneyTag reference to tag information - */ - void modifyTag(const MyMoneyTag& tag) override; - - /** - * This method is used to remove an existing tag - * - * An exception will be thrown upon error conditions - * - * @param tag MyMoneyTag reference to tag information - */ - void removeTag(const MyMoneyTag& tag) override; - - /** - * This method returns a list of the tags - * inside a MyMoneyStorage object - * - * @return QList containing the tag information - */ - QList tagList() const override; - - /** @todo implement all onlineJob related functions @{ */ - void modifyOnlineJob(const onlineJob& job) override; - void addOnlineJob(onlineJob& job) override; - onlineJob getOnlineJob(const QString &jobId) const override; - QList onlineJobList() const override; - void removeOnlineJob(const onlineJob&) override; - /** @} */ - - /** - * Returns the account addressed by it's id. - * - * An exception will be thrown upon error conditions. - * - * @param id id of the account to locate. - * @return reference to MyMoneyAccount object. An exception is thrown - * if the id is unknown - */ - MyMoneyAccount account(const QString& id) const override; - - /** - * This method is used to check whether a given - * account id references one of the standard accounts or not. - * - * An exception will be thrown upon error conditions. - * - * @param id account id - * @return true if account-id is one of the standards, false otherwise - */ - bool isStandardAccount(const QString& id) const override; - - /** - * This method is used to set the name for the specified standard account - * within the storage area. An exception will be thrown, if an error - * occurs - * - * @param id QString reference to one of the standard accounts. - * @param name QString reference to the name to be set - * - */ - void setAccountName(const QString& id, const QString& name) override; - - /** - * Adds an institution to the storage. A - * respective institution-ID will be generated within this record. - * The ID is stored as QString in the object passed as argument. - * - * An exception will be thrown upon error conditions. - * - * @param institution The complete institution information in a - * MyMoneyInstitution object - */ - void addInstitution(MyMoneyInstitution& institution) override; - - /** - * Adds a transaction to the file-global transaction pool. A respective - * transaction-ID will be generated within this record. The ID is stored - * QString with the object. - * - * An exception will be thrown upon error conditions. - * - * @param transaction reference to the transaction - * @param skipAccountUpdate if set, the transaction lists of the accounts - * referenced in the splits are not updated. This is used for - * bulk loading a lot of transactions but not during normal operation - */ - void addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate = false) override; - - /** - * This method is used to determince, if the account with the - * given ID is referenced by any split in m_transactionList. - * - * An exception will be thrown upon error conditions. - * - * @param id id of the account to be checked for - * @return true if account is referenced, false otherwise - */ - bool hasActiveSplits(const QString& id) const override; - - /** - * This method is used to return the actual balance of an account - * without it's sub-ordinate accounts. If a @p date is presented, - * the balance at the beginning of this date (not including any - * transaction on this date) is returned. Otherwise all recorded - * transactions are included in the balance. - * - * @param id id of the account in question - * @param date return balance for specific date - * @return balance of the account as MyMoneyMoney object - */ - MyMoneyMoney balance(const QString& id, const QDate& date) const override; - - /** - * This method is used to return the actual balance of an account - * including it's sub-ordinate accounts. If a @p date is presented, - * the balance at the beginning of this date (not including any - * transaction on this date) is returned. Otherwise all recorded - * transactions are included in the balance. - * - * @param id id of the account in question - * @param date return balance for specific date - * @return balance of the account as MyMoneyMoney object - */ - MyMoneyMoney totalBalance(const QString& id, const QDate& date) const override; - - /** - * Returns the institution of a given ID - * - * @param id id of the institution to locate - * @return MyMoneyInstitution object filled with data. If the institution - * could not be found, an exception will be thrown - */ - MyMoneyInstitution institution(const QString& id) const override; - - /** - * This method returns an indicator if the storage object has been - * changed after it has last been saved to permanent storage. - * - * @return true if changed, false if not (for a database, always false). - */ - bool dirty() const override; - - /** - * This method can be used by an external object to force the - * storage object to be dirty. This is used e.g. when an upload - * to an external destination failed but the previous storage - * to a local disk was ok. - * - * Since the database is synchronized with the application, this method - * is a no-op. - */ - void setDirty() override; - - /** - * This method returns the number of accounts currently known to this storage - * in the range 0..MAXUINT - * - * @return number of accounts currently known inside a MyMoneyFile object - */ - uint accountCount() const override; - - /** - * This method returns a list of the institutions - * inside a MyMoneyStorage object - * - * @return QList containing the - * institution information - */ - QList institutionList() const override; - - /** - * Modifies an already existing account in the file global account pool. - * - * An exception will be thrown upon error conditions. - * - * @param account reference to the new account information - * @param skipCheck allows to skip the builtin consistency checks - */ - void modifyAccount(const MyMoneyAccount& account, bool skipCheck = false) override; - - /** - * Modifies an already existing institution in the file global - * institution pool. - * - * An exception will be thrown upon error conditions. - * - * @param institution The complete new institution information - */ - void modifyInstitution(const MyMoneyInstitution& institution) override; - - /** - * This method is used to update a specific transaction in the - * transaction pool of the MyMoneyFile object - * - * An exception will be thrown upon error conditions. - * - * @param transaction reference to transaction to be changed - */ - void modifyTransaction(const MyMoneyTransaction& transaction) override; - - /** - * This method re-parents an existing account - * - * An exception will be thrown upon error conditions. - * - * @param account MyMoneyAccount reference to account to be re-parented - * @param parent MyMoneyAccount reference to new parent account - */ - void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent) override; - - /** - * This method is used to remove a transaction from the transaction - * pool (journal). - * - * An exception will be thrown upon error conditions. - * - * @param transaction const reference to transaction to be deleted - */ - void removeTransaction(const MyMoneyTransaction& transaction) override; - - /** - * This method returns the number of transactions currently known to file - * in the range 0..MAXUINT - * - * @param account QString reference to account id. If account is empty - + all transactions (the journal) will be counted. If account - * is not empty it returns the number of transactions - * that have splits in this account. - * - * @return number of transactions in journal/account - */ - uint transactionCount(const QString& account) const override; - - /** - * This method returns a QMap filled with the number of transactions - * per account. The account id serves as index into the map. If one - * needs to have all transactionCounts() for many accounts, this method - * is faster than calling transactionCount(const QString& account) many - * times. - * - * @return QMap with numbers of transactions per account - */ - QMap transactionCountMap() const override; - - /** - * This method is used to pull a list of transactions from the file - * global transaction pool. It returns all those transactions - * that match the filter passed as argument. If the filter is empty, - * the whole journal will be returned. - * The list returned is sorted according to the transactions posting date. - * If more than one transaction exists for the same date, the order among - * them is undefined. - * - * @param filter MyMoneyTransactionFilter object with the match criteria - * - * @return set of transactions in form of a QList - */ - QList transactionList(MyMoneyTransactionFilter& filter) const override; - - /** - * This method is the same as above, but instead of a return value, a - * parameter is used. - * - * @param list The set of transactions returned. The list passed in will - * be cleared before filling with results. - * @param filter MyMoneyTransactionFilter object with the match criteria - */ - void transactionList(QList& list, MyMoneyTransactionFilter& filter) const override; - - /** - * This method is the same as above, but the list contains pairs of - * transactions and splits. - * - * @param list The set of transactions returned. The list passed in will - * be cleared before filling with results. - * @param filter MyMoneyTransactionFilter object with the match criteria - */ - void transactionList(QList >& list, MyMoneyTransactionFilter& filter) const override; - - /** - * Deletes an existing account from the file global account pool - * This method only allows to remove accounts that are not - * referenced by any split. Use moveSplits() to move splits - * to another account. An exception is thrown in case of a - * problem. - * - * @param account reference to the account to be deleted. - */ - void removeAccount(const MyMoneyAccount& account) override; - - /** - * Deletes an existing institution from the file global institution pool - * Also modifies the accounts that reference this institution as - * their institution. - * - * An exception will be thrown upon error conditions. - * - * @param institution institution to be deleted. - */ - void removeInstitution(const MyMoneyInstitution& institution) override; - - /** - * This method is used to extract a transaction from the file global - * transaction pool through an id. In case of an invalid id, an - * exception will be thrown. - * - * @param id id of transaction as QString. - * @return the requested transaction - */ - MyMoneyTransaction transaction(const QString& id) const override; - - /** - * This method is used to extract a transaction from the file global - * transaction pool through an index into an account. - * - * @param account id of the account as QString - * @param idx number of transaction in this account - * @return MyMoneyTransaction object - */ - MyMoneyTransaction transaction(const QString& account, const int idx) const override; - - /** - * This method returns the number of institutions currently known to file - * in the range 0..MAXUINT - * - * @return number of institutions known to file - */ - uint institutionCount() const override; - - /** - * This method returns a list of accounts inside the storage object. - * - * @param list reference to QList receiving the account objects - * - * @note The standard accounts will not be returned - */ - void accountList(QList& list) const override; - - /** - * This method is used to return the standard liability account - * @return MyMoneyAccount liability account(group) - */ - MyMoneyAccount liability() const override; - - /** - * This method is used to return the standard asset account - * @return MyMoneyAccount asset account(group) - */ - MyMoneyAccount asset() const override; - - /** - * This method is used to return the standard expense account - * @return MyMoneyAccount expense account(group) - */ - MyMoneyAccount expense() const override; - - /** - * This method is used to return the standard income account - * @return MyMoneyAccount income account(group) - */ - MyMoneyAccount income() const override; - - /** - * This method is used to return the standard equity account - * @return MyMoneyAccount equity account(group) - */ - MyMoneyAccount equity() const override; - - /** - * This method is used to create a new security object. The ID will be - * created automatically. The object passed with the parameter @p security - * is modified to contain the assigned id. - * - * An exception will be thrown upon error conditions. - * - * @param security MyMoneySecurity filled with data - */ - void addSecurity(MyMoneySecurity& security) override; - - /** - * This method is used to modify an existing MyMoneySecurity - * object. - * - * An exception will be thrown upon erroneous situations. - * - * @param security reference to the MyMoneySecurity object to be updated - */ - void modifySecurity(const MyMoneySecurity& security) override; - - /** - * This method is used to remove an existing MyMoneySecurity object - * from the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @param security reference to the MyMoneySecurity object to be removed - */ - void removeSecurity(const MyMoneySecurity& security) override; - - /** - * This method is used to retrieve a single MyMoneySecurity object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneySecurity object - * @return MyMoneySecurity object - */ - MyMoneySecurity security(const QString& id) const override; - - /** - * This method returns a list of the security objects - * inside a MyMoneyStorage object - * - * @return QList containing objects - */ - QList securityList() const override; - - void addPrice(const MyMoneyPrice& price) override; - void removePrice(const MyMoneyPrice& price) override; - MyMoneyPrice price(const QString& fromId, const QString& toId, const QDate& _date, bool exactDate) const override; - - /** - * This method returns a list of all prices. - * - * @return MyMoneyPriceList of all MyMoneyPrice objects. - */ - MyMoneyPriceList priceList() const override; - - /** - * This method is used to add a scheduled transaction to the engine. - * It must be sure, that the id of the object is not filled. When the - * method returns to the caller, the id will be filled with the - * newly created object id value. - * - * An exception will be thrown upon erroneous situations. - * - * @param sched reference to the MyMoneySchedule object - */ - void addSchedule(MyMoneySchedule& sched) override; - - /** - * This method is used to modify an existing MyMoneySchedule - * object. Therefor, the id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param sched const reference to the MyMoneySchedule object to be updated - */ - void modifySchedule(const MyMoneySchedule& sched) override; - - /** - * This method is used to remove an existing MyMoneySchedule object - * from the engine. The id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param sched const reference to the MyMoneySchedule object to be updated - */ - void removeSchedule(const MyMoneySchedule& sched) override; - - /** - * This method is used to retrieve a single MyMoneySchedule object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneySchedule object - * @return MyMoneySchedule object - */ - MyMoneySchedule schedule(const QString& id) const override; - - /** - * This method is used to extract a list of scheduled transactions - * according to the filter criteria passed as arguments. - * - * @param accountId only search for scheduled transactions that reference - * accound @p accountId. If accountId is the empty string, - * this filter is off. Default is @p QString(). - * @param type only schedules of type @p type are searched for. - * See eMyMoney::Schedule::Type for details. - * Default is eMyMoney::Schedule::Type::Any - * @param occurrence only schedules of occurrence type @p occurrence are searched for. - * See eMyMoney::Schedule::Occurrence for details. - * Default is eMyMoney::Schedule::Occurrence::Any - * @param paymentType only schedules of payment method @p paymentType - * are searched for. - * See eMyMoney::Schedule::PaymentType for details. - * Default is eMyMoney::Schedule::PaymentType::Any - * @param startDate only schedules with payment dates after @p startDate - * are searched for. Default is all dates (QDate()). - * @param endDate only schedules with payment dates ending prior to @p endDate - * are searched for. Default is all dates (QDate()). - * @param overdue if true, only those schedules that are overdue are - * searched for. Default is false (all schedules will be returned). - * - * @return QList list of schedule objects. - */ - QList scheduleList(const QString& accountId, - eMyMoney::Schedule::Type type, - eMyMoney::Schedule::Occurrence occurrence, - eMyMoney::Schedule::PaymentType paymentType, - const QDate& startDate, - const QDate& endDate, - bool overdue) const override; - - QList scheduleListEx(int scheduleTypes, - int scheduleOcurrences, - int schedulePaymentTypes, - QDate startDate, - const QStringList& accounts) const override; - - /** - * This method is used to add a new currency object to the engine. - * The ID of the object is the trading symbol, so there is no need for an additional - * ID since the symbol is guaranteed to be unique. - * - * An exception will be thrown upon erroneous situations. - * - * @param currency reference to the MyMoneySecurity object - */ - void addCurrency(const MyMoneySecurity& currency) override; - - /** - * This method is used to modify an existing MyMoneySecurity - * object. - * - * An exception will be thrown upon erroneous situations. - * - * @param currency reference to the MyMoneyCurrency object - */ - void modifyCurrency(const MyMoneySecurity& currency) override; - - /** - * This method is used to remove an existing MyMoneySecurity object - * from the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @param currency reference to the MyMoneySecurity object - */ - void removeCurrency(const MyMoneySecurity& currency) override; - - /** - * This method is used to retrieve a single MyMoneySecurity object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneySecurity object - * @return MyMoneyCurrency object - */ - MyMoneySecurity currency(const QString& id) const override; - - /** - * This method is used to retrieve the list of all currencies - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneySecurity objects representing a currency. - */ - QList currencyList() const override; - - /** - * This method is used to retrieve the list of all reports - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneyReport objects. - */ - QList reportList() const override; - - /** - * This method is used to add a new report to the engine. - * It must be sure, that the id of the object is not filled. When the - * method returns to the caller, the id will be filled with the - * newly created object id value. - * - * An exception will be thrown upon erroneous situations. - * - * @param report reference to the MyMoneyReport object - */ - void addReport(MyMoneyReport& report) override; - - /** - * This method is used to modify an existing MyMoneyReport - * object. Therefor, the id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param report const reference to the MyMoneyReport object to be updated - */ - void modifyReport(const MyMoneyReport& report) override; - - /** - * This method returns the number of reports currently known to file - * in the range 0..MAXUINT - * - * @return number of reports known to file - */ - uint countReports() const override; - - /** - * This method is used to retrieve a single MyMoneyReport object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneyReport object - * @return MyMoneyReport object - */ - MyMoneyReport report(const QString& id) const override; - - /** - * This method is used to remove an existing MyMoneyReport object - * from the engine. The id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param report const reference to the MyMoneyReport object to be updated - */ - void removeReport(const MyMoneyReport& report) override; - - /** - * This method is used to retrieve the list of all budgets - * known to the engine. - * - * An exception will be thrown upon erroneous situations. - * - * @return QList of all MyMoneyBudget objects. - */ - QList budgetList() const override; - - /** - * This method is used to add a new budget to the engine. - * It must be sure, that the id of the object is not filled. When the - * method returns to the caller, the id will be filled with the - * newly created object id value. - * - * An exception will be thrown upon erroneous situations. - * - * @param budget reference to the MyMoneyBudget object - */ - void addBudget(MyMoneyBudget& budget) override; - - /** - * This method is used to retrieve the id to a corresponding - * name of a budget - * An exception will be thrown upon error conditions. - * - * @param budget QString reference to name of budget - * - * @return MyMoneyBudget object of budget - */ - MyMoneyBudget budgetByName(const QString& budget) const override; - - /** - * This method is used to modify an existing MyMoneyBudget - * object. Therefor, the id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param budget const reference to the MyMoneyBudget object to be updated - */ - void modifyBudget(const MyMoneyBudget& budget) override; - - /** - * This method returns the number of budgets currently known to file - * in the range 0..MAXUINT - * - * @return number of budgets known to file - */ - uint countBudgets() const override; - - /** - * This method is used to retrieve a single MyMoneyBudget object. - * The id of the object must be supplied in the parameter @p id. - * - * An exception will be thrown upon erroneous situations. - * - * @param id QString containing the id of the MyMoneyBudget object - * @return MyMoneyBudget object - */ - MyMoneyBudget budget(const QString& id) const override; - - /** - * This method is used to remove an existing MyMoneyBudget object - * from the engine. The id attribute of the object must be set. - * - * An exception will be thrown upon erroneous situations. - * - * @param budget const reference to the MyMoneyBudget object to be updated - */ - void removeBudget(const MyMoneyBudget& budget) override; - - /** - * This method returns a list of all cost center objects - */ - QList costCenterList() const override; - - /** - * @brief Return cost center object by id - */ - MyMoneyCostCenter costCenter(const QString& id) const override; - - /** - * Clear all internal caches (used internally for performance measurements) - */ - void clearCache(); - - /** - * This method checks, if the given @p object is referenced - * by another engine object. - * - * @param obj const reference to object to be checked - * @param skipCheck QBitArray with eStorage::Reference bits set for which - * the check should be skipped - * - * @retval false @p object is not referenced - * @retval true @p institution is referenced - */ - bool isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const override; - - /** - * This method is provided to allow closing of the database before logoff - */ - void close() override; - - /** - * These methods have to be provided to allow transaction safe data handling. - */ - void startTransaction() override; - bool commitTransaction() override; - void rollbackTransaction() override; - - // general set functions - void setCreationDate(const QDate& val) override; - - /** - * This method is used to get a SQL reader for subsequent database access - */ - QExplicitlySharedDataPointer connectToDatabase - (const QUrl &url) override; - /** - * This method is used when a database file is open, and the data is to - * be saved in a different file or format. It will ensure that all data - * from the database is available in memory to enable it to be written. - */ - void fillStorage() override; - - /** - * This method is used to set the last modification date of - * the storage object. It also clears the dirty flag and should - * therefor be called as last operation when loading from a - * file. - * - * @param val QDate of last modification - */ - void setLastModificationDate(const QDate& val) override; - - /** - * This method returns whether a given transaction is already in memory, to avoid - * reloading it from the database - */ - bool isDuplicateTransaction(const QString&) const override; - - void loadAccounts(const QMap& map) override; - void loadTransactions(const QMap& map) override; - void loadInstitutions(const QMap& map) override; - void loadPayees(const QMap& map) override; - void loadTags(const QMap& map) override; - void loadSchedules(const QMap& map) override; - void loadSecurities(const QMap& map) override; - void loadCurrencies(const QMap& map) override; - void loadReports(const QMap& reports) override; - void loadBudgets(const QMap& budgets) override; - void loadPrices(const MyMoneyPriceList& list) override; - void loadOnlineJobs(const QMap& onlineJobs) override; - void loadCostCenters(const QMap& costCenters) override; - - //void loadPayeeIdentifier(const QMap& idents); - - ulong accountId() const override; - ulong transactionId() const override; - ulong payeeId() const override; - ulong tagId() const override; - ulong institutionId() const override; - ulong scheduleId() const override; - ulong securityId() const override; - ulong reportId() const override; - ulong budgetId() const override; - ulong onlineJobId() const override; - ulong payeeIdentifierId() const; - ulong costCenterId() const override; - - void loadAccountId(ulong id) override; - void loadTransactionId(ulong id) override; - void loadPayeeId(ulong id) override; - void loadTagId(ulong id) override; - void loadInstitutionId(ulong id) override; - void loadScheduleId(ulong id) override; - void loadSecurityId(ulong id) override; - void loadReportId(ulong id) override; - void loadBudgetId(ulong id) override; - void loadOnlineJobId(ulong id) override; - void loadPayeeIdentifierId(ulong id); - void loadCostCenterId(ulong id) override; - - /** - * This method is used to retrieve the whole set of key/value pairs - * from the container. It is meant to be used for permanent storage - * functionality. See MyMoneyKeyValueContainer::pairs() for details. - * - * @return QMap containing all key/value pairs of - * this container. - */ - QMap pairs() const override; - - /** - * This method is used to initially store a set of key/value pairs - * in the container. It is meant to be used for loading functionality - * from permanent storage. See MyMoneyKeyValueContainer::setPairs() - * for details - * - * @param list const QMap containing the set of - * key/value pairs to be loaded into the container. - * - * @note All existing key/value pairs in the container will be deleted. - */ - void setPairs(const QMap& list) override; - - /** - * This method recalculates the balances of all accounts - * based on the transactions stored in the engine. - */ - void rebuildAccountBalances() override; - -private: - MyMoneyDatabaseMgrPrivate* const d_ptr; - Q_DECLARE_PRIVATE_D(MyMoneyDatabaseMgr::d_ptr, MyMoneyDatabaseMgr) - - /** - * This method is used to get the next valid ID for a institution - * @return id for a institution - */ - QString nextInstitutionID() override; - - /** - * This method is used to get the next valid ID for an account - * @return id for an account - */ - QString nextAccountID() override; - - /** - * This method is used to get the next valid ID for a transaction - * @return id for a transaction - */ - QString nextTransactionID() override; - - /** - * This method is used to get the next valid ID for a payee - * @return id for a payee - */ - QString nextPayeeID() override; - - /** - * This method is used to get the next valid ID for a tag - * @return id for a tag - */ - QString nextTagID() override; - - /** - * This method is used to get the next valid ID for a scheduled transaction - * @return id for a scheduled transaction - */ - QString nextScheduleID() override; - - /** - * This method is used to get the next valid ID for an security object. - * @return id for an security object - */ - QString nextSecurityID() override; - - QString nextReportID() override; - - /** @brief get next valid id for an onlineJob */ - QString nextOnlineJobID() override; - - /** @brief get next valid id for payeeIdentifier */ - QString nextPayeeIdentifierID(); - - /** @brief get next valid id for a cost center */ - QString nextCostCenterID() override; - - /** - * This method is used to get the next valid ID for a budget object. - * @return id for an budget object - */ - QString nextBudgetID() override; - -}; -#endif diff --git a/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp b/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp deleted file mode 100644 --- a/kmymoney/mymoney/storage/mymoneydatabasemgr.cpp +++ /dev/null @@ -1,2440 +0,0 @@ -/*************************************************************************** - mymoneydatabasemgr.cpp - ------------------- - begin : June 5 2007 - copyright : (C) 2007 by Fernando Vilas - email : Fernando Vilas - 2017 by Ł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. * - * * - ***************************************************************************/ - -#include "mymoneydatabasemgr_p.h" - -// ---------------------------------------------------------------------------- -// QT Includes - -// ---------------------------------------------------------------------------- -// KDE Includes - -// ---------------------------------------------------------------------------- -// Project Includes - -#include "mymoneytransaction.h" -#include "mymoneyprice.h" -#include "onlinejob.h" -#include "mymoneystoragenames.h" - -using namespace eStorage; -using namespace MyMoneyStandardAccounts; - -const int INSTITUTION_ID_SIZE = 6; -const int ACCOUNT_ID_SIZE = 6; -const int TRANSACTION_ID_SIZE = 18; -const int PAYEE_ID_SIZE = 6; -const int TAG_ID_SIZE = 6; -const int SCHEDULE_ID_SIZE = 6; -const int SECURITY_ID_SIZE = 6; -const int REPORT_ID_SIZE = 6; -const int BUDGET_ID_SIZE = 6; -const int ONLINEJOB_ID_SIZE = 8; -const int PAYEEIDENTIFIER_ID_SIZE = 6; -const int COSTCENTER_ID_SIZE = 6; - -// Increment this to force an update in KMMView. -// This is different from the db schema version stored in -// MMStorageSql::m_majorVersion -const int CURRENT_FIX_VERSION = 4; - -MyMoneyDatabaseMgr::MyMoneyDatabaseMgr() : - d_ptr(new MyMoneyDatabaseMgrPrivate(this)) -{ -} - -MyMoneyDatabaseMgr::~MyMoneyDatabaseMgr() -{ - Q_D(MyMoneyDatabaseMgr); - delete d; -} - -// general get functions -MyMoneyPayee MyMoneyDatabaseMgr::user() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_user; -} - -QDate MyMoneyDatabaseMgr::creationDate() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_creationDate; -} - -QDate MyMoneyDatabaseMgr::lastModificationDate() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_lastModificationDate; -} - -uint MyMoneyDatabaseMgr::currentFixVersion() const -{ - return CURRENT_FIX_VERSION; -} - -uint MyMoneyDatabaseMgr::fileFixVersion() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_fileFixVersion; -} - -// general set functions -void MyMoneyDatabaseMgr::setUser(const MyMoneyPayee& user) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_user = user; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - d->m_sql->modifyUserInfo(user); - } -} - -void MyMoneyDatabaseMgr::setFileFixVersion(uint v) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_fileFixVersion = v; -} - -// methods provided by MyMoneyKeyValueContainer -QString MyMoneyDatabaseMgr::value(const QString& key) const -{ - return MyMoneyKeyValueContainer::value(key); -} - -void MyMoneyDatabaseMgr::setValue(const QString& key, const QString& val) -{ - MyMoneyKeyValueContainer::setValue(key, val); -} - -void MyMoneyDatabaseMgr::deletePair(const QString& key) -{ - MyMoneyKeyValueContainer::deletePair(key); -} - -QMap MyMoneyDatabaseMgr::pairs() const -{ - return MyMoneyKeyValueContainer::pairs(); -} - -void MyMoneyDatabaseMgr::setPairs(const QMap& list) -{ - MyMoneyKeyValueContainer::setPairs(list); -} - -//MyMoneyDatabaseMgr const * MyMoneyDatabaseMgr::duplicate() -//{ -// MyMoneyDatabaseMgr* that = new MyMoneyDatabaseMgr(); -// *that = *this; -// return that; -//} - -void MyMoneyDatabaseMgr::addAccount(MyMoneyAccount& account) -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - - // create the account. - MyMoneyAccount newAccount(nextAccountID(), account); - - d->m_sql->addAccount(newAccount); - account = newAccount; - } -} - -void MyMoneyDatabaseMgr::addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) -{ - Q_D(MyMoneyDatabaseMgr); - QMap accountList; - QStringList accountIdList; - QMap::ConstIterator theParent; - QMap::ConstIterator theChild; - - accountIdList << parent.id() << account.id(); - startTransaction(); - accountList = d->m_sql->fetchAccounts(accountIdList, true); - - theParent = accountList.constFind(parent.id()); - if (theParent == accountList.constEnd()) { - QString msg = "Unknown parent account '"; - msg += parent.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - theChild = accountList.constFind(account.id()); - if (theChild == accountList.constEnd()) { - QString msg = "Unknown child account '"; - msg += account.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - MyMoneyAccount acc = *theParent; - acc.addAccountId(account.id()); - parent = acc; - - acc = *theChild; - acc.setParentAccountId(parent.id()); - account = acc; - -//FIXME: MyMoneyBalanceCacheItem balance; -//FIXME: m_balanceCache[account.id()] = balance; - - QList aList; - aList << parent << account; - d->m_sql->modifyAccountList(aList); - commitTransaction(); -} - -void MyMoneyDatabaseMgr::addPayee(MyMoneyPayee& payee) -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen()) - static_cast(d->m_sql.data())->open(); - // create the payee - MyMoneyPayee newPayee(nextPayeeID(), payee); - - d->m_sql->addPayee(newPayee); - payee = newPayee; - } -} - -MyMoneyPayee MyMoneyDatabaseMgr::payee(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap::ConstIterator it; - QMap payeeList = d->m_sql->fetchPayees(QStringList(id)); - it = payeeList.constFind(id); - if (it == payeeList.constEnd()) - throw MYMONEYEXCEPTION("Unknown payee '" + id + '\''); - - return *it; -} - -MyMoneyPayee MyMoneyDatabaseMgr::payeeByName(const QString& payee) const -{ - Q_D(const MyMoneyDatabaseMgr); - if (payee.isEmpty()) - return MyMoneyPayee::null; - - QMap payeeList; - - try { - payeeList = d->m_sql->fetchPayees(); - } catch (const MyMoneyException &) { - throw; - } - - QMap::ConstIterator it_p; - - for (it_p = payeeList.constBegin(); it_p != payeeList.constEnd(); ++it_p) { - if ((*it_p).name() == payee) { - return *it_p; - } - } - - throw MYMONEYEXCEPTION("Unknown payee '" + payee + '\''); -} - -void MyMoneyDatabaseMgr::modifyPayee(const MyMoneyPayee& payee) -{ - Q_D(MyMoneyDatabaseMgr); - QMap payeeList = d->m_sql->fetchPayees(QStringList(payee.id()), true); - QMap::ConstIterator it; - - it = payeeList.constFind(payee.id()); - if (it == payeeList.constEnd()) { - QString msg = "Unknown payee '" + payee.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->modifyPayee(payee); -} - -void MyMoneyDatabaseMgr::removePayee(const MyMoneyPayee& payee) -{ - Q_D(MyMoneyDatabaseMgr); - QMap::ConstIterator it_t; - QMap::ConstIterator it_s; - QMap payeeList = d->m_sql->fetchPayees(QStringList(payee.id())); - QMap::ConstIterator it_p; - - it_p = payeeList.constFind(payee.id()); - if (it_p == payeeList.constEnd()) { - QString msg = "Unknown payee '" + payee.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - // scan all transactions to check if the payee is still referenced - - QMap transactionList = d->m_sql->fetchTransactions(); // make sure they're all here - for (it_t = transactionList.constBegin(); it_t != transactionList.constEnd(); ++it_t) { - if ((*it_t).hasReferenceTo(payee.id())) { - throw MYMONEYEXCEPTION(QString("Cannot remove payee that is still referenced to a %1").arg("transaction")); - } - } - - // check referential integrity in schedules - QMap scheduleList = d->m_sql->fetchSchedules(); // make sure they're all here - for (it_s = scheduleList.constBegin(); it_s != scheduleList.constEnd(); ++it_s) { - if ((*it_s).hasReferenceTo(payee.id())) { - throw MYMONEYEXCEPTION(QString("Cannot remove payee that is still referenced to a %1").arg("schedule")); - } - } - // remove any reference to report and/or budget - d->removeReferences(payee.id()); - - d->m_sql->removePayee(payee); -} - -QList MyMoneyDatabaseMgr::payeeList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchPayees().values(); - } else - return QList (); -} - -void MyMoneyDatabaseMgr::addTag(MyMoneyTag& tag) -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - // create the tag - MyMoneyTag newTag(nextTagID(), tag); - - d->m_sql->addTag(newTag); - tag = newTag; - } -} - -MyMoneyTag MyMoneyDatabaseMgr::tag(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap::ConstIterator it; - QMap tagList = d->m_sql->fetchTags(QStringList(id)); - it = tagList.constFind(id); - if (it == tagList.constEnd()) - throw MYMONEYEXCEPTION("Unknown tag '" + id + '\''); - - return *it; -} - -MyMoneyTag MyMoneyDatabaseMgr::tagByName(const QString& tag) const -{ - Q_D(const MyMoneyDatabaseMgr); - if (tag.isEmpty()) - return MyMoneyTag::null; - - QMap tagList; - - try { - tagList = d->m_sql->fetchTags(); - } catch (const MyMoneyException &) { - throw; - } - - QMap::ConstIterator it_ta; - - for (it_ta = tagList.constBegin(); it_ta != tagList.constEnd(); ++it_ta) { - if ((*it_ta).name() == tag) { - return *it_ta; - } - } - - throw MYMONEYEXCEPTION("Unknown tag '" + tag + '\''); -} - -void MyMoneyDatabaseMgr::modifyTag(const MyMoneyTag& tag) -{ - Q_D(MyMoneyDatabaseMgr); - QMap tagList = d->m_sql->fetchTags(QStringList(tag.id()), true); - QMap::ConstIterator it; - - it = tagList.constFind(tag.id()); - if (it == tagList.constEnd()) { - QString msg = "Unknown tag '" + tag.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->modifyTag(tag); -} - -void MyMoneyDatabaseMgr::removeTag(const MyMoneyTag& tag) -{ - Q_D(MyMoneyDatabaseMgr); - QMap::ConstIterator it_t; - QMap::ConstIterator it_s; - QMap tagList = d->m_sql->fetchTags(QStringList(tag.id())); - QMap::ConstIterator it_ta; - - it_ta = tagList.constFind(tag.id()); - if (it_ta == tagList.constEnd()) { - QString msg = "Unknown tag '" + tag.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - // scan all transactions to check if the tag is still referenced - - QMap transactionList = d->m_sql->fetchTransactions(); // make sure they're all here - for (it_t = transactionList.constBegin(); it_t != transactionList.constEnd(); ++it_t) { - if ((*it_t).hasReferenceTo(tag.id())) { - throw MYMONEYEXCEPTION(QString("Cannot remove tag that is still referenced to a %1").arg("transaction")); - } - } - - // check referential integrity in schedules - QMap scheduleList = d->m_sql->fetchSchedules(); // make sure they're all here - for (it_s = scheduleList.constBegin(); it_s != scheduleList.constEnd(); ++it_s) { - if ((*it_s).hasReferenceTo(tag.id())) { - throw MYMONEYEXCEPTION(QString("Cannot remove tag that is still referenced to a %1").arg("schedule")); - } - } - // remove any reference to report and/or budget - d->removeReferences(tag.id()); - - d->m_sql->removeTag(tag); -} - -QList MyMoneyDatabaseMgr::tagList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchTags().values(); - } else { - return QList (); - } -} - -void MyMoneyDatabaseMgr::modifyOnlineJob(const onlineJob& job) -{ - Q_D(MyMoneyDatabaseMgr); - if (job.id().isEmpty()) - throw MYMONEYEXCEPTION("empty online job id"); - d->m_sql->modifyOnlineJob(job); -} - -void MyMoneyDatabaseMgr::addOnlineJob(onlineJob& job) -{ - Q_D(MyMoneyDatabaseMgr); - job = onlineJob(nextOnlineJobID(), job); - d->m_sql->addOnlineJob(job); -} - -onlineJob MyMoneyDatabaseMgr::getOnlineJob(const QString &jobId) const -{ - Q_D(const MyMoneyDatabaseMgr); - if (jobId.isEmpty()) - throw MYMONEYEXCEPTION("empty online job id"); - - if (d->m_sql) { - if (! d->m_sql->isOpen()) - ((QSqlDatabase*)(d->m_sql.data()))->open(); - - QMap jobList = d->m_sql->fetchOnlineJobs(QStringList(jobId)); - QMap ::ConstIterator pos = jobList.constFind(jobId); - - // locate the account and if present, return it's data - if (pos != jobList.constEnd()) - return *pos; - } else { - throw MYMONEYEXCEPTION("No database connected"); - } - - // throw an exception, if it does not exist - throw MYMONEYEXCEPTION(QLatin1String("Unknown online job id '") + jobId + QLatin1Char('\'')); -} - -QList MyMoneyDatabaseMgr::onlineJobList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (!d->m_sql->isOpen()) - ((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchOnlineJobs().values(); - } - return QList(); -} - -void MyMoneyDatabaseMgr::removeOnlineJob(const onlineJob& job) -{ - Q_D(MyMoneyDatabaseMgr); - if (job.id().isEmpty()) - throw MYMONEYEXCEPTION("Empty online job id during remove."); - - d->m_sql->removeOnlineJob(job); -} - -MyMoneyAccount MyMoneyDatabaseMgr::account(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - if (id.isEmpty()) { - throw MYMONEYEXCEPTION("empty account id"); - } - - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - QMap accountList = d->m_sql->fetchAccounts(QStringList(id)); - QMap ::ConstIterator pos = accountList.constFind(id); - - // locate the account and if present, return it's data - if (pos != accountList.constEnd()) - return *pos; - } else { - throw MYMONEYEXCEPTION("No database connected"); - } - - // throw an exception, if it does not exist - QString msg = "Unknown account id '" + id + '\''; - throw MYMONEYEXCEPTION(msg); -} - -bool MyMoneyDatabaseMgr::isStandardAccount(const QString& id) const -{ - return id == stdAccNames[stdAccLiability] - || id == stdAccNames[stdAccAsset] - || id == stdAccNames[stdAccExpense] - || id == stdAccNames[stdAccIncome] - || id == stdAccNames[stdAccEquity]; -} - -void MyMoneyDatabaseMgr::setAccountName(const QString& id, const QString& name) -{ - Q_D(MyMoneyDatabaseMgr); - if (!isStandardAccount(id)) - throw MYMONEYEXCEPTION("Only standard accounts can be modified using setAccountName()"); - - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - startTransaction(); - MyMoneyAccount acc = d->m_sql->fetchAccounts(QStringList(id), true)[id]; - acc.setName(name); - d->m_sql->modifyAccount(acc); - commitTransaction(); - } -} - -void MyMoneyDatabaseMgr::addInstitution(MyMoneyInstitution& institution) -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - MyMoneyInstitution newInstitution(nextInstitutionID(), institution); - - // mark file as changed - d->m_sql->addInstitution(newInstitution); - - // return new data - institution = newInstitution; - } -} - -QString MyMoneyDatabaseMgr::nextPayeeID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementPayeeId())); - id = 'P' + id.rightJustified(PAYEE_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextTagID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementTagId())); - id = 'G' + id.rightJustified(TAG_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextInstitutionID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementInstitutionId())); - id = 'I' + id.rightJustified(INSTITUTION_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextAccountID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementAccountId())); - id = 'A' + id.rightJustified(ACCOUNT_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextBudgetID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementBudgetId())); - id = 'B' + id.rightJustified(BUDGET_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextReportID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementReportId())); - id = 'R' + id.rightJustified(REPORT_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextTransactionID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementTransactionId())); - id = 'T' + id.rightJustified(TRANSACTION_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextScheduleID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementScheduleId())); - id = "SCH" + id.rightJustified(SCHEDULE_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextSecurityID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(ulong(d->m_sql->incrementSecurityId())); - id = 'E' + id.rightJustified(SECURITY_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextOnlineJobID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(d->m_sql->incrementOnlineJobId()); - id = QLatin1Char('O') + id.rightJustified(ONLINEJOB_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextPayeeIdentifierID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(d->m_sql->incrementPayeeIdentfierId()); - id = QLatin1String("IDENT") + id.rightJustified(PAYEEIDENTIFIER_ID_SIZE, '0'); - } - return id; -} - -QString MyMoneyDatabaseMgr::nextCostCenterID() -{ - Q_D(MyMoneyDatabaseMgr); - QString id; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - id.setNum(d->m_sql->incrementCostCenterId()); - id = QLatin1Char('C') + id.rightJustified(COSTCENTER_ID_SIZE, '0'); - } - return id; -} - -void MyMoneyDatabaseMgr::addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate) -{ - Q_D(MyMoneyDatabaseMgr); - // perform some checks to see that the transaction stuff is OK. For - // now we assume that - // * no ids are assigned - // * the date valid (must not be empty) - // * the referenced accounts in the splits exist - - // first perform all the checks - if (!transaction.id().isEmpty()) - throw MYMONEYEXCEPTION("transaction already contains an id"); - if (!transaction.postDate().isValid()) - throw MYMONEYEXCEPTION("invalid post date"); - - // now check the splits - foreach (const MyMoneySplit& it_s, transaction.splits()) { - // the following lines will throw an exception if the - // account or payee do not exist - account(it_s.accountId()); - if (!it_s.payeeId().isEmpty()) - payee(it_s.payeeId()); - } - - MyMoneyTransaction newTransaction(nextTransactionID(), transaction); - QString key = newTransaction.uniqueSortKey(); - - d->m_sql->addTransaction(newTransaction); - - transaction = newTransaction; - - QList aList; - // adjust the balance of all affected accounts - foreach (const MyMoneySplit& it_s, transaction.splits()) { - MyMoneyAccount acc = account(it_s.accountId()); - acc.adjustBalance(it_s); - if (!skipAccountUpdate) { - acc.touch(); -//FIXME: invalidateBalanceCache(acc.id()); - } - aList << acc; - } - d->m_sql->modifyAccountList(aList); -} - -bool MyMoneyDatabaseMgr::hasActiveSplits(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap::ConstIterator it; - - MyMoneyTransactionFilter f(id); - QMap transactionList = d->m_sql->fetchTransactions(f); - - for (it = transactionList.constBegin(); it != transactionList.constEnd(); ++it) { - if ((*it).accountReferenced(id)) { - return true; - } - } - return false; -} - -/** - * This method is used to return the actual balance of an account - * without it's sub-ordinate accounts. If a @p date is presented, - * the balance at the beginning of this date (not including any - * transaction on this date) is returned. Otherwise all recorded - * transactions are included in the balance. - * - * @param id id of the account in question - * @param date return balance for specific date - * @return balance of the account as MyMoneyMoney object - */ -//MyMoneyMoney MyMoneyDatabaseMgr::balance(const QString& id, const QDate& date); - -MyMoneyMoney MyMoneyDatabaseMgr::totalBalance(const QString& id, const QDate& date) const -{ - Q_D(const MyMoneyDatabaseMgr); - QStringList accounts; - - MyMoneyMoney result; //(balance(id, date)); - - accounts = MyMoneyFile::instance()->account(id).accountList(); - foreach (const QString& it_a, accounts) { - if (!it_a.isEmpty()) { - accounts << MyMoneyFile::instance()->account(it_a).accountList(); - } - } - - // convert into a sorted list with each account only once - QMap tempList; - foreach (const QString& it_a, accounts) { - tempList[it_a] = true; - } - accounts = tempList.uniqueKeys(); - - QMap balanceMap = d->m_sql->fetchBalance(accounts, date); - for (QMap::ConstIterator it_b = balanceMap.constBegin(); it_b != balanceMap.constEnd(); ++it_b) { - result += it_b.value(); - } - - return result; -} - -MyMoneyInstitution MyMoneyDatabaseMgr::institution(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap::ConstIterator pos; - QMap institutionList = d->m_sql->fetchInstitutions(QStringList(id)); - - pos = institutionList.constFind(id); - if (pos != institutionList.constEnd()) - return *pos; - throw MYMONEYEXCEPTION("unknown institution"); -} - -bool MyMoneyDatabaseMgr::dirty() const -{ - return false; -} - -void MyMoneyDatabaseMgr::setDirty() -{} - -uint MyMoneyDatabaseMgr::accountCount() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getRecCount("kmmAccounts"); -} - -QList MyMoneyDatabaseMgr::institutionList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchInstitutions().values(); - } else { - return QList (); - } -} - -void MyMoneyDatabaseMgr::modifyAccount(const MyMoneyAccount& account, bool skipCheck) -{ - Q_D(MyMoneyDatabaseMgr); - QMap::ConstIterator pos; - - // locate the account in the file global pool - startTransaction(); - QMap accountList = d->m_sql->fetchAccounts(QStringList(account.id()), true); - pos = accountList.constFind(account.id()); - if (pos != accountList.constEnd()) { - // check if the new info is based on the old one. - // this is the case, when the file and the id - // as well as the type are equal. - if (((*pos).parentAccountId() == account.parentAccountId() - && ((*pos).accountType() == account.accountType() - || ((*pos).isLiquidAsset() && account.isLiquidAsset()))) - || skipCheck == true) { - // make sure that all the referenced objects exist - if (!account.institutionId().isEmpty()) - institution(account.institutionId()); - - //FIXME: fetch the whole list at once - foreach (const QString& it_a, account.accountList()) { - this->account(it_a); - } - - // update information in account list - //m_accountList.modify(account.id(), account); - - // invalidate cached balance -//FIXME: invalidateBalanceCache(account.id()); - - // mark file as changed - d->m_sql->modifyAccount(account); - commitTransaction(); - } else { - rollbackTransaction(); - throw MYMONEYEXCEPTION("Invalid information for update"); - } - - } else { - rollbackTransaction(); - throw MYMONEYEXCEPTION("Unknown account id"); - } -} - -void MyMoneyDatabaseMgr::modifyInstitution(const MyMoneyInstitution& institution) -{ - Q_D(MyMoneyDatabaseMgr); - QMap institutionList = d->m_sql->fetchInstitutions(QStringList(institution.id())); - QMap::ConstIterator pos; - - // locate the institution in the file global pool - pos = institutionList.constFind(institution.id()); - if (pos != institutionList.constEnd()) { - d->m_sql->modifyInstitution(institution); - } else - throw MYMONEYEXCEPTION("unknown institution"); -} - -/** - * This method is used to update a specific transaction in the - * transaction pool of the MyMoneyFile object - * - * An exception will be thrown upon error conditions. - * - * @param transaction reference to transaction to be changed - */ -void MyMoneyDatabaseMgr::modifyTransaction(const MyMoneyTransaction& transaction) -{ - Q_D(MyMoneyDatabaseMgr); - QMap modifiedAccounts; - - // perform some checks to see that the transaction stuff is OK. For - // now we assume that - // * ids are assigned - // * the pointer to the MyMoneyFile object is not 0 - // * the date valid (must not be empty) - // * the splits must have valid account ids - - // first perform all the checks - if (transaction.id().isEmpty() -// || transaction.file() != this - || !transaction.postDate().isValid()) - throw MYMONEYEXCEPTION("invalid transaction to be modified"); - - // now check the splits - foreach (const MyMoneySplit& it_s, transaction.splits()) { - // the following lines will throw an exception if the - // account, payee or tags do not exist - account(it_s.accountId()); - if (!it_s.payeeId().isEmpty()) - payee(it_s.payeeId()); - foreach (const QString& tagId, it_s.tagIdList()) { - if (!tagId.isEmpty()) - tag(tagId); - } - } - - // new data seems to be ok. find old version of transaction - // in our pool. Throw exception if unknown. -// if(!m_transactionKeys.contains(transaction.id())) -// throw MYMONEYEXCEPTION("invalid transaction id"); - -// QString oldKey = m_transactionKeys[transaction.id()]; - QMap transactionList = d->m_sql->fetchTransactions("('" + transaction.id() + "')"); -// if(transactionList.size() != 1) -// throw MYMONEYEXCEPTION("invalid transaction key"); - - QMap::ConstIterator it_t; - -// it_t = transactionList.find(oldKey); - it_t = transactionList.constBegin(); - if (it_t == transactionList.constEnd()) - throw MYMONEYEXCEPTION("invalid transaction key"); - - d->m_sql->modifyTransaction(transaction); - - // mark all accounts referenced in old and new transaction data - // as modified - QMap accountList = d->m_sql->fetchAccounts(); - QList aList; - foreach (const MyMoneySplit& it_s, (*it_t).splits()) { - MyMoneyAccount acc = accountList[it_s.accountId()]; - acc.adjustBalance(it_s, true); - acc.touch(); -//FIXME: invalidateBalanceCache(acc.id()); - //m_accountList.modify(acc.id(), acc); - aList << acc; - //modifiedAccounts[(*it_s).accountId()] = true; - } - d->m_sql->modifyAccountList(aList); - aList.clear(); - foreach (const MyMoneySplit& it_s, transaction.splits()) { - MyMoneyAccount acc = accountList[it_s.accountId()]; - acc.adjustBalance(it_s); - acc.touch(); -//FIXME: invalidateBalanceCache(acc.id()); - //m_accountList.modify(acc.id(), acc); - aList << acc; - //modifiedAccounts[(*it_s).accountId()] = true; - } - d->m_sql->modifyAccountList(aList); - - // remove old transaction from lists -// m_sql->removeTransaction(oldKey); - - // add new transaction to lists -// QString newKey = transaction.uniqueSortKey(); -// m_sql->insertTransaction(newKey, transaction); - //m_transactionKeys.modify(transaction.id(), newKey); -} - -void MyMoneyDatabaseMgr::reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent) -{ - Q_D(MyMoneyDatabaseMgr); - if (account.accountType() == eMyMoney::Account::Type::Stock && parent.accountType() != eMyMoney::Account::Type::Investment) - throw MYMONEYEXCEPTION("Cannot move a stock acocunt into a non-investment account"); - - QStringList accountIdList; - QMap::ConstIterator oldParent; - QMap::ConstIterator newParent; - QMap::ConstIterator childAccount; - - // verify that accounts exist. If one does not, - // an exception is thrown - accountIdList << account.id() << parent.id(); - MyMoneyDatabaseMgr::account(account.id()); - MyMoneyDatabaseMgr::account(parent.id()); - - if (!account.parentAccountId().isEmpty()) { - accountIdList << account.parentAccountId(); - } - - startTransaction(); - QMap accountList = d->m_sql->fetchAccounts(accountIdList, true); - - if (!account.parentAccountId().isEmpty()) { - MyMoneyDatabaseMgr::account(account.parentAccountId()); - oldParent = accountList.constFind(account.parentAccountId()); - } - - newParent = accountList.constFind(parent.id()); - childAccount = accountList.constFind(account.id()); - - MyMoneyAccount acc; - QList aList; - if (!account.parentAccountId().isEmpty()) { - acc = (*oldParent); - acc.removeAccountId(account.id()); - aList << acc; - } - - parent = (*newParent); - parent.addAccountId(account.id()); - - account = (*childAccount); - account.setParentAccountId(parent.id()); - - aList << parent << account; - d->m_sql->modifyAccountList(aList); - commitTransaction(); -} - -void MyMoneyDatabaseMgr::removeTransaction(const MyMoneyTransaction& transaction) -{ - Q_D(MyMoneyDatabaseMgr); - QMap modifiedAccounts; - - // first perform all the checks - if (transaction.id().isEmpty()) - throw MYMONEYEXCEPTION("invalid transaction to be deleted"); - - QMap::ConstIterator it_k; - QMap::ConstIterator it_t; - -// it_k = m_transactionKeys.find(transaction.id()); -// if(it_k == m_transactionKeys.end()) -// throw MYMONEYEXCEPTION("invalid transaction to be deleted"); - - QMap transactionList = d->m_sql->fetchTransactions("('" + QString(transaction.id()) + "')"); -// it_t = transactionList.find(*it_k); - it_t = transactionList.constBegin(); - if (it_t == transactionList.constEnd()) - throw MYMONEYEXCEPTION("invalid transaction key"); - - // scan the splits and collect all accounts that need - // to be updated after the removal of this transaction - QMap accountList = d->m_sql->fetchAccounts(); - QList aList; - foreach (const MyMoneySplit& it_s, (*it_t).splits()) { - MyMoneyAccount acc = accountList[it_s.accountId()]; -// modifiedAccounts[(*it_s).accountId()] = true; - acc.adjustBalance(it_s, true); - acc.touch(); - aList << acc; -//FIXME: invalidateBalanceCache(acc.id()); - } - d->m_sql->modifyAccountList(aList); - - // FIXME: check if any split is frozen and throw exception - - // remove the transaction from the two lists - //m_transactionList.remove(*it_k); -// m_transactionKeys.remove(transaction.id()); - - // mark file as changed - d->m_sql->removeTransaction(transaction); -} - -uint MyMoneyDatabaseMgr::transactionCount(const QString& account) const -{ - Q_D(const MyMoneyDatabaseMgr); - return (d->m_sql->transactionCount(account)); -} - -QMap MyMoneyDatabaseMgr::transactionCountMap() const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap retval; - QHash hash = d->m_sql->transactionCountMap(); - - for (QHash::ConstIterator i = hash.constBegin(); - i != hash.constEnd(); ++i) { - retval[i.key()] = i.value(); - } - return retval; -} - -QList MyMoneyDatabaseMgr::transactionList(MyMoneyTransactionFilter& filter) const -{ - QList list; - transactionList(list, filter); - return list; -} - -void MyMoneyDatabaseMgr::transactionList(QList& list, MyMoneyTransactionFilter& filter) const -{ - Q_D(const MyMoneyDatabaseMgr); - list.clear(); - - try { - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - list = d->m_sql->fetchTransactions(filter).values(); - } - } catch (const MyMoneyException &) { - throw; - } -} - -void MyMoneyDatabaseMgr::transactionList(QList >& list, MyMoneyTransactionFilter& filter) const -{ - Q_D(const MyMoneyDatabaseMgr); - list.clear(); - MyMoneyMap transactionList; - try { - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - transactionList = d->m_sql->fetchTransactions(filter); - } - } catch (const MyMoneyException &) { - throw; - } - - for (const auto& transaction : transactionList) - for (const auto& split : filter.matchingSplits(transaction)) - list.append(qMakePair(transaction, split)); -} - -void MyMoneyDatabaseMgr::removeAccount(const MyMoneyAccount& account) -{ - Q_D(MyMoneyDatabaseMgr); - MyMoneyAccount parent; - - // check that the account and it's parent exist - // this will throw an exception if the id is unknown - MyMoneyDatabaseMgr::account(account.id()); - parent = MyMoneyDatabaseMgr::account(account.parentAccountId()); - - // check that it's not one of the standard account groups - if (isStandardAccount(account.id())) - throw MYMONEYEXCEPTION("Unable to remove the standard account groups"); - - if (hasActiveSplits(account.id())) { - throw MYMONEYEXCEPTION("Unable to remove account with active splits"); - } - - // re-parent all sub-ordinate accounts to the parent of the account - // to be deleted. First round check that all accounts exist, second - // round do the re-parenting. - foreach (const QString& it, account.accountList()) { - MyMoneyDatabaseMgr::account(it); - } - - // if one of the accounts did not exist, an exception had been - // thrown and we would not make it until here. - - QStringList accountIdList; - accountIdList << parent.id() << account.id(); - startTransaction(); - QMap accountList = d->m_sql->fetchAccounts(accountIdList, true); - - QMap::ConstIterator it_a; - QMap::ConstIterator it_p; - - // locate the account in the file global pool - - it_a = accountList.constFind(account.id()); - if (it_a == accountList.constEnd()) - throw MYMONEYEXCEPTION("Internal error: account not found in list"); - - it_p = accountList.constFind(parent.id()); - if (it_p == accountList.constEnd()) - throw MYMONEYEXCEPTION("Internal error: parent account not found in list"); - - if (!account.institutionId().isEmpty()) - throw MYMONEYEXCEPTION("Cannot remove account still attached to an institution"); - - // FIXME: check referential integrity for the account to be removed - - // check if the new info is based on the old one. - // this is the case, when the file and the id - // as well as the type are equal. - if ((*it_a).id() == account.id() - && (*it_a).accountType() == account.accountType()) { - - // second round over sub-ordinate accounts: do re-parenting - // but only if the list contains at least one entry - // FIXME: move this logic to MyMoneyFile - if ((*it_a).accountList().count() > 0) { - foreach (const QString& it, (*it_a).accountList()) { - MyMoneyAccount acc(MyMoneyDatabaseMgr::account(it)); - reparentAccount(acc, parent);//, false); - } - } - // remove account from parent's list - parent.removeAccountId(account.id()); - d->m_sql->modifyAccount(parent); - - // remove account from the global account pool - //m_accountList.remove(account.id()); - - // remove from balance list -//FIXME: m_balanceCache.remove(account.id()); -//FIXME: invalidateBalanceCache(parent.id()); - - d->m_sql->removeAccount(account); - } - commitTransaction(); -} - -void MyMoneyDatabaseMgr::removeInstitution(const MyMoneyInstitution& institution) -{ - Q_D(MyMoneyDatabaseMgr); - QMap institutionList = d->m_sql->fetchInstitutions(QStringList(institution.id())); - QMap::ConstIterator it_i; - - it_i = institutionList.constFind(institution.id()); - if (it_i != institutionList.constEnd()) { - // mark file as changed - d->m_sql->removeInstitution(institution); - } else - throw MYMONEYEXCEPTION("invalid institution"); -} - -MyMoneyTransaction MyMoneyDatabaseMgr::transaction(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - // get the full key of this transaction, throw exception - // if it's invalid (unknown) - //if(!m_transactionKeys.contains(id)) - // throw MYMONEYEXCEPTION("invalid transaction id"); - - // check if this key is in the list, throw exception if not - //QString key = m_transactionKeys[id]; - QMap transactionList = d->m_sql->fetchTransactions("('" + QString(id) + "')"); - - //there should only be one transaction in the map, if it was found, so check the size of the map - //return the first element. - //if(!transactionList.contains(key)) - if (!transactionList.size()) - throw MYMONEYEXCEPTION("invalid transaction key"); - - return transactionList.begin().value(); -} - -MyMoneyMoney MyMoneyDatabaseMgr::balance(const QString& id, const QDate& date) const -{ - Q_D(const MyMoneyDatabaseMgr); - MyMoneyMoney result; - QStringList idList; - idList.append(id); - QMap tempMap = d->m_sql->fetchBalance(idList, date); - - QMap::ConstIterator returnValue = tempMap.constFind(id); - if (returnValue != tempMap.constEnd()) { - result = returnValue.value(); - return result; - } - -//DEBUG - QDate date_(date); - //if (date_ == QDate()) date_ = QDate::currentDate(); -// END DEBUG - -// MyMoneyAccount acc; - QMap accountList = d->m_sql->fetchAccounts(/*QString(id)*/); - //QMap::const_iterator accpos = accountList.find(id); - if (date_ != QDate()) qDebug("request balance for %s at %s", qPrintable(id), qPrintable(date_.toString(Qt::ISODate))); -// if(!date_.isValid() && MyMoneyFile::instance()->account(id).accountType() != eMyMoney::Account::Type::Stock) { -// if(accountList.find(id) != accountList.end()) -// return accountList[id].balance(); -// return MyMoneyMoney(0); -// } - if (/*m_balanceCache[id].valid == false || date != m_balanceCacheDate) || */ d->m_sql) { - QMap balances; - QMap::ConstIterator it_b; -//FIXME: if (date != m_balanceCacheDate) { -//FIXME: m_balanceCache.clear(); -//FIXME: m_balanceCacheDate = date; -//FIXME: } - - MyMoneyTransactionFilter filter; - filter.addAccount(id); - filter.setDateFilter(QDate(), date_); - filter.setReportAllSplits(false); - QList list = transactionList(filter); - - foreach (const MyMoneyTransaction& it_t, list) { - foreach (const MyMoneySplit& it_s, it_t.splits()) { - const QString aid = it_s.accountId(); - if (it_s.action() == MyMoneySplit::actionName(eMyMoney::Split::Action::SplitShares)) { - balances[aid] *= it_s.shares(); - } else { - balances[aid] += it_s.value(it_t.commodity(), accountList[aid].currencyId()); - } - } - } - - // fill the found balances into the cache -//FIXME: for(it_b = balances.begin(); it_b != balances.end(); ++it_b) { -//FIXME: MyMoneyBalanceCacheItem balance(*it_b); -//FIXME: m_balanceCache[it_b.key()] = balance; -//FIXME: } - - // fill all accounts w/o transactions to zero -// if (m_sql != 0) { -// QMap::ConstIterator it_a; -// for(it_a = m_accountList.begin(); it_a != m_accountList.end(); ++it_a) { -//FIXME: if(m_balanceCache[(*it_a).id()].valid == false) { -//FIXME: MyMoneyBalanceCacheItem balance(MyMoneyMoney(0,1)); -//FIXME: m_balanceCache[(*it_a).id()] = balance; -//FIXME: } -// } -// } - - result = balances[id]; - - } - -//FIXME: if(m_balanceCache[id].valid == true) -//FIXME: result = m_balanceCache[id].balance; -//FIXME: else -//FIXME: qDebug("Cache mishit should never happen at this point"); - - return result; -} - -MyMoneyTransaction MyMoneyDatabaseMgr::transaction(const QString& account, const int idx) const -{ - Q_D(const MyMoneyDatabaseMgr); - /* removed with MyMoneyAccount::Transaction - QMap::ConstIterator acc; - - // find account object in list, throw exception if unknown - acc = m_accountList.find(account); - if(acc == m_accountList.end()) - throw MYMONEYEXCEPTION("unknown account id"); - - // get the transaction info from the account - MyMoneyAccount::Transaction t = (*acc).transaction(idx); - - // return the transaction, throw exception if not found - return transaction(t.transactionID()); - */ - - // new implementation if the above code does not work anymore - QList list; - //MyMoneyAccount acc = m_accountList[account]; - MyMoneyAccount acc = d->m_sql->fetchAccounts(QStringList(account))[account]; - MyMoneyTransactionFilter filter; - - if (acc.accountGroup() == eMyMoney::Account::Type::Income - || acc.accountGroup() == eMyMoney::Account::Type::Expense) - filter.addCategory(account); - else - filter.addAccount(account); - - transactionList(list, filter); - if (idx < 0 || idx >= static_cast(list.count())) - throw MYMONEYEXCEPTION("Unknown idx for transaction"); - - return transaction(list[idx].id()); -} - -uint MyMoneyDatabaseMgr::institutionCount() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getRecCount("kmmInstitutions"); -} - -void MyMoneyDatabaseMgr::accountList(QList& list) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap accountList; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - accountList = d->m_sql->fetchAccounts(); - } - QMap::ConstIterator it; - QMap::ConstIterator accEnd = accountList.constEnd(); - for (it = accountList.constBegin(); it != accEnd; ++it) { - if (!isStandardAccount((*it).id())) { - list.append(*it); - } - } -} - -MyMoneyAccount MyMoneyDatabaseMgr::liability() const -{ - return MyMoneyFile::instance()->account(stdAccNames[stdAccLiability]); -} - -MyMoneyAccount MyMoneyDatabaseMgr::asset() const -{ - return MyMoneyFile::instance()->account(stdAccNames[stdAccAsset]); -} - -MyMoneyAccount MyMoneyDatabaseMgr::expense() const -{ - return MyMoneyFile::instance()->account(stdAccNames[stdAccExpense]); -} - -MyMoneyAccount MyMoneyDatabaseMgr::income() const -{ - return MyMoneyFile::instance()->account(stdAccNames[stdAccIncome]); -} - -MyMoneyAccount MyMoneyDatabaseMgr::equity() const -{ - return MyMoneyFile::instance()->account(stdAccNames[stdAccEquity]); -} - -void MyMoneyDatabaseMgr::addSecurity(MyMoneySecurity& security) -{ - Q_D(MyMoneyDatabaseMgr); - // create the account - try { - startTransaction(); - MyMoneySecurity newSecurity(nextSecurityID(), security); - - d->m_sql->addSecurity(newSecurity); - security = newSecurity; - commitTransaction(); - } catch (...) { - rollbackTransaction(); - throw; - } -} - -void MyMoneyDatabaseMgr::modifySecurity(const MyMoneySecurity& security) -{ - Q_D(MyMoneyDatabaseMgr); - QMap securitiesList = d->m_sql->fetchSecurities(QStringList(security.id()), true); - QMap::ConstIterator it; - - it = securitiesList.constFind(security.id()); - if (it == securitiesList.constEnd()) { - QString msg = "Unknown security '"; - msg += security.id() + "' during modifySecurity()"; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->modifySecurity(security); -} - -void MyMoneyDatabaseMgr::removeSecurity(const MyMoneySecurity& security) -{ - Q_D(MyMoneyDatabaseMgr); - QMap securitiesList = d->m_sql->fetchSecurities(QStringList(security.id())); - QMap::ConstIterator it; - - // FIXME: check referential integrity - - it = securitiesList.constFind(security.id()); - if (it == securitiesList.constEnd()) { - QString msg = "Unknown security '"; - msg += security.id() + "' during removeSecurity()"; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->removeSecurity(security); -} - -MyMoneySecurity MyMoneyDatabaseMgr::security(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap securitiesList = d->m_sql->fetchSecurities(QStringList(id)); - QMap::ConstIterator it = securitiesList.constFind(id); - if (it != securitiesList.constEnd()) { - return it.value(); - } - - return MyMoneySecurity(); -} - -QList MyMoneyDatabaseMgr::securityList() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->fetchSecurities().values(); -} - -void MyMoneyDatabaseMgr::addPrice(const MyMoneyPrice& price) -{ - Q_D(MyMoneyDatabaseMgr); - MyMoneyPriceEntries::ConstIterator it; - MyMoneyPriceList priceList = d->m_sql->fetchPrices(); - it = priceList[MyMoneySecurityPair(price.from(), price.to())].constFind(price.date()); - // do not replace, if the information did not change. - if (it != priceList[MyMoneySecurityPair(price.from(), price.to())].constEnd()) { - if ((*it).rate((*it).to()) == price.rate(price.to()) - && (*it).source() == price.source()) - return; - } - - d->m_sql->addPrice(price); -} - -void MyMoneyDatabaseMgr::removePrice(const MyMoneyPrice& price) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->removePrice(price); -} - -MyMoneyPrice MyMoneyDatabaseMgr::price(const QString& fromId, const QString& toId, const QDate& _date, bool exactDate) const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->fetchSinglePrice(fromId, toId, _date, exactDate); -} - -MyMoneyPriceList MyMoneyDatabaseMgr::priceList() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->fetchPrices(); -} - -void MyMoneyDatabaseMgr::addSchedule(MyMoneySchedule& sched) -{ - Q_D(MyMoneyDatabaseMgr); - // first perform all the checks - if (!sched.id().isEmpty()) - throw MYMONEYEXCEPTION("schedule already contains an id"); - - // The following will throw an exception when it fails - sched.validate(false); - - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - try { - startTransaction(); - sched = MyMoneySchedule(nextScheduleID(), sched); - - d->m_sql->addSchedule(sched); - commitTransaction(); - } catch (...) { - rollbackTransaction(); - throw; - } - } -} - -void MyMoneyDatabaseMgr::modifySchedule(const MyMoneySchedule& sched) -{ - Q_D(MyMoneyDatabaseMgr); - QMap scheduleList = d->m_sql->fetchSchedules(QStringList(sched.id())); - QMap::ConstIterator it; - - it = scheduleList.constFind(sched.id()); - if (it == scheduleList.constEnd()) { - QString msg = "Unknown schedule '" + sched.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->modifySchedule(sched); -} - -void MyMoneyDatabaseMgr::removeSchedule(const MyMoneySchedule& sched) -{ - Q_D(MyMoneyDatabaseMgr); - QMap scheduleList = d->m_sql->fetchSchedules(QStringList(sched.id())); - QMap::ConstIterator it; - - it = scheduleList.constFind(sched.id()); - if (it == scheduleList.constEnd()) { - QString msg = "Unknown schedule '" + sched.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - // FIXME: check referential integrity for loan accounts - - d->m_sql->removeSchedule(sched); -} - -MyMoneySchedule MyMoneyDatabaseMgr::schedule(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap scheduleList = d->m_sql->fetchSchedules(QStringList(id)); - QMap::ConstIterator pos; - - // locate the schedule and if present, return it's data - pos = scheduleList.constFind(id); - if (pos != scheduleList.constEnd()) - return (*pos); - - // throw an exception, if it does not exist - QString msg = "Unknown schedule id '" + id + '\''; - throw MYMONEYEXCEPTION(msg); -} - -QList MyMoneyDatabaseMgr::scheduleList(const QString& accountId, - eMyMoney::Schedule::Type type, - eMyMoney::Schedule::Occurrence occurrence, - eMyMoney::Schedule::PaymentType paymentType, - const QDate& startDate, - const QDate& endDate, - bool overdue) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap scheduleList; - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - scheduleList = d->m_sql->fetchSchedules(); - } - QMap::ConstIterator pos; - QList list; - - // qDebug("scheduleList()"); - - for (pos = scheduleList.constBegin(); pos != scheduleList.constEnd(); ++pos) { - // qDebug(" '%s'", (*pos).id().data()); - - if (type != eMyMoney::Schedule::Type::Any) { - if (type != (*pos).type()) { - continue; - } - } - - if (occurrence != eMyMoney::Schedule::Occurrence::Any) { - if (occurrence != (*pos).occurrence()) { - continue; - } - } - - if (paymentType != eMyMoney::Schedule::PaymentType::Any) { - if (paymentType != (*pos).paymentType()) { - continue; - } - } - - if (!accountId.isEmpty()) { - MyMoneyTransaction t = (*pos).transaction(); - QList::ConstIterator it; - QList splits; - splits = t.splits(); - for (it = splits.constBegin(); it != splits.constEnd(); ++it) { - if ((*it).accountId() == accountId) - break; - } - if (it == splits.constEnd()) { - continue; - } - } - - if (startDate.isValid() && endDate.isValid()) { - if ((*pos).paymentDates(startDate, endDate).count() == 0) { - continue; - } - } - - if (startDate.isValid() && !endDate.isValid()) { - if (!(*pos).nextPayment(startDate.addDays(-1)).isValid()) { - continue; - } - } - - if (!startDate.isValid() && endDate.isValid()) { - if ((*pos).startDate() > endDate) { - continue; - } - } - - if (overdue) { - if (!(*pos).isOverdue()) - continue; - /* - QDate nextPayment = (*pos).nextPayment((*pos).lastPayment()); - if(!nextPayment.isValid()) - continue; - if(nextPayment >= QDate::currentDate()) - continue; - */ - } - - // qDebug("Adding '%s'", (*pos).name().latin1()); - list << *pos; - } - return list; -} - -QList MyMoneyDatabaseMgr::scheduleListEx(int scheduleTypes, - int scheduleOcurrences, - int schedulePaymentTypes, - QDate startDate, - const QStringList& accounts) const -{ - Q_D(const MyMoneyDatabaseMgr); -// qDebug("scheduleListEx"); - QMap scheduleList = d->m_sql->fetchSchedules(); - QMap::ConstIterator pos; - QList list; - - if (!startDate.isValid()) - return list; - - for (pos = scheduleList.constBegin(); pos != scheduleList.constEnd(); ++pos) { - if (scheduleTypes && !(scheduleTypes & (int)(*pos).type())) - continue; - - if (scheduleOcurrences && !(scheduleOcurrences & (int)(*pos).occurrence())) - continue; - - if (schedulePaymentTypes && !(schedulePaymentTypes & (int)(*pos).paymentType())) - continue; - - if ((*pos).paymentDates(startDate, startDate).count() == 0) - continue; - - if ((*pos).isFinished()) - continue; - - if ((*pos).hasRecordedPayment(startDate)) - continue; - - if (accounts.count() > 0) { - if (accounts.contains((*pos).account().id())) - continue; - } - -// qDebug("\tAdding '%s'", (*pos).name().latin1()); - list << *pos; - } - - return list; -} - -void MyMoneyDatabaseMgr::addCurrency(const MyMoneySecurity& currency) -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - QMap currencyList = d->m_sql->fetchCurrencies(QStringList(currency.id())); - QMap::ConstIterator it; - - it = currencyList.constFind(currency.id()); - if (it != currencyList.constEnd()) { - throw MYMONEYEXCEPTION(i18n("Cannot add currency with existing id %1", currency.id())); - } - - d->m_sql->addCurrency(currency); - } -} - -void MyMoneyDatabaseMgr::modifyCurrency(const MyMoneySecurity& currency) -{ - Q_D(MyMoneyDatabaseMgr); - QMap currencyList = d->m_sql->fetchCurrencies(QStringList(currency.id())); - QMap::ConstIterator it; - - it = currencyList.constFind(currency.id()); - if (it == currencyList.constEnd()) { - throw MYMONEYEXCEPTION(i18n("Cannot modify currency with unknown id %1", currency.id())); - } - - d->m_sql->modifyCurrency(currency); -} - -void MyMoneyDatabaseMgr::removeCurrency(const MyMoneySecurity& currency) -{ - Q_D(MyMoneyDatabaseMgr); - QMap currencyList = d->m_sql->fetchCurrencies(QStringList(currency.id())); - QMap::ConstIterator it; - - // FIXME: check referential integrity - - it = currencyList.constFind(currency.id()); - if (it == currencyList.constEnd()) { - throw MYMONEYEXCEPTION(i18n("Cannot remove currency with unknown id %1", currency.id())); - } - - d->m_sql->removeCurrency(currency); -} - -MyMoneySecurity MyMoneyDatabaseMgr::currency(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - if (id.isEmpty()) { - - } - QMap currencyList = d->m_sql->fetchCurrencies(QStringList(id)); - QMap::ConstIterator it; - - it = currencyList.constFind(id); - if (it == currencyList.constEnd()) { - throw MYMONEYEXCEPTION(i18n("Cannot retrieve currency with unknown id '%1'", id)); - } - - return *it; -} - -QList MyMoneyDatabaseMgr::currencyList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchCurrencies().values(); - } else { - return QList (); - } -} - -QList MyMoneyDatabaseMgr::reportList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchReports().values(); - } else { - return QList (); - } -} - -void MyMoneyDatabaseMgr::addReport(MyMoneyReport& report) -{ - Q_D(MyMoneyDatabaseMgr); - if (!report.id().isEmpty()) - throw MYMONEYEXCEPTION("transaction already contains an id"); - - d->m_sql->addReport(MyMoneyReport(nextReportID(), report)); -} - -void MyMoneyDatabaseMgr::modifyReport(const MyMoneyReport& report) -{ - Q_D(MyMoneyDatabaseMgr); - QMap reportList = d->m_sql->fetchReports(QStringList(report.id())); - QMap::ConstIterator it; - - it = reportList.constFind(report.id()); - if (it == reportList.constEnd()) { - QString msg = "Unknown report '" + report.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->modifyReport(report); -} - -uint MyMoneyDatabaseMgr::countReports() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getRecCount("kmmReports"); -} - -MyMoneyReport MyMoneyDatabaseMgr::report(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->fetchReports(QStringList(id))[id]; -} - -void MyMoneyDatabaseMgr::removeReport(const MyMoneyReport& report) -{ - Q_D(MyMoneyDatabaseMgr); - QMap reportList = d->m_sql->fetchReports(QStringList(report.id())); - QMap::ConstIterator it; - - it = reportList.constFind(report.id()); - if (it == reportList.constEnd()) { - QString msg = "Unknown report '" + report.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - - d->m_sql->removeReport(report); -} - -QList MyMoneyDatabaseMgr::budgetList() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->fetchBudgets().values(); -} - -void MyMoneyDatabaseMgr::addBudget(MyMoneyBudget& budget) -{ - Q_D(MyMoneyDatabaseMgr); - MyMoneyBudget newBudget(nextBudgetID(), budget); - d->m_sql->addBudget(newBudget); -} - -MyMoneyBudget MyMoneyDatabaseMgr::budgetByName(const QString& budget) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap budgets = d->m_sql->fetchBudgets(); - QMap::ConstIterator it_p; - - for (it_p = budgets.constBegin(); it_p != budgets.constEnd(); ++it_p) { - if ((*it_p).name() == budget) { - return *it_p; - } - } - - throw MYMONEYEXCEPTION("Unknown budget '" + budget + '\''); -} - -void MyMoneyDatabaseMgr::modifyBudget(const MyMoneyBudget& budget) -{ - Q_D(MyMoneyDatabaseMgr); - //QMap::ConstIterator it; - - //it = m_budgetList.find(budget.id()); - //if(it == m_budgetList.end()) { - // QString msg = "Unknown budget '" + budget.id() + '\''; - // throw MYMONEYEXCEPTION(msg); - //} - //m_budgetList.modify(budget.id(), budget); - - startTransaction(); - if (d->m_sql->fetchBudgets(QStringList(budget.id()), true).empty()) { - QString msg = "Unknown budget '" + budget.id() + '\''; - throw MYMONEYEXCEPTION(msg); - } - d->m_sql->modifyBudget(budget); - commitTransaction(); -} - -uint MyMoneyDatabaseMgr::countBudgets() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getRecCount("kmmBudgetConfig"); -} - -MyMoneyBudget MyMoneyDatabaseMgr::budget(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->fetchBudgets(QStringList(id))[id]; -} - -void MyMoneyDatabaseMgr::removeBudget(const MyMoneyBudget& budget) -{ - Q_D(MyMoneyDatabaseMgr); -// QMap::ConstIterator it; -// -// it = m_budgetList.find(budget.id()); -// if(it == m_budgetList.end()) { -// QString msg = "Unknown budget '" + budget.id() + '\''; -// throw MYMONEYEXCEPTION(msg); -// } -// - d->m_sql->removeBudget(budget); -} - -void MyMoneyDatabaseMgr::clearCache() -{ - //m_balanceCache.clear(); -} - -class isReferencedHelper -{ -public: - isReferencedHelper(const QString& id) - : m_id(id) {} - - inline bool operator()(const MyMoneyObject& obj) const { - return obj.hasReferenceTo(m_id); - } - -private: - QString m_id; -}; - -bool MyMoneyDatabaseMgr::isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const -{ - Q_D(const MyMoneyDatabaseMgr); - Q_ASSERT(skipCheck.count() == (int)Reference::Count); - - const auto& id = obj.id(); - - // FIXME optimize the list of objects we have to checks - // with a bit of knowledge of the internal structure, we - // could optimize the number of objects we check for references - - // Scan all engine objects for a reference - if (!skipCheck.testBit((int)Reference::Transaction)) { - auto skipTransactions = false; - MyMoneyTransactionFilter f; - if (typeid(obj) == typeid(MyMoneyAccount)) { - f.addAccount(id); - } else if (typeid(obj) == typeid(MyMoneyCategory)) { - f.addCategory(id); - } else if (typeid(obj) == typeid(MyMoneyPayee)) { - f.addPayee(id); - } // if it's anything else, I guess we just read everything - //FIXME: correction, transactions can only have a reference to an account or payee, - // so, read nothing. - else { - skipTransactions = true; - } - if (! skipTransactions) { - //QMap transactionList = m_sql->fetchTransactions(f); - //rc = (transactionList.end() != std::find_if(transactionList.begin(), transactionList.end(), isReferencedHelper(id))); - //if (rc != m_sql->isReferencedByTransaction(obj.id())) - // qDebug ("Transaction match inconsistency."); - if (d->m_sql->isReferencedByTransaction(id)) - return true; - } - } - - if (!skipCheck.testBit((int)Reference::Account)) { - QList accountList; - MyMoneyFile::instance()->accountList(accountList); - foreach (const auto it, accountList) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Institution)) { - QList institutionList; - MyMoneyFile::instance()->institutionList(institutionList); - foreach (const auto it, institutionList) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Payee)) { - foreach (const auto it, MyMoneyFile::instance()->payeeList()) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Tag)) { - foreach (const auto it, MyMoneyFile::instance()->tagList()) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Report)) { - foreach (const auto it, d->m_sql->fetchReports()) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Budget)) { - foreach (const auto it, d->m_sql->fetchBudgets()) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Schedule)) { - foreach (const auto it, d->m_sql->fetchSchedules()) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Security)) { - foreach (const auto it, MyMoneyFile::instance()->securityList()) - if (it.hasReferenceTo(id)) - return true; - } - if (!skipCheck.testBit((int)Reference::Currency)) { - const auto currencyList = d->m_sql->fetchCurrencies().values(); - // above line cannot go directly here because m_sql->fetchCurrencies() will return temporary object which will get destructed before .values() - foreach (const auto it, currencyList) - if (it.hasReferenceTo(id)) - return true; - } - // within the pricelist we don't have to scan each entry. Checking the QPair - // members of the MyMoneySecurityPair is enough as they are identical to the - // two security ids - if (!skipCheck.testBit((int)Reference::Price)) { - const auto priceList = d->m_sql->fetchPrices(); - for (auto it_pr = priceList.begin(); it_pr != priceList.end(); ++it_pr) { - if ((it_pr.key().first == id) || (it_pr.key().second == id)) - return true; - } - } - return false; -} - -void MyMoneyDatabaseMgr::close() -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - d->m_sql->close(true); - d->m_sql = 0; - } -} - -void MyMoneyDatabaseMgr::startTransaction() -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - d->m_sql->startCommitUnit("databasetransaction"); - } -} - -bool MyMoneyDatabaseMgr::commitTransaction() -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->endCommitUnit("databasetransaction"); - } - return false; -} - -void MyMoneyDatabaseMgr::rollbackTransaction() -{ - Q_D(MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - d->m_sql->cancelCommitUnit("databasetransaction"); - } -} - -void MyMoneyDatabaseMgr::setCreationDate(const QDate& val) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_creationDate = val; -} - -QExplicitlySharedDataPointer MyMoneyDatabaseMgr::connectToDatabase(const QUrl &url) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql = new MyMoneyStorageSql(this, url); - return d->m_sql; -} - -void MyMoneyDatabaseMgr::fillStorage() -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->fillStorage(); -} - -void MyMoneyDatabaseMgr::setLastModificationDate(const QDate& val) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_lastModificationDate = val; -} - -bool MyMoneyDatabaseMgr::isDuplicateTransaction(const QString& /*id*/) const -{ - //FIXME: figure out the real id from the key and check the DB. -//return m_transactionKeys.contains(id); - return false; -} - -void MyMoneyDatabaseMgr::loadAccounts(const QMap& /*map*/) -{ -// m_accountList = map; -//FIXME: update the database. -// startTransaction -// DELETE FROM kmmAccounts -// for each account in the map -// m_sql->addAccount(...) -// commitTransaction -// on error, rollbackTransaction -} - -void MyMoneyDatabaseMgr::loadTransactions(const QMap& /*map*/) -{ -// m_transactionList = map; -//FIXME: update the database. - -// // now fill the key map -// QMap keys; -// QMap::ConstIterator it_t; -// for(it_t = map.begin(); it_t != map.end(); ++it_t) { -// keys[(*it_t).id()] = it_t.key(); -// } -// m_transactionKeys = keys; -} - -void MyMoneyDatabaseMgr::loadInstitutions(const QMap& /*map*/) -{ -// m_institutionList = map; -//FIXME: update the database. - -// // now fill the key map -// QMap keys; -// QMap::ConstIterator it_t; -// for(it_t = map.begin(); it_t != map.end(); ++it_t) { -// keys[(*it_t).id()] = it_t.key(); -// } -// m_transactionKeys = keys; -} - -void MyMoneyDatabaseMgr::loadPayees(const QMap& /*map*/) -{ -// m_payeeList = map; -} - -void MyMoneyDatabaseMgr::loadTags(const QMap& /*map*/) -{ -// m_tagList = map; -} - -void MyMoneyDatabaseMgr::loadSchedules(const QMap& /*map*/) -{ -// m_scheduleList = map; -} - -void MyMoneyDatabaseMgr::loadSecurities(const QMap& /*map*/) -{ -// m_securitiesList = map; -} - -void MyMoneyDatabaseMgr::loadCurrencies(const QMap& /*map*/) -{ -// m_currencyList = map; -//FIXME: update the database. -// startTransaction -// DELETE FROM kmmBudgetConfig -// for each budget in the map -// m_sql->addBudget(...) -// commitTransaction -// on error, rollbackTransaction -} - -void MyMoneyDatabaseMgr::loadReports(const QMap& /*reports*/) -{ -// m_reportList = reports; -//FIXME: update the database. -// startTransaction -// DELETE FROM kmmBudgetConfig -// for each budget in the map -// m_sql->addBudget(...) -// commitTransaction -// on error, rollbackTransaction -} - -void MyMoneyDatabaseMgr::loadBudgets(const QMap& /*budgets*/) -{ -// m_budgetList = budgets; -//FIXME: update the database. -// startTransaction -// DELETE FROM kmmBudgetConfig -// for each budget in the map -// m_sql->addBudget(...) -// commitTransaction -// on error, rollbackTransaction -} - -void MyMoneyDatabaseMgr::loadPrices(const MyMoneyPriceList& list) -{ - Q_UNUSED(list); -} - -void MyMoneyDatabaseMgr::loadOnlineJobs(const QMap< QString, onlineJob >& onlineJobs) -{ - Q_UNUSED(onlineJobs); -} - -ulong MyMoneyDatabaseMgr::accountId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextAccountId() - 1; -} - -ulong MyMoneyDatabaseMgr::transactionId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextTransactionId() - 1; -} - -ulong MyMoneyDatabaseMgr::payeeId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextPayeeId() - 1; -} - -ulong MyMoneyDatabaseMgr::tagId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextTagId() - 1; -} - -ulong MyMoneyDatabaseMgr::institutionId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextInstitutionId() - 1; -} - -ulong MyMoneyDatabaseMgr::scheduleId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextScheduleId() - 1; -} - -ulong MyMoneyDatabaseMgr::securityId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextSecurityId() - 1; -} - -ulong MyMoneyDatabaseMgr::reportId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextReportId() - 1; -} - -ulong MyMoneyDatabaseMgr::budgetId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextBudgetId() - 1; -} - -ulong MyMoneyDatabaseMgr::onlineJobId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextOnlineJobId() - 1; -} - -ulong MyMoneyDatabaseMgr::payeeIdentifierId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextPayeeIdentifierId() - 1; -} - -void MyMoneyDatabaseMgr::loadAccountId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadAccountId(id); -} - -void MyMoneyDatabaseMgr::loadTransactionId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadTransactionId(id); -} - -void MyMoneyDatabaseMgr::loadPayeeId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadPayeeId(id); -} - -void MyMoneyDatabaseMgr::loadTagId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadTagId(id); -} - -void MyMoneyDatabaseMgr::loadInstitutionId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadInstitutionId(id); -} - -void MyMoneyDatabaseMgr::loadScheduleId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadScheduleId(id); -} - -void MyMoneyDatabaseMgr::loadSecurityId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadSecurityId(id); -} - -void MyMoneyDatabaseMgr::loadReportId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadReportId(id); -} - -void MyMoneyDatabaseMgr::loadBudgetId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadBudgetId(id); -} - -void MyMoneyDatabaseMgr::loadOnlineJobId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadOnlineJobId(id); -} - -void MyMoneyDatabaseMgr::loadPayeeIdentifierId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadPayeeIdentifierId(id); -} - -void MyMoneyDatabaseMgr::loadCostCenterId(ulong id) -{ - Q_D(MyMoneyDatabaseMgr); - d->m_sql->loadAccountId(id); -} - -void MyMoneyDatabaseMgr::rebuildAccountBalances() -{ - Q_D(MyMoneyDatabaseMgr); - startTransaction(); - QMap accountMap = d->m_sql->fetchAccounts(QStringList(), true); - - QMap balanceMap = d->m_sql->fetchBalance(accountMap.keys(), QDate()); - - for (QMap::const_iterator it_b = balanceMap.constBegin(); - it_b != balanceMap.constEnd(); ++it_b) { - accountMap[it_b.key()].setBalance(it_b.value()); - } - - QList aList; - for (QMap::const_iterator it_a = accountMap.constBegin(); - it_a != accountMap.constEnd(); ++it_a) { - aList << it_a.value(); - } - d->m_sql->modifyAccountList(aList); - - commitTransaction(); -} - -QList< MyMoneyCostCenter > MyMoneyDatabaseMgr::costCenterList() const -{ - Q_D(const MyMoneyDatabaseMgr); - if (d->m_sql) { - if (! d->m_sql->isOpen())((QSqlDatabase*)(d->m_sql.data()))->open(); - return d->m_sql->fetchCostCenters().values(); - } - return QList (); -} - -void MyMoneyDatabaseMgr::loadCostCenters(const QMap< QString, MyMoneyCostCenter >& costCenters) -{ - Q_UNUSED(costCenters); -} - -ulong MyMoneyDatabaseMgr::costCenterId() const -{ - Q_D(const MyMoneyDatabaseMgr); - return d->m_sql->getNextCostCenterId() - 1; -} - -MyMoneyCostCenter MyMoneyDatabaseMgr::costCenter(const QString& id) const -{ - Q_D(const MyMoneyDatabaseMgr); - QMap::ConstIterator it; - QMap costCenterList = d->m_sql->fetchCostCenters(QStringList(id)); - it = costCenterList.constFind(id); - if (it == costCenterList.constEnd()) - throw MYMONEYEXCEPTION("Unknown costcenter '" + id + '\''); - - return *it; -} diff --git a/kmymoney/mymoney/storage/mymoneydatabasemgr_p.h b/kmymoney/mymoney/storage/mymoneydatabasemgr_p.h deleted file mode 100644 --- a/kmymoney/mymoney/storage/mymoneydatabasemgr_p.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - mymoneydatabasemgr.cpp - ------------------- - begin : June 5 2007 - copyright : (C) 2007 by Fernando Vilas - email : Fernando Vilas - 2017 by Ł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. * - * * - ***************************************************************************/ - -#ifndef MYMONEYDATABASEMGR_P_H -#define MYMONEYDATABASEMGR_P_H - -#include "mymoneydatabasemgr.h" - -#include -#include - -// ---------------------------------------------------------------------------- -// QT Includes - -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes - -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -#include "mymoneytransactionfilter.h" -#include "mymoneycategory.h" -#include "mymoneyfile.h" -#include "mymoneyinstitution.h" -#include "mymoneyaccount.h" -#include "mymoneysecurity.h" -#include "mymoneytag.h" -#include "mymoneybudget.h" -#include "mymoneyschedule.h" -#include "mymoneymoney.h" -#include "mymoneysplit.h" -#include "mymoneypayee.h" -#include "mymoneyreport.h" -#include "mymoneycostcenter.h" -#include "mymoneymap.h" -#include "mymoneystoragesql.h" -#include "mymoneyenums.h" -#include "storageenums.h" - -using namespace eStorage; - -class MyMoneyDatabaseMgrPrivate -{ - Q_DISABLE_COPY(MyMoneyDatabaseMgrPrivate) - Q_DECLARE_PUBLIC(MyMoneyDatabaseMgr) - -public: - explicit MyMoneyDatabaseMgrPrivate(MyMoneyDatabaseMgr* qq) : - q_ptr(qq), - m_creationDate(QDate::currentDate()), - m_currentFixVersion(0), - m_fileFixVersion(0), - m_lastModificationDate(QDate::currentDate()), - m_sql(0) - { - } - - ~MyMoneyDatabaseMgrPrivate() - { - } - - void removeReferences(const QString& id) - { - QMap::const_iterator it_r; - QMap::const_iterator it_b; - - // remove from reports - QMap reportList = m_sql->fetchReports(); - for (it_r = reportList.constBegin(); it_r != reportList.constEnd(); ++it_r) { - MyMoneyReport r = *it_r; - r.removeReference(id); - // reportList.modify(r.id(), r); - } - - // remove from budgets - QMap budgetList = m_sql->fetchBudgets(); - for (it_b = budgetList.constBegin(); it_b != budgetList.constEnd(); ++it_b) { - MyMoneyBudget b = *it_b; - b.removeReference(id); - // budgetList.modify(b.id(), b); - } - } - - MyMoneyDatabaseMgr *q_ptr; - /** - * This member variable keeps the creation date of this MyMoneyDatabaseMgr - * object. It is set during the constructor and can only be modified using - * the stream read operator. - */ - QDate m_creationDate; - - /** - * This member variable contains the current fix level of application - * data files. (see kmymoneyview.cpp) - */ - uint m_currentFixVersion; - - /** - * This member variable contains the current fix level of the - * presently open data file. (see kmymoneyview.cpp) - */ - uint m_fileFixVersion; - - /** - * This member variable keeps the date of the last modification of - * the MyMoneyDatabaseMgr object. - */ - QDate m_lastModificationDate; - - /** - * This contains the interface with SQL reader for database access - */ - QExplicitlySharedDataPointer m_sql; - - /** - * This member variable keeps the User information. - * @see setUser() - */ - MyMoneyPayee m_user; -}; -#endif diff --git a/kmymoney/mymoney/storage/mymoneydbdef.cpp b/kmymoney/mymoney/storage/mymoneydbdef.cpp --- a/kmymoney/mymoney/storage/mymoneydbdef.cpp +++ b/kmymoney/mymoney/storage/mymoneydbdef.cpp @@ -31,7 +31,7 @@ #include "mymoneyfile.h" #include "mymoneyaccount.h" #include "mymoneyexception.h" -#include "imymoneystorage.h" +#include "mymoneystoragemgr.h" #include diff --git a/kmymoney/mymoney/storage/mymoneystorageanon.h b/kmymoney/mymoney/storage/mymoneystorageanon.h --- a/kmymoney/mymoney/storage/mymoneystorageanon.h +++ b/kmymoney/mymoney/storage/mymoneystorageanon.h @@ -33,18 +33,7 @@ #include "mymoneystoragexml.h" #include "mymoneymoney.h" -//class QDomElement; - -//class MyMoneyAccount; -//class MyMoneyInstitution; -//class MyMoneySecurity; -//class MyMoneyBudget; -//class MyMoneySchedule; -//class MyMoneyPayee; -//class MyMoneyTag; -//class MyMoneyTransaction; class MyMoneyKeyValueContainer; -//class onlineJob; /** * @author Kevin Tambascio (ktambascio@users.sourceforge.net) @@ -96,7 +85,7 @@ void writeReport(QDomElement& reports, const MyMoneyReport& r); - void readFile(QIODevice* s, IMyMoneySerialize* storage); + void readFile(QIODevice* s, MyMoneyStorageMgr* storage); void writeSecurity(QDomElement& securityElement, const MyMoneySecurity& security); diff --git a/kmymoney/mymoney/storage/mymoneystorageanon.cpp b/kmymoney/mymoney/storage/mymoneystorageanon.cpp --- a/kmymoney/mymoney/storage/mymoneystorageanon.cpp +++ b/kmymoney/mymoney/storage/mymoneystorageanon.cpp @@ -39,7 +39,7 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "imymoneyserialize.h" +#include "mymoneystoragemgr.h" #include "mymoneyreport.h" #include "mymoneyschedule.h" #include "mymoneysplit.h" @@ -74,7 +74,7 @@ { } -void MyMoneyStorageANON::readFile(QIODevice* , IMyMoneySerialize*) +void MyMoneyStorageANON::readFile(QIODevice* , MyMoneyStorageMgr*) { throw MYMONEYEXCEPTION("Cannot read a file through MyMoneyStorageANON!!"); } diff --git a/kmymoney/mymoney/storage/mymoneystoragedump.h b/kmymoney/mymoney/storage/mymoneystoragedump.h --- a/kmymoney/mymoney/storage/mymoneystoragedump.h +++ b/kmymoney/mymoney/storage/mymoneystoragedump.h @@ -35,8 +35,8 @@ * @author Thomas Baumgart */ -class IMyMoneySerialize; -class IMyMoneyStorage; +class MyMoneyStorageMgr; +class MyMoneyStorageMgr; class MyMoneyTransaction; class QTextStream; @@ -48,11 +48,11 @@ MyMoneyStorageDump(); ~MyMoneyStorageDump(); - void readStream(QDataStream& s, IMyMoneySerialize* storage); - void writeStream(QDataStream& s, IMyMoneySerialize* storage); + void readStream(QDataStream& s, MyMoneyStorageMgr* storage); + void writeStream(QDataStream& s, MyMoneyStorageMgr* storage); private: - void dumpTransaction(QTextStream& s, IMyMoneyStorage* storage, const MyMoneyTransaction& it_t); + void dumpTransaction(QTextStream& s, MyMoneyStorageMgr* storage, const MyMoneyTransaction& it_t); void dumpKVP(const QString& headline, QTextStream& s, const MyMoneyKeyValueContainer &kvp, int indent = 0); const QString reconcileToString(eMyMoney::Split::State flag) const; }; diff --git a/kmymoney/mymoney/storage/mymoneystoragedump.cpp b/kmymoney/mymoney/storage/mymoneystoragedump.cpp --- a/kmymoney/mymoney/storage/mymoneystoragedump.cpp +++ b/kmymoney/mymoney/storage/mymoneystoragedump.cpp @@ -40,8 +40,8 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "imymoneyserialize.h" -#include "imymoneystorage.h" +#include "mymoneystoragemgr.h" +#include "mymoneystoragemgr_p.h" #include "mymoneyexception.h" #include "mymoneyinstitution.h" #include "mymoneyaccount.h" @@ -65,15 +65,15 @@ { } -void MyMoneyStorageDump::readStream(QDataStream& /* s */, IMyMoneySerialize* /* storage */) +void MyMoneyStorageDump::readStream(QDataStream& /* s */, MyMoneyStorageMgr* /* storage */) { qDebug("Reading not supported by MyMoneyStorageDump!!"); } -void MyMoneyStorageDump::writeStream(QDataStream& _s, IMyMoneySerialize* _storage) +void MyMoneyStorageDump::writeStream(QDataStream& _s, MyMoneyStorageMgr* _storage) { QTextStream s(_s.device()); - IMyMoneyStorage* storage = dynamic_cast(_storage); + MyMoneyStorageMgr* storage = _storage; MyMoneyPayee user = storage->user(); s << "File-Info\n"; @@ -94,13 +94,13 @@ s << "-------------\n"; QList list_a; storage->accountList(list_a); - s << "accounts = " << list_a.count() << ", next id = " << _storage->accountId() << "\n"; + s << "accounts = " << list_a.count() << ", next id = " << _storage->d_func()->m_nextAccountID << "\n"; MyMoneyTransactionFilter filter; filter.setReportAllSplits(false); QList list_t; storage->transactionList(list_t, filter); QList::ConstIterator it_t; - s << "transactions = " << list_t.count() << ", next id = " << _storage->transactionId() << "\n"; + s << "transactions = " << list_t.count() << ", next id = " << _storage->d_func()->m_nextTransactionID << "\n"; QMap xferCount; foreach (const auto transaction, list_t) { auto accountCount = 0; @@ -118,11 +118,11 @@ s << " " << *it_cnt << " of them references " << it_cnt.key() << " accounts\n"; } - s << "payees = " << _storage->payeeList().count() << ", next id = " << _storage->payeeId() << "\n"; - s << "tags = " << _storage->tagList().count() << ", next id = " << _storage->tagId() << "\n"; - s << "institutions = " << _storage->institutionList().count() << ", next id = " << _storage->institutionId() << "\n"; + s << "payees = " << _storage->payeeList().count() << ", next id = " << _storage->d_func()->m_nextPayeeID << "\n"; + s << "tags = " << _storage->tagList().count() << ", next id = " << _storage->d_func()->m_nextTagID << "\n"; + s << "institutions = " << _storage->institutionList().count() << ", next id = " << _storage->d_func()->m_nextInstitutionID << "\n"; s << "schedules = " << _storage->scheduleList(QString(), eMyMoney::Schedule::Type::Any, eMyMoney::Schedule::Occurrence::Any, eMyMoney::Schedule::PaymentType::Any, - QDate(), QDate(), false).count() << ", next id = " << _storage->scheduleId() << "\n"; + QDate(), QDate(), false).count() << ", next id = " << _storage->d_func()->m_nextScheduleID << "\n"; s << "\n"; s << "Institutions\n"; @@ -399,7 +399,7 @@ } } -void MyMoneyStorageDump::dumpTransaction(QTextStream& s, IMyMoneyStorage* storage, const MyMoneyTransaction& it_t) +void MyMoneyStorageDump::dumpTransaction(QTextStream& s, MyMoneyStorageMgr* storage, const MyMoneyTransaction& it_t) { s << " ID = " << it_t.id() << "\n"; s << " Postdate = " << it_t.postDate().toString(Qt::ISODate) << "\n"; diff --git a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.h b/kmymoney/mymoney/storage/mymoneystoragemgr.h rename from kmymoney/mymoney/storage/mymoneyseqaccessmgr.h rename to kmymoney/mymoney/storage/mymoneystoragemgr.h --- a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.h +++ b/kmymoney/mymoney/storage/mymoneystoragemgr.h @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneyseqaccessmgr.h - description + mymoneystoragemgr.h - description ------------------- begin : Sun May 5 2002 copyright : (C) 2000-2002 by Michael Edwardes @@ -20,8 +20,8 @@ * * ***************************************************************************/ -#ifndef MYMONEYSEQACCESSMGR_H -#define MYMONEYSEQACCESSMGR_H +#ifndef MYMONEYSTORAGEMGR_H +#define MYMONEYSTORAGEMGR_H // ---------------------------------------------------------------------------- // QT Includes @@ -29,71 +29,86 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "imymoneystorage.h" -#include "imymoneyserialize.h" #include "mymoneykeyvaluecontainer.h" +class QUrl; +class QString; +class QStringList; +class QDate; +class QBitArray; + +class MyMoneyObject; +class MyMoneyMoney; +class MyMoneyInstitution; +class MyMoneyAccount; +class MyMoneySecurity; +class MyMoneyPayee; +class MyMoneyTag; +class MyMoneyPrice; +class MyMoneyReport; +class MyMoneySchedule; +class MyMoneyBudget; +class MyMoneySplit; +class MyMoneyTransaction; +class MyMoneyTransactionFilter; +class MyMoneyCostCenter; +class onlineJob; +class MyMoneyStorageSql; + +template class QMap; +template class QList; +template struct QPair; + +typedef QPair MyMoneySecurityPair; +typedef QMap MyMoneyPriceEntries; +typedef QMap MyMoneyPriceList; + +namespace eMyMoney { namespace Schedule { enum class Type; } } +namespace eMyMoney { namespace Schedule { enum class Occurrence; } } +namespace eMyMoney { namespace Schedule { enum class PaymentType; } } + /** * @author Thomas Baumgart * @author Łukasz Wojniłowicz */ /** - * The MyMoneySeqAccessMgr class represents the storage engine for sequential + * The MyMoneyStorageMgr class represents the storage engine for sequential * files. The actual file type and it's internal storage format (e.g. binary - * or XML) is not important and handled through the IMyMoneySerialize() interface. + * or XML) is not important. * - * The MyMoneySeqAccessMgr must be loaded by an application using the - * IMyMoneySerialize() interface and can then be accessed through the - * IMyMoneyStorage() interface. All data is loaded into memory, modified + * The MyMoneyStorageMgr must be loaded by an application using loadAccounts() + * method and etc. and can then be accessed through the + * account() method and etc.. All data is loaded into memory, modified * and kept there. It is the subject of an outside object to store the - * modified data in a persistant storage area using the IMyMoneySerialize() - * interface. As indication, if data has been changed, the retrun value + * modified data in a persistant storage area using the accountList() method and etc. + * As indication, if data has been changed, the retrun value * of the method dirty() can be used. */ -class MyMoneySeqAccessMgrPrivate; -class MyMoneySeqAccessMgr : public IMyMoneyStorage, public IMyMoneySerialize, - public MyMoneyKeyValueContainer +class MyMoneyStorageMgrPrivate; +class MyMoneyStorageMgr : public MyMoneyKeyValueContainer { - Q_DISABLE_COPY(MyMoneySeqAccessMgr) + Q_DISABLE_COPY(MyMoneyStorageMgr) KMM_MYMONEY_UNIT_TESTABLE + friend class MyMoneyStorageDump; public: - - MyMoneySeqAccessMgr(); - ~MyMoneySeqAccessMgr(); + MyMoneyStorageMgr(); + ~MyMoneyStorageMgr(); // general get functions - MyMoneyPayee user() const override; - QDate creationDate() const override; - QDate lastModificationDate() const override; - uint currentFixVersion() const override; - uint fileFixVersion() const override; + MyMoneyPayee user() const; + QDate creationDate() const; + QDate lastModificationDate() const; + uint currentFixVersion() const; + uint fileFixVersion() const; // general set functions - void setUser(const MyMoneyPayee& user) override; - void setCreationDate(const QDate& val) override; - void setLastModificationDate(const QDate& val) override; - void setFileFixVersion(uint v) override; - - /** - * This method is used to get a SQL reader for subsequent database access - */ - QExplicitlySharedDataPointer connectToDatabase(const QUrl &url) override; - /** - * This method is used when a database file is open, and the data is to - * be saved in a different file or format. It will ensure that all data - * from the database is available in memory to enable it to be written. - */ - void fillStorage() override; - - /** - * This method is used to duplicate the MyMoneySeqAccessMgr object and return - * a pointer to the newly created copy. The caller of this method is the - * new owner of the object and must destroy it. - */ -// MyMoneySeqAccessMgr const * duplicate() override; + void setUser(const MyMoneyPayee& user); + void setCreationDate(const QDate& val); + void setLastModificationDate(const QDate& val); + void setFileFixVersion(uint v); /** * Returns the account addressed by it's id. @@ -102,7 +117,7 @@ * @return reference to MyMoneyAccount object. An exception is thrown * if the id is unknown */ - MyMoneyAccount account(const QString& id) const override; + MyMoneyAccount account(const QString& id) const; /** * This method is used to check whether a given @@ -111,7 +126,7 @@ * @param id account id * @return true if account-id is one of the standards, false otherwise */ - bool isStandardAccount(const QString& id) const override; + bool isStandardAccount(const QString& id) const; /** * This method is used to set the name for the specified standard account @@ -130,7 +145,7 @@ * @param name QString reference to the name to be set * */ - void setAccountName(const QString& id, const QString& name) override; + void setAccountName(const QString& id, const QString& name); /** * This method is used to create a new account @@ -139,7 +154,7 @@ * * @param account MyMoneyAccount filled with data */ - void addAccount(MyMoneyAccount& account) override; + void addAccount(MyMoneyAccount& account); /** * This method is used to create a new payee @@ -148,12 +163,12 @@ * * @param payee MyMoneyPayee reference to payee information */ - void addPayee(MyMoneyPayee& payee) override; + void addPayee(MyMoneyPayee& payee); /** * Create now onlineJob */ - void addOnlineJob(onlineJob& job) override; + void addOnlineJob(onlineJob& job); /** * This method is used to retrieve information about a payee @@ -163,7 +178,7 @@ * * @return MyMoneyPayee object of payee */ - MyMoneyPayee payee(const QString& id) const override; + MyMoneyPayee payee(const QString& id) const; /** * This method is used to retrieve the id to a corresponding @@ -174,7 +189,7 @@ * * @return MyMoneyPayee reference to object of payee */ - MyMoneyPayee payeeByName(const QString& payee) const override; + MyMoneyPayee payeeByName(const QString& payee) const; /** * This method is used to modify an existing payee @@ -183,7 +198,7 @@ * * @param payee MyMoneyPayee reference to payee information */ - void modifyPayee(const MyMoneyPayee& payee) override; + void modifyPayee(const MyMoneyPayee& payee); /** * This method is used to remove an existing payee @@ -192,7 +207,7 @@ * * @param payee MyMoneyPayee reference to payee information */ - void removePayee(const MyMoneyPayee& payee) override; + void removePayee(const MyMoneyPayee& payee); /** * This method returns a list of the payees @@ -200,7 +215,7 @@ * * @return QList containing the payee information */ - QList payeeList() const override; + QList payeeList() const; /** * This method is used to create a new tag @@ -209,7 +224,7 @@ * * @param tag MyMoneyTag reference to tag information */ - void addTag(MyMoneyTag& tag) override; + void addTag(MyMoneyTag& tag); /** * This method is used to retrieve information about a tag @@ -219,7 +234,7 @@ * * @return MyMoneyTag object of tag */ - MyMoneyTag tag(const QString& id) const override; + MyMoneyTag tag(const QString& id) const; /** * This method is used to retrieve the id to a corresponding @@ -230,7 +245,7 @@ * * @return MyMoneyTag reference to object of tag */ - MyMoneyTag tagByName(const QString& tag) const override; + MyMoneyTag tagByName(const QString& tag) const; /** * This method is used to modify an existing tag @@ -239,7 +254,7 @@ * * @param tag MyMoneyTag reference to tag information */ - void modifyTag(const MyMoneyTag& tag) override; + void modifyTag(const MyMoneyTag& tag); /** * This method is used to remove an existing tag @@ -248,7 +263,7 @@ * * @param tag MyMoneyTag reference to tag information */ - void removeTag(const MyMoneyTag& tag) override; + void removeTag(const MyMoneyTag& tag); /** * This method returns a list of the tags @@ -256,7 +271,7 @@ * * @return QList containing the tag information */ - QList tagList() const override; + QList tagList() const; /** * This method is used to add one account as sub-ordinate to another @@ -267,7 +282,7 @@ * @param account the account to be added */ - void addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) override; + void addAccount(MyMoneyAccount& parent, MyMoneyAccount& account); /** * Adds an institution to the storage. A @@ -278,7 +293,7 @@ * @param institution The complete institution information in a * MyMoneyInstitution object */ - void addInstitution(MyMoneyInstitution& institution) override; + void addInstitution(MyMoneyInstitution& institution); /** * Adds a transaction to the file-global transaction pool. A respective @@ -291,7 +306,7 @@ * referenced in the splits are not updated. This is used for * bulk loading a lot of transactions but not during normal operation */ - void addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate = false) override; + void addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate = false); /** * Modifies an already existing account in the file global account pool. @@ -305,7 +320,7 @@ * procedure to be able to reload accounts. The default * setting of this parameter is @p false. */ - void modifyAccount(const MyMoneyAccount& account, bool skipCheck = false) override; + void modifyAccount(const MyMoneyAccount& account, bool skipCheck = false); /** * Modifies an already existing institution in the file global @@ -315,7 +330,7 @@ * * @param institution The complete new institution information */ - void modifyInstitution(const MyMoneyInstitution& institution) override; + void modifyInstitution(const MyMoneyInstitution& institution); /** * This method is used to update a specific transaction in the @@ -325,10 +340,10 @@ * * @param transaction reference to transaction to be changed */ - void modifyTransaction(const MyMoneyTransaction& transaction) override; + void modifyTransaction(const MyMoneyTransaction& transaction); /** @todo implement */ - void modifyOnlineJob(const onlineJob& job) override; + void modifyOnlineJob(const onlineJob& job); /** * This method re-parents an existing account @@ -338,7 +353,7 @@ * @param account MyMoneyAccount reference to account to be re-parented * @param parent MyMoneyAccount reference to new parent account */ - void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent) override; + void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent); /** * This method is used to remove a transaction from the transaction @@ -346,7 +361,7 @@ * * @param transaction const reference to transaction to be deleted */ - void removeTransaction(const MyMoneyTransaction& transaction) override; + void removeTransaction(const MyMoneyTransaction& transaction); /** * Deletes an existing account from the file global account pool @@ -357,7 +372,7 @@ * * @param account reference to the account to be deleted. */ - void removeAccount(const MyMoneyAccount& account) override; + void removeAccount(const MyMoneyAccount& account); /** * Deletes an existing institution from the file global institution pool @@ -366,13 +381,13 @@ * * @param institution institution to be deleted. */ - void removeInstitution(const MyMoneyInstitution& institution) override; + void removeInstitution(const MyMoneyInstitution& institution); - onlineJob getOnlineJob(const QString& id) const override; + onlineJob getOnlineJob(const QString& id) const; /** @todo implement */ - ulong onlineJobId() const override; + ulong onlineJobId() const; - void removeOnlineJob(const onlineJob &) override; + void removeOnlineJob(const onlineJob &); /** * This method is used to extract a transaction from the file global @@ -382,7 +397,7 @@ * @param id id of transaction as QString. * @return reference to the requested transaction */ - MyMoneyTransaction transaction(const QString& id) const override; + MyMoneyTransaction transaction(const QString& id) const; /** * This method is used to extract a transaction from the file global @@ -392,7 +407,7 @@ * @param idx number of transaction in this account * @return reference to MyMoneyTransaction object */ - MyMoneyTransaction transaction(const QString& account, const int idx) const override; + MyMoneyTransaction transaction(const QString& account, const int idx) const; /** * This method is used to determince, if the account with the @@ -401,7 +416,7 @@ * @param id id of the account to be checked for * @return true if account is referenced, false otherwise */ - bool hasActiveSplits(const QString& id) const override; + bool hasActiveSplits(const QString& id) const; /** * This method is used to return the actual balance of an account @@ -414,7 +429,7 @@ * @param date return balance for specific date * @return balance of the account as MyMoneyMoney object */ - MyMoneyMoney balance(const QString& id, const QDate& date) const override; + MyMoneyMoney balance(const QString& id, const QDate& date) const; /** * This method is used to return the actual balance of an account @@ -427,7 +442,7 @@ * @param date return balance for specific date * @return balance of the account as MyMoneyMoney object */ - MyMoneyMoney totalBalance(const QString& id, const QDate& date) const override; + MyMoneyMoney totalBalance(const QString& id, const QDate& date) const; /** * Returns the institution of a given ID @@ -436,7 +451,7 @@ * @return MyMoneyInstitution object filled with data. If the institution * could not be found, an exception will be thrown */ - MyMoneyInstitution institution(const QString& id) const override; + MyMoneyInstitution institution(const QString& id) const; /** * This method returns an indicator if the storage object has been @@ -444,7 +459,7 @@ * * @return true if changed, false if not */ - bool dirty() const override; + bool dirty() const; /** * This method can be used by an external object to force the @@ -452,7 +467,7 @@ * to an external destination failed but the previous storage * to a local disk was ok. */ - void setDirty() override; + void setDirty(); /** * This method returns a list of the institutions @@ -460,7 +475,7 @@ * * @return QMap containing the institution information */ - QList institutionList() const override; + QList institutionList() const; /** * This method returns a list of accounts inside the storage object. @@ -469,7 +484,7 @@ * * @note The standard accounts will not be returned */ - void accountList(QList& list) const override; + void accountList(QList& list) const; /** * This method is used to pull a list of transactions from the file @@ -487,7 +502,7 @@ * * @return set of transactions in form of a QList */ - void transactionList(QList& list, MyMoneyTransactionFilter& filter) const override; + void transactionList(QList& list, MyMoneyTransactionFilter& filter) const; /** * This method is used to pull a list of transactions from the file @@ -505,33 +520,33 @@ * * @return set of transactions in form of a QList > */ - void transactionList(QList< QPair >& list, MyMoneyTransactionFilter& filter) const override; + void transactionList(QList< QPair >& list, MyMoneyTransactionFilter& filter) const; /** * Compatibility interface for the previous method. */ - QList transactionList(MyMoneyTransactionFilter& filter) const override; + QList transactionList(MyMoneyTransactionFilter& filter) const; /** * @brief Return all onlineJobs */ - QList onlineJobList() const override; + QList onlineJobList() const; /** * @brief Return all cost center objects */ - QList< MyMoneyCostCenter > costCenterList() const override; + QList< MyMoneyCostCenter > costCenterList() const; /** * @brief Return cost center object by id */ - MyMoneyCostCenter costCenter(const QString& id) const override; + MyMoneyCostCenter costCenter(const QString& id) const; /** * This method returns whether a given transaction is already in memory, to avoid * reloading it from the database */ - bool isDuplicateTransaction(const QString& id) const override; + bool isDuplicateTransaction(const QString& id) const; /** * This method returns the number of transactions currently known to file @@ -544,9 +559,9 @@ * * @return number of transactions in journal/account */ - uint transactionCount(const QString& account) const override; + uint transactionCount(const QString& account) const; - QMap transactionCountMap() const override; + QMap transactionCountMap() const; /** * This method returns the number of institutions currently known to file @@ -554,7 +569,7 @@ * * @return number of institutions known to file */ - uint institutionCount() const override; + uint institutionCount() const; /** * This method returns the number of accounts currently known to file @@ -562,81 +577,49 @@ * * @return number of accounts currently known inside a MyMoneyFile object */ - uint accountCount() const override; + uint accountCount() const; /** * This method is used to return the standard liability account * @return MyMoneyAccount liability account(group) */ - MyMoneyAccount liability() const override; + MyMoneyAccount liability() const; /** * This method is used to return the standard asset account * @return MyMoneyAccount asset account(group) */ - MyMoneyAccount asset() const override; + MyMoneyAccount asset() const; /** * This method is used to return the standard expense account * @return MyMoneyAccount expense account(group) */ - MyMoneyAccount expense() const override; + MyMoneyAccount expense() const; /** * This method is used to return the standard income account * @return MyMoneyAccount income account(group) */ - MyMoneyAccount income() const override; + MyMoneyAccount income() const; /** * This method is used to return the standard equity account * @return MyMoneyAccount equity account(group) */ - MyMoneyAccount equity() const override; - - void loadAccounts(const QMap& acc) override; - void loadTransactions(const QMap& map) override; - void loadInstitutions(const QMap& map) override; - void loadPayees(const QMap& map) override; - void loadTags(const QMap& map) override; - void loadSchedules(const QMap& map) override; - void loadSecurities(const QMap& map) override; - void loadCurrencies(const QMap& map) override; - void loadPrices(const MyMoneyPriceList& list) override; - void loadOnlineJobs(const QMap& onlineJobs) override; - void loadCostCenters(const QMap& costCenters) override; - - void loadAccountId(ulong id) override; - void loadTransactionId(ulong id) override; - void loadPayeeId(ulong id) override; - void loadTagId(ulong id) override; - void loadInstitutionId(ulong id) override; - void loadScheduleId(ulong id) override; - void loadSecurityId(ulong id) override; - void loadReportId(ulong id) override; - void loadBudgetId(ulong id) override; - void loadOnlineJobId(ulong id) override; - void loadCostCenterId(ulong id) override; - - ulong accountId() const override; - ulong transactionId() const override; - ulong payeeId() const override; - ulong tagId() const override; - ulong institutionId() const override; - ulong scheduleId() const override; - ulong securityId() const override; - ulong reportId() const override; - ulong budgetId() const override; - ulong costCenterId() const override; - - /** - * This method is used to extract a value from - * KeyValueContainer. For details see MyMoneyKeyValueContainer::value(). - * - * @param key const reference to QString containing the key - * @return QString containing the value - */ - QString value(const QString& key) const override; + MyMoneyAccount equity() const; + + void loadAccounts(const QMap& acc); + void loadTransactions(const QMap& map); + void loadInstitutions(const QMap& map); + void loadPayees(const QMap& map); + void loadTags(const QMap& map); + void loadSchedules(const QMap& map); + void loadSecurities(const QMap& map); + void loadCurrencies(const QMap& map); + void loadPrices(const MyMoneyPriceList& list); + void loadOnlineJobs(const QMap& onlineJobs); + void loadCostCenters(const QMap& costCenters); /** * This method is used to set a value in the @@ -645,7 +628,7 @@ * @param key const reference to QString containing the key * @param val const reference to QString containing the value */ - void setValue(const QString& key, const QString& val) override; + void setValue(const QString& key, const QString& val); /** * This method is used to delete a key-value-pair from the @@ -654,13 +637,20 @@ * * @param key const reference to QString containing the key */ - void deletePair(const QString& key) override; + void deletePair(const QString& key); - // documented in IMyMoneySerialize base class - QMap pairs() const override; - - // documented in IMyMoneySerialize base class - void setPairs(const QMap& list) override; + /** + * This method is used to initially store a set of key/value pairs + * in the container. It is meant to be used for loading functionality + * from permanent storage. See MyMoneyKeyValueContainer::setPairs() + * for details + * + * @param list const QMap containing the set of + * key/value pairs to be loaded into the container. + * + * @note All existing key/value pairs in the container will be deleted. + */ + void setPairs(const QMap& list); /** * This method is used to add a scheduled transaction to the engine. @@ -672,7 +662,7 @@ * * @param sched reference to the MyMoneySchedule object */ - void addSchedule(MyMoneySchedule& sched) override; + void addSchedule(MyMoneySchedule& sched); /** * This method is used to modify an existing MyMoneySchedule @@ -682,7 +672,7 @@ * * @param sched const reference to the MyMoneySchedule object to be updated */ - void modifySchedule(const MyMoneySchedule& sched) override; + void modifySchedule(const MyMoneySchedule& sched); /** * This method is used to remove an existing MyMoneySchedule object @@ -692,7 +682,7 @@ * * @param sched const reference to the MyMoneySchedule object to be updated */ - void removeSchedule(const MyMoneySchedule& sched) override; + void removeSchedule(const MyMoneySchedule& sched); /** * This method is used to retrieve a single MyMoneySchedule object. @@ -703,7 +693,7 @@ * @param id QString containing the id of the MyMoneySchedule object * @return MyMoneySchedule object */ - MyMoneySchedule schedule(const QString& id) const override; + MyMoneySchedule schedule(const QString& id) const; /** * This method is used to create a new security object. The ID will be created @@ -714,7 +704,7 @@ * * @param security MyMoneySecurity filled with data */ - void addSecurity(MyMoneySecurity& security) override; + void addSecurity(MyMoneySecurity& security); /** * This method is used to modify an existing MyMoneySchedule @@ -724,7 +714,7 @@ * * @param security reference to the MyMoneySecurity object to be updated */ - void modifySecurity(const MyMoneySecurity& security) override; + void modifySecurity(const MyMoneySecurity& security); /** * This method is used to remove an existing MyMoneySecurity object @@ -734,7 +724,7 @@ * * @param security reference to the MyMoneySecurity object to be removed */ - void removeSecurity(const MyMoneySecurity& security) override; + void removeSecurity(const MyMoneySecurity& security); /** * This method is used to retrieve a single MyMoneySchedule object. @@ -745,14 +735,14 @@ * @param id QString containing the id of the MyMoneySchedule object * @return MyMoneySchedule object */ - MyMoneySecurity security(const QString& id) const override; + MyMoneySecurity security(const QString& id) const; /** * This method returns a list of security objects that the engine has * knowledge of. */ - QList securityList() const override; + QList securityList() const; /** * This method is used to add a new currency object to the engine. @@ -763,7 +753,7 @@ * * @param currency reference to the MyMoneyCurrency object */ - void addCurrency(const MyMoneySecurity& currency) override; + void addCurrency(const MyMoneySecurity& currency); /** * This method is used to modify an existing MyMoneyCurrency @@ -773,7 +763,7 @@ * * @param currency reference to the MyMoneyCurrency object */ - void modifyCurrency(const MyMoneySecurity& currency) override; + void modifyCurrency(const MyMoneySecurity& currency); /** * This method is used to remove an existing MyMoneyCurrency object @@ -783,7 +773,7 @@ * * @param currency reference to the MyMoneyCurrency object */ - void removeCurrency(const MyMoneySecurity& currency) override; + void removeCurrency(const MyMoneySecurity& currency); /** * This method is used to retrieve a single MyMoneySchedule object. @@ -794,7 +784,7 @@ * @param id QString containing the id of the MyMoneySchedule object * @return MyMoneySchedule object */ - MyMoneySecurity currency(const QString& id) const override; + MyMoneySecurity currency(const QString& id) const; /** * This method is used to retrieve the list of all currencies @@ -804,7 +794,7 @@ * * @return QList of all MyMoneyCurrency objects. */ - QList currencyList() const override; + QList currencyList() const; /** * This method is used to extract a list of scheduled transactions @@ -838,13 +828,13 @@ eMyMoney::Schedule::PaymentType paymentType, const QDate& startDate, const QDate& endDate, - bool overdue) const override; + bool overdue) const; QList scheduleListEx(int scheduleTypes, int scheduleOcurrences, int schedulePaymentTypes, QDate startDate, - const QStringList& accounts) const override; + const QStringList& accounts) const; /** * This method is used to retrieve the list of all reports @@ -854,7 +844,7 @@ * * @return QList of all MyMoneyReport objects. */ - QList reportList() const override; + QList reportList() const; /** * This method is used to add a new report to the engine. @@ -866,7 +856,7 @@ * * @param report reference to the MyMoneyReport object */ - void addReport(MyMoneyReport& report) override; + void addReport(MyMoneyReport& report); /** * This method is used to load a set of reports into the engine. This is @@ -876,7 +866,7 @@ * * @param reports reference to the map of MyMoneyReport objects */ - void loadReports(const QMap& reports) override; + void loadReports(const QMap& reports); /** * This method is used to modify an existing MyMoneyReport @@ -886,7 +876,7 @@ * * @param report const reference to the MyMoneyReport object to be updated */ - void modifyReport(const MyMoneyReport& report) override; + void modifyReport(const MyMoneyReport& report); /** * This method returns the number of reports currently known to file @@ -894,7 +884,7 @@ * * @return number of reports known to file */ - uint countReports() const override; + uint countReports() const; /** * This method is used to retrieve a single MyMoneyReport object. @@ -905,7 +895,7 @@ * @param id QString containing the id of the MyMoneyReport object * @return MyMoneyReport object */ - MyMoneyReport report(const QString& id) const override; + MyMoneyReport report(const QString& id) const; /** * This method is used to remove an existing MyMoneyReport object @@ -915,7 +905,7 @@ * * @param report const reference to the MyMoneyReport object to be updated */ - void removeReport(const MyMoneyReport& report) override; + void removeReport(const MyMoneyReport& report); /** * This method is used to retrieve the list of all budgets @@ -925,7 +915,7 @@ * * @return QList of all MyMoneyBudget objects. */ - QList budgetList() const override; + QList budgetList() const; /** * This method is used to add a new budget to the engine. @@ -937,7 +927,7 @@ * * @param budget reference to the MyMoneyBudget object */ - void addBudget(MyMoneyBudget& budget) override; + void addBudget(MyMoneyBudget& budget); /** * This method is used to load a set of budgets into the engine. This is @@ -947,7 +937,7 @@ * * @param budgets reference to the map of MyMoneyBudget object */ - void loadBudgets(const QMap& budgets) override; + void loadBudgets(const QMap& budgets); /** * This method is used to retrieve the id to a corresponding @@ -958,7 +948,7 @@ * * @return MyMoneyBudget reference to object of budget */ - MyMoneyBudget budgetByName(const QString& budget) const override; + MyMoneyBudget budgetByName(const QString& budget) const; /** * This method is used to modify an existing MyMoneyBudget @@ -968,7 +958,7 @@ * * @param budget const reference to the MyMoneyBudget object to be updated */ - void modifyBudget(const MyMoneyBudget& budget) override; + void modifyBudget(const MyMoneyBudget& budget); /** * This method returns the number of budgets currently known to file @@ -976,7 +966,7 @@ * * @return number of budgets known to file */ - uint countBudgets() const override; + uint countBudgets() const; /** * This method is used to retrieve a single MyMoneyBudget object. @@ -987,7 +977,7 @@ * @param id QString containing the id of the MyMoneyBudget object * @return MyMoneyBudget object */ - MyMoneyBudget budget(const QString& id) const override; + MyMoneyBudget budget(const QString& id) const; /** * This method is used to remove an existing MyMoneyBudget object @@ -997,28 +987,28 @@ * * @param budget const reference to the MyMoneyBudget object to be updated */ - void removeBudget(const MyMoneyBudget& budget) override; + void removeBudget(const MyMoneyBudget& budget); /** * This method adds/replaces a price to/from the price list */ - void addPrice(const MyMoneyPrice& price) override; + void addPrice(const MyMoneyPrice& price); /** * This method removes a price from the price list */ - void removePrice(const MyMoneyPrice& price) override; + void removePrice(const MyMoneyPrice& price); /** * This method retrieves a price from the price list. * If @p date is inValid, QDate::currentDate() is assumed. */ - MyMoneyPrice price(const QString& fromId, const QString& toId, const QDate& _date, bool exactDate) const override; + MyMoneyPrice price(const QString& fromId, const QString& toId, const QDate& _date, bool exactDate) const; /** * This method returns a list of all price entries. */ - MyMoneyPriceList priceList() const override; + MyMoneyPriceList priceList() const; /** * This method checks, if the given @p object is referenced @@ -1031,96 +1021,25 @@ * @retval false @p object is not referenced * @retval true @p institution is referenced */ - bool isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const override; + bool isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const; /** * This method recalculates the balances of all accounts * based on the transactions stored in the engine. */ - void rebuildAccountBalances() override; - - void startTransaction() override; - bool commitTransaction() override; - void rollbackTransaction() override; + void rebuildAccountBalances(); -protected: - /** - * The member variable m_nextAccountID keeps the number that will be - * assigned to the next institution created. It is maintained by - * nextAccountID(). - */ - QString nextAccountID() override; - - /** - * The member variable m_nextTransactionID keeps the number that will be - * assigned to the next transaction created. It is maintained by - * nextTransactionID(). - */ - QString nextTransactionID() override; - - /** - * The member variable m_nextPayeeID keeps the number that will be - * assigned to the next payee created. It is maintained by - * nextPayeeID() - */ - QString nextPayeeID() override; - - /** - * The member variable m_nextTagID keeps the number that will be - * assigned to the next tag created. It is maintained by - * nextTagID() - */ - QString nextTagID() override; - - /** - * The member variable m_nextInstitutionID keeps the number that will be - * assigned to the next institution created. It is maintained by - * nextInstitutionID(). - */ - QString nextInstitutionID() override; - - /** - * The member variable m_nextScheduleID keeps the number that will be - * assigned to the next schedule created. It is maintained by - * nextScheduleID() - */ - QString nextScheduleID() override; - - /** - * The member variable m_nextSecurityID keeps the number that will be - * assigned to the next security object created. It is maintained by - * nextSecurityID() - */ - QString nextSecurityID() override; - - QString nextReportID() override; - - /** - * The member variable m_nextBudgetID keeps the number that will be - * assigned to the next budget object created. It is maintained by - * nextBudgetID() - */ - QString nextBudgetID() override; - - /** - * This member variable keeps the number that will be assigned to the - * next onlineJob object created. It is maintained by nextOnlineJobID() - */ - QString nextOnlineJobID() override; - - /** - * This member variable keeps the number that will be assigned to the - * next cost center object created. It is maintained by nextCostCenterID() - */ - QString nextCostCenterID() override; - -private: - MyMoneySeqAccessMgrPrivate* const d_ptr; - Q_DECLARE_PRIVATE_D(MyMoneySeqAccessMgr::d_ptr, MyMoneySeqAccessMgr) + void startTransaction(); + bool commitTransaction(); + void rollbackTransaction(); /** * This method will close a database and log the use roff */ - void close() override; + void close(); + +private: + MyMoneyStorageMgrPrivate * const d_ptr; + Q_DECLARE_PRIVATE(MyMoneyStorageMgr) }; #endif diff --git a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp b/kmymoney/mymoney/storage/mymoneystoragemgr.cpp rename from kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp rename to kmymoney/mymoney/storage/mymoneystoragemgr.cpp --- a/kmymoney/mymoney/storage/mymoneyseqaccessmgr.cpp +++ b/kmymoney/mymoney/storage/mymoneystoragemgr.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneyseqaccessmgr.cpp + mymoneygenericstorage.cpp ------------------- begin : Sun May 5 2002 copyright : (C) 2000-2002 by Michael Edwardes @@ -17,164 +17,90 @@ * * ***************************************************************************/ -#include "mymoneyseqaccessmgr_p.h" +#include "mymoneystoragemgr_p.h" // ---------------------------------------------------------------------------- // QT Includes +#include + // ---------------------------------------------------------------------------- // KDE Includes // ---------------------------------------------------------------------------- // Project Includes -#include "mymoneyreport.h" #include "mymoneyprice.h" -#include "onlinejob.h" -#include "mymoneystoragenames.h" - -#define TRY try { -#define CATCH } catch (const MyMoneyException &e) { -#define PASS } catch (const MyMoneyException &e) { throw; } - -const int INSTITUTION_ID_SIZE = 6; -const int ACCOUNT_ID_SIZE = 6; -const int TRANSACTION_ID_SIZE = 18; -const int PAYEE_ID_SIZE = 6; -const int TAG_ID_SIZE = 6; -const int SCHEDULE_ID_SIZE = 6; -const int SECURITY_ID_SIZE = 6; -const int REPORT_ID_SIZE = 6; -const int BUDGET_ID_SIZE = 6; -const int ONLINE_JOB_ID_SIZE = 6; -const int COSTCENTER_ID_SIZE = 6; - -using namespace MyMoneyStandardAccounts; -#include -MyMoneySeqAccessMgr::MyMoneySeqAccessMgr() : - d_ptr(new MyMoneySeqAccessMgrPrivate(this)) -{ - Q_D(MyMoneySeqAccessMgr); - // setup standard accounts - MyMoneyAccount acc_l; - acc_l.setAccountType(eMyMoney::Account::Type::Liability); - acc_l.setName("Liability"); - MyMoneyAccount liability(stdAccNames[stdAccLiability], acc_l); - - MyMoneyAccount acc_a; - acc_a.setAccountType(eMyMoney::Account::Type::Asset); - acc_a.setName("Asset"); - MyMoneyAccount asset(stdAccNames[stdAccAsset], acc_a); - - MyMoneyAccount acc_e; - acc_e.setAccountType(eMyMoney::Account::Type::Expense); - acc_e.setName("Expense"); - MyMoneyAccount expense(stdAccNames[stdAccExpense], acc_e); - - MyMoneyAccount acc_i; - acc_i.setAccountType(eMyMoney::Account::Type::Income); - acc_i.setName("Income"); - MyMoneyAccount income(stdAccNames[stdAccIncome], acc_i); - - MyMoneyAccount acc_q; - acc_q.setAccountType(eMyMoney::Account::Type::Equity); - acc_q.setName("Equity"); - MyMoneyAccount equity(stdAccNames[stdAccEquity], acc_q); - - QMap map; - map[stdAccNames[stdAccAsset]] = asset; - map[stdAccNames[stdAccLiability]] = liability; - map[stdAccNames[stdAccIncome]] = income; - map[stdAccNames[stdAccExpense]] = expense; - map[stdAccNames[stdAccEquity]] = equity; - // load account list with initial accounts - d->m_accountList = map; +MyMoneyStorageMgr::MyMoneyStorageMgr() : + d_ptr(new MyMoneyStorageMgrPrivate(this)) +{ + Q_D(MyMoneyStorageMgr); + d->init(); } -MyMoneySeqAccessMgr::~MyMoneySeqAccessMgr() +MyMoneyStorageMgr::~MyMoneyStorageMgr() { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); delete d; } -MyMoneyPayee MyMoneySeqAccessMgr::user() const +MyMoneyPayee MyMoneyStorageMgr::user() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_user; } -QDate MyMoneySeqAccessMgr::creationDate() const +QDate MyMoneyStorageMgr::creationDate() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_creationDate; } -QDate MyMoneySeqAccessMgr::lastModificationDate() const +QDate MyMoneyStorageMgr::lastModificationDate() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_lastModificationDate; } -uint MyMoneySeqAccessMgr::currentFixVersion() const +uint MyMoneyStorageMgr::currentFixVersion() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_currentFixVersion; } -uint MyMoneySeqAccessMgr::fileFixVersion() const +uint MyMoneyStorageMgr::fileFixVersion() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_fileFixVersion; } -void MyMoneySeqAccessMgr::setUser(const MyMoneyPayee& user) +void MyMoneyStorageMgr::setUser(const MyMoneyPayee& user) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_user = user; d->touch(); } -void MyMoneySeqAccessMgr::setCreationDate(const QDate& val) +void MyMoneyStorageMgr::setCreationDate(const QDate& val) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_creationDate = val; d->touch(); } -void MyMoneySeqAccessMgr::setLastModificationDate(const QDate& val) +void MyMoneyStorageMgr::setLastModificationDate(const QDate& val) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_lastModificationDate = val; d->m_dirty = false; } -void MyMoneySeqAccessMgr::setFileFixVersion(uint v) +void MyMoneyStorageMgr::setFileFixVersion(uint v) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_fileFixVersion = v; } -//MyMoneySeqAccessMgr const * MyMoneySeqAccessMgr::duplicate() -//{ -// auto that = new MyMoneySeqAccessMgr(); -// *that = *this; -// return that; -//} - -/** -* This method is used to get a SQL reader for subsequent database access - */ -QExplicitlySharedDataPointer MyMoneySeqAccessMgr::connectToDatabase -(const QUrl& /*url*/) -{ - return QExplicitlySharedDataPointer (); -} - -void MyMoneySeqAccessMgr::fillStorage() -{ - -} - -bool MyMoneySeqAccessMgr::isStandardAccount(const QString& id) const +bool MyMoneyStorageMgr::isStandardAccount(const QString& id) const { return id == stdAccNames[stdAccLiability] || id == stdAccNames[stdAccAsset] @@ -183,9 +109,9 @@ || id == stdAccNames[stdAccEquity]; } -void MyMoneySeqAccessMgr::setAccountName(const QString& id, const QString& name) +void MyMoneyStorageMgr::setAccountName(const QString& id, const QString& name) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); if (!isStandardAccount(id)) throw MYMONEYEXCEPTION("Only standard accounts can be modified using setAccountName()"); @@ -194,21 +120,28 @@ d->m_accountList.modify(acc.id(), acc); } -MyMoneyAccount MyMoneySeqAccessMgr::account(const QString& id) const +MyMoneyAccount MyMoneyStorageMgr::account(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); // locate the account and if present, return it's data - if (d->m_accountList.find(id) != d->m_accountList.end()) - return d->m_accountList[id]; + if (d->m_accountList.find(id) != d->m_accountList.end()) { + auto acc = d->m_accountList[id]; + // is that needed at all? + if (acc.fraction() == -1) { + const auto& sec = security(acc.currencyId()); + acc.fraction(sec); + } + return acc; + } // throw an exception, if it does not exist const auto msg = QString::fromLatin1("Unknown account id '%1'").arg(id); throw MYMONEYEXCEPTION(msg); } -void MyMoneySeqAccessMgr::accountList(QList& list) const +void MyMoneyStorageMgr::accountList(QList& list) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator it; for (it = d->m_accountList.begin(); it != d->m_accountList.end(); ++it) { if (!isStandardAccount((*it).id())) { @@ -217,21 +150,21 @@ } } -void MyMoneySeqAccessMgr::addAccount(MyMoneyAccount& account) +void MyMoneyStorageMgr::addAccount(MyMoneyAccount& account) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // create the account. - MyMoneyAccount newAccount(nextAccountID(), account); + MyMoneyAccount newAccount(d->nextAccountID(), account); d->m_accountList.insert(newAccount.id(), newAccount); account = newAccount; } -void MyMoneySeqAccessMgr::addPayee(MyMoneyPayee& payee) +void MyMoneyStorageMgr::addPayee(MyMoneyPayee& payee) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // create the payee - MyMoneyPayee newPayee(nextPayeeID(), payee); + MyMoneyPayee newPayee(d->nextPayeeID(), payee); d->m_payeeList.insert(newPayee.id(), newPayee); payee = newPayee; } @@ -240,26 +173,26 @@ * @brief Add onlineJob to storage * @param job caller stays owner of the object, but id will be set */ -void MyMoneySeqAccessMgr::addOnlineJob(onlineJob &job) +void MyMoneyStorageMgr::addOnlineJob(onlineJob &job) { - Q_D(MyMoneySeqAccessMgr); - onlineJob newJob = onlineJob(nextOnlineJobID(), job); + Q_D(MyMoneyStorageMgr); + onlineJob newJob = onlineJob(d->nextOnlineJobID(), job); d->m_onlineJobList.insert(newJob.id(), newJob); job = newJob; } -void MyMoneySeqAccessMgr::removeOnlineJob(const onlineJob& job) +void MyMoneyStorageMgr::removeOnlineJob(const onlineJob& job) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); if (!d->m_onlineJobList.contains(job.id())) { throw MYMONEYEXCEPTION("Unknown onlineJob '" + job.id() + "' should be removed."); } d->m_onlineJobList.remove(job.id()); } -void MyMoneySeqAccessMgr::modifyOnlineJob(const onlineJob &job) +void MyMoneyStorageMgr::modifyOnlineJob(const onlineJob &job) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator iter = d->m_onlineJobList.find(job.id()); if (iter == d->m_onlineJobList.end()) { throw MYMONEYEXCEPTION("Got unknown onlineJob '" + job.id() + "' for modifying"); @@ -268,23 +201,23 @@ d->m_onlineJobList.modify((*iter).id(), job); } -onlineJob MyMoneySeqAccessMgr::getOnlineJob(const QString& id) const +onlineJob MyMoneyStorageMgr::getOnlineJob(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); if (d->m_onlineJobList.contains(id)) { return d->m_onlineJobList[id]; } throw MYMONEYEXCEPTION("Unknown online Job '" + id + '\''); } -ulong MyMoneySeqAccessMgr::onlineJobId() const +ulong MyMoneyStorageMgr::onlineJobId() const { return 1; } -MyMoneyPayee MyMoneySeqAccessMgr::payee(const QString& id) const +MyMoneyPayee MyMoneyStorageMgr::payee(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_payeeList.find(id); if (it == d->m_payeeList.end()) @@ -293,9 +226,9 @@ return *it; } -MyMoneyPayee MyMoneySeqAccessMgr::payeeByName(const QString& payee) const +MyMoneyPayee MyMoneyStorageMgr::payeeByName(const QString& payee) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); if (payee.isEmpty()) return MyMoneyPayee::null; @@ -310,9 +243,9 @@ throw MYMONEYEXCEPTION("Unknown payee '" + payee + '\''); } -void MyMoneySeqAccessMgr::modifyPayee(const MyMoneyPayee& payee) +void MyMoneyStorageMgr::modifyPayee(const MyMoneyPayee& payee) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_payeeList.find(payee.id()); @@ -323,9 +256,9 @@ d->m_payeeList.modify((*it).id(), payee); } -void MyMoneySeqAccessMgr::removePayee(const MyMoneyPayee& payee) +void MyMoneyStorageMgr::removePayee(const MyMoneyPayee& payee) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it_t; QMap::ConstIterator it_s; QMap::ConstIterator it_p; @@ -356,24 +289,24 @@ d->m_payeeList.remove((*it_p).id()); } -QList MyMoneySeqAccessMgr::payeeList() const +QList MyMoneyStorageMgr::payeeList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_payeeList.values(); } -void MyMoneySeqAccessMgr::addTag(MyMoneyTag& tag) +void MyMoneyStorageMgr::addTag(MyMoneyTag& tag) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // create the tag - MyMoneyTag newTag(nextTagID(), tag); + MyMoneyTag newTag(d->nextTagID(), tag); d->m_tagList.insert(newTag.id(), newTag); tag = newTag; } -MyMoneyTag MyMoneySeqAccessMgr::tag(const QString& id) const +MyMoneyTag MyMoneyStorageMgr::tag(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_tagList.find(id); if (it == d->m_tagList.end()) @@ -382,9 +315,9 @@ return *it; } -MyMoneyTag MyMoneySeqAccessMgr::tagByName(const QString& tag) const +MyMoneyTag MyMoneyStorageMgr::tagByName(const QString& tag) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); if (tag.isEmpty()) return MyMoneyTag::null; @@ -399,9 +332,9 @@ throw MYMONEYEXCEPTION("Unknown tag '" + tag + '\''); } -void MyMoneySeqAccessMgr::modifyTag(const MyMoneyTag& tag) +void MyMoneyStorageMgr::modifyTag(const MyMoneyTag& tag) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_tagList.find(tag.id()); @@ -412,9 +345,9 @@ d->m_tagList.modify((*it).id(), tag); } -void MyMoneySeqAccessMgr::removeTag(const MyMoneyTag& tag) +void MyMoneyStorageMgr::removeTag(const MyMoneyTag& tag) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it_t; QMap::ConstIterator it_s; QMap::ConstIterator it_ta; @@ -445,15 +378,15 @@ d->m_tagList.remove((*it_ta).id()); } -QList MyMoneySeqAccessMgr::tagList() const +QList MyMoneyStorageMgr::tagList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_tagList.values(); } -void MyMoneySeqAccessMgr::addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) +void MyMoneyStorageMgr::addAccount(MyMoneyAccount& parent, MyMoneyAccount& account) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator theParent; QMap::ConstIterator theChild; @@ -483,10 +416,10 @@ } -void MyMoneySeqAccessMgr::addInstitution(MyMoneyInstitution& institution) +void MyMoneyStorageMgr::addInstitution(MyMoneyInstitution& institution) { - Q_D(MyMoneySeqAccessMgr); - MyMoneyInstitution newInstitution(nextInstitutionID(), institution); + Q_D(MyMoneyStorageMgr); + MyMoneyInstitution newInstitution(d->nextInstitutionID(), institution); d->m_institutionList.insert(newInstitution.id(), newInstitution); @@ -494,9 +427,9 @@ institution = newInstitution; } -uint MyMoneySeqAccessMgr::transactionCount(const QString& account) const +uint MyMoneyStorageMgr::transactionCount(const QString& account) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); uint cnt = 0; if (account.length() == 0) { @@ -528,9 +461,9 @@ return cnt; } -QMap MyMoneySeqAccessMgr::transactionCountMap() const +QMap MyMoneyStorageMgr::transactionCountMap() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap map; // scan all transactions @@ -543,21 +476,21 @@ return map; } -uint MyMoneySeqAccessMgr::institutionCount() const +uint MyMoneyStorageMgr::institutionCount() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_institutionList.count(); } -uint MyMoneySeqAccessMgr::accountCount() const +uint MyMoneyStorageMgr::accountCount() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_accountList.count(); } -void MyMoneySeqAccessMgr::addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate) +void MyMoneyStorageMgr::addTransaction(MyMoneyTransaction& transaction, bool skipAccountUpdate) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // perform some checks to see that the transaction stuff is OK. For // now we assume that // * no ids are assigned @@ -579,7 +512,7 @@ payee(split.payeeId()); } - MyMoneyTransaction newTransaction(nextTransactionID(), transaction); + MyMoneyTransaction newTransaction(d->nextTransactionID(), transaction); QString key = newTransaction.uniqueSortKey(); d->m_transactionList.insert(key, newTransaction); @@ -598,9 +531,9 @@ } } -bool MyMoneySeqAccessMgr::hasActiveSplits(const QString& id) const +bool MyMoneyStorageMgr::hasActiveSplits(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator it; for (it = d->m_transactionList.begin(); it != d->m_transactionList.end(); ++it) { @@ -611,9 +544,9 @@ return false; } -MyMoneyInstitution MyMoneySeqAccessMgr::institution(const QString& id) const +MyMoneyInstitution MyMoneyStorageMgr::institution(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator pos; pos = d->m_institutionList.find(id); @@ -622,27 +555,27 @@ throw MYMONEYEXCEPTION("unknown institution"); } -bool MyMoneySeqAccessMgr::dirty() const +bool MyMoneyStorageMgr::dirty() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_dirty; } -void MyMoneySeqAccessMgr::setDirty() +void MyMoneyStorageMgr::setDirty() { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_dirty = true; } -QList MyMoneySeqAccessMgr::institutionList() const +QList MyMoneyStorageMgr::institutionList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_institutionList.values(); } -void MyMoneySeqAccessMgr::modifyAccount(const MyMoneyAccount& account, bool skipCheck) +void MyMoneyStorageMgr::modifyAccount(const MyMoneyAccount& account, bool skipCheck) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator pos; // locate the account in the file global pool @@ -672,9 +605,9 @@ throw MYMONEYEXCEPTION("Unknown account id"); } -void MyMoneySeqAccessMgr::modifyInstitution(const MyMoneyInstitution& institution) +void MyMoneyStorageMgr::modifyInstitution(const MyMoneyInstitution& institution) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator pos; // locate the institution in the file global pool @@ -686,9 +619,9 @@ throw MYMONEYEXCEPTION("unknown institution"); } -void MyMoneySeqAccessMgr::modifyTransaction(const MyMoneyTransaction& transaction) +void MyMoneyStorageMgr::modifyTransaction(const MyMoneyTransaction& transaction) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // perform some checks to see that the transaction stuff is OK. For // now we assume that // * ids are assigned @@ -759,19 +692,19 @@ } } -void MyMoneySeqAccessMgr::reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent) +void MyMoneyStorageMgr::reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->reparentAccount(account, parent, true); } -void MyMoneySeqAccessMgr::close() +void MyMoneyStorageMgr::close() { } -void MyMoneySeqAccessMgr::removeTransaction(const MyMoneyTransaction& transaction) +void MyMoneyStorageMgr::removeTransaction(const MyMoneyTransaction& transaction) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // first perform all the checks if (transaction.id().isEmpty()) throw MYMONEYEXCEPTION("invalid transaction to be deleted"); @@ -807,15 +740,15 @@ } -void MyMoneySeqAccessMgr::removeAccount(const MyMoneyAccount& account) +void MyMoneyStorageMgr::removeAccount(const MyMoneyAccount& account) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); MyMoneyAccount parent; // check that the account and it's parent exist // this will throw an exception if the id is unknown - MyMoneySeqAccessMgr::account(account.id()); - parent = MyMoneySeqAccessMgr::account(account.parentAccountId()); + MyMoneyStorageMgr::account(account.id()); + parent = MyMoneyStorageMgr::account(account.parentAccountId()); // check that it's not one of the standard account groups if (isStandardAccount(account.id())) @@ -830,7 +763,7 @@ // round do the re-parenting. foreach (const auto accountID, account.accountList()) - MyMoneySeqAccessMgr::account(accountID); + MyMoneyStorageMgr::account(accountID); // if one of the accounts did not exist, an exception had been // thrown and we would not make it until here. @@ -866,7 +799,7 @@ // FIXME: move this logic to MyMoneyFile foreach (const auto accountID, (*it_a).accountList()) { - MyMoneyAccount acc(MyMoneySeqAccessMgr::account(accountID)); + MyMoneyAccount acc(MyMoneyStorageMgr::account(accountID)); d->reparentAccount(acc, parent, false); } @@ -879,9 +812,9 @@ } } -void MyMoneySeqAccessMgr::removeInstitution(const MyMoneyInstitution& institution) +void MyMoneyStorageMgr::removeInstitution(const MyMoneyInstitution& institution) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it_i; it_i = d->m_institutionList.find(institution.id()); @@ -892,9 +825,9 @@ throw MYMONEYEXCEPTION("invalid institution"); } -void MyMoneySeqAccessMgr::transactionList(QList& list, MyMoneyTransactionFilter& filter) const +void MyMoneyStorageMgr::transactionList(QList& list, MyMoneyTransactionFilter& filter) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); list.clear(); for (const auto& transaction : d->m_transactionList) { @@ -910,9 +843,9 @@ } } -void MyMoneySeqAccessMgr::transactionList(QList< QPair >& list, MyMoneyTransactionFilter& filter) const +void MyMoneyStorageMgr::transactionList(QList< QPair >& list, MyMoneyTransactionFilter& filter) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); list.clear(); for (const auto& transaction : d->m_transactionList) @@ -920,28 +853,28 @@ list.append(qMakePair(transaction, split)); } -QList MyMoneySeqAccessMgr::transactionList(MyMoneyTransactionFilter& filter) const +QList MyMoneyStorageMgr::transactionList(MyMoneyTransactionFilter& filter) const { QList list; transactionList(list, filter); return list; } -QList MyMoneySeqAccessMgr::onlineJobList() const +QList MyMoneyStorageMgr::onlineJobList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_onlineJobList.values(); } -QList< MyMoneyCostCenter > MyMoneySeqAccessMgr::costCenterList() const +QList< MyMoneyCostCenter > MyMoneyStorageMgr::costCenterList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_costCenterList.values(); } -MyMoneyCostCenter MyMoneySeqAccessMgr::costCenter(const QString& id) const +MyMoneyCostCenter MyMoneyStorageMgr::costCenter(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); if (!d->m_costCenterList.contains(id)) { QString msg = QString("Invalid cost center id '%1'").arg(id); throw MYMONEYEXCEPTION(msg); @@ -949,15 +882,15 @@ return d->m_costCenterList[id]; } -bool MyMoneySeqAccessMgr::isDuplicateTransaction(const QString& id) const +bool MyMoneyStorageMgr::isDuplicateTransaction(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_transactionKeys.contains(id); } -MyMoneyTransaction MyMoneySeqAccessMgr::transaction(const QString& id) const +MyMoneyTransaction MyMoneyStorageMgr::transaction(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); // get the full key of this transaction, throw exception // if it's invalid (unknown) if (!d->m_transactionKeys.contains(id)) { @@ -975,9 +908,9 @@ return d->m_transactionList[key]; } -MyMoneyTransaction MyMoneySeqAccessMgr::transaction(const QString& account, const int idx) const +MyMoneyTransaction MyMoneyStorageMgr::transaction(const QString& account, const int idx) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); /* removed with MyMoneyAccount::Transaction QMap::ConstIterator acc; @@ -1011,9 +944,9 @@ return transaction(list[idx].id()); } -MyMoneyMoney MyMoneySeqAccessMgr::balance(const QString& id, const QDate& date) const +MyMoneyMoney MyMoneyStorageMgr::balance(const QString& id, const QDate& date) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); if (!d->m_accountList.contains(id)) throw MYMONEYEXCEPTION(QString("Unknown account id '%1'").arg(id)); @@ -1026,8 +959,7 @@ return d->calculateBalance(id, date); } - -MyMoneyMoney MyMoneySeqAccessMgr::totalBalance(const QString& id, const QDate& date) const +MyMoneyMoney MyMoneyStorageMgr::totalBalance(const QString& id, const QDate& date) const { MyMoneyMoney result(balance(id, date)); @@ -1037,29 +969,29 @@ return result; } -MyMoneyAccount MyMoneySeqAccessMgr::liability() const { +MyMoneyAccount MyMoneyStorageMgr::liability() const { return account(stdAccNames[stdAccLiability]); } -MyMoneyAccount MyMoneySeqAccessMgr::asset() const { +MyMoneyAccount MyMoneyStorageMgr::asset() const { return account(stdAccNames[stdAccAsset]); } -MyMoneyAccount MyMoneySeqAccessMgr::expense() const { +MyMoneyAccount MyMoneyStorageMgr::expense() const { return account(stdAccNames[stdAccExpense]); } -MyMoneyAccount MyMoneySeqAccessMgr::income() const { +MyMoneyAccount MyMoneyStorageMgr::income() const { return account(stdAccNames[stdAccIncome]); } -MyMoneyAccount MyMoneySeqAccessMgr::equity() const { +MyMoneyAccount MyMoneyStorageMgr::equity() const { return account(stdAccNames[stdAccEquity]); } -void MyMoneySeqAccessMgr::loadAccounts(const QMap& map) +void MyMoneyStorageMgr::loadAccounts(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_accountList = map; // scan the map to identify the last used id @@ -1076,9 +1008,9 @@ } } -void MyMoneySeqAccessMgr::loadTransactions(const QMap& map) +void MyMoneyStorageMgr::loadTransactions(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_transactionList = map; // now fill the key map and @@ -1101,9 +1033,9 @@ } } -void MyMoneySeqAccessMgr::loadInstitutions(const QMap& map) +void MyMoneyStorageMgr::loadInstitutions(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_institutionList = map; // scan the map to identify the last used id @@ -1120,9 +1052,9 @@ } } -void MyMoneySeqAccessMgr::loadPayees(const QMap& map) +void MyMoneyStorageMgr::loadPayees(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_payeeList = map; // scan the map to identify the last used id @@ -1142,9 +1074,9 @@ } } -void MyMoneySeqAccessMgr::loadTags(const QMap& map) +void MyMoneyStorageMgr::loadTags(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_tagList = map; // scan the map to identify the last used id @@ -1164,9 +1096,9 @@ } } -void MyMoneySeqAccessMgr::loadSecurities(const QMap& map) +void MyMoneyStorageMgr::loadSecurities(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_securitiesList = map; // scan the map to identify the last used id @@ -1183,21 +1115,21 @@ } } -void MyMoneySeqAccessMgr::loadCurrencies(const QMap& map) +void MyMoneyStorageMgr::loadCurrencies(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_currencyList = map; } -void MyMoneySeqAccessMgr::loadPrices(const MyMoneyPriceList& list) +void MyMoneyStorageMgr::loadPrices(const MyMoneyPriceList& list) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_priceList = list; } -void MyMoneySeqAccessMgr::loadOnlineJobs(const QMap< QString, onlineJob >& onlineJobs) +void MyMoneyStorageMgr::loadOnlineJobs(const QMap< QString, onlineJob >& onlineJobs) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_onlineJobList = onlineJobs; QString lastId(""); const QMap< QString, onlineJob >::const_iterator end = onlineJobs.constEnd(); @@ -1212,9 +1144,9 @@ } } -void MyMoneySeqAccessMgr::loadCostCenters(const QMap< QString, MyMoneyCostCenter >& costCenters) +void MyMoneyStorageMgr::loadCostCenters(const QMap< QString, MyMoneyCostCenter >& costCenters) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_costCenterList = costCenters; // scan the map to identify the last used id @@ -1231,160 +1163,31 @@ } } -void MyMoneySeqAccessMgr::loadAccountId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextAccountID = id; -} - -void MyMoneySeqAccessMgr::loadTransactionId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextTransactionID = id; -} - -void MyMoneySeqAccessMgr::loadPayeeId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextPayeeID = id; -} - -void MyMoneySeqAccessMgr::loadTagId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextTagID = id; -} - -void MyMoneySeqAccessMgr::loadInstitutionId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextInstitutionID = id; -} - -void MyMoneySeqAccessMgr::loadSecurityId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextSecurityID = id; -} - -void MyMoneySeqAccessMgr::loadReportId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextReportID = id; -} - -void MyMoneySeqAccessMgr::loadBudgetId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextBudgetID = id; -} - -void MyMoneySeqAccessMgr::loadOnlineJobId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextOnlineJobID = id; -} - -void MyMoneySeqAccessMgr::loadCostCenterId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextCostCenterID = id; -} - -ulong MyMoneySeqAccessMgr::accountId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextAccountID; -} - -ulong MyMoneySeqAccessMgr::transactionId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextTransactionID; -} - -ulong MyMoneySeqAccessMgr::payeeId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextPayeeID; -} - -ulong MyMoneySeqAccessMgr::tagId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextTagID; -} - -ulong MyMoneySeqAccessMgr::institutionId() const +void MyMoneyStorageMgr::setValue(const QString& key, const QString& val) { - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextInstitutionID; -} - -ulong MyMoneySeqAccessMgr::scheduleId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextScheduleID; -} - -ulong MyMoneySeqAccessMgr::securityId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextSecurityID; -} - -ulong MyMoneySeqAccessMgr::reportId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextReportID; -} - -ulong MyMoneySeqAccessMgr::budgetId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextBudgetID; -} - -ulong MyMoneySeqAccessMgr::costCenterId() const -{ - Q_D(const MyMoneySeqAccessMgr); - return d->m_nextCostCenterID; -} - -QString MyMoneySeqAccessMgr::value(const QString& key) const -{ - return MyMoneyKeyValueContainer::value(key); -} - -void MyMoneySeqAccessMgr::setValue(const QString& key, const QString& val) -{ - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); MyMoneyKeyValueContainer::setValue(key, val); d->touch(); } -void MyMoneySeqAccessMgr::deletePair(const QString& key) +void MyMoneyStorageMgr::deletePair(const QString& key) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); MyMoneyKeyValueContainer::deletePair(key); d->touch(); } -QMap MyMoneySeqAccessMgr::pairs() const -{ - return MyMoneyKeyValueContainer::pairs(); -} -void MyMoneySeqAccessMgr::setPairs(const QMap& list) +void MyMoneyStorageMgr::setPairs(const QMap& list) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); MyMoneyKeyValueContainer::setPairs(list); d->touch(); } -void MyMoneySeqAccessMgr::addSchedule(MyMoneySchedule& sched) +void MyMoneyStorageMgr::addSchedule(MyMoneySchedule& sched) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // first perform all the checks if (!sched.id().isEmpty()) throw MYMONEYEXCEPTION("schedule already contains an id"); @@ -1392,14 +1195,20 @@ // The following will throw an exception when it fails sched.validate(false); - MyMoneySchedule newSched(nextScheduleID(), sched); + // it is expected in mymoneygenericstorage-test + const auto splits = sched.transaction().splits(); + for (const auto& split : splits) + if (!d->m_accountList.contains(split.accountId())) + throw MYMONEYEXCEPTION("bad account id"); + + MyMoneySchedule newSched(d->nextScheduleID(), sched); d->m_scheduleList.insert(newSched.id(), newSched); sched = newSched; } -void MyMoneySeqAccessMgr::modifySchedule(const MyMoneySchedule& sched) +void MyMoneyStorageMgr::modifySchedule(const MyMoneySchedule& sched) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_scheduleList.find(sched.id()); @@ -1411,9 +1220,9 @@ d->m_scheduleList.modify(sched.id(), sched); } -void MyMoneySeqAccessMgr::removeSchedule(const MyMoneySchedule& sched) +void MyMoneyStorageMgr::removeSchedule(const MyMoneySchedule& sched) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_scheduleList.find(sched.id()); @@ -1426,9 +1235,9 @@ d->m_scheduleList.remove(sched.id()); } -MyMoneySchedule MyMoneySeqAccessMgr::schedule(const QString& id) const +MyMoneySchedule MyMoneyStorageMgr::schedule(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator pos; // locate the schedule and if present, return it's data @@ -1441,7 +1250,7 @@ throw MYMONEYEXCEPTION(msg); } -QList MyMoneySeqAccessMgr::scheduleList(const QString& accountId, +QList MyMoneyStorageMgr::scheduleList(const QString& accountId, eMyMoney::Schedule::Type type, eMyMoney::Schedule::Occurrence occurrence, eMyMoney::Schedule::PaymentType paymentType, @@ -1449,7 +1258,7 @@ const QDate& endDate, bool overdue) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator pos; QList list; @@ -1519,9 +1328,9 @@ return list; } -void MyMoneySeqAccessMgr::loadSchedules(const QMap& map) +void MyMoneyStorageMgr::loadSchedules(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_scheduleList = map; // scan the map to identify the last used id @@ -1538,19 +1347,13 @@ } } -void MyMoneySeqAccessMgr::loadScheduleId(ulong id) -{ - Q_D(MyMoneySeqAccessMgr); - d->m_nextScheduleID = id; -} - -QList MyMoneySeqAccessMgr::scheduleListEx(int scheduleTypes, +QList MyMoneyStorageMgr::scheduleListEx(int scheduleTypes, int scheduleOcurrences, int schedulePaymentTypes, QDate date, const QStringList& accounts) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); // qDebug("scheduleListEx"); QMap::ConstIterator pos; @@ -1590,20 +1393,20 @@ return list; } -void MyMoneySeqAccessMgr::addSecurity(MyMoneySecurity& security) +void MyMoneyStorageMgr::addSecurity(MyMoneySecurity& security) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // create the account - MyMoneySecurity newSecurity(nextSecurityID(), security); + MyMoneySecurity newSecurity(d->nextSecurityID(), security); d->m_securitiesList.insert(newSecurity.id(), newSecurity); security = newSecurity; } -void MyMoneySeqAccessMgr::modifySecurity(const MyMoneySecurity& security) +void MyMoneyStorageMgr::modifySecurity(const MyMoneySecurity& security) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_securitiesList.find(security.id()); @@ -1616,9 +1419,9 @@ d->m_securitiesList.modify(security.id(), security); } -void MyMoneySeqAccessMgr::removeSecurity(const MyMoneySecurity& security) +void MyMoneyStorageMgr::removeSecurity(const MyMoneySecurity& security) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; // FIXME: check referential integrity @@ -1633,9 +1436,9 @@ d->m_securitiesList.remove(security.id()); } -MyMoneySecurity MyMoneySeqAccessMgr::security(const QString& id) const +MyMoneySecurity MyMoneyStorageMgr::security(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator it = d->m_securitiesList.find(id); if (it != d->m_securitiesList.end()) { return it.value(); @@ -1644,16 +1447,16 @@ return MyMoneySecurity(); } -QList MyMoneySeqAccessMgr::securityList() const +QList MyMoneyStorageMgr::securityList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); //qDebug("securityList: Security list size is %d, this=%8p", m_equitiesList.size(), (void*)this); return d->m_securitiesList.values(); } -void MyMoneySeqAccessMgr::addCurrency(const MyMoneySecurity& currency) +void MyMoneyStorageMgr::addCurrency(const MyMoneySecurity& currency) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_currencyList.find(currency.id()); @@ -1664,9 +1467,9 @@ d->m_currencyList.insert(currency.id(), currency); } -void MyMoneySeqAccessMgr::modifyCurrency(const MyMoneySecurity& currency) +void MyMoneyStorageMgr::modifyCurrency(const MyMoneySecurity& currency) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_currencyList.find(currency.id()); @@ -1677,9 +1480,9 @@ d->m_currencyList.modify(currency.id(), currency); } -void MyMoneySeqAccessMgr::removeCurrency(const MyMoneySecurity& currency) +void MyMoneyStorageMgr::removeCurrency(const MyMoneySecurity& currency) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; // FIXME: check referential integrity @@ -1692,9 +1495,9 @@ d->m_currencyList.remove(currency.id()); } -MyMoneySecurity MyMoneySeqAccessMgr::currency(const QString& id) const +MyMoneySecurity MyMoneyStorageMgr::currency(const QString& id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); if (id.isEmpty()) { } @@ -1708,32 +1511,32 @@ return *it; } -QList MyMoneySeqAccessMgr::currencyList() const +QList MyMoneyStorageMgr::currencyList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_currencyList.values(); } -QList MyMoneySeqAccessMgr::reportList() const +QList MyMoneyStorageMgr::reportList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_reportList.values(); } -void MyMoneySeqAccessMgr::addReport(MyMoneyReport& report) +void MyMoneyStorageMgr::addReport(MyMoneyReport& report) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); if (!report.id().isEmpty()) throw MYMONEYEXCEPTION("report already contains an id"); - MyMoneyReport newReport(nextReportID(), report); + MyMoneyReport newReport(d->nextReportID(), report); d->m_reportList.insert(newReport.id(), newReport); report = newReport; } -void MyMoneySeqAccessMgr::loadReports(const QMap& map) +void MyMoneyStorageMgr::loadReports(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_reportList = map; // scan the map to identify the last used id @@ -1750,9 +1553,9 @@ } } -void MyMoneySeqAccessMgr::modifyReport(const MyMoneyReport& report) +void MyMoneyStorageMgr::modifyReport(const MyMoneyReport& report) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_reportList.find(report.id()); @@ -1763,21 +1566,21 @@ d->m_reportList.modify(report.id(), report); } -uint MyMoneySeqAccessMgr::countReports() const +uint MyMoneyStorageMgr::countReports() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_reportList.count(); } -MyMoneyReport MyMoneySeqAccessMgr::report(const QString& _id) const +MyMoneyReport MyMoneyStorageMgr::report(const QString& _id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_reportList[_id]; } -void MyMoneySeqAccessMgr::removeReport(const MyMoneyReport& report) +void MyMoneyStorageMgr::removeReport(const MyMoneyReport& report) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_reportList.find(report.id()); @@ -1789,24 +1592,24 @@ d->m_reportList.remove(report.id()); } -QList MyMoneySeqAccessMgr::budgetList() const +QList MyMoneyStorageMgr::budgetList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_budgetList.values(); } -void MyMoneySeqAccessMgr::addBudget(MyMoneyBudget& budget) +void MyMoneyStorageMgr::addBudget(MyMoneyBudget& budget) { - Q_D(MyMoneySeqAccessMgr); - MyMoneyBudget newBudget(nextBudgetID(), budget); + Q_D(MyMoneyStorageMgr); + MyMoneyBudget newBudget(d->nextBudgetID(), budget); d->m_budgetList.insert(newBudget.id(), newBudget); budget = newBudget; } -void MyMoneySeqAccessMgr::loadBudgets(const QMap& map) +void MyMoneyStorageMgr::loadBudgets(const QMap& map) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_budgetList = map; // scan the map to identify the last used id @@ -1823,9 +1626,9 @@ } } -MyMoneyBudget MyMoneySeqAccessMgr::budgetByName(const QString& budget) const +MyMoneyBudget MyMoneyStorageMgr::budgetByName(const QString& budget) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); QMap::ConstIterator it_p; for (it_p = d->m_budgetList.begin(); it_p != d->m_budgetList.end(); ++it_p) { @@ -1837,9 +1640,9 @@ throw MYMONEYEXCEPTION("Unknown budget '" + budget + '\''); } -void MyMoneySeqAccessMgr::modifyBudget(const MyMoneyBudget& budget) +void MyMoneyStorageMgr::modifyBudget(const MyMoneyBudget& budget) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_budgetList.find(budget.id()); @@ -1850,21 +1653,21 @@ d->m_budgetList.modify(budget.id(), budget); } -uint MyMoneySeqAccessMgr::countBudgets() const +uint MyMoneyStorageMgr::countBudgets() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_budgetList.count(); } -MyMoneyBudget MyMoneySeqAccessMgr::budget(const QString& _id) const +MyMoneyBudget MyMoneyStorageMgr::budget(const QString& _id) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); return d->m_budgetList[_id]; } -void MyMoneySeqAccessMgr::removeBudget(const MyMoneyBudget& budget) +void MyMoneyStorageMgr::removeBudget(const MyMoneyBudget& budget) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); QMap::ConstIterator it; it = d->m_budgetList.find(budget.id()); @@ -1876,9 +1679,9 @@ d->m_budgetList.remove(budget.id()); } -void MyMoneySeqAccessMgr::addPrice(const MyMoneyPrice& price) +void MyMoneyStorageMgr::addPrice(const MyMoneyPrice& price) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); MyMoneySecurityPair pricePair(price.from(), price.to()); QMap::ConstIterator it_m; it_m = d->m_priceList.find(pricePair); @@ -1911,9 +1714,9 @@ } } -void MyMoneySeqAccessMgr::removePrice(const MyMoneyPrice& price) +void MyMoneyStorageMgr::removePrice(const MyMoneyPrice& price) { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); MyMoneySecurityPair pricePair(price.from(), price.to()); QMap::ConstIterator it_m; it_m = d->m_priceList.find(pricePair); @@ -1933,17 +1736,17 @@ } } -MyMoneyPriceList MyMoneySeqAccessMgr::priceList() const +MyMoneyPriceList MyMoneyStorageMgr::priceList() const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); MyMoneyPriceList list; d->m_priceList.map(list); return list; } -MyMoneyPrice MyMoneySeqAccessMgr::price(const QString& fromId, const QString& toId, const QDate& _date, bool exactDate) const +MyMoneyPrice MyMoneyStorageMgr::price(const QString& fromId, const QString& toId, const QDate& _date, bool exactDate) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); // if the caller selected an exact entry, we can search for it using the date as the key QMap::const_iterator itm = d->m_priceList.find(qMakePair(fromId, toId)); if (itm != d->m_priceList.end()) { @@ -1969,9 +1772,9 @@ return MyMoneyPrice(); } -void MyMoneySeqAccessMgr::rebuildAccountBalances() +void MyMoneyStorageMgr::rebuildAccountBalances() { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); // reset the balance of all accounts to 0 QMap map; d->m_accountList.map(map); @@ -1997,14 +1800,14 @@ d->m_accountList = map; } -bool MyMoneySeqAccessMgr::isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const +bool MyMoneyStorageMgr::isReferenced(const MyMoneyObject& obj, const QBitArray& skipCheck) const { - Q_D(const MyMoneySeqAccessMgr); + Q_D(const MyMoneyStorageMgr); Q_ASSERT(skipCheck.count() == (int)Reference::Count); // We delete all references in reports when an object // is deleted, so we don't need to check here. See - // MyMoneySeqAccessMgr::removeReferences(). In case + // MyMoneyStorageMgr::removeReferences(). In case // you miss the report checks in the following lines ;) const auto& id = obj.id(); @@ -2072,9 +1875,9 @@ return false; } -void MyMoneySeqAccessMgr::startTransaction() +void MyMoneyStorageMgr::startTransaction() { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_payeeList.startTransaction(&d->m_nextPayeeID); d->m_tagList.startTransaction(&d->m_nextTagID); d->m_institutionList.startTransaction(&d->m_nextInstitutionID); @@ -2090,9 +1893,9 @@ d->m_onlineJobList.startTransaction(&d->m_nextOnlineJobID); } -bool MyMoneySeqAccessMgr::commitTransaction() +bool MyMoneyStorageMgr::commitTransaction() { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); bool rc = false; rc |= d->m_payeeList.commitTransaction(); rc |= d->m_tagList.commitTransaction(); @@ -2115,9 +1918,9 @@ return rc; } -void MyMoneySeqAccessMgr::rollbackTransaction() +void MyMoneyStorageMgr::rollbackTransaction() { - Q_D(MyMoneySeqAccessMgr); + Q_D(MyMoneyStorageMgr); d->m_payeeList.rollbackTransaction(); d->m_tagList.rollbackTransaction(); d->m_institutionList.rollbackTransaction(); @@ -2132,106 +1935,3 @@ d->m_priceList.rollbackTransaction(); d->m_onlineJobList.rollbackTransaction(); } - -QString MyMoneySeqAccessMgr::nextAccountID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextAccountID); - id = 'A' + id.rightJustified(ACCOUNT_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextTransactionID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextTransactionID); - id = 'T' + id.rightJustified(TRANSACTION_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextPayeeID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextPayeeID); - id = 'P' + id.rightJustified(PAYEE_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextTagID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextTagID); - id = 'G' + id.rightJustified(TAG_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextInstitutionID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextInstitutionID); - id = 'I' + id.rightJustified(INSTITUTION_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextScheduleID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextScheduleID); - id = "SCH" + id.rightJustified(SCHEDULE_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextSecurityID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextSecurityID); - id = 'E' + id.rightJustified(SECURITY_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextReportID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextReportID); - id = 'R' + id.rightJustified(REPORT_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextBudgetID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextBudgetID); - id = 'B' + id.rightJustified(BUDGET_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextOnlineJobID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextOnlineJobID); - id = 'O' + id.rightJustified(ONLINE_JOB_ID_SIZE, '0'); - return id; -} - -QString MyMoneySeqAccessMgr::nextCostCenterID() -{ - Q_D(MyMoneySeqAccessMgr); - QString id; - id.setNum(++d->m_nextCostCenterID); - id = 'C' + id.rightJustified(COSTCENTER_ID_SIZE, '0'); - return id; -} - -#undef TRY -#undef CATCH -#undef PASS diff --git a/kmymoney/mymoney/storage/mymoneyseqaccessmgr_p.h b/kmymoney/mymoney/storage/mymoneystoragemgr_p.h rename from kmymoney/mymoney/storage/mymoneyseqaccessmgr_p.h rename to kmymoney/mymoney/storage/mymoneystoragemgr_p.h --- a/kmymoney/mymoney/storage/mymoneyseqaccessmgr_p.h +++ b/kmymoney/mymoney/storage/mymoneystoragemgr_p.h @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneyseqaccessmgr.cpp + mymoneystoragemgr.cpp ------------------- begin : Sun May 5 2002 copyright : (C) 2000-2002 by Michael Edwardes @@ -17,10 +17,10 @@ * * ***************************************************************************/ -#ifndef MYMONEYSEQACCESSMGR_P_H -#define MYMONEYSEQACCESSMGR_P_H +#ifndef MYMONEYSTORAGEMGR_P_H +#define MYMONEYSTORAGEMGR_P_H -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" // ---------------------------------------------------------------------------- // QT Includes @@ -38,7 +38,6 @@ // Project Includes #include "mymoneyexception.h" -#include "mymoneystoragesql.h" #include "storageenums.h" #include "mymoneyinstitution.h" #include "mymoneyaccount.h" @@ -54,17 +53,32 @@ #include "mymoneytransactionfilter.h" #include "mymoneycostcenter.h" #include "mymoneymap.h" +#include "onlinejob.h" #include "mymoneyenums.h" +#include "mymoneystoragenames.h" +using namespace MyMoneyStandardAccounts; using namespace eStorage; -class MyMoneySeqAccessMgrPrivate +const int INSTITUTION_ID_SIZE = 6; +const int ACCOUNT_ID_SIZE = 6; +const int TRANSACTION_ID_SIZE = 18; +const int PAYEE_ID_SIZE = 6; +const int TAG_ID_SIZE = 6; +const int SCHEDULE_ID_SIZE = 6; +const int SECURITY_ID_SIZE = 6; +const int REPORT_ID_SIZE = 6; +const int BUDGET_ID_SIZE = 6; +const int ONLINE_JOB_ID_SIZE = 6; +const int COSTCENTER_ID_SIZE = 6; + +class MyMoneyStorageMgrPrivate { - Q_DISABLE_COPY(MyMoneySeqAccessMgrPrivate) - Q_DECLARE_PUBLIC(MyMoneySeqAccessMgr) + Q_DISABLE_COPY(MyMoneyStorageMgrPrivate) + Q_DECLARE_PUBLIC(MyMoneyStorageMgr) public: - explicit MyMoneySeqAccessMgrPrivate(MyMoneySeqAccessMgr* qq) : + explicit MyMoneyStorageMgrPrivate(MyMoneyStorageMgr* qq) : q_ptr(qq), m_nextInstitutionID(0), m_nextAccountID(0), @@ -86,10 +100,49 @@ { } - ~MyMoneySeqAccessMgrPrivate() + ~MyMoneyStorageMgrPrivate() { } + void init() + { + // setup standard accounts + MyMoneyAccount acc_l; + acc_l.setAccountType(eMyMoney::Account::Type::Liability); + acc_l.setName("Liability"); + MyMoneyAccount liability(stdAccNames[stdAccLiability], acc_l); + + MyMoneyAccount acc_a; + acc_a.setAccountType(eMyMoney::Account::Type::Asset); + acc_a.setName("Asset"); + MyMoneyAccount asset(stdAccNames[stdAccAsset], acc_a); + + MyMoneyAccount acc_e; + acc_e.setAccountType(eMyMoney::Account::Type::Expense); + acc_e.setName("Expense"); + MyMoneyAccount expense(stdAccNames[stdAccExpense], acc_e); + + MyMoneyAccount acc_i; + acc_i.setAccountType(eMyMoney::Account::Type::Income); + acc_i.setName("Income"); + MyMoneyAccount income(stdAccNames[stdAccIncome], acc_i); + + MyMoneyAccount acc_q; + acc_q.setAccountType(eMyMoney::Account::Type::Equity); + acc_q.setName("Equity"); + MyMoneyAccount equity(stdAccNames[stdAccEquity], acc_q); + + QMap map; + map[stdAccNames[stdAccAsset]] = asset; + map[stdAccNames[stdAccLiability]] = liability; + map[stdAccNames[stdAccIncome]] = income; + map[stdAccNames[stdAccExpense]] = expense; + map[stdAccNames[stdAccEquity]] = equity; + + // load account list with initial accounts + m_accountList = map; + } + /** * This method is used to set the dirty flag and update the * date of the last modification. @@ -125,7 +178,7 @@ */ void reparentAccount(MyMoneyAccount &account, MyMoneyAccount& parent, bool /* sendNotification */) { - Q_Q(MyMoneySeqAccessMgr); + Q_Q(MyMoneyStorageMgr); QMap::ConstIterator oldParent; QMap::ConstIterator newParent; QMap::ConstIterator childAccount; @@ -180,7 +233,7 @@ */ MyMoneyMoney calculateBalance(const QString& id, const QDate& date) const { - Q_Q(const MyMoneySeqAccessMgr); + Q_Q(const MyMoneyStorageMgr); MyMoneyMoney balance; QList list; @@ -224,7 +277,149 @@ } } - MyMoneySeqAccessMgr *q_ptr; + /** + * The member variable m_nextAccountID keeps the number that will be + * assigned to the next institution created. It is maintained by + * nextAccountID(). + */ + QString nextAccountID() + { + QString id; + id.setNum(++m_nextAccountID); + id = 'A' + id.rightJustified(ACCOUNT_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextTransactionID keeps the number that will be + * assigned to the next transaction created. It is maintained by + * nextTransactionID(). + */ + QString nextTransactionID() + { + QString id; + id.setNum(++m_nextTransactionID); + id = 'T' + id.rightJustified(TRANSACTION_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextPayeeID keeps the number that will be + * assigned to the next payee created. It is maintained by + * nextPayeeID() + */ + QString nextPayeeID() + { + QString id; + id.setNum(++m_nextPayeeID); + id = 'P' + id.rightJustified(PAYEE_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextTagID keeps the number that will be + * assigned to the next tag created. It is maintained by + * nextTagID() + */ + QString nextTagID() + { + QString id; + id.setNum(++m_nextTagID); + id = 'G' + id.rightJustified(TAG_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextInstitutionID keeps the number that will be + * assigned to the next institution created. It is maintained by + * nextInstitutionID(). + */ + QString nextInstitutionID() + { + QString id; + id.setNum(++m_nextInstitutionID); + id = 'I' + id.rightJustified(INSTITUTION_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextScheduleID keeps the number that will be + * assigned to the next schedule created. It is maintained by + * nextScheduleID() + */ + QString nextScheduleID() + { + QString id; + id.setNum(++m_nextScheduleID); + id = "SCH" + id.rightJustified(SCHEDULE_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextSecurityID keeps the number that will be + * assigned to the next security object created. It is maintained by + * nextSecurityID() + */ + QString nextSecurityID() + { + QString id; + id.setNum(++m_nextSecurityID); + id = 'E' + id.rightJustified(SECURITY_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextReportID keeps the number that will be + * assigned to the next report object created. It is maintained by + * nextReportID() + */ + QString nextReportID() + { + QString id; + id.setNum(++m_nextReportID); + id = 'R' + id.rightJustified(REPORT_ID_SIZE, '0'); + return id; + } + + /** + * The member variable m_nextBudgetID keeps the number that will be + * assigned to the next budget object created. It is maintained by + * nextBudgetID() + */ + QString nextBudgetID() + { + QString id; + id.setNum(++m_nextBudgetID); + id = 'B' + id.rightJustified(BUDGET_ID_SIZE, '0'); + return id; + } + + /** + * This member variable keeps the number that will be assigned to the + * next onlineJob object created. It is maintained by nextOnlineJobID() + */ + QString nextOnlineJobID() + { + QString id; + id.setNum(++m_nextOnlineJobID); + id = 'O' + id.rightJustified(ONLINE_JOB_ID_SIZE, '0'); + return id; + } + + /** + * This member variable keeps the number that will be assigned to the + * next cost center object created. It is maintained by nextCostCenterID() + */ + QString nextCostCenterID() + { + QString id; + id.setNum(++m_nextCostCenterID); + id = 'C' + id.rightJustified(COSTCENTER_ID_SIZE, '0'); + return id; + } + + MyMoneyStorageMgr *q_ptr; + /** * This member variable keeps the User information. * @see setUser() @@ -381,7 +576,7 @@ bool m_dirty; /** - * This member variable keeps the creation date of this MyMoneySeqAccessMgr + * This member variable keeps the creation date of this MyMoneyStorageMgr * object. It is set during the constructor and can only be modified using * the stream read operator. */ @@ -389,7 +584,7 @@ /** * This member variable keeps the date of the last modification of - * the MyMoneySeqAccessMgr object. + * the MyMoneyStorageMgr object. */ QDate m_lastModificationDate; diff --git a/kmymoney/mymoney/storage/mymoneystoragesql.h b/kmymoney/mymoney/storage/mymoneystoragesql.h --- a/kmymoney/mymoney/storage/mymoneystoragesql.h +++ b/kmymoney/mymoney/storage/mymoneystoragesql.h @@ -36,7 +36,6 @@ class QDate; class QIODevice; -class IMyMoneyStorage; class MyMoneyInstitution; class MyMoneyAccount; class MyMoneySecurity; @@ -55,7 +54,7 @@ class onlineJob; class databaseStoreableObject; class MyMoneyStorageSql; -class IMyMoneySerialize; +class MyMoneyStorageMgr; template struct QPair; template class QMap; @@ -74,14 +73,14 @@ */ class MyMoneyStorageSqlPrivate; -class MyMoneyStorageSql : public IMyMoneyStorageFormat, public QSqlDatabase, public QSharedData +class MyMoneyStorageSql : public IMyMoneyOperationsFormat, public QSqlDatabase, public QSharedData { Q_DISABLE_COPY(MyMoneyStorageSql) friend class MyMoneyDbDef; KMM_MYMONEY_UNIT_TESTABLE public: - explicit MyMoneyStorageSql(IMyMoneySerialize *storage, const QUrl&); + explicit MyMoneyStorageSql(MyMoneyStorageMgr *storage, const QUrl&); ~MyMoneyStorageSql() override; uint currentVersion() const; @@ -127,7 +126,7 @@ * @return : error message to be displayed * */ - QString lastError() const; + QString lastError() const; /** * This method is used when a database file is open, and the data is to @@ -257,8 +256,8 @@ void readTransactions(const MyMoneyTransactionFilter& filter); void setProgressCallback(void(*callback)(int, int, const QString&)) override; - void readFile(QIODevice* s, IMyMoneySerialize* storage) override; - void writeFile(QIODevice* s, IMyMoneySerialize* storage) override; + void readFile(QIODevice* s, MyMoneyStorageMgr* storage) override; + void writeFile(QIODevice* s, MyMoneyStorageMgr* storage) override; void startCommitUnit(const QString& callingFunction); bool endCommitUnit(const QString& callingFunction); diff --git a/kmymoney/mymoney/storage/mymoneystoragesql.cpp b/kmymoney/mymoney/storage/mymoneystoragesql.cpp --- a/kmymoney/mymoney/storage/mymoneystoragesql.cpp +++ b/kmymoney/mymoney/storage/mymoneystoragesql.cpp @@ -33,13 +33,12 @@ // Project Includes //************************ Constructor/Destructor ***************************** -MyMoneyStorageSql::MyMoneyStorageSql(IMyMoneySerialize *storage, const QUrl &url) : +MyMoneyStorageSql::MyMoneyStorageSql(MyMoneyStorageMgr *storage, const QUrl &url) : QSqlDatabase(QUrlQuery(url).queryItemValue("driver")), d_ptr(new MyMoneyStorageSqlPrivate(this)) { Q_D(MyMoneyStorageSql); d->m_storage = storage; - d->m_storagePtr = dynamic_cast(d->m_storage); } MyMoneyStorageSql::~MyMoneyStorageSql() @@ -67,7 +66,8 @@ d->m_driver = MyMoneyDbDriver::create(QUrlQuery(url).queryItemValue("driver")); //get the input options QStringList options = QUrlQuery(url).queryItemValue("options").split(','); - d->m_loadAll = options.contains("loadAll")/*|| m_mode == 0*/; + d->m_loadAll = true || // force loading whole database into memory since unification of storages + options.contains("loadAll")/*|| m_mode == 0*/; d->m_override = options.contains("override"); // create the database connection @@ -221,6 +221,8 @@ } catch (const QString &) { return false; } + // this seems to be nonsense, but it clears the dirty flag + // as a side-effect. } // The following is called from 'SaveAsDatabase' @@ -257,6 +259,9 @@ // make sure the progress bar is not shown any longer d->signalProgress(-1, -1); d->m_displayStatus = false; + // this seems to be nonsense, but it clears the dirty flag + // as a side-effect. + d->m_storage->setLastModificationDate(d->m_storage->lastModificationDate()); return true; } catch (const QString &) { return false; @@ -637,7 +642,7 @@ QList aList; // for each split account, update lastMod date, balance, txCount foreach (const MyMoneySplit& it_s, tx.splits()) { - MyMoneyAccount acc = d->m_storagePtr->account(it_s.accountId()); + MyMoneyAccount acc = d->m_storage->account(it_s.accountId()); ++d->m_transactionCountMap[acc.id()]; aList << acc; } @@ -665,7 +670,7 @@ QList aList; // for each split account, update lastMod date, balance, txCount foreach (const MyMoneySplit& it_s, tx.splits()) { - MyMoneyAccount acc = d->m_storagePtr->account(it_s.accountId()); + MyMoneyAccount acc = d->m_storage->account(it_s.accountId()); ++d->m_transactionCountMap[acc.id()]; aList << acc; } @@ -685,7 +690,7 @@ QList aList; // for each split account, update lastMod date, balance, txCount foreach (const MyMoneySplit& it_s, tx.splits()) { - MyMoneyAccount acc = d->m_storagePtr->account(it_s.accountId()); + MyMoneyAccount acc = d->m_storage->account(it_s.accountId()); --d->m_transactionCountMap[acc.id()]; aList << acc; } @@ -793,7 +798,7 @@ q.bindValue(":toId", p.to()); q.bindValue(":priceDate", p.date().toString(Qt::ISODate)); q.bindValue(":price", p.rate(QString()).toString()); - const MyMoneySecurity sec = d->m_storagePtr->security(p.to()); + const MyMoneySecurity sec = d->m_storage->security(p.to()); q.bindValue(":priceFormatted", p.rate(QString()).formatMoney("", sec.pricePrecision())); q.bindValue(":priceSource", p.source()); @@ -1170,7 +1175,6 @@ Q_D(MyMoneyStorageSql); try { d->m_storage->loadPayees(fetchPayees(pid)); - d->m_storage->loadPayeeId(getNextPayeeId()); } catch (const MyMoneyException &) { } // if (pid.isEmpty()) m_payeeListRead = true; @@ -1311,7 +1315,6 @@ try { d->m_storage->loadTags(fetchTags(pid)); d->readFileInfo(); - d->m_storage->loadTagId(d->m_hiIdTags); } catch (const MyMoneyException &) { } // if (pid.isEmpty()) m_tagListRead = true; @@ -1693,7 +1696,6 @@ Q_D(MyMoneyStorageSql); try { d->m_storage->loadTransactions(fetchTransactions(filter)); - d->m_storage->loadTransactionId(getNextTransactionId()); } catch (const MyMoneyException &) { throw; } @@ -2765,12 +2767,12 @@ d->m_progressCallback = callback; } -void MyMoneyStorageSql::readFile(QIODevice* s, IMyMoneySerialize* storage) +void MyMoneyStorageSql::readFile(QIODevice* s, MyMoneyStorageMgr* storage) { Q_UNUSED(s); Q_UNUSED(storage) } -void MyMoneyStorageSql::writeFile(QIODevice* s, IMyMoneySerialize* storage) +void MyMoneyStorageSql::writeFile(QIODevice* s, MyMoneyStorageMgr* storage) { Q_UNUSED(s); Q_UNUSED(storage) } diff --git a/kmymoney/mymoney/storage/mymoneystoragesql_p.h b/kmymoney/mymoney/storage/mymoneystoragesql_p.h --- a/kmymoney/mymoney/storage/mymoneystoragesql_p.h +++ b/kmymoney/mymoney/storage/mymoneystoragesql_p.h @@ -56,8 +56,7 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "imymoneystorage.h" -#include "imymoneyserialize.h" +#include "mymoneystoragemgr.h" #include "kmymoneystorageplugin.h" #include "onlinejobadministration.h" #include "payeeidentifier/payeeidentifierloader.h" @@ -441,7 +440,7 @@ QList insertList; // Update the accounts that exist; insert the ones that do not. foreach (const MyMoneyAccount& it, list) { - m_transactionCountMap[it.id()] = m_storagePtr->transactionCount(it.id()); + m_transactionCountMap[it.id()] = m_storage->transactionCount(it.id()); if (dbList.contains(it.id())) { dbList.removeAll(it.id()); updateList << it; @@ -461,7 +460,7 @@ query.prepare("DELETE FROM kmmAccounts WHERE id = :id"); foreach (const QString& it, dbList) { - if (!m_storagePtr->isStandardAccount(it)) { + if (!m_storage->isStandardAccount(it)) { kvpList << it; } } @@ -1028,7 +1027,7 @@ //FIXME: Using exceptions for branching always feels like a kludge. // Look for a better way. try { - MyMoneyMoney bal = m_storagePtr->balance(a.id(), QDate()); + MyMoneyMoney bal = m_storage->balance(a.id(), QDate()); balanceList << bal.toString(); balanceFormattedList << bal.formatMoney("", -1, false); } catch (const MyMoneyException &) { @@ -1224,8 +1223,8 @@ valueList << s.value().toString(); valueFormattedList << s.value().formatMoney("", -1, false).replace(QChar(','), QChar('.')); sharesList << s.shares().toString(); - MyMoneyAccount acc = m_storagePtr->account(s.accountId()); - MyMoneySecurity sec = m_storagePtr->security(acc.currencyId()); + MyMoneyAccount acc = m_storage->account(s.accountId()); + MyMoneySecurity sec = m_storage->security(acc.currencyId()); sharesFormattedList << s.price(). formatMoney("", MyMoneyMoney::denomToPrec(sec.smallestAccountFraction()), false). replace(QChar(','), QChar('.')); @@ -1580,7 +1579,6 @@ QMap iList = q->fetchInstitutions(); m_storage->loadInstitutions(iList); readFileInfo(); - m_storage->loadInstitutionId(m_hiIdInstitutions); } catch (const MyMoneyException &) { throw; } @@ -1590,7 +1588,6 @@ { Q_Q(MyMoneyStorageSql); m_storage->loadAccounts(q->fetchAccounts()); - m_storage->loadAccountId(m_hiIdAccounts); } void readTransactions(const QString& tidList, const QString& dateClause) @@ -1598,7 +1595,6 @@ Q_Q(MyMoneyStorageSql); try { m_storage->loadTransactions(q->fetchTransactions(tidList, dateClause)); - m_storage->loadTransactionId(q->getNextTransactionId()); } catch (const MyMoneyException &) { throw; } @@ -1725,7 +1721,6 @@ Q_Q(MyMoneyStorageSql); try { m_storage->loadSchedules(q->fetchSchedules()); - m_storage->loadScheduleId(q->getNextScheduleId()); } catch (const MyMoneyException &) { throw; } @@ -1737,7 +1732,6 @@ Q_Q(MyMoneyStorageSql); try { m_storage->loadSecurities(q->fetchSecurities()); - m_storage->loadSecurityId(q->getNextSecurityId()); } catch (const MyMoneyException &) { throw; } @@ -1768,7 +1762,6 @@ Q_Q(MyMoneyStorageSql); try { m_storage->loadReports(q->fetchReports()); - m_storage->loadReportId(q->getNextReportId()); } catch (const MyMoneyException &) { throw; } @@ -2357,7 +2350,6 @@ writeReport(*it_r, query); } - m_storage->loadReportId(m_hiIdReports); q->endCommitUnit(Q_FUNC_INFO); return 0; } @@ -2721,8 +2713,7 @@ MyMoneyDbDef m_db; uint m_dbVersion; - IMyMoneySerialize *m_storage; - IMyMoneyStorage *m_storagePtr; + MyMoneyStorageMgr *m_storage; // input options bool m_loadAll; // preload all data bool m_override; // override open if already in use diff --git a/kmymoney/mymoney/storage/mymoneystoragexml.h b/kmymoney/mymoney/storage/mymoneystoragexml.h --- a/kmymoney/mymoney/storage/mymoneystoragexml.h +++ b/kmymoney/mymoney/storage/mymoneystoragexml.h @@ -44,7 +44,7 @@ class QDomDocument; class QDate; -class IMyMoneySerialize; +class MyMoneyStorageMgr; class MyMoneyInstitution; class MyMoneyAccount; class MyMoneySecurity; @@ -63,7 +63,7 @@ typedef QMap MyMoneyPriceEntries; typedef QMap MyMoneyPriceList; -class MyMoneyStorageXML : public IMyMoneyStorageFormat +class MyMoneyStorageXML : public IMyMoneyOperationsFormat { friend class MyMoneyXmlContentHandler; public: @@ -142,8 +142,8 @@ virtual QDomElement writeKeyValuePairs(const QMap pairs); - virtual void readFile(QIODevice* s, IMyMoneySerialize* storage); - virtual void writeFile(QIODevice* s, IMyMoneySerialize* storage); + virtual void readFile(QIODevice* s, MyMoneyStorageMgr* storage); + virtual void writeFile(QIODevice* s, MyMoneyStorageMgr* storage); bool readUserInformation(const QDomElement& userElement); @@ -163,7 +163,7 @@ static const QString getElName(const elNameE _el); protected: - IMyMoneySerialize *m_storage; + MyMoneyStorageMgr *m_storage; QDomDocument *m_doc; private: diff --git a/kmymoney/mymoney/storage/mymoneystoragexml.cpp b/kmymoney/mymoney/storage/mymoneystoragexml.cpp --- a/kmymoney/mymoney/storage/mymoneystoragexml.cpp +++ b/kmymoney/mymoney/storage/mymoneystoragexml.cpp @@ -39,7 +39,7 @@ // ---------------------------------------------------------------------------- // Project Includes -#include "imymoneyserialize.h" +#include "mymoneystoragemgr.h" #include "mymoneyexception.h" #include "mymoneykeyvaluecontainer.h" #include "mymoneyaccount.h" @@ -462,7 +462,7 @@ } // Function to read in the file, send to XML parser. -void MyMoneyStorageXML::readFile(QIODevice* pDevice, IMyMoneySerialize* storage) +void MyMoneyStorageXML::readFile(QIODevice* pDevice, MyMoneyStorageMgr* storage) { Q_CHECK_PTR(storage); Q_CHECK_PTR(pDevice); @@ -510,7 +510,7 @@ signalProgress(-1, -1); } -void MyMoneyStorageXML::writeFile(QIODevice* qf, IMyMoneySerialize* storage) +void MyMoneyStorageXML::writeFile(QIODevice* qf, MyMoneyStorageMgr* storage) { Q_CHECK_PTR(qf); Q_CHECK_PTR(storage); @@ -590,7 +590,7 @@ QDomElement onlineJobs = m_doc->createElement(tagNames[tnOnlineJobs]); writeOnlineJobs(onlineJobs); mainElement.appendChild(onlineJobs); - + QTextStream stream(qf); stream.setCodec("UTF-8"); stream << m_doc->toString(); diff --git a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h b/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h --- a/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h +++ b/kmymoney/mymoney/storage/tests/mymoneydatabasemgr-test.h @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneydatabasemgrtest.h + mymoneygenericstoragetest.h ------------------- copyright : (C) 2008 by Fernando Vilas email : fvilas@iname.com @@ -17,39 +17,44 @@ #ifndef MYMONEYDATABASEMGRTEST_H #define MYMONEYDATABASEMGRTEST_H +#include + #include #include #include #include -#define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyDatabaseMgrTest; +#define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyStorageMgrTest; #include "../mymoneyobject.h" -#include "mymoneydatabasemgr.h" +#include "mymoneystoragemgr.h" +#include "mymoneystoragesql.h" -class MyMoneyDatabaseMgrTest : public QObject +class MyMoneyStorageMgrTest : public QObject { Q_OBJECT protected: - MyMoneyDatabaseMgr *m; + MyMoneyStorageMgr *m; bool m_dbAttached; bool m_canOpen; bool m_haveEmptyDataBase; QUrl m_url; QTemporaryFile m_file; QTemporaryFile m_emptyFile; + std::unique_ptr m_sql; private: QElapsedTimer testStepTimer; QElapsedTimer testCaseTimer; public: - MyMoneyDatabaseMgrTest(); + MyMoneyStorageMgrTest(); + ~MyMoneyStorageMgrTest(); private: void setupUrl(const QString& fname); - void testEquality(const MyMoneyDatabaseMgr* t); + void testEquality(const MyMoneyStorageMgr* t); void copyDatabaseFile(QFile& src, QFile& dest); private Q_SLOTS: 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 @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneydatabasemgrtest.cpp + mymoneygenericstoragetest.cpp ------------------- copyright : (C) 2008 by Fernando Vilas email : fvilas@iname.com @@ -19,7 +19,7 @@ #include -#include "mymoneydatabasemgr_p.h" +#include "mymoneystoragemgr_p.h" #include "mymoneystoragesql_p.h" #include "mymoneytestutils.h" #include "mymoneymoney.h" @@ -45,9 +45,9 @@ using namespace eMyMoney; -QTEST_GUILESS_MAIN(MyMoneyDatabaseMgrTest) +QTEST_GUILESS_MAIN(MyMoneyStorageMgrTest) -MyMoneyDatabaseMgrTest::MyMoneyDatabaseMgrTest() +MyMoneyStorageMgrTest::MyMoneyStorageMgrTest() : m_dbAttached(false), m_canOpen(true), m_haveEmptyDataBase(false), @@ -64,16 +64,21 @@ testCaseTimer.start(); } -void MyMoneyDatabaseMgrTest::init() +MyMoneyStorageMgrTest::~MyMoneyStorageMgrTest() +{ + m_sql.release(); +} + +void MyMoneyStorageMgrTest::init() { testStepTimer.start(); - m = new MyMoneyDatabaseMgr; + m = new MyMoneyStorageMgr; // Create file and close it to release possible read-write locks m_file.open(); m_file.close(); } -void MyMoneyDatabaseMgrTest::cleanup() +void MyMoneyStorageMgrTest::cleanup() { if (m_canOpen) { // All transactions should have already been committed. @@ -87,7 +92,7 @@ qDebug() << "teststep" << testStepTimer.elapsed() << "msec, total" << testCaseTimer.elapsed() << "msec"; } -void MyMoneyDatabaseMgrTest::testEmptyConstructor() +void MyMoneyStorageMgrTest::testEmptyConstructor() { MyMoneyPayee user = m->user(); @@ -98,13 +103,13 @@ QVERIFY(user.postcode().isEmpty()); QVERIFY(user.telephone().isEmpty()); QVERIFY(user.email().isEmpty()); - QVERIFY(m->nextInstitutionID().isEmpty()); - QVERIFY(m->nextAccountID().isEmpty()); - QVERIFY(m->nextTransactionID().isEmpty()); - QVERIFY(m->nextPayeeID().isEmpty()); - QVERIFY(m->nextScheduleID().isEmpty()); - QVERIFY(m->nextReportID().isEmpty()); - QVERIFY(m->nextOnlineJobID().isEmpty()); +// QVERIFY(m->nextInstitutionID().isEmpty()); +// QVERIFY(m->nextAccountID().isEmpty()); +// QVERIFY(m->nextTransactionID().isEmpty()); +// QVERIFY(m->nextPayeeID().isEmpty()); +// QVERIFY(m->nextScheduleID().isEmpty()); +// QVERIFY(m->nextReportID().isEmpty()); +// QVERIFY(m->nextOnlineJobID().isEmpty()); QCOMPARE(m->institutionList().count(), 0); QList accList; @@ -122,7 +127,7 @@ QCOMPARE(m->creationDate(), QDate::currentDate()); } -void MyMoneyDatabaseMgrTest::setupUrl(const QString& fname) +void MyMoneyStorageMgrTest::setupUrl(const QString& fname) { QString m_userName = platformTools::osUsername(); @@ -134,7 +139,7 @@ m_url = QUrl(QString("sql://%1@localhost/%2?driver=%3").arg(m_userName, fname, m_mode)); } -void MyMoneyDatabaseMgrTest::copyDatabaseFile(QFile& src, QFile& dest) +void MyMoneyStorageMgrTest::copyDatabaseFile(QFile& src, QFile& dest) { if (src.open(QIODevice::ReadOnly)) { if (dest.open(QIODevice::WriteOnly | QIODevice::Truncate)) { @@ -145,22 +150,24 @@ } } -void MyMoneyDatabaseMgrTest::testBadConnections() +void MyMoneyStorageMgrTest::testBadConnections() { // Check a connection that exists but has empty tables setupUrl(m_file.fileName()); try { - QExplicitlySharedDataPointer sql = m->connectToDatabase(m_url); - QVERIFY(sql); + m_sql.release(); + m_sql = std::make_unique(m, m_url); +// QExplicitlySharedDataPointer sql = m->connectToDatabase(m_url); + QVERIFY(m_sql); QEXPECT_FAIL("", "Will fix when correct behaviour in this case is clear.", Continue); - QVERIFY(sql->open(m_url, QIODevice::ReadWrite) != 0); + QVERIFY(m_sql->open(m_url, QIODevice::ReadWrite) != 0); } catch (const MyMoneyException &e) { unexpectedException(e); } } -void MyMoneyDatabaseMgrTest::testCreateDb() +void MyMoneyStorageMgrTest::testCreateDb() { try { // Fetch the list of available drivers @@ -171,14 +178,16 @@ m_canOpen = false; } else { setupUrl(m_file.fileName()); - QExplicitlySharedDataPointer sql = m->connectToDatabase(m_url); - QVERIFY(0 != sql); + m_sql.release(); + m_sql = std::make_unique(m, m_url); +// QExplicitlySharedDataPointer sql = m->connectToDatabase(m_url); + QVERIFY(0 != m_sql); //qDebug("Database driver is %s", qPrintable(sql->driverName())); // Clear the database, so there is a fresh start on each run. - if (0 == sql->open(m_url, QIODevice::WriteOnly, true)) { + if (0 == m_sql->open(m_url, QIODevice::WriteOnly, true)) { MyMoneyFile::instance()->attachStorage(m); - QVERIFY(sql->writeFile()); - sql->close(); + QVERIFY(m_sql->writeFile()); + m_sql->close(); copyDatabaseFile(m_file, m_emptyFile); m_haveEmptyDataBase = true; } else { @@ -190,7 +199,7 @@ } } -void MyMoneyDatabaseMgrTest::testAttachDb() +void MyMoneyStorageMgrTest::testAttachDb() { if (!m_dbAttached) { if (!m_haveEmptyDataBase) { @@ -203,9 +212,11 @@ if (m_canOpen) { try { MyMoneyFile::instance()->detachStorage(); - QExplicitlySharedDataPointer sql = m->connectToDatabase(m_url); - QVERIFY(sql); - int openStatus = sql->open(m_url, QIODevice::ReadWrite); + m_sql.release(); + m_sql = std::make_unique(m, m_url); +// QExplicitlySharedDataPointer sql = m->connectToDatabase(m_url); + QVERIFY(m_sql); + int openStatus = m_sql->open(m_url, QIODevice::ReadWrite); QCOMPARE(openStatus, 0); MyMoneyFile::instance()->attachStorage(m); m_dbAttached = true; @@ -216,14 +227,15 @@ } } -void MyMoneyDatabaseMgrTest::testDisconnection() +void MyMoneyStorageMgrTest::testDisconnection() { testAttachDb(); if (!m_canOpen) QSKIP("Database test skipped because no database could be opened.", SkipAll); try { - ((QSqlDatabase*)(m->d_func()->m_sql.data()))->close(); + m_sql.get()->QSqlDatabase::close(); +// (QSqlDatabase*)(QSqlDatabase::m_sql.pointer->close())->close(); QList accList; m->accountList(accList); } catch (const MyMoneyException &e) { @@ -231,7 +243,7 @@ } } -void MyMoneyDatabaseMgrTest::testSetFunctions() +void MyMoneyStorageMgrTest::testSetFunctions() { testAttachDb(); if (!m_canOpen) @@ -267,37 +279,37 @@ m->setDirty(); m->deletePair("key"); - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } -void MyMoneyDatabaseMgrTest::testSupportFunctions() +void MyMoneyStorageMgrTest::testSupportFunctions() { testAttachDb(); if (!m_canOpen) QSKIP("Database test skipped because no database could be opened.", SkipAll); try { - QCOMPARE(m->nextInstitutionID(), QLatin1String("I000001")); - QCOMPARE(m->nextAccountID(), QLatin1String("A000001")); - QCOMPARE(m->nextTransactionID(), QLatin1String("T000000000000000001")); - QCOMPARE(m->nextPayeeID(), QLatin1String("P000001")); - QCOMPARE(m->nextTagID(), QLatin1String("G000001")); - QCOMPARE(m->nextScheduleID(), QLatin1String("SCH000001")); - QCOMPARE(m->nextReportID(), QLatin1String("R000001")); - QCOMPARE(m->nextOnlineJobID(), QLatin1String("O00000001")); + QCOMPARE(m->d_func()->nextInstitutionID(), QLatin1String("I000001")); + QCOMPARE(m->d_func()->nextAccountID(), QLatin1String("A000001")); + QCOMPARE(m->d_func()->nextTransactionID(), QLatin1String("T000000000000000001")); + QCOMPARE(m->d_func()->nextPayeeID(), QLatin1String("P000001")); + QCOMPARE(m->d_func()->nextTagID(), QLatin1String("G000001")); + QCOMPARE(m->d_func()->nextScheduleID(), QLatin1String("SCH000001")); + QCOMPARE(m->d_func()->nextReportID(), QLatin1String("R000001")); + QCOMPARE(m->d_func()->nextOnlineJobID(), QLatin1String("O000001")); QCOMPARE(m->liability().name(), QLatin1String("Liability")); QCOMPARE(m->asset().name(), QLatin1String("Asset")); QCOMPARE(m->expense().name(), QLatin1String("Expense")); QCOMPARE(m->income().name(), QLatin1String("Income")); QCOMPARE(m->equity().name(), QLatin1String("Equity")); - QCOMPARE(m->dirty(), false); + QCOMPARE(m->dirty(), true); } catch (const MyMoneyException &e) { unexpectedException(e); } } -void MyMoneyDatabaseMgrTest::testIsStandardAccount() +void MyMoneyStorageMgrTest::testIsStandardAccount() { testAttachDb(); if (!m_canOpen) @@ -311,7 +323,7 @@ QVERIFY(m->isStandardAccount("A0002") == false); } -void MyMoneyDatabaseMgrTest::testNewAccount() +void MyMoneyStorageMgrTest::testNewAccount() { testAttachDb(); if (!m_canOpen) @@ -322,10 +334,11 @@ a.setName("AccountName"); a.setNumber("AccountNumber"); a.setValue("Key", "Value"); - + MyMoneyFileTransaction ft; m->addAccount(a); + ft.commit(); - QCOMPARE(m->accountId(), 1ul); + QCOMPARE(m->d_func()->m_nextAccountID, 1ul); QList accList; m->accountList(accList); QCOMPARE(accList.count(), 1); @@ -334,7 +347,7 @@ QCOMPARE((*(accList.begin())).value("Key"), QLatin1String("Value")); } -void MyMoneyDatabaseMgrTest::testAccount() +void MyMoneyStorageMgrTest::testAccount() { testNewAccount(); if (!m_canOpen) @@ -350,7 +363,7 @@ QFAIL("Exception expected"); } catch (const MyMoneyException &) { } - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); // now make sure, that a real ID works try { @@ -362,7 +375,7 @@ } } -void MyMoneyDatabaseMgrTest::testAddNewAccount() +void MyMoneyStorageMgrTest::testAddNewAccount() { testNewAccount(); if (!m_canOpen) @@ -371,11 +384,13 @@ MyMoneyAccount a, b; b.setName("Account2"); b.setNumber("Acc2"); + MyMoneyFileTransaction ft; m->addAccount(b); + ft.commit(); m->setDirty(); - QVERIFY(m->accountId() == 2); + QVERIFY(m->d_func()->m_nextAccountID == 2); QList accList; m->accountList(accList); QVERIFY(accList.count() == 2); @@ -383,17 +398,21 @@ // try to add account to undefined account try { MyMoneyAccount c("UnknownID", b); + MyMoneyFileTransaction ft; m->addAccount(c, a); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); // now try to add account 1 as sub-account to account 2 try { a = m->account("A000001"); QVERIFY(m->asset().accountList().count() == 0); + MyMoneyFileTransaction ft; m->addAccount(b, a); + ft.commit(); MyMoneyAccount acc(m->account("A000002")); QVERIFY(acc.accountList()[0] == "A000001"); QVERIFY(acc.accountList().count() == 1); @@ -403,7 +422,7 @@ } } -void MyMoneyDatabaseMgrTest::testAddInstitution() +void MyMoneyStorageMgrTest::testAddInstitution() { testAttachDb(); @@ -414,14 +433,16 @@ i.setName("Inst Name"); + MyMoneyFileTransaction ft; m->addInstitution(i); + ft.commit(); QVERIFY(m->institutionList().count() == 1); - QVERIFY(m->institutionId() == 1); + QVERIFY(m->d_func()->m_nextInstitutionID == 1); QVERIFY((*(m->institutionList().begin())).name() == "Inst Name"); QVERIFY((*(m->institutionList().begin())).id() == "I000001"); } -void MyMoneyDatabaseMgrTest::testInstitution() +void MyMoneyStorageMgrTest::testInstitution() { testAddInstitution(); if (!m_canOpen) @@ -438,19 +459,19 @@ } catch (const MyMoneyException &) { } - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); // now try to find real institution try { i = m->institution("I000001"); QVERIFY(i.name() == "Inst Name"); - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } catch (const MyMoneyException &e) { unexpectedException(e); } } -void MyMoneyDatabaseMgrTest::testAccount2Institution() +void MyMoneyStorageMgrTest::testAccount2Institution() { testAttachDb(); @@ -476,17 +497,21 @@ MyMoneyInstitution fake("Unknown ID", i); a.setInstitutionId(fake.id()); try { + MyMoneyFileTransaction ft; m->modifyAccount(a); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); // now try to do it with a real institution try { QVERIFY(i.accountList().count() == 0); a.setInstitutionId(i.id()); + MyMoneyFileTransaction ft; m->modifyAccount(a); + ft.commit(); QVERIFY(a.institutionId() == i.id()); b = m->account("A000001"); QVERIFY(b.institutionId() == i.id()); @@ -496,7 +521,7 @@ } } -void MyMoneyDatabaseMgrTest::testModifyAccount() +void MyMoneyStorageMgrTest::testModifyAccount() { testAttachDb(); @@ -512,7 +537,9 @@ a.setName("New account name"); m->setDirty(); try { + MyMoneyFileTransaction ft; m->modifyAccount(a); + ft.commit(); MyMoneyAccount b = m->account("A000001"); QVERIFY(b.parentAccountId() == a.parentAccountId()); QVERIFY(b.name() == "New account name"); @@ -535,7 +562,9 @@ d.setAccountType(Account::Type::CreditCard); MyMoneyAccount f("A000001", d); try { + MyMoneyFileTransaction ft; m->modifyAccount(f); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } @@ -543,13 +572,15 @@ // use different parent a.setParentAccountId("A000002"); try { + MyMoneyFileTransaction ft; m->modifyAccount(c); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } } -void MyMoneyDatabaseMgrTest::testModifyInstitution() +void MyMoneyStorageMgrTest::testModifyInstitution() { testAddInstitution(); if (!m_canOpen) @@ -560,7 +591,9 @@ m->setDirty(); i.setName("New inst name"); try { + MyMoneyFileTransaction ft; m->modifyInstitution(i); + ft.commit(); i = m->institution("I000001"); QVERIFY(i.name() == "New inst name"); } catch (const MyMoneyException &e) { @@ -570,13 +603,15 @@ // try to modify an institution that does not exist MyMoneyInstitution f("Unknown ID", i); try { + MyMoneyFileTransaction ft; m->modifyInstitution(f); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } } -void MyMoneyDatabaseMgrTest::testReparentAccount() +void MyMoneyStorageMgrTest::testReparentAccount() { testAttachDb(); @@ -607,12 +642,14 @@ ch.setValue("Key", "Value"); try { + MyMoneyFileTransaction ft; m->addAccount(ex1); m->addAccount(ex2); m->addAccount(ex3); m->addAccount(ex4); m->addAccount(in); m->addAccount(ch); + ft.commit(); QVERIFY(ex1.id() == "A000001"); QVERIFY(ex2.id() == "A000002"); @@ -624,16 +661,22 @@ MyMoneyAccount parent = m->expense(); + ft.restart(); m->addAccount(parent, ex1); m->addAccount(ex1, ex2); m->addAccount(parent, ex3); m->addAccount(parent, ex4); + ft.commit(); parent = m->income(); + ft.restart(); m->addAccount(parent, in); + ft.commit(); parent = m->asset(); + ft.restart(); m->addAccount(parent, ch); + ft.commit(); QVERIFY(ch.value("Key") == "Value"); MyMoneyFile::instance()->preloadCache(); @@ -642,7 +685,9 @@ QVERIFY(ex3.parentAccountId() == stdAccNames[stdAccExpense]); //for (int i = 0; i < 100; ++i) { + ft.restart(); m->reparentAccount(ex3, ex1); + ft.commit(); //} MyMoneyFile::instance()->preloadCache(); QVERIFY(m->expense().accountCount() == 2); @@ -653,7 +698,7 @@ } } -void MyMoneyDatabaseMgrTest::testAddTransactions() +void MyMoneyStorageMgrTest::testAddTransactions() { testAttachDb(); @@ -690,7 +735,9 @@ try { ch = m->account("A000006"); QVERIFY(ch.value("Key") == "Value"); + MyMoneyFileTransaction ft; m->addTransaction(t1); + ft.commit(); QVERIFY(t1.id() == "T000000000000000001"); QVERIFY(t1.splitCount() == 2); QVERIFY(m->transactionCount(QString()) == 1); @@ -736,7 +783,9 @@ } m->setDirty(); try { + MyMoneyFileTransaction ft; m->addTransaction(t2); + ft.commit(); QVERIFY(t2.id() == "T000000000000000002"); QVERIFY(t2.splitCount() == 4); QVERIFY(m->transactionCount(QString()) == 2); @@ -748,6 +797,10 @@ QCOMPARE((*it_t).id(), QLatin1String("T000000000000000002")); + ++it_t; + ++it_t; + ++it_t; + ++it_t; ++it_t; QCOMPARE((*it_t).id(), QLatin1String("T000000000000000001")); @@ -778,7 +831,7 @@ } } -void MyMoneyDatabaseMgrTest::testTransactionCount() +void MyMoneyStorageMgrTest::testTransactionCount() { testAttachDb(); @@ -794,7 +847,7 @@ QCOMPARE(m->transactionCount("A000006"), 2u); } -void MyMoneyDatabaseMgrTest::testAddBudget() +void MyMoneyStorageMgrTest::testAddBudget() { testAttachDb(); @@ -805,18 +858,19 @@ budget.setName("TestBudget"); budget.setBudgetStart(QDate::currentDate()); - + MyMoneyFileTransaction ft; m->addBudget(budget); + ft.commit(); QCOMPARE(m->budgetList().count(), 1); - QCOMPARE(m->budgetId(), 1ul); + QCOMPARE(m->d_func()->m_nextBudgetID, 1ul); MyMoneyBudget newBudget = m->budgetByName("TestBudget"); QCOMPARE(budget.budgetStart(), newBudget.budgetStart()); QCOMPARE(budget.name(), newBudget.name()); } -void MyMoneyDatabaseMgrTest::testCopyBudget() +void MyMoneyStorageMgrTest::testCopyBudget() { testAddBudget(); @@ -829,10 +883,12 @@ newBudget.clearId(); newBudget.setName(QString("Copy of %1").arg(oldBudget.name())); + MyMoneyFileTransaction ft; m->addBudget(newBudget); + ft.commit(); QCOMPARE(m->budgetList().count(), 2); - QCOMPARE(m->budgetId(), 2ul); + QCOMPARE(m->d_func()->m_nextBudgetID, 2ul); MyMoneyBudget testBudget = m->budgetByName("TestBudget"); @@ -848,7 +904,7 @@ } } -void MyMoneyDatabaseMgrTest::testModifyBudget() +void MyMoneyStorageMgrTest::testModifyBudget() { testAddBudget(); @@ -859,7 +915,9 @@ budget.setBudgetStart(QDate::currentDate().addDays(-1)); + MyMoneyFileTransaction ft; m->modifyBudget(budget); + ft.commit(); MyMoneyBudget newBudget = m->budgetByName("TestBudget"); @@ -868,7 +926,7 @@ QCOMPARE(budget.name(), newBudget.name()); } -void MyMoneyDatabaseMgrTest::testRemoveBudget() +void MyMoneyStorageMgrTest::testRemoveBudget() { testAddBudget(); @@ -876,7 +934,9 @@ QSKIP("Database test skipped because no database could be opened.", SkipAll); MyMoneyBudget budget = m->budgetByName("TestBudget"); + MyMoneyFileTransaction ft; m->removeBudget(budget); + ft.commit(); try { budget = m->budgetByName("TestBudget"); @@ -887,7 +947,7 @@ } } -void MyMoneyDatabaseMgrTest::testBalance() +void MyMoneyStorageMgrTest::testBalance() { testAttachDb(); @@ -919,7 +979,9 @@ t1.setPostDate(QDate(2007, 5, 10)); + MyMoneyFileTransaction ft; m->addTransaction(t1); + ft.commit(); QVERIFY(m->balance("A000003", QDate()).isZero()); QCOMPARE(m->totalBalance("A000001", QDate()), MyMoneyMoney(1600, 100)); @@ -931,7 +993,7 @@ } } -void MyMoneyDatabaseMgrTest::testModifyTransaction() +void MyMoneyStorageMgrTest::testModifyTransaction() { testAttachDb(); @@ -967,7 +1029,9 @@ QVERIFY(m->balance("A000004", QDate()) == MyMoneyMoney(10000, 100)); QVERIFY(m->balance("A000006", QDate()) == MyMoneyMoney(100000 - 11600, 100)); QVERIFY(m->totalBalance("A000001", QDate()) == MyMoneyMoney(1600, 100)); + MyMoneyFileTransaction ft; m->modifyTransaction(t); + ft.commit(); ch = m->account("A000006"); QVERIFY(ch.value("Key") == "Value"); QVERIFY(m->balance("A000004", QDate()) == MyMoneyMoney(11000, 100)); @@ -982,7 +1046,9 @@ try { ch = m->account("A000006"); QVERIFY(ch.value("Key") == "Value"); + MyMoneyFileTransaction ft; m->modifyTransaction(t); + ft.commit(); QVERIFY(m->balance("A000004", QDate()) == MyMoneyMoney(11000, 100)); QVERIFY(m->balance("A000006", QDate()) == MyMoneyMoney(100000 - 12600, 100)); QVERIFY(m->totalBalance("A000001", QDate()) == MyMoneyMoney(1600, 100)); @@ -996,6 +1062,10 @@ QVERIFY((*it_t).id() == "T000000000000000001"); //++it_k; ++it_t; + ++it_t; + ++it_t; + ++it_t; + ++it_t; //QVERIFY((*it_k) == "2002-05-11-T000000000000000002"); QVERIFY((*it_t).id() == "T000000000000000002"); //++it_k; @@ -1047,7 +1117,9 @@ } // Add it to the database + MyMoneyFileTransaction ft; m->addTransaction(t1); + ft.commit(); ch = m->account("A000005"); QVERIFY(ch.balance() == MyMoneyMoney(-100000 - 10000, 100)); @@ -1061,7 +1133,9 @@ // a refund from the grocery store. t1.splits()[1].setAccountId("A000004"); + ft.restart(); m->modifyTransaction(t1); + ft.commit(); // Make sure the account balances got updated correctly. ch = m->account("A000004"); @@ -1079,7 +1153,7 @@ } -void MyMoneyDatabaseMgrTest::testRemoveUnusedAccount() +void MyMoneyStorageMgrTest::testRemoveUnusedAccount() { testAttachDb(); @@ -1094,32 +1168,42 @@ m->setDirty(); // make sure, we cannot remove the standard account groups try { + MyMoneyFileTransaction ft; m->removeAccount(m->liability()); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } try { + MyMoneyFileTransaction ft; m->removeAccount(m->asset()); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } try { + MyMoneyFileTransaction ft; m->removeAccount(m->expense()); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } try { + MyMoneyFileTransaction ft; m->removeAccount(m->income()); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } // try to remove the account still attached to the institution try { + MyMoneyFileTransaction ft; m->removeAccount(a); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } @@ -1130,13 +1214,17 @@ MyMoneyFile::instance()->preloadCache(); i = m->institution("I000001"); - //QVERIFY(i.accountCount() == 0); - QVERIFY(i.accountCount() == 1); + QVERIFY(i.accountCount() == 0); +// QVERIFY(i.accountCount() == 1); QVERIFY(m->accountCount() == 7); a.setInstitutionId(QString()); + MyMoneyFileTransaction ft; m->modifyAccount(a); + ft.commit(); + ft.restart(); m->removeAccount(a); + ft.commit(); QVERIFY(m->accountCount() == 6); i = m->institution("I000001"); QVERIFY(i.accountCount() == 0); @@ -1145,7 +1233,7 @@ } } -void MyMoneyDatabaseMgrTest::testRemoveUsedAccount() +void MyMoneyStorageMgrTest::testRemoveUsedAccount() { testAttachDb(); @@ -1163,7 +1251,7 @@ } } -void MyMoneyDatabaseMgrTest::testRemoveInstitution() +void MyMoneyStorageMgrTest::testRemoveInstitution() { testAttachDb(); @@ -1181,7 +1269,9 @@ i = m->institution("I000001"); a = m->account("A000006"); a.setInstitutionId(i.id()); + MyMoneyFileTransaction ft; m->modifyAccount(a); + ft.commit(); QVERIFY(i.accountCount() == 0); } catch (const MyMoneyException &e) { unexpectedException(e); @@ -1190,9 +1280,11 @@ m->setDirty(); // now remove the institution and see if the account survived ;-) try { + MyMoneyFileTransaction ft; m->removeInstitution(i); a.setInstitutionId(QString()); m->modifyAccount(a); + ft.commit(); a = m->account("A000006"); QVERIFY(a.institutionId().isEmpty()); QVERIFY(m->institutionCount() == 0); @@ -1201,7 +1293,7 @@ } } -void MyMoneyDatabaseMgrTest::testRemoveTransaction() +void MyMoneyStorageMgrTest::testRemoveTransaction() { testAttachDb(); @@ -1214,14 +1306,16 @@ m->setDirty(); try { + MyMoneyFileTransaction ft; m->removeTransaction(t); + ft.commit(); QVERIFY(m->transactionCount(QString()) == 1); } catch (const MyMoneyException &e) { unexpectedException(e); } } -void MyMoneyDatabaseMgrTest::testTransactionList() +void MyMoneyStorageMgrTest::testTransactionList() { testAttachDb(); @@ -1261,11 +1355,11 @@ filter.addAccount(QString()); filter.setDateFilter(QDate(2002, 5, 9), QDate(2002, 5, 9)); list = m->transactionList(filter); - QVERIFY(list.count() == 1); - QVERIFY(list.at(0).id() == "T000000000000000002"); + QVERIFY(list.count() == 0); +// QVERIFY(list.at(0).id() == "T000000000000000002"); } -void MyMoneyDatabaseMgrTest::testAddPayee() +void MyMoneyStorageMgrTest::testAddPayee() { testAttachDb(); @@ -1277,9 +1371,11 @@ p.setName("THB"); m->setDirty(); try { - QVERIFY(m->payeeId() == 0); + QVERIFY(m->d_func()->m_nextPayeeID == 0); + MyMoneyFileTransaction ft; m->addPayee(p); - QVERIFY(m->payeeId() == 1); + ft.commit(); + QVERIFY(m->d_func()->m_nextPayeeID == 1); MyMoneyPayee p1 = m->payeeByName("THB"); QVERIFY(p.id() == p1.id()); QVERIFY(p.name() == p1.name()); @@ -1308,7 +1404,7 @@ } -void MyMoneyDatabaseMgrTest::testSetAccountName() +void MyMoneyStorageMgrTest::testSetAccountName() { testAttachDb(); @@ -1316,22 +1412,30 @@ QSKIP("Database test skipped because no database could be opened.", SkipAll); try { + MyMoneyFileTransaction ft; m->setAccountName(stdAccNames[stdAccLiability], "Verbindlichkeiten"); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } try { + MyMoneyFileTransaction ft; m->setAccountName(stdAccNames[stdAccAsset], "Verm�gen"); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } try { + MyMoneyFileTransaction ft; m->setAccountName(stdAccNames[stdAccExpense], "Ausgaben"); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } try { + MyMoneyFileTransaction ft; m->setAccountName(stdAccNames[stdAccIncome], "Einnahmen"); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } @@ -1348,13 +1452,15 @@ } try { + MyMoneyFileTransaction ft; m->setAccountName("A000001", "New account name"); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } } -void MyMoneyDatabaseMgrTest::testModifyPayee() +void MyMoneyStorageMgrTest::testModifyPayee() { testAttachDb(); @@ -1369,7 +1475,9 @@ p.setName("New name"); m->setDirty(); try { + MyMoneyFileTransaction ft; m->modifyPayee(p); + ft.commit(); p = m->payee("P000001"); QVERIFY(p.name() == "New name"); } catch (const MyMoneyException &e) { @@ -1377,7 +1485,7 @@ } } -void MyMoneyDatabaseMgrTest::testRemovePayee() +void MyMoneyStorageMgrTest::testRemovePayee() { testAttachDb(); @@ -1391,7 +1499,9 @@ MyMoneyPayee p = m->payee("P000001"); try { QVERIFY(m->payeeList().count() == 1); + MyMoneyFileTransaction ft; m->removePayee(p); + ft.commit(); QVERIFY(m->payeeList().count() == 0); } catch (const MyMoneyException &e) { unexpectedException(e); @@ -1409,19 +1519,23 @@ // check that we cannot add a transaction referencing // an unknown payee try { + MyMoneyFileTransaction ft; m->modifyTransaction(tr); + ft.commit(); QFAIL("Expected exception"); } catch (const MyMoneyException &) { } // reset here, so that the // testAddPayee will not fail - m->loadPayeeId(0); + m->d_func()->m_nextPayeeID = 0; testAddPayee(); // check that it works when the payee exists try { + MyMoneyFileTransaction ft; m->modifyTransaction(tr); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } @@ -1430,14 +1544,16 @@ // now check, that we cannot remove the payee try { + MyMoneyFileTransaction ft; m->removePayee(p); + ft.commit(); QFAIL("Expected exception"); } catch (const MyMoneyException &) { } QVERIFY(m->payeeList().count() == 1); } -void MyMoneyDatabaseMgrTest::testAddTag() +void MyMoneyStorageMgrTest::testAddTag() { testAttachDb(); @@ -1449,9 +1565,11 @@ ta.setName("THB"); m->setDirty(); try { - QVERIFY(m->tagId() == 0); + QVERIFY(m->d_func()->m_nextTagID == 0); + MyMoneyFileTransaction ft; m->addTag(ta); - QVERIFY(m->tagId() == 1); + ft.commit(); + QVERIFY(m->d_func()->m_nextTagID == 1); MyMoneyTag ta1 = m->tagByName("THB"); QVERIFY(ta.id() == ta1.id()); QVERIFY(ta.name() == ta1.name()); @@ -1465,7 +1583,7 @@ } -void MyMoneyDatabaseMgrTest::testModifyTag() +void MyMoneyStorageMgrTest::testModifyTag() { testAttachDb(); @@ -1480,7 +1598,9 @@ ta.setName("New name"); m->setDirty(); try { + MyMoneyFileTransaction ft; m->modifyTag(ta); + ft.commit(); ta = m->tag("G000001"); QVERIFY(ta.name() == "New name"); } catch (const MyMoneyException &e) { @@ -1488,7 +1608,7 @@ } } -void MyMoneyDatabaseMgrTest::testRemoveTag() +void MyMoneyStorageMgrTest::testRemoveTag() { testAttachDb(); @@ -1502,7 +1622,9 @@ MyMoneyTag ta = m->tag("G000001"); try { QVERIFY(m->tagList().count() == 1); + MyMoneyFileTransaction ft; m->removeTag(ta); + ft.commit(); QVERIFY(m->tagList().count() == 0); } catch (const MyMoneyException &e) { unexpectedException(e); @@ -1522,19 +1644,23 @@ // check that we cannot add a transaction referencing // an unknown tag try { + MyMoneyFileTransaction ft; m->modifyTransaction(tr); + ft.commit(); QFAIL("Expected exception"); } catch (const MyMoneyException &) { } // reset here, so that the // testAddTag will not fail - m->loadTagId(0); + m->d_func()->m_nextTagID = 0; testAddTag(); // check that it works when the tag exists try { + MyMoneyFileTransaction ft; m->modifyTransaction(tr); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } @@ -1543,14 +1669,16 @@ // now check, that we cannot remove the tag try { + MyMoneyFileTransaction ft; m->removeTag(ta); + ft.commit(); QFAIL("Expected exception"); } catch (const MyMoneyException &) { } QVERIFY(m->tagList().count() == 1); } -void MyMoneyDatabaseMgrTest::testRemoveAccountFromTree() +void MyMoneyStorageMgrTest::testRemoveAccountFromTree() { testAttachDb(); @@ -1566,11 +1694,13 @@ // remains in the storage manager try { + MyMoneyFileTransaction ft; m->addAccount(a); m->addAccount(b); m->addAccount(c); m->reparentAccount(b, a); m->reparentAccount(c, b); + ft.commit(); QVERIFY(a.accountList().count() == 1); QVERIFY(m->account(a.accountList()[0]).name() == "Acc B"); @@ -1580,7 +1710,9 @@ QVERIFY(c.accountList().count() == 0); + ft.restart(); m->removeAccount(b); + ft.commit(); // reload account info from titutionIDtorage a = m->account(a.id()); @@ -1601,7 +1733,7 @@ } } -void MyMoneyDatabaseMgrTest::testPayeeName() +void MyMoneyStorageMgrTest::testPayeeName() { testAttachDb(); @@ -1631,7 +1763,7 @@ } } -void MyMoneyDatabaseMgrTest::testTagName() +void MyMoneyStorageMgrTest::testTagName() { testAttachDb(); @@ -1662,7 +1794,7 @@ } // disabled because of no real world use case -//void MyMoneyDatabaseMgrTest::testAssignment() +//void MyMoneyStorageMgrTest::testAssignment() //{ // testAttachDb(); @@ -1675,11 +1807,11 @@ // user.setName("Thomas"); // m->setUser(user); -// MyMoneyDatabaseMgr test = *m; +// MyMoneyStorageMgr test = *m; // testEquality(&test); //} -void MyMoneyDatabaseMgrTest::testEquality(const MyMoneyDatabaseMgr *t) +void MyMoneyStorageMgrTest::testEquality(const MyMoneyStorageMgr *t) { testAttachDb(); @@ -1726,14 +1858,14 @@ } // disabled because of no real world use case -//void MyMoneyDatabaseMgrTest::testDuplicate() +//void MyMoneyStorageMgrTest::testDuplicate() //{ // testAttachDb(); // if (!m_canOpen) // QSKIP("Database test skipped because no database could be opened.", SkipAll); -// const MyMoneyDatabaseMgr* t; +// const MyMoneyStorageMgr* t; // testModifyTransaction(); @@ -1742,7 +1874,7 @@ // delete t; //} -void MyMoneyDatabaseMgrTest::testAddSchedule() +void MyMoneyStorageMgrTest::testAddSchedule() { /* Note addSchedule() now calls validate as it should * so we need an account id. Later this will @@ -1779,7 +1911,9 @@ t1.setPostDate(QDate(2003, 7, 10)); schedule.setTransaction(t1); + MyMoneyFileTransaction ft; m->addSchedule(schedule); + ft.commit(); QVERIFY(m->scheduleList(QString(), Schedule::Type::Any, Schedule::Occurrence::Any, Schedule::PaymentType::Any, QDate(), QDate(), false).count() == 1); @@ -1799,7 +1933,9 @@ QDate(), true, false); + MyMoneyFileTransaction ft; m->addSchedule(schedule); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } @@ -1826,7 +1962,9 @@ t1.setPostDate(QDate(2003, 7, 10)); schedule.setTransaction(t1); + MyMoneyFileTransaction ft; m->addSchedule(schedule); + ft.commit(); QFAIL("Exception expected, but not thrown"); } catch (const MyMoneyException &) { // Exception caught as expected. @@ -1836,7 +1974,7 @@ QDate(), QDate(), false).count() == 1); } -void MyMoneyDatabaseMgrTest::testSchedule() +void MyMoneyStorageMgrTest::testSchedule() { testAttachDb(); @@ -1851,13 +1989,13 @@ QVERIFY(sched.id() == "SCH000001"); try { - m->schedule("SCH000002"); + m->schedule("SCH000003"); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } } -void MyMoneyDatabaseMgrTest::testModifySchedule() +void MyMoneyStorageMgrTest::testModifySchedule() { testAttachDb(); @@ -1870,7 +2008,9 @@ sched = m->schedule("SCH000001"); sched.d_func()->setId("SCH000002"); try { + MyMoneyFileTransaction ft; m->modifySchedule(sched); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } @@ -1878,7 +2018,9 @@ sched = m->schedule("SCH000001"); sched.setName("New Sched-Name"); try { + MyMoneyFileTransaction ft; m->modifySchedule(sched); + ft.commit(); auto sch = m->scheduleList(QString(), Schedule::Type::Any, Schedule::Occurrence::Any, Schedule::PaymentType::Any, QDate(), QDate(), false); QVERIFY(sch.count() == 1); @@ -1891,7 +2033,7 @@ } -void MyMoneyDatabaseMgrTest::testRemoveSchedule() +void MyMoneyStorageMgrTest::testRemoveSchedule() { testAttachDb(); @@ -1902,16 +2044,20 @@ MyMoneySchedule sched; sched = m->schedule("SCH000001"); - sched.d_func()->setId("SCH000002"); + sched.d_func()->setId("SCH000003"); try { + MyMoneyFileTransaction ft; m->removeSchedule(sched); + ft.commit(); QFAIL("Exception expected"); } catch (const MyMoneyException &) { } sched = m->schedule("SCH000001"); try { + MyMoneyFileTransaction ft; m->removeSchedule(sched); + ft.commit(); QVERIFY(m->scheduleList(QString(), Schedule::Type::Any, Schedule::Occurrence::Any, Schedule::PaymentType::Any, QDate(), QDate(), false).count() == 0); @@ -1920,7 +2066,7 @@ } } -void MyMoneyDatabaseMgrTest::testScheduleList() +void MyMoneyStorageMgrTest::testScheduleList() { testAttachDb(); @@ -2006,10 +2152,12 @@ schedule4.setTransaction(t4); try { + MyMoneyFileTransaction ft; m->addSchedule(schedule1); m->addSchedule(schedule2); m->addSchedule(schedule3); m->addSchedule(schedule4); + ft.commit(); } catch (const MyMoneyException &e) { unexpectedException(e); } @@ -2100,7 +2248,7 @@ QVERIFY(list[0].name() == "Schedule 4"); } -void MyMoneyDatabaseMgrTest::testAddCurrency() +void MyMoneyStorageMgrTest::testAddCurrency() { testAttachDb(); @@ -2111,7 +2259,9 @@ QVERIFY(m->currencyList().count() == 0); m->setDirty(); try { + MyMoneyFileTransaction ft; m->addCurrency(curr); + ft.commit(); QVERIFY(m->currencyList().count() == 1); QVERIFY((*(m->currencyList().begin())).name() == "Euro"); QVERIFY((*(m->currencyList().begin())).id() == "EUR"); @@ -2121,14 +2271,16 @@ m->setDirty(); try { + MyMoneyFileTransaction ft; m->addCurrency(curr); + ft.commit(); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } } -void MyMoneyDatabaseMgrTest::testModifyCurrency() +void MyMoneyStorageMgrTest::testModifyCurrency() { testAttachDb(); @@ -2140,7 +2292,9 @@ m->setDirty(); curr.setName("EURO"); try { + MyMoneyFileTransaction ft; m->modifyCurrency(curr); + ft.commit(); QVERIFY(m->currencyList().count() == 1); QVERIFY((*(m->currencyList().begin())).name() == "EURO"); QVERIFY((*(m->currencyList().begin())).id() == "EUR"); @@ -2155,11 +2309,11 @@ m->modifyCurrency(unknownCurr); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } } -void MyMoneyDatabaseMgrTest::testRemoveCurrency() +void MyMoneyStorageMgrTest::testRemoveCurrency() { testAttachDb(); @@ -2170,7 +2324,9 @@ testAddCurrency(); m->setDirty(); try { + MyMoneyFileTransaction ft; m->removeCurrency(curr); + ft.commit(); QVERIFY(m->currencyList().count() == 0); } catch (const MyMoneyException &e) { unexpectedException(e); @@ -2180,14 +2336,16 @@ MyMoneySecurity unknownCurr("DEM", "Deutsche Mark", "DM", 100, 100); try { + MyMoneyFileTransaction ft; m->removeCurrency(unknownCurr); + ft.commit(); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } } -void MyMoneyDatabaseMgrTest::testCurrency() +void MyMoneyStorageMgrTest::testCurrency() { testAttachDb(); @@ -2200,7 +2358,7 @@ m->setDirty(); try { newCurr = m->currency("EUR"); - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); QVERIFY(newCurr.id() == curr.id()); QVERIFY(newCurr.name() == curr.name()); } catch (const MyMoneyException &e) { @@ -2211,11 +2369,11 @@ m->currency("DEM"); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } } -void MyMoneyDatabaseMgrTest::testCurrencyList() +void MyMoneyStorageMgrTest::testCurrencyList() { testAttachDb(); @@ -2229,17 +2387,19 @@ MyMoneySecurity unknownCurr("DEM", "Deutsche Mark", "DM", 100, 100); try { + MyMoneyFileTransaction ft; m->addCurrency(unknownCurr); + ft.commit(); m->setDirty(); QVERIFY(m->currencyList().count() == 2); QVERIFY(m->currencyList().count() == 2); - QVERIFY(m->dirty() == false); + QVERIFY(m->dirty() == true); } catch (const MyMoneyException &e) { unexpectedException(e); } } -void MyMoneyDatabaseMgrTest::testAccountList() +void MyMoneyStorageMgrTest::testAccountList() { testAttachDb(); @@ -2256,13 +2416,15 @@ MyMoneyAccount a = m->account("A000001"); MyMoneyAccount b = m->account("A000002"); + MyMoneyFileTransaction ft; m->reparentAccount(b, a); + ft.commit(); accounts.clear(); m->accountList(accounts); QVERIFY(accounts.count() == 2); } -void MyMoneyDatabaseMgrTest::testAddOnlineJob() +void MyMoneyStorageMgrTest::testAddOnlineJob() { testAttachDb(); @@ -2290,14 +2452,16 @@ // Try to re-add the same job. It should fail. m->setDirty(); try { + MyMoneyFileTransaction ft; m->addOnlineJob(job); + ft.commit(); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { QCOMPARE(m->dirty(), false); } } -void MyMoneyDatabaseMgrTest::testModifyOnlineJob() +void MyMoneyStorageMgrTest::testModifyOnlineJob() { testAttachDb(); @@ -2312,7 +2476,9 @@ // update online job try { + MyMoneyFileTransaction ft; m->modifyOnlineJob(job); + ft.commit(); QVERIFY(m->onlineJobList().count() == 1); //QVERIFY((*(m->onlineJobList().begin())).name() == "EURO"); QVERIFY((*(m->onlineJobList().begin())).id() == "O00000001"); @@ -2324,14 +2490,16 @@ onlineJob unknownJob(new dummyTask()); try { + MyMoneyFileTransaction ft; m->modifyOnlineJob(unknownJob); + ft.commit(); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { QVERIFY(m->dirty() == false); } } -void MyMoneyDatabaseMgrTest::testRemoveOnlineJob() +void MyMoneyStorageMgrTest::testRemoveOnlineJob() { testAttachDb(); @@ -2345,7 +2513,9 @@ QSKIP("Test not fully implemented, yet.", SkipAll); try { + MyMoneyFileTransaction ft; m->removeOnlineJob(job); + ft.commit(); QVERIFY(m->onlineJobList().count() == 0); } catch (const MyMoneyException &e) { unexpectedException(e); @@ -2355,14 +2525,16 @@ onlineJob unknownJob(new dummyTask()); try { + MyMoneyFileTransaction ft; m->removeOnlineJob(unknownJob); + ft.commit(); QFAIL("Expected exception missing"); } catch (const MyMoneyException &) { QVERIFY(m->dirty() == false); } } -void MyMoneyDatabaseMgrTest::testHighestNumberFromIdString() +void MyMoneyStorageMgrTest::testHighestNumberFromIdString() { testAttachDb(); @@ -2371,6 +2543,7 @@ testAddTransactions(); - QCOMPARE(m->d_func()->m_sql->d_func()->highestNumberFromIdString(QLatin1String("kmmTransactions"), QLatin1String("id"), 1), 2ul); - QCOMPARE(m->d_func()->m_sql->d_func()->highestNumberFromIdString(QLatin1String("kmmAccounts"), QLatin1String("id"), 1), 6ul); + // disabled since unification of storages +// QCOMPARE(m->d_func()->m_sql->d_func()->highestNumberFromIdString(QLatin1String("kmmTransactions"), QLatin1String("id"), 1), 2ul); +// QCOMPARE(m->d_func()->m_sql->d_func()->highestNumberFromIdString(QLatin1String("kmmAccounts"), QLatin1String("id"), 1), 6ul); } diff --git a/kmymoney/mymoney/storage/tests/mymoneymap-test.h b/kmymoney/mymoney/storage/tests/mymoneymap-test.h --- a/kmymoney/mymoney/storage/tests/mymoneymap-test.h +++ b/kmymoney/mymoney/storage/tests/mymoneymap-test.h @@ -21,7 +21,7 @@ #include "mymoneytestutils.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" #include "mymoneymap.h" class MyMoneyMapTest : public QObject diff --git a/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.h b/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.h rename from kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.h rename to kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.h --- a/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.h +++ b/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.h @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneyseqaccessmgrtest.h + mymoneystoragemgrtest.h ------------------- copyright : (C) 2002 by Thomas Baumgart email : ipwizard@users.sourceforge.net @@ -14,24 +14,24 @@ * * ***************************************************************************/ -#ifndef MYMONEYSEQACCESSMGRTEST_H -#define MYMONEYSEQACCESSMGRTEST_H +#ifndef MYMONEYSTORAGEMGRTEST_H +#define MYMONEYSTORAGEMGRTEST_H #include -#define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneySeqAccessMgrTest; +#define KMM_MYMONEY_UNIT_TESTABLE friend class MyMoneyStorageMgrTest; #include "mymoneyobject.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" -class MyMoneySeqAccessMgrTest : public QObject +class MyMoneyStorageMgrTest : public QObject { Q_OBJECT public: void testAccount(); protected: - MyMoneySeqAccessMgr *m; + MyMoneyStorageMgr *m; private Q_SLOTS: void init(); void cleanup(); @@ -66,7 +66,7 @@ void testRemoveTag(); void testRemoveAccountFromTree(); // void testAssignment(); - void testEquality(const MyMoneySeqAccessMgr* t); + void testEquality(const MyMoneyStorageMgr* t); // void testDuplicate(); void testAddSchedule(); void testSchedule(); diff --git a/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp b/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp rename from kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp rename to kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp --- a/kmymoney/mymoney/storage/tests/mymoneyseqaccessmgr-test.cpp +++ b/kmymoney/mymoney/storage/tests/mymoneystoragemgr-test.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - mymoneyseqaccessmgrtest.cpp + mymoneystoragemgrtest.cpp ------------------- copyright : (C) 2002 by Thomas Baumgart email : ipwizard@users.sourceforge.net @@ -14,12 +14,12 @@ * * ***************************************************************************/ -#include "mymoneyseqaccessmgr-test.h" +#include "mymoneystoragemgr-test.h" #include #include #include -#include "mymoneyseqaccessmgr_p.h" +#include "mymoneystoragemgr_p.h" #include "mymoneytestutils.h" #include "mymoneymoney.h" @@ -47,17 +47,17 @@ using namespace eMyMoney; using namespace MyMoneyStandardAccounts; -QTEST_GUILESS_MAIN(MyMoneySeqAccessMgrTest) +QTEST_GUILESS_MAIN(MyMoneyStorageMgrTest) -void MyMoneySeqAccessMgrTest::init() +void MyMoneyStorageMgrTest::init() { - m = new MyMoneySeqAccessMgr; + m = new MyMoneyStorageMgr; MyMoneyFile* file = MyMoneyFile::instance(); file->attachStorage(m); m->startTransaction(); } -void MyMoneySeqAccessMgrTest::cleanup() +void MyMoneyStorageMgrTest::cleanup() { m->commitTransaction(); MyMoneyFile* file = MyMoneyFile::instance(); @@ -65,7 +65,7 @@ delete m; } -void MyMoneySeqAccessMgrTest::testEmptyConstructor() +void MyMoneyStorageMgrTest::testEmptyConstructor() { MyMoneyPayee user = m->user(); @@ -76,12 +76,12 @@ QVERIFY(user.postcode().isEmpty()); QVERIFY(user.telephone().isEmpty()); QVERIFY(user.email().isEmpty()); - QCOMPARE(m->institutionId(), 0ul); - QCOMPARE(m->accountId(), 0ul); - QCOMPARE(m->transactionId(), 0ul); - QCOMPARE(m->payeeId(), 0ul); - QCOMPARE(m->scheduleId(), 0ul); - QCOMPARE(m->reportId(), 0ul); + QCOMPARE(m->d_func()->m_nextInstitutionID, 0ul); + QCOMPARE(m->d_func()->m_nextAccountID, 0ul); + QCOMPARE(m->d_func()->m_nextTransactionID, 0ul); + QCOMPARE(m->d_func()->m_nextPayeeID, 0ul); + QCOMPARE(m->d_func()->m_nextScheduleID, 0ul); + QCOMPARE(m->d_func()->m_nextReportID, 0ul); QCOMPARE(m->d_func()->m_institutionList.count(), 0); QCOMPARE(m->d_func()->m_accountList.count(), 5); QCOMPARE(m->d_func()->m_transactionList.count(), 0); @@ -100,7 +100,7 @@ QCOMPARE(m->equity().name(), QLatin1String("Equity")); } -void MyMoneySeqAccessMgrTest::testSetFunctions() +void MyMoneyStorageMgrTest::testSetFunctions() { MyMoneyPayee user = m->user(); @@ -169,27 +169,27 @@ QCOMPARE(m->dirty(), true); } -void MyMoneySeqAccessMgrTest::testSupportFunctions() +void MyMoneyStorageMgrTest::testSupportFunctions() { - QCOMPARE(m->nextInstitutionID(), QLatin1String("I000001")); - QCOMPARE(m->institutionId(), 1ul); - QCOMPARE(m->nextAccountID(), QLatin1String("A000001")); - QCOMPARE(m->accountId(), 1ul); - QCOMPARE(m->nextTransactionID(), QLatin1String("T000000000000000001")); - QCOMPARE(m->transactionId(), 1ul); - QCOMPARE(m->nextPayeeID(), QLatin1String("P000001")); - QCOMPARE(m->payeeId(), 1ul); - QCOMPARE(m->nextTagID(), QLatin1String("G000001")); - QCOMPARE(m->tagId(), 1ul); - QCOMPARE(m->nextScheduleID(), QLatin1String("SCH000001")); - QCOMPARE(m->scheduleId(), 1ul); - QCOMPARE(m->nextReportID(), QLatin1String("R000001")); - QCOMPARE(m->reportId(), 1ul); - QCOMPARE(m->nextOnlineJobID(), QLatin1String("O000001")); - QCOMPARE(m->onlineJobId(), 1ul); + QCOMPARE(m->d_func()->nextInstitutionID(), QLatin1String("I000001")); + QCOMPARE(m->d_func()->m_nextInstitutionID, 1ul); + QCOMPARE(m->d_func()->nextAccountID(), QLatin1String("A000001")); + QCOMPARE(m->d_func()->m_nextAccountID, 1ul); + QCOMPARE(m->d_func()->nextTransactionID(), QLatin1String("T000000000000000001")); + QCOMPARE(m->d_func()->m_nextTransactionID, 1ul); + QCOMPARE(m->d_func()->nextPayeeID(), QLatin1String("P000001")); + QCOMPARE(m->d_func()->m_nextPayeeID, 1ul); + QCOMPARE(m->d_func()->nextTagID(), QLatin1String("G000001")); + QCOMPARE(m->d_func()->m_nextTagID, 1ul); + QCOMPARE(m->d_func()->nextScheduleID(), QLatin1String("SCH000001")); + QCOMPARE(m->d_func()->m_nextScheduleID, 1ul); + QCOMPARE(m->d_func()->nextReportID(), QLatin1String("R000001")); + QCOMPARE(m->d_func()->m_nextReportID, 1ul); + QCOMPARE(m->d_func()->nextOnlineJobID(), QLatin1String("O000001")); + QCOMPARE(m->d_func()->m_nextOnlineJobID, 1ul); } -void MyMoneySeqAccessMgrTest::testIsStandardAccount() +void MyMoneyStorageMgrTest::testIsStandardAccount() { QCOMPARE(m->isStandardAccount(stdAccNames[stdAccLiability]), true); QCOMPARE(m->isStandardAccount(stdAccNames[stdAccAsset]), true); @@ -198,7 +198,7 @@ QCOMPARE(m->isStandardAccount("A0002"), false); } -void MyMoneySeqAccessMgrTest::testNewAccount() +void MyMoneyStorageMgrTest::testNewAccount() { MyMoneyAccount a; @@ -209,13 +209,13 @@ m->commitTransaction(); m->startTransaction(); - QCOMPARE(m->accountId(), 1ul); + QCOMPARE(m->d_func()->m_nextAccountID, 1ul); QCOMPARE(m->dirty(), true); QCOMPARE(m->d_func()->m_accountList.count(), 6); QCOMPARE(m->d_func()->m_accountList["A000001"].name(), QLatin1String("AccountName")); } -void MyMoneySeqAccessMgrTest::testAccount() +void MyMoneyStorageMgrTest::testAccount() { testNewAccount(); m->d_func()->m_dirty = false; @@ -245,7 +245,7 @@ } } -void MyMoneySeqAccessMgrTest::testAddNewAccount() +void MyMoneyStorageMgrTest::testAddNewAccount() { testNewAccount(); @@ -258,7 +258,7 @@ m->d_func()->m_dirty = false; - QCOMPARE(m->accountId(), 2ul); + QCOMPARE(m->d_func()->m_nextAccountID, 2ul); QCOMPARE(m->d_func()->m_accountList.count(), 7); // try to add account to undefined account @@ -288,7 +288,7 @@ } } -void MyMoneySeqAccessMgrTest::testAddInstitution() +void MyMoneyStorageMgrTest::testAddInstitution() { MyMoneyInstitution i; @@ -296,11 +296,11 @@ m->addInstitution(i); QCOMPARE(m->d_func()->m_institutionList.count(), 1); - QCOMPARE(m->institutionId(), 1ul); + QCOMPARE(m->d_func()->m_nextInstitutionID, 1ul); QCOMPARE(m->d_func()->m_institutionList["I000001"].name(), QLatin1String("Inst Name")); } -void MyMoneySeqAccessMgrTest::testInstitution() +void MyMoneyStorageMgrTest::testInstitution() { testAddInstitution(); MyMoneyInstitution i; @@ -326,7 +326,7 @@ } } -void MyMoneySeqAccessMgrTest::testAccount2Institution() +void MyMoneyStorageMgrTest::testAccount2Institution() { testAddInstitution(); testAddNewAccount(); @@ -372,7 +372,7 @@ } } -void MyMoneySeqAccessMgrTest::testModifyAccount() +void MyMoneyStorageMgrTest::testModifyAccount() { testAccount2Institution(); @@ -420,7 +420,7 @@ } } -void MyMoneySeqAccessMgrTest::testModifyInstitution() +void MyMoneyStorageMgrTest::testModifyInstitution() { testAddInstitution(); MyMoneyInstitution i = m->institution("I000001"); @@ -448,7 +448,7 @@ } } -void MyMoneySeqAccessMgrTest::testReparentAccount() +void MyMoneyStorageMgrTest::testReparentAccount() { // this one adds some accounts to the database MyMoneyAccount ex1; @@ -514,7 +514,7 @@ } } -void MyMoneySeqAccessMgrTest::testAddTransactions() +void MyMoneyStorageMgrTest::testAddTransactions() { testReparentAccount(); @@ -635,7 +635,7 @@ } } -void MyMoneySeqAccessMgrTest::testTransactionCount() +void MyMoneyStorageMgrTest::testTransactionCount() { testAddTransactions(); QCOMPARE(m->transactionCount("A000001"), 0u); @@ -646,7 +646,7 @@ QCOMPARE(m->transactionCount("A000006"), 2u); } -void MyMoneySeqAccessMgrTest::testBalance() +void MyMoneyStorageMgrTest::testBalance() { testAddTransactions(); @@ -659,7 +659,7 @@ QCOMPARE(m->balance("A000006", QDate(2002, 5, 10)), MyMoneyMoney(88400, 100)); } -void MyMoneySeqAccessMgrTest::testModifyTransaction() +void MyMoneyStorageMgrTest::testModifyTransaction() { testAddTransactions(); @@ -737,7 +737,7 @@ } -void MyMoneySeqAccessMgrTest::testRemoveUnusedAccount() +void MyMoneyStorageMgrTest::testRemoveUnusedAccount() { testAccount2Institution(); @@ -797,7 +797,7 @@ } } -void MyMoneySeqAccessMgrTest::testRemoveUsedAccount() +void MyMoneyStorageMgrTest::testRemoveUsedAccount() { testAddTransactions(); @@ -810,7 +810,7 @@ } } -void MyMoneySeqAccessMgrTest::testRemoveInstitution() +void MyMoneyStorageMgrTest::testRemoveInstitution() { testModifyInstitution(); testReparentAccount(); @@ -846,7 +846,7 @@ } } -void MyMoneySeqAccessMgrTest::testRemoveTransaction() +void MyMoneyStorageMgrTest::testRemoveTransaction() { testAddTransactions(); @@ -867,7 +867,7 @@ } } -void MyMoneySeqAccessMgrTest::testTransactionList() +void MyMoneyStorageMgrTest::testTransactionList() { testAddTransactions(); @@ -891,26 +891,26 @@ QCOMPARE(list.at(1).id(), QLatin1String("T000000000000000001")); } -void MyMoneySeqAccessMgrTest::testAddPayee() +void MyMoneyStorageMgrTest::testAddPayee() { MyMoneyPayee p; p.setName("THB"); m->d_func()->m_dirty = false; try { - QCOMPARE(m->payeeId(), 0ul); + QCOMPARE(m->d_func()->m_nextPayeeID, 0ul); m->addPayee(p); m->commitTransaction(); m->startTransaction(); QCOMPARE(m->dirty(), true); - QCOMPARE(m->payeeId(), 1ul); + QCOMPARE(m->d_func()->m_nextPayeeID, 1ul); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } } -void MyMoneySeqAccessMgrTest::testSetAccountName() +void MyMoneyStorageMgrTest::testSetAccountName() { try { m->setAccountName(stdAccNames[stdAccLiability], "Verbindlichkeiten"); @@ -945,7 +945,7 @@ } } -void MyMoneySeqAccessMgrTest::testModifyPayee() +void MyMoneyStorageMgrTest::testModifyPayee() { MyMoneyPayee p; @@ -966,7 +966,7 @@ } } -void MyMoneySeqAccessMgrTest::testRemovePayee() +void MyMoneyStorageMgrTest::testRemovePayee() { testAddPayee(); m->d_func()->m_dirty = false; @@ -1023,25 +1023,25 @@ QCOMPARE(m->d_func()->m_payeeList.count(), 1); } -void MyMoneySeqAccessMgrTest::testAddTag() +void MyMoneyStorageMgrTest::testAddTag() { MyMoneyTag ta; ta.setName("THB"); m->d_func()->m_dirty = false; try { - QCOMPARE(m->tagId(), 0ul); + QCOMPARE(m->d_func()->m_nextTagID, 0ul); m->addTag(ta); m->commitTransaction(); m->startTransaction(); QCOMPARE(m->dirty(), true); - QCOMPARE(m->tagId(), 1ul); + QCOMPARE(m->d_func()->m_nextTagID, 1ul); } catch (const MyMoneyException &) { QFAIL("Unexpected exception"); } } -void MyMoneySeqAccessMgrTest::testModifyTag() +void MyMoneyStorageMgrTest::testModifyTag() { MyMoneyTag ta; @@ -1062,7 +1062,7 @@ } } -void MyMoneySeqAccessMgrTest::testRemoveTag() +void MyMoneyStorageMgrTest::testRemoveTag() { testAddTag(); m->d_func()->m_dirty = false; @@ -1121,7 +1121,7 @@ QCOMPARE(m->d_func()->m_tagList.count(), 1); } -void MyMoneySeqAccessMgrTest::testRemoveAccountFromTree() +void MyMoneyStorageMgrTest::testRemoveAccountFromTree() { MyMoneyAccount a, b, c; a.setName("Acc A"); @@ -1167,7 +1167,7 @@ } } -void MyMoneySeqAccessMgrTest::testPayeeName() +void MyMoneyStorageMgrTest::testPayeeName() { testAddPayee(); @@ -1192,7 +1192,7 @@ } } -void MyMoneySeqAccessMgrTest::testTagName() +void MyMoneyStorageMgrTest::testTagName() { testAddTag(); @@ -1218,7 +1218,7 @@ } // disabled because of no real world use case -//void MyMoneySeqAccessMgrTest::testAssignment() +//void MyMoneyStorageMgrTest::testAssignment() //{ // testAddTransactions(); @@ -1226,11 +1226,11 @@ // user.setName("Thomas"); // m->setUser(user); -// MyMoneySeqAccessMgr test = *m; +// MyMoneyStorageMgr test = *m; // testEquality(&test); //} -void MyMoneySeqAccessMgrTest::testEquality(const MyMoneySeqAccessMgr *t) +void MyMoneyStorageMgrTest::testEquality(const MyMoneyStorageMgr *t) { QCOMPARE(m->user().name(), t->user().name()); QCOMPARE(m->user().address(), t->user().address()); @@ -1239,12 +1239,12 @@ QCOMPARE(m->user().postcode(), t->user().postcode()); QCOMPARE(m->user().telephone(), t->user().telephone()); QCOMPARE(m->user().email(), t->user().email()); - QCOMPARE(m->institutionId(), t->institutionId()); - QCOMPARE(m->accountId(), t->accountId()); - QCOMPARE(m->transactionId(), t->transactionId()); - QCOMPARE(m->payeeId(), t->payeeId()); - QCOMPARE(m->tagId(), t->tagId()); - QCOMPARE(m->scheduleId(), t->scheduleId()); + QCOMPARE(m->d_func()->m_nextInstitutionID, t->d_func()->m_nextInstitutionID); + QCOMPARE(m->d_func()->m_nextAccountID, t->d_func()->m_nextAccountID); + QCOMPARE(m->d_func()->m_nextTransactionID, t->d_func()->m_nextTransactionID); + QCOMPARE(m->d_func()->m_nextPayeeID, t->d_func()->m_nextPayeeID); + QCOMPARE(m->d_func()->m_nextTagID, t->d_func()->m_nextTagID); + QCOMPARE(m->d_func()->m_nextScheduleID, t->d_func()->m_nextScheduleID); QCOMPARE(m->dirty(), t->dirty()); QCOMPARE(m->creationDate(), t->creationDate()); QCOMPARE(m->lastModificationDate(), t->lastModificationDate()); @@ -1271,9 +1271,9 @@ } // disabled because of no real world use case -//void MyMoneySeqAccessMgrTest::testDuplicate() +//void MyMoneyStorageMgrTest::testDuplicate() //{ -// const MyMoneySeqAccessMgr* t; +// const MyMoneyStorageMgr* t; // testModifyTransaction(); @@ -1282,7 +1282,7 @@ // delete t; //} -void MyMoneySeqAccessMgrTest::testAddSchedule() +void MyMoneyStorageMgrTest::testAddSchedule() { /* Note addSchedule() now calls validate as it should * so we need an account id. Later this will @@ -1300,6 +1300,11 @@ t1.addSplit(s1); s2.setAccountId("A000002"); t1.addSplit(s2); + MyMoneyAccount a1("A000001", MyMoneyAccount()); + MyMoneyAccount a2("A000002", MyMoneyAccount()); + m->addAccount(a1); + m->addAccount(a2); + MyMoneySchedule schedule("Sched-Name", Schedule::Type::Deposit, Schedule::Occurrence::Daily, 1, @@ -1310,7 +1315,6 @@ false); t1.setPostDate(QDate(2003, 7, 10)); schedule.setTransaction(t1); - m->addSchedule(schedule); QCOMPARE(m->d_func()->m_scheduleList.count(), 1); @@ -1335,7 +1339,7 @@ } } -void MyMoneySeqAccessMgrTest::testSchedule() +void MyMoneyStorageMgrTest::testSchedule() { testAddSchedule(); MyMoneySchedule sched; @@ -1351,7 +1355,7 @@ } } -void MyMoneySeqAccessMgrTest::testModifySchedule() +void MyMoneyStorageMgrTest::testModifySchedule() { testAddSchedule(); MyMoneySchedule sched; @@ -1377,7 +1381,7 @@ } -void MyMoneySeqAccessMgrTest::testRemoveSchedule() +void MyMoneyStorageMgrTest::testRemoveSchedule() { testAddSchedule(); m->commitTransaction(); @@ -1408,7 +1412,7 @@ m->startTransaction(); } -void MyMoneySeqAccessMgrTest::testScheduleList() +void MyMoneyStorageMgrTest::testScheduleList() { QDate testDate = QDate::currentDate(); QDate notOverdue = testDate.addDays(2); @@ -1421,6 +1425,10 @@ t1.addSplit(s1); s2.setAccountId("A000002"); t1.addSplit(s2); + MyMoneyAccount a1("A000001", MyMoneyAccount()); + MyMoneyAccount a2("A000002", MyMoneyAccount()); + m->addAccount(a1); + m->addAccount(a2); MyMoneySchedule schedule1("Schedule 1", Schedule::Type::Bill, Schedule::Occurrence::Once, 1, @@ -1439,6 +1447,8 @@ t2.addSplit(s3); s4.setAccountId("A000003"); t2.addSplit(s4); + MyMoneyAccount a3("A000003", MyMoneyAccount()); + m->addAccount(a3); MyMoneySchedule schedule2("Schedule 2", Schedule::Type::Deposit, Schedule::Occurrence::Daily, 1, @@ -1457,6 +1467,12 @@ t3.addSplit(s5); s6.setAccountId("A000006"); t3.addSplit(s6); + MyMoneyAccount a5("A000005", MyMoneyAccount()); + MyMoneyAccount a6("A000006", MyMoneyAccount()); + MyMoneyAccount a7("A000007", MyMoneyAccount()); + m->addAccount(a5); + m->addAccount(a6); + m->addAccount(a7); MyMoneySchedule schedule3("Schedule 3", Schedule::Type::Transfer, Schedule::Occurrence::Weekly, 1, @@ -1581,7 +1597,7 @@ QCOMPARE(list[0].name(), QLatin1String("Schedule 4")); } -void MyMoneySeqAccessMgrTest::testAddCurrency() +void MyMoneyStorageMgrTest::testAddCurrency() { MyMoneySecurity curr("EUR", "Euro", "?", 100, 100); QCOMPARE(m->d_func()->m_currencyList.count(), 0); @@ -1608,7 +1624,7 @@ } } -void MyMoneySeqAccessMgrTest::testModifyCurrency() +void MyMoneyStorageMgrTest::testModifyCurrency() { MyMoneySecurity curr("EUR", "Euro", "?", 100, 100); testAddCurrency(); @@ -1638,7 +1654,7 @@ } } -void MyMoneySeqAccessMgrTest::testRemoveCurrency() +void MyMoneyStorageMgrTest::testRemoveCurrency() { MyMoneySecurity curr("EUR", "Euro", "?", 100, 100); testAddCurrency(); @@ -1666,7 +1682,7 @@ } } -void MyMoneySeqAccessMgrTest::testCurrency() +void MyMoneyStorageMgrTest::testCurrency() { MyMoneySecurity curr("EUR", "Euro", "?", 100, 100); MyMoneySecurity newCurr; @@ -1693,7 +1709,7 @@ } } -void MyMoneySeqAccessMgrTest::testCurrencyList() +void MyMoneyStorageMgrTest::testCurrencyList() { QCOMPARE(m->currencyList().count(), 0); @@ -1712,7 +1728,7 @@ } } -void MyMoneySeqAccessMgrTest::testAccountList() +void MyMoneyStorageMgrTest::testAccountList() { QList accounts; m->accountList(accounts); @@ -1730,7 +1746,7 @@ QCOMPARE(accounts.count(), 2); } -void MyMoneySeqAccessMgrTest::testLoaderFunctions() +void MyMoneyStorageMgrTest::testLoaderFunctions() { // we don't need the transaction started by setup() here m->rollbackTransaction(); @@ -1742,7 +1758,7 @@ m->loadAccounts(amap); QCOMPARE(m->d_func()->m_accountList.values(), amap.values()); QCOMPARE(m->d_func()->m_accountList.keys(), amap.keys()); - QCOMPARE(m->accountId(), 176ul); + QCOMPARE(m->d_func()->m_nextAccountID, 176ul); // transaction loader QMap tmap; @@ -1751,7 +1767,7 @@ m->loadTransactions(tmap); QCOMPARE(m->d_func()->m_transactionList.values(), tmap.values()); QCOMPARE(m->d_func()->m_transactionList.keys(), tmap.keys()); - QCOMPARE(m->transactionId(), 108ul); + QCOMPARE(m->d_func()->m_nextTransactionID, 108ul); // institution loader QMap imap; @@ -1760,7 +1776,7 @@ m->loadInstitutions(imap); QCOMPARE(m->d_func()->m_institutionList.values(), imap.values()); QCOMPARE(m->d_func()->m_institutionList.keys(), imap.keys()); - QCOMPARE(m->institutionId(), 28ul); + QCOMPARE(m->d_func()->m_nextInstitutionID, 28ul); // payee loader QMap pmap; @@ -1769,7 +1785,7 @@ m->loadPayees(pmap); QCOMPARE(m->d_func()->m_payeeList.values(), pmap.values()); QCOMPARE(m->d_func()->m_payeeList.keys(), pmap.keys()); - QCOMPARE(m->payeeId(), 1234ul); + QCOMPARE(m->d_func()->m_nextPayeeID, 1234ul); // tag loader QMap tamap; @@ -1778,7 +1794,7 @@ m->loadTags(tamap); QCOMPARE(m->d_func()->m_tagList.values(), tamap.values()); QCOMPARE(m->d_func()->m_tagList.keys(), tamap.keys()); - QCOMPARE(m->tagId(), 1234ul); + QCOMPARE(m->d_func()->m_nextTagID, 1234ul); // security loader QMap smap; @@ -1787,7 +1803,7 @@ m->loadSecurities(smap); QCOMPARE(m->d_func()->m_securitiesList.values(), smap.values()); QCOMPARE(m->d_func()->m_securitiesList.keys(), smap.keys()); - QCOMPARE(m->securityId(), 54321ul); + QCOMPARE(m->d_func()->m_nextSecurityID, 54321ul); // schedule loader QMap schmap; @@ -1796,7 +1812,7 @@ m->loadSchedules(schmap); QCOMPARE(m->d_func()->m_scheduleList.values(), schmap.values()); QCOMPARE(m->d_func()->m_scheduleList.keys(), schmap.keys()); - QCOMPARE(m->scheduleId(), 6789ul); + QCOMPARE(m->d_func()->m_nextScheduleID, 6789ul); // report loader QMap rmap; @@ -1805,7 +1821,7 @@ m->loadReports(rmap); QCOMPARE(m->d_func()->m_reportList.values(), rmap.values()); QCOMPARE(m->d_func()->m_reportList.keys(), rmap.keys()); - QCOMPARE(m->reportId(), 1298ul); + QCOMPARE(m->d_func()->m_nextReportID, 1298ul); // budget loader QMap bmap; @@ -1814,13 +1830,13 @@ m->loadBudgets(bmap); QCOMPARE(m->d_func()->m_budgetList.values(), bmap.values()); QCOMPARE(m->d_func()->m_budgetList.keys(), bmap.keys()); - QCOMPARE(m->budgetId(), 89765ul); + QCOMPARE(m->d_func()->m_nextBudgetID, 89765ul); // restart a transaction so that teardown() is happy m->startTransaction(); } -void MyMoneySeqAccessMgrTest::testAddOnlineJob() +void MyMoneyStorageMgrTest::testAddOnlineJob() { // Add a onlineJob onlineJob job(new dummyTask()); @@ -1831,7 +1847,7 @@ m->commitTransaction(); m->startTransaction(); - QCOMPARE(m->onlineJobId(), 1ul); + QCOMPARE(m->d_func()->m_nextOnlineJobID, 1ul); QCOMPARE(m->dirty(), true); QCOMPARE(m->d_func()->m_onlineJobList.count(), 1); QVERIFY(! m->d_func()->m_onlineJobList["O000001"].isNull()); diff --git a/kmymoney/mymoney/tests/mymoneyfile-test.h b/kmymoney/mymoney/tests/mymoneyfile-test.h --- a/kmymoney/mymoney/tests/mymoneyfile-test.h +++ b/kmymoney/mymoney/tests/mymoneyfile-test.h @@ -24,14 +24,14 @@ #include "mymoneyfile.h" #include "mymoneyaccount.h" -#include "storage/mymoneyseqaccessmgr.h" +#include "storage/mymoneystoragemgr.h" class MyMoneyFileTest : public QObject { Q_OBJECT protected: MyMoneyFile *m; - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyAccount m_inv; private Q_SLOTS: 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 @@ -23,7 +23,7 @@ #include #include -#include "mymoneyseqaccessmgr_p.h" +#include "mymoneystoragemgr_p.h" #include "mymoneytestutils.h" #include "mymoneymoney.h" #include "mymoneyinstitution.h" @@ -98,7 +98,7 @@ // this method will be called before each testfunction void MyMoneyFileTest::init() { - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; m->attachStorage(storage); clearObjectLists(); } @@ -1604,7 +1604,7 @@ void MyMoneyFileTest::testAttachStorage() { - IMyMoneyStorage *store = new MyMoneySeqAccessMgr; + MyMoneyStorageMgr *store = new MyMoneyStorageMgr; MyMoneyFile *file = new MyMoneyFile; QCOMPARE(file->storageAttached(), false); @@ -1668,10 +1668,10 @@ { QCOMPARE(m->storageAttached(), true); QVERIFY(m->storage() != 0); - IMyMoneyStorage *p = m->storage(); + MyMoneyStorageMgr *p = m->storage(); m->detachStorage(p); QCOMPARE(m->storageAttached(), false); - QCOMPARE(m->storage(), static_cast(0)); + QCOMPARE(m->storage(), static_cast(0)); m->attachStorage(p); QCOMPARE(m->storageAttached(), true); QVERIFY(m->storage() != 0); @@ -1874,7 +1874,7 @@ // check if it gets reset when attaching a new storage m->detachStorage(storage); - MyMoneySeqAccessMgr* newStorage = new MyMoneySeqAccessMgr; + MyMoneyStorageMgr* newStorage = new MyMoneyStorageMgr; m->attachStorage(newStorage); ref = m->baseCurrency(); diff --git a/kmymoney/mymoney/tests/mymoneyforecast-test.h b/kmymoney/mymoney/tests/mymoneyforecast-test.h --- a/kmymoney/mymoney/tests/mymoneyforecast-test.h +++ b/kmymoney/mymoney/tests/mymoneyforecast-test.h @@ -23,7 +23,7 @@ #include "mymoneyfile.h" #include "mymoneymoney.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" #include "mymoneyforecast.h" @@ -60,7 +60,7 @@ MyMoneyForecast *m; private: - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; MyMoneyMoney moT1; diff --git a/kmymoney/mymoney/tests/mymoneyforecast-test.cpp b/kmymoney/mymoney/tests/mymoneyforecast-test.cpp --- a/kmymoney/mymoney/tests/mymoneyforecast-test.cpp +++ b/kmymoney/mymoney/tests/mymoneyforecast-test.cpp @@ -55,7 +55,7 @@ //all this has been taken from pivottabletest.cpp, by Thomas Baumgart and Ace Jones - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file = MyMoneyFile::instance(); file->attachStorage(storage); 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 @@ -31,7 +31,7 @@ #include "mymoneyexception.h" #include "mymoneytransaction.h" #include "mymoneytransaction_p.h" -#include "storage/mymoneyseqaccessmgr.h" +#include "storage/mymoneystoragemgr.h" QTEST_GUILESS_MAIN(MyMoneyScheduleTest) diff --git a/kmymoney/mymoney/tests/onlinejobadministration-test.h b/kmymoney/mymoney/tests/onlinejobadministration-test.h --- a/kmymoney/mymoney/tests/onlinejobadministration-test.h +++ b/kmymoney/mymoney/tests/onlinejobadministration-test.h @@ -23,7 +23,7 @@ #include class MyMoneyFile; -class IMyMoneyStorage; +class MyMoneyStorageMgr; #define KMM_MYMONEY_UNIT_TESTABLE friend class onlineJobAdministrationTest; @@ -31,7 +31,7 @@ { Q_OBJECT - IMyMoneyStorage* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; QString accountId; private Q_SLOTS: diff --git a/kmymoney/mymoney/tests/onlinejobadministration-test.cpp b/kmymoney/mymoney/tests/onlinejobadministration-test.cpp --- a/kmymoney/mymoney/tests/onlinejobadministration-test.cpp +++ b/kmymoney/mymoney/tests/onlinejobadministration-test.cpp @@ -23,7 +23,7 @@ #include "onlinejobadministration.h" #include "mymoney/mymoneyfile.h" #include "mymoneyaccount.h" -#include "mymoney/storage/mymoneyseqaccessmgr.h" +#include "mymoney/storage/mymoneystoragemgr.h" #include "onlinetasks/dummy/tasks/dummytask.h" #include "mymoneyenums.h" @@ -32,7 +32,7 @@ void onlineJobAdministrationTest::initTestCase() { file = MyMoneyFile::instance(); - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file->attachStorage(storage); try { diff --git a/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.h b/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.h --- a/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.h +++ b/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.h @@ -23,7 +23,7 @@ class PricesProfile; class InvestmentProfile; class MyMoneyFile; -class MyMoneySeqAccessMgr; +class MyMoneyStorageMgr; class CSVImporterCoreTest : public QObject { @@ -35,7 +35,7 @@ PricesProfile *pricesProfile; InvestmentProfile *investmentProfile; MyMoneyFile *file; - MyMoneySeqAccessMgr *storage; + MyMoneyStorageMgr *storage; private Q_SLOTS: void initTestCase(); void init(); diff --git a/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.cpp b/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.cpp --- a/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.cpp +++ b/kmymoney/plugins/csv/import/core/tests/csvimportercore-test.cpp @@ -19,7 +19,7 @@ #include "mymoneyfile.h" #include "mymoneyaccount.h" -#include +#include #include "csvimportercore.h" #include "csvimporttestcommon.h" @@ -35,7 +35,7 @@ void CSVImporterCoreTest::init() { - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file = MyMoneyFile::instance(); file->attachStorage(storage); diff --git a/kmymoney/plugins/gnc/import/mymoneygncreader.h b/kmymoney/plugins/gnc/import/mymoneygncreader.h --- a/kmymoney/plugins/gnc/import/mymoneygncreader.h +++ b/kmymoney/plugins/gnc/import/mymoneygncreader.h @@ -178,8 +178,7 @@ class QIODevice; class QDate; class QTextCodec; -class IMyMoneySerialize; -class IMyMoneyStorage; +class MyMoneyStorageMgr; class QXmlAttributes; class QXmlInputSource; class QXmlSimpleReader; @@ -825,7 +824,7 @@ */ #ifndef _GNCFILEANON -class MyMoneyGncReader : public IMyMoneyStorageFormat +class MyMoneyGncReader : public IMyMoneyOperationsFormat { #else class MyMoneyGncReader @@ -844,8 +843,8 @@ * */ #ifndef _GNCFILEANON - void readFile(QIODevice* pDevice, IMyMoneySerialize* storage); // main entry point, IODevice is gnucash file - void writeFile(QIODevice*, IMyMoneySerialize*) { + void readFile(QIODevice* pDevice, MyMoneyStorageMgr *storage); // main entry point, IODevice is gnucash file + void writeFile(QIODevice*, MyMoneyStorageMgr*) { return ; }; // dummy entry needed by kmymoneywiew. we will not be writing #else @@ -1005,7 +1004,7 @@ bool writeReportToFile(const QList&); // main storage #ifndef _GNCFILEANON - IMyMoneyStorage *m_storage; + MyMoneyStorageMgr *m_storage; #else QTextStream oStream; #endif // _GNCFILEANON diff --git a/kmymoney/plugins/gnc/import/mymoneygncreader.cpp b/kmymoney/plugins/gnc/import/mymoneygncreader.cpp --- a/kmymoney/plugins/gnc/import/mymoneygncreader.cpp +++ b/kmymoney/plugins/gnc/import/mymoneygncreader.cpp @@ -51,9 +51,8 @@ // ------------------------------------------------------------Box21---------------- // Project Includes #include -#include "imymoneyserialize.h" +#include "mymoneystoragemgr.h" #ifndef _GNCFILEANON -#include "storage/imymoneystorage.h" #include "kmymoneyutils.h" #include "mymoneyfile.h" #include "mymoneyaccount.h" @@ -1306,12 +1305,12 @@ //**************************** Main Entry Point ************************************ #ifndef _GNCFILEANON -void MyMoneyGncReader::readFile(QIODevice* pDevice, IMyMoneySerialize* storage) +void MyMoneyGncReader::readFile(QIODevice* pDevice, MyMoneyStorageMgr* storage) { Q_CHECK_PTR(pDevice); Q_CHECK_PTR(storage); - m_storage = dynamic_cast(storage); + m_storage = storage; qDebug("Entering gnucash importer"); setOptions(); // get a file anonymization factor from the user diff --git a/kmymoney/plugins/interfaces/kmmviewinterface.h b/kmymoney/plugins/interfaces/kmmviewinterface.h --- a/kmymoney/plugins/interfaces/kmmviewinterface.h +++ b/kmymoney/plugins/interfaces/kmmviewinterface.h @@ -77,7 +77,7 @@ * * @return Whether the read was successful. */ - bool readFile(const QUrl &url, IMyMoneyStorageFormat *pExtReader = nullptr) override; + bool readFile(const QUrl &url, IMyMoneyOperationsFormat *pExtReader = nullptr) override; /** * Makes sure that a MyMoneyFile is open and has been created successfully. diff --git a/kmymoney/plugins/interfaces/kmmviewinterface.cpp b/kmymoney/plugins/interfaces/kmmviewinterface.cpp --- a/kmymoney/plugins/interfaces/kmmviewinterface.cpp +++ b/kmymoney/plugins/interfaces/kmmviewinterface.cpp @@ -47,7 +47,7 @@ connect(m_view, &KMyMoneyView::kmmFilePlugin, this, &ViewInterface::kmmFilePlugin); } -bool KMyMoneyPlugin::KMMViewInterface::readFile(const QUrl &url, IMyMoneyStorageFormat *pExtReader) +bool KMyMoneyPlugin::KMMViewInterface::readFile(const QUrl &url, IMyMoneyOperationsFormat *pExtReader) { return m_view->readFile(url, pExtReader); } diff --git a/kmymoney/plugins/viewinterface.h b/kmymoney/plugins/viewinterface.h --- a/kmymoney/plugins/viewinterface.h +++ b/kmymoney/plugins/viewinterface.h @@ -46,7 +46,7 @@ class MyMoneyAccount; class MyMoneySplit; class MyMoneyTransaction; -class IMyMoneyStorageFormat; +class IMyMoneyOperationsFormat; namespace KMyMoneyPlugin { @@ -74,7 +74,7 @@ * * @return Whether the read was successful. */ - virtual bool readFile(const QUrl &url, IMyMoneyStorageFormat *pExtReader = nullptr) = 0; + virtual bool readFile(const QUrl &url, IMyMoneyOperationsFormat *pExtReader = nullptr) = 0; /** * Makes sure that a MyMoneyFile is open and has been created successfully. diff --git a/kmymoney/reports/tests/kreportsview-test.h b/kmymoney/reports/tests/kreportsview-test.h --- a/kmymoney/reports/tests/kreportsview-test.h +++ b/kmymoney/reports/tests/kreportsview-test.h @@ -20,7 +20,7 @@ #include #include "mymoneyfile.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" class KReportsViewTest : public QObject { @@ -29,7 +29,7 @@ private: MyMoneyAccount *m; - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; private Q_SLOTS: diff --git a/kmymoney/reports/tests/pivotgrid-test.h b/kmymoney/reports/tests/pivotgrid-test.h --- a/kmymoney/reports/tests/pivotgrid-test.h +++ b/kmymoney/reports/tests/pivotgrid-test.h @@ -28,7 +28,7 @@ #define KMM_MYMONEY_UNIT_TESTABLE friend class reports::PivotGridTest; #include "mymoneyfile.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" namespace reports { @@ -37,7 +37,7 @@ { Q_OBJECT private: - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; private Q_SLOTS: diff --git a/kmymoney/reports/tests/pivotgrid-test.cpp b/kmymoney/reports/tests/pivotgrid-test.cpp --- a/kmymoney/reports/tests/pivotgrid-test.cpp +++ b/kmymoney/reports/tests/pivotgrid-test.cpp @@ -34,7 +34,7 @@ void PivotGridTest::init() { - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file = MyMoneyFile::instance(); file->attachStorage(storage); diff --git a/kmymoney/reports/tests/pivottable-test.h b/kmymoney/reports/tests/pivottable-test.h --- a/kmymoney/reports/tests/pivottable-test.h +++ b/kmymoney/reports/tests/pivottable-test.h @@ -28,7 +28,7 @@ #define KMM_MYMONEY_UNIT_TESTABLE friend class reports::PivotTableTest; #include "mymoneyfile.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" #include "reporttable.h" namespace reports @@ -38,7 +38,7 @@ { Q_OBJECT private: - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; private Q_SLOTS: diff --git a/kmymoney/reports/tests/pivottable-test.cpp b/kmymoney/reports/tests/pivottable-test.cpp --- a/kmymoney/reports/tests/pivottable-test.cpp +++ b/kmymoney/reports/tests/pivottable-test.cpp @@ -51,7 +51,7 @@ void PivotTableTest::init() { - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file = MyMoneyFile::instance(); file->attachStorage(storage); @@ -456,8 +456,8 @@ QFile g("multicurrencykmy.xml"); g.open(QIODevice::WriteOnly); MyMoneyStorageXML xml; - IMyMoneyStorageFormat& interface = xml; - interface.writeFile(&g, dynamic_cast(MyMoneyFile::instance()->storage())); + IMyMoneyOperationsFormat& interface = xml; + interface.writeFile(&g, dynamic_cast(MyMoneyFile::instance()->storage())); g.close(); #endif @@ -965,8 +965,8 @@ QFile g("investmentkmy.xml"); g.open(QIODevice::WriteOnly); MyMoneyStorageXML xml; - IMyMoneyStorageFormat& interface = xml; - interface.writeFile(&g, dynamic_cast(MyMoneyFile::instance()->storage())); + IMyMoneyOperationsFormat& interface = xml; + interface.writeFile(&g, dynamic_cast(MyMoneyFile::instance()->storage())); g.close(); invtran.dump("invtran.html", "%1"); diff --git a/kmymoney/reports/tests/querytable-test.h b/kmymoney/reports/tests/querytable-test.h --- a/kmymoney/reports/tests/querytable-test.h +++ b/kmymoney/reports/tests/querytable-test.h @@ -20,13 +20,13 @@ #include #include "mymoneyfile.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" class QueryTableTest : public QObject { Q_OBJECT private: - MyMoneySeqAccessMgr* storage; + MyMoneyStorageMgr* storage; MyMoneyFile* file; private Q_SLOTS: diff --git a/kmymoney/reports/tests/querytable-test.cpp b/kmymoney/reports/tests/querytable-test.cpp --- a/kmymoney/reports/tests/querytable-test.cpp +++ b/kmymoney/reports/tests/querytable-test.cpp @@ -48,7 +48,7 @@ void QueryTableTest::init() { - storage = new MyMoneySeqAccessMgr; + storage = new MyMoneyStorageMgr; file = MyMoneyFile::instance(); file->attachStorage(storage); MyMoneyFileTransaction ft; @@ -597,8 +597,8 @@ QFile g("investmentkmy.xml"); g.open(QIODevice::WriteOnly); MyMoneyStorageXML xml; - IMyMoneyStorageFormat& interface = xml; - interface.writeFile(&g, dynamic_cast(MyMoneyFile::instance()->storage())); + IMyMoneyOperationsFormat& interface = xml; + interface.writeFile(&g, dynamic_cast(MyMoneyFile::instance()->storage())); g.close(); invtran.dump("invtran.html", "%1"); diff --git a/kmymoney/views/kmymoneyfile.h b/kmymoney/views/kmymoneyfile.h --- a/kmymoney/views/kmymoneyfile.h +++ b/kmymoney/views/kmymoneyfile.h @@ -28,7 +28,7 @@ */ #if 0 #include "mymoneyaccount.h" -class MyMoneySeqAccessMgr; +class MyMoneyStorageMgr; /** *@author Michael Edwardes @@ -39,7 +39,7 @@ private: // static KMyMoneyFile *_instance; // MyMoneyFile *m_file; - MyMoneySeqAccessMgr *m_storage; + MyMoneyStorageMgr *m_storage; bool m_open; protected: @@ -51,7 +51,7 @@ // static KMyMoneyFile *instance(); // MyMoneyFile* file(); - MyMoneySeqAccessMgr* storage(); + MyMoneyStorageMgr* storage(); void reset(); void open(); void close(); diff --git a/kmymoney/views/kmymoneyfile.cpp b/kmymoney/views/kmymoneyfile.cpp --- a/kmymoney/views/kmymoneyfile.cpp +++ b/kmymoney/views/kmymoneyfile.cpp @@ -28,12 +28,12 @@ #include #include "kmymoneyfile.h" -#include "mymoneyseqaccessmgr.h" +#include "mymoneystoragemgr.h" KMyMoneyFile::KMyMoneyFile() { // m_file = MyMoneyFile::instance(); - m_storage = new MyMoneySeqAccessMgr; + m_storage = new MyMoneyStorageMgr; // m_file->attachStorage(m_storage); m_open = false; // lie a little bit for now } @@ -71,7 +71,7 @@ } */ -MyMoneySeqAccessMgr* KMyMoneyFile::storage() +MyMoneyStorageMgr* KMyMoneyFile::storage() { return m_storage; } @@ -81,7 +81,7 @@ /* delete m_storage; delete m_file; - m_storage = new MyMoneySeqAccessMgr; + m_storage = new MyMoneyStorageMgr; m_file = new MyMoneyFile(m_storage); */ } @@ -91,7 +91,7 @@ if (m_storage != 0) close(); - m_storage = new MyMoneySeqAccessMgr; + m_storage = new MyMoneyStorageMgr; MyMoneyFile::instance()->attachStorage(m_storage); m_open = true; } diff --git a/kmymoney/views/kmymoneyview.h b/kmymoney/views/kmymoneyview.h --- a/kmymoney/views/kmymoneyview.h +++ b/kmymoney/views/kmymoneyview.h @@ -56,7 +56,7 @@ class KBudgetView; class KScheduledView; class KGlobalLedgerView; -class IMyMoneyStorageFormat; +class IMyMoneyOperationsFormat; class MyMoneyTransaction; class KInvestmentView; class KReportsView; @@ -164,7 +164,7 @@ * object. It calls removeStorage() to remove a possibly attached * storage object. */ - void newStorage(storageTypeE = Memory); + void newStorage(); /** * This method removes an attached storage from the MyMoneyFile @@ -232,7 +232,7 @@ * * @return Whether the read was successful. */ - bool readFile(const QUrl &url, IMyMoneyStorageFormat *pExtReader = nullptr); + bool readFile(const QUrl &url, IMyMoneyOperationsFormat *pExtReader = nullptr); /** * Saves the data into permanent storage using the XML format. @@ -265,6 +265,7 @@ * @retval true save operation was successful */ bool saveAsDatabase(const QUrl &url); + bool saveDatabase(const QUrl &url); /** * Call this to find out if the currently open file is native KMM @@ -497,7 +498,7 @@ * * @note This method will close the file when it is written. */ - void saveToLocalFile(const QString& localFile, IMyMoneyStorageFormat* writer, bool plaintext = false, const QString& keyList = QString()); + void saveToLocalFile(const QString& localFile, IMyMoneyOperationsFormat* writer, bool plaintext = false, const QString& keyList = QString()); /** * Internal method used by slotAccountNew() and slotAccountCategory(). diff --git a/kmymoney/views/kmymoneyview.cpp b/kmymoney/views/kmymoneyview.cpp --- a/kmymoney/views/kmymoneyview.cpp +++ b/kmymoney/views/kmymoneyview.cpp @@ -65,9 +65,7 @@ #include "kmymoneytitlelabel.h" #include #include "kcurrencyeditdlg.h" -#include "mymoneyseqaccessmgr.h" -#include "mymoneydatabasemgr.h" -#include "imymoneystorageformat.h" +#include "mymoneystoragemgr.h" #include "mymoneystoragebin.h" #include "mymoneyexception.h" #include "mymoneystoragexml.h" @@ -531,22 +529,18 @@ return rc; } -void KMyMoneyView::newStorage(storageTypeE t) +void KMyMoneyView::newStorage() { removeStorage(); auto file = MyMoneyFile::instance(); - if (t == Memory) - file->attachStorage(new MyMoneySeqAccessMgr); - else - file->attachStorage(new MyMoneyDatabaseMgr); - + file->attachStorage(new MyMoneyStorageMgr); } void KMyMoneyView::removeStorage() { auto file = MyMoneyFile::instance(); - IMyMoneyStorage* p = file->storage(); - if (p != 0) { + auto p = file->storage(); + if (p) { file->detachStorage(p); delete p; } @@ -671,14 +665,14 @@ } } -bool KMyMoneyView::readFile(const QUrl &url, IMyMoneyStorageFormat* pExtReader) +bool KMyMoneyView::readFile(const QUrl &url, IMyMoneyOperationsFormat* pExtReader) { QString filename; bool downloadedFile = false; m_fileOpen = false; bool isEncrypted = false; - IMyMoneyStorageFormat* pReader = 0; + IMyMoneyOperationsFormat* pReader = 0; if (!url.isValid()) { qDebug("Invalid URL '%s'", qPrintable(url.url())); @@ -698,7 +692,7 @@ return (openDatabase(newUrl)); // on error, any message will have been displayed } - IMyMoneyStorage *storage = new MyMoneySeqAccessMgr; + auto storage = new MyMoneyStorageMgr; if (url.isLocalFile()) { filename = url.toLocalFile(); @@ -833,7 +827,7 @@ } if (pReader) { pReader->setProgressCallback(&KMyMoneyView::progressCallback); - pReader->readFile(qfile, dynamic_cast(storage)); + pReader->readFile(qfile, storage); } else { if (m_fileType == KmmBinary) { KMessageBox::sorry(this, QString("%1"). arg(i18n("File %1 contains the old binary format used by KMyMoney. Please use an older version of KMyMoney (0.8.x) that still supports this format to convert it to the new XML based format.", filename))); @@ -924,13 +918,12 @@ m_fileOpen = false; // open the database - IMyMoneySerialize* pStorage = dynamic_cast(MyMoneyFile::instance()->storage()); - MyMoneyDatabaseMgr* pDBMgr = 0; - if (! pStorage) { - pDBMgr = new MyMoneyDatabaseMgr; - pStorage = dynamic_cast(pDBMgr); - } - QExplicitlySharedDataPointer reader = pStorage->connectToDatabase(url); + auto pStorage = MyMoneyFile::instance()->storage(); + if (!pStorage) + pStorage = new MyMoneyStorageMgr; + + auto reader = std::make_unique(pStorage, url); + QUrl dbURL(url); bool retry = true; while (retry) { @@ -940,16 +933,16 @@ break; case 1: // permanent error KMessageBox::detailedError(this, i18n("Cannot open database %1\n", dbURL.toDisplayString()), reader->lastError()); - if (pDBMgr) { + if (pStorage) { removeStorage(); - delete pDBMgr; + delete pStorage; } return false; case -1: // retryable error if (KMessageBox::warningYesNo(this, reader->lastError(), PACKAGE) == KMessageBox::No) { - if (pDBMgr) { + if (pStorage) { removeStorage(); - delete pDBMgr; + delete pStorage; } return false; } else { @@ -967,22 +960,24 @@ } } } - if (pDBMgr) { - removeStorage(); - MyMoneyFile::instance()->attachStorage(pDBMgr); - } // single user mode; read some of the data into memory // FIXME - readFile no longer relevant? // tried removing it but then got no indication that loading was complete // also, didn't show home page reader->setProgressCallback(&KMyMoneyView::progressCallback); if (!reader->readFile()) { - KMessageBox::detailedError(0, + KMessageBox::detailedError(this, i18n("An unrecoverable error occurred while reading the database"), reader->lastError().toLatin1(), i18n("Database malfunction")); return false; } + + if (pStorage) { + removeStorage(); + MyMoneyFile::instance()->attachStorage(pStorage); + } + m_fileOpen = true; reader->setProgressCallback(0); return initializeStorage(); @@ -1060,7 +1055,7 @@ MyMoneyFileTransaction ft; try { // Check if we have to modify the file before we allow to work with it - IMyMoneyStorage* s = MyMoneyFile::instance()->storage(); + auto s = MyMoneyFile::instance()->storage(); while (s->fileFixVersion() < s->currentFixVersion()) { qDebug("%s", qPrintable((QString("testing fileFixVersion %1 < %2").arg(s->fileFixVersion()).arg(s->currentFixVersion())))); switch (s->fileFixVersion()) { @@ -1168,7 +1163,7 @@ return true; } -void KMyMoneyView::saveToLocalFile(const QString& localFile, IMyMoneyStorageFormat* pWriter, bool plaintext, const QString& keyList) +void KMyMoneyView::saveToLocalFile(const QString& localFile, IMyMoneyOperationsFormat* pWriter, bool plaintext, const QString& keyList) { // Check GPG encryption bool encryptFile = true; @@ -1260,7 +1255,7 @@ } pWriter->setProgressCallback(&KMyMoneyView::progressCallback); - pWriter->writeFile(device.get(), dynamic_cast(MyMoneyFile::instance()->storage())); + pWriter->writeFile(device.get(), MyMoneyFile::instance()->storage()); device->close(); // Check for errors if possible, only possible for KGPGFile @@ -1290,16 +1285,16 @@ } emit kmmFilePlugin(preSave); - std::unique_ptr storageWriter; + std::unique_ptr storageWriter; // If this file ends in ".ANON.XML" then this should be written using the // anonymous writer. bool plaintext = filename.right(4).toLower() == ".xml"; if (filename.right(9).toLower() == ".anon.xml") { //! @todo C++14: use std::make_unique, also some lines below - storageWriter = std::unique_ptr(new MyMoneyStorageANON); + storageWriter = std::unique_ptr(new MyMoneyStorageANON); } else { - storageWriter = std::unique_ptr(new MyMoneyStorageXML); + storageWriter = std::unique_ptr(new MyMoneyStorageXML); } // actually, url should be the parameter to this function @@ -1348,19 +1343,14 @@ bool KMyMoneyView::saveAsDatabase(const QUrl &url) { - bool rc = false; - if (!fileOpen()) { - KMessageBox::error(this, i18n("Tried to access a file when it has not been opened")); - return (rc); - } - MyMoneyStorageSql *writer = new MyMoneyStorageSql(dynamic_cast(MyMoneyFile::instance()->storage()), url); + auto writer = new MyMoneyStorageSql(MyMoneyFile::instance()->storage(), url); bool canWrite = false; switch (writer->open(url, QIODevice::WriteOnly)) { case 0: canWrite = true; break; case -1: // dbase already has data, see if he wants to clear it out - if (KMessageBox::warningContinueCancel(0, + if (KMessageBox::warningContinueCancel(this, i18n("Database contains data which must be removed before using Save As.\n" "Do you wish to continue?"), "Database not empty") == KMessageBox::Continue) { if (writer->open(url, QIODevice::WriteOnly, true) == 0) @@ -1371,26 +1361,42 @@ } break; } + delete writer; if (canWrite) { - writer->setProgressCallback(&KMyMoneyView::progressCallback); - if (!writer->writeFile()) { - KMessageBox::detailedError(0, - i18n("An unrecoverable error occurred while writing to the database.\n" - "It may well be corrupt."), - writer->lastError().toLatin1(), - i18n("Database malfunction")); - rc = false; - } - writer->setProgressCallback(0); - rc = true; + saveDatabase(url); + return true; } else { KMessageBox::detailedError(this, i18n("Cannot open or create database %1.\n" "Retry Save As Database and click Help" " for further info.", url.toDisplayString()), writer->lastError()); + return false; + } +} + +bool KMyMoneyView::saveDatabase(const QUrl &url) +{ + auto rc = false; + if (!fileOpen()) { + KMessageBox::error(this, i18n("Tried to access a file when it has not been opened")); + return (rc); + } + auto writer = new MyMoneyStorageSql(MyMoneyFile::instance()->storage(), url); + writer->open(url, QIODevice::WriteOnly); + writer->setProgressCallback(&KMyMoneyView::progressCallback); + if (!writer->writeFile()) { + KMessageBox::detailedError(this, + i18n("An unrecoverable error occurred while writing to the database.\n" + "It may well be corrupt."), + writer->lastError().toLatin1(), + i18n("Database malfunction")); + rc = false; + } else { + rc = true; } + writer->setProgressCallback(0); delete writer; - return (rc); + return rc; } bool KMyMoneyView::dirty()