5
5
6
6
namespace Ripes {
7
7
8
- ISAInstructionsModel::ISAInstructionsModel (QObject *parent) {}
8
+ InstructionItem::InstructionItem (const InstructionBase &instruction,
9
+ InstructionItem *parent)
10
+ : m_instruction(instruction), m_parent(parent) {
11
+ if (!parent)
12
+ m_children.push_back (std::make_unique<InstructionItem>(instruction, this ));
13
+ }
14
+
15
+ InstructionItem *InstructionItem::child () {
16
+ return m_children.size () > 0 ? m_children.at (0 ).get () : nullptr ;
17
+ }
18
+
19
+ const InstructionBase &InstructionItem::data () const { return m_instruction; }
9
20
10
- int ISAInstructionsModel::rowCount ( const QModelIndex &) const { return 0 ; }
21
+ InstructionItem * InstructionItem::parent () { return m_parent ; }
11
22
12
- int ISAInstructionsModel::columnCount (const QModelIndex &) const { return 0 ; }
23
+ bool InstructionItem::hasParent () const { return m_parent; }
24
+
25
+ ISAInstructionsModel::ISAInstructionsModel (QObject *parent) {
26
+ for (const auto &instr : ProcessorHandler::currentISA ()->instructions ()) {
27
+ m_instrItems.push_back (std::make_unique<InstructionItem>(*instr.get ()));
28
+ }
29
+ }
30
+
31
+ int ISAInstructionsModel::rowCount (const QModelIndex &parent) const {
32
+ if (parent.isValid ()) {
33
+ return parent.parent ().isValid () ? 0 : 1 ;
34
+ }
35
+ return m_instrItems.size ();
36
+ }
37
+
38
+ int ISAInstructionsModel::columnCount (const QModelIndex &) const { return 1 ; }
13
39
14
40
QVariant ISAInstructionsModel::data (const QModelIndex &index, int role) const {
15
- return {};
41
+ if (!index.isValid () || role != Qt::DisplayRole) {
42
+ return {};
43
+ }
44
+
45
+ const auto *item =
46
+ static_cast <const InstructionItem *>(index.internalPointer ());
47
+ return !item->hasParent () ? item->data ().name () : item->data ().description ();
48
+ }
49
+
50
+ Qt::ItemFlags ISAInstructionsModel::flags (const QModelIndex &index) const {
51
+ return index.isValid () ? QAbstractItemModel::flags (index)
52
+ : Qt::ItemFlags (Qt::NoItemFlags);
16
53
}
17
54
18
55
QVariant ISAInstructionsModel::headerData (int section,
@@ -21,6 +58,37 @@ QVariant ISAInstructionsModel::headerData(int section,
21
58
return {};
22
59
}
23
60
61
+ QModelIndex ISAInstructionsModel::index (int row, int column,
62
+ const QModelIndex &parent) const {
63
+ if (!hasIndex (row, column, parent)) {
64
+ return {};
65
+ }
66
+
67
+ if (parent.isValid ()) {
68
+ if (auto *child =
69
+ static_cast <InstructionItem *>(parent.internalPointer ())->child ()) {
70
+ return createIndex (row, column, child);
71
+ }
72
+ } else {
73
+ if (static_cast <size_t >(row) < m_instrItems.size ()) {
74
+ return createIndex (row, column, m_instrItems.at (row).get ());
75
+ }
76
+ }
77
+
78
+ return {};
79
+ }
80
+
81
+ QModelIndex ISAInstructionsModel::parent (const QModelIndex &index) const {
82
+ if (!index.isValid ()) {
83
+ return {};
84
+ }
85
+
86
+ auto *item = static_cast <InstructionItem *>(index.internalPointer ());
87
+ auto *parent = item->parent ();
88
+
89
+ return parent ? createIndex (0 , 0 , parent) : QModelIndex{};
90
+ }
91
+
24
92
SliderulesTab::SliderulesTab (QToolBar *toolbar, QWidget *parent)
25
93
: RipesTab(toolbar, parent), ui(new Ui::SliderulesTab) {
26
94
ui->setupUi (this );
@@ -30,6 +98,9 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
30
98
mainExtBox = ui->mainExtBox ;
31
99
baseExtCheckBox = ui->baseExtCheckBox ;
32
100
101
+ m_isaModel = std::make_unique<ISAInstructionsModel>();
102
+ ui->encodingTable ->setModel (m_isaModel.get ());
103
+
33
104
for (const auto &familyName : ISAFamilyNames) {
34
105
isaFamilyBox->addItem (familyName.second ,
35
106
QVariant (static_cast <int >(familyName.first )));
0 commit comments