This commit is contained in:
deeaitch committed 2026-10-06 17:14:50 -04:00
1 parent e5d818d9b2
commit a533d9aa00
13 files changed
+527 -12

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
#ifndef DBC_TREE_MODEL_H
#define DBC_TREE_MODEL_H
#include "tree_node.h"
#include <QAbstractItemModel>
/** Read-only model. Owns an immutable tree; all indexes expire on SetTree().
* Use QPersistentModelIndex to observe reset invalidation. Call on the model thread.
*/
class DbcTreeModel : public QAbstractItemModel {
public:
enum Column { Name,
CanId,
PayloadLength,
StartBit,
BitLength,
ByteOrder,
Signed,
Unit,
Comment,
ColumnCount };
// Metadata roles apply on every column; inapplicable roles return invalid QVariant.
enum Role { NodeTypeRole = Qt::UserRole + 1,
CanIdRole,
PayloadLengthRole,
StartBitRole,
BitLengthRole,
LittleEndianRole,
SignedRole,
UnitRole,
CommentRole,
ValueDescriptionsRole,
ExtendedRole };
explicit DbcTreeModel(QObject *parent = nullptr);
void SetTree(std::unique_ptr<TreeNode> root);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
private:
const TreeNode *Node(const QModelIndex &index) const;
std::unique_ptr<TreeNode> m_root;
};
#endif