File indexing completed on 2024-04-28 04:37:30

0001 /*
0002     SPDX-FileCopyrightText: 2007 Alexander Dymo <adymo@kdevelop.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_SUBLIMEAGGREGATEMODEL_H
0008 #define KDEVPLATFORM_SUBLIMEAGGREGATEMODEL_H
0009 
0010 #include <QAbstractItemModel>
0011 #include "sublimeexport.h"
0012 
0013 class QStandardItemModel;
0014 
0015 namespace Sublime {
0016 
0017 class AggregateModelPrivate;
0018 
0019 /**
0020 @short A model to combine several QStandardItemModel's into one.
0021 Combine standard models into the aggregate model to display them in the one view.
0022 
0023 Each new model gets its own parent item to differentiate items between different models,
0024 for example:
0025 
0026 Tea Model:
0027 @code
0028 - Black
0029 - Green
0030 - White
0031 @endcode
0032 Coffee Model:
0033 @code
0034 - Arabica
0035 - Robusta
0036 @endcode
0037 
0038 When aggregated with
0039 @code
0040     AggregateModel model;
0041     model->addModel("Tea", teaModel);
0042     model->addModel("Coffee", coffeeModel);
0043 @endcode
0044 they will look as:
0045 @code
0046 - Tea
0047     - Black
0048     - Green
0049     - White
0050 - Coffee
0051     - Arabica
0052     - Robusta
0053 @endcode
0054 
0055 @note It is impossible to aggregate any model, aggregation works only for standard models.
0056 @note Currently aggregate model displays only 1 column.
0057 */
0058 class KDEVPLATFORMSUBLIME_EXPORT AggregateModel: public QAbstractItemModel {
0059     Q_OBJECT
0060 public:
0061     explicit AggregateModel(QObject *parent = nullptr);
0062     ~AggregateModel() override;
0063 
0064     /**Adds the model and creates a parent item with given @p name
0065     in the aggregated model.*/
0066     void addModel(const QString &name, QStandardItemModel *model);
0067     /**Removes the model from aggregation.*/
0068     void removeModel(QStandardItemModel *model);
0069 
0070     //reimplemented methods from QAbstractItemModel
0071     Qt::ItemFlags flags(const QModelIndex &index) const override;
0072     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0073     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0074     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0075     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0076     QModelIndex parent(const QModelIndex &index) const override;
0077     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0078 
0079 private:
0080     const QScopedPointer<class AggregateModelPrivate> d_ptr;
0081     Q_DECLARE_PRIVATE(AggregateModel)
0082 };
0083 
0084 }
0085 
0086 #endif
0087