Tulip  6.0.0
Large graphs analysis and drawing
InteractorComposite.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 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  * @brief This method is called whenever the context menu is required on the view.
81  * @param point The screen coordinates where the context menu should be displayed.
82  @return true or false whether the context menu has been shown or not
83  */
84  virtual bool showContextMenu(const QPoint & /*point*/, const QPointF & /*scenePoint*/) {
85  return false;
86  }
87 };
88 
89 /**
90  @class InteractorComposite is a subclass of Interactor that allows building Interactors using
91  component classes focused specifically on input handling.
92 
93  The composite behaves like a regular interactor. Event handling is made using InteractorComponent
94  subclasses.
95  Basically, an InteractorComposite is a list of InteractorComponent. Each of them are meant to be
96  pushed in the list using the push_back and push_front methods.
97  When an event is caught by the InteractorComposite, it will iterate over all components (in th
98  order provided by the list) and run eventFilter on each one of them until one of the component
99  returns true.
100 
101  When subclassing InteractorComposite, you should push your components in the construct() method
102  (take care of the order they are pushed in).
103  Once the setView() method is called (after construct()), the init() method will be run on every
104  components.
105  */
106 class TLP_QT_SCOPE InteractorComposite : public tlp::Interactor {
107  Q_OBJECT
108  QAction *_action;
109  tlp::View *_view;
110  QObject *_lastTarget;
111 
112 protected:
113  QList<tlp::InteractorComponent *> _components;
114  /**
115  @brief backup a QObject into the InteractorComposite.
116  This can be used to store the last target the interactor was installed on. This can be used when
117  uninstall is called.
118  */
119  void setLastTarget(QObject *);
120 
121  /**
122  @return The last target the interactor was installed on.
123  @note If the lastTarget is destroyed before uninstall was called, the lastTarget() method will
124  return nullptr.
125  */
126  QObject *lastTarget() const;
127 
128 protected slots:
129  void lastTargetDestroyed();
130 
131 public:
132  typedef QList<InteractorComponent *>::iterator iterator;
133  typedef QList<InteractorComponent *>::const_iterator const_iterator;
134 
135  /**
136  @brief Default constructor
137  @param icon The icon set on the interactor's action
138  @param text The text set on the interactor's action
139  */
140  InteractorComposite(const QIcon &icon, const QString &text = "");
141  ~InteractorComposite() override;
142 
143  tlp::View *view() const override;
144  QAction *action() const override;
145  QCursor cursor() const override;
146 
147  /**
148  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
149  to allow this class to be iterable
150  */
151  iterator begin();
152  /**
153  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
154  to allow this class to be iterable
155  */
156  iterator end();
157  /**
158  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
159  to allow this class to be iterable
160  */
161  const_iterator begin() const;
162  /**
163  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here
164  to allow this class to be iterable
165  */
166  const_iterator end() const;
167 
168  /**
169  @brief Pushs an InteractorComponent at the end of the list
170  */
171  void push_back(InteractorComponent *component);
172 
173  /**
174  @brief Push an InteractorComponent at the beginning of the list
175  */
176  void push_front(InteractorComponent *component);
177 
178  /**
179  @brief iterate on _components to show context menu
180  */
181  bool showContextMenu(const QPoint & /*point*/, const QPointF & /*scenePoint*/) override;
182 
183 public slots:
184  void undoIsDone() override;
185  void setView(tlp::View *view) override;
186  void install(QObject *target) override;
187  void uninstall() override;
188 };
189 } // namespace tlp
190 #endif // INTERACTORCOMPOSITE_H
const_iterator end() const
Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow thi...
iterator end()
Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow thi...
void push_front(InteractorComponent *component)
Push an InteractorComponent at the beginning of the list.
iterator begin()
Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow thi...
void setLastTarget(QObject *)
backup a QObject into the InteractorComposite. This can be used to store the last target the interact...
bool showContextMenu(const QPoint &, const QPointF &) override
iterate on _components to show context menu
QAction * action() const override
InteractorComposite(const QIcon &icon, const QString &text="")
Default constructor.
QObject * lastTarget() const
QCursor cursor() const override
void push_back(InteractorComponent *component)
Pushs an InteractorComponent at the end of the list.
const_iterator begin() const
Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow thi...
tlp::View * view() const override
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