File indexing completed on 2024-05-12 16:44:00
0001 /* 0002 SPDX-FileCopyrightText: 2004-2017 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 KMYMONEYACCOUNTCOMBO_H 0008 #define KMYMONEYACCOUNTCOMBO_H 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 // ---------------------------------------------------------------------------- 0014 // KDE Includes 0015 0016 #include <KComboBox> 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 #include "accountsproxymodel.h" 0022 #include "onlinebankingaccountsfilterproxymodel.h" 0023 0024 /** 0025 * A proxy model used to filter all the data from the core accounts model leaving 0026 * only the name of the accounts so this model can be used in the account 0027 * completion combo. 0028 * 0029 * It shows only the first column (account name) and makes top level items non-selectable. 0030 * 0031 * @see AccountsModel 0032 * @see AccountsFilterProxyModel 0033 * 0034 * @author Cristian Onet 2010 0035 * @author Christian David 0036 */ 0037 0038 template <class baseProxyModel> 0039 class AccountNamesFilterProxyModelTpl : public baseProxyModel 0040 { 0041 public: 0042 explicit AccountNamesFilterProxyModelTpl(QObject *parent = 0); 0043 0044 virtual Qt::ItemFlags flags(const QModelIndex &index) const override; 0045 0046 protected: 0047 bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override; 0048 }; 0049 0050 /** 0051 * @brief "typedef" for AccountNamesFilterProxyModelTpl<AccountsFilterProxyModel> 0052 * 0053 * To create valid Qt moc data this class inherits the template and uses Q_OBJECT. 0054 * 0055 * @code 0056 * typedef AccountNamesFilterProxyModelTpl<AccountsFilterProxyModel> AccountNamesFilterProxyModel; 0057 * @endcode 0058 * 0059 * should work as well. 0060 */ 0061 class AccountNamesFilterProxyModel : public AccountNamesFilterProxyModelTpl<AccountsProxyModel> 0062 { 0063 Q_OBJECT 0064 public: 0065 explicit AccountNamesFilterProxyModel(QObject* parent = 0) 0066 : AccountNamesFilterProxyModelTpl< AccountsProxyModel >(parent) {} 0067 }; 0068 0069 /** 0070 * @brief OnlineBankingAccountFilterProxyModel showing only the name column 0071 * 0072 * Is equivalent to AccountNamesFilterProxyModel using OnlineBankingAccountFilterProxyModel as base. 0073 */ 0074 typedef AccountNamesFilterProxyModelTpl<OnlineBankingAccountsFilterProxyModel> OnlineBankingAccountNamesFilterProxyModel; 0075 0076 0077 /** 0078 * @brief A general account selection widget based on a KComboBox 0079 * 0080 * This widget allows to select an account from the provided set of accounts. This 0081 * set is passed as model in the constructor or via setModel(). In case the widget 0082 * is configured to be editable via setEditable() the combo box contains a lineedit 0083 * widget. This lineedit provides auto completion. 0084 * 0085 * In addition to the KComboBox which supports a list view popup, this widget 0086 * provides a tree view popup to show the account hierarchy. 0087 * 0088 * @author Cristian Onet 0089 */ 0090 class KMyMoneyAccountCombo : public KComboBox 0091 { 0092 Q_OBJECT 0093 Q_DISABLE_COPY(KMyMoneyAccountCombo) 0094 0095 public: 0096 explicit KMyMoneyAccountCombo(QSortFilterProxyModel *model, QWidget* parent = nullptr); 0097 explicit KMyMoneyAccountCombo(QWidget* parent = nullptr); 0098 ~KMyMoneyAccountCombo(); 0099 0100 void setSelected(const QString& id); 0101 const QString& getSelected() const; 0102 0103 void setModel(QSortFilterProxyModel *model); 0104 0105 /** 0106 * Overridden to get specific behavior 0107 */ 0108 void setEditable(bool isEditable); 0109 0110 bool eventFilter(QObject* o, QEvent* e) override; 0111 0112 public Q_SLOTS: 0113 void expandAll(); 0114 void collapseAll(); 0115 void showPopup() override; 0116 void hidePopup() override; 0117 0118 protected: 0119 void wheelEvent(QWheelEvent *ev) override; 0120 0121 protected Q_SLOTS: 0122 void activated(); 0123 void makeCompletion(const QString& txt) override; 0124 void selectItem(const QModelIndex& index); 0125 0126 Q_SIGNALS: 0127 void accountSelected(const QString&); 0128 0129 private: 0130 class Private; 0131 QScopedPointer<Private> const d; 0132 }; 0133 0134 template <class baseProxyModel> 0135 AccountNamesFilterProxyModelTpl<baseProxyModel>::AccountNamesFilterProxyModelTpl(QObject *parent) 0136 : baseProxyModel(parent) 0137 { 0138 } 0139 0140 /** 0141 * Top items are not selectable because they are not real accounts but are only used for grouping. 0142 */ 0143 template <class baseProxyModel> 0144 Qt::ItemFlags AccountNamesFilterProxyModelTpl<baseProxyModel>::flags(const QModelIndex &index) const 0145 { 0146 if (!index.parent().isValid()) 0147 return baseProxyModel::flags(index) & ~Qt::ItemIsSelectable; 0148 return baseProxyModel::flags(index); 0149 } 0150 0151 /** 0152 * Filter all but the first column. 0153 */ 0154 template <class baseProxyModel> 0155 bool AccountNamesFilterProxyModelTpl<baseProxyModel>::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const 0156 { 0157 Q_UNUSED(source_parent) 0158 if (source_column == 0) 0159 return true; 0160 return false; 0161 } 0162 #endif 0163 // kate: space-indent on; indent-width 2; remove-trailing-space on; remove-trailing-space-save on;