]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/Mainwindow.cxx
Change from QListWidget to QTreeWidget
[frida/frida.git] / src / gui / Mainwindow.cxx
index 0c08892642dd760b4f5e611254e9c8c67de2467e..fe48f8fd38cb4d0af385844466fc7e1921d5c22a 100644 (file)
@@ -44,7 +44,8 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
        addDockWidget(Qt::BottomDockWidgetArea, scripting);
 
        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&)));
        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);
 
        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"));
 
 
        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_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();
 }
                });
        setGlobalHotkeys();
 }
@@ -76,7 +82,7 @@ void Mainwindow::setGlobalHotkeys() {
 
        shortcut = new QShortcut(QKeySequence("r"), listWidget);
        connect(shortcut, &QShortcut::activated, [=]() {
 
        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());
                });
 }
                        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);
 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 {
                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) {
 }
 
 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");
        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());
                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");
        }
        } else {
                LOG4CXX_DEBUG(logger, "renameFunction aborted");
        }
@@ -194,7 +201,7 @@ void Mainwindow::addFunction(Function* fun) {
 
        w->addTab(t, "Listing");
 
 
        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
        stackedWidget->addWidget(w);
        objects_list.insert(std::make_pair(item, w));
        LOG4CXX_DEBUG(logger, "Adding function widget at " << std::hex