File indexing completed on 2024-05-12 04:37:37

0001 /*
0002     SPDX-FileCopyrightText: 2008 Vladimir Prus <ghost@cs.msu.su>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_TREEMODEL_H
0008 #define KDEVPLATFORM_TREEMODEL_H
0009 
0010 #include <QAbstractItemModel>
0011 #include <QModelIndex>
0012 #include <QVariant>
0013 #include <QVector>
0014 #include <QString>
0015 
0016 #include <debugger/debuggerexport.h>
0017 
0018 namespace KDevelop {
0019 
0020 class TreeItem;
0021 class TreeModelPrivate;
0022 
0023 class KDEVPLATFORMDEBUGGER_EXPORT TreeModel : public QAbstractItemModel
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit TreeModel(const QVector<QString>& headers, QObject *parent = nullptr);
0029     void setRootItem(TreeItem *item);
0030     ~TreeModel() override;
0031 
0032     void expanded(const QModelIndex &index);
0033     void collapsed(const QModelIndex &index);
0034     void clicked(const QModelIndex &index);
0035 
0036     void setEditable(bool);
0037     TreeItem* root() const;
0038 
0039     enum {
0040         ItemRole = Qt::UserRole,
0041     };
0042 
0043 public: // QAbstractItemModel overrides
0044     QVariant data(const QModelIndex &index, int role) const override;
0045     Qt::ItemFlags flags(const QModelIndex &index) const override;
0046     QVariant headerData(int section, Qt::Orientation orientation,
0047                         int role = Qt::DisplayRole) const override;
0048     QModelIndex index(int row, int column,
0049                       const QModelIndex &parent = QModelIndex()) const override;
0050     QModelIndex parent(const QModelIndex &index) const override;
0051     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0052     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0053     bool setData(const QModelIndex& index, const QVariant& value,
0054                  int role) override;
0055 
0056 Q_SIGNALS:
0057     void itemChildrenReady();
0058 
0059 public:
0060     TreeItem* itemForIndex(const QModelIndex& index) const;
0061     QModelIndex indexForItem(TreeItem *item, int column) const;
0062 
0063     using QAbstractItemModel::beginInsertRows;
0064     using QAbstractItemModel::endInsertRows;
0065     using QAbstractItemModel::beginRemoveRows;
0066     using QAbstractItemModel::endRemoveRows;
0067     using QAbstractItemModel::dataChanged;
0068 
0069 private:
0070     const QScopedPointer<class TreeModelPrivate> d_ptr;
0071     Q_DECLARE_PRIVATE(TreeModel)
0072 };
0073 
0074 }
0075 
0076 #endif