DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
dbc_tree_model.h
1// SPDX-License-Identifier: MIT
2#ifndef DBC_TREE_MODEL_H
3#define DBC_TREE_MODEL_H
4
5#include "tree_node.h"
6#include <QAbstractItemModel>
7
11class DbcTreeModel : public QAbstractItemModel {
12public:
14 enum Column { Name,
15 CanId,
16 PayloadLength,
17 StartBit,
18 BitLength,
20 Signed,
21 Unit,
22 Comment,
23 ColumnCount };
24 // Metadata roles apply on every column; inapplicable roles return invalid QVariant.
26 enum Role { NodeTypeRole = Qt::UserRole + 1,
27 CanIdRole,
28 PayloadLengthRole,
29 StartBitRole,
30 BitLengthRole,
31 LittleEndianRole,
32 SignedRole,
33 UnitRole,
34 CommentRole,
35 ValueDescriptionsRole,
36 ExtendedRole };
37
39 explicit DbcTreeModel(QObject *parent = nullptr);
41 void SetTree(std::unique_ptr<TreeNode> root);
43 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
45 QModelIndex parent(const QModelIndex &child) const override;
47 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
49 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
51 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
53 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
55 Qt::ItemFlags flags(const QModelIndex &index) const override;
56
57private:
58 const TreeNode *Node(const QModelIndex &index) const;
59 std::unique_ptr<TreeNode> m_root;
60};
61#endif
Role
Typed metadata roles in addition to Qt display roles.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return the child count, capped at the Qt integer limit.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Return the fixed metadata column count for this model.
Column
Display columns for frame and signal metadata.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Return a child index; only column zero can have children.
void SetTree(std::unique_ptr< TreeNode > root)
Replace the tree and invalidate indexes; reject roots with a parent or non-root type.
Qt::ItemFlags flags(const QModelIndex &index) const override
Allow selecting and enabling valid indexes without editing.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Return horizontal display column titles.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Return display text or typed metadata for an index.
QModelIndex parent(const QModelIndex &child) const override
Return the parent in column zero, or an invalid index for frames.
Tree node for later use in model/view or other hierarchy consumers.
Definition tree_node.h:37
ByteOrder
Signal byte order used for runtime decoding.
Qt-independent metadata tree nodes.