Tulip  5.3.0
Large graphs analysis and drawing
GlMainView.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef Tulip_GLMAINVIEW_H
21 #define Tulip_GLMAINVIEW_H
22 
23 #include <tulip/ViewWidget.h>
24 
25 class QGraphicsProxyWidget;
26 class QAction;
27 class QPushButton;
28 class QRectF;
29 
30 namespace tlp {
31 class GlOverviewGraphicsItem;
32 class SceneConfigWidget;
33 class SceneLayersConfigWidget;
34 class GlMainWidget;
35 class QuickAccessBar;
36 class ViewActionsManager;
37 
38 /**
39  * @ingroup Plugins
40  *
41  * @brief An abstract view that displays a GlMainWidget as its central widget.
42  *
43  * The GlMainView subclasses ViewWidget and always uses a GlMainWidget as the central widget of the
44  panel. It also adds the following features:
45  * @list
46  * @li An overview of the scene that can be toggled on or off.
47  * @li Some configuration widgets that modify the rendering parameters.
48  * @li A quick access bar widget that allows the user to quickly modify some of the most used
49  rendering parameters and graph properties (nodes color, edges display, etc)
50  * @li The possibility to make snapshots of the current scene
51  * @endlist
52  *
53  * Subclassing GlMainView means you will only want to display graphs in a single GlMainWidget.
54  Switching the central widget can only be achieved from the ViewWidget class.
55  *
56  * @warning It is strongly unadvised to re-implement methods already implemented into tlp::View or
57  tlp::ViewWidget. If you have to add custom behavior to those method, make sure to call the
58  upper-class methods first:
59  @code
60  void MyView::setupWidget() { // Where MyView is a subclass of tlp::GlMainView
61  GlMainView::setupWidget(); // call this first
62  // insert custom behavior here
63  }
64  @endcode
65 
66  * @see tlp::ViewWidget
67  */
68 class TLP_QT_SCOPE GlMainView : public tlp::ViewWidget {
69 
70  Q_OBJECT
71 
72  tlp::GlMainWidget *_glMainWidget;
73  tlp::GlOverviewGraphicsItem *_overviewItem;
74  tlp::ViewActionsManager *_viewActionsManager;
75 
76  QPushButton *_showOvButton, *_showQabButton;
77 
78 protected:
79  bool needQuickAccessBar, _needTooltipAndUrlManager;
80  QGraphicsProxyWidget *_quickAccessBarItem;
81  tlp::QuickAccessBar *_quickAccessBar;
82  tlp::SceneConfigWidget *_sceneConfigurationWidget;
83  tlp::SceneLayersConfigWidget *_sceneLayersConfigurationWidget;
84 
85 public:
86  enum OverviewPosition {
87  OVERVIEW_TOP_LEFT,
88  OVERVIEW_TOP_RIGHT,
89  OVERVIEW_BOTTOM_LEFT,
90  OVERVIEW_BOTTOM_RIGHT
91  };
92 
93  GlMainView(bool needTooltipAndUrlManager = false);
94  ~GlMainView() override;
95  tlp::GlMainWidget *getGlMainWidget() const;
96  QList<QWidget *> configurationWidgets() const override;
97  bool overviewVisible() const;
98  QPixmap snapshot(const QSize &outputSize = QSize()) const override;
99 
100  void setOverviewPosition(const OverviewPosition &position);
101  OverviewPosition overviewPosition() const;
102 
103  void setUpdateOverview(bool updateOverview);
104  bool updateOverview() const;
105 
106  void setState(const tlp::DataSet &) override;
107  tlp::DataSet state() const override;
108 
109 public slots:
110  /**
111  * @brief Calls GlMainWidget::draw();
112  */
113  void draw() override;
114 
115  /**
116  * @brief Calls GlMainWidget::redraw();
117  */
118  void redraw();
119 
120  /**
121  * @brief Calls GlMainWidget::redraw();
122  */
123  void refresh() override;
124 
125  /**
126  * @brief Force the overview to be redrawn. Since GlMainView already detects graph's
127  * modifications, this method should not be called manually to avoid extra rendering.
128  */
129  virtual void drawOverview(bool generatePixmap = true);
130 
131  /**
132  * @brief Centers the scene's camera
133  */
134  void centerView(bool graphChanged = false) override;
135 
136  /**
137  * @brief Toggles the overview on or off
138  */
139  void setOverviewVisible(bool);
140 
141  /**
142  * @brief Toggles the orthogonal projection on or off, then draws
143  */
144  void setViewOrtho(bool);
145 
146  /**
147  * @brief Force the settings set in the configuration widgets to be re-applied.
148  */
149  void applySettings() override;
150 
151  void undoCallback() override;
152 
153  static bool getNodeOrEdgeAtViewportPos(GlMainWidget *glw, int x, int y, node &n, edge &e);
154 
155  bool getNodeOrEdgeAtViewportPos(int x, int y, node &n, edge &e) const override {
156  return getNodeOrEdgeAtViewportPos(_glMainWidget, x, y, n, e);
157  }
158 
159 protected slots:
160  virtual void glMainViewDrawn(bool graphChanged);
161  virtual void sceneRectChanged(const QRectF &);
162  void setQuickAccessBarVisible(bool);
163  void fillContextMenu(QMenu *menu, const QPointF &) override;
164 
165 protected:
166  void setupWidget() override;
167  bool quickAccessBarVisible() const;
168  void assignNewGlMainWidget(GlMainWidget *glMainWidget, bool deleteOldGlMainWidget = true);
169  bool eventFilter(QObject *obj, QEvent *event) override;
170 
171  tlp::GlOverviewGraphicsItem *overviewItem() const;
172  void updateShowOverviewButton();
173  void updateShowQuickAccessBarButton();
174  virtual QuickAccessBar *getQuickAccessBarImpl();
175 
176  OverviewPosition _overviewPosition;
177 
178  bool _updateOverview;
179 };
180 } // namespace tlp
181 
182 #endif /* GLMAINVIEW_H_ */
An abstract view that displays a GlMainWidget as its central widget.
Definition: GlMainView.h:68
A container that can store data from any type.
Definition: DataSet.h:189
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
The node struct represents a node in a Graph object.
Definition: Node.h:40
ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QW...
Definition: ViewWidget.h:49
This widget provide a simple system to visualize data/graph with OpenGL 3D engine.
Definition: GlMainWidget.h:64