| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef STACKHANDLER_H |
| 6 | #define STACKHANDLER_H |
| 7 | |
| 8 | #include "stackframe.h" |
| 9 | |
| 10 | #include <QAbstractItemModel> |
| 11 | |
| 12 | enum { |
| 13 | ItemActivatedRole = Qt::UserRole, |
| 14 | ItemClickedRole |
| 15 | }; |
| 16 | |
| 17 | class StackFrameModel : public QAbstractTableModel |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | |
| 21 | public: |
| 22 | explicit StackFrameModel(); |
| 23 | ~StackFrameModel() override; |
| 24 | |
| 25 | void setFrames(const StackFrames &frames, bool canExpand = false); |
| 26 | void setCurrentIndex(int index); |
| 27 | const StackFrameData &frameAt(int index) const { return stackFrames.at(index); } |
| 28 | int stackSize() const { return stackFrames.size(); } |
| 29 | void removeAll(); |
| 30 | QAbstractItemModel *model() { return this; } |
| 31 | bool isContentsValid() const { return contentsValid; } |
| 32 | StackFrameData currentFrame() const; |
| 33 | signals: |
| 34 | void stackChanged(); |
| 35 | void currentIndexChanged(); |
| 36 | |
| 37 | private: |
| 38 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 39 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
| 40 | QVariant data(const QModelIndex &index, int role) const override; |
| 41 | QVariant (int section, Qt::Orientation orientation, int role) const override; |
| 42 | bool setData(const QModelIndex &idx, const QVariant &data, int role) override; |
| 43 | |
| 44 | StackFrames stackFrames; |
| 45 | int currentIndex = -1; |
| 46 | bool canExpand = false; |
| 47 | bool contentsValid = false; |
| 48 | }; |
| 49 | |
| 50 | #endif // STACKHANDLER_H |
| 51 | |