File indexing completed on 2024-05-19 05:06:59

0001 /*
0002     SPDX-FileCopyrightText: 2019-2020 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef SPECIALDATESFILTER_H
0007 #define SPECIALDATESFILTER_H
0008 
0009 #include "kmm_models_export.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 #include <QSortFilterProxyModel>
0015 
0016 // ----------------------------------------------------------------------------
0017 // KDE Includes
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "ledgersortproxymodel.h"
0023 
0024 class SpecialLedgerItemFilterPrivate;
0025 class KMM_MODELS_EXPORT SpecialLedgerItemFilter : public LedgerSortProxyModel
0026 {
0027     Q_OBJECT
0028     Q_DECLARE_PRIVATE(SpecialLedgerItemFilter)
0029     Q_DISABLE_COPY(SpecialLedgerItemFilter)
0030 
0031 public:
0032     typedef enum {
0033         FilterBalanceNormal,
0034         FilterBalanceReconciliation,
0035     } FilterBalanceMode;
0036 
0037     explicit SpecialLedgerItemFilter(QObject* parent);
0038 
0039     /**
0040      * Reimplemented to propagate sorting to sourceModel
0041      */
0042     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
0043 
0044     void setSourceModel(LedgerSortProxyModel* model);
0045 
0046     /**
0047      * This method returns the data from the base model and
0048      * intercepts the balance column and returns a fixed string
0049      * in case a balance cannot be provided (e.g. sorting is
0050      * not by date or some data is filtered)
0051      */
0052     QVariant data(const QModelIndex& index, int role) const override;
0053 
0054     /**
0055      * Reimplemented to propagate setting of sort order to sourceModel
0056      */
0057     void setLedgerSortOrder(LedgerSortOrder sortOrder) override;
0058 
0059     LedgerSortOrder ledgerSortOrder() const override;
0060 
0061     /**
0062      * Reimplemented to propagate setting to sourceModel
0063      */
0064     void setSortingEnabled(bool enable) override;
0065 
0066     /**
0067      * Control visibility of reconciliation entries in ledger
0068      */
0069     void setShowReconciliationEntries(LedgerViewSettings::ReconciliationHeader show);
0070 
0071     /**
0072      * Make sure to suppress multiple reconciliation headers following each other
0073      */
0074     void setHideReconciledTransactions(bool hide);
0075 
0076     /**
0077      * Setup how the balance display shall be filtered. In @a FilterBalanceNormal mode
0078      * balances will be filtered if any filter is active or the transactions are
0079      * not sorted by date. In @a FilterBalanceReconciliation mode balances
0080      * will be filtered if any text filter is active, the state filter is not
0081      * equal to NotReconciled or the transactions are not sorted by date.
0082      */
0083     void setFilterBalanceMode(FilterBalanceMode mode);
0084 
0085 public Q_SLOTS:
0086     void forceReload();
0087 
0088 protected:
0089     /**
0090      * @note Does not call base class implementation
0091      */
0092     bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
0093 
0094     /**
0095      * Reimplemented to propagate setting to sourceModel
0096      */
0097     void doSortOnIdle() override;
0098 
0099 private:
0100     // make sure that only LedgerSortProxyModel models can be used as sources
0101     void setSourceModel(QAbstractItemModel* model) override;
0102 };
0103 
0104 #endif // SPECIALDATESFILTER_H