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