From: Christoph Egger Date: Wed, 4 Mar 2015 14:12:46 +0000 (+0100) Subject: Change from QListWidget to QTreeWidget X-Git-Tag: v0.1~78 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=eaea9a6612e5dc13b5fda28e943e632e3de713da;p=frida%2Ffrida.git Change from QListWidget to QTreeWidget This way we can group functions on the left plane. Allows to group and hide some groups of items. As a first take, group the external functions. This also places them at the top where they stay together. --- diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 0c08892..fe48f8f 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -44,7 +44,8 @@ Mainwindow::Mainwindow(InformationManager* mgr) scripting->setAllowedAreas(Qt::BottomDockWidgetArea); addDockWidget(Qt::BottomDockWidgetArea, scripting); - listWidget = new QListWidget(); + listWidget = new QTreeWidget(); + listWidget->setColumnCount(1); listWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(listWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showListContextMenu(const QPoint&))); @@ -57,15 +58,20 @@ Mainwindow::Mainwindow(InformationManager* mgr) addDockWidget(Qt::LeftDockWidgetArea, dockWidget); setCentralWidget(stackedWidget); - connect(listWidget, SIGNAL(currentRowChanged(int)), - this, SLOT(switchMainPlane(int))); + connect(listWidget, &QTreeWidget::currentItemChanged, + [=] (QTreeWidgetItem* current, QTreeWidgetItem*) { + switchMainPlane(current); + }); setWindowTitle(tr("FRIDA")); + QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList("External Functions")); + external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); + external->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd))); mgr->connect_new_function_signal([&] (Function* fun) {addFunction(fun);}); - mgr->connect_new_dyn_symbol_signal([&] (const std::string& name) { - auto item = new QListWidgetItem(name.c_str(), listWidget); - item->setBackground(QBrush(QColor(0xff, 0xdd, 0xdd))); + mgr->connect_new_dyn_symbol_signal([=] (const std::string& name) { + auto item = new QTreeWidgetItem(external, QStringList(name.c_str())); + item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd))); }); setGlobalHotkeys(); } @@ -76,7 +82,7 @@ void Mainwindow::setGlobalHotkeys() { shortcut = new QShortcut(QKeySequence("r"), listWidget); connect(shortcut, &QShortcut::activated, [=]() { - QListWidgetItem * item = listWidget->currentItem(); + QTreeWidgetItem * item = listWidget->currentItem(); if (item) renameFunction(objects_list[item]->getFunction()); }); } @@ -107,7 +113,7 @@ void Mainwindow::save() { void Mainwindow::switchMainPlaneToAddress(uint64_t address) { if (objects_list_by_address.find(address) != objects_list_by_address.end()) { LOG4CXX_DEBUG(logger, "Switching to function " << std::hex << address); - QListWidgetItem * item = objects_list_by_address[address]; + QTreeWidgetItem * item = objects_list_by_address[address]; listWidget->setCurrentItem(item); stackedWidget->setCurrentWidget(objects_list[item]); } else { @@ -116,12 +122,13 @@ void Mainwindow::switchMainPlaneToAddress(uint64_t address) { } } -void Mainwindow::switchMainPlane(int) { - stackedWidget->setCurrentWidget(objects_list[listWidget->currentItem()]); +void Mainwindow::switchMainPlane(QTreeWidgetItem* to) { + if (objects_list.end() != objects_list.find(to)) + stackedWidget->setCurrentWidget(objects_list[to]); } void Mainwindow::showListContextMenu(const QPoint& point) { - QListWidgetItem * item = listWidget->itemAt(point); + QTreeWidgetItem * item = listWidget->itemAt(point); QMenu menu(this); if (item) { QAction * act = menu.addAction("Rename Function"); @@ -156,7 +163,7 @@ void Mainwindow::renameFunction(Function* function) { LOG4CXX_DEBUG(logger, "renaming Function " << function->getName() << " to " << dialog.result().toStdString()); function->setName(dialog.result().toStdString()); - objects_list_by_address[function->getStartAddress()]->setText(dialog.result()); + objects_list_by_address[function->getStartAddress()]->setText(0, dialog.result()); } else { LOG4CXX_DEBUG(logger, "renameFunction aborted"); } @@ -194,7 +201,7 @@ void Mainwindow::addFunction(Function* fun) { w->addTab(t, "Listing"); - QListWidgetItem * item = new QListWidgetItem(fun->getName().c_str(), listWidget); + QTreeWidgetItem * item = new QTreeWidgetItem(listWidget, QStringList(fun->getName().c_str())); stackedWidget->addWidget(w); objects_list.insert(std::make_pair(item, w)); LOG4CXX_DEBUG(logger, "Adding function widget at " << std::hex diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index ba0d8b4..a3bd4bd 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -37,7 +37,7 @@ private: QMenu *fileMenu; QTabWidget * tabwidget; - QListWidget * listWidget; + QTreeWidget * listWidget; QStackedWidget * stackedWidget; QDockWidget * dockWidget; ScriptingDock * scripting; @@ -48,8 +48,8 @@ private: std::map blocks; std::map functions; - std::map objects_list; - std::map objects_list_by_address; + std::map objects_list; + std::map objects_list_by_address; InformationManager* manager; log4cxx::LoggerPtr logger; @@ -58,7 +58,7 @@ private Q_SLOTS: void quit(); void open(); void save(); - void switchMainPlane(int); + void switchMainPlane(QTreeWidgetItem* item); void showListContextMenu(const QPoint&); void requestNewFunction(); void renameFunction(Function* function); diff --git a/src/gui/qt.hxx b/src/gui/qt.hxx index ae4ef2c..ae370d5 100644 --- a/src/gui/qt.hxx +++ b/src/gui/qt.hxx @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include