Fix nested CommentsWidget double click (Fix #119)

This commit is contained in:
Florian Märkl 2017-12-03 12:47:26 +01:00
parent 40a3928ab6
commit b63d85b23d
5 changed files with 50 additions and 33 deletions

View File

@ -355,26 +355,6 @@ void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset)
emit instructionChanged(offset); emit instructionChanged(offset);
} }
QMap<QString, QList<QList<QString>>> CutterCore::getNestedComments()
{
QMap<QString, QList<QList<QString>>> ret;
QString comments = cmd("CC~CCu");
for (QString line : comments.split("\n"))
{
QStringList fields = line.split("CCu");
if (fields.length() == 2)
{
QList<QString> tmp = QList<QString>();
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) void CutterCore::seek(QString addr)
{ {
// Slower than using the API, but the API is not complete // Slower than using the API, but the API is not complete

View File

@ -209,7 +209,7 @@ public:
void delComment(ut64 addr); void delComment(ut64 addr);
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID); void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
QMap<QString, QList<QList<QString>>> getNestedComments();
void setOptions(QString key); 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 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); bool tryFile(QString path, bool rw);

View File

@ -35,13 +35,25 @@ CommentsWidget::CommentsWidget(MainWindow *main, QWidget *parent) :
CommentsWidget::~CommentsWidget() {} 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<CommentDescription>();
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 // Get offset and name of item double clicked
CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>(); CommentDescription comment = item->data(0, Qt::UserRole).value<CommentDescription>();
CutterCore::getInstance()->seek(comment.offset); CutterCore::getInstance()->seek(comment.offset);
} }
void CommentsWidget::on_toolButton_clicked() void CommentsWidget::on_toolButton_clicked()
@ -89,6 +101,8 @@ void CommentsWidget::on_actionVertical_triggered()
ui->tabWidget->setCurrentIndex(1); ui->tabWidget->setCurrentIndex(1);
} }
void CommentsWidget::resizeEvent(QResizeEvent *event) void CommentsWidget::resizeEvent(QResizeEvent *event)
{ {
if (main->responsive && isVisible()) if (main->responsive && isVisible())
@ -107,12 +121,34 @@ void CommentsWidget::resizeEvent(QResizeEvent *event)
QDockWidget::resizeEvent(event); QDockWidget::resizeEvent(event);
} }
/*
*
QMap<QString, QList<QList<QString>>> CutterCore::getNestedComments()
{
QMap<QString, QList<QList<QString>>> ret;
QString comments = cmd("CC~CCu");
for (QString line : comments.split("\n"))
{
QStringList fields = line.split("CCu");
if (fields.length() == 2)
{
QList<QString> tmp = QList<QString>();
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() void CommentsWidget::refreshTree()
{ {
ui->nestedCmtsTreeWidget->clear(); ui->nestedCmtsTreeWidget->clear();
QList<CommentDescription> comments = CutterCore::getInstance()->getAllComments("CCu"); QList<CommentDescription> comments = CutterCore::getInstance()->getAllComments("CCu");
QMap<QString, QList<CommentDescription>> nestedComments;
for (CommentDescription comment : comments) for (CommentDescription comment : comments)
{ {
@ -123,23 +159,23 @@ void CommentsWidget::refreshTree()
item->setText(2, comment.name); item->setText(2, comment.name);
item->setData(0, Qt::UserRole, QVariant::fromValue(comment)); item->setData(0, Qt::UserRole, QVariant::fromValue(comment));
ui->commentsTreeWidget->addTopLevelItem(item); ui->commentsTreeWidget->addTopLevelItem(item);
nestedComments[fcn_name].append(comment);
} }
qhelpers::adjustColumns(ui->commentsTreeWidget); qhelpers::adjustColumns(ui->commentsTreeWidget);
// Add nested comments // Add nested comments
ui->nestedCmtsTreeWidget->clear(); ui->nestedCmtsTreeWidget->clear();
QMap<QString, QList<QList<QString>>> cmts = CutterCore::getInstance()->getNestedComments(); for (auto functionName : nestedComments.keys())
for (auto cmt : cmts.keys())
{ {
QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedCmtsTreeWidget); QTreeWidgetItem *item = new QTreeWidgetItem(ui->nestedCmtsTreeWidget);
item->setText(0, cmt); item->setText(0, functionName);
QList<QList<QString>> meow = cmts.value(cmt); for (CommentDescription comment : nestedComments.value(functionName))
for (int i = 0; i < meow.size(); ++i)
{ {
QList<QString> tmp = meow.at(i);
QTreeWidgetItem *it = new QTreeWidgetItem(); QTreeWidgetItem *it = new QTreeWidgetItem();
it->setText(0, tmp[1]); it->setText(0, RAddressString(comment.offset));
it->setText(1, tmp[0].remove('"')); it->setText(1, comment.name);
it->setData(0, Qt::UserRole, QVariant::fromValue(comment));
item->addChild(it); item->addChild(it);
} }
ui->nestedCmtsTreeWidget->addTopLevelItem(item); ui->nestedCmtsTreeWidget->addTopLevelItem(item);

View File

@ -26,6 +26,7 @@ protected:
private slots: private slots:
void on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column); void on_commentsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
void on_nestedCmtsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column);
void on_toolButton_clicked(); void on_toolButton_clicked();
void on_toolButton_2_clicked(); void on_toolButton_2_clicked();

View File

@ -808,7 +808,7 @@ void HexdumpWidget::on_action1column_triggered()
refresh(); refresh();
} }
void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &arg1) void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &)
{ {
if (ui->parseTypeComboBox->currentIndex() == 0) if (ui->parseTypeComboBox->currentIndex() == 0)
{ {
@ -821,7 +821,7 @@ void HexdumpWidget::on_parseTypeComboBox_currentTextChanged(const QString &arg1)
on_hexHexText_selectionChanged(); on_hexHexText_selectionChanged();
} }
void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &arg1) void HexdumpWidget::on_parseEndianComboBox_currentTextChanged(const QString &)
{ {
on_hexHexText_selectionChanged(); on_hexHexText_selectionChanged();
} }