QGVScene.h
Go to the documentation of this file.
1 /***************************************************************
2 QGVCore
3 Copyright (c) 2014, Bergont Nicolas, All rights reserved.
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3.0 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library.
17 ***************************************************************/
18 #ifndef QGVSCENE_H
19 #define QGVSCENE_H
20 
21 #include "qgv.h"
22 #include <QGraphicsScene>
23 
24 class QGVNode;
25 class QGVEdge;
26 class QGVSubGraph;
27 
28 class QGVGraphPrivate;
29 class QGVGvcPrivate;
30 
35 class QGVCORE_EXPORT QGVScene : public QGraphicsScene
36 {
37  Q_OBJECT
38 public:
39 
40  explicit QGVScene(const QString &name, QObject *parent = 0);
41  ~QGVScene();
42 
43  void setGraphAttribute(const QString &name, const QString &value);
44  void setNodeAttribute(const QString &name, const QString &value);
45  void setEdgeAttribute(const QString &name, const QString &value);
46 
47  QGVNode* addNode(const QString& label);
48  QGVEdge* addEdge(QGVNode* source, QGVNode* target, const QString& label=QString());
49  QGVSubGraph* addSubGraph(const QString& name, bool cluster=true);
50 
51  void setRootNode(QGVNode *node);
52 
53  void setNodePositionAttribute();
54 
55  void loadLayout(const QString &text);
56  void applyLayout(const QString &algorithm = "dot");
57  void render (const QString &algorithm);
58  void render (const QString algorithm, const QString file);
59  void freeLayout();
60  void clear();
61 
62  bool writeGraph (const QString filename);
63 
64 signals:
65  void nodeContextMenu(QGVNode* node);
66  void nodeDoubleClick(QGVNode* node);
67  void nodeChanged (QGVNode* node);
68  void nodeMouseRelease (QGVNode* node);
69 
70  void edgeContextMenu(QGVEdge* edge);
71  void edgeDoubleClick(QGVEdge* edge);
72 
73  void subGraphContextMenu(QGVSubGraph* graph);
74  void subGraphDoubleClick(QGVSubGraph* graph);
75 
76  void graphContextMenuEvent();
77 
78 public slots:
79 
80 protected:
81  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent * contextMenuEvent);
82  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * mouseEvent);
83  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent);
84  virtual void drawBackground(QPainter * painter, const QRectF & rect);
85 
86 private:
87  friend class QGVNode;
88  friend class QGVEdge;
89  friend class QGVSubGraph;
90 
91  QGVGvcPrivate *_context;
92  QGVGraphPrivate *_graph;
93  //QFont _font;
94 
95  QList<QGVNode*> _nodes;
96  QList<QGVEdge*> _edges;
97  QList<QGVSubGraph*> _subGraphs;
98  QGraphicsTextItem* _label;
99 };
100 
101 #endif // QGVSCENE_H
Node item.
Definition: QGVNode.h:33
Definition: QGVGraphPrivate.h:6
Edge item.
Definition: QGVEdge.h:33
SubGraph item.
Definition: QGVSubGraph.h:34
GraphViz interactive scene.
Definition: QGVScene.h:35
Definition: QGVGvcPrivate.h:6
#define QGVCORE_EXPORT
Definition: qgv.h:9