File indexing completed on 2024-04-28 15:51:39

0001 /*
0002     SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef ANNOTATIONPROXYMODEL_H
0008 #define ANNOTATIONPROXYMODEL_H
0009 
0010 #include <QPair>
0011 #include <QSortFilterProxyModel>
0012 
0013 /**
0014  * A proxy model, which filters out all pages except the
0015  * current one.
0016  */
0017 class PageFilterProxyModel : public QSortFilterProxyModel
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     /**
0023      * Creates a new page filter proxy model.
0024      *
0025      * @param parent The parent object.
0026      */
0027     explicit PageFilterProxyModel(QObject *parent = nullptr);
0028 
0029     /**
0030      * Reimplemented from QSortFilterProxy.
0031      */
0032     bool filterAcceptsRow(int, const QModelIndex &) const override;
0033 
0034 public Q_SLOTS:
0035     /**
0036      * Sets whether the proxy model shall filter
0037      * by current page.
0038      */
0039     void groupByCurrentPage(bool value);
0040 
0041     /**
0042      * Sets the current page.
0043      */
0044     void setCurrentPage(int page);
0045 
0046 private:
0047     bool mGroupByCurrentPage;
0048     int mCurrentPage;
0049 };
0050 
0051 /**
0052  * A proxy model which either groups the annotations by
0053  * pages or shows them all as list.
0054  */
0055 class PageGroupProxyModel : public QAbstractProxyModel
0056 {
0057     Q_OBJECT
0058 
0059 public:
0060     /**
0061      * Creates a new page group proxy model.
0062      *
0063      * @param parent The parent object.
0064      */
0065     explicit PageGroupProxyModel(QObject *parent = nullptr);
0066 
0067     int columnCount(const QModelIndex &parentIndex) const override;
0068     int rowCount(const QModelIndex &parentIndex) const override;
0069 
0070     QModelIndex index(int row, int column, const QModelIndex &parentIndex = QModelIndex()) const override;
0071     QModelIndex parent(const QModelIndex &idx) const override;
0072 
0073     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
0074     QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
0075 
0076     void setSourceModel(QAbstractItemModel *model) override;
0077 
0078 public Q_SLOTS:
0079     /**
0080      * Sets whether the proxy model shall group
0081      * the annotations by page.
0082      */
0083     void groupByPage(bool value);
0084 
0085 private Q_SLOTS:
0086     void rebuildIndexes();
0087     void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
0088 
0089 private:
0090     bool mGroupByPage;
0091     QList<QModelIndex> mIndexes;
0092     QList<QPair<QModelIndex, QList<QModelIndex>>> mTreeIndexes;
0093 };
0094 
0095 /**
0096  * A proxy model which groups the annotations by author.
0097  */
0098 class AuthorGroupProxyModel : public QAbstractProxyModel
0099 {
0100     Q_OBJECT
0101 
0102 public:
0103     /**
0104      * Creates a new author group proxy model.
0105      *
0106      * @param parent The parent object.
0107      */
0108     explicit AuthorGroupProxyModel(QObject *parent = nullptr);
0109     ~AuthorGroupProxyModel() override;
0110 
0111     int columnCount(const QModelIndex &parentIndex) const override;
0112     int rowCount(const QModelIndex &parentIndex) const override;
0113 
0114     QModelIndex index(int row, int column, const QModelIndex &parentIndex = QModelIndex()) const override;
0115     QModelIndex parent(const QModelIndex &index) const override;
0116 
0117     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
0118     QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
0119 
0120     void setSourceModel(QAbstractItemModel *model) override;
0121 
0122     QItemSelection mapSelectionToSource(const QItemSelection &selection) const override;
0123     QItemSelection mapSelectionFromSource(const QItemSelection &selection) const override;
0124     QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override;
0125     QMap<int, QVariant> itemData(const QModelIndex &index) const override;
0126     Qt::ItemFlags flags(const QModelIndex &index) const override;
0127 
0128 public Q_SLOTS:
0129     /**
0130      * Sets whether the proxy model shall group
0131      * the annotations by author.
0132      */
0133     void groupByAuthor(bool value);
0134 
0135 private Q_SLOTS:
0136     void rebuildIndexes();
0137     void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
0138 
0139 private:
0140     class Private;
0141     Private *const d;
0142 };
0143 
0144 #endif