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 | { | 42 | { | ||
43 | | ||||
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 | { | 47 | { | ||
49 | Q_OBJECT | 48 | Q_OBJECT | ||
50 | public: | 49 | public: | ||
51 | enum ParsePhase {Initial, Final}; | 50 | enum ParsePhase { Initial, Final }; | ||
52 | 51 | | |||
53 | DotGraph(); | 52 | DotGraph(); | ||
54 | DotGraph(const QString& command, const QString& fileName); | 53 | DotGraph(const QString &command, const QString &fileName); | ||
55 | 54 | | |||
56 | ~DotGraph() override; | 55 | ~DotGraph() override; | ||
57 | 56 | | |||
58 | QString chooseLayoutProgramForFile(const QString& str); | 57 | QString chooseLayoutProgramForFile(const QString &str); | ||
59 | bool parseDot(const QString& str); | 58 | bool parseDot(const QString &str); | ||
60 | 59 | | |||
61 | /** Constant accessor to the nodes of this graph */ | 60 | /** Constant accessor to the nodes of this graph */ | ||
62 | inline const GraphNodeMap& nodes() const {return m_nodesMap;} | 61 | inline const GraphNodeMap &nodes() const | ||
62 | { | ||||
63 | return m_nodesMap; | ||||
64 | } | ||||
63 | /** Constant accessor to the edges of this graph */ | 65 | /** Constant accessor to the edges of this graph */ | ||
64 | inline const GraphEdgeMap& edges() const {return m_edgesMap;} | 66 | inline const GraphEdgeMap &edges() const | ||
65 | inline const GraphSubgraphMap& subgraphs() const {return m_subgraphsMap;} | 67 | { | ||
68 | return m_edgesMap; | ||||
69 | } | ||||
70 | inline const GraphSubgraphMap &subgraphs() const | ||||
71 | { | ||||
72 | return m_subgraphsMap; | ||||
73 | } | ||||
66 | /** Accessor to the nodes of this graph */ | 74 | /** Accessor to the nodes of this graph */ | ||
67 | inline GraphNodeMap& nodes() {return m_nodesMap;} | 75 | inline GraphNodeMap &nodes() | ||
76 | { | ||||
77 | return m_nodesMap; | ||||
78 | } | ||||
68 | /** Accessor to the edges of this graph */ | 79 | /** Accessor to the edges of this graph */ | ||
69 | inline GraphEdgeMap& edges() {return m_edgesMap;} | 80 | inline GraphEdgeMap &edges() | ||
70 | inline GraphSubgraphMap& subgraphs() {return m_subgraphsMap;} | 81 | { | ||
71 | double width() const {return m_width;} | 82 | return m_edgesMap; | ||
72 | double height() const {return m_height;} | 83 | } | ||
73 | double scale() const {return m_scale;} | 84 | inline GraphSubgraphMap &subgraphs() | ||
74 | void width(double w) {m_width = w;} | 85 | { | ||
75 | void height(double h) {m_height = h;} | 86 | return m_subgraphsMap; | ||
76 | void scale(double s) {m_scale = s;} | 87 | } | ||
88 | double width() const | ||||
89 | { | ||||
90 | return m_width; | ||||
91 | } | ||||
92 | double height() const | ||||
93 | { | ||||
94 | return m_height; | ||||
95 | } | ||||
96 | double scale() const | ||||
97 | { | ||||
98 | return m_scale; | ||||
99 | } | ||||
100 | void width(double w) | ||||
101 | { | ||||
102 | m_width = w; | ||||
103 | } | ||||
104 | void height(double h) | ||||
105 | { | ||||
106 | m_height = h; | ||||
107 | } | ||||
108 | void scale(double s) | ||||
109 | { | ||||
110 | m_scale = s; | ||||
111 | } | ||||
77 | QString backColor() const override; | 112 | QString backColor() const override; | ||
78 | 113 | | |||
79 | inline void strict(bool s) {m_strict = s;} | 114 | inline void strict(bool s) | ||
80 | inline void directed(bool d) {m_directed = d;} | 115 | { | ||
81 | inline bool strict() const {return m_strict;} | 116 | m_strict = s; | ||
82 | inline bool directed() const {return m_directed;} | 117 | } | ||
118 | inline void directed(bool d) | ||||
119 | { | ||||
120 | m_directed = d; | ||||
121 | } | ||||
122 | inline bool strict() const | ||||
123 | { | ||||
124 | return m_strict; | ||||
125 | } | ||||
126 | inline bool directed() const | ||||
127 | { | ||||
128 | return m_directed; | ||||
129 | } | ||||
83 | 130 | | |||
84 | QSet< GraphNode* >& nodesOfCell(unsigned int id); | 131 | QSet<GraphNode *> &nodesOfCell(unsigned int id); | ||
85 | 132 | | |||
86 | inline unsigned int horizCellFactor() const {return m_horizCellFactor;} | 133 | inline unsigned int horizCellFactor() const | ||
87 | inline unsigned int vertCellFactor() const {return m_vertCellFactor;} | 134 | { | ||
88 | inline double wdhcf() const {return m_wdhcf;} | 135 | return m_horizCellFactor; | ||
89 | inline double hdvcf() const {return m_hdvcf;} | 136 | } | ||
137 | inline unsigned int vertCellFactor() const | ||||
138 | { | ||||
139 | return m_vertCellFactor; | ||||
140 | } | ||||
141 | inline double wdhcf() const | ||||
142 | { | ||||
143 | return m_wdhcf; | ||||
144 | } | ||||
145 | inline double hdvcf() const | ||||
146 | { | ||||
147 | return m_hdvcf; | ||||
148 | } | ||||
90 | 149 | | |||
91 | inline void layoutCommand(const QString& command) {m_layoutCommand = command;} | 150 | inline void layoutCommand(const QString &command) | ||
92 | inline const QString& layoutCommand() {return m_layoutCommand;} | 151 | { | ||
152 | m_layoutCommand = command; | ||||
153 | } | ||||
154 | inline const QString &layoutCommand() | ||||
155 | { | ||||
156 | return m_layoutCommand; | ||||
157 | } | ||||
93 | 158 | | |||
94 | inline void dotFileName(const QString& fileName) {m_dotFileName = fileName;} | 159 | inline void dotFileName(const QString &fileName) | ||
95 | inline const QString& dotFileName() const {return m_dotFileName;} | 160 | { | ||
161 | m_dotFileName = fileName; | ||||
162 | } | ||||
163 | inline const QString &dotFileName() const | ||||
164 | { | ||||
165 | return m_dotFileName; | ||||
166 | } | ||||
96 | 167 | | |||
97 | bool update(); | 168 | bool update(); | ||
98 | 169 | | |||
99 | inline void setReadWrite() {m_readWrite = true;} | 170 | inline void setReadWrite() | ||
100 | inline void setReadOnly() {m_readWrite = false;} | 171 | { | ||
172 | m_readWrite = true; | ||||
173 | } | ||||
174 | inline void setReadOnly() | ||||
175 | { | ||||
176 | m_readWrite = false; | ||||
177 | } | ||||
101 | 178 | | |||
102 | void storeOriginalAttributes() override; | 179 | void storeOriginalAttributes() override; | ||
103 | 180 | | |||
104 | void KGRAPHVIEWER_EXPORT saveTo(const QString& fileName); | 181 | void KGRAPHVIEWER_EXPORT saveTo(const QString &fileName); | ||
105 | 182 | | |||
106 | void updateWithGraph(graph_t* newGraph); | 183 | void updateWithGraph(graph_t *newGraph); | ||
107 | void updateWithGraph(const DotGraph& graph); | 184 | void updateWithGraph(const DotGraph &graph); | ||
108 | 185 | | |||
109 | void KGRAPHVIEWER_EXPORT setAttribute(const QString& elementId, const QString& attributeName, const QString& attributeValue); | 186 | void KGRAPHVIEWER_EXPORT setAttribute(const QString &elementId, const QString &attributeName, const QString &attributeValue); | ||
110 | 187 | | |||
111 | GraphElement* elementNamed(const QString& id); | 188 | GraphElement *elementNamed(const QString &id); | ||
112 | 189 | | |||
113 | inline void setUseLibrary(bool value) {m_useLibrary = value;} | 190 | inline void setUseLibrary(bool value) | ||
114 | inline bool useLibrary() {return m_useLibrary;} | 191 | { | ||
192 | m_useLibrary = value; | ||||
193 | } | ||||
194 | inline bool useLibrary() | ||||
195 | { | ||||
196 | return m_useLibrary; | ||||
197 | } | ||||
115 | 198 | | |||
116 | void KGRAPHVIEWER_EXPORT setGraphAttributes(QMap<QString,QString> attribs); | 199 | void KGRAPHVIEWER_EXPORT setGraphAttributes(QMap<QString, QString> attribs); | ||
117 | void KGRAPHVIEWER_EXPORT addNewNode(QMap<QString,QString> attribs); | 200 | void KGRAPHVIEWER_EXPORT addNewNode(QMap<QString, QString> attribs); | ||
118 | void KGRAPHVIEWER_EXPORT addNewSubgraph(QMap<QString,QString> attribs); | 201 | void KGRAPHVIEWER_EXPORT addNewSubgraph(QMap<QString, QString> attribs); | ||
119 | void KGRAPHVIEWER_EXPORT addNewNodeToSubgraph(QMap<QString,QString> attribs, QString subgraph); | 202 | void KGRAPHVIEWER_EXPORT addNewNodeToSubgraph(QMap<QString, QString> attribs, QString subgraph); | ||
120 | void KGRAPHVIEWER_EXPORT addExistingNodeToSubgraph(QMap<QString,QString> attribs,QString subgraph); | 203 | void KGRAPHVIEWER_EXPORT addExistingNodeToSubgraph(QMap<QString, QString> attribs, QString subgraph); | ||
121 | void KGRAPHVIEWER_EXPORT moveExistingNodeToMainGraph(QMap<QString,QString> attribs); | 204 | void KGRAPHVIEWER_EXPORT moveExistingNodeToMainGraph(QMap<QString, QString> attribs); | ||
122 | void KGRAPHVIEWER_EXPORT addNewEdge(QString src, QString tgt, QMap<QString,QString> attribs); | 205 | void KGRAPHVIEWER_EXPORT addNewEdge(QString src, QString tgt, QMap<QString, QString> attribs); | ||
123 | using GraphElement::removeAttribute; | 206 | using GraphElement::removeAttribute; | ||
124 | void KGRAPHVIEWER_EXPORT removeAttribute(const QString& nodeName, const QString& attribName); | 207 | void KGRAPHVIEWER_EXPORT removeAttribute(const QString &nodeName, const QString &attribName); | ||
125 | void KGRAPHVIEWER_EXPORT renameNode(const QString& oldNodeName, const QString& newNodeName); | 208 | void KGRAPHVIEWER_EXPORT renameNode(const QString &oldNodeName, const QString &newNodeName); | ||
126 | void KGRAPHVIEWER_EXPORT removeNodeNamed(const QString& nodeName); | 209 | void KGRAPHVIEWER_EXPORT removeNodeNamed(const QString &nodeName); | ||
127 | void KGRAPHVIEWER_EXPORT removeNodeFromSubgraph(const QString& nodeName, const QString& subgraphName); | 210 | void KGRAPHVIEWER_EXPORT removeNodeFromSubgraph(const QString &nodeName, const QString &subgraphName); | ||
128 | void KGRAPHVIEWER_EXPORT removeSubgraphNamed(const QString& subgraphName); | 211 | void KGRAPHVIEWER_EXPORT removeSubgraphNamed(const QString &subgraphName); | ||
129 | void KGRAPHVIEWER_EXPORT removeEdge(const QString& id); | 212 | void KGRAPHVIEWER_EXPORT removeEdge(const QString &id); | ||
130 | void KGRAPHVIEWER_EXPORT removeElement(const QString& id); | 213 | void KGRAPHVIEWER_EXPORT removeElement(const QString &id); | ||
131 | 214 | | |||
132 | Q_SIGNALS: | 215 | Q_SIGNALS: | ||
133 | void readyToDisplay(); | 216 | void readyToDisplay(); | ||
134 | 217 | | |||
135 | private Q_SLOTS: | 218 | private Q_SLOTS: | ||
136 | void slotDotRunningDone(int,QProcess::ExitStatus); | 219 | void slotDotRunningDone(int, QProcess::ExitStatus); | ||
137 | void slotDotRunningError(QProcess::ProcessError); | 220 | void slotDotRunningError(QProcess::ProcessError); | ||
138 | 221 | | |||
139 | private: | 222 | private: | ||
140 | unsigned int cellNumber(int x, int y); | 223 | unsigned int cellNumber(int x, int y); | ||
141 | void computeCells(); | 224 | void computeCells(); | ||
142 | QByteArray getDotResult(int exitCode, QProcess::ExitStatus exitStatus); | 225 | QByteArray getDotResult(int exitCode, QProcess::ExitStatus exitStatus); | ||
143 | 226 | | |||
144 | QString m_dotFileName; | 227 | QString m_dotFileName; | ||
145 | GraphSubgraphMap m_subgraphsMap; | 228 | GraphSubgraphMap m_subgraphsMap; | ||
146 | GraphNodeMap m_nodesMap; | 229 | GraphNodeMap m_nodesMap; | ||
147 | GraphEdgeMap m_edgesMap; | 230 | GraphEdgeMap m_edgesMap; | ||
148 | double m_width, m_height; | 231 | double m_width, m_height; | ||
149 | double m_scale; | 232 | double m_scale; | ||
150 | bool m_directed; | 233 | bool m_directed; | ||
151 | bool m_strict; | 234 | bool m_strict; | ||
152 | QString m_layoutCommand; | 235 | QString m_layoutCommand; | ||
153 | 236 | | |||
154 | unsigned int m_horizCellFactor, m_vertCellFactor; | 237 | unsigned int m_horizCellFactor, m_vertCellFactor; | ||
155 | QVector< QSet< GraphNode* > > m_cells; | 238 | QVector<QSet<GraphNode *>> m_cells; | ||
156 | 239 | | |||
157 | double m_wdhcf, m_hdvcf; | 240 | double m_wdhcf, m_hdvcf; | ||
158 | 241 | | |||
159 | bool m_readWrite; | 242 | bool m_readWrite; | ||
160 | QProcess* m_dot; | 243 | QProcess *m_dot; | ||
161 | 244 | | |||
162 | ParsePhase m_phase; | 245 | ParsePhase m_phase; | ||
163 | 246 | | |||
164 | QMutex m_dotProcessMutex; | 247 | QMutex m_dotProcessMutex; | ||
165 | 248 | | |||
166 | bool m_useLibrary; | 249 | bool m_useLibrary; | ||
167 | }; | 250 | }; | ||
168 | 251 | | |||
169 | } | 252 | } | ||
170 | 253 | | |||
171 | #endif | 254 | #endif | ||
172 | | ||||
173 | | ||||
174 | |