Changeset View
Changeset View
Standalone View
Standalone View
src/part/graphelement.h
Show All 15 Lines | 1 | /* This file is part of KGraphViewer. | |||
---|---|---|---|---|---|
16 | 02110-1301, USA | 16 | 02110-1301, USA | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #ifndef GRAPH_ELEMENT_H | 19 | #ifndef GRAPH_ELEMENT_H | ||
20 | #define GRAPH_ELEMENT_H | 20 | #define GRAPH_ELEMENT_H | ||
21 | 21 | | |||
22 | #include "dotrenderop.h" | 22 | #include "dotrenderop.h" | ||
23 | 23 | | |||
24 | #include <QVector> | | |||
25 | #include <QList> | 24 | #include <QList> | ||
26 | #include <QMap> | 25 | #include <QMap> | ||
27 | #include <QTextStream> | 26 | #include <QTextStream> | ||
27 | #include <QVector> | ||||
28 | 28 | | |||
29 | namespace KGraphViewer | 29 | namespace KGraphViewer | ||
30 | { | 30 | { | ||
31 | | ||||
32 | class CanvasElement; | 31 | class CanvasElement; | ||
33 | 32 | | |||
34 | /** | 33 | /** | ||
35 | * The base of all Graphviz DOT graph elements (nodes, edges, subgraphs, | 34 | * The base of all Graphviz DOT graph elements (nodes, edges, subgraphs, | ||
36 | * graphs). It is used to store the element attributes | 35 | * graphs). It is used to store the element attributes | ||
37 | */ | 36 | */ | ||
38 | class GraphElement: public QObject | 37 | class GraphElement : public QObject | ||
39 | { | 38 | { | ||
40 | Q_OBJECT | 39 | Q_OBJECT | ||
41 | public: | 40 | public: | ||
42 | GraphElement(); | 41 | GraphElement(); | ||
43 | GraphElement(const GraphElement& element); | 42 | GraphElement(const GraphElement &element); | ||
44 | 43 | | |||
45 | ~GraphElement() override {} | 44 | ~GraphElement() override | ||
45 | { | ||||
46 | } | ||||
47 | | ||||
48 | inline void setId(const QString &id) | ||||
49 | { | ||||
50 | m_attributes[KEY_ID] = id; | ||||
51 | } | ||||
52 | inline void setStyle(const QString &ls) | ||||
53 | { | ||||
54 | m_attributes[KEY_STYLE] = ls; | ||||
55 | } | ||||
56 | inline void setShape(const QString &lc) | ||||
57 | { | ||||
58 | m_attributes[KEY_SHAPE] = lc; | ||||
59 | } | ||||
60 | inline void setColor(const QString &nt) | ||||
61 | { | ||||
62 | m_attributes[KEY_COLOR] = nt; | ||||
63 | } | ||||
64 | inline void setLineColor(const QString &nt) | ||||
65 | { | ||||
66 | m_attributes[KEY_COLOR] = nt; | ||||
67 | } | ||||
68 | inline void setBackColor(const QString &nc) | ||||
69 | { | ||||
70 | m_attributes[KEY_BGCOLOR] = nc; | ||||
71 | } | ||||
46 | 72 | | |||
47 | inline void setId(const QString& id) {m_attributes[KEY_ID]=id;} | 73 | inline QString id() const | ||
48 | inline void setStyle(const QString& ls) {m_attributes[KEY_STYLE]=ls;} | 74 | { | ||
49 | inline void setShape(const QString& lc) {m_attributes[KEY_SHAPE]=lc;} | 75 | return m_attributes[KEY_ID]; | ||
50 | inline void setColor(const QString& nt) {m_attributes[KEY_COLOR]=nt;} | 76 | } | ||
51 | inline void setLineColor(const QString& nt) {m_attributes[KEY_COLOR]=nt;} | 77 | inline QString style() const | ||
52 | inline void setBackColor(const QString& nc) {m_attributes[KEY_BGCOLOR]=nc;} | 78 | { | ||
53 | 79 | return m_attributes[KEY_STYLE]; | |||
54 | inline QString id() const {return m_attributes[KEY_ID];} | 80 | } | ||
55 | inline QString style() const {return m_attributes[KEY_STYLE];} | 81 | inline QString shape() const | ||
56 | inline QString shape() const {return m_attributes[KEY_SHAPE];} | 82 | { | ||
57 | inline QString color() const {return m_attributes[KEY_COLOR];} | 83 | return m_attributes[KEY_SHAPE]; | ||
58 | inline QString lineColor() const {return m_attributes[KEY_COLOR];} | 84 | } | ||
85 | inline QString color() const | ||||
86 | { | ||||
87 | return m_attributes[KEY_COLOR]; | ||||
88 | } | ||||
89 | inline QString lineColor() const | ||||
90 | { | ||||
91 | return m_attributes[KEY_COLOR]; | ||||
92 | } | ||||
59 | virtual QString backColor() const; | 93 | virtual QString backColor() const; | ||
60 | 94 | | |||
61 | inline void setLabel(const QString& label) {m_attributes[KEY_LABEL]=label;} | 95 | inline void setLabel(const QString &label) | ||
62 | inline const QString label() const {return m_attributes[KEY_LABEL];} | 96 | { | ||
97 | m_attributes[KEY_LABEL] = label; | ||||
98 | } | ||||
99 | inline const QString label() const | ||||
100 | { | ||||
101 | return m_attributes[KEY_LABEL]; | ||||
102 | } | ||||
63 | 103 | | |||
64 | inline unsigned int fontSize() const {return m_attributes[KEY_FONTSIZE].toUInt();} | 104 | inline unsigned int fontSize() const | ||
65 | inline void setFontSize(unsigned int fs) {m_attributes[KEY_FONTSIZE]=QString::number(fs);} | 105 | { | ||
66 | inline QString fontName() const {return m_attributes[KEY_FONTNAME];} | 106 | return m_attributes[KEY_FONTSIZE].toUInt(); | ||
67 | inline void setFontName(const QString& fn) {m_attributes[KEY_FONTNAME]=fn;} | 107 | } | ||
68 | inline QString fontColor() const {return m_attributes[KEY_FONTCOLOR];} | 108 | inline void setFontSize(unsigned int fs) | ||
69 | inline void setFontColor(const QString& fc) {m_attributes[KEY_FONTCOLOR] = fc;} | 109 | { | ||
110 | m_attributes[KEY_FONTSIZE] = QString::number(fs); | ||||
111 | } | ||||
112 | inline QString fontName() const | ||||
113 | { | ||||
114 | return m_attributes[KEY_FONTNAME]; | ||||
115 | } | ||||
116 | inline void setFontName(const QString &fn) | ||||
117 | { | ||||
118 | m_attributes[KEY_FONTNAME] = fn; | ||||
119 | } | ||||
120 | inline QString fontColor() const | ||||
121 | { | ||||
122 | return m_attributes[KEY_FONTCOLOR]; | ||||
123 | } | ||||
124 | inline void setFontColor(const QString &fc) | ||||
125 | { | ||||
126 | m_attributes[KEY_FONTCOLOR] = fc; | ||||
127 | } | ||||
70 | 128 | | |||
71 | inline const DotRenderOpVec& renderOperations() const {return m_renderOperations;}; | 129 | inline const DotRenderOpVec &renderOperations() const | ||
130 | { | ||||
131 | return m_renderOperations; | ||||
132 | }; | ||||
72 | void setRenderOperations(const DotRenderOpVec& drov); | 133 | void setRenderOperations(const DotRenderOpVec &drov); | ||
73 | /** | 134 | /** | ||
74 | * indicates the version of the render operations, gets increased every time | 135 | * indicates the version of the render operations, gets increased every time | ||
75 | * @c setRenderOperations gets called. | 136 | * @c setRenderOperations gets called. | ||
76 | */ | 137 | */ | ||
77 | inline quint32 renderOperationsRevision() const {return m_renderOperationsRevision;}; | 138 | inline quint32 renderOperationsRevision() const | ||
139 | { | ||||
140 | return m_renderOperationsRevision; | ||||
141 | }; | ||||
78 | 142 | | |||
79 | inline double z() const {return m_z;} | 143 | inline double z() const | ||
80 | inline void setZ(double thez) {m_z = thez;} | 144 | { | ||
145 | return m_z; | ||||
146 | } | ||||
147 | inline void setZ(double thez) | ||||
148 | { | ||||
149 | m_z = thez; | ||||
150 | } | ||||
81 | 151 | | |||
82 | inline QString shapeFile() const {return m_attributes[KEY_SHAPEFILE];} | 152 | inline QString shapeFile() const | ||
83 | inline void setShapeFile(const QString& sf) {m_attributes[KEY_SHAPEFILE] = sf;} | 153 | { | ||
154 | return m_attributes[KEY_SHAPEFILE]; | ||||
155 | } | ||||
156 | inline void setShapeFile(const QString &sf) | ||||
157 | { | ||||
158 | m_attributes[KEY_SHAPEFILE] = sf; | ||||
159 | } | ||||
84 | 160 | | |||
85 | inline QString url() const {return m_attributes[KEY_URL];} | 161 | inline QString url() const | ||
86 | inline void setUrl(const QString& theUrl) {m_attributes[KEY_URL] = theUrl;} | 162 | { | ||
163 | return m_attributes[KEY_URL]; | ||||
164 | } | ||||
165 | inline void setUrl(const QString &theUrl) | ||||
166 | { | ||||
167 | m_attributes[KEY_URL] = theUrl; | ||||
168 | } | ||||
87 | 169 | | |||
88 | virtual void updateWithElement(const GraphElement& element); | 170 | virtual void updateWithElement(const GraphElement &element); | ||
89 | 171 | | |||
90 | inline QMap<QString,QString>& attributes() {return m_attributes;} | 172 | inline QMap<QString, QString> &attributes() | ||
91 | inline const QMap<QString,QString>& attributes() const {return m_attributes;} | 173 | { | ||
174 | return m_attributes; | ||||
175 | } | ||||
176 | inline const QMap<QString, QString> &attributes() const | ||||
177 | { | ||||
178 | return m_attributes; | ||||
179 | } | ||||
92 | 180 | | |||
93 | inline QList<QString>& originalAttributes() {return m_originalAttributes;} | 181 | inline QList<QString> &originalAttributes() | ||
94 | inline const QList<QString>& originalAttributes() const {return m_originalAttributes;} | 182 | { | ||
183 | return m_originalAttributes; | ||||
184 | } | ||||
185 | inline const QList<QString> &originalAttributes() const | ||||
186 | { | ||||
187 | return m_originalAttributes; | ||||
188 | } | ||||
95 | 189 | | |||
96 | virtual inline void storeOriginalAttributes() {m_originalAttributes = m_attributes.keys();} | 190 | virtual inline void storeOriginalAttributes() | ||
191 | { | ||||
192 | m_originalAttributes = m_attributes.keys(); | ||||
193 | } | ||||
97 | 194 | | |||
98 | virtual void removeAttribute(const QString& attribName); | 195 | virtual void removeAttribute(const QString &attribName); | ||
99 | 196 | | |||
100 | inline CanvasElement* canvasElement() {return m_ce;} | 197 | inline CanvasElement *canvasElement() | ||
101 | inline const CanvasElement* canvasElement() const {return m_ce;} | 198 | { | ||
102 | inline void setCanvasElement(CanvasElement* ce) {m_ce = ce;} | 199 | return m_ce; | ||
200 | } | ||||
201 | inline const CanvasElement *canvasElement() const | ||||
202 | { | ||||
203 | return m_ce; | ||||
204 | } | ||||
205 | inline void setCanvasElement(CanvasElement *ce) | ||||
206 | { | ||||
207 | m_ce = ce; | ||||
208 | } | ||||
103 | 209 | | |||
104 | inline void setSelected(bool s) {m_selected=s;} | 210 | inline void setSelected(bool s) | ||
105 | inline bool isSelected() {return m_selected;} | 211 | { | ||
212 | m_selected = s; | ||||
213 | } | ||||
214 | inline bool isSelected() | ||||
215 | { | ||||
216 | return m_selected; | ||||
217 | } | ||||
106 | 218 | | |||
107 | bool isVisible() const { return m_visible; } | 219 | bool isVisible() const | ||
108 | void setVisible(bool v) { m_visible = v; } | 220 | { | ||
221 | return m_visible; | ||||
222 | } | ||||
223 | void setVisible(bool v) | ||||
224 | { | ||||
225 | m_visible = v; | ||||
226 | } | ||||
109 | 227 | | |||
110 | void exportToGraphviz(void* element) const; | 228 | void exportToGraphviz(void *element) const; | ||
111 | 229 | | |||
112 | Q_SIGNALS: | 230 | Q_SIGNALS: | ||
113 | void changed(); | 231 | void changed(); | ||
114 | 232 | | |||
115 | protected: | 233 | protected: | ||
116 | QMap<QString,QString> m_attributes; | 234 | QMap<QString, QString> m_attributes; | ||
117 | QList<QString> m_originalAttributes; | 235 | QList<QString> m_originalAttributes; | ||
118 | 236 | | |||
119 | CanvasElement* m_ce; | 237 | CanvasElement *m_ce; | ||
120 | 238 | | |||
121 | static const QString KEY_ID; | 239 | static const QString KEY_ID; | ||
122 | static const QString KEY_STYLE; | 240 | static const QString KEY_STYLE; | ||
123 | static const QString KEY_LABEL; | 241 | static const QString KEY_LABEL; | ||
124 | static const QString KEY_SHAPE; | 242 | static const QString KEY_SHAPE; | ||
125 | static const QString KEY_SHAPEFILE; | 243 | static const QString KEY_SHAPEFILE; | ||
126 | static const QString KEY_COLOR; | 244 | static const QString KEY_COLOR; | ||
127 | static const QString KEY_BGCOLOR; | 245 | static const QString KEY_BGCOLOR; | ||
128 | static const QString KEY_URL; | 246 | static const QString KEY_URL; | ||
129 | static const QString KEY_FONTSIZE; | 247 | static const QString KEY_FONTSIZE; | ||
130 | static const QString KEY_FONTNAME; | 248 | static const QString KEY_FONTNAME; | ||
131 | static const QString KEY_FONTCOLOR; | 249 | static const QString KEY_FONTCOLOR; | ||
132 | static const QString KEY_FILLCOLOR; | 250 | static const QString KEY_FILLCOLOR; | ||
133 | 251 | | |||
134 | private: | 252 | private: | ||
135 | double m_z; | 253 | double m_z; | ||
136 | bool m_visible; | 254 | bool m_visible; | ||
137 | 255 | | |||
138 | DotRenderOpVec m_renderOperations; | 256 | DotRenderOpVec m_renderOperations; | ||
139 | quint32 m_renderOperationsRevision; | 257 | quint32 m_renderOperationsRevision; | ||
140 | 258 | | |||
141 | bool m_selected; | 259 | bool m_selected; | ||
142 | }; | 260 | }; | ||
143 | 261 | | |||
144 | | ||||
145 | QTextStream& operator<<(QTextStream& s, const GraphElement& n); | 262 | QTextStream &operator<<(QTextStream &s, const GraphElement &n); | ||
146 | 263 | | |||
147 | } | 264 | } | ||
148 | 265 | | |||
149 | #endif | 266 | #endif | ||
150 | | ||||
151 | | ||||
152 | |