File indexing completed on 2024-05-12 16:44:00
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_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_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 = 0, 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 QRegExp& 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 public Q_SLOTS: 0104 /** 0105 * This slot selects all items that are currently in 0106 * the account list of the widget. 0107 */ 0108 void slotSelectAllAccounts(); 0109 0110 /** 0111 * This slot deselects all items that are currently in 0112 * the account list of the widget. 0113 */ 0114 void slotDeselectAllAccounts(); 0115 0116 protected: 0117 /** 0118 * This method loads the list of subaccounts as found in the 0119 * @p list and attaches them to the parent widget passed as @p parent. 0120 * 0121 * @param parent pointer to parent widget 0122 * @param list QStringList containing the ids of all subaccounts to load 0123 * @return This method returns the number of accounts loaded into the list 0124 */ 0125 int loadSubAccounts(QTreeWidgetItem* parent, const QStringList& list); 0126 0127 /** 0128 * This is a helper method for selectAllIncomeCategories() 0129 * and selectAllExpenseCategories(). 0130 */ 0131 void selectCategories(const bool income, const bool expense); 0132 0133 protected Q_SLOTS: 0134 /** 0135 * This slot selects all income categories 0136 */ 0137 void slotSelectIncomeCategories(); 0138 0139 /** 0140 * This slot selects all expense categories 0141 */ 0142 void slotSelectExpenseCategories(); 0143 0144 private: 0145 Q_DECLARE_PRIVATE(KMyMoneyAccountSelector) 0146 }; 0147 0148 class AccountSetPrivate; 0149 class KMM_WIDGETS_EXPORT AccountSet 0150 { 0151 Q_DISABLE_COPY(AccountSet) 0152 0153 public: 0154 AccountSet(); 0155 AccountSet(AccountSet && other); 0156 friend void swap(AccountSet& first, AccountSet& second); 0157 ~AccountSet(); 0158 0159 void addAccountType(eMyMoney::Account::Type type); 0160 void addAccountGroup(eMyMoney::Account::Type type); 0161 void removeAccountType(eMyMoney::Account::Type type); 0162 0163 void clear(); 0164 0165 int load(KMyMoneyAccountSelector* selector); 0166 int load(KMyMoneyAccountSelector* selector, const QString& baseName, const QList<QString>& accountIdList, const bool clear = false); 0167 0168 int count() const; 0169 0170 void setHideClosedAccounts(bool _bool); 0171 bool isHidingClosedAccounts() const; 0172 void setShowInvestments(bool show); 0173 0174 protected: 0175 int loadSubAccounts(KMyMoneyAccountSelector* selector, QTreeWidgetItem* parent, const QString& key, const QStringList& list); 0176 bool includeAccount(const MyMoneyAccount& acc); 0177 0178 private: 0179 AccountSetPrivate * const d_ptr; 0180 Q_DECLARE_PRIVATE(AccountSet) 0181 }; 0182 0183 #endif