Merge pull request #10586 from wwmayer/issue_9422
Gui: fixes issue #9422: Dependency Graph: export to .dot/.gv
This commit is contained in:
@@ -592,6 +592,47 @@ bool StdCmdDependencyGraph::isActive()
|
||||
return (getActiveGuiDocument() ? true : false);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_ExportDependencyGraph
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(StdCmdExportDependencyGraph)
|
||||
|
||||
StdCmdExportDependencyGraph::StdCmdExportDependencyGraph()
|
||||
: Command("Std_ExportDependencyGraph")
|
||||
{
|
||||
sGroup = "Tools";
|
||||
sMenuText = QT_TR_NOOP("Export dependency graph...");
|
||||
sToolTipText = QT_TR_NOOP("Export the dependency graph to a file");
|
||||
sStatusTip = QT_TR_NOOP("Export the dependency graph to a file");
|
||||
sWhatsThis = "Std_ExportDependencyGraph";
|
||||
eType = 0;
|
||||
//sPixmap = "Std_ExportDependencyGraph";
|
||||
}
|
||||
|
||||
void StdCmdExportDependencyGraph::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
QString format = QString::fromLatin1("%1 (*.gv)").arg(Gui::GraphvizView::tr("Graphviz format"));
|
||||
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), Gui::GraphvizView::tr("Export graph"), QString(), format);
|
||||
if (!fn.isEmpty()) {
|
||||
QFile file(fn);
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
std::stringstream str;
|
||||
doc->exportGraphviz(str);
|
||||
QByteArray buffer = QByteArray::fromStdString(str.str());
|
||||
file.write(buffer);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool StdCmdExportDependencyGraph::isActive()
|
||||
{
|
||||
return (getActiveGuiDocument() ? true : false);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// Std_New
|
||||
//===========================================================================
|
||||
@@ -1901,6 +1942,7 @@ void CreateDocCommands()
|
||||
rcCmdMgr.addCommand(new StdCmdExport());
|
||||
rcCmdMgr.addCommand(new StdCmdMergeProjects());
|
||||
rcCmdMgr.addCommand(new StdCmdDependencyGraph());
|
||||
rcCmdMgr.addCommand(new StdCmdExportDependencyGraph());
|
||||
|
||||
rcCmdMgr.addCommand(new StdCmdSave());
|
||||
rcCmdMgr.addCommand(new StdCmdSaveAs());
|
||||
|
||||
@@ -441,35 +441,45 @@ QByteArray GraphvizView::exportGraph(const QString& format)
|
||||
return dotProc.readAll();
|
||||
}
|
||||
|
||||
bool GraphvizView::onMsg(const char* pMsg,const char**)
|
||||
bool GraphvizView::onMsg(const char* pMsg, const char**)
|
||||
{
|
||||
if (strcmp("Save",pMsg) == 0 || strcmp("SaveAs",pMsg) == 0) {
|
||||
QList< QPair<QString, QString> > formatMap;
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.gv)").arg(tr("Graphviz format")), QString::fromLatin1("gv"));
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.png)").arg(tr("PNG format")), QString::fromLatin1("png"));
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.bmp)").arg(tr("Bitmap format")), QString::fromLatin1("bmp"));
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.gif)").arg(tr("GIF format")), QString::fromLatin1("gif"));
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.jpg)").arg(tr("JPG format")), QString::fromLatin1("jpg"));
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.svg)").arg(tr("SVG format")), QString::fromLatin1("svg"));
|
||||
formatMap << qMakePair(QString::fromLatin1("%1 (*.pdf)").arg(tr("PDF format")), QString::fromLatin1("pdf"));
|
||||
//formatMap << qMakePair(tr("VRML format (*.vrml)"), QString::fromLatin1("vrml"));
|
||||
|
||||
QStringList filter;
|
||||
for (const auto & it : formatMap)
|
||||
for (const auto & it : qAsConst(formatMap)) {
|
||||
filter << it.first;
|
||||
}
|
||||
|
||||
QString selectedFilter;
|
||||
QString fn = Gui::FileDialog::getSaveFileName(this, tr("Export graph"), QString(), filter.join(QLatin1String(";;")), &selectedFilter);
|
||||
if (!fn.isEmpty()) {
|
||||
QString format;
|
||||
for (const auto & it : formatMap) {
|
||||
for (const auto & it : qAsConst(formatMap)) {
|
||||
if (selectedFilter == it.first) {
|
||||
format = it.second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QByteArray buffer = exportGraph(format);
|
||||
if (buffer.isEmpty())
|
||||
QByteArray buffer;
|
||||
if (format == QLatin1String("gv")) {
|
||||
std::stringstream str;
|
||||
doc.exportGraphviz(str);
|
||||
buffer = QByteArray::fromStdString(str.str());
|
||||
}
|
||||
else {
|
||||
buffer = exportGraph(format);
|
||||
}
|
||||
if (buffer.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
QFile file(fn);
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
file.write(buffer);
|
||||
|
||||
@@ -702,6 +702,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
|
||||
<< "Std_ViewLoadImage"
|
||||
<< "Std_SceneInspector"
|
||||
<< "Std_DependencyGraph"
|
||||
<< "Std_ExportDependencyGraph"
|
||||
<< "Std_ProjectUtil"
|
||||
<< "Separator"
|
||||
<< "Std_MeasureDistance"
|
||||
|
||||
Reference in New Issue
Block a user