File indexing completed on 2024-05-12 16:43:57

0001 /*
0002     SPDX-FileCopyrightText: 2006 Darren Gould <darren_gould@gmx.de>
0003     SPDX-FileCopyrightText: 2009-2014 Alvaro Soliverez <asoliverez@gmail.com>
0004     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef BUDGETVIEWPROXYMODEL_H
0009 #define BUDGETVIEWPROXYMODEL_H
0010 
0011 #include "kmm_widgets_export.h"
0012 
0013 // ----------------------------------------------------------------------------
0014 // QT Includes
0015 
0016 // ----------------------------------------------------------------------------
0017 // KDE Includes
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "accountsviewproxymodel.h"
0023 
0024 class MyMoneyAccount;
0025 class MyMoneyBudget;
0026 class MyMoneyMoney;
0027 
0028 /**
0029   * This proxy model implements all the functionality needed by the budgets
0030   * account tree based on the @ref AccountsModel. One such functionality is
0031   * obtaining the account balance and value base on the budget.
0032   *
0033   * @author Cristian Oneț
0034   */
0035 class BudgetViewProxyModelPrivate;
0036 class KMM_WIDGETS_EXPORT BudgetViewProxyModel : public AccountsViewProxyModel
0037 {
0038     Q_OBJECT
0039     Q_DISABLE_COPY(BudgetViewProxyModel)
0040 
0041 public:
0042     explicit BudgetViewProxyModel(QObject *parent = nullptr);
0043     ~BudgetViewProxyModel() override;
0044 
0045     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0046     Qt::ItemFlags flags(const QModelIndex &index) const override;
0047 
0048     void setBudget(const MyMoneyBudget& budget);
0049 
0050 Q_SIGNALS:
0051     /**
0052       * Emit this signal when the balance of the budget is changed.
0053       */
0054     void balanceChanged(const MyMoneyMoney &);
0055 
0056 protected:
0057     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0058     MyMoneyMoney accountBalance(const QString &accountId) const;
0059     MyMoneyMoney accountValue(const MyMoneyAccount &account, const MyMoneyMoney &balance) const;
0060     MyMoneyMoney computeTotalValue(const QModelIndex &source_index) const;
0061 
0062 private:
0063     Q_DECLARE_PRIVATE(BudgetViewProxyModel)
0064 
0065     void checkBalance();
0066 };
0067 
0068 #endif