Move XML read methods to storage plugin
ClosedPublic

Authored by wojnilowicz on Jul 1 2018, 4:37 PM.

Details

Summary

This is a step in XML encapsulation direction. Because overall it's a big undertaking, only read methods from mymoneystoragexml has been moved. Save methods will follow later. Because it's an error prone undertaking, old read methods have been left untouched for a quick and transparent testing. MyMoneyObjects are loaded in mymoneystoragexml as follows:
*1) using old way (constructor accepting QDomElement),

  1. using new way (static read methods in mymoneystoragexml),

*3) returned object from old and new way are compared and inequality is signaled in terminal,
*4) returned object from old way is discarded and object from new way is going further,

*only for testing, will be removed with underlying code in the accepted patch

Test Plan

All tests pass.

Diff Detail

Repository
R261 KMyMoney
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
wojnilowicz requested review of this revision.Jul 1 2018, 4:37 PM
wojnilowicz created this revision.
tbaumgart requested changes to this revision.Jul 10 2018, 6:18 PM

Did you ever thought about using Q_ENUM? See https://woboq.com/blog/q_enum.html for some details. It looks cleaner if it can be used.

Besides that, I needed the following patch to compile the change:

diff --git a/kmymoney/plugins/views/onlinejoboutbox/onlinejobmodel.cpp b/kmymoney/plugins/views/onlinejoboutbox/onlinejobmodel.cpp
index 69a964a7..c8f6d337 100644
--- a/kmymoney/plugins/views/onlinejoboutbox/onlinejobmodel.cpp
+++ b/kmymoney/plugins/views/onlinejoboutbox/onlinejobmodel.cpp
@@ -144,11 +144,11 @@ QVariant onlineJobModel::data(const QModelIndex & index, int role) const
         return Icons::get(Icon::TaskOngoing);
 
       switch (job.bankAnswerState()) {
-        case onlineJob::acceptedByBank: return Icons::get(Icon::TaskComplete);
-        case onlineJob::sendingError:
-        case onlineJob::abortedByUser:
-        case onlineJob::rejectedByBank: return Icons::get(Icon::TaskReject);
-        case onlineJob::noBankAnswer: break;
+        case eMyMoney::OnlineJob::sendingState::acceptedByBank: return Icons::get(Icon::TaskComplete);
+        case eMyMoney::OnlineJob::sendingState::sendingError:
+        case eMyMoney::OnlineJob::sendingState::abortedByUser:
+        case eMyMoney::OnlineJob::sendingState::rejectedByBank: return Icons::get(Icon::TaskReject);
+        case eMyMoney::OnlineJob::sendingState::noBankAnswer: break;
       }
       if (job.sendDate().isValid()) {
         return Icons::get(Icon::TaskAccepted);
@@ -160,11 +160,11 @@ QVariant onlineJobModel::data(const QModelIndex & index, int role) const
         return i18n("Job is being processed at the moment.");
 
       switch (job.bankAnswerState()) {
-        case onlineJob::acceptedByBank: return i18nc("Arg 1 is a date/time", "This job was accepted by the bank on %1.", job.bankAnswerDate().toString(Qt::DefaultLocaleShortDate));
-        case onlineJob::sendingError: return i18nc("Arg 1 is a date/time", "Sending this job failed (tried on %1).", job.sendDate().toString(Qt::DefaultLocaleShortDate));
-        case onlineJob::abortedByUser: return i18n("Sending this job was manually aborted.");
-        case onlineJob::rejectedByBank: return i18nc("Arg 1 is a date/time", "The bank rejected this job on %1.", job.bankAnswerDate().toString(Qt::DefaultLocaleShortDate));
-        case onlineJob::noBankAnswer:
+        case eMyMoney::OnlineJob::sendingState::acceptedByBank: return i18nc("Arg 1 is a date/time", "This job was accepted by the bank on %1.", job.bankAnswerDate().toString(Qt::DefaultLocaleShortDate));
+        case eMyMoney::OnlineJob::sendingState::sendingError: return i18nc("Arg 1 is a date/time", "Sending this job failed (tried on %1).", job.sendDate().toString(Qt::DefaultLocaleShortDate));
+        case eMyMoney::OnlineJob::sendingState::abortedByUser: return i18n("Sending this job was manually aborted.");
+        case eMyMoney::OnlineJob::sendingState::rejectedByBank: return i18nc("Arg 1 is a date/time", "The bank rejected this job on %1.", job.bankAnswerDate().toString(Qt::DefaultLocaleShortDate));
+        case eMyMoney::OnlineJob::sendingState::noBankAnswer:
           if (job.sendDate().isValid())
             return i18nc("Arg 1 is a date/time", "The bank accepted this job on %1.", job.sendDate().toString(Qt::DefaultLocaleShortDate));
           else if (!job.isValid())
This revision now requires changes to proceed.Jul 10 2018, 6:18 PM

Did you ever thought about using Q_ENUM? See https://woboq.com/blog/q_enum.html for some details. It looks cleaner if it can be used.

I believe it needs a class with Q_OBJECT and probably would require some more includes in headers, so I don't want to switch to it now.

tbaumgart requested changes to this revision.Jul 11 2018, 3:29 PM

Did you ever thought about using Q_ENUM? See https://woboq.com/blog/q_enum.html for some details. It looks cleaner if it can be used.

I believe it needs a class with Q_OBJECT and probably would require some more includes in headers, so I don't want to switch to it now.

Ah, that could well be, since it relies on the QMetaObject stuff.

In case I load a file with this patch, the Update all accounts button is grayed out. This works OK on master with the same file. Can you please check all actions once you have fixed this?

This revision now requires changes to proceed.Jul 11 2018, 3:29 PM

Did you ever thought about using Q_ENUM? See https://woboq.com/blog/q_enum.html for some details. It looks cleaner if it can be used.

I believe it needs a class with Q_OBJECT and probably would require some more includes in headers, so I don't want to switch to it now.

Ah, that could well be, since it relies on the QMetaObject stuff.

In case I load a file with this patch, the Update all accounts button is grayed out. This works OK on master with the same file. Can you please check all actions once you have fixed this?

I cannot reproduce your issue. Update all accounts button isn't grayed out in my case. Could you provide a test case?

I used File/Dump memory with master and D13831 and here is the difference after loading the file


Since the provider is empty because it is missing in version D13831, the return value of MyMoneyAccount::hasOnlineMapping() in KMyMoneyApp::Private::canUpdateAllAccounts() returns false for all accounts, the return value of canUpdateAllAccounts() is also false.

Does this make any difference?

tbaumgart accepted this revision as: tbaumgart.Jul 14 2018, 7:29 AM

Yes it does.

This revision was not accepted when it landed; it landed in state Needs Review.Jul 14 2018, 12:00 PM
This revision was automatically updated to reflect the committed changes.