From dc869e70acaadb7ef2d96101fe8e938d53f18e65 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Fri, 2 May 2014 00:32:41 +0200 Subject: qeditor: add support for deletion of items Change-Id: I886e15585bd3bfed3303e4b845cd8960a9461277 --- utils/hwstub/hwstub_protocol.h | 4 ++ utils/regtools/lib/soc_desc.hpp | 8 ++++ utils/regtools/qeditor/main.cpp | 1 + utils/regtools/qeditor/mainwindow.cpp | 13 +++++- utils/regtools/qeditor/qeditor.pro | 4 ++ utils/regtools/qeditor/regedit.cpp | 82 ++++++++++++++++++++++++++++++++--- utils/regtools/qeditor/regedit.h | 1 + 7 files changed, 106 insertions(+), 7 deletions(-) (limited to 'utils') diff --git a/utils/hwstub/hwstub_protocol.h b/utils/hwstub/hwstub_protocol.h index fa692abab5..2c11025b1e 100644 --- a/utils/hwstub/hwstub_protocol.h +++ b/utils/hwstub/hwstub_protocol.h @@ -29,6 +29,10 @@ #define HWSTUB_VERSION_MINOR 0 #define HWSTUB_VERSION_REV 1 +#define HWSTUB_VERSION__(maj,min,rev) #maj"."#min"."#rev +#define HWSTUB_VERSION_(maj,min,rev) HWSTUB_VERSION__(maj,min,rev) +#define HWSTUB_VERSION HWSTUB_VERSION_(HWSTUB_VERSION_MAJOR,HWSTUB_VERSION_MINOR,HWSTUB_VERSION_REV) + #define HWSTUB_USB_VID 0xfee1 #define HWSTUB_USB_PID 0xdead diff --git a/utils/regtools/lib/soc_desc.hpp b/utils/regtools/lib/soc_desc.hpp index d9dbf0cc20..4aa8c975ac 100644 --- a/utils/regtools/lib/soc_desc.hpp +++ b/utils/regtools/lib/soc_desc.hpp @@ -45,6 +45,14 @@ * ignores the position of the WORD_LENGTH field in the register. */ +#define SOCDESC_VERSION_MAJOR 1 +#define SOCDESC_VERSION_MINOR 1 +#define SOCDESC_VERSION_REV 0 + +#define SOCDESC_VERSION__(maj,min,rev) #maj"."#min"."#rev +#define SOCDESC_VERSION_(maj,min,rev) SOCDESC_VERSION__(maj,min,rev) +#define SOCDESC_VERSION SOCDESC_VERSION_(SOCDESC_VERSION_MAJOR,SOCDESC_VERSION_MINOR,SOCDESC_VERSION_REV) + /** * Typedef for SoC types: word, address and flags */ typedef uint32_t soc_addr_t; diff --git a/utils/regtools/qeditor/main.cpp b/utils/regtools/qeditor/main.cpp index 576d3a16fc..c1f8df66d6 100644 --- a/utils/regtools/qeditor/main.cpp +++ b/utils/regtools/qeditor/main.cpp @@ -5,6 +5,7 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + app.setApplicationVersion(APP_VERSION); Backend backend;; QDir dir(QCoreApplication::applicationDirPath()); diff --git a/utils/regtools/qeditor/mainwindow.cpp b/utils/regtools/qeditor/mainwindow.cpp index cd0926851c..1a88ebb47e 100644 --- a/utils/regtools/qeditor/mainwindow.cpp +++ b/utils/regtools/qeditor/mainwindow.cpp @@ -97,7 +97,18 @@ void MainWindow::OnQuit() void MainWindow::OnAbout() { - QMessageBox::about(this, "About", "Written by Amaury Pouly for Rockbox"); + QMessageBox::about(this, "About", + "

QEditor

" + "

Version "APP_VERSION"

" + "

Written by Amaury Pouly

" + "

Libraries:

