From b63d85b23de4e2408e436057d07642f60987b768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 3 Dec 2017 12:47:26 +0100 Subject: [PATCH] Fix nested CommentsWidget double click (Fix #119) --- src/cutter.cpp | 20 ------------ src/cutter.h | 2 +- src/widgets/CommentsWidget.cpp | 56 ++++++++++++++++++++++++++++------ src/widgets/CommentsWidget.h | 1 + src/widgets/HexdumpWidget.cpp | 4 +-- 5 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/cutter.cpp b/src/cutter.cpp index 70c574ac..70a867f7 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -355,26 +355,6 @@ void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset) emit instructionChanged(offset); } -QMap>> CutterCore::getNestedComments() -{ - QMap>> ret; - QString comments = cmd("CC~CCu"); - - for (QString line : comments.split("\n")) - { - QStringList fields = line.split("CCu"); - if (fields.length() == 2) - { - QList tmp = QList(); - tmp << fields[1].split("\"")[1].trimmed(); - tmp << fields[0].trimmed(); - QString fcn_name = this->cmdFunctionAt(fields[0].trimmed()); - ret[fcn_name].append(tmp); - } - } - return ret; -} - void CutterCore::seek(QString addr) { // Slower than using the API, but the API is not complete diff --git a/src/cutter.h b/src/cutter.h index b2e442ad..e47f9cc8 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -209,7 +209,7 @@ public: void delComment(ut64 addr); void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID); - QMap>> getNestedComments(); + void setOptions(QString key); bool loadFile(QString path, uint64_t loadaddr = 0LL, uint64_t mapaddr = 0LL, bool rw = false, int va = 0, int idx = 0, bool loadbin = false, const QString &forceBinPlugin = nullptr); bool tryFile(QString path, bool rw); diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index bab85c51..fbafa771 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -35,13 +35,25 @@ CommentsWidget::CommentsWidget(MainWindow *main, QWidget *parent) : CommentsWidget::~CommentsWidget() {} -void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) +void CommentsWidget::on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int) { - Q_UNUSED(column); + // Get offset and name of item double clicked + CommentDescription comment = item->data(0, Qt::UserRole).value(); + CutterCore::getInstance()->seek(comment.offset); +} + +void CommentsWidget::on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int) +{ + // don't react on top-level items + if (item->parent() == nullptr) + { + return; + } // Get offset and name of item double clicked CommentDescription comment = item->data(0, Qt::UserRole).value(); CutterCore::getInstance()->seek(comment.offset); + } void CommentsWidget::on_toolButton_clicked() @@ -89,6 +101,8 @@ void CommentsWidget::on_actionVertical_triggered() ui->tabWidget->setCurrentIndex(1); } + + void CommentsWidget::resizeEvent(QResizeEvent *event) { if (main->responsive && isVisible()) @@ -107,12 +121,34 @@ void CommentsWidget::resizeEvent(QResizeEvent *event) QDockWidget::resizeEvent(event); } +/* + * +QMap>> CutterCore::getNestedComments() +{ + QMap>> ret; + QString comments = cmd("CC~CCu"); + for (QString line : comments.split("\n")) + { + QStringList fields = line.split("CCu"); + if (fields.length() == 2) + { + QList tmp = QList(); + tmp << fields[1].split("\"")[1].trimmed(); + tmp << fields[0].trimmed(); + QString fcn_name = this->cmdFunctionAt(fields[0].trimmed()); + ret[fcn_name].append(tmp); + } + } + return ret; +} + */ void CommentsWidget::refreshTree() { ui->nestedCmtsTreeWidget->clear(); QList comments = CutterCore::getInstance()->getAllComments("CCu"); + QMap> nestedComments; for (CommentDescription comment : comments) { @@ -123,23 +159,23 @@ void CommentsWidget::refreshTree() item->setText(2, comment.name); item->setData(0, Qt::UserRole, QVariant::fromValue(comment)); ui->commentsTreeWidget->addTopLevelItem(item); + + nestedComments[fcn_name].append(comment); } qhelpers::adjustColumns(ui->commentsTreeWidget); // Add nested comments ui->nestedCmtsTreeWidget->clear(); - QMap>> cmts = CutterCore::getInstance()->getNestedComments(); - for (auto cmt : cmts.keys()) + for (auto functionName : nestedComments.keys()) { QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedCmtsTreeWidget); - item->setText(0, cmt); - QList> meow = cmts.value(cmt); - for (int i = 0; i < meow.size(); ++i) + item->setText(0, functionName); + for (CommentDescription comment : nestedComments.value(functionName)) { - QList tmp = meow.at(i); QTreeWidgetItem *it = new QTreeWidgetItem(); - it->setText(0, tmp[1]); - it->setText(1, tmp[0].remove('"')); + it->setText(0, RAddressString(comment.offset)); + it->setText(1, comment.name); + it->setData(0, Qt::UserRole, QVariant::fromValue(comment)); item->addChild(it); } ui->nestedCmtsTreeWidget->addTopLevelItem(item); diff --git a/src/widgets/CommentsWidget.h b/src/widgets/CommentsWidget.h index ce5df38c..61049063 100644 --- a/src/widgets/CommentsWidget.h +++ b/src/widgets/CommentsWidget.h @@ -26,6 +26,7 @@ protected: private slots: void on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column); + void on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column); void on_toolButton_clicked(); void on_toolButton_2_clicked(); diff --git a/src/widgets/HexdumpWidget.cpp b/src/widgets/HexdumpWidget.cpp index 2ea68bb1..29a7d088 100644 --- a/src/widgets/HexdumpWidget.cpp +++ b/src/widgets/HexdumpWidget.cpp @@ -808,7 +808,7 @@ void HexdumpWidget::on_action1column_triggered() refresh(); } -void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &arg1) +void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &) { if (ui->parseTypeComboBox->currentIndex() == 0) { @@ -821,7 +821,7 @@ void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &arg1) on_hexHexText_selectionChanged(); } -void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &arg1) +void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &) { on_hexHexText_selectionChanged(); }