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