Tulip 6.1.0
Large graphs analysis and drawing
Loading...
Searching...
No Matches
Interactor.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 _INTERACTOR_H
21#define _INTERACTOR_H
22
23#include <tulip/Plugin.h>
24#include <tulip/PluginLister.h>
25
26#include <QAction>
27#include <QCursor>
28#include <QMap>
29
30#include <string>
31
32class QLabel;
33
34namespace tlp {
35
36static const std::string INTERACTOR_CATEGORY = "Interactor";
37
38class View;
39
40/**
41 @ingroup Plugins
42 @brief Interactor provides a way to handle user inputs over a view.
43 Basically, The interactor class is an overlay to the Qt's event filtering mechanism. It adds
44 several features like the ability to define priorities, custom cursors, etc
45
46 When an interactor is constructed, the following methods are called in this order:
47 @li The constructor. This method should almost be a no-op. Interactors may be instantiated by the
48 plugin manager system and doing unneeded operations in the constructor may lead to poor
49 performances when the application loads up.
50 @li isCompatible. When creating a View, the application will check for all interactors to see if
51 they could be installed on it. This is done using the isCompatible method.
52 @li construct. Initialize the interactor. Since the constructor should be a no-op, initialization
53 code should be put here.
54 @li setView. Defines the view this interactor is bound to. The Interactor may keep a reference to
55 the view object to perform specific operations on user inputs.
56
57 Methods listed above are only called once. Once the interactor is initialized, it may be
58 installed/removed several times on different QObjects. It will then repond to user inputs via the
59 eventFilter method
60 @see QObject::eventFilter()
61 */
62class TLP_QT_SCOPE Interactor : public QObject, public Plugin {
63 Q_OBJECT
64 Q_PROPERTY(unsigned int priority READ priority)
65 Q_PROPERTY(QAction *action READ action)
66 Q_PROPERTY(QCursor cursor READ cursor)
67
68public:
69 std::string category() const override {
70 return INTERACTOR_CATEGORY;
71 }
72 std::string icon() const override {
73 return ":/tulip/gui/icons/32/plugin_interactor.png";
74 }
75 /**
76 @brief Checks the compatibility between the interactor and the given view (identified by its
77 name).
78 If this method returns true, it's very likely that the interactor will be installed on the
79 associated view.
80 */
81 virtual bool isCompatible(const std::string &viewName) const = 0;
82
83 /**
84 @return The interactor documentation.
85 @warning This method MUST ALWAYS return the same pointer. Doing otherwise may lead to memory
86 leaks.
87 @note The interactor document has to be instantiated from the construct method.
88 @note It is up to the interactor developer to delete the returned pointer.
89 */
90 virtual QLabel *configurationDocWidget() const {
91 return nullptr;
92 }
93
94 /**
95 @return the configuration options widget used to set up the interactor.
96 @warning This method MUST ALWAYS return the same pointer. Doing otherwise may lead to memory
97 leaks.
98 @note The configuration widget has to be instantiated from the construct method.
99 @note It is up to the interactor developer to delete the configuration widget
100 */
101 virtual QWidget *configurationOptionsWidget() const {
102 return nullptr;
103 }
104
105 /**
106 @return the interactor's priority.
107 Priority defines how interactors gets ordered when displayed in the View's toolbar.
108 Interactors with the top-most priority value will be displayed at the beginning of the list
109 while lowest priority will be position at the end.
110 */
111 virtual unsigned int priority() const = 0;
112
113 /**
114 @return a QAction associated to this interactor.
115 This is used by the overleying system to associate an icon/text to the interactor.
116 @warning The parent (QObject::parent()) object of this QAction MUST BE the Interactor.
117 */
118 virtual QAction *action() const = 0;
119
120 /**
121 @return the View object associated to this Interactor.
122 @warning The returned object MUST be the same as the one passed down to the setView method.
123 */
124 virtual tlp::View *view() const = 0;
125
126 /**
127 @return The cursor associated to this interactor.
128 When the interactor gets active on a view, the View's cursor is changed to what this method
129 returns.
130 */
131 virtual QCursor cursor() const = 0;
132
133 /**
134 @brief Builds up the interactor's internal state.
135 This method should be used instead of the constructor to initialize the interactor.
136 */
137 virtual void construct() = 0;
138
139 /**
140 @brief this method should be called before setting up the ui
141 * of an interactor config widget
142 */
143 static void setupConfigWidget(QWidget *);
144
145public slots:
146 /**
147 @brief Defines the view object associated to this interactor.
148 @warning The view() method MUST ALWAYS return the same pointer as the one passed down to this
149 method.
150 */
151 virtual void setView(tlp::View *) = 0;
152
153 /**
154 * @brief This method is called whenever the context menu is required on the view.
155 * @param point The screen coordinates where the context menu should be displayed.
156 @return true or false whether the context menu has been shown or not
157 */
158 virtual bool showContextMenu(const QPoint & /*point*/, const QPointF & /*scenePoint*/) {
159 return false;
160 }
161
162 /**
163 @brief Install the interactor on the given target
164 A call to this method means that the interactor should start listening to the target's events
165 and handle them.
166 Returning true prevents further handling of the event. Doing otherwise means that the interactor
167 will let following filters to hand over this kind of event.
168 */
169 virtual void install(QObject *target) = 0;
170
171 /**
172 @brief Removes the interactor from the previously set target.
173 Interactors can be installed on only one target at once.
174 */
175 virtual void uninstall() = 0;
176
177 /**
178 @brief Informs the interactor when the undo command (Ctrl+Z) has been triggered
179 */
180 virtual void undoIsDone() = 0;
181
182protected:
183 /**
184 @brief Provides input filtering for the interactor
185 @see QObject::eventFilter()
186 */
187 inline bool eventFilter(QObject *obj, QEvent *ev) override {
188 return QObject::eventFilter(obj, ev);
189 }
190};
191
192///@cond DOXYGEN_HIDDEN
193/**
194 * @ingroup Plugins
195 * @brief The InteractorLister class lists compatible interactors for a given tlp::View
196 */
197class TLP_QT_SCOPE InteractorLister {
198 static QMap<std::string, std::list<std::string>> _compatibilityMap;
199
200public:
201 static void initInteractorsDependencies();
202 static std::list<std::string> compatibleInteractors(const std::string &viewName);
203};
204///@endcond
205
206} // namespace tlp
207
208#endif
Interactor provides a way to handle user inputs over a view. Basically, The interactor class is an ov...
Definition Interactor.h:62
virtual void install(QObject *target)=0
Install the interactor on the given target A call to this method means that the interactor should sta...
virtual QCursor cursor() const =0
static void setupConfigWidget(QWidget *)
this method should be called before setting up the ui of an interactor config widget
virtual bool showContextMenu(const QPoint &, const QPointF &)
This method is called whenever the context menu is required on the view.
Definition Interactor.h:158
virtual QLabel * configurationDocWidget() const
Definition Interactor.h:90
std::string category() const override
A string identifier for a plugin used for categorization purposes.
Definition Interactor.h:69
virtual QAction * action() const =0
std::string icon() const override
The icon (preferably a thumbnail) of the plugin.
Definition Interactor.h:72
virtual void undoIsDone()=0
Informs the interactor when the undo command (Ctrl+Z) has been triggered.
virtual bool isCompatible(const std::string &viewName) const =0
Checks the compatibility between the interactor and the given view (identified by its name)....
bool eventFilter(QObject *obj, QEvent *ev) override
Provides input filtering for the interactor.
Definition Interactor.h:187
virtual void uninstall()=0
Removes the interactor from the previously set target. Interactors can be installed on only one targe...
virtual void construct()=0
Builds up the interactor's internal state. This method should be used instead of the constructor to i...
virtual unsigned int priority() const =0
virtual QWidget * configurationOptionsWidget() const
Definition Interactor.h:101
virtual tlp::View * view() const =0
virtual void setView(tlp::View *)=0
Defines the view object associated to this interactor.
Top-level interface for plug-ins.
Definition Plugin.h:86
View plugins provide a way to dynamically add to a Tulip plateform various ways to visualize a graph.
Definition View.h:94