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