Warning, file /office/skrooge/skgbasegui/skgsortfilterproxymodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGSORTFILTERPROXYMODEL_H
0007 #define SKGSORTFILTERPROXYMODEL_H
0008 /** @file
0009  * This file is a proxy model with better filter mechanism.
0010  *
0011  * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 
0014 
0015 #include "skgbasegui_export.h"
0016 #include <qsortfilterproxymodel.h>
0017 
0018 class SKGSortFilterProxyModelPrivate;
0019 
0020 /**
0021  * This class is a proxy model with better filter mechanism
0022  */
0023 class SKGBASEGUI_EXPORT SKGSortFilterProxyModel : public QSortFilterProxyModel
0024 {
0025     Q_OBJECT
0026     /**
0027      * The previous sort column
0028      */
0029     Q_PROPERTY(int previousSortColumn READ getPreviousSortColumn WRITE setPreviousSortColumn USER true NOTIFY previousSortColumnModified)
0030 
0031 public:
0032     /**
0033      * Constructor
0034      * @param iParent parent widget
0035      */
0036     explicit SKGSortFilterProxyModel(QObject* iParent = nullptr);
0037 
0038     /**
0039      * Destructor
0040      */
0041     ~SKGSortFilterProxyModel() override;
0042 
0043     /**
0044      * @brief Set the previous sort column (-1 = none).
0045      *
0046      * @param iCol the column index
0047      */
0048     virtual void setPreviousSortColumn(int iCol);
0049 
0050     /**
0051      * @brief Get the previous sort column (-1 = none).
0052      * @return the column index
0053      */
0054     virtual int getPreviousSortColumn() const;
0055 
0056 protected:
0057     /**
0058      * To know if a row must be displayed or not
0059      * @param source_row source row
0060      * @param source_parent prent
0061      * @return true of false
0062      */
0063     bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
0064 
0065     /**
0066      * To sort items
0067      * @param left left item
0068      * @param right right item
0069      * @return true of false
0070      */
0071     bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
0072 
0073 Q_SIGNALS:
0074     /**
0075      * This signal is launched when the property is modified
0076      */
0077     void previousSortColumnModified();
0078 
0079 private:
0080     bool filterAcceptsRowWords(int source_row, const QModelIndex& source_parent, const QStringList& iWords) const;
0081 
0082     bool lessThan(const QVariant& iLeftData, const QVariant& iRightData) const;
0083     bool moreThan(const QVariant& iLeftData, const QVariant& iRightData) const;
0084 
0085     SKGSortFilterProxyModelPrivate* const d;
0086 };
0087 
0088 #endif