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

0001 /*
0002     SPDX-FileCopyrightText: 2022 Thomas Baumgart <tbaumgart@kde.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef LEDGERSORTPROXYMODEL_H
0007 #define LEDGERSORTPROXYMODEL_H
0008 
0009 #include "kmm_models_export.h"
0010 
0011 // ----------------------------------------------------------------------------
0012 // QT Includes
0013 
0014 #include <QSortFilterProxyModel>
0015 #include <qglobal.h>
0016 
0017 // ----------------------------------------------------------------------------
0018 // KDE Includes
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 
0023 #include "ledgerviewsettings.h"
0024 #include "mymoneyenums.h"
0025 
0026 class LedgerSortProxyModelPrivate;
0027 class KMM_MODELS_EXPORT LedgerSortProxyModel : public QSortFilterProxyModel
0028 {
0029     Q_OBJECT
0030     Q_DECLARE_PRIVATE(LedgerSortProxyModel)
0031     Q_DISABLE_COPY(LedgerSortProxyModel)
0032 
0033 public:
0034     virtual ~LedgerSortProxyModel();
0035 
0036     /**
0037      * Reimplemented to support KMyMoney specific sort options
0038      */
0039     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
0040 
0041     /**
0042      * Sorts the model on the next return to the event loop
0043      */
0044     void sortOnIdle();
0045 
0046     bool inSorting() const;
0047 
0048     /**
0049      * This method changes the global filter for
0050      * all instances of LedgerSortProxyModel and derived objects to
0051      * filter out any transaction with a post date prior to
0052      * @a date. If @a date is an invalid QDate, then the
0053      * filter is inactive.
0054      */
0055     void setHideTransactionsBefore(const QDate& date);
0056 
0057     /**
0058      * This method changes the global filter for
0059      * all instances of LedgerSortProxyModel and derived objects to
0060      * filter out any reconciled transaction.
0061      */
0062     void setHideReconciledTransactions(bool hide);
0063 
0064     /**
0065      * Reimplemented for internal reasons
0066      */
0067     void setSourceModel(QAbstractItemModel* sourceModel) override;
0068 
0069     virtual void setLedgerSortOrder(LedgerSortOrder sortOrder);
0070 
0071     virtual LedgerSortOrder ledgerSortOrder() const;
0072 
0073     /**
0074      * This method can be used to temporarily prevent
0075      * sorting of the model. Once turned back on and
0076      * sort() was called in the meantime it will be
0077      * performed upon the run of the next event loop.
0078      *
0079      * @sa doSort()
0080      */
0081     virtual void setSortingEnabled(bool enable);
0082 
0083     /**
0084      * This method is used to process postponed sorting
0085      */
0086     virtual void doSortOnIdle();
0087 
0088 protected:
0089     explicit LedgerSortProxyModel(LedgerSortProxyModelPrivate* dd, QObject* parent);
0090 
0091     bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
0092 
0093     /**
0094      * @note This does not call the base class implementation for speed purposes
0095      */
0096     bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
0097 
0098     /**
0099      * This is a convenience method for sort()
0100      */
0101     virtual void doSort();
0102 
0103     /**
0104      * This is a debugging function for developers
0105      */
0106     void dumpSourceModel() const;
0107 
0108 protected:
0109     LedgerSortProxyModelPrivate* d_ptr;
0110 };
0111 
0112 #endif // LEDGERSORTPROXYMODEL_H