Tulip 6.1.0
Large graphs analysis and drawing
Loading...
Searching...
No Matches
Perspective.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 _PERSPECTIVE_H
21#define _PERSPECTIVE_H
22
23#include <tulip/PluginContext.h>
24#include <tulip/Plugin.h>
25#include <tulip/TlpQtTools.h>
26
27#include <QString>
28#include <QVariantMap>
29#include <QSet>
30#include <QMenu>
31#include <QMainWindow>
32
33namespace tlp {
34
35class Graph;
36class PluginProgress;
37class TulipProject;
38
39static const std::string PERSPECTIVE_CATEGORY = "Perspective";
40
41/**
42 * @ingroup Plugins
43 * @brief A context data structure for tlp::Perspective instances.
44 *
45 * @see tlp::Perspective
46 */
47class TLP_QT_SCOPE PerspectiveContext : public tlp::PluginContext {
48public:
49 PerspectiveContext() : mainWindow(nullptr), project(nullptr) {}
50 QMainWindow *mainWindow;
51 TulipProject *project;
52 QString externalFile;
53 QVariantMap parameters;
54 unsigned int id;
55};
56
57/**
58 * @ingroup Plugins
59 * @brief A Perspective is a Tulip plugin that completely re-defines the user interface.
60 *
61 * A Perspective aims at using the multiple features available in Tulip to create a complete,
62 * coherent workflow dedicated to a particular use-case.
63 * The main perspective is called "Tulip". This perspective unveils all the Tulip features and aims
64 * at being a protyping and researching platform.
65 *
66 * It is the Perspective's responsibility to offer the possibility to display graphs, run
67 * plugins, etc. A lot of helper classes can be found into the tulip-gui API like pre-made widgets,
68 * Qt models, etc.
69 *
70 * Perspective's data is stored into a TulipProject. A TulipProject is an archive capable of
71 * containing heterogeneous data (like multiple graphs, textures, extra files, etc). When a
72 * TulipProject gets saved by a perspective, it is linked to it in its meta-information.
73 * Creating a Perspective primarily into implementing the start() method that builds the GUI. This
74 * method will be called by the overleying system when a new perspective is launched. The rest of
75 * the logic implementation is left to the developer.
76 */
77class TLP_QT_SCOPE Perspective : public QObject, public tlp::Plugin {
78 Q_OBJECT
79
80 static tlp::Perspective *_instance;
81 QSet<QString> _reservedProperties;
82 unsigned int _perspectiveId;
83 bool _maximised;
84
85protected:
86 /**
87 * @brief The project associated to this perspective. This project can be empty or contain data
88 * depending on how the Perspective was launched:
89 * To launch a perspective, the tulip executable is called with the following
90 * arguments:
91 * @code
92 * tulip exe [--perspective=Name] [file_path]
93 * @endcode
94 * @list
95 * @li The --perspective argument forces Tulip to start the "Name" perspective. Even if the
96 * project states otherwise. If this argument is not specified, Tulip will look in the project's
97 * meta-data to dertermine the perspective to launch.
98 * @li file_path is the absolute path of the project archive to associate with the perspective. If
99 * file_path is not given, the --perspective argument must be declared in order for Tulip to know
100 * what perspective to launch. In this case, _project will point to an empty (but valid!) project.
101 * @endlist
102 */
103 TulipProject *_project;
104
105 /**
106 * @brief The main window on which the perspective should build the GUI.
107 *
108 * It is not the Perspective's responsibility to destroy the main window when the application gets
109 * closed. Generally speaking, destroying the _mainWindow pointer could lead to undefined
110 * behavior.
111 */
112 QMainWindow *_mainWindow;
113
114 /**
115 * If the user provided a file to the tulip exe but this file is not recognized as a valid
116 * TulipProject, the full path of the file will be stored into the _externalFile member.
117 * @note Remember that perspectives should always store their data into TulipProject in order to
118 * keep a consistent workflow.
119 */
121
122 /**
123 * @brief Contains extra parameters that have not been parsed by the overleying system. Those are
124 * considered to be Perspective-specific and are forwarded into this variable.
125 */
126 QVariantMap _parameters;
127
128public:
129 enum ProgressOption {
130 NoProgressOption = 0x0,
131 IsPreviewable = 0x1,
132 IsCancellable = 0x2,
133 IsStoppable = 0x4
134 };
135 Q_DECLARE_FLAGS(ProgressOptions, ProgressOption)
136
137 std::string category() const override {
138 return PERSPECTIVE_CATEGORY;
139 }
140 std::string icon() const override {
141 return ":/tulip/gui/icons/32/plugin_controller.png";
142 }
143
144 /**
145 * @brief Called at the beginning of the tulip exe to set the Perspective singleton.
146 * @see instance()
147 */
149
150 /**
151 * Since a Perspective has its own process to work in, there can be only one perspective instance
152 * by process.
153 * In order to ease the development process, Perspective are available as a singleton in order for
154 * child widgets and plugins to be able to access to the features of a Perspective.
155 * This architecture was added for developers who want to create an application containing several
156 * plugins grouped into Perspective.
157 * @return The perspective singleton
158 */
160
161 /**
162 * @return A typed instance of the perspective singleton.
163 */
164 template <typename T>
165 static T *typedInstance() {
166 return dynamic_cast<T *>(instance());
167 }
168
169 /**
170 * @brief Constructs a perspective object
171 * @warning There should not be any logic implemented into the Perspective's constructor. See the
172 * start method instead.
173 */
175 ~Perspective() override;
176
177 /**
178 * @brief Build the main window GUI and starts the workflow.
179 * When this method is called, it means that the Perspective is responsible of the application
180 * workflow until the application is closed by the user.
181 * @param progress A progress handler
182 */
184
185 /**
186 * @brief Creates a progress handler and returns it.
187 * This method allows lower-level widgets to create top-level progress bars directly from the
188 * Perspective.
189 * @return
190 */
191 virtual PluginProgress *
192 progress(ProgressOptions options = ProgressOptions(IsPreviewable | IsStoppable | IsCancellable));
193
194 /**
195 * @brief usage Displays a usage message when called from the tulip executable
196 */
197 virtual void usage(std::string &usage_str) const {
198 usage_str = "No options for this perspective.";
199 }
200
201 /**
202 * @return The Perspective's current graph.
203 */
204 virtual Graph *currentGraph() {
205 return nullptr;
206 }
207
208 /**
209 * @return The Perspective's main window.
210 */
211 QMainWindow *mainWindow() const;
212
213 /**
214 * @brief Checks if the name corresponds to a reserved properties.
215 * Perspectives are allowed to reserve graph properties. A reserved graph properties is a core
216 * property that cannot be deleted by the user and cannot be renamed.
217 * @return true if the perspective is registered.
218 */
220
221 /**
222 * @brief Sets a new property name as registered
223 */
225
226 /**
227 * @brief Tells the perspective that the graph visualizations should be redrawn.
228 * @param center if true, visualization should also be centered (eg. the layout has been changed)
229 */
230 virtual void redrawPanels(bool center = false) = 0;
231
232 /**
233 * @brief Tells the perspective that the visualizations for a given graph should be centered.
234 * @note By default, this method does nothing.
235 */
237
238 void resetTitle() {
239 emit resetWindowTitle();
240 }
241
242 bool _restartNeeded;
243 /**
244 * @brief a function to indicate restart
245 */
246 bool needRestart() {
247 return _restartNeeded;
248 }
249
250 /**
251 * @brief a static function to ease the display of status messages
252 */
253 static void showStatusMessage(const QString &msg) {
254 instance()->displayStatusMessage(msg);
255 }
256
257 /**
258 * @brief a static function to ease the display of status messages
259 */
260 static void showStatusMessage(const std::string &msg) {
262 }
263
264 /**
265 * @brief a static function to enable the redirection of the statusTip
266 * or toolTip of menu actions
267 */
268 static void redirectStatusTipOfMenu(QMenu *menu);
269
270 /**
271 * @brief a static function to log a message
272 * see qInstallMessageHandler
273 */
274 static void showLogMessage(QtMsgType type, const QMessageLogContext &context,
275 const QString &msg) {
276 instance()->logMessage(type, context, msg);
277 }
278
279 /**
280 * @brief a static function to display the log messages
281 */
282 static void showLogMessages() {
283 instance()->displayLogMessages();
284 }
285
286 /**
287 * @brief a static function to set the same style sheet
288 * as the instance main window style sheet
289 */
290 static void setStyleSheet(QWidget *w);
291
292 /**
293 * @brief a static function to get
294 * the instance main window style sheet
295 */
296 static QString styleSheet();
297
298public slots:
299 /**
300 * @brief Called when the user wants to close the application.
301 * @return Returning false prevents the window from being closed but the Perspective will have to
302 * implement its own way of closing the application.
303 */
304 virtual bool terminated() {
305 return true;
306 }
307
308signals:
309 void resetWindowTitle();
310
311protected slots:
312 /**
313 * @brief Call this slot to switch to full screen or windowed mode
314 * @param f is true, switch to full screen mode. If false, switch to windowed mode
315 */
316 void showFullScreen(bool f);
317
318 /**
319 * @brief Open a new Tulip Project.
320 * @param path the absolute path of the project file.
321 */
322 virtual void openProjectFile(const QString &path);
323
324 /**
325 * @brief Open a new Perspective without a project.
326 * @param name The name of the Perspective to create.
327 */
328 void createPerspective(const QString &name);
329
330 /**
331 * @brief Show the statusTip (or the toolTip) of an action
332 * @param action a QAction
333 */
334 void showStatusTipOf(QAction *action);
335
336 /**
337 * @brief a virtual function to display a status message
338 */
339 virtual void displayStatusMessage(const QString &s);
340
341 /**
342 * @brief a virtual function to clear the last status message
343 */
344 virtual void clearStatusMessage();
345
346 /**
347 * @brief a virtual function to display the whole logs
348 */
349 virtual void displayLogMessages() {}
350
351 /**
352 * @brief a virtual function to log a message
353 */
354 virtual void logMessage(QtMsgType, const QMessageLogContext &, const QString &) {}
355};
356Q_DECLARE_OPERATORS_FOR_FLAGS(Perspective::ProgressOptions)
357} // namespace tlp
358
359#endif //_PERSPECTIVE_H
A Perspective is a Tulip plugin that completely re-defines the user interface.
Definition Perspective.h:77
static tlp::Perspective * instance()
virtual void centerPanelsForGraph(tlp::Graph *)
Tells the perspective that the visualizations for a given graph should be centered.
QMainWindow * _mainWindow
The main window on which the perspective should build the GUI.
virtual Graph * currentGraph()
std::string category() const override
A string identifier for a plugin used for categorization purposes.
virtual void start(tlp::PluginProgress *progress)=0
Build the main window GUI and starts the workflow. When this method is called, it means that the Pers...
static void setStyleSheet(QWidget *w)
a static function to set the same style sheet as the instance main window style sheet
TulipProject * _project
The project associated to this perspective. This project can be empty or contain data depending on ho...
static T * typedInstance()
std::string icon() const override
The icon (preferably a thumbnail) of the plugin.
static QString styleSheet()
a static function to get the instance main window style sheet
bool needRestart()
a function to indicate restart
static void redirectStatusTipOfMenu(QMenu *menu)
a static function to enable the redirection of the statusTip or toolTip of menu actions
virtual bool terminated()
Called when the user wants to close the application.
virtual void usage(std::string &usage_str) const
usage Displays a usage message when called from the tulip executable
QString _externalFile
void createPerspective(const QString &name)
Open a new Perspective without a project.
virtual void displayLogMessages()
a virtual function to display the whole logs
static void showStatusMessage(const QString &msg)
a static function to ease the display of status messages
static void showStatusMessage(const std::string &msg)
a static function to ease the display of status messages
void showFullScreen(bool f)
Call this slot to switch to full screen or windowed mode.
bool isReservedPropertyName(QString name)
Checks if the name corresponds to a reserved properties. Perspectives are allowed to reserve graph pr...
virtual void redrawPanels(bool center=false)=0
Tells the perspective that the graph visualizations should be redrawn.
Perspective(const tlp::PluginContext *c)
Constructs a perspective object.
static void showLogMessages()
a static function to display the log messages
QMainWindow * mainWindow() const
virtual void logMessage(QtMsgType, const QMessageLogContext &, const QString &)
a virtual function to log a message
static void showLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
a static function to log a message see qInstallMessageHandler
void registerReservedProperty(QString)
Sets a new property name as registered.
virtual void clearStatusMessage()
a virtual function to clear the last status message
void showStatusTipOf(QAction *action)
Show the statusTip (or the toolTip) of an action.
virtual void openProjectFile(const QString &path)
Open a new Tulip Project.
QVariantMap _parameters
Contains extra parameters that have not been parsed by the overleying system. Those are considered to...
virtual void displayStatusMessage(const QString &s)
a virtual function to display a status message
virtual PluginProgress * progress(ProgressOptions options=ProgressOptions(IsPreviewable|IsStoppable|IsCancellable))
Creates a progress handler and returns it. This method allows lower-level widgets to create top-level...
static void setInstance(tlp::Perspective *)
Called at the beginning of the tulip exe to set the Perspective singleton.
Contains runtime parameters for a plugin.
Top-level interface for plug-ins.
Definition Plugin.h:86
virtual std::string name() const =0
Returns the name of the plug-in, as registered in the Tulip plug-in system. This name must be unique,...
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.
Definition TlpQtTools.h:56