summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-09-18 19:02:54 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-09-19 10:57:32 +0200
commita01bf8d93c2289c50fa4f24c15f6255e942ee82b (patch)
tree73ddff5d20ee2dc6c198ac4ce80295303c1f42b1
parentb2ef4a806bd5f8f81917a7c93d210cee123191af (diff)
downloadrockbox-a01bf8d93c2289c50fa4f24c15f6255e942ee82b.tar.gz
rockbox-a01bf8d93c2289c50fa4f24c15f6255e942ee82b.tar.bz2
rockbox-a01bf8d93c2289c50fa4f24c15f6255e942ee82b.zip
qeditor: move backend selector to its own class, that's cleaner
Change-Id: I7f3fa66a8f67639b4b64cf9f6acc5fb10e227653 Reviewed-on: http://gerrit.rockbox.org/974 Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
-rw-r--r--utils/regtools/qeditor/regtab.cpp155
-rw-r--r--utils/regtools/qeditor/regtab.h24
-rw-r--r--utils/regtools/qeditor/utils.cpp137
-rw-r--r--utils/regtools/qeditor/utils.h43
4 files changed, 196 insertions, 163 deletions
diff --git a/utils/regtools/qeditor/regtab.cpp b/utils/regtools/qeditor/regtab.cpp
index 9fba9e9cb9..4c78c9e8b0 100644
--- a/utils/regtools/qeditor/regtab.cpp
+++ b/utils/regtools/qeditor/regtab.cpp
@@ -113,14 +113,7 @@ RegTab::RegTab(Backend *backend, QWidget *parent)
m_right_panel = new QVBoxLayout;
QGroupBox *data_sel_group = new QGroupBox("Data selection");
QHBoxLayout *data_sel_layout = new QHBoxLayout;
- m_data_selector = new QComboBox;
- m_data_selector->addItem(QIcon::fromTheme("text-x-generic"), "Explore", QVariant(DataSelNothing));
- m_data_selector->addItem(QIcon::fromTheme("document-open"), "File...", QVariant(DataSelFile));
-#ifdef HAVE_HWSTUB
- m_data_selector->addItem(QIcon::fromTheme("multimedia-player"), "Device...", QVariant(DataSelDevice));
-#endif
- m_data_sel_edit = new QLineEdit;
- m_data_sel_edit->setReadOnly(true);
+ 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;
@@ -129,13 +122,7 @@ RegTab::RegTab(Backend *backend, QWidget *parent)
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_data_selector);
- data_sel_layout->addWidget(m_data_sel_edit, 1);
- data_sel_layout->addStretch(0);
-#ifdef HAVE_HWSTUB
- m_dev_selector = new QComboBox;
- data_sel_layout->addWidget(m_dev_selector, 1);
-#endif
+ 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);
@@ -158,29 +145,24 @@ RegTab::RegTab(Backend *backend, QWidget *parent)
connect(m_backend, SIGNAL(OnSocListChanged()), this, SLOT(OnSocListChanged()));
connect(m_reg_tree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
this, SLOT(OnRegItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
- connect(m_data_selector, SIGNAL(activated(int)),
- this, SLOT(OnDataSelChanged(int)));
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 *)));
-#ifdef HAVE_HWSTUB
- connect(m_dev_selector, SIGNAL(currentIndexChanged(int)),
- this, SLOT(OnDevChanged(int)));
-#endif
+ 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();
- OnDataSelChanged(0);
+ SetDataSocName("");
}
RegTab::~RegTab()
{
-#ifdef HAVE_HWSTUB
- ClearDevList();
-#endif
- delete m_io_backend;
+ /* backend will be deleted by backend selector */
}
bool RegTab::Quit()
@@ -210,79 +192,15 @@ void RegTab::OnDataSocActivated(const QString& str)
m_soc_selector->setCurrentIndex(index);
}
-void RegTab::OnDataSelChanged(int index)
+void RegTab::OnBackendSelect(IoBackend *backend)
{
- if(index == -1)
- return;
- QVariant var = m_data_selector->itemData(index);
- if(var == DataSelFile)
- {
- m_data_sel_edit->show();
-#ifdef HAVE_HWSTUB
- m_dev_selector->hide();
-#endif
- m_readonly_check->show();
- m_data_sel_reload->show();
- m_dump->hide();
- QFileDialog *fd = new QFileDialog(m_data_selector);
- fd->setFilter("Textual files (*.txt);;All files (*)");
- fd->setDirectory(Settings::Get()->value("loaddatadir", QDir::currentPath()).toString());
- if(fd->exec())
- {
- QStringList filenames = fd->selectedFiles();
- delete m_io_backend;
- m_io_backend = m_backend->CreateFileIoBackend(filenames[0]);
- m_data_sel_edit->setText(filenames[0]);
- SetDataSocName(m_io_backend->GetSocName());
- OnDataSocActivated(m_io_backend->GetSocName());
- }
- Settings::Get()->setValue("loaddatadir", fd->directory().absolutePath());
- SetReadOnlyIndicator();
- }
-#ifdef HAVE_HWSTUB
- else if(var == DataSelDevice)
- {
- m_data_sel_edit->hide();
- m_readonly_check->show();
- m_dev_selector->show();
- m_data_sel_reload->hide();
- m_dump->show();
- OnDevListChanged();
- }
-#endif
- else
- {
- m_data_sel_edit->show();
-#ifdef HAVE_HWSTUB
- m_dev_selector->hide();
-#endif
- m_readonly_check->hide();
- m_data_sel_reload->hide();
- m_dump->hide();
-
- delete m_io_backend;
- m_io_backend = m_backend->CreateDummyIoBackend();
- m_readonly_check->setCheckState(Qt::Checked);
- SetDataSocName("");
- UpdateSocFilename();
- }
+ m_io_backend = backend;
+ SetReadOnlyIndicator();
+ SetDataSocName(m_io_backend->GetSocName());
+ OnDataSocActivated(m_io_backend->GetSocName());
OnDataChanged();
}
-void RegTab::UpdateSocFilename()
-{
- int index = m_data_selector->currentIndex();
- if(index == -1)
- return;
- if(m_data_selector->itemData(index) != DataSelNothing)
- return;
- index = m_soc_selector->currentIndex();
- if(index == -1)
- return;
- SocRef ref = m_soc_selector->itemData(index).value< SocRef >();
- m_data_sel_edit->setText(ref.GetSocFile()->GetFilename());
-}
-
void RegTab::SetReadOnlyIndicator()
{
if(m_io_backend->IsReadOnly())
@@ -371,51 +289,6 @@ void RegTab::OnSocListChanged()
}
}
-#ifdef HAVE_HWSTUB
-void RegTab::OnDevListChanged()
-{
- ClearDevList();
- QList< HWStubDevice* > list = m_hwstub_helper.GetDevList();
- foreach(HWStubDevice *dev, list)
- {
- QString name = QString("Bus %1 Device %2: %3").arg(dev->GetBusNumber())
- .arg(dev->GetDevAddress()).arg(dev->GetTargetInfo().bName);
- m_dev_selector->addItem(QIcon::fromTheme("multimedia-player"), name,
- QVariant::fromValue((void *)dev));
- }
- if(list.size() > 0)
- m_dev_selector->setCurrentIndex(0);
- else
- SetDataSocName("");
- SetReadOnlyIndicator();
-}
-
-void RegTab::OnDevChanged(int index)
-{
- if(index == -1)
- return;
- HWStubDevice *dev = reinterpret_cast< HWStubDevice* >(m_dev_selector->itemData(index).value< void* >());
- delete m_io_backend;
- /* NOTE: make a copy of the HWStubDevice device because the one in the list
- * might get destroyed when clearing the list while the backend is still
- * active: this would result in a double free when the backend is also destroyed */
- m_io_backend = m_backend->CreateHWStubIoBackend(new HWStubDevice(dev));
- SetDataSocName(m_io_backend->GetSocName());
- OnDataSocActivated(m_io_backend->GetSocName());
- OnDataChanged();
-}
-
-void RegTab::ClearDevList()
-{
- while(m_dev_selector->count() > 0)
- {
- HWStubDevice *dev = reinterpret_cast< HWStubDevice* >(m_dev_selector->itemData(0).value< void* >());
- delete dev;
- m_dev_selector->removeItem(0);
- }
-}
-#endif
-
void RegTab::FillDevSubTree(QTreeWidgetItem *_item)
{
DevTreeItem *item = dynamic_cast< DevTreeItem* >(_item);
@@ -472,7 +345,6 @@ void RegTab::OnSocChanged(int index)
m_cur_soc = m_soc_selector->itemData(index).value< SocRef >();
FillRegTree();
FillAnalyserList();
- UpdateSocFilename();
}
void RegTab::OnReadOnlyClicked(bool checked)
@@ -480,7 +352,6 @@ void RegTab::OnReadOnlyClicked(bool checked)
if(m_io_backend->IsReadOnly())
return SetReadOnlyIndicator();
m_right_content->AllowWrite(!checked);
- UpdateSocFilename();
}
void RegTab::OnDumpRegs(bool c)
diff --git a/utils/regtools/qeditor/regtab.h b/utils/regtools/qeditor/regtab.h
index 5c694464ab..f93c68278c 100644
--- a/utils/regtools/qeditor/regtab.h
+++ b/utils/regtools/qeditor/regtab.h
@@ -17,6 +17,7 @@
#include "backend.h"
#include "settings.h"
#include "mainwindow.h"
+#include "utils.h"
class RegTabPanel
{
@@ -47,15 +48,6 @@ signals:
void OnModified(bool modified);
protected:
- enum
- {
- DataSelNothing,
- DataSelFile,
- #ifdef HAVE_HWSTUB
- DataSelDevice,
- #endif
- };
-
void FillDevSubTree(QTreeWidgetItem *item);
void FillSocSubTree(QTreeWidgetItem *item);
void FillRegTree();
@@ -69,37 +61,27 @@ protected:
void UpdateSocFilename();
QComboBox *m_soc_selector;
-#ifdef HAVE_HWSTUB
- QComboBox *m_dev_selector;
- HWStubBackendHelper m_hwstub_helper;
-#endif
+ BackendSelector *m_backend_selector;
Backend *m_backend;
QTreeWidget *m_reg_tree;
SocRef m_cur_soc;
QVBoxLayout *m_right_panel;
RegTabPanel *m_right_content;
- QLineEdit *m_data_sel_edit;
QCheckBox *m_readonly_check;
QLabel *m_data_soc_label;
QPushButton *m_data_sel_reload;
QPushButton *m_dump;
- QComboBox *m_data_selector;
IoBackend *m_io_backend;
QTabWidget *m_type_selector;
QListWidget *m_analysers_list;
private slots:
-#ifdef HAVE_HWSTUB
- void OnDevListChanged();
- void OnDevChanged(int index);
- void ClearDevList();
-#endif
void SetReadOnlyIndicator();
void OnSocChanged(int index);
void OnSocListChanged();
void OnRegItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void OnRegItemClicked(QTreeWidgetItem *clicked, int col);
- void OnDataSelChanged(int index);
+ void OnBackendSelect(IoBackend *backend);
void OnDataChanged();
void OnDataSocActivated(const QString&);
void OnAnalyserChanged(QListWidgetItem *current, QListWidgetItem *previous);
diff --git a/utils/regtools/qeditor/utils.cpp b/utils/regtools/qeditor/utils.cpp
index 1662169bdb..0719eecf7c 100644
--- a/utils/regtools/qeditor/utils.cpp
+++ b/utils/regtools/qeditor/utils.cpp
@@ -798,3 +798,140 @@ bool MySwitchableTextEditor::IsModified()
return false;
return m_line_mode ? m_line->isModified() : m_edit->IsModified();
}
+
+/**
+ * BackendSelector
+ */
+BackendSelector::BackendSelector(Backend *backend, QWidget *parent)
+ :QWidget(parent), m_backend(backend)
+{
+ m_data_selector = new QComboBox;
+ m_data_selector->addItem(QIcon::fromTheme("text-x-generic"), "Nothing...", QVariant(DataSelNothing));
+ m_data_selector->addItem(QIcon::fromTheme("document-open"), "File...", QVariant(DataSelFile));
+#ifdef HAVE_HWSTUB
+ m_data_selector->addItem(QIcon::fromTheme("multimedia-player"), "Device...", QVariant(DataSelDevice));
+#endif
+ m_data_sel_edit = new QLineEdit;
+ m_data_sel_edit->setReadOnly(true);
+ QHBoxLayout *data_sel_layout = new QHBoxLayout(this);
+ data_sel_layout->addWidget(m_data_selector);
+ data_sel_layout->addWidget(m_data_sel_edit, 1);
+ data_sel_layout->addStretch(0);
+#ifdef HAVE_HWSTUB
+ m_dev_selector = new QComboBox;
+ data_sel_layout->addWidget(m_dev_selector, 1);
+#endif
+
+ m_io_backend = m_backend->CreateDummyIoBackend();
+
+ connect(m_data_selector, SIGNAL(activated(int)),
+ this, SLOT(OnDataSelChanged(int)));
+#ifdef HAVE_HWSTUB
+ connect(m_dev_selector, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(OnDevChanged(int)));
+#endif
+ OnDataSelChanged(0);
+}
+
+BackendSelector::~BackendSelector()
+{
+#ifdef HAVE_HWSTUB
+ ClearDevList();
+#endif
+ delete m_io_backend;
+}
+
+void BackendSelector::OnDataSelChanged(int index)
+{
+ if(index == -1)
+ return;
+ QVariant var = m_data_selector->itemData(index);
+ if(var == DataSelFile)
+ {
+ m_data_sel_edit->show();
+#ifdef HAVE_HWSTUB
+ m_dev_selector->hide();
+#endif
+ QFileDialog *fd = new QFileDialog(m_data_selector);
+ fd->setFilter("Textual files (*.txt);;All files (*)");
+ fd->setDirectory(Settings::Get()->value("loaddatadir", QDir::currentPath()).toString());
+ if(fd->exec())
+ {
+ QStringList filenames = fd->selectedFiles();
+ ChangeBackend(m_backend->CreateFileIoBackend(filenames[0]));
+ m_data_sel_edit->setText(filenames[0]);
+ }
+ Settings::Get()->setValue("loaddatadir", fd->directory().absolutePath());
+ }
+#ifdef HAVE_HWSTUB
+ else if(var == DataSelDevice)
+ {
+ m_data_sel_edit->hide();;
+ m_dev_selector->show();
+ OnDevListChanged();
+ }
+#endif
+ else
+ {
+ m_data_sel_edit->hide();
+#ifdef HAVE_HWSTUB
+ m_dev_selector->hide();
+#endif
+
+ ChangeBackend(m_backend->CreateDummyIoBackend());
+ }
+}
+
+#ifdef HAVE_HWSTUB
+void BackendSelector::OnDevListChanged()
+{
+ ClearDevList();
+ QList< HWStubDevice* > list = m_hwstub_helper.GetDevList();
+ foreach(HWStubDevice *dev, list)
+ {
+ QString name = QString("Bus %1 Device %2: %3").arg(dev->GetBusNumber())
+ .arg(dev->GetDevAddress()).arg(dev->GetTargetInfo().bName);
+ m_dev_selector->addItem(QIcon::fromTheme("multimedia-player"), name,
+ QVariant::fromValue((void *)dev));
+ }
+ if(list.size() > 0)
+ m_dev_selector->setCurrentIndex(0);
+}
+
+void BackendSelector::OnDevChanged(int index)
+{
+ if(index == -1)
+ return;
+ HWStubDevice *dev = reinterpret_cast< HWStubDevice* >(m_dev_selector->itemData(index).value< void* >());
+ delete m_io_backend;
+ /* NOTE: make a copy of the HWStubDevice device because the one in the list
+ * might get destroyed when clearing the list while the backend is still
+ * active: this would result in a double free when the backend is also destroyed */
+ m_io_backend = m_backend->CreateHWStubIoBackend(new HWStubDevice(dev));
+ emit OnSelect(m_io_backend);
+}
+
+void BackendSelector::ClearDevList()
+{
+ while(m_dev_selector->count() > 0)
+ {
+ HWStubDevice *dev = reinterpret_cast< HWStubDevice* >(m_dev_selector->itemData(0).value< void* >());
+ delete dev;
+ m_dev_selector->removeItem(0);
+ }
+}
+#endif
+
+IoBackend *BackendSelector::GetBackend()
+{
+ return m_io_backend;
+}
+
+void BackendSelector::ChangeBackend(IoBackend *new_backend)
+{
+ /* WARNING: delete old backend *after* calling the signal, otherwise the old backend
+ * might get used after delete */
+ emit OnSelect(new_backend);
+ delete m_io_backend;
+ m_io_backend = new_backend;
+}
diff --git a/utils/regtools/qeditor/utils.h b/utils/regtools/qeditor/utils.h
index ee08f1f31b..56d4962492 100644
--- a/utils/regtools/qeditor/utils.h
+++ b/utils/regtools/qeditor/utils.h
@@ -15,6 +15,9 @@
#include <QHBoxLayout>
#include <QItemEditorCreatorBase>
#include <QStyledItemDelegate>
+#include <QComboBox>
+#include <QFileDialog>
+#include "settings.h"
#include "backend.h"
class SocBitRangeValidator : public QValidator
@@ -274,4 +277,44 @@ protected:
QLineEdit *m_line;
};
+class BackendSelector : public QWidget
+{
+ Q_OBJECT
+public:
+ BackendSelector(Backend *backend, QWidget *parent = 0);
+ virtual ~BackendSelector();
+ IoBackend *GetBackend();
+
+signals:
+ void OnSelect(IoBackend *backend);
+
+protected:
+ enum
+ {
+ DataSelNothing,
+ DataSelFile,
+#ifdef HAVE_HWSTUB
+ DataSelDevice,
+#endif
+ };
+
+ Backend *m_backend;
+ IoBackend *m_io_backend;
+ QComboBox *m_data_selector;
+ QLineEdit *m_data_sel_edit;
+#ifdef HAVE_HWSTUB
+ QComboBox *m_dev_selector;
+ HWStubBackendHelper m_hwstub_helper;
+#endif
+ void ChangeBackend(IoBackend *new_backend);
+
+private slots:
+#ifdef HAVE_HWSTUB
+ void OnDevListChanged();
+ void OnDevChanged(int index);
+ void ClearDevList();
+#endif
+ void OnDataSelChanged(int index);
+};
+
#endif /* AUX_H */