Gui: fixes issue #9422: Dependency Graph: export to .dot/.gv

This commit is contained in:
wmayer
2023-09-07 08:40:05 +02:00
parent 80a54d51c1
commit e85c41440d
3 changed files with 59 additions and 6 deletions

View File

@@ -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());