Tulip  5.1.0
Large graphs analysis and drawing
Perspective.h
1 /*
2  *
3  * This file is part of Tulip (http://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 
32 class QMainWindow;
33 class QTcpSocket;
34 
35 namespace tlp {
36 
37 class PluginProgress;
38 class TulipProject;
39 
40 static const std::string PERSPECTIVE_CATEGORY = "Perspective";
41 
42 /**
43  * @ingroup Plugins
44  * @brief A context data structure for tlp::Perspective instances.
45  *
46  * @see tlp::Perspective
47  */
48 class TLP_QT_SCOPE PerspectiveContext : public tlp::PluginContext {
49 public:
50  PerspectiveContext(): mainWindow(0), project(0), tulipPort(0) {}
51  QMainWindow *mainWindow;
52  TulipProject *project;
53  QString externalFile;
54  QVariantMap parameters;
55  quint64 tulipPort;
56  unsigned int id;
57 };
58 
59 /**
60  * @ingroup Plugins
61  * @brief A Perspective is a Tulip plugin that completely re-defines the user interface.
62  *
63  * A Perspective aims at using the multiple features available in Tulip to create a complete, coherent workflow dedicated to a particular use-case.
64  * Perspectives are chosen by the user when first running the Tulip agent. The main perspective is called "Tulip". This perspective unveils all the Tulip features and aims at being a protyping and researching platform.
65  *
66  * A Perspective always acts in its own process and communicate with the Tulip agent via TCP sockets.
67  * Thus, it is the Perspective's responsibility to offer the possibility to display graphs, run plugins, etc. A lot of helper classes can be found into the tulip-gui API like pre-made widgets, Qt models, etc.
68  *
69  * Perspective's data is stored into a TulipProject. A TulipProject is an archive capable of containing heterogeneous data (like multiple graphs, textures, extra files, etc). When a TulipProject gets saved by a perspective, it is linked to it in its meta-information.
70  * Creating a Perspective primarily into implementing the start() method that builds the GUI. This method will be called by the overleying system when a new perspective is launched. The rest of the logic implementation is left to the developer.
71  */
72 class TLP_QT_SCOPE Perspective : public QObject, public tlp::Plugin {
73  Q_OBJECT
74 
75  static tlp::Perspective* _instance;
76  QSet<QString> _reservedProperties;
77  QTcpSocket* _agentSocket;
78  unsigned int _perspectiveId;
79  bool _maximised;
80  void sendAgentMessage(const QString&);
81  void notifyProjectLocation(const QString& path);
82 
83 
84 protected:
85  /**
86  * @brief The project associated to this perspective. This project can be empty or contain data depending on how the Perspective was launched:
87  * To launch a perspective, the tulip_perspective executable is called with the following arguments:
88  * @code
89  * tulip_perspective [--perspective=Name] [file_path]
90  * @endcode
91  * @list
92  * @li The --perspective argument forces Tulip to start the "Name" perspective. Even if the project states otherwise. If this argument is not specified, Tulip will look in the project's meta-data to dertermine the perspective to launch.
93  * @li file_path is the absolute path of the project archive to associate with the perspective. If file_path is not given, the --perspective argument must be declared in order for Tulip to know what perspective to launch. In this case, _project will point to an empty (but valid!) project.
94  * @endlist
95  */
97 
98  /**
99  * @brief The main window on which the perspective should build the GUI.
100  *
101  * It is not the Perspective's responsibility to destroy the main window when the application gets closed. Generally speaking, destorying the _mainWindow pointer could lead to undefined behavior.
102  */
103  QMainWindow *_mainWindow;
104 
105  /**
106  * If the user provided a file to the tulip_perspective but this file is not recognized as a valid TulipProject, the full path of the file will be stored into the _externalFile member.
107  * @note Remember that perspectives should always store their data into TulipProject in order to keep a consistent workflow.
108  */
109  QString _externalFile;
110 
111  /**
112  * @brief Contains extra parameters that have not been parsed by the overleying system. Those are considered to be Perspective-specific and are forwarded into this variable.
113  */
114  QVariantMap _parameters;
115  bool checkSocketConnected();
116 
117 public:
118  enum ProgressOption {
119  NoProgressOption = 0x0,
120  IsPreviewable = 0x1,
121  IsCancellable = 0x2,
122  IsStoppable = 0x4
123  };
124  Q_DECLARE_FLAGS(ProgressOptions,ProgressOption)
125 
126  virtual std::string category() const {
127  return PERSPECTIVE_CATEGORY;
128  }
129  std::string icon() const {
130  return ":/tulip/gui/icons/32/plugin_controller.png";
131  }
132 
133  /**
134  * @brief Called at the beginning of the tulip_perspective to set the Perspective singleton.
135  * @see instance()
136  */
137  static void setInstance(tlp::Perspective*);
138 
139  /**
140  * Since a Perspective has its own process to work in, there can be only one perspective instance by process.
141  * In order to ease the development process, Perspective are available as a singleton in order for child widgets and plugins to be able to access to the features of a Perspective.
142  * This architecture was added for developers who want to create an application containing several plugins grouped into Perspective.
143  * @return The perspective singleton
144  */
145  static tlp::Perspective* instance();
146 
147  /**
148  * @return A typed instance of the perspective singleton.
149  */
150  template<typename T>
151  static T* typedInstance() {
152  return dynamic_cast<T*>(instance());
153  }
154 
155  /**
156  * @brief Constructs a perspective object
157  * @warning There should not be any logic implemented into the Perspective's constructor. See the start method instead.
158  */
160  virtual ~Perspective();
161 
162  /**
163  * @brief Build the main window GUI and starts the workflow.
164  * When this method is called, it means that the Perspective is reponsible of the application workflow until the application is closed by the user.
165  * @param progress A progress handler
166  */
167  virtual void start(tlp::PluginProgress* progress)=0;
168 
169  /**
170  * @brief Creates a progress handler and returns it.
171  * This method allows lower-level widgets to create top-level progress bars directly from the Perspective.
172  * @return
173  */
174  virtual PluginProgress *progress(ProgressOptions options = ProgressOptions(IsPreviewable | IsStoppable | IsCancellable));
175 
176  /**
177  * @return The Perspective's main window.
178  */
179  QMainWindow* mainWindow() const;
180 
181  /**
182  * @brief Checks if the name corresponds to a reserved properties.
183  * Perspectives are allowed to reserve graph properties. A reserved graph properties is a core property that cannot be deleted by the user and cannot be renamed.
184  * @return true if the perspective is registered.
185  */
186  bool isReservedPropertyName(QString name);
187 
188  /**
189  * @brief Sets a new property name as registered
190  */
191  void registerReservedProperty(QString);
192 
193  /**
194  * @brief Tells the perspective that the graph visualizations should be redrawn.
195  * @param center if true, visualization should also be centered (eg. the layout has been changed)
196  */
197  virtual void redrawPanels(bool center=false)=0;
198 
199  /**
200  * @brief Tells the perspective that the visualizations for a given graph should be centered.
201  * @note By default, this method does nothing.
202  */
203  virtual void centerPanelsForGraph(tlp::Graph*);
204 
205  void resetTitle() {
206  emit resetWindowTitle();
207  }
208 
209 
210  /**
211  * @brief a static function to ease the display of messages
212  * on mainWindow()->statusBar()
213  */
214  static void showStatusMessage(const QString&);
215 
216  /**
217  * @brief a static function to ease the display of messages
218  * on mainWindow()->statusBar()
219  */
220  static void showStatusMessage(const std::string& msg) {
221  showStatusMessage(tlp::tlpStringToQString(msg));
222  }
223 
224  /**
225  * @brief a static function to enable the redirection of the statusTip or toolTip of menu actions on mainWindow->statusBar()
226  */
227  static void redirectStatusTipOfMenu(QMenu* menu);
228 
229 public slots:
230  /**
231  * @brief Called when the user wants to close the application.
232  * @return Returning false prevents the window from being closed but the Perspective will have to implement its own way of closing the application.
233  */
234  virtual bool terminated() {
235  return true;
236  }
237 
238 signals:
239  void resetWindowTitle();
240 
241 protected slots:
242  /**
243  * @brief Send a message to the Tulip agent to make him display the Plugins Center page.
244  */
245  void showPluginsCenter();
246 
247  /**
248  * @brief Call this slot to swith to full screen or windowed mode
249  * @param f is true, switch to full screen mode. If false, switch to windowed mode
250  */
251  void showFullScreen(bool f);
252 
253  /**
254  * @brief Send a message to the Tulip agent to make him display the Projects page.
255  */
256  void showProjectsPage();
257 
258  /**
259  * @brief Send a message to the Tulip agent to make him display the "About us" page.
260  */
261  void showAboutPage();
262 
263  /**
264  * @brief Send a message to the Tulip agent to make him display a message in the system notification area.
265  * @param s The message to display.
266  */
267  void showTrayMessage(const QString& s);
268 
269  /**
270  * @brief Send a message to the Tulip agent to make him display an error message that will be shown in the system notification as well as on the welcome page.
271  * @param title The message's title.
272  * @param s The message to display.
273  */
274  void showErrorMessage(const QString& title, const QString& s);
275 
276  /**
277  * @brief Send a message to the Tulip agent to make him open a new Tulip Project.
278  * @param path the absolute path of the project file.
279  */
280  virtual void openProjectFile(const QString& path);
281 
282  /**
283  * @brief Send a message to the Tulip agent to make him open a new Perspective without a project.
284  * @param name The name of the PErspective to create.
285  */
286  void createPerspective(const QString& name);
287 
288  /**
289  * @brief Show the statusTip (or the toolTip) of an action on mainWindow()->statusBar()
290  * @param action a QAction
291  */
292  void showStatusTipOf(QAction* action);
293 };
294 Q_DECLARE_OPERATORS_FOR_FLAGS(Perspective::ProgressOptions)
295 
296 }
297 
298 #endif //_PERSPECTIVE_H
QVariantMap _parameters
Contains extra parameters that have not been parsed by the overleying system. Those are considered to...
Definition: Perspective.h:114
QMainWindow * _mainWindow
The main window on which the perspective should build the GUI.
Definition: Perspective.h:103
std::string icon() const
The icon (preferably a thumbnail) of the plugin.
Definition: Perspective.h:129
QString _externalFile
Definition: Perspective.h:109
The TulipProject object handles the content of a Tulip project.
Definition: TulipProject.h:71
TulipProject * _project
The project associated to this perspective. This project can be empty or contain data depending on ho...
Definition: Perspective.h:96
virtual bool terminated()
Called when the user wants to close the application.
Definition: Perspective.h:234
Contains runtime parameters for a plugin.
Definition: PluginContext.h:39
static T * typedInstance()
Definition: Perspective.h:151
A context data structure for tlp::Perspective instances.
Definition: Perspective.h:48
Top-level interface for plug-ins.
Definition: Plugin.h:79
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
A Perspective is a Tulip plugin that completely re-defines the user interface.
Definition: Perspective.h:72
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.
Definition: TlpQtTools.h:54
static void showStatusMessage(const std::string &msg)
a static function to ease the display of messages on mainWindow()->statusBar()
Definition: Perspective.h:220