File indexing completed on 2024-05-12 05:07:56

0001 /*
0002     SPDX-FileCopyrightText: 2003-2018 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KMYMONEYACCOUNTSELECTOR_H
0008 #define KMYMONEYACCOUNTSELECTOR_H
0009 
0010 #include "kmm_base_widgets_export.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // QT Includes
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "kmymoneyselector.h"
0022 
0023 class MyMoneyAccount;
0024 
0025 template <typename T> class QList;
0026 
0027 namespace eMyMoney {
0028 namespace Account {
0029 enum class Type;
0030 }
0031 }
0032 
0033 /**
0034   * This class implements an account/category selector. It is based
0035   * on a tree view. Using this widget, one can select one or multiple
0036   * accounts depending on the mode of operation and the set of accounts
0037   * selected to be displayed. (see setSelectionMode()
0038   * and loadList() about the specifics of configuration).
0039   *
0040   * - Single selection mode\n
0041   *   In this mode the widget allows to select a single entry out of
0042   *   the set of displayed accounts.
0043   *
0044   * - Multi selection mode\n
0045   *   In this mode, the widget allows to select one or more entries
0046   *   out of the set of displayed accounts. Selection is performed
0047   *   by marking the account in the view.
0048   */
0049 class KMyMoneyAccountSelectorPrivate;
0050 class KMM_BASE_WIDGETS_EXPORT KMyMoneyAccountSelector : public KMyMoneySelector
0051 {
0052     Q_OBJECT
0053     Q_DISABLE_COPY(KMyMoneyAccountSelector)
0054 
0055 public:
0056     friend class AccountSet;
0057 
0058     explicit KMyMoneyAccountSelector(QWidget* parent = nullptr, Qt::WindowFlags flags = {}, const bool createButtons = true);
0059     ~KMyMoneyAccountSelector() override;
0060 
0061     /**
0062       * This method returns a list of account ids of those accounts
0063       * currently loaded into the widget. It is possible to select
0064       * a list of specific account types only. In this case, pass
0065       * a list of account types as parameter @p list.
0066       *
0067       * @param list QList of account types to be returned. If this
0068       *             list is empty (the default), then the ids of all accounts
0069       *             will be returned.
0070       * @return QStringList of account ids
0071       */
0072     QStringList accountList(const QList<eMyMoney::Account::Type>& list) const;
0073     QStringList accountList() const;
0074 
0075     void setSelectionMode(QTreeWidget::SelectionMode mode);
0076 
0077     /**
0078       * This method checks if a given @a item matches the given regular expression @a exp.
0079       *
0080       * @param exp const reference to a regular expression object
0081       * @param item pointer to QListViewItem
0082       *
0083       * @retval true item matches
0084       * @retval false item does not match
0085       */
0086     virtual bool match(const QRegularExpression& exp, QTreeWidgetItem* item) const override;
0087 
0088     /**
0089       * This method returns, if any of the items in the selector contains
0090       * the text @a txt.
0091       *
0092       * @param txt const reference to string to be looked for
0093       * @retval true exact match found
0094       * @retval false no match found
0095       */
0096     virtual bool contains(const QString& txt) const override;
0097 
0098     /**
0099       * This method removes all the buttons of the widget
0100       */
0101     void removeButtons();
0102 
0103     QSize sizeHint() const override;
0104 
0105 public Q_SLOTS:
0106     /**
0107       * This slot selects all items that are currently in
0108       * the account list of the widget.
0109       */
0110     void slotSelectAllAccounts();
0111 
0112     /**
0113       * This slot deselects all items that are currently in
0114       * the account list of the widget.
0115       */
0116     void slotDeselectAllAccounts();
0117 
0118 protected:
0119     /**
0120       * This method loads the list of subaccounts as found in the
0121       * @p list and attaches them to the parent widget passed as @p parent.
0122       *
0123       * @param parent pointer to parent widget
0124       * @param list QStringList containing the ids of all subaccounts to load
0125       * @return This method returns the number of accounts loaded into the list
0126       */
0127     int loadSubAccounts(QTreeWidgetItem* parent, const QStringList& list);
0128 
0129     /**
0130       * This is a helper method for selectAllIncomeCategories()
0131       * and selectAllExpenseCategories().
0132       */
0133     void selectCategories(const bool income, const bool expense);
0134 
0135 protected Q_SLOTS:
0136     /**
0137       * This slot selects all income categories
0138       */
0139     void slotSelectIncomeCategories();
0140 
0141     /**
0142       * This slot selects all expense categories
0143       */
0144     void slotSelectExpenseCategories();
0145 
0146 private:
0147     Q_DECLARE_PRIVATE(KMyMoneyAccountSelector)
0148 };
0149 
0150 class AccountSetPrivate;
0151 class KMM_BASE_WIDGETS_EXPORT AccountSet
0152 {
0153     Q_DISABLE_COPY(AccountSet)
0154 
0155 public:
0156     AccountSet();
0157     AccountSet(AccountSet && other);
0158     friend void swap(AccountSet& first, AccountSet& second);
0159     ~AccountSet();
0160 
0161     void addAccountType(eMyMoney::Account::Type type);
0162     void addAccountGroup(eMyMoney::Account::Type type);
0163     void removeAccountType(eMyMoney::Account::Type type);
0164 
0165     void clear();
0166 
0167     int load(KMyMoneyAccountSelector* selector);
0168     int load(KMyMoneyAccountSelector* selector, const QString& baseName, const QList<QString>& accountIdList, const bool clear = false);
0169 
0170     int count() const;
0171 
0172     void setHideClosedAccounts(bool _bool);
0173     bool isHidingClosedAccounts() const;
0174     void setShowInvestments(bool show);
0175 
0176 protected:
0177     int loadSubAccounts(KMyMoneyAccountSelector* selector, QTreeWidgetItem* parent, const QString& key, const QStringList& list);
0178     bool includeAccount(const MyMoneyAccount& acc);
0179 
0180 private:
0181     AccountSetPrivate * const d_ptr;
0182     Q_DECLARE_PRIVATE(AccountSet)
0183 };
0184 
0185 #endif