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 
19 #ifndef QGVSCENE_H
20 #define QGVSCENE_H
21 
22 
23 
24 #include <QMap>
25 #include <QGraphicsScene>
26 
27 #include "qgv.h"
28 
29 class QGVNode;
30 class QGVEdge;
31 class QGVSubGraph;
32 
33 class QGVGraphPrivate;
34 class QGVGvcPrivate;
35 
40 class QGVCORE_EXPORT QGVScene : public QGraphicsScene
41 {
42  Q_OBJECT
43  public:
44 
45  explicit QGVScene(const QString &name, QObject *parent = 0);
46  ~QGVScene();
47 
48  void setGraphAttribute(const QString &name, const QString &value);
49  void setNodeAttribute(const QString &name, const QString &value);
50  void setEdgeAttribute(const QString &name, const QString &value);
51 
52  QGVNode* addNode(const QString& label);
53  QGVEdge* addEdge(QGVNode* source, QGVNode* target, const QString& label);
54  QGVEdge *addEdge(const QString &source, const QString &target,
55  const QString &label);
56 
57  QGVSubGraph* addSubGraph(const QString& name, bool cluster = true);
58  void removeNode(const QString &label);
59 // void removeEdge(const QString& source, const QString& target);
60 // void removeEdge(const QPair<QString, QString>& key);
61  void removeEdge(const QString &label);
62 
63  bool hasNode(const QString &name);
64  QGVNode *getNode(const QString &name);
65 
66  void setRootNode(QGVNode *node);
67 
68  int nodeCount() const;
69  int edgeCount() const;
70 
71  void loadLayout(const QString &text);
72  void applyLayout();
73  void clearLayout();
74  void clear();
75 
76 
77  signals:
78  void nodeContextMenu(QGVNode* node);
79  void nodeDoubleClick(QGVNode* node);
80 
81  void edgeContextMenu(QGVEdge* edge);
82  void edgeDoubleClick(QGVEdge* edge);
83 
84  void subGraphContextMenu(QGVSubGraph* graph);
85  void subGraphDoubleClick(QGVSubGraph* graph);
86 
87  void graphContextMenuEvent();
88 
89  public slots:
90 
91  protected:
92  virtual void contextMenuEvent(
93  QGraphicsSceneContextMenuEvent * contextMenuEvent);
94  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * mouseEvent);
95  virtual void drawBackground(QPainter * painter, const QRectF & rect);
96  private:
97  friend class QGVNode;
98  friend class QGVEdge;
99  friend class QGVSubGraph;
100 
101  QGVGvcPrivate *_context;
102  QGVGraphPrivate *_graph;
103 
104  QMap<QString, QGVNode *> _nodes;
105 // QMap<QPair<QString, QString>, QGVEdge*> _edges;
106  QMap<QString, QGVEdge *> _edges;
107  QMap<QString, QGVSubGraph *> _subGraphs;
108 
109  bool init;
110 };
111 
112 #endif
Node item.
Definition: QGVNode.h:33
Definition: QGVGraphPrivate.h:24
Edge item.
Definition: QGVEdge.h:34
SubGraph item.
Definition: QGVSubGraph.h:35
GAZEBO_VISIBLE void init()
GraphViz interactive scene.
Definition: QGVScene.h:40
Definition: QGVGvcPrivate.h:24
#define QGVCORE_EXPORT
Definition: qgv.h:33