Code Documentation 3.1
Social Network Visualizer
Loading...
Searching...
No Matches
graphicswidget.h
Go to the documentation of this file.
1
17#ifndef GRAPHICSWIDGET_H
18#define GRAPHICSWIDGET_H
19
20
21#include <QGraphicsView>
22#include <QHash>
23
24class MainWindow;
25class GraphicsNode;
26class GraphicsEdge;
29class GraphicsGuide;
32
33typedef QHash<QString, GraphicsEdge*> H_StrToEdge;
34typedef QHash <int, GraphicsNode*> H_NumToNode;
35
36
37typedef QPair<int, int> SelectedEdge;
38
39Q_DECLARE_METATYPE(SelectedEdge)
40
41
42class GraphicsWidget : public QGraphicsView {
43 Q_OBJECT
44
45public:
46
47 GraphicsWidget(QGraphicsScene *m_scene, MainWindow *m_parent);
49
50 void clear();
51
52 QString createEdgeName(const int &v1,
53 const int &v2,
54 const int &relation=-1);
55
56 void setInitNodeSize(int);
57
58 void setInitZoomIndex (const int &);
59 void setMaxZoomIndex (const int &);
60
61 GraphicsNode* hasNode(QString text);
62 void setSelectedNodes(QList<int> list);
63
64 QList<QGraphicsItem *> selectedItems();
65 QList<int> selectedNodes();
66 QList<SelectedEdge> selectedEdges();
67
68 void selectAll();
69 void selectNone();
70
71 void removeItem(GraphicsEdge*);
72 void removeItem(GraphicsEdgeWeight *edgeWeight);
73 void removeItem(GraphicsEdgeLabel *edgeLabel);
74 void removeItem(GraphicsNode*);
75 void removeItem(GraphicsNodeNumber*);
76 void removeItem(GraphicsNodeLabel*);
77
78 void setNumbersInsideNodes(const bool &toggle);
79
80 void setAllItemsVisibility(int, bool);
81
82 void removeAllItems(int);
83
84protected:
85
86 void wheelEvent(QWheelEvent *event);
87 void mouseDoubleClickEvent ( QMouseEvent * e );
88 void mousePressEvent ( QMouseEvent * e );
89 void mouseReleaseEvent(QMouseEvent * e );
90 void resizeEvent( QResizeEvent *e );
91
92public slots:
93
94 void handleSelectionChanged();
95
96 void relationSet(int relation);
97
98 void drawNode(const QPointF &p,
99 const int &num,
100 const int &nodeSize,
101 const QString &nodeShape,
102 const QString &nodeIconPath,
103 const QString &nodeColor,
104 const QString &numberColor,
105 const int &numberSize,
106 const int &numberDistance,
107 const QString &nodeLabel,
108 const QString &labelColor,
109 const int &labelSize,
110 const int &labelDistance);
111 void removeNode(const int &nodeNum);
112 void setNodeVisibility(const int &nodeNum, const bool &toggle ); //Called from Graph via MW
113 void setNodeClicked(GraphicsNode *);
114 void moveNode(const int &num, const qreal &x, const qreal &y);
115
116 bool setNodeSize(const int &nodeNumber, const int &size=0);
117 void setNodeSizeAll(const int &size=0);
118
119 bool setNodeShape(const int &nodeNum,
120 const QString &shape,
121 const QString &iconPath=QString());
122 bool setNodeColor(const int &nodeNum, const QString &color);
123
124 void setNodeNumberColor(const int &nodeNum, const QString &color);
125 void setNodeNumberVisibility(const bool &toggle);
126 bool setNodeNumberSize(const int &nodeNum, const int &size=0);
127 bool setNodeNumberDistance(const int &, const int &distance=0);
128
129 void setNodeLabelsVisibility(const bool &toggle);
130 bool setNodeLabelColor(const int &nodeNum, const QString &color="green");
131 bool setNodeLabelSize(const int &, const int &size=0);
132 bool setNodeLabel(const int & , const QString &label);
133 bool setNodeLabelDistance(const int &, const int &distance=0);
134
135 void drawEdge(const int &source,
136 const int &target,
137 const qreal &weight,
138 const QString &label="",
139 const QString &color="black",
140 const int &type=0,
141 const bool &drawArrows=true,
142 const bool &bezier=false,
143 const bool &weightNumbers=false);
144
145 void removeEdge(const int &source,
146 const int &target,
147 const bool &removeOpposite=false);
148
149 void setEdgeVisibility (const int &relation,
150 const int &sourceNum,
151 const int &targetNum,
152 const bool &visible,
153 const bool &preserveReverseEdge=false,
154 const int &edgeWeight=1,
155 const int &reverseEdgeWeight=1);
156
157 bool setEdgeDirectionType(const int &source,
158 const int &target,
159 const int &dirType=false);
160
161 bool setEdgeWeight(const int &, const int &, const qreal &);
162
163 void setEdgeLabel(const int &source, const int &target, const QString &label);
164
165 void setEdgeColor(const int &, const int&, const QString &);
166
167 void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false);
168
169 void setEdgeOffsetFromNode(const int &source,
170 const int &target,
171 const int &offset);
172 void setEdgeArrowsVisibility(const bool &toggle);
173 void setEdgeWeightNumbersVisibility (const bool &toggle);
174 void setEdgeLabelsVisibility(const bool &toggle);
175
176 void setEdgeHighlighting(const bool &toggle);
177
178 void handleDoubleClickOnNode(GraphicsNode *node);
179
180 void clearGuides();
181 void addGuideCircle( const double&x0, const double&y0, const double&radius);
182 void addGuideHLine(const double &y0);
183
184 void zoomIn(const int step = 1);
185 void zoomOut(const int step = 1);
186 void rotateLeft();
187 void rotateRight();
188 void changeMatrixScale(const int value);
189 void changeMatrixRotation(int angle);
190 void reset();
191
192 void setOptionsOpenGL(const bool &enabled=false);
193 void setOptionsAntialiasing(const bool &toggle);
194 void setOptionsNoAntialiasingAutoAdjust(const bool &toggle);
195
196signals:
197 void userDoubleClickNewNode(const QPointF &);
198 void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1);
199 void userClickOnEmptySpace(const QPointF &p);
201 void openContextMenu(const QPointF p);
202 void userNodeMoved(const int &, const int &, const int &);
203 //void userSelectedItems(const int nodes, const int edges);
204 void userSelectedItems(const QList<int> selectedNodes,
205 const QList<SelectedEdge> selectedEdges);
206 void userClickedNode(const int &nodeNumber, const QPointF &p);
207 void userClickedEdge(const int &source, const int &target, const bool &openMenu=false);
208 void zoomChanged(const int);
209 void rotationChanged(const int);
210 void resized(const int, const int);
211 void setCursor(Qt::CursorShape);
212
213
214private:
215
216 H_NumToNode nodeHash; //Our basic hash table for node items
217 H_StrToEdge edgesHash; // Our basic hash table for edge items
218 QList<int> m_selectedNodes;
219 QList<SelectedEdge> m_selectedEdges;
220 int m_curRelation, m_nodeSize;
222 int m_zoomIndex, m_zoomIndexInit, m_zoomIndexMax;
223 int markedEdgeSourceOrigSize, markedEdgeTargetOrigSize;
226 qreal fX,fY, factor;
227 QString m_nodeLabel, m_numberColor, m_labelColor;
228 QString edgeName;
230 bool hasDoubleClickedNode, clickedEdgeExists;
231 bool m_nodeNumbersInside, m_nodeNumberVisibility, m_nodeLabelVisibility;
233 GraphicsNode *firstDoubleClickedNode, *secondDoubleClickedNode;
237};
238
239#endif
Definition graphicsedgelabel.h:28
int type() const
Definition graphicsedgelabel.h:34
Definition graphicsedgeweight.h:28
Definition graphicsedge.h:49
Definition graphicsguide.h:30
Definition graphicsnodelabel.h:26
Definition graphicsnodenumber.h:27
Definition graphicsnode.h:47
Definition graphicswidget.h:42
int m_edgeMinOffsetFromNode
Definition graphicswidget.h:224
int m_zoomIndex
Definition graphicswidget.h:222
QString m_labelColor
Definition graphicswidget.h:227
void userDoubleClickNewNode(const QPointF &)
void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1)
QList< SelectedEdge > m_selectedEdges
Definition graphicswidget.h:219
void userNodeMoved(const int &, const int &, const int &)
void resized(const int, const int)
void userClickedEdge(const int &source, const int &target, const bool &openMenu=false)
int markedEdgeSourceOrigSize
Definition graphicswidget.h:223
void userClickedNode(const int &nodeNumber, const QPointF &p)
void userClickOnEmptySpace(const QPointF &p)
H_NumToNode nodeHash
Definition graphicswidget.h:216
bool m_isTransformationActive
Definition graphicswidget.h:229
void userSelectedItems(const QList< int > selectedNodes, const QList< SelectedEdge > selectedEdges)
QList< int > m_selectedNodes
Definition graphicswidget.h:218
bool clickedEdgeExists
Definition graphicswidget.h:230
double m_currentScaleFactor
Definition graphicswidget.h:225
GraphicsNode * markedEdgeSource
Definition graphicswidget.h:234
void zoomChanged(const int)
void openContextMenu(const QPointF p)
bool m_nodeLabelVisibility
Definition graphicswidget.h:231
void setCursor(Qt::CursorShape)
QString edgeName
Definition graphicswidget.h:228
int m_curRelation
Definition graphicswidget.h:220
void openNodeMenu()
void rotationChanged(const int)
GraphicsEdge * clickedEdge
Definition graphicswidget.h:236
GraphicsNode * firstDoubleClickedNode
Definition graphicswidget.h:233
bool m_edgeHighlighting
Definition graphicswidget.h:232
GraphicsNode * markedEdgeTarget
Definition graphicswidget.h:235
qreal factor
Definition graphicswidget.h:226
int m_currentRotationAngle
Definition graphicswidget.h:221
H_StrToEdge edgesHash
Definition graphicswidget.h:217
The base window of SocNetV contains all widgets and functionality.
Definition mainwindow.h:102
QPair< int, int > SelectedEdge
Definition global.h:147
QHash< int, GraphicsNode * > H_NumToNode
Definition graphicswidget.h:34
QPair< int, int > SelectedEdge
Definition graphicswidget.h:37
QHash< QString, GraphicsEdge * > H_StrToEdge
Definition graphicswidget.h:33