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>
This commit is contained in:
Amaury Pouly 2014-09-18 21:36:17 +02:00
parent dbb59291e7
commit 970c2482dd
7 changed files with 129 additions and 48 deletions

View file

@ -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;

View file

@ -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)
void MainWindow::AddTab(DocumentTab *doc, const QString& title)
{
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)
{
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()

View file

@ -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;

View file

@ -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()

View file

@ -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;

View file

@ -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()

View file

@ -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;