File indexing completed on 2024-05-12 16:42:18
0001 /* 0002 SPDX-FileCopyrightText: 2016-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 LEDGERPROXYMODEL_H 0008 #define LEDGERPROXYMODEL_H 0009 0010 #include "kmm_models_export.h" 0011 0012 // ---------------------------------------------------------------------------- 0013 // QT Includes 0014 0015 #include <QSortFilterProxyModel> 0016 0017 // ---------------------------------------------------------------------------- 0018 // KDE Includes 0019 0020 // ---------------------------------------------------------------------------- 0021 // Project Includes 0022 0023 #include "mymoneyenums.h" 0024 0025 class KMM_MODELS_EXPORT LedgerProxyModel : public QSortFilterProxyModel 0026 { 0027 Q_OBJECT 0028 public: 0029 explicit LedgerProxyModel(QObject* parent = nullptr); 0030 virtual ~LedgerProxyModel(); 0031 0032 /** 0033 * Set if the attached views shall show an empty transaction at 0034 * the end of the ledger which clicked starts editing a new transaction. 0035 * 0036 * @note This must be called before setAccount(). 0037 */ 0038 void setShowNewTransaction(bool show); 0039 0040 void setAccountType(eMyMoney::Account::Type type); 0041 0042 void setFilterFixedString(const QString& filter); 0043 0044 void setFilterRole(int role); 0045 0046 int filterRole() const; 0047 0048 /** 0049 * This method maps the @a index to the base model and calls setData on it 0050 */ 0051 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 0052 0053 /** 0054 * This method returns the headerData adjusted to the current 0055 * accountType 0056 */ 0057 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0058 0059 protected: 0060 bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; 0061 /** 0062 * Currently filtering only on account id provided by @sa setAccount() 0063 * 0064 * @note This does not call the base class implementation for speed purposes 0065 */ 0066 bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; 0067 0068 private: 0069 bool m_showNewTransaction; 0070 eMyMoney::Account::Type m_accountType; 0071 QString m_filterId; 0072 int m_filterRole; 0073 }; 0074 0075 #endif // LEDGERPROXYMODEL_H 0076