Changeset View
Changeset View
Standalone View
Standalone View
src/part/dotgraphview.h
Show All 18 Lines | |||||
19 | /* This file was callgraphview.h, part of KCachegrind. | 19 | /* This file was callgraphview.h, part of KCachegrind. | ||
20 | Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | 20 | Copyright (C) 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | ||
21 | 21 | | |||
22 | KCachegrind is free software; you can redistribute it and/or | 22 | KCachegrind is free software; you can redistribute it and/or | ||
23 | modify it under the terms of the GNU General Public | 23 | modify it under the terms of the GNU General Public | ||
24 | License as published by the Free Software Foundation, version 2. | 24 | License as published by the Free Software Foundation, version 2. | ||
25 | */ | 25 | */ | ||
26 | 26 | | |||
27 | | ||||
28 | /* | 27 | /* | ||
29 | * Callgraph View | 28 | * Callgraph View | ||
30 | */ | 29 | */ | ||
31 | 30 | | |||
32 | #ifndef DOTGRAPHVIEW_H | 31 | #ifndef DOTGRAPHVIEW_H | ||
33 | #define DOTGRAPHVIEW_H | 32 | #define DOTGRAPHVIEW_H | ||
34 | 33 | | |||
35 | #include <kconfig.h> | | |||
36 | #include <kactioncollection.h> | 34 | #include <kactioncollection.h> | ||
35 | #include <kconfig.h> | ||||
37 | #include <kconfiggroup.h> | 36 | #include <kconfiggroup.h> | ||
38 | 37 | | |||
39 | #include <QGraphicsView> | 38 | #include <QGraphicsView> | ||
40 | #include <QSet> | 39 | #include <QSet> | ||
41 | 40 | | |||
42 | #include <graphviz/types.h> | 41 | #include <graphviz/types.h> | ||
43 | 42 | | |||
44 | #include "kgraphviewer_export.h" | 43 | #include "kgraphviewer_export.h" | ||
45 | #include "kgraphviewer_interface.h" | 44 | #include "kgraphviewer_interface.h" | ||
46 | 45 | | |||
47 | class KSelectAction; | 46 | class KSelectAction; | ||
48 | 47 | | |||
49 | class QKeyEvent; | 48 | class QKeyEvent; | ||
50 | class QMouseEvent; | 49 | class QMouseEvent; | ||
51 | class QFocusEvent; | 50 | class QFocusEvent; | ||
52 | class QResizeEvent; | 51 | class QResizeEvent; | ||
53 | class QWheelEvent; | 52 | class QWheelEvent; | ||
54 | class QContextMenuEvent; | 53 | class QContextMenuEvent; | ||
55 | class QWidget; | 54 | class QWidget; | ||
56 | 55 | | |||
57 | namespace KGraphViewer | 56 | namespace KGraphViewer | ||
58 | { | 57 | { | ||
59 | | ||||
60 | class GraphElement; | 58 | class GraphElement; | ||
61 | class CanvasElement; | 59 | class CanvasElement; | ||
62 | class CanvasEdge; | 60 | class CanvasEdge; | ||
63 | class DotGraph; | 61 | class DotGraph; | ||
64 | 62 | | |||
65 | #define DEFAULT_DETAILLEVEL 1 | 63 | #define DEFAULT_DETAILLEVEL 1 | ||
66 | 64 | | |||
67 | class DotGraphViewPrivate; | 65 | class DotGraphViewPrivate; | ||
68 | /** | 66 | /** | ||
69 | * A CanvasView showing a part of the call graph | 67 | * A CanvasView showing a part of the call graph | ||
70 | * and another zoomed out CanvasView in a border acting as | 68 | * and another zoomed out CanvasView in a border acting as | ||
71 | * a panner to select to visible part (only if needed) | 69 | * a panner to select to visible part (only if needed) | ||
72 | */ | 70 | */ | ||
73 | class KGRAPHVIEWER_EXPORT DotGraphView: public QGraphicsView | 71 | class KGRAPHVIEWER_EXPORT DotGraphView : public QGraphicsView | ||
74 | { | 72 | { | ||
75 | Q_OBJECT | 73 | Q_OBJECT | ||
76 | 74 | | |||
77 | public: | 75 | public: | ||
78 | enum EditingMode { None, AddNewElement, AddNewEdge, DrawNewEdge, SelectingElements }; | 76 | enum EditingMode { None, AddNewElement, AddNewEdge, DrawNewEdge, SelectingElements }; | ||
79 | enum ScrollDirection { Here, Left, Right, Top, Bottom }; | 77 | enum ScrollDirection { Here, Left, Right, Top, Bottom }; | ||
80 | 78 | | |||
81 | explicit KGRAPHVIEWER_EXPORT DotGraphView(KActionCollection* actions, QWidget* parent = nullptr); | 79 | explicit KGRAPHVIEWER_EXPORT DotGraphView(KActionCollection *actions, QWidget *parent = nullptr); | ||
82 | ~DotGraphView() override; | 80 | ~DotGraphView() override; | ||
83 | 81 | | |||
84 | bool KGRAPHVIEWER_EXPORT loadDot(const QString& dotFileName); | 82 | bool KGRAPHVIEWER_EXPORT loadDot(const QString &dotFileName); | ||
85 | bool KGRAPHVIEWER_EXPORT loadLibrary(const QString& dotFileName); | 83 | bool KGRAPHVIEWER_EXPORT loadLibrary(const QString &dotFileName); | ||
86 | bool KGRAPHVIEWER_EXPORT loadLibrarySync(const QString& dotFileName); | 84 | bool KGRAPHVIEWER_EXPORT loadLibrarySync(const QString &dotFileName); | ||
87 | bool loadLibrary(graph_t* graph, const QString& layoutCommand = "dot"); | 85 | bool loadLibrary(graph_t *graph, const QString &layoutCommand = "dot"); | ||
88 | 86 | | |||
89 | void readViewConfig(); | 87 | void readViewConfig(); | ||
90 | void saveViewConfig(); | 88 | void saveViewConfig(); | ||
91 | 89 | | |||
92 | //TODO: rename zoomPos -> bev / panner, but _please_ make it consistent... | 90 | // TODO: rename zoomPos -> bev / panner, but _please_ make it consistent... | ||
93 | KGraphViewerInterface::PannerPosition zoomPos() const; | 91 | KGraphViewerInterface::PannerPosition zoomPos() const; | ||
94 | static KGraphViewerInterface::PannerPosition zoomPos(const QString&); | 92 | static KGraphViewerInterface::PannerPosition zoomPos(const QString &); | ||
95 | static QString zoomPosString(KGraphViewerInterface::PannerPosition); | 93 | static QString zoomPosString(KGraphViewerInterface::PannerPosition); | ||
96 | void setPannerEnabled(bool enabled); | 94 | void setPannerEnabled(bool enabled); | ||
97 | 95 | | |||
98 | static KConfigGroup* configGroup(KConfig*, const QString& prefix, const QString& postfix); | 96 | static KConfigGroup *configGroup(KConfig *, const QString &prefix, const QString &postfix); | ||
99 | static void writeConfigEntry(KConfigGroup*, const char* pKey, const QString& value, | 97 | static void writeConfigEntry(KConfigGroup *, const char *pKey, const QString &value, const char *def); | ||
100 | const char* def); | 98 | static void writeConfigEntry(KConfigGroup *, const char *pKey, int value, int def); | ||
101 | static void writeConfigEntry(KConfigGroup*, const char* pKey, | 99 | static void writeConfigEntry(KConfigGroup *, const char *pKey, bool value, bool def); | ||
102 | int value, int def); | 100 | static void writeConfigEntry(KConfigGroup *, const char *pKey, double value, double def); | ||
103 | static void writeConfigEntry(KConfigGroup*, const char* pKey, | | |||
104 | bool value, bool def); | | |||
105 | static void writeConfigEntry(KConfigGroup*, const char* pKey, | | |||
106 | double value, double def); | | |||
107 | 101 | | |||
108 | /// multiplies current zoom factor with @p factor | 102 | /// multiplies current zoom factor with @p factor | ||
109 | void applyZoom(double factor); | 103 | void applyZoom(double factor); | ||
110 | /// sets zoom factor to @p factor | 104 | /// sets zoom factor to @p factor | ||
111 | void setZoomFactor(double factor); | 105 | void setZoomFactor(double factor); | ||
112 | 106 | | |||
113 | void setLayoutCommand(const QString& command); | 107 | void setLayoutCommand(const QString &command); | ||
114 | 108 | | |||
115 | const QString& dotFileName(); | 109 | const QString &dotFileName(); | ||
116 | 110 | | |||
117 | void hideToolsWindows(); | 111 | void hideToolsWindows(); | ||
118 | double zoom() const; | 112 | double zoom() const; | ||
119 | KSelectAction* bevPopup(); | 113 | KSelectAction *bevPopup(); | ||
120 | 114 | | |||
121 | DotGraph* graph(); | 115 | DotGraph *graph(); | ||
122 | const DotGraph* graph() const; | 116 | const DotGraph *graph() const; | ||
123 | 117 | | |||
124 | const GraphElement* defaultNewElement() const; | 118 | const GraphElement *defaultNewElement() const; | ||
125 | QPixmap defaultNewElementPixmap() const; | 119 | QPixmap defaultNewElementPixmap() const; | ||
126 | 120 | | |||
127 | void setDefaultNewElement(GraphElement* elem); | 121 | void setDefaultNewElement(GraphElement *elem); | ||
128 | void setDefaultNewElementPixmap(const QPixmap& pm); | 122 | void setDefaultNewElementPixmap(const QPixmap &pm); | ||
129 | 123 | | |||
130 | void prepareAddNewElement(QMap<QString,QString> attribs); | 124 | void prepareAddNewElement(QMap<QString, QString> attribs); | ||
131 | void prepareAddNewEdge(QMap<QString,QString> attribs); | 125 | void prepareAddNewEdge(QMap<QString, QString> attribs); | ||
132 | void prepareSelectElements(); | 126 | void prepareSelectElements(); | ||
133 | 127 | | |||
134 | void createNewEdgeDraftFrom(CanvasElement* node); | 128 | void createNewEdgeDraftFrom(CanvasElement *node); | ||
135 | void finishNewEdgeTo(CanvasElement* node); | 129 | void finishNewEdgeTo(CanvasElement *node); | ||
136 | 130 | | |||
137 | EditingMode editingMode() const; | 131 | EditingMode editingMode() const; | ||
138 | 132 | | |||
139 | void KGRAPHVIEWER_EXPORT setReadOnly(); | 133 | void KGRAPHVIEWER_EXPORT setReadOnly(); | ||
140 | void KGRAPHVIEWER_EXPORT setReadWrite(); | 134 | void KGRAPHVIEWER_EXPORT setReadWrite(); | ||
141 | bool isReadWrite() const; | 135 | bool isReadWrite() const; | ||
142 | bool isReadOnly() const; | 136 | bool isReadOnly() const; | ||
143 | 137 | | |||
144 | void removeSelectedNodes(); | 138 | void removeSelectedNodes(); | ||
145 | void removeSelectedEdges(); | 139 | void removeSelectedEdges(); | ||
146 | void removeSelectedSubgraphs(); | 140 | void removeSelectedSubgraphs(); | ||
147 | void removeSelectedElements(); | 141 | void removeSelectedElements(); | ||
148 | 142 | | |||
149 | bool highlighting(); | 143 | bool highlighting(); | ||
150 | void setHighlighting(bool highlightingValue); | 144 | void setHighlighting(bool highlightingValue); | ||
151 | 145 | | |||
152 | // public so that the panner view can bubble through | 146 | // public so that the panner view can bubble through | ||
153 | void contextMenuEvent(QContextMenuEvent*) override; | 147 | void contextMenuEvent(QContextMenuEvent *) override; | ||
154 | 148 | | |||
155 | void setBackgroundColor(const QColor& color); | 149 | void setBackgroundColor(const QColor &color); | ||
156 | 150 | | |||
157 | Q_SIGNALS: | 151 | Q_SIGNALS: | ||
158 | void zoomed(double factor); | 152 | void zoomed(double factor); | ||
159 | void sigViewBevEnabledToggled(bool value); | 153 | void sigViewBevEnabledToggled(bool value); | ||
160 | void sigViewBevActivated(int newPos); | 154 | void sigViewBevActivated(int newPos); | ||
161 | void graphLoaded(); | 155 | void graphLoaded(); | ||
162 | void newNodeAdded(const QString&); | 156 | void newNodeAdded(const QString &); | ||
163 | void newEdgeAdded(const QString&, const QString&); | 157 | void newEdgeAdded(const QString &, const QString &); | ||
164 | /** signals that the user has activated a remove edge command */ | 158 | /** signals that the user has activated a remove edge command */ | ||
165 | void removeEdge(const QString&); | 159 | void removeEdge(const QString &); | ||
166 | /** signals that the user has activated a remove edge command */ | 160 | /** signals that the user has activated a remove edge command */ | ||
167 | void removeNodeNamed(const QString&); | 161 | void removeNodeNamed(const QString &); | ||
168 | /** signals that the user has activated a remove element command */ | 162 | /** signals that the user has activated a remove element command */ | ||
169 | void removeElement(const QString&); | 163 | void removeElement(const QString &); | ||
170 | /** signals the content of the new selection */ | 164 | /** signals the content of the new selection */ | ||
171 | void selectionIs(const QList<QString>, const QPoint&); | 165 | void selectionIs(const QList<QString>, const QPoint &); | ||
172 | /** let the application tweak the created edge if necessary */ | 166 | /** let the application tweak the created edge if necessary */ | ||
173 | void newEdgeFinished( | 167 | void newEdgeFinished(const QString &, const QString &, const QMap<QString, QString> &); | ||
174 | const QString&, const QString&, | | |||
175 | const QMap<QString, QString>&); | | |||
176 | void contextMenuEvent(const QString&, const QPoint&); | 168 | void contextMenuEvent(const QString &, const QPoint &); | ||
177 | void hoverEnter(const QString&); | 169 | void hoverEnter(const QString &); | ||
178 | void hoverLeave(const QString&); | 170 | void hoverLeave(const QString &); | ||
179 | 171 | | |||
180 | public Q_SLOTS: | 172 | public Q_SLOTS: | ||
181 | void zoomIn(); | 173 | void zoomIn(); | ||
182 | void zoomOut(); | 174 | void zoomOut(); | ||
183 | void zoomRectMovedTo(QPointF newZoomPos); | 175 | void zoomRectMovedTo(QPointF newZoomPos); | ||
184 | void zoomRectMoveFinished(); | 176 | void zoomRectMoveFinished(); | ||
185 | bool initEmpty(); | 177 | bool initEmpty(); | ||
186 | bool slotLoadLibrary(graph_t* graph); | 178 | bool slotLoadLibrary(graph_t *graph); | ||
187 | bool reload(); | 179 | bool reload(); | ||
188 | void dirty(const QString& dotFileName); | 180 | void dirty(const QString &dotFileName); | ||
189 | void pageSetup(); | 181 | void pageSetup(); | ||
190 | void print(); | 182 | void print(); | ||
191 | void printPreview(); | 183 | void printPreview(); | ||
192 | void viewBevActivated(int newPos); | 184 | void viewBevActivated(int newPos); | ||
193 | void slotExportImage(); | 185 | void slotExportImage(); | ||
194 | void slotSelectLayoutAlgo(const QString& text); | 186 | void slotSelectLayoutAlgo(const QString &text); | ||
195 | void slotLayoutSpecify(); | 187 | void slotLayoutSpecify(); | ||
196 | void slotLayoutReset(); | 188 | void slotLayoutReset(); | ||
197 | void slotSelectLayoutDot(); | 189 | void slotSelectLayoutDot(); | ||
198 | void slotSelectLayoutNeato(); | 190 | void slotSelectLayoutNeato(); | ||
199 | void slotSelectLayoutTwopi(); | 191 | void slotSelectLayoutTwopi(); | ||
200 | void slotSelectLayoutFdp(); | 192 | void slotSelectLayoutFdp(); | ||
201 | void slotSelectLayoutCirco(); | 193 | void slotSelectLayoutCirco(); | ||
202 | void slotBevToggled(); | 194 | void slotBevToggled(); | ||
203 | void slotBevTopLeft(); | 195 | void slotBevTopLeft(); | ||
204 | void slotBevTopRight(); | 196 | void slotBevTopRight(); | ||
205 | void slotBevBottomLeft(); | 197 | void slotBevBottomLeft(); | ||
206 | void slotBevBottomRight(); | 198 | void slotBevBottomRight(); | ||
207 | void slotBevAutomatic(); | 199 | void slotBevAutomatic(); | ||
208 | void slotUpdate(); | 200 | void slotUpdate(); | ||
209 | bool displayGraph(); | 201 | bool displayGraph(); | ||
210 | void slotEdgeSelected(CanvasEdge*, Qt::KeyboardModifiers); | 202 | void slotEdgeSelected(CanvasEdge *, Qt::KeyboardModifiers); | ||
211 | void slotElementSelected(CanvasElement*, Qt::KeyboardModifiers); | 203 | void slotElementSelected(CanvasElement *, Qt::KeyboardModifiers); | ||
212 | void slotSelectionChanged(); | 204 | void slotSelectionChanged(); | ||
213 | void slotContextMenuEvent(const QString&, const QPoint&); | 205 | void slotContextMenuEvent(const QString &, const QPoint &); | ||
214 | void slotElementHoverEnter(CanvasElement*); | 206 | void slotElementHoverEnter(CanvasElement *); | ||
215 | void slotElementHoverLeave(CanvasElement*); | 207 | void slotElementHoverLeave(CanvasElement *); | ||
216 | void slotElementHoverEnter(CanvasEdge*); | 208 | void slotElementHoverEnter(CanvasEdge *); | ||
217 | void slotElementHoverLeave(CanvasEdge*); | 209 | void slotElementHoverLeave(CanvasEdge *); | ||
218 | void slotSelectNode(const QString& nodeName); | 210 | void slotSelectNode(const QString &nodeName); | ||
219 | void centerOnNode(const QString& nodeId); | 211 | void centerOnNode(const QString &nodeId); | ||
220 | 212 | | |||
221 | protected: | 213 | protected: | ||
222 | void scrollViewPercent(bool horizontal, int percent); | 214 | void scrollViewPercent(bool horizontal, int percent); | ||
223 | 215 | | |||
224 | void scrollContentsBy(int dx, int dy) override; | 216 | void scrollContentsBy(int dx, int dy) override; | ||
225 | void resizeEvent(QResizeEvent*) override; | 217 | void resizeEvent(QResizeEvent *) override; | ||
226 | void mousePressEvent(QMouseEvent*) override; | 218 | void mousePressEvent(QMouseEvent *) override; | ||
227 | void mouseMoveEvent(QMouseEvent*) override; | 219 | void mouseMoveEvent(QMouseEvent *) override; | ||
228 | void mouseReleaseEvent(QMouseEvent*) override; | 220 | void mouseReleaseEvent(QMouseEvent *) override; | ||
229 | void mouseDoubleClickEvent(QMouseEvent*) override; | 221 | void mouseDoubleClickEvent(QMouseEvent *) override; | ||
230 | void keyPressEvent(QKeyEvent*) override; | 222 | void keyPressEvent(QKeyEvent *) override; | ||
231 | void wheelEvent(QWheelEvent* e) override; | 223 | void wheelEvent(QWheelEvent *e) override; | ||
232 | void focusInEvent(QFocusEvent*) override; | 224 | void focusInEvent(QFocusEvent *) override; | ||
233 | void focusOutEvent(QFocusEvent*) override; | 225 | void focusOutEvent(QFocusEvent *) override; | ||
234 | 226 | | |||
235 | void timerEvent(QTimerEvent* event) override; | 227 | void timerEvent(QTimerEvent *event) override; | ||
236 | void leaveEvent(QEvent* event) override; | 228 | void leaveEvent(QEvent *event) override; | ||
237 | void enterEvent(QEvent* event) override; | 229 | void enterEvent(QEvent *event) override; | ||
238 | 230 | | |||
239 | private Q_SLOTS: | 231 | private Q_SLOTS: | ||
240 | void slotAGraphReadFinished(); | 232 | void slotAGraphReadFinished(); | ||
241 | void slotAGraphLayoutFinished(); | 233 | void slotAGraphLayoutFinished(); | ||
242 | 234 | | |||
243 | protected: | 235 | protected: | ||
244 | DotGraphViewPrivate * const d_ptr; | 236 | DotGraphViewPrivate *const d_ptr; | ||
245 | 237 | | |||
246 | private: | 238 | private: | ||
247 | Q_DECLARE_PRIVATE(DotGraphView); | 239 | Q_DECLARE_PRIVATE(DotGraphView); | ||
248 | | ||||
249 | }; | 240 | }; | ||
250 | 241 | | |||
251 | } | 242 | } | ||
252 | 243 | | |||
253 | #endif // DOTGRAPHVIEW_H | 244 | #endif // DOTGRAPHVIEW_H |