[Uml-devel] KDE/kdesdk/umbrello/umbrello
Ralf Habacker
ralf.habacker at gmail.com
Wed Mar 7 13:20:54 UTC 2012
SVN commit 1284087 by habacker:
Moved out dot generating code into separate class DotGenerator, which makes it able
to use this code also for diagram dot export feature.
CCBUG: 67059
A dotgenerator.h [License: GPL (v2+)]
M +4 -198 layoutgenerator.h
M +25 -25 layouts/class-horizontal.desktop
M +27 -26 layouts/class-vertical.desktop
M +18 -19 layouts/usecase-default.desktop
--- trunk/KDE/kdesdk/umbrello/umbrello/layoutgenerator.h #1284086:1284087
@@ -12,6 +12,7 @@
#include "associationwidget.h"
#include "debug_utils.h"
+#include "dotgenerator.h"
#include "floatingtextwidget.h"
#include "umlwidget.h"
@@ -83,7 +84,7 @@
*
* @author Ralf Habacker <ralf.habacker at freenet.de>
*/
-class LayoutGenerator
+class LayoutGenerator : public DotGenerator
{
public:
typedef QHash<QString,QRectF> NodeType;
@@ -273,185 +274,6 @@
return true;
}
- /**
- * Read a layout config file
- *
- * @param diagramType String identifing the diagram
- * @param variant String identifing the variant
- * @return true on success
- */
- bool readConfigFile(QString diagramType, const QString &variant = "default")
- {
- QStringList fileNames;
-
- if (!variant.isEmpty())
- fileNames << QString("%1-%2.desktop").arg(diagramType).arg(variant);
- fileNames << QString("%1-default.desktop").arg(diagramType);
- fileNames << "default.desktop";
-
- QString configFileName;
- foreach(const QString &fileName, fileNames) {
- configFileName = KStandardDirs::locate("data", QString("umbrello/layouts/%1").arg(fileName));
- if (!configFileName.isEmpty())
- break;
- }
-
- if (configFileName.isEmpty()) {
- uError() << "could not find layout config file name for diagram type" << diagramType << "and variant" << variant;
- return false;
- }
-
- m_configFileName = configFileName;
- KDesktopFile desktopFile(configFileName);
- KConfigGroup edgesRankingAttributes(&desktopFile,"X-UMBRELLO-Edges-Ranking");
- KConfigGroup edgesVisualAttributes(&desktopFile,"X-UMBRELLO-Edges-Visual");
- KConfigGroup nodesAttributes(&desktopFile,"X-UMBRELLO-Nodes");
- KConfigGroup attributes(&desktopFile,"X-UMBRELLO-Attributes");
- KConfigGroup settings(&desktopFile,"X-UMBRELLO-Settings");
-
- m_edgeParameters.clear();
- m_nodeParameters.clear();
- m_dotParameters.clear();
-
- foreach(const QString &key, attributes.keyList()) {
- QString value = attributes.readEntry(key);
- if (!value.isEmpty())
- m_dotParameters[key] = value;
- }
-
- foreach(const QString &key, nodesAttributes.keyList()) {
- QString value = nodesAttributes.readEntry(key);
- m_nodeParameters[key] = value;
- }
-
- foreach(const QString &key, edgesRankingAttributes.keyList()) {
- QString value = edgesRankingAttributes.readEntry(key);
- if (m_edgeParameters.contains(key)) {
- m_edgeParameters[key] += ',' + value;
- } else {
- m_edgeParameters[key] = value;
- }
- }
-
- foreach(const QString &key, edgesVisualAttributes.keyList()) {
- QString value = edgesVisualAttributes.readEntry(key);
- if (m_edgeParameters.contains(key)) {
- m_edgeParameters[key] += ',' + value;
- } else {
- m_edgeParameters[key] = value;
- }
- }
-
- QString value = settings.readEntry("origin");
- QStringList a = value.split(",");
- if (a.size() == 2)
- m_origin = QPointF(a[0].toDouble(), a[1].toDouble());
- else
- uError() << "illegal format of entry 'origin'" << value;
-
-#ifdef LAYOUTGENERATOR_DATA_DEBUG
- uDebug() << m_edgeParameters;
- uDebug() << m_nodeParameters;
- uDebug() << m_dotParameters;
-#endif
- return true;
- }
-
- /**
- * Create dot file using displayed widgets
- * and associations of the provided scene
- * @note This method could also be used as a base to export diagrams as dot file
- *
- * @param fileName Filename where to create the dot file
- * @param scene The diagram from which the widget informations are fetched
- *
- * @return true if generating finished successfully
- */
- bool createDotFile(UMLScene *scene, const QString &fileName, const QString &variant = "default")
- {
- QFile file(fileName);
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
- return false;
-
- QString diagramType = scene->type().toString().toLower();
- if (!readConfigFile(diagramType, variant))
- return false;
-
- QString data;
- QTextStream out(&data);
-
- foreach(UMLWidget *widget, scene->getWidgetList()) {
- QStringList params;
-
- if (m_nodeParameters.contains("all"))
- params << m_nodeParameters["all"];
-
- params << QString("width=\"%1\"").arg(widget->getWidth()/m_scale)
- << QString("height=\"%1\"").arg(widget->getHeight()/m_scale);
-
- QString type = QString(widget->baseTypeStr()).toLower().remove("wt_");
- QString key = "type::" + type;
- QString label = widget->name() + "\\n" + type;
-
- if (m_nodeParameters.contains(key))
- params << m_nodeParameters[key];
- else if (m_nodeParameters.contains("type::default")) {
- params << m_nodeParameters["type::default"];
- if (label.isEmpty())
- label = type;
- }
-
- params << QString("label=\"%1\"").arg(label);
-
-#ifdef LAYOUTGENERATOR_DATA_DEBUG
- uDebug() << type << params;
-#endif
- QString id = fixID(ID2STR(widget->id()));
- if (widget->baseType() != WidgetBase::wt_Text)
- out << "\"" << id << "\""
- << " [" << params.join(",") << "];\n";
- }
-
- foreach(AssociationWidget *assoc, scene->getAssociationList()) {
- QStringList params;
- QString label;
- QString type = assoc->associationType().toString().toLower();
- QString key = "type::" + type;
- label = type;
- QString edgeParameters;
-
- if (m_edgeParameters.contains(key))
- edgeParameters = m_edgeParameters[key];
- else if (m_edgeParameters.contains("type::default")) {
- edgeParameters = m_edgeParameters["type::default"];
- }
- params << edgeParameters;
-
- QString aID = fixID(ID2STR(assoc->getWidgetID(Uml::A)));
- QString bID = fixID(ID2STR(assoc->getWidgetID(Uml::B)));
- params << QString("label=\"%1\"").arg(type);
-
-#ifdef LAYOUTGENERATOR_DATA_DEBUG
- uDebug() << type << params;
-#endif
- out << "\"" << bID << "\" -> \"" << aID << "\""
- << " [" << params.join(",") << "];\n";
- }
-
- QTextStream o(&file);
- o << "# generated from " << m_configFileName << "\n";
- o << "digraph G {\n";
-
- foreach(const QString &key, m_dotParameters.keys()) {
- o << "\t" << key << " [" << m_dotParameters[key] << "];\n";
- }
-
- o << data << "\n";
- o << "}\n";
-
- return true;
- }
-
protected:
/**
* Return the origin of node based on the bottom/left corner
@@ -498,17 +320,6 @@
return true;
}
- /**
- * There are id wrapped with '"', remove it.
- */
- QString fixID(const QString &_id)
- {
- // FIXME: some widget's ids returned from the list are wrapped with "\"", find and fix them
- QString id(_id);
- id.remove("\"");
- return id;
- }
-
#ifndef USE_XDOT
/**
* Parse line from dot generated plain-ext output format
@@ -717,12 +528,7 @@
NodeType m_nodes; ///< list of nodes found in parsed dot file
EdgeType m_edges; ///< list of edges found in parsed dot file
double m_scale; ///< scale factor
- QString m_executable; ///< dot executable
- QString m_configFileName; ///< template filename
- QHash<QString, QString> m_dotParameters; ///< contains global graph parameters
- QHash<QString, QString> m_edgeParameters; ///< contains global edge parameters
- QHash<QString, QString> m_nodeParameters; ///< contains global node parameters
- QHash<QString, QPointF> m_edgeLabelPosition; ///< contains global node parameters
+ //QHash<QString, QPointF> m_edgeLabelPosition; ///< contains global node parameters
QPointF m_origin;
friend QDebug operator<<(QDebug out, LayoutGenerator &c);
@@ -740,4 +546,4 @@
return out;
}
#endif
-#endif
\ No newline at end of file
+#endif
--- trunk/KDE/kdesdk/umbrello/umbrello/layouts/class-horizontal.desktop #1284086:1284087
@@ -4,39 +4,39 @@
Comment=Layout which renders Horizontal
Comment[x-test]=xxHorizontal Layoutxx
-[X-UMBRELLO-Nodes]
+[X-UMBRELLO-Dot-Nodes]
type::class=shape=box
type::default=shape=box
# for image output
-[X-UMBRELLO-Edges-Visual]
-type::anchor=arrowhead=none
-type::aggregation=arrowhead=odiamond
-type::composition=arrowhead=diamond
-type::dependency=arrowtail=vee,style=dashed,dir=back
-type::uniassociation=arrowtail=vee,dir=back
-type::association=arrowhead=none
-type::generalization=arrowtail=normal,dir=back
-type::realisation=arrowtail=normal,dir=back
-type::default=arrowhead=none
+[X-UMBRELLO-Dot-Edges]
+visual::type::anchor=arrowhead=none,style=dashed
+visual::type::aggregation=arrowtail=odiamond,dir=back
+visual::type::composition=arrowtail=diamond,dir=back
+visual::type::dependency=arrowtail=vee,style=dashed,dir=back
+visual::type::uniassociation=arrowtail=vee,dir=back
+visual::type::association=arrowhead=none
+visual::type::generalization=arrowtail=normal,dir=back
+visual::type::realisation=arrowtail=normal,dir=back
+visual::type::default=arrowhead=none
+# for position ranking
+ranking::type::anchor=constraint=false
+ranking::type::aggregation=weight=0.01
+ranking::type::association=constraint=false
+ranking::type::composition=weight=0.01
+ranking::type::dependency=weight=0.01
+ranking::type::generalization=weight=1.0
+ranking::type::realisation=weight=0.8
+ranking::type::uniassociation=constraint=false
+ranking::type::default=constraint=false
+# id handling
+id::type::aggregation=swap
-# for ranking (entries are added)
-[X-UMBRELLO-Edges-Ranking]
-type::anchor=constraint=false
-type::aggregation=weight=0.01
-type::association=constraint=false
-type::composition=weight=0.01
-type::dependency=weight=0.01
-type::generalization=weight=1.0
-type::realisation=weight=0.8
-type::uniassociation=constraint=false
-type::default=constraint=false
-
-[X-UMBRELLO-Attributes]
+[X-UMBRELLO-Dot-Attributes]
graph=splines=polyline,rankdir=LR,outputorder=nodesfirst,ranksep=1.0,nodesep=0.8
node=
edge=
-[X-UMBRELLO-Settings]
+[X-UMBRELLO-Dot-Settings]
origin=50,50
--- trunk/KDE/kdesdk/umbrello/umbrello/layouts/class-vertical.desktop #1284086:1284087
@@ -4,38 +4,39 @@
Comment=Layout which renders vertical
Comment[x-test]=xxVertical Layoutxx
-[X-UMBRELLO-Nodes]
+[X-UMBRELLO-Dot-Nodes]
type::class=shape=box
type::default=shape=box
# for dot output
-[X-UMBRELLO-Edges-Visual]
-type::anchor=arrowhead=none
-type::aggregation=arrowhead=odiamond
-type::composition=arrowhead=diamond
-type::dependency=arrowtail=vee,style=dashed,dir=back
-type::uniassociation=arrowtail=vee,dir=back
-type::association=arrowhead=none
-type::generalization=arrowtail=normal,dir=back
-type::realisation=arrowtail=normal,dir=back
-type::default=arrowhead=none
+[X-UMBRELLO-Dot-Edges]
+# for visual representation
+visual::type::anchor=arrowhead=none,style=dashed
+visual::type::aggregation=arrowtail=odiamond,dir=back
+visual::type::composition=arrowtail=diamond,dir=back
+visual::type::dependency=arrowtail=vee,style=dashed,dir=back
+visual::type::uniassociation=arrowtail=vee,dir=back
+visual::type::association=arrowhead=none
+visual::type::generalization=arrowtail=normal,dir=back
+visual::type::realisation=arrowtail=normal,dir=back
+visual::type::default=arrowhead=none
+# for position ranking
+ranking::type::anchor=constraint=false
+ranking::type::aggregation=weight=0.001
+ranking::type::association=constraint=false
+ranking::type::composition=weight=0.001
+ranking::type::dependency=weight=0.001
+ranking::type::generalization=weight=1.0
+ranking::type::realisation=weight=0.8
+ranking::type::uniassociation=constraint=false
+ranking::type::default=constraint=false
+# id handling
+id::type::aggregation=swap
-# for ranking (entries are added)
-[X-UMBRELLO-Edges-Ranking]
-type::anchor=constraint=false
-type::aggregation=weight=0.01
-type::association=constraint=false
-type::composition=weight=0.01
-type::dependency=constraint=false
-type::generalization=weight=1.0
-type::realisation=weight=0.8
-type::uniassociation=constraint=false
-type::default=constraint=false
-
-[X-UMBRELLO-Attributes]
-graph=splines=polyline,rankdir=TB,outputorder=nodesfirst,ranksep=1.5,nodesep=0.5
+[X-UMBRELLO-Dot-Attributes]
+graph=splines=polyline,rankdir=TB,outputorder=nodesfirst,ranksep=0.5,nodesep=0.5
node=
edge=
-[X-UMBRELLO-Settings]
+[X-UMBRELLO-Dot-Settings]
origin=50,50
--- trunk/KDE/kdesdk/umbrello/umbrello/layouts/usecase-default.desktop #1284086:1284087
@@ -4,34 +4,33 @@
Comment=Usecase Default Layout
Comment[x-test]=xxDefault Layoutxx
-[X-UMBRELLO-Nodes]
+[X-UMBRELLO-Dot-Nodes]
type::usecase shape=ellipse
type::actor shape=circle
type::note shape=box
type::default=shape=box
# for dot output
-[X-UMBRELLO-Edges-Visual]
-type::anchor=arrowhead=none
-type::aggregation=arrowhead=odiamond
-type::composition=arrowhead=diamond
-type::dependency=arrowtail=vee,style=dashed,dir=back
-type::uniassociation=arrowtail=vee,dir=back
-type::association=arrowhead=none
-type::generalization=arrowtail=normal,dir=back
-type::realisation=arrowtail=normal,dir=back
-type::default=arrowhead=none
+[X-UMBRELLO-Dot-Edges]
+# for visual representation
+visual::type::anchor=arrowhead=none,style=dashed
+visual::type::aggregation=arrowtail=odiamond,dir=back
+visual::type::composition=arrowtail=diamond,dir=back
+visual::type::dependency=arrowtail=vee,style=dashed,dir=back
+visual::type::uniassociation=arrowtail=vee,dir=back
+visual::type::association=arrowhead=none
+visual::type::generalization=arrowtail=normal,dir=back
+visual::type::realisation=arrowtail=normal,dir=back
+visual::type::default=arrowhead=none
+# for position ranking
+ranking::type::association=weight=1.0
+ranking::type::uniassociation=weight=0.1
+ranking::type::default=constraint=false
-# for ranking (entries are added)
-[X-UMBRELLO-Edges-Ranking]
-type::association=weight=1.0
-type::uniassociation=weight=0.1
-type::default=constraint=false
-
-[X-UMBRELLO-Attributes]
+[X-UMBRELLO-Dot-Attributes]
graph=splines=polyline,rankdir=RL,outputorder=nodesfirst,ranksep=1.5,nodesep=0.5
node=
edge=
-[X-UMBRELLO-Settings]
+[X-UMBRELLO-Dot-Settings]
origin=50,50
More information about the umbrello-devel
mailing list