|
| 1 | +#include "devgraphs.h" |
| 2 | +#include "support/surfacerenderer.h" |
| 3 | +#include <QApplication> |
| 4 | +#include <QClipboard> |
| 5 | +#include <QHeaderView> |
| 6 | + |
| 7 | +DevGraphsDialog::DevGraphsDialog(RDContext* ctx, QWidget* parent) |
| 8 | + : QDialog{parent}, m_ui{this}, m_context{ctx} { |
| 9 | + |
| 10 | + m_ui.ftbcopyhash->setEnabled(false); |
| 11 | + m_ui.ftbcopygraph->setEnabled(false); |
| 12 | + |
| 13 | + m_functionsmodel = new FunctionsModel(ctx, m_ui.tvfunctions); |
| 14 | + m_ui.tvfunctions->setModel(m_functionsmodel); |
| 15 | + |
| 16 | + m_ui.ptedot->setFont(surface_renderer::get_font()); |
| 17 | + m_ui.ptedot->setTabStopDistance(4 * surface_renderer::cell_width()); |
| 18 | + |
| 19 | + QHeaderView* hdrview = m_ui.tvfunctions->header(); |
| 20 | + hdrview->setSectionResizeMode(0, QHeaderView::ResizeToContents); |
| 21 | + hdrview->setSectionResizeMode(1, QHeaderView::Stretch); |
| 22 | + |
| 23 | + this->setFocus(); // don't focus function list |
| 24 | + |
| 25 | + connect(m_ui.tvfunctions, &QTreeView::clicked, this, |
| 26 | + &DevGraphsDialog::show_dot); |
| 27 | + |
| 28 | + connect(m_ui.ftbcopytests, &FeedbackPushButton::feedback, this, |
| 29 | + &DevGraphsDialog::copy_tests); |
| 30 | + |
| 31 | + connect(m_ui.ftbcopygraph, &FeedbackPushButton::feedback, this, |
| 32 | + [&]() { qApp->clipboard()->setText(m_currentgraph); }); |
| 33 | + |
| 34 | + connect(m_ui.ftbcopyhash, &FeedbackPushButton::feedback, this, [&]() { |
| 35 | + qApp->clipboard()->setText(QString{"0x%1"}.arg( |
| 36 | + static_cast<qulonglong>(m_currenthash), 8, 16, '0')); |
| 37 | + }); |
| 38 | +} |
| 39 | + |
| 40 | +void DevGraphsDialog::copy_tests() { |
| 41 | + QString s = "{\n"; |
| 42 | + |
| 43 | + for(int i = 0; i < m_functionsmodel->rowCount({}); i++) { |
| 44 | + QModelIndex index = m_functionsmodel->index(i); |
| 45 | + RDAddress address = m_functionsmodel->address(index); |
| 46 | + const RDFunction* f = rd_find_function(m_context, address); |
| 47 | + Q_ASSERT(f); |
| 48 | + u32 hash = rd_function_get_hash(f); |
| 49 | + |
| 50 | + s.append(QString{" {0x%1, 0x%2},\n"} |
| 51 | + .arg(static_cast<qulonglong>(address), 8, 16, '0') |
| 52 | + .arg(static_cast<qulonglong>(hash), 8, 16, '0')); |
| 53 | + } |
| 54 | + |
| 55 | + s.append("};"); |
| 56 | + qApp->clipboard()->setText(s); |
| 57 | +} |
| 58 | + |
| 59 | +void DevGraphsDialog::show_dot(const QModelIndex& index) { |
| 60 | + m_currentgraph = {}; |
| 61 | + m_currenthash = {}; |
| 62 | + m_ui.ptedot->clear(); |
| 63 | + |
| 64 | + RDAddress address = m_functionsmodel->address(index); |
| 65 | + const char* dot = nullptr; |
| 66 | + |
| 67 | + const RDFunction* f = rd_find_function(m_context, address); |
| 68 | + if(!f) goto fail; |
| 69 | + |
| 70 | + dot = rd_function_generate_dot(f); |
| 71 | + if(!dot) goto fail; |
| 72 | + |
| 73 | + m_currenthash = rd_function_get_hash(f); |
| 74 | + m_currentgraph = QString::fromUtf8(dot); |
| 75 | + |
| 76 | + m_ui.ptedot->setPlainText(m_currentgraph); |
| 77 | + m_ui.ftbcopyhash->setEnabled(true); |
| 78 | + m_ui.ftbcopygraph->setEnabled(true); |
| 79 | + return; |
| 80 | + |
| 81 | +fail: |
| 82 | + m_ui.ftbcopyhash->setEnabled(false); |
| 83 | + m_ui.ftbcopygraph->setEnabled(false); |
| 84 | +} |
0 commit comments