Tulip  5.3.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  void resetGraphicsScene() override {}
69 
70 public slots:
71  /**
72  @see View::setupUi
73  @note This method should not be reimplemented as a subclass of ViewWidget
74  */
75  void setupUi() override;
76 
77  /**
78  @brief Reimplemented from View::draw()
79  By default, this method does nothing. We assume the widget is automatically repainted by Qt's
80  windowing manager
81  */
82  void draw() override {}
83 
84 protected slots:
85  /**
86  By default, the current interactor gets installed over the central widget.
87 
88  @see View::currentInteractorChanged()
89  */
90  void currentInteractorChanged(tlp::Interactor *) override;
91 
92  void graphDeleted(Graph *parentGraph) override;
93 
94 protected:
95  /**
96  @brief Sets up the central widget.
97  This is similar to View::setupUi in the sense that the purpose of setupWidget is to construct
98  the GUI element.
99  @warning This method MUST call the setCentralWidget to provide the ViewWidget with a valid
100  widget.
101  */
102  virtual void setupWidget() = 0;
103 
104  /**
105  @brief Adds an item to the graphicsView that will be drawn on top of the widget
106  This is a convenience function for the user to avoid taking care of item parenthood.
107  */
108  void addToScene(QGraphicsItem *item);
109 
110  /**
111  @brief Removes a graphics item from the view.
112  This is a convenience function for the user to avoid taking care of item parenthood.
113  */
114  void removeFromScene(QGraphicsItem *item);
115 
116  /**
117  @brief Sets the widget to be drawn as the view's background.
118  This method may be called several times. Parenthood between the widget and items added using
119  addToScene will be automatically updated.
120  @note The ViewWidget takes ownership of the central widget. The previous central widget gets
121  deleted in the process.
122  */
123  void setCentralWidget(QWidget *, bool deleteOldCentralWidget = true);
124 
125  /**
126  @return The graphics item associated to the central widget
127  @see setCentralWidget
128  */
129  QGraphicsItem *centralItem() const override;
130 
131  QPixmap snapshot(const QSize &outputSize = QSize()) const override;
132 };
133 } // namespace tlp
134 
135 #endif // VIEWWIDGET_H
Interactor provides a way to handle user inputs over a view. Basically, The interactor class is an ov...
Definition: Interactor.h:62
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:92
void draw() override
Reimplemented from View::draw() By default, this method does nothing. We assume the widget is automat...
Definition: ViewWidget.h:82