Tulip  5.2.0
Large graphs analysis and drawing
InteractorComposite.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 INTERACTORCOMPOSITE_H
21 #define INTERACTORCOMPOSITE_H
22 
23 #include <tulip/Interactor.h>
24 
25 #include <QObject>
26 
27 class QIcon;
28 
29 namespace tlp {
30 
31 /**
32  @class InteractorComposite represent an event handler stored inside an InteractorComposite
33 
34  This is meant to be focused on event handling only. An InteractorComponent should respond to user
35  inputs in its eventFilter method and return true to avoid further propagation of the event to
36  other components.
37  This system is inherited from Qt event handling, see QObject::eventFilter() for details.
38  */
39 class TLP_QT_SCOPE InteractorComponent : public QObject {
40  Q_OBJECT
41 
42  View *_view;
43 
44 public:
45  /**
46  * @brief The init() method is called after the component gets installed on a target. Note that
47  * this method is called before any event from could have been retrieved.
48  */
49  virtual void init();
50 
51  /**
52  * @brief The main event handling method.
53  * See QObject::eventFilter for details.
54  * @note The target object is the one on which the InteractorComponent has been installed.
55  */
56  bool eventFilter(QObject *, QEvent *) override;
57 
58  /**
59  * @brief This method is called after the component is uninstalled from its target.
60  */
61  virtual void clear() {}
62 
63  /**
64  * @brief setView is called when the InteractorComposite is installed on a new view.
65  * @see InteractorComposite::setView
66  */
67  void setView(View *view);
68 
69  /**
70  * @return The view on which the interactor is installed (nullptr if none)
71  */
72  View *view() const;
73 
74  /**
75  * @brief A callback method after setView was called.
76  */
77  virtual void viewChanged(View *) {}
78 };
79 
80 /**
81  @class InteractorComposite is a subclass of Interactor that allows building Interactors using
82  component classes focused specifically on input handling.
83 
84  The composite behaves like a regular interactor. Event handling is made using InteractorComponent
85  subclasses.
86  Basically, an InteractorComposite is a list of InteractorComponent. Each of them are meant to be
87  pushed in the list using the push_back and push_front methods.
88  When an event is caught by the InteractorComposite, it will iterate over all components (in th
89  order provided by the list) and run eventFilter on each one of them until one of the component
90  returns true.
91 
92  When subclassing InteractorComposite, you should push your components in the construct() method
93  (take care of the order they are pushed in).
94  Once the setView() method is called (after construct()), the init() method will be run on every
95  components.
96  */
97 class TLP_QT_SCOPE InteractorComposite : public tlp::Interactor {
98  Q_OBJECT
99  QAction *_action;
100  tlp::View *_view;
101  QObject *_lastTarget;
102 
103 protected:
104  QList<tlp::InteractorComponent *> _components;
105  /**
106  @brief backup a QObject into the InteractorComposite.
107  This can be used to store the last target the interactor was installed on. This can be used when
108  uninstall is called.
109  */
110  void setLastTarget(QObject *);
111 
112  /**
113  @return The last target the interactor was installed on.
114  @note If the lastTarget is destroyed before uninstall was called, the lastTarget() method will
115  return nullptr.
116  */
117  QObject *lastTarget() const;
118 
119 protected slots:
120  void lastTargetDestroyed();
121 
122 public:
123  typedef QList<InteractorComponent *>::iterator iterator;
124  typedef QList<InteractorComponent *>::const_iterator const_iterator;
125 
126  /**
127  @brief Default constructor
128  @param icon The icon set on the interactor's action
129  @param text The text set on the interactor's action
130  */
131  InteractorComposite(const QIcon &icon, const QString &text = "");
132  ~InteractorComposite() override;
133 
134  tlp::View *view() const override;
135  QAction *action() const override;
136  QCursor cursor() const override;
137 
138  /**
139  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
140  to allow this class to be iterable
141  */
142  iterator begin();
143  /**
144  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
145  to allow this class to be iterable
146  */
147  iterator end();
148  /**
149  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
150  to allow this class to be iterable
151  */
152  const_iterator begin() const;
153  /**
154  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
155  to allow this class to be iterable
156  */
157  const_iterator end() const;
158 
159  /**
160  @brief Pushs an InteractorComponent at the end of the list
161  */
162  void push_back(InteractorComponent *component);
163 
164  /**
165  @brief Pushs an InteractorComponent at the beggining of the list
166  */
167  void push_front(InteractorComponent *component);
168 
169 public slots:
170  void undoIsDone() override;
171  void setView(tlp::View *view) override;
172  void install(QObject *target) override;
173  void uninstall() override;
174 };
175 }
176 #endif // INTERACTORCOMPOSITE_H
Interactor provides a way to handle user inputs over a view. Basically, The interactor class is an ov...
Definition: Interactor.h:61
View plugins provide a way to dynamically add to a Tulip plateform various ways to visualize a graph...
Definition: View.h:90