" + ""); } void MainWindow::OnAboutQt() diff --git a/utils/regtools/qeditor/qeditor.pro b/utils/regtools/qeditor/qeditor.pro index 38d7c987bf..279b3532c0 100644 --- a/utils/regtools/qeditor/qeditor.pro +++ b/utils/regtools/qeditor/qeditor.pro @@ -7,6 +7,10 @@ SOURCES += main.cpp mainwindow.cpp regtab.cpp backend.cpp analyser.cpp \ LIBS += -L../lib/ -lsocdesc -lxml2 INCLUDEPATH += ../lib/ ../../hwstub/lib +VERSION = 2.0.1 + +DEFINES += APP_VERSION=\\\"$$VERSION\\\" + unix { !nohwstub { message("Use 'qmake -config nohwstub' if you want to disable hwstub support") diff --git a/utils/regtools/qeditor/regedit.cpp b/utils/regtools/qeditor/regedit.cpp index 5e498ce496..bb1abc0825 100644 --- a/utils/regtools/qeditor/regedit.cpp +++ b/utils/regtools/qeditor/regedit.cpp @@ -206,6 +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); } else if(type == DevInstNewType) { @@ -526,6 +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); } else if(type == RegInstNewType) { @@ -729,6 +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); } else if(type == FieldValueNewType) { @@ -921,6 +924,11 @@ RegEdit::RegEdit(Backend *backend, QWidget *parent) m_soc_tree = new QTreeWidget(this); m_soc_tree->setColumnCount(1); m_soc_tree->setHeaderLabel(QString("Name")); + m_soc_tree->setContextMenuPolicy(Qt::ActionsContextMenu); + QAction *soc_tree_delete_action = new QAction("&Delete", this); + soc_tree_delete_action->setIcon(QIcon::fromTheme("list-remove")); + connect(soc_tree_delete_action, SIGNAL(triggered()), this, SLOT(OnSocItemDelete())); + m_soc_tree->addAction(soc_tree_delete_action); m_splitter->addWidget(m_soc_tree); m_splitter->setStretchFactor(0, 0); @@ -962,12 +970,11 @@ bool RegEdit::CloseSoc() { if(!m_modified) return true; - QMessageBox msgBox; - msgBox.setText("The description has been modified."); - msgBox.setInformativeText("Do you want to save your changes?"); - msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Save); - int ret = msgBox.exec(); + QMessageBox msgbox(QMessageBox::Question, "Save changes ?", + "The description has been modified. Do you want to save your changes ?", + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, this); + msgbox.setDefaultButton(QMessageBox::Cancel); + int ret = msgbox.exec(); if(ret == QMessageBox::Discard) return true; if(ret == QMessageBox::Cancel) @@ -1188,6 +1195,66 @@ void RegEdit::SetModified(bool add, bool mod) emit OnModified(mod); } +namespace +{ + +template< typename T > +void my_remove_at(std::vector< T >& v, size_t at) +{ + v.erase(v.begin() + at); +} + +} + +void RegEdit::OnSocItemDelete() +{ + QTreeWidgetItem *current = m_soc_tree->currentItem(); + if(current == 0) + return; + QMessageBox msgbox(QMessageBox::Question, "Delete item ?", + "Are you sure you want to delete this item ?", + QMessageBox::Yes | QMessageBox::No, this); + msgbox.setDefaultButton(QMessageBox::No); + int ret = msgbox.exec(); + if(ret != QMessageBox::Yes) + return; + if(current->type() == SocTreeSocType) + { + SocTreeItem *item = dynamic_cast< SocTreeItem * >(current); + item->GetRef().GetSoc().dev.clear(); + item->takeChildren(); + FillSocTreeItem(item); + m_soc_tree->expandItem(item); + } + else if(current->type() == SocTreeDevType) + { + DevTreeItem *item = dynamic_cast< DevTreeItem * >(current); + my_remove_at(item->GetRef().GetSoc().dev, item->GetRef().GetDevIndex()); + QTreeWidgetItem *parent = item->parent(); + parent->takeChildren(); + FillSocTreeItem(parent); + m_soc_tree->expandItem(parent); + } + else if(current->type() == SocTreeRegType) + { + RegTreeItem *item = dynamic_cast< RegTreeItem * >(current); + my_remove_at(item->GetRef().GetDev().reg, item->GetRef().GetRegIndex()); + QTreeWidgetItem *parent = item->parent(); + parent->takeChildren(); + FillDevTreeItem(parent); + m_soc_tree->expandItem(parent); + } + else if(current->type() == SocTreeFieldType) + { + FieldTreeItem *item = dynamic_cast< FieldTreeItem * >(current); + my_remove_at(item->GetRef().GetReg().field, item->GetRef().GetFieldIndex()); + QTreeWidgetItem *parent = item->parent(); + parent->takeChildren(); + FillRegTreeItem(parent); + m_soc_tree->expandItem(parent); + } +} + void RegEdit::OnSocModified(bool modified) { // we might need to update the name in the tree @@ -1293,6 +1360,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); } void RegEdit::AddRegister(QTreeWidgetItem *_item) @@ -1305,6 +1373,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); } void RegEdit::AddField(QTreeWidgetItem *_item) @@ -1316,6 +1385,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); } bool RegEdit::Quit() diff --git a/utils/regtools/qeditor/regedit.h b/utils/regtools/qeditor/regedit.h index 8615816783..b5ccd249fa 100644 --- a/utils/regtools/qeditor/regedit.h +++ b/utils/regtools/qeditor/regedit.h @@ -238,6 +238,7 @@ protected slots: void OnSaveAs(); void OnSocModified(bool modified); void OnNew(); + void OnSocItemDelete(); protected: void LoadSocFile(const QString& filename); -- cgit v1.2.3