Skip to content

Commit 85bf980

Browse files
committed
feat(DevGraphsDialog): added "copy functions" button
1 parent d07f7b7 commit 85bf980

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/dialogs/devgraphs.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ DevGraphsDialog::DevGraphsDialog(RDContext* ctx, QWidget* parent)
2626
connect(m_ui.tvfunctions, &QTreeView::clicked, this,
2727
&DevGraphsDialog::show_dot);
2828

29-
connect(m_ui.ftbcopytests, &FeedbackPushButton::feedback, this,
30-
&DevGraphsDialog::copy_tests);
29+
connect(m_ui.ftbcopygraphhashes, &FeedbackPushButton::feedback, this,
30+
&DevGraphsDialog::copy_graph_hashes);
31+
32+
connect(m_ui.ftbcopyfunctions, &FeedbackPushButton::feedback, this,
33+
&DevGraphsDialog::copy_functions);
3134

3235
connect(m_ui.ftbcopygraph, &FeedbackPushButton::feedback, this,
3336
[&]() { qApp->clipboard()->setText(m_currentgraph); });
@@ -38,7 +41,7 @@ DevGraphsDialog::DevGraphsDialog(RDContext* ctx, QWidget* parent)
3841
});
3942
}
4043

41-
void DevGraphsDialog::copy_tests() {
44+
void DevGraphsDialog::copy_graph_hashes() {
4245
QString s = "{\n";
4346

4447
for(int i = 0; i < m_functionsmodel->rowCount({}); i++) {
@@ -57,6 +60,26 @@ void DevGraphsDialog::copy_tests() {
5760
qApp->clipboard()->setText(s);
5861
}
5962

63+
void DevGraphsDialog::copy_functions() {
64+
QString s = "{\n";
65+
66+
for(int i = 0; i < m_functionsmodel->rowCount({}); i++) {
67+
QModelIndex index = m_functionsmodel->index(i);
68+
RDAddress address = m_functionsmodel->address(index);
69+
const RDFunction* f = rd_find_function(m_context, address);
70+
Q_ASSERT(f);
71+
const char* name = rd_get_name(m_context, address);
72+
Q_ASSERT(name);
73+
74+
s.append(QString{" {0x%1, \"%2\"},\n"}
75+
.arg(utils::to_hex(address))
76+
.arg(QString::fromUtf8(name)));
77+
}
78+
79+
s.append("};");
80+
qApp->clipboard()->setText(s);
81+
}
82+
6083
void DevGraphsDialog::show_dot(const QModelIndex& index) {
6184
m_currentgraph = {};
6285
m_currenthash = {};

src/dialogs/devgraphs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class DevGraphsDialog: public QDialog {
1212

1313
private Q_SLOTS:
1414
void show_dot(const QModelIndex& index);
15-
void copy_tests();
15+
void copy_graph_hashes();
16+
void copy_functions();
1617

1718
private:
1819
ui::DevGraphsDialog m_ui;

src/ui/devgraphsdialog.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
namespace ui {
1212

1313
struct DevGraphsDialog {
14-
FeedbackPushButton *ftbcopytests, *ftbcopyhash, *ftbcopygraph;
14+
FeedbackPushButton *ftbcopygraphhashes, *ftbcopyhash, *ftbcopyfunctions,
15+
*ftbcopygraph;
1516
QTreeView* tvfunctions;
1617
QPlainTextEdit* ptedot;
1718

@@ -24,13 +25,20 @@ struct DevGraphsDialog {
2425
this->tvfunctions->setUniformRowHeights(true);
2526
this->tvfunctions->setRootIsDecorated(false);
2627

27-
this->ftbcopytests = new FeedbackPushButton();
28-
this->ftbcopytests->setText("Copy Tests");
29-
this->ftbcopytests->set_feedback_text("Copied");
28+
this->ftbcopygraphhashes = new FeedbackPushButton();
29+
this->ftbcopygraphhashes->setText("Copy Graph Hashes");
30+
this->ftbcopygraphhashes->set_feedback_text("Copied");
31+
this->ftbcopyfunctions = new FeedbackPushButton();
32+
this->ftbcopyfunctions->setText("Copy Functions");
33+
this->ftbcopyfunctions->set_feedback_text("Copied");
34+
35+
auto* hbox = new QHBoxLayout();
36+
hbox->addWidget(this->ftbcopygraphhashes);
37+
hbox->addWidget(this->ftbcopyfunctions);
3038

3139
auto* vbox_left = new QVBoxLayout(new QWidget());
3240
vbox_left->addWidget(this->tvfunctions, 1);
33-
vbox_left->addWidget(this->ftbcopytests);
41+
vbox_left->addLayout(hbox);
3442

3543
this->ptedot = new QPlainTextEdit();
3644
this->ptedot->setUndoRedoEnabled(false);
@@ -43,7 +51,7 @@ struct DevGraphsDialog {
4351
this->ftbcopygraph->setText("Copy Graph");
4452
this->ftbcopygraph->set_feedback_text("Copied");
4553

46-
auto* hbox = new QHBoxLayout();
54+
hbox = new QHBoxLayout();
4755
hbox->addWidget(this->ftbcopyhash);
4856
hbox->addWidget(this->ftbcopygraph);
4957

0 commit comments

Comments
 (0)