File indexing completed on 2024-06-23 05:06:44

0001 /*
0002     SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
0003                   2016 David Faure <faure@kde.org>s
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "akonadicore_export.h"
0011 
0012 #include <KExtraColumnsProxyModel>
0013 
0014 #include <memory>
0015 
0016 namespace Akonadi
0017 {
0018 class StatisticsProxyModelPrivate;
0019 
0020 /**
0021  * @short A proxy model that exposes collection statistics through extra columns.
0022  *
0023  * This class can be used on top of an EntityTreeModel to display extra columns
0024  * summarizing statistics of collections.
0025  *
0026  * @code
0027  *
0028  *   Akonadi::EntityTreeModel *model = new Akonadi::EntityTreeModel( ... );
0029  *
0030  *   Akonadi::StatisticsProxyModel *proxy = new Akonadi::StatisticsProxyModel();
0031  *   proxy->setSourceModel( model );
0032  *
0033  *   Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView( this );
0034  *   view->setModel( proxy );
0035  *
0036  * @endcode
0037  *
0038  * @author Kevin Ottens <ervin@kde.org>, now maintained by David Faure <faure@kde.org>
0039  * @since 4.4
0040  */
0041 class AKONADICORE_EXPORT StatisticsProxyModel : public KExtraColumnsProxyModel
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     /**
0047      * Creates a new statistics proxy model.
0048      *
0049      * @param parent The parent object.
0050      */
0051     explicit StatisticsProxyModel(QObject *parent = nullptr);
0052 
0053     /**
0054      * Destroys the statistics proxy model.
0055      */
0056     ~StatisticsProxyModel() override;
0057 
0058     /**
0059      * @param enable Display tooltips
0060      * By default, tooltips are disabled.
0061      */
0062     void setToolTipEnabled(bool enable);
0063 
0064     /**
0065      * Return true if we display tooltips, otherwise false
0066      */
0067     [[nodiscard]] bool isToolTipEnabled() const;
0068 
0069     /**
0070      * @param enable Display extra statistics columns
0071      * By default, the extra columns are enabled.
0072      */
0073     void setExtraColumnsEnabled(bool enable);
0074 
0075     /**
0076      * Return true if we display extra statistics columns, otherwise false
0077      */
0078     [[nodiscard]] bool isExtraColumnsEnabled() const;
0079 
0080     [[nodiscard]] QVariant extraColumnData(const QModelIndex &parent, int row, int extraColumn, int role) const override;
0081     [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0082     [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
0083 
0084     [[nodiscard]] QModelIndexList match(const QModelIndex &start,
0085                                         int role,
0086                                         const QVariant &value,
0087                                         int hits = 1,
0088                                         Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override;
0089 
0090     void setSourceModel(QAbstractItemModel *model) override;
0091 
0092 private:
0093     /// @cond PRIVATE
0094     std::unique_ptr<StatisticsProxyModelPrivate> const d;
0095     /// @endcond
0096 };
0097 
0098 }