File indexing completed on 2024-05-19 05:06:56

0001 /*
0002     SPDX-FileCopyrightText: 2010-2014 Cristian Oneț <onet.cristian@gmail.com>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-FileCopyrightText: 2019-2020 Thomas Baumgart <tbaumgart@kde.org>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "accountsproxymodel.h"
0009 #include "accountsproxymodel_p.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 // ----------------------------------------------------------------------------
0015 // KDE Includes
0016 
0017 #include <KLocalizedString>
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "accountsmodel.h"
0023 #include "journalmodel.h"
0024 #include "mymoneyenums.h"
0025 #include "mymoneyfile.h"
0026 #include "mymoneymoney.h"
0027 #include "schedulesjournalmodel.h"
0028 
0029 AccountsProxyModel::AccountsProxyModel(QObject *parent) :
0030     QSortFilterProxyModel(parent),
0031     d_ptr(new AccountsProxyModelPrivate)
0032 {
0033     setObjectName("AccountsProxyModel");
0034     setRecursiveFilteringEnabled(true);
0035     setDynamicSortFilter(true);
0036     setSortLocaleAware(true);
0037     setFilterCaseSensitivity(Qt::CaseInsensitive);
0038 }
0039 
0040 AccountsProxyModel::AccountsProxyModel(AccountsProxyModelPrivate &dd, QObject *parent) :
0041     QSortFilterProxyModel(parent), d_ptr(&dd)
0042 {
0043     setRecursiveFilteringEnabled(true);
0044 }
0045 
0046 AccountsProxyModel::~AccountsProxyModel()
0047 {
0048 }
0049 
0050 void AccountsProxyModel::setSourceModel(QAbstractItemModel* model)
0051 {
0052     if (sourceModel() != nullptr) {
0053         disconnect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &QSortFilterProxyModel::invalidate);
0054         disconnect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, &QSortFilterProxyModel::invalidate);
0055     }
0056     QSortFilterProxyModel::setSourceModel(model);
0057     if (sourceModel() != nullptr) {
0058         connect(sourceModel(), &QAbstractItemModel::rowsInserted, this, &QSortFilterProxyModel::invalidate);
0059         connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, &QSortFilterProxyModel::invalidate);
0060     }
0061 }
0062 
0063 /**
0064   * This function was re-implemented so we could have a special display order (favorites first)
0065   */
0066 bool AccountsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
0067 {
0068     if (!left.isValid() || !right.isValid())
0069         return false;
0070     // different sorting based on the column which is being sorted
0071     switch (left.column()) {
0072     // for the accounts column sort based on the DisplayOrderRole
0073     default:
0074     case AccountsModel::Column::AccountName: {
0075         const auto leftData = sourceModel()->data(left, eMyMoney::Model::Roles::AccountDisplayOrderRole);
0076         const auto rightData = sourceModel()->data(right, eMyMoney::Model::Roles::AccountDisplayOrderRole);
0077 
0078         if (leftData.toInt() == rightData.toInt()) {
0079             // sort items of the same display order alphabetically
0080             return QSortFilterProxyModel::lessThan(left, right);
0081         }
0082         return leftData.toInt() < rightData.toInt();
0083     }
0084     // the balance and total value columns are sorted based on the value of the account
0085     case AccountsModel::Column::Balance:
0086     case AccountsModel::Column::TotalPostedValue: {
0087         const auto leftData = sourceModel()->data(sourceModel()->index(left.row(), AccountsModel::Column::AccountName, left.parent()), eMyMoney::Model::Roles::AccountTotalValueRole);
0088         const auto rightData = sourceModel()->data(sourceModel()->index(right.row(), AccountsModel::Column::AccountName, right.parent()), eMyMoney::Model::Roles::AccountTotalValueRole);
0089         return leftData.value<MyMoneyMoney>() < rightData.value<MyMoneyMoney>();
0090     }
0091     break;
0092     }
0093     return QSortFilterProxyModel::lessThan(left, right);
0094 }
0095 
0096 /**
0097   * This function was re-implemented to consider all the filtering aspects that we need in the application.
0098   */
0099 bool AccountsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
0100 {
0101     Q_D(const AccountsProxyModel);
0102     if (d->m_hideAllEntries)
0103         return false;
0104 
0105     if (!source_parent.isValid() && (source_row == 0) && hideFavoriteAccounts())
0106         return false;
0107 
0108     const auto index = sourceModel()->index(source_row, AccountsModel::Column::AccountName, source_parent);
0109     return acceptSourceItem(index) && filterAcceptsRowOrChildRows(source_row, source_parent);
0110 }
0111 
0112 /**
0113   * This function implements a recursive matching. It is used to match a row even if it's values
0114   * doesn't match the current filtering criteria but it has at least one child row that does match.
0115   */
0116 bool AccountsProxyModel::filterAcceptsRowOrChildRows(int source_row, const QModelIndex &source_parent) const
0117 {
0118     if (QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent))
0119         return true;
0120 
0121     const auto index = sourceModel()->index(source_row, AccountsModel::Column::AccountName, source_parent);
0122     for (auto i = 0; i < sourceModel()->rowCount(index); ++i) {
0123         if (filterAcceptsRowOrChildRows(i, index))
0124             return true;
0125     }
0126     return false;
0127 }
0128 
0129 /**
0130   * Add the given account group to the filter.
0131   * @param group The account group to be added.
0132   * @see eMyMoney::Account
0133   */
0134 void AccountsProxyModel::addAccountGroup(const QVector<eMyMoney::Account::Type> &groups)
0135 {
0136     Q_D(AccountsProxyModel);
0137     for (const auto& group : groups) {
0138         switch (group) {
0139         case eMyMoney::Account::Type::Asset:
0140             d->m_typeList << eMyMoney::Account::Type::Checkings;
0141             d->m_typeList << eMyMoney::Account::Type::Savings;
0142             d->m_typeList << eMyMoney::Account::Type::Cash;
0143             d->m_typeList << eMyMoney::Account::Type::AssetLoan;
0144             d->m_typeList << eMyMoney::Account::Type::CertificateDep;
0145             d->m_typeList << eMyMoney::Account::Type::Investment;
0146             d->m_typeList << eMyMoney::Account::Type::Stock;
0147             d->m_typeList << eMyMoney::Account::Type::MoneyMarket;
0148             d->m_typeList << eMyMoney::Account::Type::Asset;
0149             d->m_typeList << eMyMoney::Account::Type::Currency;
0150             break;
0151         case eMyMoney::Account::Type::Liability:
0152             d->m_typeList << eMyMoney::Account::Type::CreditCard;
0153             d->m_typeList << eMyMoney::Account::Type::Loan;
0154             d->m_typeList << eMyMoney::Account::Type::Liability;
0155             break;
0156         case eMyMoney::Account::Type::Income:
0157             d->m_typeList << eMyMoney::Account::Type::Income;
0158             break;
0159         case eMyMoney::Account::Type::Expense:
0160             d->m_typeList << eMyMoney::Account::Type::Expense;
0161             break;
0162         case eMyMoney::Account::Type::Equity:
0163             d->m_typeList << eMyMoney::Account::Type::Equity;
0164             break;
0165         default:
0166             d->m_typeList << group;
0167             break;
0168         }
0169     }
0170     invalidateFilter();
0171 }
0172 
0173 /**
0174   * Add the given account type to the filter.
0175   * @param type The account type to be added.
0176   * @see eMyMoney::Account
0177   */
0178 void AccountsProxyModel::addAccountType(eMyMoney::Account::Type type)
0179 {
0180     Q_D(AccountsProxyModel);
0181     if (!d->m_typeList.contains(type)) {
0182         d->m_typeList << type;
0183         invalidateFilter();
0184     }
0185 }
0186 
0187 /**
0188   * Remove the given account type from the filter.
0189   * @param type The account type to be removed.
0190   * @see eMyMoney::Account
0191   */
0192 void AccountsProxyModel::removeAccountType(eMyMoney::Account::Type type)
0193 {
0194     Q_D(AccountsProxyModel);
0195     if (d->m_typeList.removeAll(type) > 0) {
0196         invalidateFilter();
0197     }
0198 }
0199 
0200 /**
0201   * Use this to reset the filter.
0202   */
0203 void AccountsProxyModel::clear()
0204 {
0205     Q_D(AccountsProxyModel);
0206     d->m_typeList.clear();
0207     d->m_notSelectableId.clear();
0208     invalidateFilter();
0209 }
0210 
0211 void AccountsProxyModel::setNotSelectable(const QString& accountId)
0212 {
0213     Q_D(AccountsProxyModel);
0214     d->m_notSelectableId = accountId;
0215 }
0216 
0217 void AccountsProxyModel::setClosedSelectable(bool selectable)
0218 {
0219     Q_D(AccountsProxyModel);
0220     d->m_canSelectClosedAccounts = selectable;
0221 }
0222 
0223 Qt::ItemFlags AccountsProxyModel::flags(const QModelIndex& index) const
0224 {
0225     Q_D(const AccountsProxyModel);
0226     auto flags = QSortFilterProxyModel::flags(index);
0227     if (d->m_notSelectableId == index.data(eMyMoney::Model::IdRole).toString()) {
0228         flags.setFlag(Qt::ItemIsSelectable, false);
0229         flags.setFlag(Qt::ItemIsEnabled, false);
0230     }
0231     if (!d->m_canSelectClosedAccounts && index.data(eMyMoney::Model::AccountIsClosedRole).toBool()) {
0232         flags.setFlag(Qt::ItemIsSelectable, false);
0233     }
0234     if (!d->m_selectableAccountTypes.isEmpty()
0235         && !d->m_selectableAccountTypes.contains(index.data(eMyMoney::Model::AccountTypeRole).value<eMyMoney::Account::Type>())) {
0236         flags.setFlag(Qt::ItemIsEnabled, false);
0237         flags.setFlag(Qt::ItemIsSelectable, false);
0238     }
0239     return flags;
0240 }
0241 
0242 /**
0243   * Implementation function that performs the actual filtering.
0244   */
0245 bool AccountsProxyModel::acceptSourceItem(const QModelIndex &source) const
0246 {
0247     Q_D(const AccountsProxyModel);
0248 
0249     if (source.isValid()) {
0250         const auto accountTypeValue = source.data(eMyMoney::Model::Roles::AccountTypeRole);
0251         const bool isValidAccountEntry = accountTypeValue.isValid();
0252         const bool isValidInstititonEntry = source.data(eMyMoney::Model::Roles::InstitutionBankCodeRole).isValid();
0253 
0254         if (isValidAccountEntry) {
0255             const auto accountType = static_cast<eMyMoney::Account::Type>(accountTypeValue.toInt());
0256 
0257             switch (state()) {
0258             case State::Any:
0259                 if (hideClosedAccounts() && source.data(eMyMoney::Model::Roles::AccountIsClosedRole).toBool())
0260                     return false;
0261 
0262                 // we hide stock accounts if not in expert mode
0263                 // we hide equity accounts if not in expert mode
0264                 if (hideEquityAccounts()) {
0265                     if (accountType == eMyMoney::Account::Type::Equity)
0266                         return false;
0267 
0268                     if (source.data(eMyMoney::Model::Roles::AccountIsInvestRole).toBool())
0269                         return false;
0270                 }
0271 
0272                 // we hide unused income and expense accounts if the specific flag is set
0273                 if (hideUnusedIncomeExpenseAccounts()) {
0274                     if ((accountType == eMyMoney::Account::Type::Income) || (accountType == eMyMoney::Account::Type::Expense)) {
0275                         const auto totalValue = source.data(eMyMoney::Model::Roles::AccountTotalValueRole);
0276                         if (totalValue.isValid() && totalValue.value<MyMoneyMoney>().isZero()) {
0277                             Q_EMIT const_cast<AccountsProxyModel*>(this)->unusedIncomeExpenseAccountHidden();
0278                             return false;
0279                         }
0280                     }
0281                 }
0282 
0283                 // we don't hide the top level accounts
0284                 if (source.parent() != QModelIndex()) {
0285                     // we hide zero balance investment accounts
0286                     if (hideZeroBalancedEquityAccounts()) {
0287                         if (accountType == eMyMoney::Account::Type::Equity || source.data(eMyMoney::Model::Roles::AccountIsInvestRole).toBool()) {
0288                             const auto totalValue = source.data(eMyMoney::Model::Roles::AccountTotalValueRole);
0289                             if (totalValue.isValid() && totalValue.value<MyMoneyMoney>().isZero()) {
0290                                 return false;
0291                             }
0292                         }
0293                     }
0294 
0295                     // check if we hide zero balanced accounts
0296                     if (hideZeroBalancedAccounts()) {
0297                         const auto totalValue = source.data(eMyMoney::Model::Roles::AccountTotalValueRole);
0298                         if (totalValue.isValid() && totalValue.value<MyMoneyMoney>().isZero()) {
0299                             return false;
0300                         }
0301                     }
0302                 }
0303                 break;
0304 
0305             case State::Unused: {
0306                 // if an account has sub-accounts it is still used
0307                 if (sourceModel()->rowCount(source) > 0) {
0308                     return false;
0309                 }
0310                 const auto accountId = source.data(eMyMoney::Model::IdRole).toString();
0311                 auto journalModel = MyMoneyFile::instance()->journalModel();
0312                 auto indexes = journalModel->match(journalModel->index(0, 0), eMyMoney::Model::JournalSplitAccountIdRole, accountId);
0313                 if (!indexes.isEmpty())
0314                     return false;
0315                 journalModel = MyMoneyFile::instance()->schedulesJournalModel();
0316                 indexes = journalModel->match(journalModel->index(0, 0), eMyMoney::Model::JournalSplitAccountIdRole, accountId);
0317                 if (!indexes.isEmpty())
0318                     return false;
0319                 break;
0320             }
0321             case State::Closed:
0322                 if (source.data(eMyMoney::Model::AccountIsClosedRole).toBool() == false) {
0323                     return false;
0324                 }
0325                 break;
0326             }
0327 
0328             // in case we should hide the favorite accounts section, we filter it out here
0329             if (d->m_hideFavoriteAccounts && source.data(eMyMoney::Model::AccountIsFavoriteIndexRole).toBool()) {
0330                 return false;
0331             }
0332 
0333             if (d->m_typeList.contains(accountType)) {
0334                 return true;
0335             }
0336 
0337         } else if (isValidInstititonEntry) {
0338             if (sourceModel()->rowCount(source) == 0) {
0339                 // if this is an institution that has no children show it only if hide unused institutions
0340                 // (hide closed accounts for now) is not checked
0341                 return !hideClosedAccounts();
0342             }
0343             return true;
0344         }
0345 
0346         // all parents that have at least one visible child must be visible
0347         const auto rowCount = sourceModel()->rowCount(source);
0348         for (auto i = 0; i < rowCount; ++i) {
0349             const auto index = sourceModel()->index(i, AccountsModel::Column::AccountName, source);
0350             if (acceptSourceItem(index)) {
0351                 return true;
0352             }
0353         }
0354     }
0355     return false;
0356 }
0357 
0358 /**
0359   * Set if closed accounts should be hidden or not.
0360   * @param hideClosedAccounts
0361   */
0362 void AccountsProxyModel::setHideClosedAccounts(bool hideClosedAccounts)
0363 {
0364     Q_D(AccountsProxyModel);
0365     if (d->m_hideClosedAccounts ^ hideClosedAccounts) {
0366         d->m_hideClosedAccounts = hideClosedAccounts;
0367         invalidateFilter();
0368     }
0369 }
0370 
0371 /**
0372   * Check if closed accounts are hidden or not.
0373   */
0374 bool AccountsProxyModel::hideClosedAccounts() const
0375 {
0376     Q_D(const AccountsProxyModel);
0377     return d->m_hideClosedAccounts && !d->m_showAllEntries;
0378 }
0379 
0380 /**
0381   * Set if equity and investment accounts should be hidden or not.
0382   * @param hideEquityAccounts
0383   */
0384 void AccountsProxyModel::setHideEquityAccounts(bool hideEquityAccounts)
0385 {
0386     Q_D(AccountsProxyModel);
0387     if (d->m_hideEquityAccounts ^ hideEquityAccounts) {
0388         d->m_hideEquityAccounts = hideEquityAccounts;
0389         invalidateFilter();
0390     }
0391 }
0392 
0393 /**
0394   * Check if equity and investment accounts are hidden or not.
0395   */
0396 bool AccountsProxyModel::hideEquityAccounts() const
0397 {
0398     Q_D(const AccountsProxyModel);
0399     return d->m_hideEquityAccounts && !d->m_showAllEntries;
0400 }
0401 
0402 /**
0403  * Set if equity or investment accounts should be hidden if their balance is zero.
0404  * @param hideZeroBalancedEquityAccounts
0405  */
0406 void AccountsProxyModel::setHideZeroBalancedEquityAccounts(bool hideZeroBalancedEquityAccounts)
0407 {
0408     Q_D(AccountsProxyModel);
0409     if (d->m_hideZeroBalanceEquityAccounts ^ hideZeroBalancedEquityAccounts) {
0410         d->m_hideZeroBalanceEquityAccounts = hideZeroBalancedEquityAccounts;
0411         invalidateFilter();
0412     }
0413 }
0414 
0415 /**
0416  * Check if equity or investment accounts are hidden when their balance is zero.
0417  */
0418 bool AccountsProxyModel::hideZeroBalancedEquityAccounts() const
0419 {
0420     Q_D(const AccountsProxyModel);
0421     return d->m_hideZeroBalanceEquityAccounts && !d->m_showAllEntries;
0422 }
0423 
0424 /**
0425  * Set if accounts should be hidden if their balance is zero.
0426  * @param hideZeroBalancedAccounts
0427  */
0428 void AccountsProxyModel::setHideZeroBalancedAccounts(bool hideZeroBalancedAccounts)
0429 {
0430     Q_D(AccountsProxyModel);
0431     if (d->m_hideZeroBalanceAccounts ^ hideZeroBalancedAccounts) {
0432         d->m_hideZeroBalanceAccounts = hideZeroBalancedAccounts;
0433         invalidateFilter();
0434     }
0435 }
0436 
0437 /**
0438  * Check if accounts are hidden when their balance is zero.
0439  */
0440 bool AccountsProxyModel::hideZeroBalancedAccounts() const
0441 {
0442     Q_D(const AccountsProxyModel);
0443     return d->m_hideZeroBalanceAccounts && !d->m_showAllEntries;
0444 }
0445 
0446 /**
0447   * Set if empty categories should be hidden or not.
0448   * @param hideUnusedIncomeExpenseAccounts
0449   */
0450 void AccountsProxyModel::setHideUnusedIncomeExpenseAccounts(bool hideUnusedIncomeExpenseAccounts)
0451 {
0452     Q_D(AccountsProxyModel);
0453     if (d->m_hideUnusedIncomeExpenseAccounts ^ hideUnusedIncomeExpenseAccounts) {
0454         d->m_hideUnusedIncomeExpenseAccounts = hideUnusedIncomeExpenseAccounts;
0455         invalidateFilter();
0456     }
0457 }
0458 
0459 /**
0460   * Check if empty categories are hidden or not.
0461   */
0462 bool AccountsProxyModel::hideUnusedIncomeExpenseAccounts() const
0463 {
0464     Q_D(const AccountsProxyModel);
0465     return d->m_hideUnusedIncomeExpenseAccounts && !d->m_showAllEntries;
0466 }
0467 
0468 /**
0469  * Set if favorite accounts should be hidden or not.
0470  * @param hideFavoriteAccounts
0471  */
0472 void AccountsProxyModel::setHideFavoriteAccounts(bool hideFavoriteAccounts)
0473 {
0474     Q_D(AccountsProxyModel);
0475     if (d->m_hideFavoriteAccounts ^ hideFavoriteAccounts) {
0476         d->m_hideFavoriteAccounts = hideFavoriteAccounts;
0477         invalidateFilter();
0478     }
0479 }
0480 
0481 /**
0482  * Check if empty categories are hidden or not.
0483  */
0484 bool AccountsProxyModel::hideFavoriteAccounts() const
0485 {
0486     Q_D(const AccountsProxyModel);
0487     return d->m_hideFavoriteAccounts;
0488 }
0489 
0490 void AccountsProxyModel::setHideAllEntries(bool hideAllEntries)
0491 {
0492     Q_D(AccountsProxyModel);
0493     if (d->m_hideAllEntries ^ hideAllEntries) {
0494         d->m_hideAllEntries = hideAllEntries;
0495         invalidateFilter();
0496     }
0497 }
0498 
0499 bool AccountsProxyModel::hideAllEntries() const
0500 {
0501     Q_D(const AccountsProxyModel);
0502     return d->m_hideAllEntries;
0503 }
0504 
0505 void AccountsProxyModel::setShowAllEntries(bool showAllEntries)
0506 {
0507     Q_D(AccountsProxyModel);
0508     if (d->m_showAllEntries ^ showAllEntries) {
0509         d->m_showAllEntries = showAllEntries;
0510         invalidateFilter();
0511     }
0512 }
0513 
0514 bool AccountsProxyModel::showAllEntries() const
0515 {
0516     Q_D(const AccountsProxyModel);
0517     return d->m_showAllEntries;
0518 }
0519 
0520 /**
0521   * Returns the number of visible items after filtering. In case @a includeBaseAccounts
0522   * is set to @c true, the 5 base accounts (asset, liability, income, expense and equity)
0523   * will also be counted. The default is @c false.
0524   */
0525 int AccountsProxyModel::visibleItems(bool includeBaseAccounts) const
0526 {
0527     auto rows = 0;
0528     for (auto i = 0; i < rowCount(QModelIndex()); ++i) {
0529         if(includeBaseAccounts) {
0530             ++rows;
0531         }
0532         const auto childIndex = index(i, 0);
0533         if (hasChildren(childIndex)) {
0534             rows += visibleItems(childIndex);
0535         }
0536     }
0537     return rows;
0538 }
0539 
0540 /**
0541   * Returns the number of visible items under the given @a index.
0542   * The column of the @a index must be 0, otherwise no count will
0543   * be returned (returns 0).
0544   */
0545 int AccountsProxyModel::visibleItems(const QModelIndex& index) const
0546 {
0547     auto rows = 0;
0548     if (index.isValid() && index.column() == AccountsModel::Column::AccountName) { // CAUTION! Assumption is being made that Account column number is always 0
0549         const auto *model = index.model();
0550         const auto rowCount = model->rowCount(index);
0551         for (auto i = 0; i < rowCount; ++i) {
0552             ++rows;
0553             const auto childIndex = model->index(i, index.column(), index);
0554             if (model->hasChildren(childIndex))
0555                 rows += visibleItems(childIndex);
0556         }
0557     }
0558     return rows;
0559 }
0560 
0561 QVector<eMyMoney::Account::Type> AccountsProxyModel::assetLiability()
0562 {
0563     return QVector<eMyMoney::Account::Type>({eMyMoney::Account::Type::Asset, eMyMoney::Account::Type::Liability});
0564 }
0565 
0566 QVector<eMyMoney::Account::Type> AccountsProxyModel::assetLiabilityEquity()
0567 {
0568     return QVector<eMyMoney::Account::Type>({ eMyMoney::Account::Type::Asset, eMyMoney::Account::Type::Liability, eMyMoney::Account::Type::Equity });
0569 }
0570 
0571 QVector<eMyMoney::Account::Type> AccountsProxyModel::incomeExpense()
0572 {
0573     return QVector<eMyMoney::Account::Type>({ eMyMoney::Account::Type::Income, eMyMoney::Account::Type::Expense });
0574 }
0575 
0576 QVector<eMyMoney::Account::Type> AccountsProxyModel::assetLiabilityEquityIncomeExpense()
0577 {
0578     return assetLiabilityEquity() << incomeExpense();
0579 }
0580 
0581 void AccountsProxyModel::setState(AccountsProxyModel::State state)
0582 {
0583     Q_D(AccountsProxyModel);
0584     if (d->m_state != state) {
0585         d->m_state = state;
0586         invalidateFilter();
0587     }
0588 }
0589 
0590 AccountsProxyModel::State AccountsProxyModel::state() const
0591 {
0592     Q_D(const AccountsProxyModel);
0593     return d->m_state;
0594 }
0595 
0596 void AccountsProxyModel::setFilterComboBox(QComboBox* comboBox)
0597 {
0598     Q_D(AccountsProxyModel);
0599     d->m_filterComboBox = comboBox;
0600     d->m_filterComboBox->clear();
0601     d->m_filterComboBox->insertItem(static_cast<int>(State::Any), i18nc("Account filter", "Any status"));
0602     d->m_filterComboBox->insertItem(static_cast<int>(State::Unused), i18nc("Account filter", "Unused"));
0603     d->m_filterComboBox->insertItem(static_cast<int>(State::Closed), i18nc("Account filter", "Closed"));
0604 
0605     connect(comboBox, QOverload<int>::of(&QComboBox::activated), this, [&](int idx) {
0606         setState(static_cast<AccountsProxyModel::State>(idx));
0607     });
0608     connect(comboBox, &QComboBox::destroyed, this, [&]() {
0609         Q_D(AccountsProxyModel);
0610         d->m_filterComboBox = nullptr;
0611     });
0612 }
0613 
0614 void AccountsProxyModel::setSelectableAccountTypes(QSet<eMyMoney::Account::Type> selectableAccountTypes)
0615 {
0616     Q_D(AccountsProxyModel);
0617     d->m_selectableAccountTypes = selectableAccountTypes;
0618 }