[Qt-creator] qmodel2svg

Jochen Becher jochen_becher at gmx.de
Sun Dec 9 13:06:15 CET 2018


Hi Christian,

yes, writing a tool that loads a qmodel file and exports an svg diagram
(or pdf or pixel image) is not a big deal using modelinglib:

1. Create an instance of qmt::DocumentController

2. Load a qmodel file with qmt::DocumentController::loadProject().
Handle some exceptions for file-not-found etc. You must look into the
implementation of loadProject() to find out which exceptions are thrown
during loading.

3. Implement a visitor derived from qmt::MVoidConstVisitor that
searches for a diagram by name. Look into qmt::MChildrenVisitor on how
to visit the whole model tree (you could also derive from
qmt::MChildrenVisitor but that is not a const visitor). You get the
root element on which you accept the visitor from
qmt::ModelController::rootPackage(). The ModelController is available
from your DocumentController instance.

4. From your DocumentController instance get the qmt::DiagramsManager.
Bind your qmt::MDiagram* that you got from the visitor with
DiagramsManager::bindDiagramSceneModel().

5. Use the returned qmt::DiagramSceneModel to exportImage(),
exportPdf() or exportSvg().

That's all. Should be a single file program with less than 500 lines
including the visitor.

Please submit the tool as part of the tools of the QtCreator project.

Regards, Jochen


Am Sonntag, den 09.12.2018, 19:47 +1300 schrieb Christian Gagneraud:
> Hi there,
> 
> Every now and then I use QtCreator's ModelEditor plugin.
> I like to write documentation in MD, and i usually manage the sources
> with a Makefile to automate various stages for the final off-line
> production.
> A missing tool in my workflow is one that could convert a qmodel file
> into SVG, from the command line.
> Is it possible to use qtcreator in command line mode to ask the
> ModelEditor plugin to do an SVG export?
> If not, I do think that it shouldn't be that hard to write such a
> dedicated tool, I see 3 ways, from the easiest to the hackiest:
> 1:
>  - link to modellib and find a way to do the export
> Is that simple?
> 2:
>  - link against corelib, and initialise it with defaults
>  - link against extentionsystem, and initialise it with defaults
>  - ask the extension system to load modeleditor plugin
>  - call directly into this plugin and ask for the conversion
> 3:
> Like 2, but given that Core contains the editor manager and the
> document manager, i should be able to open a document  with an editor
> and automate the export (if i don't want to see any UI, i could use
> the Linux offscreen QPA to hide it)
> 
> Chris
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at lists.qt-project.org
> https://lists.qt-project.org/listinfo/qt-creator




More information about the Qt-creator mailing list