summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-09-18 21:36:17 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-09-19 10:58:33 +0200
commit970c2482dd22a84a5973b73621d0dd06e6f45a25 (patch)
tree3131c033b3f3e385eceed7beb16e8b143ff0caf1
parentdbb59291e745c7cc640a35fc40faa083648793bf (diff)
downloadrockbox-970c2482dd22a84a5973b73621d0dd06e6f45a25.tar.gz
rockbox-970c2482dd22a84a5973b73621d0dd06e6f45a25.tar.bz2
rockbox-970c2482dd22a84a5973b73621d0dd06e6f45a25.zip
qeditor: rework modified indicator, register tab names depend on content
Because Qt doesn't support QObject multiple inherance, it is a bit tricky to have a base class which interact with the UI. The register tab name now display: - file dump name (for dumps) - hwstub device path (for hwstub) And the register editor display the filename Change-Id: If2579992098c02627c67d560c824f1668e73bc45 Reviewed-on: http://gerrit.rockbox.org/979 Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
-rw-r--r--utils/regtools/qeditor/backend.h2
-rw-r--r--utils/regtools/qeditor/mainwindow.cpp53
-rw-r--r--utils/regtools/qeditor/mainwindow.h16
-rw-r--r--utils/regtools/qeditor/regedit.cpp64
-rw-r--r--utils/regtools/qeditor/regedit.h5
-rw-r--r--utils/regtools/qeditor/regtab.cpp32
-rw-r--r--utils/regtools/qeditor/regtab.h5
7 files changed, 129 insertions, 48 deletions
diff --git a/utils/regtools/qeditor/backend.h b/utils/regtools/qeditor/backend.h
index e876e9d286..de450143f1 100644
--- a/utils/regtools/qeditor/backend.h
+++ b/utils/regtools/qeditor/backend.h
@@ -99,6 +99,7 @@ public:
{ Q_UNUSED(addr); Q_UNUSED(value); Q_UNUSED(mode); return false; }
virtual bool IsDirty() { return m_dirty; }
virtual bool Commit();
+ QString GetFileName() { return m_filename; }
protected:
QString m_filename;
@@ -164,6 +165,7 @@ public:
virtual bool WriteRegister(soc_addr_t addr, soc_word_t value, WriteMode mode);
virtual bool IsDirty() { return false; }
virtual bool Commit() { return true; }
+ HWStubDevice *GetDevice() { return m_dev; }
protected:
QString m_soc;
diff --git a/utils/regtools/qeditor/mainwindow.cpp b/utils/regtools/qeditor/mainwindow.cpp
index 1a88ebb47e..58f9766761 100644
--- a/utils/regtools/qeditor/mainwindow.cpp
+++ b/utils/regtools/qeditor/mainwindow.cpp
@@ -14,6 +14,25 @@
#include "regtab.h"
#include "regedit.h"
+/**
+ * DocumentTab
+ */
+void DocumentTab::OnModified(bool modified)
+{
+ if(m_tab)
+ m_tab->SetTabModified(this, modified);
+}
+
+void DocumentTab::SetTabName(const QString& name)
+{
+ if(m_tab)
+ m_tab->SetTabName(this, name);
+}
+
+/**
+ * MyTabWidget
+ */
+
MyTabWidget::MyTabWidget()
{
setMovable(true);
@@ -21,6 +40,20 @@ MyTabWidget::MyTabWidget()
connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(OnCloseTab(int)));
}
+void MyTabWidget::SetTabModified(DocumentTab *doc, bool modified)
+{
+ int index = indexOf(doc->GetWidget());
+ if(modified)
+ setTabIcon(index, QIcon::fromTheme("document-save"));
+ else
+ setTabIcon(index, QIcon());
+}
+
+void MyTabWidget::SetTabName(DocumentTab *doc, const QString& name)
+{
+ setTabText(indexOf(doc->GetWidget()), name);
+}
+
bool MyTabWidget::CloseTab(int index)
{
QWidget *w = this->widget(index);
@@ -40,6 +73,10 @@ void MyTabWidget::OnCloseTab(int index)
CloseTab(index);
}
+/**
+ * MainWindow
+ */
+
MainWindow::MainWindow(Backend *backend)
:m_backend(backend)
{
@@ -144,20 +181,10 @@ void MainWindow::OnLoadDesc()
}
}
-void MainWindow::OnTabModified(bool modified)
-{
- QWidget *sender = qobject_cast< QWidget* >(QObject::sender());
- int index = m_tab->indexOf(sender);
- if(modified)
- m_tab->setTabIcon(index, QIcon::fromTheme("document-save"));
- else
- m_tab->setTabIcon(index, QIcon());
-}
-
-void MainWindow::AddTab(QWidget *tab, const QString& title)
+void MainWindow::AddTab(DocumentTab *doc, const QString& title)
{
- connect(tab, SIGNAL(OnModified(bool)), this, SLOT(OnTabModified(bool)));
- m_tab->setCurrentIndex(m_tab->addTab(tab, title));
+ m_tab->setCurrentIndex(m_tab->addTab(doc->GetWidget(), title));
+ doc->SetTabWidget(m_tab);
}
void MainWindow::OnNewRegTab()
diff --git a/utils/regtools/qeditor/mainwindow.h b/utils/regtools/qeditor/mainwindow.h
index b32b0647f5..47cfa6796d 100644
--- a/utils/regtools/qeditor/mainwindow.h
+++ b/utils/regtools/qeditor/mainwindow.h
@@ -7,11 +7,20 @@
#include "backend.h"
#include "settings.h"
+class MyTabWidget;
+
class DocumentTab
{
public:
+ DocumentTab() { m_tab = 0; }
virtual bool Quit() = 0;
- virtual void OnModified(bool modified) = 0;
+ virtual QWidget *GetWidget() = 0;
+ void SetTabWidget(MyTabWidget *tab) { m_tab = tab; }
+
+protected:
+ void OnModified(bool modified);
+ void SetTabName(const QString& name);
+ MyTabWidget *m_tab;
};
class MyTabWidget : public QTabWidget
@@ -20,6 +29,8 @@ class MyTabWidget : public QTabWidget
public:
MyTabWidget();
bool CloseTab(int index);
+ void SetTabModified(DocumentTab *tab, bool mod);
+ void SetTabName(DocumentTab *tab, const QString& name);
private slots:
void OnCloseTab(int index);
@@ -39,7 +50,7 @@ private:
void closeEvent(QCloseEvent *event);
protected:
- void AddTab(QWidget *tab, const QString& title);
+ void AddTab(DocumentTab *tab, const QString& title);
bool Quit();
private slots:
@@ -49,7 +60,6 @@ private slots:
void OnLoadDesc();
void OnNewRegTab();
void OnNewRegEdit();
- void OnTabModified(bool modified);
private:
MyTabWidget *m_tab;
diff --git a/utils/regtools/qeditor/regedit.cpp b/utils/regtools/qeditor/regedit.cpp
index bb1abc0825..316b5b0dc9 100644
--- a/utils/regtools/qeditor/regedit.cpp
+++ b/utils/regtools/qeditor/regedit.cpp
@@ -47,13 +47,13 @@ SocEditPanel::SocEditPanel(SocRef ref, QWidget *parent)
void SocEditPanel::OnNameEdited(const QString& text)
{
m_ref.GetSoc().name = text.toStdString();
- emit OnModified(m_name_edit->isModified());
+ OnModified(m_name_edit->isModified());
}
void SocEditPanel::OnTextEdited()
{
m_ref.GetSoc().desc = m_desc_edit->GetTextHtml().toStdString();
- emit OnModified(m_desc_edit->IsModified());
+ OnModified(m_desc_edit->IsModified());
}
/**
@@ -143,25 +143,25 @@ DevEditPanel::DevEditPanel(SocDevRef ref, QWidget *parent)
void DevEditPanel::OnNameEdited(const QString& text)
{
m_ref.GetDev().name = text.toStdString();
- emit OnModified(m_name_edit->isModified());
+ OnModified(m_name_edit->isModified());
}
void DevEditPanel::OnLongNameEdited(const QString& text)
{
m_ref.GetDev().long_name = text.toStdString();
- emit OnModified(m_long_name_edit->isModified());
+ OnModified(m_long_name_edit->isModified());
}
void DevEditPanel::OnVersionEdited(const QString& text)
{
m_ref.GetDev().version = text.toStdString();
- emit OnModified(m_version_edit->isModified());
+ OnModified(m_version_edit->isModified());
}
void DevEditPanel::OnDescEdited()
{
m_ref.GetDev().desc = m_desc_edit->GetTextHtml().toStdString();
- emit OnModified(m_desc_edit->IsModified());
+ OnModified(m_desc_edit->IsModified());
}
void DevEditPanel::CreateNewRow(int row)
@@ -206,7 +206,7 @@ void DevEditPanel::OnInstActivated(int row, int column)
{
m_ref.GetDev().addr.erase(m_ref.GetDev().addr.begin() + row);
m_instances_table->removeRow(row);
- emit OnModified(true);
+ OnModified(true);
}
else if(type == DevInstNewType)
{
@@ -228,12 +228,12 @@ void DevEditPanel::OnInstChanged(int row, int column)
if(column == DevInstNameColumn)
{
m_ref.GetDev().addr[row].name = item->text().toStdString();
- emit OnModified(true);
+ OnModified(true);
}
else if(column == DevInstAddrColumn)
{
m_ref.GetDev().addr[row].addr = item->data(Qt::DisplayRole).toUInt();
- emit OnModified(true);
+ OnModified(true);
}
}
@@ -389,7 +389,7 @@ void RegEditPanel::UpdateWarning(int row)
void RegEditPanel::OnFormulaStringChanged(const QString& text)
{
m_ref.GetReg().formula.string = text.toStdString();
- emit OnModified(true);
+ OnModified(true);
}
void RegEditPanel::OnFormulaGenerate(bool checked)
@@ -445,7 +445,7 @@ void RegEditPanel::OnFormulaChanged(int index)
return;
m_ref.GetReg().formula.type = static_cast< soc_reg_formula_type_t >(m_formula_combo->itemData(index).toInt());
UpdateFormula();
- emit OnModified(true);
+ OnModified(true);
}
void RegEditPanel::UpdateFormula()
@@ -470,7 +470,7 @@ void RegEditPanel::OnSctEdited(int state)
m_ref.GetReg().flags |= REG_HAS_SCT;
else
m_ref.GetReg().flags &= ~REG_HAS_SCT;
- emit OnModified(true);
+ OnModified(true);
}
void RegEditPanel::FillRow(int row, const soc_reg_addr_t& addr)
@@ -509,13 +509,13 @@ void RegEditPanel::CreateNewAddrRow(int row)
void RegEditPanel::OnNameEdited(const QString& text)
{
m_ref.GetReg().name = text.toStdString();
- emit OnModified(m_name_edit->isModified());
+ OnModified(m_name_edit->isModified());
}
void RegEditPanel::OnDescEdited()
{
m_ref.GetReg().desc = m_desc_edit->GetTextHtml().toStdString();
- emit OnModified(m_desc_edit->IsModified());
+ OnModified(m_desc_edit->IsModified());
}
void RegEditPanel::OnInstActivated(int row, int column)
@@ -527,7 +527,7 @@ void RegEditPanel::OnInstActivated(int row, int column)
{
m_ref.GetReg().addr.erase(m_ref.GetReg().addr.begin() + row);
m_instances_table->removeRow(row);
- emit OnModified(true);
+ OnModified(true);
}
else if(type == RegInstNewType)
{
@@ -549,12 +549,12 @@ void RegEditPanel::OnInstChanged(int row, int column)
if(column == RegInstNameColumn)
{
m_ref.GetReg().addr[row].name = item->text().toStdString();
- emit OnModified(true);
+ OnModified(true);
}
else if(column == RegInstAddrColumn)
{
m_ref.GetReg().addr[row].addr = item->data(Qt::DisplayRole).toUInt();
- emit OnModified(true);
+ OnModified(true);
}
}
@@ -707,19 +707,19 @@ void FieldEditPanel::OnBitRangeEdited(const QString& input)
UpdateWarning(row);
// also updates delegates because they now have the wrong view of the field
UpdateDelegates();
- emit OnModified(true);
+ OnModified(true);
}
void FieldEditPanel::OnNameEdited(const QString& text)
{
m_ref.GetField().name = text.toStdString();
- emit OnModified(m_name_edit->isModified());
+ OnModified(m_name_edit->isModified());
}
void FieldEditPanel::OnDescEdited()
{
m_ref.GetField().desc = m_desc_edit->GetTextHtml().toStdString();
- emit OnModified(m_desc_edit->IsModified());
+ OnModified(m_desc_edit->IsModified());
}
void FieldEditPanel::OnValueActivated(int row, int column)
@@ -731,7 +731,7 @@ void FieldEditPanel::OnValueActivated(int row, int column)
{
m_ref.GetField().value.erase(m_ref.GetField().value.begin() + row);
m_value_table->removeRow(row);
- emit OnModified(true);
+ OnModified(true);
}
else if(type == FieldValueNewType)
{
@@ -766,7 +766,7 @@ void FieldEditPanel::OnValueChanged(int row, int column)
}
else if(column == FieldValueDescColumn)
m_ref.GetField().value[row].desc = item->text().toStdString();
- emit OnModified(true);
+ OnModified(true);
}
namespace
@@ -952,6 +952,11 @@ RegEdit::RegEdit(Backend *backend, QWidget *parent)
this, SLOT(OnSocItemActivated(QTreeWidgetItem*, int)));
}
+QWidget *RegEdit::GetWidget()
+{
+ return this;
+}
+
RegEdit::~RegEdit()
{
}
@@ -1052,6 +1057,12 @@ bool RegEdit::SaveSocFile(const QString& filename)
return true;
}
+void RegEdit::UpdateTabName()
+{
+ QFileInfo info(m_cur_socfile.GetFilename());
+ SetTabName(info.fileName());
+}
+
void RegEdit::LoadSocFile(const QString& filename)
{
m_cur_socfile = SocFile(filename);
@@ -1064,6 +1075,7 @@ void RegEdit::LoadSocFile(const QString& filename)
m_file_edit->setText(filename);
SetModified(false, false);
UpdateSocFile();
+ UpdateTabName();
}
void RegEdit::CreateNewFieldItem(QTreeWidgetItem *_parent)
@@ -1192,7 +1204,7 @@ void RegEdit::SetPanel(QWidget *panel)
void RegEdit::SetModified(bool add, bool mod)
{
m_modified = add ? (m_modified || mod) : mod;
- emit OnModified(mod);
+ OnModified(mod);
}
namespace
@@ -1360,7 +1372,7 @@ void RegEdit::AddDevice(QTreeWidgetItem *_item)
item->parent()->insertChild(item->parent()->indexOfChild(item), dev_item);
CreateNewRegisterItem(dev_item);
m_soc_tree->setCurrentItem(dev_item);
- emit OnModified(true);
+ OnModified(true);
}
void RegEdit::AddRegister(QTreeWidgetItem *_item)
@@ -1373,7 +1385,7 @@ void RegEdit::AddRegister(QTreeWidgetItem *_item)
item->parent()->insertChild(item->parent()->indexOfChild(item), reg_item);
CreateNewFieldItem(reg_item);
m_soc_tree->setCurrentItem(reg_item);
- emit OnModified(true);
+ OnModified(true);
}
void RegEdit::AddField(QTreeWidgetItem *_item)
@@ -1385,7 +1397,7 @@ void RegEdit::AddField(QTreeWidgetItem *_item)
FixupEmptyItem(field_item);
item->parent()->insertChild(item->parent()->indexOfChild(item), field_item);
m_soc_tree->setCurrentItem(field_item);
- emit OnModified(true);
+ OnModified(true);
}
bool RegEdit::Quit()
diff --git a/utils/regtools/qeditor/regedit.h b/utils/regtools/qeditor/regedit.h
index cec92d7c03..049da4ee16 100644
--- a/utils/regtools/qeditor/regedit.h
+++ b/utils/regtools/qeditor/regedit.h
@@ -226,9 +226,7 @@ public:
RegEdit(Backend *backend, QWidget *parent = 0);
~RegEdit();
virtual bool Quit();
-
-signals:
- void OnModified(bool mod);
+ virtual QWidget *GetWidget();
protected slots:
void OnSocItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
@@ -267,6 +265,7 @@ protected:
void CreateNewDeviceItem(QTreeWidgetItem *parent);
void CreateNewRegisterItem(QTreeWidgetItem *parent);
void CreateNewFieldItem(QTreeWidgetItem *parent);
+ void UpdateTabName();
QGroupBox *m_file_group;
QToolButton *m_file_open;
diff --git a/utils/regtools/qeditor/regtab.cpp b/utils/regtools/qeditor/regtab.cpp
index 132308e8ff..f6a726746f 100644
--- a/utils/regtools/qeditor/regtab.cpp
+++ b/utils/regtools/qeditor/regtab.cpp
@@ -160,6 +160,11 @@ RegTab::RegTab(Backend *backend, QWidget *parent)
SetDataSocName("");
}
+QWidget *RegTab::GetWidget()
+{
+ return this;
+}
+
RegTab::~RegTab()
{
/* backend will be deleted by backend selector */
@@ -192,6 +197,32 @@ void RegTab::OnDataSocActivated(const QString& str)
m_soc_selector->setCurrentIndex(index);
}
+void RegTab::UpdateTabName()
+{
+ /* do it the ugly way: try to cast to the different possible backends */
+ FileIoBackend *file = dynamic_cast< FileIoBackend* >(m_io_backend);
+#ifdef HAVE_HWSTUB
+ HWStubIoBackend *hwstub = dynamic_cast< HWStubIoBackend* >(m_io_backend);
+#endif
+ if(file)
+ {
+ QFileInfo info(file->GetFileName());
+ SetTabName(info.fileName());
+ }
+#ifdef HAVE_HWSTUB
+ else if(hwstub)
+ {
+ HWStubDevice *dev = hwstub->GetDevice();
+ SetTabName(QString("HWStub %1.%2").arg(dev->GetBusNumber())
+ .arg(dev->GetDevAddress()));
+ }
+#endif
+ else
+ {
+ SetTabName("Register Tab");
+ }
+}
+
void RegTab::OnBackendSelect(IoBackend *backend)
{
m_io_backend = backend;
@@ -199,6 +230,7 @@ void RegTab::OnBackendSelect(IoBackend *backend)
SetDataSocName(m_io_backend->GetSocName());
OnDataSocActivated(m_io_backend->GetSocName());
OnDataChanged();
+ UpdateTabName();
}
void RegTab::SetReadOnlyIndicator()
diff --git a/utils/regtools/qeditor/regtab.h b/utils/regtools/qeditor/regtab.h
index f48b72e683..1936ca1f4d 100644
--- a/utils/regtools/qeditor/regtab.h
+++ b/utils/regtools/qeditor/regtab.h
@@ -43,9 +43,7 @@ public:
RegTab(Backend *backend, QWidget *parent = 0);
~RegTab();
virtual bool Quit();
-
-signals:
- void OnModified(bool modified);
+ virtual QWidget *GetWidget();
protected:
void FillDevSubTree(QTreeWidgetItem *item);
@@ -59,6 +57,7 @@ protected:
void SetDataSocName(const QString& socname);
void SetPanel(RegTabPanel *panel);
void UpdateSocFilename();
+ void UpdateTabName();
QComboBox *m_soc_selector;
BackendSelector *m_backend_selector;