File indexing completed on 2024-05-12 05:06:16

0001 /*
0002     SPDX-FileCopyrightText: 2019 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef LEDGERFILTERBASE_H
0007 #define LEDGERFILTERBASE_H
0008 
0009 #include "kmm_models_export.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 #include <qglobal.h>
0015 #include <QSortFilterProxyModel>
0016 
0017 // ----------------------------------------------------------------------------
0018 // KDE Includes
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 
0023 #include "ledgersortproxymodel.h"
0024 
0025 class LedgerFilterBasePrivate;
0026 class KMM_MODELS_EXPORT LedgerFilterBase : public LedgerSortProxyModel
0027 {
0028     Q_OBJECT
0029     Q_DECLARE_PRIVATE(LedgerFilterBase)
0030     Q_DISABLE_COPY(LedgerFilterBase)
0031 
0032 public:
0033     virtual ~LedgerFilterBase();
0034 
0035     void setAccountType(eMyMoney::Account::Type type);
0036 
0037     void setFilterFixedString(const QString& filter);
0038     void setFilterFixedStrings(const QStringList& filters);
0039     void appendFilterFixedString(const QString& filter);
0040 
0041     QStringList filterFixedStrings() const;
0042 
0043     /**
0044      * This method returns the headerData adjusted to the current
0045      * accountType
0046      */
0047     QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
0048 
0049     /**
0050      * This method is used to update the balance data. All other
0051      * roles are forwarded to the source model. The balance can
0052      * be retrieved using the derived model.
0053      *
0054      * It also maintains the split height cache. Setting any @a index
0055      * with role JournalSplitMaxLinesCountRole to a @a value of -1
0056      * will clear the cache of all items.
0057      *
0058      * Call with any @a index and @a value of -1 and @a role
0059      * @c eMyMoney::Model::JournalSplitMaxLinesCountRole to reset
0060      * the split height cache
0061      *
0062      * @sa LedgerAccountFilter::data()
0063      */
0064     bool setData(const QModelIndex& index, const QVariant& value, int role) override;
0065 
0066     QVariant data(const QModelIndex& index, int role) const override;
0067 
0068     /**
0069      * Overridden for internal reasons to implement the functionality
0070      * provided by setLedgerIsEditable()
0071      *
0072      * @sa setLedgerIsEditable()
0073      */
0074     Qt::ItemFlags flags(const QModelIndex& idx) const override;
0075 
0076     void setShowEntryForNewTransaction(bool show);
0077 
0078     void setShowScheduledTransactions(bool show);
0079 
0080     /**
0081      * add @a model to the source models
0082      */
0083     void addSourceModel(QAbstractItemModel* model);
0084 
0085     /**
0086      * remove @a model from the source models
0087      */
0088     void removeSourceModel(QAbstractItemModel* model);
0089 
0090     /**
0091      * Use to control maintenance of balance information
0092      */
0093     void setMaintainBalances(bool maintainBalances);
0094 
0095     /**
0096      * This can be used to prevent editing items in
0097      * the views using this model. The default value
0098      * when this object is constructed for this setting
0099      * is @c true. If set to false, editing the transactions
0100      * shown is not possible anymore.
0101      */
0102     void setLedgerIsEditable(bool enableEdit);
0103 
0104 protected:
0105     explicit LedgerFilterBase(LedgerFilterBasePrivate* dd, QObject* parent);
0106 
0107     /**
0108      * @note This does not call the base class implementation for speed purposes
0109      */
0110     bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
0111 
0112 };
0113 
0114 #endif // LEDGERFILTERBASE_H
0115