[Uml-devel] branches/work/soc-umbrello/umbrello
Andi Fischer
andi.fischer at hispeed.ch
Sun Mar 18 18:54:48 UTC 2012
SVN commit 1286228 by fischer:
Changes from trunk applied.
M +1 -0 CMakeLists.txt
A dotgenerator.cpp [License: GENERATED FILE]
M +14 -315 dotgenerator.h
M +1 -0 layoutgenerator.h
M +6 -6 layouts/state-export.desktop
M +0 -1 widgets/activitywidget.h
M +1 -0 widgets/categorywidget.h
M +3 -2 widgets/combinedfragmentwidget.h
--- branches/work/soc-umbrello/umbrello/CMakeLists.txt #1286227:1286228
@@ -393,6 +393,7 @@
cmdlineexportallviewsevent.cpp
codeaccessormethod.cpp
component.cpp
+ dotgenerator.cpp
docwindow.cpp
entity.cpp
entityattribute.cpp
--- branches/work/soc-umbrello/umbrello/dotgenerator.h #1286227:1286228
@@ -10,29 +10,10 @@
#ifndef DOTGENERATOR_H
-// app includes
-#include "associationwidget.h"
-#include "statewidget.h"
-#include "debug_utils.h"
-#include "umlwidget.h"
-
-// qt includes
-#include <QFile>
+class UMLScene;
#include <QHash>
-#include <QProcess>
-#include <QRectF>
-#include <QRegExp>
-#include <QString>
-#include <QTemporaryFile>
-#include <QTextStream>
-#include <QtDebug>
+#include <QPointF>
-// kde includes
-#include <KConfigGroup>
-#include <KDesktopFile>
-#include <KStandardDirs>
-
-
#define DOTGENERATOR_DEBUG
/**
* The class DotGenerator provides export of diagrams as dot files.
@@ -42,293 +23,22 @@
class DotGenerator
{
public:
- /**
- * constructor
- */
- DotGenerator()
- : m_scale(72),
- m_usePosition(false)
- {
- }
+ DotGenerator();
- /**
- * set usage of position attribute in dot file
- *
- * @param state The new state
- */
- void setUsePosition(bool state)
- {
- m_usePosition = state;
- }
+ bool usePosition();
+ void setUsePosition(bool state);
- /**
- * return usage of position attribute
- *
- * @return true if position are used
- */
- bool usePosition()
- {
- return m_usePosition;
- }
+ bool useFullNodeLabels();
+ void setUseFullNodeLabels(bool state);
- /**
- * Return a list of available templates for a given scene type
- *
- * @param scene The diagram
- * @param configFiles will contain the collected list of config files
- * @return true if collecting succeeds
- */
- static bool availableConfigFiles(UMLScene *scene, QHash<QString,QString> &configFiles)
- {
- QString diagramType = scene->type().toString().toLower();
- KStandardDirs dirs;
+ static bool availableConfigFiles(UMLScene *scene, QHash<QString,QString> &configFiles);
+ bool readConfigFile(QString diagramType, const QString &variant = "default");
- QStringList fileNames = dirs.findAllResources("data", QString("umbrello/layouts/%1*.desktop").arg(diagramType));
- foreach(const QString &fileName, fileNames) {
- QFileInfo fi(fileName);
- QString baseName;
- if (fi.baseName().contains("-"))
- baseName = fi.baseName().remove(diagramType + "-");
- else if (fi.baseName() == diagramType)
- baseName = fi.baseName();
- else
- baseName = "default";
- KDesktopFile desktopFile(fileName);
- configFiles[baseName] = desktopFile.readName();
- }
- return true;
- }
+ bool createDotFile(UMLScene *scene, const QString &fileName, const QString &variant = "default");
- /**
- * 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;
- }
- uDebug() << "reading config file" << configFileName;
- m_configFileName = configFileName;
- KDesktopFile desktopFile(configFileName);
- KConfigGroup edgesAttributes(&desktopFile,"X-UMBRELLO-Dot-Edges");
- KConfigGroup nodesAttributes(&desktopFile,"X-UMBRELLO-Dot-Nodes");
- KConfigGroup attributes(&desktopFile,"X-UMBRELLO-Dot-Attributes");
- // settings are not needed by dotgenerator
- KConfigGroup settings(&desktopFile,"X-UMBRELLO-Dot-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, edgesAttributes.keyList()) {
- QString value = edgesAttributes.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;
-
- m_generator = settings.readEntry("generator","dot");
-
-#ifdef LAYOUTGENERATOR_DATA_DEBUG
- uDebug() << m_edgeParameters;
- uDebug() << m_nodeParameters;
- uDebug() << m_dotParameters;
-#endif
- return true;
- }
-
- bool findItem(QStringList ¶ms, const QString &search)
- {
- foreach(const QString &s, params) {
- if (s.startsWith(search))
- return true;
- }
- return false;
- }
-
- /**
- * 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->widgetList()) {
- QStringList params;
-
- if (m_nodeParameters.contains("all"))
- params << m_nodeParameters["all"].split(',');
-
- if (usePosition())
- params << QString("pos=\"%1,%2\"").arg(widget->pos().x()+widget->width()/2).arg(widget->pos().y()+widget->height()/2);
-
- QString type = QString(widget->baseTypeStr()).toLower().remove("wt_");
- QString key = "type::" + type;
-
- if (type == "state") {
- StateWidget *w = static_cast<StateWidget *>(widget);
- type = w->stateTypeStr().toLower();
- }
- key = "type::" + type;
- QString label = widget->name() + "\\n" + type;
-
- if (m_nodeParameters.contains(key))
- params << m_nodeParameters[key].split(',');
- else if (m_nodeParameters.contains("type::default"))
- params << m_nodeParameters["type::default"].split(',');
-
- if (!findItem(params,"label="))
- params << QString("label=\"%1\"").arg(label);
-
- if (!findItem(params,"width="))
- params << QString("width=\"%1\"").arg(widget->width()/m_scale);
-
- if (!findItem(params,"height="))
- params << QString("height=\"%1\"").arg(widget->height()/m_scale);
-
-#ifdef DOTGENERATOR_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->associationList()) {
- QString type = assoc->associationType().toString().toLower();
- QString key = "type::" + type;
- bool swapId = m_edgeParameters.contains("id::" + key) && m_edgeParameters["id::" + key] == "swap";
-
- QString label = assoc->name();
-
- QString headLabel = assoc->roleName(swapId ? Uml::B : Uml::A);
- QString tailLabel = assoc->roleName(swapId ? Uml::A : Uml::B);
-
- if (!headLabel.isEmpty())
- headLabel.prepend("+");
- if (!tailLabel.isEmpty())
- tailLabel.prepend("+");
-
- headLabel += QLatin1String(" ") + assoc->multiplicity(swapId ? Uml::B : Uml::A);
- tailLabel += QLatin1String(" ") + assoc->multiplicity(swapId ? Uml::A : Uml::B);
-
- QString edgeParameters;
- QStringList params;
- QString rkey = QLatin1String("ranking::") + key;
- if (m_edgeParameters.contains(rkey))
- edgeParameters = m_edgeParameters[rkey];
- else if (m_edgeParameters.contains("ranking::type::default")) {
- edgeParameters = m_edgeParameters["ranking::type::default"];
- }
- params << edgeParameters.split(',');
-
- QString vkey = QLatin1String("visual::") + key;
- if (m_edgeParameters.contains(vkey))
- edgeParameters = m_edgeParameters[vkey];
- else if (m_edgeParameters.contains("visual::type::default")) {
- edgeParameters = m_edgeParameters["visual::type::default"];
- }
- params << edgeParameters.split(',');
-
- if (!findItem(params,"label="))
- params << QString("label=\"%1\"").arg(label);
-
- if (!findItem(params,"headlabel="))
- params << QString("headlabel=\"%1\"").arg(headLabel);
-
- if (!findItem(params,"taillabel="))
- params << QString("taillabel=\"%1\"").arg(tailLabel);
-
-#ifdef DOTGENERATOR_DATA_DEBUG
- uDebug() << type << params;
-#endif
- QString aID = fixID(ID2STR(assoc->widgetIDForRole(swapId ? Uml::A : Uml::B)));
- QString bID = fixID(ID2STR(assoc->widgetIDForRole(swapId ? Uml::B : Uml::A)));
-
- out << "\"" << aID << "\" -> \"" << bID << "\"" << " [" << 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:
- /**
- * 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;
- }
+ bool findItem(QStringList ¶ms, const QString &search);
+ QString fixID(const QString &_id);
double m_scale; ///< scale factor
QString m_executable; ///< dot executable
@@ -338,21 +48,10 @@
QHash<QString, QString> m_nodeParameters; ///< contains global node parameters
QPointF m_origin;
QString m_generator; ///< name of graphviz generator
- bool m_usePosition;
+ bool m_usePosition; ///< use position tag from dot (not used yet)
+ bool m_useFullNodeLabels; ///< use full node labels
friend QDebug operator<<(QDebug out, DotGenerator &c);
};
-#if 0
-static QDebug operator<<(QDebug out, LayoutGenerator &c)
-{
- out << "LayoutGenerator:"
- << "m_boundingRect:" << c.m_boundingRect
- << "m_nodes:" << c.m_nodes
- << "m_edges:" << c.m_edges
- << "m_scale:" << c.m_scale
- << "m_executable:" << c.m_executable;
- return out;
-}
#endif
-#endif
--- branches/work/soc-umbrello/umbrello/layoutgenerator.h #1286227:1286228
@@ -97,6 +97,7 @@
*/
LayoutGenerator()
{
+ setUseFullNodeLabels(false);
}
/**
--- branches/work/soc-umbrello/umbrello/layouts/state-export.desktop #1286227:1286228
@@ -19,9 +19,9 @@
type::initial=shape=circle
type::normal=shape=box,style=rounded
type::end=shape=doublecircle
-type::fork=style=filled,shape=box,fillcolor=black,width="0.1",label=""
-type::join=style=filled,shape=box,fillcolor=black,width="0.1",label=""
-type::junction=shape=circle,fillcolor=black,width="0.4",label=""
+type::fork=shape=box,style=filled,fillcolor=black,width="0.1",label=""
+type::join=shape=box,style=filled,fillcolor=black,width="0.1",label=""
+type::junction=shape=circle,style=filled,fillcolor=black,width="0.4",label=""
type::deephistory=shape=circle,width="0.4",label="H*"
type::shallowhistory=shape=circle,width="0.4",label="H"
type::choice=shape=diamond
@@ -31,15 +31,15 @@
# for visual representation
visual::type::state=arrowhead=normal,label=""
#visual::type::default=arrowhead=none,minlen=0.5
-ranking::type::default=constraint=false
+ranking::type::default=len=2
# id handling
id::type::state=swap
[X-UMBRELLO-Dot-Attributes]
-graph=splines=polyline,rankdir=TB,outputorder=nodesfirst,ranksep=0.5,nodesep=0.5
+graph=splines=polyline,model=mds,normalize=yes
node=
edge=
[X-UMBRELLO-Dot-Settings]
origin=50,50
-generator=circo
+generator=neato
--- branches/work/soc-umbrello/umbrello/widgets/activitywidget.h #1286227:1286228
@@ -74,7 +74,6 @@
virtual void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
public Q_SLOTS:
-
virtual void slotMenuSelection(QAction* action);
protected:
--- branches/work/soc-umbrello/umbrello/widgets/categorywidget.h #1286227:1286228
@@ -42,6 +42,7 @@
public Q_SLOTS:
void slotMenuSelection(QAction* action);
+
};
#endif
--- branches/work/soc-umbrello/umbrello/widgets/combinedfragmentwidget.h #1286227:1286228
@@ -4,14 +4,15 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2002-2006 *
+ * copyright (C) 2002-2009 *
* Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
#ifndef COMBINEDFRAGMENTWIDGET_H
#define COMBINEDFRAGMENTWIDGET_H
-#include <qlist.h>
+#include <QtCore/QList>
+
#include "umlwidget.h"
#include "worktoolbar.h"
#include "floatingdashlinewidget.h"
More information about the umbrello-devel
mailing list