Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/models/accountsmodel.cpp
Context not available. | |||||
37 | 37 | | |||
---|---|---|---|---|---|
38 | #include "mymoneyutils.h" | 38 | #include "mymoneyutils.h" | ||
39 | #include "mymoneyfile.h" | 39 | #include "mymoneyfile.h" | ||
40 | #include "mymoneyinstitution.h" | ||||
41 | #include "mymoneyaccount.h" | ||||
42 | #include "mymoneysecurity.h" | ||||
43 | #include "mymoneyprice.h" | ||||
40 | #include "kmymoneyglobalsettings.h" | 44 | #include "kmymoneyglobalsettings.h" | ||
41 | #include "icons.h" | 45 | #include "icons.h" | ||
42 | #include "modelenums.h" | 46 | #include "modelenums.h" | ||
43 | 47 | | |||
44 | using namespace Icons; | 48 | using namespace Icons; | ||
45 | using namespace eAccountsModel; | 49 | using namespace eAccountsModel; | ||
50 | using namespace eMyMoney; | ||||
46 | 51 | | |||
47 | class AccountsModel::Private | 52 | class AccountsModel::Private | ||
48 | { | 53 | { | ||
Context not available. | |||||
173 | 178 | | |||
174 | const auto checkMark = QIcon::fromTheme(g_Icons[Icon::DialogOK]); | 179 | const auto checkMark = QIcon::fromTheme(g_Icons[Icon::DialogOK]); | ||
175 | switch (account.accountType()) { | 180 | switch (account.accountType()) { | ||
176 | case MyMoneyAccount::Income: | 181 | case Account::Income: | ||
177 | case MyMoneyAccount::Expense: | 182 | case Account::Expense: | ||
178 | case MyMoneyAccount::Asset: | 183 | case Account::Asset: | ||
179 | case MyMoneyAccount::Liability: | 184 | case Account::Liability: | ||
180 | // Tax | 185 | // Tax | ||
181 | if (columns.contains(Column::Tax)) { | 186 | if (columns.contains(Column::Tax)) { | ||
182 | colNum = m_columns.indexOf(Column::Tax); | 187 | colNum = m_columns.indexOf(Column::Tax); | ||
Context not available. | |||||
361 | 366 | | |||
362 | // for income and liability accounts, we reverse the sign | 367 | // for income and liability accounts, we reverse the sign | ||
363 | switch (account.accountGroup()) { | 368 | switch (account.accountGroup()) { | ||
364 | case MyMoneyAccount::Income: | 369 | case Account::Income: | ||
365 | case MyMoneyAccount::Liability: | 370 | case Account::Liability: | ||
366 | case MyMoneyAccount::Equity: | 371 | case Account::Equity: | ||
367 | balance = -balance; | 372 | balance = -balance; | ||
368 | break; | 373 | break; | ||
369 | 374 | | |||
Context not available. | |||||
448 | auto value = data.value<MyMoneyMoney>(); | 453 | auto value = data.value<MyMoneyMoney>(); | ||
449 | if (isInstitutionsModel) { | 454 | if (isInstitutionsModel) { | ||
450 | const auto account = childNode->data((int)Role::Account).value<MyMoneyAccount>(); | 455 | const auto account = childNode->data((int)Role::Account).value<MyMoneyAccount>(); | ||
451 | if (account.accountGroup() == MyMoneyAccount::Liability) | 456 | if (account.accountGroup() == Account::Liability) | ||
452 | value = -value; | 457 | value = -value; | ||
453 | } | 458 | } | ||
454 | totalValue += value; | 459 | totalValue += value; | ||
Context not available. | |||||
578 | } | 583 | } | ||
579 | 584 | | |||
580 | // adding account categories (asset, liability, etc.) node | 585 | // adding account categories (asset, liability, etc.) node | ||
581 | QVector <MyMoneyAccount::_accountTypeE> categories { | 586 | QVector <Account> categories { | ||
582 | MyMoneyAccount::Asset, MyMoneyAccount::Liability, | 587 | Account::Asset, Account::Liability, | ||
583 | MyMoneyAccount::Income, MyMoneyAccount::Expense, | 588 | Account::Income, Account::Expense, | ||
584 | MyMoneyAccount::Equity | 589 | Account::Equity | ||
585 | }; | 590 | }; | ||
586 | 591 | | |||
587 | foreach (const auto category, categories) { | 592 | foreach (const auto category, categories) { | ||
Context not available. | |||||
590 | int displayOrder; | 595 | int displayOrder; | ||
591 | 596 | | |||
592 | switch (category) { | 597 | switch (category) { | ||
593 | case MyMoneyAccount::Asset: | 598 | case Account::Asset: | ||
594 | // Asset accounts | 599 | // Asset accounts | ||
595 | account = d->m_file->asset(); | 600 | account = d->m_file->asset(); | ||
596 | accountName = i18n("Asset accounts"); | 601 | accountName = i18n("Asset accounts"); | ||
597 | displayOrder = 1; | 602 | displayOrder = 1; | ||
598 | break; | 603 | break; | ||
599 | case MyMoneyAccount::Liability: | 604 | case Account::Liability: | ||
600 | // Liability accounts | 605 | // Liability accounts | ||
601 | account = d->m_file->liability(); | 606 | account = d->m_file->liability(); | ||
602 | accountName = i18n("Liability accounts"); | 607 | accountName = i18n("Liability accounts"); | ||
603 | displayOrder = 2; | 608 | displayOrder = 2; | ||
604 | break; | 609 | break; | ||
605 | case MyMoneyAccount::Income: | 610 | case Account::Income: | ||
606 | // Income categories | 611 | // Income categories | ||
607 | account = d->m_file->income(); | 612 | account = d->m_file->income(); | ||
608 | accountName = i18n("Income categories"); | 613 | accountName = i18n("Income categories"); | ||
609 | displayOrder = 3; | 614 | displayOrder = 3; | ||
610 | break; | 615 | break; | ||
611 | case MyMoneyAccount::Expense: | 616 | case Account::Expense: | ||
612 | // Expense categories | 617 | // Expense categories | ||
613 | account = d->m_file->expense(); | 618 | account = d->m_file->expense(); | ||
614 | accountName = i18n("Expense categories"); | 619 | accountName = i18n("Expense categories"); | ||
615 | displayOrder = 4; | 620 | displayOrder = 4; | ||
616 | break; | 621 | break; | ||
617 | case MyMoneyAccount::Equity: | 622 | case Account::Equity: | ||
618 | // Equity accounts | 623 | // Equity accounts | ||
619 | account = d->m_file->equity(); | 624 | account = d->m_file->equity(); | ||
620 | accountName = i18n("Equity accounts"); | 625 | accountName = i18n("Equity accounts"); | ||
Context not available. | |||||
879 | * Notify the model that an object has been added. An action is performed only if the object is an account. | 884 | * Notify the model that an object has been added. An action is performed only if the object is an account. | ||
880 | * | 885 | * | ||
881 | */ | 886 | */ | ||
882 | void AccountsModel::slotObjectAdded(MyMoneyFile::notificationObjectT objType, const MyMoneyObject * const obj) | 887 | void AccountsModel::slotObjectAdded(File::Object objType, const MyMoneyObject * const obj) | ||
883 | { | 888 | { | ||
884 | if (objType != MyMoneyFile::notifyAccount) | 889 | if (objType != File::Object::Account) | ||
885 | return; | 890 | return; | ||
886 | 891 | | |||
887 | const MyMoneyAccount * const account = dynamic_cast<const MyMoneyAccount * const>(obj); | 892 | const MyMoneyAccount * const account = dynamic_cast<const MyMoneyAccount * const>(obj); | ||
Context not available. | |||||
912 | * Notify the model that an object has been modified. An action is performed only if the object is an account. | 917 | * Notify the model that an object has been modified. An action is performed only if the object is an account. | ||
913 | * | 918 | * | ||
914 | */ | 919 | */ | ||
915 | void AccountsModel::slotObjectModified(MyMoneyFile::notificationObjectT objType, const MyMoneyObject * const obj) | 920 | void AccountsModel::slotObjectModified(File::Object objType, const MyMoneyObject * const obj) | ||
916 | { | 921 | { | ||
917 | if (objType != MyMoneyFile::notifyAccount) | 922 | if (objType != File::Object::Account) | ||
918 | return; | 923 | return; | ||
919 | 924 | | |||
920 | const MyMoneyAccount * const account = dynamic_cast<const MyMoneyAccount * const>(obj); | 925 | const MyMoneyAccount * const account = dynamic_cast<const MyMoneyAccount * const>(obj); | ||
Context not available. | |||||
938 | favoriteAccountsItem->removeRow(favItem->row()); // it's not favorite anymore | 943 | favoriteAccountsItem->removeRow(favItem->row()); // it's not favorite anymore | ||
939 | } else { | 944 | } else { | ||
940 | // this means that the hierarchy was changed - simulate this with a remove followed by and add operation | 945 | // this means that the hierarchy was changed - simulate this with a remove followed by and add operation | ||
941 | slotObjectRemoved(MyMoneyFile::notifyAccount, oldAccount.id()); | 946 | slotObjectRemoved(File::Object::Account, oldAccount.id()); | ||
942 | slotObjectAdded(MyMoneyFile::notifyAccount, obj); | 947 | slotObjectAdded(File::Object::Account, obj); | ||
943 | } | 948 | } | ||
944 | 949 | | |||
945 | checkNetWorth(); | 950 | checkNetWorth(); | ||
Context not available. | |||||
950 | * Notify the model that an object has been removed. An action is performed only if the object is an account. | 955 | * Notify the model that an object has been removed. An action is performed only if the object is an account. | ||
951 | * | 956 | * | ||
952 | */ | 957 | */ | ||
953 | void AccountsModel::slotObjectRemoved(MyMoneyFile::notificationObjectT objType, const QString& id) | 958 | void AccountsModel::slotObjectRemoved(File::Object objType, const QString& id) | ||
954 | { | 959 | { | ||
955 | if (objType != MyMoneyFile::notifyAccount) | 960 | if (objType != File::Object::Account) | ||
956 | return; | 961 | return; | ||
957 | 962 | | |||
958 | auto list = match(index(0, 0), (int)Role::ID, id, -1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive)); | 963 | auto list = match(index(0, 0), (int)Role::ID, id, -1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive)); | ||
Context not available. | |||||
1121 | * Notify the model that an object has been added. An action is performed only if the object is an account or an institution. | 1126 | * Notify the model that an object has been added. An action is performed only if the object is an account or an institution. | ||
1122 | * | 1127 | * | ||
1123 | */ | 1128 | */ | ||
1124 | void InstitutionsModel::slotObjectAdded(MyMoneyFile::notificationObjectT objType, const MyMoneyObject * const obj) | 1129 | void InstitutionsModel::slotObjectAdded(File::Object objType, const MyMoneyObject * const obj) | ||
1125 | { | 1130 | { | ||
1126 | auto modelUtils = static_cast<InstitutionsPrivate *>(d); | 1131 | auto modelUtils = static_cast<InstitutionsPrivate *>(d); | ||
1127 | if (objType == MyMoneyFile::notifyInstitution) { | 1132 | if (objType == File::Object::Institution) { | ||
1128 | // if an institution was added then add the item which will represent it | 1133 | // if an institution was added then add the item which will represent it | ||
1129 | const MyMoneyInstitution * const institution = dynamic_cast<const MyMoneyInstitution * const>(obj); | 1134 | const MyMoneyInstitution * const institution = dynamic_cast<const MyMoneyInstitution * const>(obj); | ||
1130 | if (!institution) | 1135 | if (!institution) | ||
Context not available. | |||||
1132 | modelUtils->addInstitutionItem(this, *institution); | 1137 | modelUtils->addInstitutionItem(this, *institution); | ||
1133 | } | 1138 | } | ||
1134 | 1139 | | |||
1135 | if (objType != MyMoneyFile::notifyAccount) | 1140 | if (objType != File::Object::Account) | ||
1136 | return; | 1141 | return; | ||
1137 | 1142 | | |||
1138 | // if an account was added then add the item which will represent it only for real accounts | 1143 | // if an account was added then add the item which will represent it only for real accounts | ||
Context not available. | |||||
1161 | * Notify the model that an object has been modified. An action is performed only if the object is an account or an institution. | 1166 | * Notify the model that an object has been modified. An action is performed only if the object is an account or an institution. | ||
1162 | * | 1167 | * | ||
1163 | */ | 1168 | */ | ||
1164 | void InstitutionsModel::slotObjectModified(MyMoneyFile::notificationObjectT objType, const MyMoneyObject * const obj) | 1169 | void InstitutionsModel::slotObjectModified(File::Object objType, const MyMoneyObject * const obj) | ||
1165 | { | 1170 | { | ||
1166 | if (objType == MyMoneyFile::notifyInstitution) { | 1171 | if (objType == File::Object::Institution) { | ||
1167 | // if an institution was modified then modify the item which represents it | 1172 | // if an institution was modified then modify the item which represents it | ||
1168 | const MyMoneyInstitution * const institution = dynamic_cast<const MyMoneyInstitution * const>(obj); | 1173 | const MyMoneyInstitution * const institution = dynamic_cast<const MyMoneyInstitution * const>(obj); | ||
1169 | if (!institution) | 1174 | if (!institution) | ||
Context not available. | |||||
1174 | institutionItem->setIcon(institution->pixmap()); | 1179 | institutionItem->setIcon(institution->pixmap()); | ||
1175 | } | 1180 | } | ||
1176 | 1181 | | |||
1177 | if (objType != MyMoneyFile::notifyAccount) | 1182 | if (objType != File::Object::Account) | ||
1178 | return; | 1183 | return; | ||
1179 | 1184 | | |||
1180 | // if an account was modified then modify the item which represents it | 1185 | // if an account was modified then modify the item which represents it | ||
1181 | const MyMoneyAccount * const account = dynamic_cast<const MyMoneyAccount * const>(obj); | 1186 | const MyMoneyAccount * const account = dynamic_cast<const MyMoneyAccount * const>(obj); | ||
1182 | // nothing to do for root accounts, categories and equity accounts since they don't have a representation in this model | 1187 | // nothing to do for root accounts, categories and equity accounts since they don't have a representation in this model | ||
1183 | if (!account || account->parentAccountId().isEmpty() || account->isIncomeExpense() || account->accountType() == MyMoneyAccount::Equity) | 1188 | if (!account || account->parentAccountId().isEmpty() || account->isIncomeExpense() || account->accountType() == Account::Equity) | ||
1184 | return; | 1189 | return; | ||
1185 | 1190 | | |||
1186 | auto accountItem = d->itemFromAccountId(this, account->id()); | 1191 | auto accountItem = d->itemFromAccountId(this, account->id()); | ||
Context not available. | |||||
1190 | d->setAccountData(accountItem->parent(), accountItem->row(), *account, d->m_columns); | 1195 | d->setAccountData(accountItem->parent(), accountItem->row(), *account, d->m_columns); | ||
1191 | } else { | 1196 | } else { | ||
1192 | // this means that the hierarchy was changed - simulate this with a remove followed by and add operation | 1197 | // this means that the hierarchy was changed - simulate this with a remove followed by and add operation | ||
1193 | slotObjectRemoved(MyMoneyFile::notifyAccount, oldAccount.id()); | 1198 | slotObjectRemoved(File::Object::Account, oldAccount.id()); | ||
1194 | slotObjectAdded(MyMoneyFile::notifyAccount, obj); | 1199 | slotObjectAdded(File::Object::Account, obj); | ||
1195 | } | 1200 | } | ||
1196 | } | 1201 | } | ||
1197 | 1202 | | |||
Context not available. | |||||
1199 | * Notify the model that an object has been removed. An action is performed only if the object is an account or an institution. | 1204 | * Notify the model that an object has been removed. An action is performed only if the object is an account or an institution. | ||
1200 | * | 1205 | * | ||
1201 | */ | 1206 | */ | ||
1202 | void InstitutionsModel::slotObjectRemoved(MyMoneyFile::notificationObjectT objType, const QString& id) | 1207 | void InstitutionsModel::slotObjectRemoved(File::Object objType, const QString& id) | ||
1203 | { | 1208 | { | ||
1204 | if (objType == MyMoneyFile::notifyInstitution) { | 1209 | if (objType == File::Object::Institution) { | ||
1205 | // if an institution was removed then remove the item which represents it | 1210 | // if an institution was removed then remove the item which represents it | ||
1206 | auto itInstitution = static_cast<InstitutionsPrivate *>(d)->institutionItemFromId(this, id); | 1211 | auto itInstitution = static_cast<InstitutionsPrivate *>(d)->institutionItemFromId(this, id); | ||
1207 | if (itInstitution) | 1212 | if (itInstitution) | ||
1208 | removeRow(itInstitution->row(), itInstitution->index().parent()); | 1213 | removeRow(itInstitution->row(), itInstitution->index().parent()); | ||
1209 | } | 1214 | } | ||
1210 | 1215 | | |||
1211 | if (objType != MyMoneyFile::notifyAccount) | 1216 | if (objType != File::Object::Account) | ||
1212 | return; | 1217 | return; | ||
1213 | 1218 | | |||
1214 | // if an account was removed then remove the item which represents it and recompute the institution's value | 1219 | // if an account was removed then remove the item which represents it and recompute the institution's value | ||
Context not available. |