Tulip  5.2.0
Large graphs analysis and drawing
ViewWidget.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 VIEWWIDGET_H
21 #define VIEWWIDGET_H
22 
23 #include <tulip/tulipconf.h>
24 #include <tulip/View.h>
25 
26 class QGraphicsItem;
27 
28 namespace tlp {
29 
30 /**
31  @ingroup Plugins
32 
33  @brief ViewWidget provides convenience functions to allow the user to build a view plugin that
34  displays a QWidget as its main element.
35 
36  The ViewWidget class will build a QGraphicsView that sets a widget as the background of the whole
37  panel.
38  Sublassing ViewWidget means that you'll have to provide a centralWidget (see
39  ViewWidget::setCentralWidget) that will take up the whole panel and be drawn in the background.
40  You can use the addToScene() and removeFromScene() methods to edit the QGraphicsItems that will
41  drawn over the widget.
42 
43  By default, when an interactor gets active on a ViewWidget, it gets installed on the centralWidget
44  (see Interactor::install)
45 
46  @note When creating a ViewWidget, you should overload setupWidget instead of setupUi. If you still
47  want to implement setupUi, you must call the ViewWidget::setupUi() method first.
48  */
49 class TLP_QT_SCOPE ViewWidget : public tlp::View {
50  Q_OBJECT
51 
52  QSet<QGraphicsItem *> _items;
53  QGraphicsView *_graphicsView;
54  QWidget *_centralWidget;
55  QGraphicsItem *_centralWidgetItem;
56 
57  void refreshItemsParenthood();
58 
59 public:
60  ViewWidget();
61  ~ViewWidget() override;
62 
63  /**
64  @see View::graphicsView()
65  @note This method should not be reimplemented as a subclass of ViewWidget
66  */
67  QGraphicsView *graphicsView() const override;
68 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
69  void resetGraphicsScene() override {}
70 #endif
71 
72 public slots:
73  /**
74  @see View::setupUi
75  @note This method should not be reimplemented as a subclass of ViewWidget
76  */
77  void setupUi() override;
78 
79  /**
80  @brief Reimplemented from View::draw()
81  By default, this method does nothing. We assume the widget is automatically repainted by Qt's
82  windowing manager
83  */
84  void draw() override {}
85 
86 protected slots:
87  /**
88  By default, the current interactor gets installed over the central widget.
89 
90  @see View::currentInteractorChanged()
91  */
92  void currentInteractorChanged(tlp::Interactor *) override;
93 
94  void graphDeleted(Graph *parentGraph) override;
95 
96 protected:
97  /**
98  @brief Sets up the central widget.
99  This is similar to View::setupUi in the sense that the purpose of setupWidget is to construct
100  the GUI element.
101  @warning This method MUST call the setCentralWidget to provide the ViewWidget with a valid
102  widget.
103  */
104  virtual void setupWidget() = 0;
105 
106  /**
107  @brief Adds an item to the graphicsView that will be drawn on top of the widget
108  This is a convenience function for the user to avoid taking care of item parenthood.
109  */
110  void addToScene(QGraphicsItem *item);
111 
112  /**
113  @brief Removes a graphics item from the view.
114  This is a convenience function for the user to avoid taking care of item parenthood.
115  */
116  void removeFromScene(QGraphicsItem *item);
117 
118  /**
119  @brief Sets the widget to be drawn as the view's background.
120  This method may be called several times. Parenthood between the widget and items added using
121  addToScene will be automatically updated.
122  @note The ViewWidget takes ownership of the central widget. The previous central widget gets
123  deleted in the process.
124  */
125  void setCentralWidget(QWidget *, bool deleteOldCentralWidget = true);
126 
127  /**
128  @return The graphics item associated to the central widget
129  @see setCentralWidget
130  */
131  QGraphicsItem *centralItem() const override;
132 
133  QPixmap snapshot(const QSize &outputSize = QSize()) const override;
134 };
135 } // namespace tlp
136 
137 #endif // VIEWWIDGET_H
Interactor provides a way to handle user inputs over a view. Basically, The interactor class is an ov...
Definition: Interactor.h:61
ViewWidget provides convenience functions to allow the user to build a view plugin that displays a QW...
Definition: ViewWidget.h:49
View plugins provide a way to dynamically add to a Tulip plateform various ways to visualize a graph...
Definition: View.h:90
void draw() override
Reimplemented from View::draw() By default, this method does nothing. We assume the widget is automat...
Definition: ViewWidget.h:84