File indexing completed on 2024-05-26 05:56:50

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009, 2011 Alex Richardson <alex.richardson@gmx.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_STRUCTURETREEMODEL_HPP
0010 #define KASTEN_STRUCTURETREEMODEL_HPP
0011 
0012 #include <QAbstractItemModel>
0013 #include <QSet>
0014 
0015 class DataInformationBase;
0016 class DataInformation;
0017 
0018 namespace Kasten {
0019 class StructuresTool;
0020 
0021 class StructureTreeModel : public QAbstractItemModel
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     enum Roles {
0027         DataInformationRole = Qt::UserRole,
0028     };
0029 
0030 public:
0031     explicit StructureTreeModel(StructuresTool* tool, QObject* parent = nullptr);
0032     ~StructureTreeModel() override;
0033 
0034 public: // QAbstractItemModel API
0035     QVariant data(const QModelIndex& index, int role) const override;
0036     Qt::ItemFlags flags(const QModelIndex& index) const override;
0037     QMimeData* mimeData(const QModelIndexList& indexes) const override;
0038     QStringList mimeTypes() const override;
0039     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0040     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0041     QModelIndex parent(const QModelIndex& index) const override;
0042     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0043     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0044     bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
0045     bool hasChildren(const QModelIndex& parent = QModelIndex()) const override;
0046 
0047 private:
0048     QModelIndex findItemInModel(DataInformationBase* data) const;
0049 
0050 private Q_SLOTS:
0051     void onToolDataChange(int row, void* data);
0052     void onToolDataClear();
0053     void onChildrenAboutToBeRemoved(DataInformation* sender, uint startIndex, uint endIndex);
0054     void onChildrenAboutToBeInserted(DataInformation* sender, uint startIndex, uint endIndex);
0055     void onChildrenRemoved(const DataInformation* sender, uint startIndex, uint endIndex);
0056     void onChildrenInserted(const DataInformation* sender, uint startIndex, uint endIndex);
0057 
0058 private:
0059     StructuresTool* mTool;
0060     // just for checking in debug mode:
0061     DataInformation* mLastSender;
0062     uint mLastStartIndex;
0063     uint mLastEndIndex;
0064 };
0065 
0066 }
0067 
0068 #endif