Tulip  5.1.0
Large graphs analysis and drawing
View.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 #ifndef VIEW_H
20 #define VIEW_H
21 
22 #include <QObject>
23 #include <QSet>
24 #include <QList>
25 #include <QSize>
26 
27 #include <tulip/tulipconf.h>
28 #include <tulip/Observable.h>
29 #include <tulip/Plugin.h>
30 
31 class QGraphicsView;
32 class QGraphicsItem;
33 class QWidget;
34 class QPixmap;
35 class QMenu;
36 class QPointF;
37 class QPoint;
38 
39 namespace tlp {
40 static const std::string VIEW_CATEGORY = "Panel";
41 
42 class Interactor;
43 
44 /**
45  @ingroup Plugins
46 
47  @brief View plugins provide a way to dynamically add to a Tulip plateform various ways to visualize a graph.
48 
49  A view takes the following elements as inputs:
50  @li A graph which contains the data to be displayed.
51  @li A state (@c tlp::DataSet) which contains initialization parameters.
52 
53  As an output, a View must provide a @c QGraphicsView instance where all drawing is done.
54  User interaction on a View is handled by the tlp::Interactor class. Several interactors can be installed on the same view but there can be only one active interactor at the same time.
55  In the end, the view can provide several configuration widgets used to set up additional parameters.
56 
57  When a View gets created, the following methods will always be called in the following order:
58  @li The constructor. Basically, you don't want to do anything in this method as View instance may be created at Tulip startup when the plugin system gets initialized. Subsequent methods will be called in order for the view to build UI elements
59  @li View::setupUi(). Notifies the view it can now build GUI components since every part of its initial state should be valid by now. Once this method is called, any call to View::graphicsView() is expected to return a valid pointer object.
60  @li View::setGraph. Sets the graph that is meant to be visualized in the View's panel.
61  @li View::setState(). Sets initial data. This method may be used to restore a previously backed-up state retrieved from the View::state() method.
62  @li View::interactorsInstalled(). Notifies the view of the available interactors. Interactors objects taken from the list have already been initialized.
63 
64  Once the View is initialized, none of the previously mentioned methods, except View::setGraph(), can be called again.
65  View::setGraph method may be called again to notify the view that another graph should be displayed (this may be a sub/parent graph of the previously displayed graph or a graph coming from a totally different hierarchy)
66 
67  Views are meant to be managed by an overleying system. As a consequence, a view may not decide directly when to redraw.
68  Thus, you should never call the View::draw() method. To notify the overleying system that your view needs to be redrawn, emit the View::drawNeeded() signal instead.
69 
70  A tlp::View subclass automatically inherits from the tlp::Observable interface. The tlp::View interface also automatically listn to its active graph to trigger handling trigger when this graph gets deleted.
71  When the graph associated to a View gets deleted, the View::graphDeleted() callback is triggered. @see graphDeleted() for more information.
72  */
73 class TLP_QT_SCOPE View: public QObject, public tlp::Plugin, public tlp::Observable {
74  Q_OBJECT
75 
76  QList<tlp::Interactor*> _interactors;
77  tlp::Interactor* _currentInteractor;
78  tlp::Graph* _graph;
79 
80  QSet<tlp::Observable*> _triggers;
81 
82 public:
83  /**
84  @brief Default constructor
85  @warning Code of this method should almost be a no-op. Subsequent calls on other methods should allow you to setup your view.
86  */
87  View();
88 
89  /**
90  @brief Destructor
91  View's GUI components (graphics view, configuration widgets) responsibility belongs to the overleying system. Thus, the View is not in charge of deleting its graphcis view.
92  View's interactors are already deleted in the top class.
93  */
94  virtual ~View();
95 
96  virtual std::string category() const {
97  return VIEW_CATEGORY;
98  }
99  std::string icon() const {
100  return ":/tulip/gui/icons/32/plugin_view.png";
101  }
102 
103  /**
104  @return the View's panel as a @c QGraphicsView instance.
105  @note This method MUST ALWAYS return the same instance of a QGraphicsView.
106  */
107  virtual QGraphicsView* graphicsView() const=0;
108 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
109 //Following commit #10531 (see void WorkspacePanel::showEvent(QShowEvent *event);)
110 //this method is called when creating a new QGraphicsScene
111 //to restore any specific behaviour in user made graph views
112  virtual void resetGraphicsScene() {}
113 #endif
114 
115  /**
116  @return The list of interactors installed on this view.
117  The list is always the same as the one given when View::setInteractors() was called.
118  @see setInteractors();
119  */
120  QList<tlp::Interactor*> interactors() const;
121 
122  /**
123  @return The currently active interactor.
124  The active interactor is the one that currently recieve user inputs.
125  @see setCurrentInteractor();
126  @warning This method may return a NULL pointer if no interactor is currently active.
127  */
128  tlp::Interactor* currentInteractor() const;
129 
130  /**
131  @return a list of widgets that can be used to set up the view.
132  Since several widgets can be retrived, user will be able to select them from a combo box where each widget will be identified by its windowsTitle.
133  @see View::applySettings()
134  @warning This method must not instantiate configuration widgets on the fly.
135  */
136  virtual QList<QWidget*> configurationWidgets() const;
137 
138  /**
139  * @brief This method can be used to change the configuration widgets' style
140  * sheet. From Qt documentation: The style sheet contains a textual description of customizations to the
141  * widget's style, as described in the Qt Style Sheets document. see http://qt-project.org/doc/qt-4.7/stylesheet.html.
142  * @return The stylesheet to use
143  */
144  virtual QString configurationWidgetsStyleSheet() const;
145 
146  /**
147  @brief Backup the state of the view.
148  This method is used to restore the View's parameters when it's re-opened.
149  */
150  virtual tlp::DataSet state() const=0;
151 
152  /**
153  @return the graph displayed by the view.
154  @note This method MUST return the same graph pointer that was previously passed down to setGraph.
155  */
156  tlp::Graph* graph() const;
157 
158  /**
159  @return The list of currently registered triggers.
160  @see View::addRedrawTrigger()
161  */
162  QSet<tlp::Observable*> triggers() const;
163 
164  /**
165  @brief reimplemented from tlp::Observable to provide the triggers mechanism.
166  @see View::addRedrawTrigger()
167  */
168  void treatEvents(const std::vector<Event> &events);
169 
170  /**
171  @brief defines which item is considered as the central item in the view.
172  The central item is considered to be a background item that will be set as parent of every graphics item added by the workspace into the view.
173  By default, this method returns NULL, which means that no central item is defined.
174  */
175  virtual QGraphicsItem* centralItem() const;
176 
177  /**
178  @brief Takes a snapshot of the view's screen and saves it into the given pixmap.
179  The snapshot is scaled to outputSize. If a null size is given, the snapshot is to be on a 1:1 ratio
180  @return A non-null pixmap of the snapshot was correctly taken.
181  */
182  virtual QPixmap snapshot(const QSize& outputSize=QSize()) const=0;
183 
184 public slots:
185  /**
186  * @brief This method is called whenever the context menu is required on the view.
187  * @param point The screen coordinates where the context menu should be displayed.
188  */
189  void showContextMenu(const QPoint& point, const QPointF &scenePoint);
190 
191  /**
192  * @brief This method is a callback to notify the panel that the pop() method (undo) has just been called on the graph.
193  * By default, this method will make a call to centerView()
194  **/
195  virtual void undoCallback();
196 
197  /**
198  @brief This method applies settings changed in the configuration widgets
199  This method may be called from the overleying system in various situations. The View is expected to apply settings in an optimized way to prevent extra redraws.
200  By default, this method does nothing.
201  */
202  virtual void applySettings();
203 
204  /**
205  @brief Reset the visualization to the center.
206  This method is called after major changes into the data structure. At this point, the user point of view should be reset and brought back to a point where all the data can be seen.
207  @note It is expected for the view to be redrawn when calling centerView
208  For a 3D visualization, this method could be implemented by centering the camera. For a table, this could be done by setting the scroll bar to the top position etc...
209  By default, this method calls draw().
210  */
211  virtual void centerView(bool graphChanged = false);
212 
213 
214  /**
215  @brief defines the list of interactors available on this View
216  @note Calling this will trigger the View::interactorsInstalled() callback for custom handling.
217  */
218  virtual void setInteractors(const QList<tlp::Interactor*>&);
219 
220  /**
221  @brief defines the active interactor that will receive user inputs.
222  @note This method will first remove the previously active interactor (if any) using Interactor::uninstall()
223  @note Calling this will trigger the View::currentInteractorChanged() callback for custom handling.
224  @note Calling View::setCurrentInteractor(NULL) will only remove the previous current interactor.
225  */
226  void setCurrentInteractor(tlp::Interactor* currentInteractor);
227 
228  /**
229  @brief Restores the state of the view.
230  DataSet passed down to this method can come from a previous backup or be generated by the overleying system. It's up to the view to use this data or not.
231  */
232  virtual void setState(const tlp::DataSet&)=0;
233 
234  /**
235  @brief Defines the graph that should be displayed by the View
236  @note Calling setGraph triggers the View::graphChanged() callback for custom handling.
237  @warning This method and its subsequent callback might be called several times.
238  */
239  void setGraph(tlp::Graph* graph);
240 
241  /**
242  @brief Asks the view to draw.
155  @note This method will first remove eno"sl 9 state babl>me="l00155"> /**
175 
void undoCallback();
233  /**
175  @warning This method and f the view.
242  */
61  */
61 virtual 211 
99  std::str61131aabe4ec7a6ab3b4b317ab3751bcs="c251/spanywordtype">void undoCallback(inc9">>
242 t25ggers the View::graphChanged() callback f"> 61 
t, the usool> 105  /**
211  */
242  71 
211  @brief reimplemented fro26keywordtype">void undoCallback();
tlp::DataSet&)=0;
233 t2er()
211 
242  /**
andling.">me="l00155">
ast> &s.
207
  /**
div> 207  */
207 v> 207 
me="l00155"> */
175  virtual QGraphicsIt2m* centralItem()
177  /**
178  @brief Takes a snapshot 2f the view's screen and saves it into the giRe"><">
167  @return A non-null pixma2 of the snapshot was correctly taken. 175  */
void centerView(a name="l00113">">virtual QPixmap sna28> 103  l00178"> 178 public slots:
178 virtual QGraphicsIt2"line"> 61  * @brief This method is ca2led whenever the context menu is requir bor (ifFted to amo setaiv>
,sno upda>asholdss="lia namineno"> 61  /**
175  @brief Takes a snapshot 28const std::vector<Evenclear> 203 void showContex28> 220 
178  /**
178 virtual QPixmap sna2callback to notify the panel that the pop"lineno"> 175  * By default, this method29d by the view.o"word">const std::vector<Evene) 203  **/
175  virtual QGraphicsIt29"line"> 242 
230  /**
,slass=e"> 230  @brief Takes a snapshot 2s settings changed in the configuration w"lineno"> 175  void showCont<4502f1b2ac9"> 99  std::stra875086b1089b5383e3daa5d6a46a9c7hot 2s9/spanywordtype">void undoCallback();
  By default, this method 30e" href="classtloid undoCallbacf"l0s=rm">
185  /**
205  @brief Reset the visuali3ation to the center.
e="l0lineno"> 230  This method is called af3er major changes into the data structure.or (ifDepss="d will fame="l0 cla donemed trilineno"> 230  /**
175  For a 3D visualization, 30const std::vector<Even/> 203  By default, this method 3alls draw().
175  */
205 virtual 118  into the data structure.or (if At tsig9 stan><) 118 
175  /**
203  @brief defines the list 3f interactors av 203  This method is called af31teractor(  /**
205  /**
118  @brief defines the activ3 interactor that will receive user inputsback to a point94"> 118  175  @note Calling this will 32d by the view.o"word">const sk();
tlp::DataSete="l00219">  @note Calling View::setC3rrentInteractor(NULL) will only removineno"> 175  @brief defines the list 3line"> 205  This method is called af32>tlp::Interacto)1"> 118  /**
175  DataSet passed down to t33e" href="classtlp_1_1_data_set.html">tlp::DataSet ss="line">
  */
175  153 
193  @brief Defines the graph3that should be displayed by the View 175  This method is called af33teractor(
233  @warning This method and3its subsequent callback might be callineno"> 175  For a 3D visualization, 3="line"> 153 
71 
/div>
61  /**
61 
233  /**
175  @brief Defines the graph34ine"> 205  /**
61  */
175  virtual 99  std::str440d13e61af3778729cd782c89ad403b"lin35"lipanywordtype">void undoCallback();
tlp::DataSete/a> 102 
  @brief Defines the graph3="line">#ss="f ineno"> "l00150"> "l00156">ineno"> 175 ttc" id="ss="s> ttss="n clalass="ss="s> ttdefn cb>>#mme0t"> Abst0227Property.h:thatpany175 ttc" id="line"> ttss="n clalass="line"> ttdefn cb>>#mment"> G"l0024:ter mpany175 ttc" id="line"> ttss="n clalass="line">ny175 ttdoc">Iclass="lineme="l0clase="l002 clasy,imeiv class="lin>) juste.<="lin175 ttdefn cb>>#mme0t"> I class="lin:ed bpany175 ttc" id="line">_ad1a389af9683bdfd6582b4502f1b2ac9 ttss="n clalass="line"> ttdeci">ame="st0> ttdoc">meiv s:D (preflasbl><)n> ttdefn cb>>#mme0trdt/a> ttc" id="line"> ttss="n clalass="line"> ttdoc">A "> ttdefn cb>>#mment"> ttc" id="line">_a61131aabe4ec7a6ab3b4b317ab3751bcs=/span> ttss="n clalass="line"> ttdeci">); ttdoc">amfl00h61">