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