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