Export graph as SVG, PDF, PNG... Fix #242

Export graph as SVG, PDF, PNG... Fix #242
This commit is contained in:
Paul I 2018-08-25 21:54:23 +03:00 committed by Maijin
parent ec2807a897
commit c6787fd58d
2 changed files with 32 additions and 3 deletions

@ -1 +1 @@
Subproject commit f82b289822825e4c7403734f3b95dfd7f5e4f725 Subproject commit b5044de59bf36a2ba6deb19100b57aa40592e829

View File

@ -12,6 +12,7 @@
#include <QFile> #include <QFile>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QRegularExpression> #include <QRegularExpression>
#include <QStandardPaths>
#include "Cutter.h" #include "Cutter.h"
#include "utils/Colors.h" #include "utils/Colors.h"
@ -821,8 +822,36 @@ void DisassemblerGraphView::blockTransitionedTo(GraphView::GraphBlock *to)
void DisassemblerGraphView::on_actionExportGraph_triggered() void DisassemblerGraphView::on_actionExportGraph_triggered()
{ {
QString fileName = QFileDialog::getSaveFileName(this, QStringList filters;
tr("Export Graph"), "", tr("Dot file (*.dot)")); filters.append(tr("Graphiz dot (*.dot)"));
if (!QStandardPaths::findExecutable("dot").isEmpty()
|| !QStandardPaths::findExecutable("xdot").isEmpty()) {
filters.append(tr("GIF (*.gif)"));
filters.append(tr("PNG (*.png)"));
filters.append(tr("JPEG (*.jpg)"));
filters.append(tr("PostScript (*.ps)"));
filters.append(tr("SVG (*.svg)"));
filters.append(tr("JSON (*.json)"));
}
QFileDialog dialog(this, tr("Export Graph"));
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilters(filters);
dialog.selectFile("graph");
dialog.setDefaultSuffix("dot");
if (!dialog.exec())
return;
int startIdx = dialog.selectedNameFilter().lastIndexOf("*.") + 2;
int count = dialog.selectedNameFilter().length() - startIdx - 1;
QString format = dialog.selectedNameFilter().mid(startIdx, count);
QString fileName = dialog.selectedFiles()[0];
if (format != "dot") {
TempConfig tempConfig;
tempConfig.set("graph.gv.format", format);
qWarning() << Core()->cmd(QString("agfw \"%1\" @ $FB").arg(fileName));
return;
}
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Can't open file"; qWarning() << "Can't open file";