Debian Codegraph @

src/DebuggableViewer.cpp

raw symbols SCIP
1 #include "DebuggableViewer.h"
2 #include "HexViewer.h"
3 #include <QComboBox>
4 #include <QVBoxLayout>
5
6 DebuggableViewer::DebuggableViewer(QWidget* parent)
7 : QWidget(parent)
8 {
9 // create selection list and viewer
10 debuggableList = new QComboBox();
11 debuggableList->setEditable(false);
12
13 hexView = new HexViewer();
14 hexView->setIsInteractive(true);
15 hexView->setIsEditable(true);
16
17 auto* vbox = new QVBoxLayout();
18 vbox->setMargin(0);
19 vbox->addWidget(debuggableList);
20 vbox->addWidget(hexView);
21 setLayout(vbox);
22
23 connect(hexView, &HexViewer::locationChanged,
24 this, &DebuggableViewer::locationChanged);
25 }
26
27 void DebuggableViewer::settingsChanged()
28 {
29 hexView->settingsChanged();
30 }
31
32 void DebuggableViewer::refresh()
33 {
34 hexView->refresh();
35 }
36
37 void DebuggableViewer::debuggableSelected(int index)
38 {
39 QString name = debuggableList->itemText(index);
40 int size = debuggableList->itemData(index).toInt();
41
42 if (index >= 0)
43 lastSelected = name;
44 // add braces when the name contains a space
45 if (name.contains(QChar(' '))) {
46 name.append(QChar('}'));
47 name.prepend(QChar('{'));
48 }
49 hexView->setDebuggable(name, size);
50 }
51
52 void DebuggableViewer::locationChanged(int loc)
53 {
54 lastLocation = loc;
55 }
56
57 void DebuggableViewer::setDebuggables(const QMap<QString, int>& list)
58 {
59 int select = -1;
60
61 // disconnect signal to prevent updates
62 debuggableList->disconnect(this);
63
64 debuggableList->clear();
65 for (auto it = list.begin(); it != list.end(); ++it) {
66 // set name and strip braces if necessary
67 QString name = it.key();
68 if (name.contains(QChar(' '))) {
69 name = name.mid(1, name.size() - 2);
70 }
71 // check if this was the previous selection
72 if (name == lastSelected)
73 select = debuggableList->count();
74
75 debuggableList->addItem(name, it.value());
76 }
77
78 // reconnect signal before selecting item
79 connect(debuggableList, qOverload<int>(&QComboBox::currentIndexChanged),
80 this, &DebuggableViewer::debuggableSelected);
81
82 if (!list.empty() && select >= 0) {
83 debuggableList->setCurrentIndex(select);
84 hexView->setLocation(lastLocation);
85 }
86 }