28#include <QAbstractItemModel>
41class AstModel :
public QAbstractItemModel {
45 explicit AstModel(QObject *parent =
nullptr);
66 QModelIndex index(
int row,
int column,
67 const QModelIndex &parent = QModelIndex())
const override;
68 QModelIndex parent(
const QModelIndex &child)
const override;
69 int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
70 int columnCount(
const QModelIndex &parent = QModelIndex())
const override;
71 QVariant data(
const QModelIndex &index,
72 int role = Qt::DisplayRole)
const override;
73 QVariant headerData(
int section, Qt::Orientation orientation,
74 int role = Qt::DisplayRole)
const override;
75 Qt::ItemFlags flags(
const QModelIndex &index)
const override;
79 NodePtrRole = Qt::UserRole + 1
95 bool hasNodes()
const {
return root_ !=
nullptr; }
102 AstViewNode *getNodeFromIndex(
const QModelIndex &index)
const;
105 QModelIndex findNodeIndex(
AstViewNode *node)
const;
108 const std::vector<AstViewNode *> &
116 std::size_t totalNodeCount_ = 0;
117 QString emptyMessage_;
AST data structures and memory management.
void updateSelectionFromIndex(const QModelIndex &index)
Update selection from a QModelIndex (e.g., when user clicks directly).
bool hasNodes() const
Check if model has any nodes loaded.
int visibleNodeCount() const
Number of nodes currently visible.
void setTotalNodeCount(std::size_t count)
Set total node count for display.
void clear()
Clear model and delete AST.
void setRootNode(AstViewNode *root)
Set the root node of AST.
AstViewNode * selectedNode() const
Get currently selected node.
QModelIndex selectNode(AstViewNode *node)
Programmatically select node and get its model index.
void nodeSelected(AstViewNode *node)
Emitted when node is selected.
void setEmptyMessage(const QString &message)
Message shown when the model has no AST loaded.
Represents node in AST tree hierarchy.