question on finding account id from name

Jack ostroffjh at users.sourceforge.net
Wed Jun 22 17:11:28 BST 2022


On 6/22/22 12:07, Thomas Baumgart via KMyMoney-devel wrote:
> On Mittwoch, 22. Juni 2022 16:10:26 CEST Jack via KMyMoney-devel wrote:
>> On 6/22/22 02:18, Thomas Baumgart via KMyMoney-devel wrote:
>>> On Dienstag, 21. Juni 2022 22:46:35 CEST Jack via KMyMoney-devel wrote:
>>>> I'm trying to find an way to easily switch between an investment
>>>> account and it's brokerage account.  I have figured out how to test for
>>>> the two types of accounts (testing the .accountType() or looking for "
>>>> (Brokerage)" at the end of the name.)  However, I don't see any way to
>>>> look up an account by name.  Does this actually require looping through
>>>> all accounts and testing if the name matches?
>>> In master you can do this:
>>>
>>>     QString accountName;
>>>     auto account = MyMoneyFile::instance()->accountsModel()->itemByName(accountName);
>>>
>>>     or if you want to stick with the model type access to the data:
>>>
>>>     auto idx = MyMoneyFile::instance()->accountsModel()->indexByName(accountName);
>>>     auto name = idx.data(eMyMoney::Model::AccountNameRole).toString();
>>>
>>> which in fact does the looping for you in AccountsModel::indexListByName().
>>>
>>> Hope that helps.
>> Thanks.  Either of those is shorter than what I came up with, although
>> mine does seem to work (looking with gdb.)
>>
>> My current problem is that I'm trying to add a "go to brokerage" line
>> after the "go to account" and "go to payee" menu choices, but it is not
>> appearing in any of the menus (either main menu or context menu.)  I
>> can't find anywhere in the code where either of the old ones appears
>> where I haven't added the new one, so I don't know what I am missing.
> Did you increase the version of the .rc menu file? Something that I also
> run into myself.
That sounds like the reason.  I'll try that later.
> OTOH, this could be much different in 5.1.  I am not working on 5.1 anymore.
> Concentrate on master.
I'd like to complete it in 5.1, so I can use it for my actual work. As I 
understand, master (especially the new ledger) is not yet sufficiently 
safe for production use.
> In the meantime I came across MyMoneyAccount::brokerageName() that returns
> that constructed name for the brokerage account for an account of type
> Investment. Not sure if that already exists in 5.1 though.

It does, although I did it manually, using the same underlying code.  I 
probably should use the function, so when the brokerage account actually 
gets stored, and that function gets updated, that can then be used 
without changing my code.

Jack



More information about the KMyMoney-devel mailing list