From acc34914344962b8af7656c54cd442dad1341c92 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 4 Mar 2015 15:42:01 +0100 Subject: [PATCH] Allow creation of custom groups Users can now create Groups of functions and move individual functions there --- src/gui/Mainwindow.cxx | 36 ++++++++++++++++++++++++++++++++---- src/gui/Mainwindow.hxx | 3 +++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index a15aa66..10046ba 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -128,15 +128,31 @@ void Mainwindow::switchMainPlane(QTreeWidgetItem* to) { } void Mainwindow::showListContextMenu(const QPoint& point) { + QAction * act; QTreeWidgetItem * item = listWidget->itemAt(point); QMenu menu(this); + + act = menu.addAction("Add Function"); + connect(act, &QAction::triggered, this, &Mainwindow::requestNewFunction); + + act = menu.addAction("Add Group"); + connect(act, &QAction::triggered, this, &Mainwindow::requestNewGroup); + if (item) { - QAction * act = menu.addAction("Rename Function"); + act = menu.addAction("Rename Function"); connect(act, &QAction::triggered, [=]() {this->renameFunction(objects_list[item]->getFunction());}); - } - QAction * act = menu.addAction("AddFunction"); - connect(act, SIGNAL(triggered()), this, SLOT(requestNewFunction())); + QMenu* submenu = menu.addMenu("Move to group"); + + for (QTreeWidgetItem* groupitem : group_list) { + act = submenu->addAction(groupitem->text(0)); + connect(act, &QAction::triggered, + [=] () { + listWidget->invisibleRootItem()->removeChild(item); + groupitem->addChild(item); + }); + } + } menu.exec(listWidget->mapToGlobal(point)); } @@ -151,6 +167,18 @@ void Mainwindow::requestNewFunction() { } } +void Mainwindow::requestNewGroup() { + SimpleStringDialog dialog("New Group"); + int result = dialog.exec(); + if (QDialog::Accepted == result) { + QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList(dialog.result())); + external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); + group_list.push_back(external); + } else { + LOG4CXX_DEBUG(logger, "requestNewGroup aborted"); + } +} + void Mainwindow::requestNewFunctionByAddress(uint64_t address) { LOG4CXX_DEBUG(logger, "requesting Function at " << std::hex << address); manager->getDisassembler()->disassembleFunctionAt(address); diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index a3bd4bd..7e9cb3a 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -50,6 +51,7 @@ private: std::map functions; std::map objects_list; std::map objects_list_by_address; + std::vector group_list; InformationManager* manager; log4cxx::LoggerPtr logger; @@ -61,6 +63,7 @@ private Q_SLOTS: void switchMainPlane(QTreeWidgetItem* item); void showListContextMenu(const QPoint&); void requestNewFunction(); + void requestNewGroup(); void renameFunction(Function* function); }; -- 2.39.5