1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
#include "regtab.h"
#include <QSizePolicy>
#include <QStringBuilder>
#include <QFileDialog>
#include <QDebug>
#include <QStyle>
#include <QMessageBox>
#include "backend.h"
#include "analyser.h"
#include "regdisplaypanel.h"
namespace
{
enum
{
RegTreeDevType = QTreeWidgetItem::UserType,
RegTreeRegType,
RegTreeSocType
};
class SocTreeItem : public QTreeWidgetItem
{
public:
SocTreeItem(const QString& string, const SocRef& ref)
:QTreeWidgetItem(QStringList(string), RegTreeSocType), m_ref(ref) {}
const SocRef& GetRef() { return m_ref; }
private:
SocRef m_ref;
};
class DevTreeItem : public QTreeWidgetItem
{
public:
DevTreeItem(const QString& string, const SocDevRef& ref)
:QTreeWidgetItem(QStringList(string), RegTreeDevType), m_ref(ref) {}
const SocDevRef& GetRef() { return m_ref; }
private:
SocDevRef m_ref;
};
class RegTreeItem : public QTreeWidgetItem
{
public:
RegTreeItem(const QString& string, const SocRegRef& ref)
:QTreeWidgetItem(QStringList(string), RegTreeRegType), m_ref(ref) {}
const SocRegRef& GetRef() { return m_ref; }
private:
SocRegRef m_ref;
};
}
/**
* EmptyRegTabPanel
*/
EmptyRegTabPanel::EmptyRegTabPanel(QWidget *parent)
:QWidget(parent)
{
QVBoxLayout *l = new QVBoxLayout;
l->addStretch();
setLayout(l);
}
void EmptyRegTabPanel::AllowWrite(bool en)
{
Q_UNUSED(en);
}
QWidget *EmptyRegTabPanel::GetWidget()
{
return this;
}
/**
* RegTab
*/
RegTab::RegTab(Backend *backend, QWidget *parent)
:QSplitter(parent), m_backend(backend)
{
QWidget *left = new QWidget;
this->addWidget(left);
this->setStretchFactor(0, 1);
QVBoxLayout *left_layout = new QVBoxLayout;
left->setLayout(left_layout);
QGroupBox *top_group = new QGroupBox("SOC selection");
QVBoxLayout *top_group_layout = new QVBoxLayout;
m_soc_selector = new QComboBox;
top_group_layout->addWidget(m_soc_selector);
top_group->setLayout(top_group_layout);
m_reg_tree = new QTreeWidget();
m_reg_tree->setColumnCount(1);
m_reg_tree->setHeaderLabel(QString("Name"));
m_analysers_list = new QListWidget;
m_type_selector = new QTabWidget;
m_type_selector->addTab(m_reg_tree, "Registers");
m_type_selector->addTab(m_analysers_list, "Analyzers");
m_type_selector->setTabPosition(QTabWidget::West);
left_layout->addWidget(top_group);
left_layout->addWidget(m_type_selector);
m_right_panel = new QVBoxLayout;
QGroupBox *data_sel_group = new QGroupBox("Data selection");
QHBoxLayout *data_sel_layout = new QHBoxLayout;
m_backend_selector = new BackendSelector(m_backend, this);
m_readonly_check = new QCheckBox("Read-only");
m_readonly_check->setCheckState(Qt::Checked);
m_data_soc_label = new QLabel;
m_dump = new QPushButton("Dump", this);
m_dump->setIcon(QIcon::fromTheme("system-run"));
m_data_sel_reload = new QPushButton(this);
m_data_sel_reload->setIcon(QIcon::fromTheme("view-refresh"));
m_data_sel_reload->setToolTip("Reload data");
data_sel_layout->addWidget(m_backend_selector);
data_sel_layout->addWidget(m_readonly_check);
data_sel_layout->addWidget(m_data_soc_label);
data_sel_layout->addWidget(m_dump);
data_sel_layout->addWidget(m_data_sel_reload);
data_sel_group->setLayout(data_sel_layout);
m_data_soc_label->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
m_right_panel->addWidget(data_sel_group, 0);
m_right_content = 0;
SetPanel(new EmptyRegTabPanel);
QWidget *w = new QWidget;
w->setLayout(m_right_panel);
this->addWidget(w);
this->setStretchFactor(1, 2);
m_io_backend = m_backend_selector->GetBackend();
connect(m_soc_selector, SIGNAL(currentIndexChanged(int)),
this, SLOT(OnSocChanged(int)));
connect(m_backend, SIGNAL(OnSocListChanged()), this, SLOT(OnSocListChanged()));
connect(m_reg_tree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
this, SLOT(OnRegItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
connect(m_data_soc_label, SIGNAL(linkActivated(const QString&)), this,
SLOT(OnDataSocActivated(const QString&)));
connect(m_analysers_list, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
this, SLOT(OnAnalyserChanged(QListWidgetItem *, QListWidgetItem *)));
connect(m_backend_selector, SIGNAL(OnSelect(IoBackend *)),
this, SLOT(OnBackendSelect(IoBackend *)));
connect(m_readonly_check, SIGNAL(clicked(bool)), this, SLOT(OnReadOnlyClicked(bool)));
connect(m_dump, SIGNAL(clicked(bool)), this, SLOT(OnDumpRegs(bool)));
connect(m_data_sel_reload, SIGNAL(clicked(bool)), this, SLOT(OnBackendReload(bool)));
connect(m_type_selector, SIGNAL(currentChanged(int)), this, SLOT(OnTypeChanged(int)));
OnSocListChanged();
SetDataSocName("");
}
RegTab::~RegTab()
{
/* backend will be deleted by backend selector */
}
bool RegTab::Quit()
{
return true;
}
void RegTab::SetDataSocName(const QString& socname)
{
if(socname.size() != 0)
{
m_data_soc_label->setText("<a href=\"" + socname + "\">" + socname + "</a>");
m_data_soc_label->setTextFormat(Qt::RichText);
m_data_soc_label->show();
}
else
{
m_data_soc_label->setText("");
m_data_soc_label->hide();
}
}
void RegTab::OnDataSocActivated(const QString& str)
{
int index = m_soc_selector->findText(str);
if(index != -1)
m_soc_selector->setCurrentIndex(index);
}
void RegTab::OnBackendSelect(IoBackend *backend)
{
m_io_backend = backend;
SetReadOnlyIndicator();
SetDataSocName(m_io_backend->GetSocName());
OnDataSocActivated(m_io_backend->GetSocName());
OnDataChanged();
}
void RegTab::SetReadOnlyIndicator()
{
if(m_io_backend->IsReadOnly())
m_readonly_check->setCheckState(Qt::Checked);
}
void RegTab::OnDataChanged()
{
OnRegItemChanged(m_reg_tree->currentItem(), m_reg_tree->currentItem());
}
void RegTab::OnRegItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous);
OnRegItemClicked(current, 0);
}
void RegTab::OnRegItemClicked(QTreeWidgetItem *current, int col)
{
Q_UNUSED(col);
if(current == 0)
return;
if(current->type() == RegTreeSocType)
{
SocTreeItem *item = dynamic_cast< SocTreeItem * >(current);
DisplaySoc(item->GetRef());
}
if(current->type() == RegTreeRegType)
{
RegTreeItem *item = dynamic_cast< RegTreeItem * >(current);
DisplayRegister(item->GetRef());
}
else if(current->type() == RegTreeDevType)
{
DevTreeItem *item = dynamic_cast< DevTreeItem * >(current);
DisplayDevice(item->GetRef());
}
}
void RegTab::OnAnalyserChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
Q_UNUSED(previous);
OnAnalyserClicked(current);
}
void RegTab::OnAnalyserClicked(QListWidgetItem *current)
{
if(current == 0)
return;
AnalyserFactory *ana = AnalyserFactory::GetAnalyserByName(current->text());
SetPanel(ana->Create(m_cur_soc, m_io_backend));
}
void RegTab::DisplayRegister(const SocRegRef& ref)
{
SetPanel(new RegDisplayPanel(this, m_io_backend, ref));
}
void RegTab::DisplayDevice(const SocDevRef& ref)
{
SetPanel(new DevDisplayPanel(this, ref));
}
void RegTab::DisplaySoc(const SocRef& ref)
{
SetPanel(new SocDisplayPanel(this, ref));
}
void RegTab::SetPanel(RegTabPanel *panel)
{
delete m_right_content;
m_right_content = panel;
m_right_content->AllowWrite(m_readonly_check->checkState() == Qt::Unchecked);
m_right_panel->addWidget(m_right_content->GetWidget(), 1);
}
void RegTab::OnSocListChanged()
{
m_soc_selector->clear();
QList< SocRef > socs = m_backend->GetSocList();
for(int i = 0; i < socs.size(); i++)
{
QVariant v;
v.setValue(socs[i]);
m_soc_selector->addItem(QString::fromStdString(socs[i].GetSoc().name), v);
}
}
void RegTab::FillDevSubTree(QTreeWidgetItem *_item)
{
DevTreeItem *item = dynamic_cast< DevTreeItem* >(_item);
const soc_dev_t& dev = item->GetRef().GetDev();
for(size_t i = 0; i < dev.reg.size(); i++)
{
const soc_reg_t& reg = dev.reg[i];
for(size_t j = 0; j < reg.addr.size(); j++)
{
RegTreeItem *reg_item = new RegTreeItem(reg.addr[j].name.c_str(),
SocRegRef(item->GetRef(), i, j));
item->addChild(reg_item);
}
}
}
void RegTab::FillSocSubTree(QTreeWidgetItem *_item)
{
SocTreeItem *item = dynamic_cast< SocTreeItem* >(_item);
const soc_t& soc = item->GetRef().GetSoc();
for(size_t i = 0; i < soc.dev.size(); i++)
{
const soc_dev_t& dev = soc.dev[i];
for(size_t j = 0; j < dev.addr.size(); j++)
{
DevTreeItem *dev_item = new DevTreeItem(dev.addr[j].name.c_str(),
SocDevRef(m_cur_soc, i, j));
FillDevSubTree(dev_item);
item->addChild(dev_item);
}
}
}
void RegTab::FillRegTree()
{
SocTreeItem *soc_item = new SocTreeItem(m_cur_soc.GetSoc().name.c_str(),
m_cur_soc);
FillSocSubTree(soc_item);
m_reg_tree->addTopLevelItem(soc_item);
m_reg_tree->expandItem(soc_item);
}
void RegTab::FillAnalyserList()
{
m_analysers_list->clear();
m_analysers_list->addItems(AnalyserFactory::GetAnalysersForSoc(m_cur_soc.GetSoc().name.c_str()));
}
void RegTab::OnSocChanged(int index)
{
if(index == -1)
return;
m_reg_tree->clear();
m_cur_soc = m_soc_selector->itemData(index).value< SocRef >();
FillRegTree();
FillAnalyserList();
}
void RegTab::OnReadOnlyClicked(bool checked)
{
if(m_io_backend->IsReadOnly())
return SetReadOnlyIndicator();
m_right_content->AllowWrite(!checked);
}
void RegTab::OnDumpRegs(bool c)
{
Q_UNUSED(c);
QFileDialog *fd = new QFileDialog(this);
fd->setAcceptMode(QFileDialog::AcceptSave);
fd->setFilter("Textual files (*.txt);;All files (*)");
fd->setDirectory(Settings::Get()->value("loaddatadir", QDir::currentPath()).toString());
if(!fd->exec())
return;
QStringList filenames = fd->selectedFiles();
Settings::Get()->setValue("loaddatadir", fd->directory().absolutePath());
BackendHelper bh(m_io_backend, m_cur_soc);
if(!bh.DumpAllRegisters(filenames[0]))
{
QMessageBox::warning(this, "The register dump was not saved",
"There was an error when dumping the registers");
}
}
void RegTab::OnBackendReload(bool c)
{
Q_UNUSED(c);
m_io_backend->Reload();
OnDataChanged();
}
void RegTab::OnTypeChanged(int index)
{
if(index == -1)
return;
if(index == 0) /* registers */
OnRegItemClicked(m_reg_tree->currentItem(), 0);
else if(index == 1) /* analysers */
OnAnalyserClicked(m_analysers_list->currentItem());
}
|