layoutgenerator.h 2.82 KB
Newer Older
1
2
3
4
5
6
/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
Oliver Kellogg's avatar
Oliver Kellogg committed
7
 *   copyright (C) 2012-2014                                               *
Ralf Habacker's avatar
Ralf Habacker committed
8
 *   Umbrello UML Modeller Authors <umbrello-devel@kde.org>                *
9
10
11
12
 ***************************************************************************/

#ifndef LAYOUTGENERATOR_H

13
#include "dotgenerator.h"
14
#include "optionstate.h"
15

16
//// qt includes
17
18
19
20
21
22
23
24
#include <QRectF>

/**
 * The class LayoutGenerator provides calculated layouts of diagrams.
 *
 * It uses the dot executable from the graphviz package for calculation
 * of widget positions.
 *
Ralf Habacker's avatar
Ralf Habacker committed
25
26
 * The implementation calls dot with information from the displayed
 * widgets and associations by creating a temporary dot file based on a
27
28
 * layout configure file, which is located in the umbrello/layouts subdir of
 * the "data" resource type. The config file is determined from the
Ralf Habacker's avatar
Ralf Habacker committed
29
 * type of the currently displayed diagram and the layout chosen by the user.
30
31
32
33
34
35
36
37
 *
 * Dot creates a file containing the calculated widget positions.
 * The widget positions are retrieved from this file and used to move
 * widgets on the provided diagram. Additional points in association lines
 * are removed.
 *
 * @author Ralf Habacker <ralf.habacker@freenet.de>
 */
38
class LayoutGenerator : public DotGenerator
39
40
41
42
43
44
45
{
public:
    typedef QHash<QString,QRectF> NodeType;
    typedef QList<QPointF> EdgePoints;
    typedef QHash<QString,EdgePoints> EdgeType;
    typedef QMap<QString,QStringList> ParameterList;

46
    LayoutGenerator();
47

48
49
50
51
52
    bool isEnabled();
    static QString currentDotPath();
    bool generate(UMLScene *scene, const QString &variant = QString());
    bool apply(UMLScene *scene);
    static bool availableConfigFiles(UMLScene *scene, QHash<QString,QString> &configFiles);
53
    QPointF origin(const QString &id);
54
55
56
57
    bool readGeneratedDotFile(const QString &fileName);
    bool parseLine(const QString &line);
    bool splitParameters(QMap<QString,QStringList> &map, const QString &s);
    QPointF mapToScene(const QPointF &p);
58

59
protected:
60
61
62
    QRectF m_boundingRect;
    NodeType m_nodes;      ///< list of nodes found in parsed dot file
    EdgeType m_edges;      ///< list of edges found in parsed dot file
Ralf Habacker's avatar
Ralf Habacker committed
63
    QHash<QString, QPointF> m_edgeLabelPosition; ///< contains global node parameters
64
    QString m_dotPath;     ///< contains path to dot executable
65
66
67
68
69

    friend QDebug operator<<(QDebug out, LayoutGenerator &c);
};

#if 0
70
static QDebug operator<<(QDebug out, LayoutGenerator &c);
71
#endif
72

73
#endif