[Kmymoney-devel] Trying to understand the code in GroupMarker::paintRegisterCell()

Thomas Baumgart thb at net-bembel.de
Fri Nov 25 14:43:40 UTC 2011


Hi,

on Friday 25 November 2011 08:49:27 Cristian Oneț wrote:

> 2011/11/25 Marko Käning <mk-lists at email.de>:
> > Hi Alvaro,
> > 
> > always great to hear from you! :-)
> > 
> >> that's because it's KXConfig stuff.
> >> 
> >> The code is autogenerated from the kmymoney settings file.
> > 
> > I see.
> > 
> >> What do you want to do with it?
> > 
> > As my feature request https://bugs.kde.org/show_bug.cgi?id=287494
> > describes, I would like to have the group marker for "Online Statement
> > Balance: %.2f" change its background and font color depending on whether
> > the online balance is equal to the local one or not. I.e. I'd rather be
> > alerted by a red group marker if there is a difference in both balances.
> > 
> > The motivation behind it is that I had a every now and then a difference
> > in the two balances which stayed unnoticed for quite a few weeks, simply
> > because the numbers were different only in one digit, usually stg like
> > 50 EUR or so. This can happen if there are older transactions which get
> > delivered by the bank with too big a lag, so that KMyMoney doesn't
> > import it anymore by default. Sometimes I myself messed up without
> > noticing it as well.
> > 
> > To find the cause of such balance differences can sometimes be quite a
> > PITA, I tell you! :-(
> > 
> > Therefore an early alerting of the user by KMyMoney itself would be a
> > nice feature for me. :-)
> > 
> > After posting my feature request I thought I dig a little into the code
> > and perhaps figure out how to implement this myself. It took me a while
> > to figure out which methods were responsible for those group markers,
> > but I was still in good spirits… Now that I see you writing about
> > generated code I see my hopes waning, though, because I am afraid I
> > won't be able to get anything done without more substantial knowledge of
> > QT, KDE and the like.
> 
> You should not give up that easily. Your feature request seems
> alright, after all the application should provide the user with all
> information which he needs. You can find the auto generated code in
> the build directory if you need to take a look at it.
> 
> > Anyway, still, one can always learn and skimming through KMM's code is
> > always an interesting endeavor, so, if you're willing to share a little
> > knowledge about how one could achieve this, I'd be very grateful,
> > Alvaro. :-)
> 
> To implement this you don't really need to know about KConfig unless
> you want to make the "balance mismatch" color user configurable.
> 
> bool bBalanceDoesNotMatch = condition // only for the online statement
> balance group marker
> 
> option.palette.setColor(QPalette::Base, bBalanceDoesNotMatch ?
> KMyMoneyGlobalSettings::listErronousTransactionColor() :
> KMyMoneyGlobalSettings::groupMarkerColor());

A few more hints from the author:

the detection if the balances (online and KMyMoney) should be done in 
Register::addGroupMarkers(void). You can use MyMoneyFile::balance(accId, date) 
to get the balance for the date in question from the engine. The actual 
expression would be:

  MyMoneyMoney accBalance = MyMoneyFile::instance()->balance(m_account.id(),
    QDate::fromString(m_account.value("lastImportedTransactionDate"));

Once you created the StatementMarker object, you could add a method to set if 
it is erroneous or not. S.th. like:

   KMyMoneyRegister::StatementGroupMarker *p = new 
KMyMoneyRegister::StatementGroupMarker(this, ..., txt);
   p->setErroneous(balance != accBalance);

balance in this case is already computed with the current code. That's how I 
would implement it. YMMV.


-- 

Regards

Thomas Baumgart

GPG-FP: E55E D592 F45F 116B 8429   4F99 9C59 DB40 B75D D3BA
-------------------------------------------------------------
Any sufficiently advanced bug is indistinguishable from a feature.
(Rich Kulawiec)
-------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 225 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20111125/f32d4847/attachment.sig>


More information about the KMyMoney-devel mailing list