From kde-commits Sun Jan 26 10:53:19 2014 From: Allan Anderson Date: Sun, 26 Jan 2014 10:53:19 +0000 To: kde-commits Subject: [kmymoney] kmymoney: BUG:319801 - Fix losing track of check number if check number sequence is inter Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=139073361432342 Git commit 1dede8b9dfb550b3a26e4fc0ade208788c877b2c by Allan Anderson. Committed on 26/01/2014 at 10:49. Pushed by allananderson into branch 'master'. BUG:319801 - Fix losing track of check number if check number sequence is i= nterrupted. REVIEW:115302 M +16 -8 kmymoney/dialogs/transactioneditor.cpp M +7 -1 kmymoney/dialogs/transactioneditor.h M +14 -0 kmymoney/kmymoneyutils.cpp M +6 -0 kmymoney/kmymoneyutils.h http://commits.kde.org/kmymoney/1dede8b9dfb550b3a26e4fc0ade208788c877b2c diff --git a/kmymoney/dialogs/transactioneditor.cpp b/kmymoney/dialogs/tran= sactioneditor.cpp index 26e7672..3c148d8 100644 --- a/kmymoney/dialogs/transactioneditor.cpp +++ b/kmymoney/dialogs/transactioneditor.cpp @@ -605,14 +605,7 @@ bool TransactionEditor::enterTransactions(QString& new= Id, bool askForSchedule, b t =3D (*it_ts); = // if a new transaction has a valid number, keep it with the a= ccount - QString number; - if (!(*it_ts).splits().isEmpty()) - number =3D (*it_ts).splits().front().number(); - if (!number.isEmpty()) { - m_account.setValue("lastNumberUsed", number); - file->modifyAccount(m_account); - } - + keepNewNumber((*it_ts)); } else { // turn object creation on, so that moving the focus does // not screw up the dialog that might be popping up @@ -627,6 +620,9 @@ bool TransactionEditor::enterTransactions(QString& newI= d, bool askForSchedule, b emit lastPostDateUsed((*it_ts).postDate()); } else { // modify existing transaction + // its number might have been edited + // bearing in mind it could contain alpha characters + keepNewNumber((*it_ts)); file->modifyTransaction(*it_ts); } } @@ -722,6 +718,18 @@ bool TransactionEditor::enterTransactions(QString& new= Id, bool askForSchedule, b return storeTransactions; } = +void TransactionEditor::keepNewNumber(const MyMoneyTransaction& tr) +{ + MyMoneyFile* file =3D MyMoneyFile::instance(); + if (!tr.splits().isEmpty()) { + const quint64 num64 =3D KMyMoneyUtils::numericPart(tr.splits().front()= .number()); + if (num64 > 0) { + m_account.setValue("lastNumberUsed", tr.splits().front().number()); + file->modifyAccount(m_account); + } + } +} + void TransactionEditor::resizeForm(void) { // force resizeing of the columns in the form diff --git a/kmymoney/dialogs/transactioneditor.h b/kmymoney/dialogs/transa= ctioneditor.h index 25705a0..db86832 100644 --- a/kmymoney/dialogs/transactioneditor.h +++ b/kmymoney/dialogs/transactioneditor.h @@ -310,8 +310,14 @@ protected: KMyMoneyRegister::Action m_initialAction; bool m_openEditSplits; bool m_memoChanged; -}; = + private: + /** + * If a new or an edited transaction has a valid number, keep it with th= e account + */ + void keepNewNumber(const MyMoneyTransaction& tr); + +}; = class StdTransactionEditor : public TransactionEditor { diff --git a/kmymoney/kmymoneyutils.cpp b/kmymoney/kmymoneyutils.cpp index 7058557..e89528e 100644 --- a/kmymoney/kmymoneyutils.cpp +++ b/kmymoney/kmymoneyutils.cpp @@ -374,6 +374,20 @@ QString KMyMoneyUtils::nextCheckNumber(const MyMoneyAc= count& acc) return number; } = +quint64 KMyMoneyUtils::numericPart(const QString & num) +{ + quint64 num64 =3D 0; + QRegExp exp(QString("(.*\\D)?(0*)(\\d+)(\\D.*)?")); + if (exp.indexIn(num) !=3D -1) { + QString arg1 =3D exp.cap(1); + QString arg2 =3D exp.cap(2); + QString arg3 =3D QString::number(exp.cap(3).toULongLong()); + QString arg4 =3D exp.cap(4); + num64 =3D QString("%2%3").arg(arg2).arg(arg3).toULongLong(); + } + return num64; +} + QString KMyMoneyUtils::reconcileStateToString(MyMoneySplit::reconcileFlagE= flag, bool text) { QString txt; diff --git a/kmymoney/kmymoneyutils.h b/kmymoney/kmymoneyutils.h index f64a55e..a899121 100644 --- a/kmymoney/kmymoneyutils.h +++ b/kmymoney/kmymoneyutils.h @@ -353,6 +353,12 @@ public: static QString nextCheckNumber(const MyMoneyAccount& acc); = /** + * remove any non-numeric characters from check number + * to allow validity check + */ + static quint64 numericPart(const QString & num); + + /** * Returns the text representing the reconcile flag. If @a text is @p t= rue * then the full text will be returned otherwise a short form (usually = one character). */