+ fix minor issues with graph export
This commit is contained in:
parent
2845505c9f
commit
6eee3c6146
|
@ -63,19 +63,12 @@ void GraphvizView::setDependencyGraph(const std::string& s)
|
|||
graphCode = s;
|
||||
}
|
||||
|
||||
QByteArray GraphvizView::exportGraph(const QString& filter)
|
||||
QByteArray GraphvizView::exportGraph(const QString& format)
|
||||
{
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Paths");
|
||||
QProcess proc;
|
||||
QStringList args;
|
||||
if (filter.indexOf(QLatin1String("png")) > 0)
|
||||
args << QLatin1String("-Tpng");
|
||||
else if (filter.indexOf(QLatin1String("svg")) > 0)
|
||||
args << QLatin1String("-Tsvg");
|
||||
else if (filter.indexOf(QLatin1String("pdf")) > 0)
|
||||
args << QLatin1String("-Tpdf");
|
||||
else
|
||||
return QByteArray();
|
||||
args << QString::fromLatin1("-T%1").arg(format);
|
||||
|
||||
#ifdef FC_OS_LINUX
|
||||
QString path = QString::fromUtf8(hGrp->GetASCII("Graphviz", "/usr/bin").c_str());
|
||||
|
@ -105,32 +98,50 @@ QByteArray GraphvizView::exportGraph(const QString& filter)
|
|||
bool GraphvizView::onMsg(const char* pMsg,const char** ppReturn)
|
||||
{
|
||||
if (strcmp("Save",pMsg) == 0 || strcmp("SaveAs",pMsg) == 0) {
|
||||
QList< QPair<QString, QString> > formatMap;
|
||||
formatMap << qMakePair(tr("PNG format (*.png)"), QString::fromLatin1("png"));
|
||||
formatMap << qMakePair(tr("Bitmap format (*.bmp)"), QString::fromLatin1("bmp"));
|
||||
formatMap << qMakePair(tr("GIF format (*.gif)"), QString::fromLatin1("gif"));
|
||||
formatMap << qMakePair(tr("JPG format (*.jpg)"), QString::fromLatin1("jpg"));
|
||||
formatMap << qMakePair(tr("SVG format (*.svg)"), QString::fromLatin1("svg"));
|
||||
formatMap << qMakePair(tr("PDF format (*.pdf)"), QString::fromLatin1("pdf"));
|
||||
//formatMap << qMakePair(tr("VRML format (*.vrml)"), QString::fromLatin1("vrml"));
|
||||
|
||||
QStringList filter;
|
||||
filter << tr("PNG format (*.png)");
|
||||
filter << tr("SVG format (*.svg)");
|
||||
filter << tr("PDF format (*.pdf)");
|
||||
for (QList< QPair<QString, QString> >::iterator it = formatMap.begin(); it != formatMap.end(); ++it)
|
||||
filter << it->first;
|
||||
|
||||
QString selectedFilter;
|
||||
QString fn = Gui::FileDialog::getSaveFileName(this, tr("Export graph"), QString(), filter.join(QLatin1String(";;")), &selectedFilter);
|
||||
if (!fn.isEmpty()) {
|
||||
QByteArray buffer = exportGraph(selectedFilter);
|
||||
QString format;
|
||||
for (QList< QPair<QString, QString> >::iterator it = formatMap.begin(); it != formatMap.end(); ++it) {
|
||||
if (selectedFilter == it->first) {
|
||||
format = it->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QByteArray buffer = exportGraph(format);
|
||||
if (buffer.isEmpty())
|
||||
return false;
|
||||
return true;
|
||||
QFile file(fn);
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
file.write(buffer);
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("Print",pMsg) == 0) {
|
||||
print();
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("PrintPreview",pMsg) == 0) {
|
||||
printPreview();
|
||||
return true;
|
||||
}
|
||||
else if (strcmp("PrintPdf",pMsg) == 0) {
|
||||
printPdf();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -139,7 +150,7 @@ bool GraphvizView::onMsg(const char* pMsg,const char** ppReturn)
|
|||
|
||||
bool GraphvizView::onHasMsg(const char* pMsg) const
|
||||
{
|
||||
if (strcmp("Save",pMsg) == 0)
|
||||
if (strcmp("Save",pMsg) == 0)
|
||||
return true;
|
||||
else if (strcmp("SaveAs",pMsg) == 0)
|
||||
return true;
|
||||
|
@ -157,7 +168,7 @@ void GraphvizView::print(QPrinter* printer)
|
|||
QPainter p(printer);
|
||||
QRect rect = printer->pageRect();
|
||||
view->scene()->render(&p, rect);
|
||||
//QByteArray buffer = exportGraph(QString::fromLatin1("(*.svg)"));
|
||||
//QByteArray buffer = exportGraph(QString::fromLatin1("svg"));
|
||||
//QSvgRenderer svg(buffer);
|
||||
//svg.render(&p, rect);
|
||||
p.end();
|
||||
|
|
Loading…
Reference in New Issue
Block a user