#ifndef GITSTATUSMODEL_H #define GITSTATUSMODEL_H #include #include #include #include /** * Represents a single file entry in git status output. */ struct GitStatusEntry { QString file; // relative path QChar indexStatus; // X column from --porcelain=v1 QChar workStatus; // Y column from --porcelain=v1 }; /** * Tree model for displaying git status. * Has three top-level nodes: Staged, Changed (unstaged), Untracked. * Each node contains file entries. */ class GitStatusModel : public QAbstractItemModel { Q_OBJECT public: enum NodeType { NodeStaged = 0, NodeChanged, NodeUntracked, NodeCount }; enum Roles { FilePathRole = Qt::UserRole + 1, NodeTypeRole, }; explicit GitStatusModel(QObject *parent = nullptr); ~GitStatusModel() override = default; // --- QAbstractItemModel interface --- QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; QModelIndex parent(const QModelIndex &child) const override; int rowCount(const QModelIndex &parent = {}) const override; int columnCount(const QModelIndex &parent = {}) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; /** * Parse raw output from `git status --porcelain=v1` and populate the model. */ void parseStatus(const QByteArray &raw); /** * Get files for a given node type. */ const QList &entries(NodeType type) const { return m_entries[type]; } private: static constexpr quintptr TopLevelId = 0xFFFFFFFF; QList m_entries[NodeCount]; QString m_nodeNames[NodeCount]; QIcon m_nodeIcons[NodeCount]; }; #endif // GITSTATUSMODEL_H