File indexing completed on 2024-05-12 05:10:47
0001 /* 0002 SPDX-FileCopyrightText: 2012 Sérgio Martins <iamsergio@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadi-calendar_export.h" 0010 #include <Akonadi/Item> 0011 0012 #include <QAbstractProxyModel> 0013 0014 #include <memory> 0015 0016 namespace Akonadi 0017 { 0018 0019 class IncidenceTreeModelPrivate; 0020 0021 /** Hierarchical incidence model. 0022 * Useful as a source for TodoModel for example. 0023 */ 0024 class AKONADI_CALENDAR_EXPORT IncidenceTreeModel : public QAbstractProxyModel 0025 { 0026 Q_OBJECT 0027 public: 0028 /** 0029 * Constructs a new IncidenceTreeModel. 0030 */ 0031 explicit IncidenceTreeModel(QObject *parent = nullptr); 0032 0033 /** 0034 * Constructs a new IncidenceTreeModel which will only show incidences of 0035 * type @p mimeTypes. Common use case is a to-do tree. 0036 * 0037 * This constructor is offered for performance reasons. The filtering has 0038 * zero overhead, and we avoid stacking mime type filter proxy models. 0039 * 0040 * If you're more concerned about clean design than performance, use the default 0041 * constructor and stack a Akonadi::EntityMimeTypeFilterModel on top of this one. 0042 */ 0043 explicit IncidenceTreeModel(const QStringList &mimeTypes, QObject *parent = nullptr); 0044 0045 ~IncidenceTreeModel() override; 0046 0047 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0048 [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0049 0050 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override; 0051 0052 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0053 0054 [[nodiscard]] QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; 0055 [[nodiscard]] QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; 0056 0057 [[nodiscard]] QModelIndex parent(const QModelIndex &child) const override; 0058 0059 void setSourceModel(QAbstractItemModel *sourceModel) override; 0060 [[nodiscard]] bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 0061 0062 /** 0063 * Returns the akonadi item containing the incidence with @p incidenceUid. 0064 */ 0065 [[nodiscard]] Akonadi::Item item(const QString &incidenceUid) const; 0066 0067 Q_SIGNALS: 0068 /** 0069 * This signal is emitted whenever an index changes parent. 0070 * The view can then expand the parent if desired. 0071 * This is better than the view waiting for "rows moved" signals because those 0072 * signals are also sent when the model is initially populated. 0073 */ 0074 void indexChangedParent(const QModelIndex &index); 0075 0076 /** 0077 * Signals that we finished doing a batch of insertions. 0078 * 0079 * One rowsInserted() signal from the ETM, will make IncidenceTreeModel generate 0080 * several rowsInserted(), layoutChanged() or rowsMoved() signals. 0081 * 0082 * A tree view can use this signal to know when to call KConfigViewStateSaver::restore() 0083 * to restore expansion states. Listening to rowsInserted() signals would be a 0084 * performance problem. 0085 */ 0086 void batchInsertionFinished(); 0087 0088 private: 0089 friend class IncidenceTreeModelPrivate; 0090 std::unique_ptr<IncidenceTreeModelPrivate> const d; 0091 }; 0092 0093 }