Changeset View
Changeset View
Standalone View
Standalone View
src/part/dotgraph.h
Show All 18 Lines | |||||
19 | /* | 19 | /* | ||
20 | * Graphviz DOT graph model | 20 | * Graphviz DOT graph model | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #ifndef DOT_GRAPH_H | 23 | #ifndef DOT_GRAPH_H | ||
24 | #define DOT_GRAPH_H | 24 | #define DOT_GRAPH_H | ||
25 | 25 | | |||
26 | #include <QList> | 26 | #include <QList> | ||
27 | #include <QMutex> | ||||
28 | #include <QProcess> | ||||
27 | #include <QSet> | 29 | #include <QSet> | ||
28 | #include <QString> | 30 | #include <QString> | ||
29 | #include <QProcess> | | |||
30 | #include <QMutex> | | |||
31 | 31 | | |||
32 | #include <graphviz/gvc.h> | 32 | #include <graphviz/gvc.h> | ||
33 | 33 | | |||
34 | #include "kgraphviewer_export.h" | 34 | #include "dotdefaults.h" | ||
35 | #include "graphedge.h" | ||||
35 | #include "graphelement.h" | 36 | #include "graphelement.h" | ||
36 | #include "graphsubgraph.h" | | |||
37 | #include "graphnode.h" | 37 | #include "graphnode.h" | ||
38 | #include "graphedge.h" | 38 | #include "graphsubgraph.h" | ||
39 | #include "dotdefaults.h" | 39 | #include "kgraphviewer_export.h" | ||
40 | 40 | | |||
41 | namespace KGraphViewer | 41 | namespace KGraphViewer { | ||
42 | { | | |||
43 | 42 | | |||
44 | /** | 43 | /** | ||
45 | * A class representing the model of a Graphviz DOT graph | 44 | * A class representing the model of a Graphviz DOT graph | ||
46 | */ | 45 | */ | ||
47 | class DotGraph : public GraphElement | 46 | class DotGraph : public GraphElement { | ||
48 | { | | |||
49 | Q_OBJECT | 47 | Q_OBJECT | ||
50 | public: | 48 | public: | ||
51 | enum ParsePhase {Initial, Final}; | 49 | enum ParsePhase { Initial, Final }; | ||
52 | 50 | | |||
53 | DotGraph(); | 51 | DotGraph(); | ||
54 | DotGraph(const QString& command, const QString& fileName); | 52 | DotGraph(const QString &command, const QString &fileName); | ||
55 | 53 | | |||
56 | ~DotGraph() override; | 54 | ~DotGraph() override; | ||
57 | 55 | | |||
58 | QString chooseLayoutProgramForFile(const QString& str); | 56 | QString chooseLayoutProgramForFile(const QString &str); | ||
59 | bool parseDot(const QString& str); | 57 | bool parseDot(const QString &str); | ||
60 | 58 | | |||
61 | /** Constant accessor to the nodes of this graph */ | 59 | /** Constant accessor to the nodes of this graph */ | ||
62 | inline const GraphNodeMap& nodes() const {return m_nodesMap;} | 60 | inline const GraphNodeMap &nodes() const { return m_nodesMap; } | ||
63 | /** Constant accessor to the edges of this graph */ | 61 | /** Constant accessor to the edges of this graph */ | ||
64 | inline const GraphEdgeMap& edges() const {return m_edgesMap;} | 62 | inline const GraphEdgeMap &edges() const { return m_edgesMap; } | ||
65 | inline const GraphSubgraphMap& subgraphs() const {return m_subgraphsMap;} | 63 | inline const GraphSubgraphMap &subgraphs() const { return m_subgraphsMap; } | ||
66 | /** Accessor to the nodes of this graph */ | 64 | /** Accessor to the nodes of this graph */ | ||
67 | inline GraphNodeMap& nodes() {return m_nodesMap;} | 65 | inline GraphNodeMap &nodes() { return m_nodesMap; } | ||
68 | /** Accessor to the edges of this graph */ | 66 | /** Accessor to the edges of this graph */ | ||
69 | inline GraphEdgeMap& edges() {return m_edgesMap;} | 67 | inline GraphEdgeMap &edges() { return m_edgesMap; } | ||
70 | inline GraphSubgraphMap& subgraphs() {return m_subgraphsMap;} | 68 | inline GraphSubgraphMap &subgraphs() { return m_subgraphsMap; } | ||
71 | double width() const {return m_width;} | 69 | double width() const { return m_width; } | ||
72 | double height() const {return m_height;} | 70 | double height() const { return m_height; } | ||
73 | double scale() const {return m_scale;} | 71 | double scale() const { return m_scale; } | ||
74 | void width(double w) {m_width = w;} | 72 | void width(double w) { m_width = w; } | ||
75 | void height(double h) {m_height = h;} | 73 | void height(double h) { m_height = h; } | ||
76 | void scale(double s) {m_scale = s;} | 74 | void scale(double s) { m_scale = s; } | ||
77 | QString backColor() const override; | 75 | QString backColor() const override; | ||
78 | 76 | | |||
79 | inline void strict(bool s) {m_strict = s;} | 77 | inline void strict(bool s) { m_strict = s; } | ||
80 | inline void directed(bool d) {m_directed = d;} | 78 | inline void directed(bool d) { m_directed = d; } | ||
81 | inline bool strict() const {return m_strict;} | 79 | inline bool strict() const { return m_strict; } | ||
82 | inline bool directed() const {return m_directed;} | 80 | inline bool directed() const { return m_directed; } | ||
83 | 81 | | |||
84 | QSet< GraphNode* >& nodesOfCell(unsigned int id); | 82 | QSet<GraphNode *> &nodesOfCell(unsigned int id); | ||
85 | 83 | | |||
86 | inline unsigned int horizCellFactor() const {return m_horizCellFactor;} | 84 | inline unsigned int horizCellFactor() const { return m_horizCellFactor; } | ||
87 | inline unsigned int vertCellFactor() const {return m_vertCellFactor;} | 85 | inline unsigned int vertCellFactor() const { return m_vertCellFactor; } | ||
88 | inline double wdhcf() const {return m_wdhcf;} | 86 | inline double wdhcf() const { return m_wdhcf; } | ||
89 | inline double hdvcf() const {return m_hdvcf;} | 87 | inline double hdvcf() const { return m_hdvcf; } | ||
90 | 88 | | |||
91 | inline void layoutCommand(const QString& command) {m_layoutCommand = command;} | 89 | inline void layoutCommand(const QString &command) { | ||
90 | m_layoutCommand = command; | ||||
91 | } | ||||
92 | inline const QString& layoutCommand() {return m_layoutCommand;} | 92 | inline const QString &layoutCommand() { return m_layoutCommand; } | ||
93 | 93 | | |||
94 | inline void dotFileName(const QString& fileName) {m_dotFileName = fileName;} | 94 | inline void dotFileName(const QString &fileName) { | ||
95 | m_dotFileName = fileName; | ||||
96 | } | ||||
95 | inline const QString& dotFileName() const {return m_dotFileName;} | 97 | inline const QString &dotFileName() const { return m_dotFileName; } | ||
96 | 98 | | |||
97 | bool update(); | 99 | bool update(); | ||
98 | 100 | | |||
99 | inline void setReadWrite() {m_readWrite = true;} | 101 | inline void setReadWrite() { m_readWrite = true; } | ||
100 | inline void setReadOnly() {m_readWrite = false;} | 102 | inline void setReadOnly() { m_readWrite = false; } | ||
101 | 103 | | |||
102 | void storeOriginalAttributes() override; | 104 | void storeOriginalAttributes() override; | ||
103 | 105 | | |||
104 | void KGRAPHVIEWER_EXPORT saveTo(const QString& fileName); | 106 | void KGRAPHVIEWER_EXPORT saveTo(const QString &fileName); | ||
105 | 107 | | |||
106 | void updateWithGraph(graph_t* newGraph); | 108 | void updateWithGraph(graph_t *newGraph); | ||
107 | void updateWithGraph(const DotGraph& graph); | 109 | void updateWithGraph(const DotGraph &graph); | ||
108 | 110 | | |||
109 | void KGRAPHVIEWER_EXPORT setAttribute(const QString& elementId, const QString& attributeName, const QString& attributeValue); | 111 | void KGRAPHVIEWER_EXPORT setAttribute(const QString &elementId, | ||
112 | const QString &attributeName, | ||||
113 | const QString &attributeValue); | ||||
110 | 114 | | |||
111 | GraphElement* elementNamed(const QString& id); | 115 | GraphElement *elementNamed(const QString &id); | ||
112 | 116 | | |||
113 | inline void setUseLibrary(bool value) {m_useLibrary = value;} | 117 | inline void setUseLibrary(bool value) { m_useLibrary = value; } | ||
114 | inline bool useLibrary() {return m_useLibrary;} | 118 | inline bool useLibrary() { return m_useLibrary; } | ||
115 | 119 | | |||
116 | void KGRAPHVIEWER_EXPORT setGraphAttributes(QMap<QString,QString> attribs); | 120 | void KGRAPHVIEWER_EXPORT setGraphAttributes(QMap<QString, QString> attribs); | ||
117 | void KGRAPHVIEWER_EXPORT addNewNode(QMap<QString,QString> attribs); | 121 | void KGRAPHVIEWER_EXPORT addNewNode(QMap<QString, QString> attribs); | ||
118 | void KGRAPHVIEWER_EXPORT addNewSubgraph(QMap<QString,QString> attribs); | 122 | void KGRAPHVIEWER_EXPORT addNewSubgraph(QMap<QString, QString> attribs); | ||
119 | void KGRAPHVIEWER_EXPORT addNewNodeToSubgraph(QMap<QString,QString> attribs, QString subgraph); | 123 | void KGRAPHVIEWER_EXPORT | ||
120 | void KGRAPHVIEWER_EXPORT addExistingNodeToSubgraph(QMap<QString,QString> attribs,QString subgraph); | 124 | addNewNodeToSubgraph(QMap<QString, QString> attribs, QString subgraph); | ||
121 | void KGRAPHVIEWER_EXPORT moveExistingNodeToMainGraph(QMap<QString,QString> attribs); | 125 | void KGRAPHVIEWER_EXPORT | ||
122 | void KGRAPHVIEWER_EXPORT addNewEdge(QString src, QString tgt, QMap<QString,QString> attribs); | 126 | addExistingNodeToSubgraph(QMap<QString, QString> attribs, QString subgraph); | ||
127 | void KGRAPHVIEWER_EXPORT | ||||
128 | moveExistingNodeToMainGraph(QMap<QString, QString> attribs); | ||||
129 | void KGRAPHVIEWER_EXPORT addNewEdge(QString src, QString tgt, | ||||
130 | QMap<QString, QString> attribs); | ||||
123 | using GraphElement::removeAttribute; | 131 | using GraphElement::removeAttribute; | ||
124 | void KGRAPHVIEWER_EXPORT removeAttribute(const QString& nodeName, const QString& attribName); | 132 | void KGRAPHVIEWER_EXPORT removeAttribute(const QString &nodeName, | ||
125 | void KGRAPHVIEWER_EXPORT renameNode(const QString& oldNodeName, const QString& newNodeName); | 133 | const QString &attribName); | ||
134 | void KGRAPHVIEWER_EXPORT renameNode(const QString &oldNodeName, | ||||
135 | const QString &newNodeName); | ||||
126 | void KGRAPHVIEWER_EXPORT removeNodeNamed(const QString& nodeName); | 136 | void KGRAPHVIEWER_EXPORT removeNodeNamed(const QString &nodeName); | ||
127 | void KGRAPHVIEWER_EXPORT removeNodeFromSubgraph(const QString& nodeName, const QString& subgraphName); | 137 | void KGRAPHVIEWER_EXPORT removeNodeFromSubgraph( | ||
138 | const QString &nodeName, const QString &subgraphName); | ||||
128 | void KGRAPHVIEWER_EXPORT removeSubgraphNamed(const QString& subgraphName); | 139 | void KGRAPHVIEWER_EXPORT removeSubgraphNamed(const QString &subgraphName); | ||
129 | void KGRAPHVIEWER_EXPORT removeEdge(const QString& id); | 140 | void KGRAPHVIEWER_EXPORT removeEdge(const QString &id); | ||
130 | void KGRAPHVIEWER_EXPORT removeElement(const QString& id); | 141 | void KGRAPHVIEWER_EXPORT removeElement(const QString &id); | ||
131 | 142 | | |||
132 | Q_SIGNALS: | 143 | Q_SIGNALS: | ||
133 | void readyToDisplay(); | 144 | void readyToDisplay(); | ||
134 | 145 | | |||
135 | private Q_SLOTS: | 146 | private Q_SLOTS: | ||
136 | void slotDotRunningDone(int,QProcess::ExitStatus); | 147 | void slotDotRunningDone(int, QProcess::ExitStatus); | ||
137 | void slotDotRunningError(QProcess::ProcessError); | 148 | void slotDotRunningError(QProcess::ProcessError); | ||
138 | 149 | | |||
139 | private: | 150 | private: | ||
140 | unsigned int cellNumber(int x, int y); | 151 | unsigned int cellNumber(int x, int y); | ||
141 | void computeCells(); | 152 | void computeCells(); | ||
142 | QByteArray getDotResult(int exitCode, QProcess::ExitStatus exitStatus); | 153 | QByteArray getDotResult(int exitCode, QProcess::ExitStatus exitStatus); | ||
143 | 154 | | |||
144 | QString m_dotFileName; | 155 | QString m_dotFileName; | ||
145 | GraphSubgraphMap m_subgraphsMap; | 156 | GraphSubgraphMap m_subgraphsMap; | ||
146 | GraphNodeMap m_nodesMap; | 157 | GraphNodeMap m_nodesMap; | ||
147 | GraphEdgeMap m_edgesMap; | 158 | GraphEdgeMap m_edgesMap; | ||
148 | double m_width, m_height; | 159 | double m_width, m_height; | ||
149 | double m_scale; | 160 | double m_scale; | ||
150 | bool m_directed; | 161 | bool m_directed; | ||
151 | bool m_strict; | 162 | bool m_strict; | ||
152 | QString m_layoutCommand; | 163 | QString m_layoutCommand; | ||
153 | 164 | | |||
154 | unsigned int m_horizCellFactor, m_vertCellFactor; | 165 | unsigned int m_horizCellFactor, m_vertCellFactor; | ||
155 | QVector< QSet< GraphNode* > > m_cells; | 166 | QVector<QSet<GraphNode *>> m_cells; | ||
156 | 167 | | |||
157 | double m_wdhcf, m_hdvcf; | 168 | double m_wdhcf, m_hdvcf; | ||
158 | 169 | | |||
159 | bool m_readWrite; | 170 | bool m_readWrite; | ||
160 | QProcess* m_dot; | 171 | QProcess *m_dot; | ||
161 | 172 | | |||
162 | ParsePhase m_phase; | 173 | ParsePhase m_phase; | ||
163 | 174 | | |||
164 | QMutex m_dotProcessMutex; | 175 | QMutex m_dotProcessMutex; | ||
165 | 176 | | |||
166 | bool m_useLibrary; | 177 | bool m_useLibrary; | ||
167 | }; | 178 | }; | ||
168 | 179 | | |||
169 | } | 180 | } // namespace KGraphViewer | ||
170 | 181 | | |||
171 | #endif | 182 | #endif | ||
172 | | ||||
173 | | ||||
174 | |