Tulip  4.0.0
Better Visualization Through Research
 All Classes 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 1 and Inria Bordeaux - Sud Ouest
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 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef INTERACTORCOMPOSITE_H
22 #define INTERACTORCOMPOSITE_H
23 
24 #include <tulip/Interactor.h>
25 #include <QtCore/QList>
26 
27 namespace tlp {
28 
29 /**
30  @class InteractorComposite represent a handler item inside an InteractorComposite
31 
32  @see InteractorComposite for details.
33  */
34 class TLP_QT_SCOPE InteractorComponent: public QObject {
35  Q_OBJECT
36 
37  View* _view;
38 
39 public:
40  virtual void init();
41  virtual bool eventFilter(QObject*, QEvent*);
42  virtual void clear() {}
43 
44  void setView(View* view);
45  View* view() const;
46 
47  virtual void viewChanged(View *) {}
48 };
49 
50 /**
51  @class InteractorComposite is a subclass of Interactor that allows building Interactors using component classes focused specifically on input handling.
52 
53  The composite behaves like a regular interactor. Event handling is made using InteractorComponent subclasses.
54  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.
55  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.
56 
57  When subclassing InteractorComposite, you should push your components in the construct() method (take care of the order they are pushed in).
58  Once the setView() method is called (after construct()), the init() method will be run on every components.
59  */
60 class TLP_QT_SCOPE InteractorComposite : public tlp::Interactor {
61  Q_OBJECT
62  QAction* _action;
63  tlp::View* _view;
64  QObject* _lastTarget;
65 
66 protected:
67  QList<tlp::InteractorComponent*> _components;
68  /**
69  @brief backup a QObject into the InteractorComposite.
70  This can be used to store the last target the interactor was installed on. This can be used when uninstall is called.
71  */
72  void setLastTarget(QObject*);
73 
74  /**
75  @return The last target the interactor was installed on.
76  @note If the lastTarget is destroyed before uninstall was called, the lastTarget() method will return NULL.
77  */
78  QObject* lastTarget() const;
79 
80 protected slots:
81  void lastTargetDestroyed();
82 
83 public:
84  typedef QList<InteractorComponent*>::iterator iterator;
85  typedef QList<InteractorComponent*>::const_iterator const_iterator;
86 
87  /**
88  @brief Default constructor
89  @param icon The icon set on the interactor's action
90  @param text The text set on the interactor's action
91  */
92  InteractorComposite(const QIcon& icon, const QString& text="");
93  virtual ~InteractorComposite();
94 
95  virtual tlp::View* view() const;
96  virtual QAction* action() const;
97  virtual QCursor cursor() const;
98 
99  /**
100  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow this class to be iterable
101  */
102  iterator begin();
103  /**
104  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow this class to be iterable
105  */
106  iterator end();
107  /**
108  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow this class to be iterable
109  */
110  const_iterator begin() const;
111  /**
112  @brief Since InteractorComposte behaves like a list of InteractorComponent, this method is here to allow this class to be iterable
113  */
114  const_iterator end() const;
115 
116  /**
117  @brief Pushs an InteractorComponent at the end of the list
118  */
119  void push_back(InteractorComponent* component);
120 
121  /**
122  @brief Pushs an InteractorComponent at the beggining of the list
123  */
124  void push_front(InteractorComponent* component);
125 
126 public slots:
127  virtual void undoIsDone();
128  virtual void setView(tlp::View* view);
129  virtual void install(QObject* target);
130  virtual void uninstall();
131 };
132 
133 }
134 #endif // INTERACTORCOMPOSITE_H
135 ///@endcond