ApplicationController.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/af/ApplicationController.h
22 
23  \brief The base API for controllers of TerraLib applications.
24 */
25 
26 #ifndef __TERRALIB_QT_AF_INTERNAL_APPLICATIONCONTROLLER_H
27 #define __TERRALIB_QT_AF_INTERNAL_APPLICATIONCONTROLLER_H
28 
29 // Terralib
30 #include "../../common/Singleton.h"
31 #include "Config.h"
32 
33 // STL
34 #include <map>
35 #include <set>
36 #include <vector>
37 
38 // Boost
39 //#include <boost/noncopyable.hpp>
40 
41 // Qt
42 #include <QObject>
43 #include <QStringList>
44 #include <QSettings>
45 #include <QColor>
46 
47 // Forward declarations
48 class QAction;
49 class QActionGroup;
50 class QMenu;
51 class QMenuBar;
52 class QToolBar;
53 class QWidget;
54 
55 namespace te
56 {
57  namespace qt
58  {
59  namespace af
60  {
61 // class Project;
62 
63  namespace evt
64  {
65  // Forward declarations
66  struct Event;
67  }
68 
70  {
74  };
75 
76  /*!
77  \class ApplicationController
78 
79  \brief The base API for TerraLib applications.
80 
81  \note Temporally this class is a singleton!
82 
83  \ingroup af
84  */
85  class TEQTAFEXPORT ApplicationController : public QObject//, public te::common::Singleton<ApplicationController>
86  {
87  Q_OBJECT
88 
89  public:
90 
91  /*!
92  \brief Constructor.
93 
94  \param parent The parent object.
95  */
96  ApplicationController(/*QObject* parent = 0*/);
97 
98  /*!
99  \brief Destructor.
100  */
101  virtual ~ApplicationController();
102 
103  /*!
104  \brief It gives access to the controller singleton.
105 
106  \return A pointer to the application singleton.
107 
108  \pre The application must have been initialized before calling this method.
109  */
110 // static ApplicationController& getInstance();
111 
112  /*!
113  \brief Tells wich configuration file to be used by the controller during its initialization.
114 
115  \param configFileName The configuration file name with full path.
116  */
117  virtual void setConfigFile(const std::string& configFileName);
118 
119  /*!
120  \brief Tells the widget to be used as the parent of messages showned in a QMessageBox.
121 
122  \param w The widget to be used as the parent of messages showned in a QMessageBox.
123  */
124  virtual void setMsgBoxParentWidget(QWidget* w);
125 
126  /*!
127  \name Menus and Menubars Management.
128 
129  \brief Register and recover menus and menu bars.
130 
131  The methods \a find will returns a valid object only if it exists in some menu, otherwise the return will be a NULL pointer.
132  The methods \a get ALWAYS returns a valid pointer. If the requested menu or menubar does not exists these funtions will create,
133  register and return the object.
134 
135  \note The identifiers of the menus are the texts presented by menus.
136  \note The search for menus will occurs in ALL OF THE REGISTERED menus and menu bars, including submenus. The correct sintaxe
137  for searchies submenus may be found in the documentation of the findMenu(QString mnuText, QMenu* mnu) method.
138  */
139  //@{
140 
141  /*!
142  \brief Register the toolbar in the list of the known toolbars and dispatch an event.
143 
144  \param id The toolbar identification string.
145  \param bar The toolbar to be registered. The controller will not take the \a bar ownership.
146 
147  \pos An event will be broadcasted to indicate that the toolbar was appended.
148 
149  \exception Exception It throws an exception if a toolbar with the given \a id already exists.
150  */
151  void addToolBar(const QString& id, QToolBar* bar);
152 
153  /*!
154  \brief Register the toolbar in the list of the known toolbars.
155 
156  \param id The toolbar identification string.
157  \param bar The toolbar to be registered. The controller will not take the \a bar ownership.
158 
159  \exception Exception It throws an exception if a toolbar with the given \a id already exists.
160 
161  \todo Rever se este metodo eh necessario ou nao! Talvez possamos viver somente com o addToolBar!
162  */
163  void registerToolBar(const QString& id, QToolBar* bar);
164 
165  /*!
166  \brief Return the toolbar identified by \a id or \a NULL if none is found.
167 
168  \param id The toolbar identification string.
169 
170  \return A toolbar identified by \a id or \a NULL if none is found.
171  */
172  QToolBar* getToolBar(const QString& id) const;
173 
174  /*!
175  \brief Return the list of registered toolbars.
176 
177  \return List of registered ToolBars.
178  */
179  std::vector<QToolBar*> getToolBars() const;
180 
181  /*!
182  \brief Removes the toolbar identified by \a id.
183 
184  \param id Identifier of the tool bar.
185  */
186  void removeToolBar(const QString& id);
187 
188  /*!
189  \brief Register the \a mnu.
190 
191  \param mnu Pointer to the menu to be registered.
192  */
193  void registerMenu(QMenu* mnu);
194 
195  /*!
196  \brief Returns the menu registered with key \a id
197 
198  \param id Indentifier of the menu.
199 
200  \return Menu registered or NULL with there is not one registered with the key \a id.
201  */
202  QMenu* findMenu(const QString& id) const;
203 
204  /*!
205  \brief Returns a menu registered with key \a id.
206 
207  \param id Identifier of menu to be searched.
208 
209  \return The menu registered with the \a id identifier.
210 
211  \note If the menu does not exists, then this function will create it.
212  */
213  QMenu* getMenu(const QString& id);
214 
215  /*!
216  \brief Register the \a bar.
217 
218  \param bar Pointer to the menu bar to be registered.
219  */
220  void registerMenuBar(QMenuBar* bar);
221 
222  /*!
223  \brief Returns the menu bar registered with key \a id
224 
225  \param id Indentifier of the menu bar.
226 
227  \return Menu bar registered or NULL with there is not one registered with the key \a id.
228  */
229  QMenuBar* findMenuBar(const QString& id) const;
230 
231  /*!
232  \brief Returns a menu bar registered with key \a id.
233 
234  \param id Identifier of menu bar to be searched.
235 
236  \return The menu bar registered with the \a id identifier.
237 
238  \note If the menu bar does not exists, then this function will create it.
239  */
240  QMenuBar* getMenuBar(const QString& id) const;
241 
242  /*!
243  \brief Returns the action identified by \a id or NULL if there's not an action identified by \a id.
244 
245  \param id Identifier if the action.
246 
247  \return QAction identified or NULL if could not find one.
248 
249  \note There's a rule to determine \a id. The text of menus and submenus separated by '.' character.
250  */
251  QAction* findAction(const QString& id) const;
252 
253  /*!
254  \brief Returns the action group identified by \a id or NULL if there's not an action group identified by \a id.
255 
256  \param id Identifier of the action group.
257 
258  \return QActionGroup identified or NULL if could not find one.
259  */
260  QActionGroup* findActionGroup(const QString& id) const;
261 
262  //@}
263 
264  /*!
265  \brief Insert an application item that will listen to framework events.
266 
267  \param obj The application item that will listen to framework events.
268 
269  \note The \a obj MUST HAVE AN IMPLEMENTATION of the slot \a onApplicationTriggered(Event*). If it hasn't, a warning will be sent at run-time.
270 
271  \note If the \a obj was previously registered, nothing will be done.
272  */
273  void addListener(QObject* obj, const ListenerType& type = BOTH);
274 
275  /*!
276  \brief Remove the \a obj from the list of event listeners.
277 
278  \param obj The application item to be removed.
279 
280  \note If the \a obj was not previously registered, nothing will be done.
281  */
282  void removeListener(QObject* obj);
283 
284  /*!
285  \brief Initializes the application framework.
286 
287  The initialization will read the following configurations files (in order):
288  <ul>
289  <li>A main config file, generally called config.xml</li>
290  <li>A user settings file, generally called user_settings.xml<li>
291  </ul>
292 
293  It will start by initializing the available TerraLib modules.
294  This means that applications that uses the application framework,
295  does not need to call TerraLib initialization (TerraLib::getInstance().initialize()) and
296  finalization methods (TerraLib::getInstance().finalize()).
297 
298  \exception Exception It throws an exception if the initialization fails.
299 
300  \note Make sure that the application calls this method BEFORE it uses any TerraLib modules or functions.
301  */
302  virtual void initialize();
303 
304  /*!
305  \brief Load the plugin list and initialize the plugins enabled by the user.
306 
307  The plugin initialization will read a file containing a list of plugins with their addresses.
308  This file is generally called application_plugins.xml.
309 
310  \pre The application must assure that any resource needed by their plugins are ready for use. This
311  means that initialize should be called before initializing the plugins.
312  */
313  virtual void initializePlugins();
314 
315  /*!
316  \brief Initializes the menus for the most recent open projects.
317  */
318  //virtual void initializeProjectMenus();
319 
320  /*!
321  \brief Update the list of recent projects. This is commonly used when there's a new most recent project.
322 
323  \param prj_file Complete file name for the project file.
324 
325  \param prj_title Title of the project.
326  */
327  //void updateRecentProjects(const QString& prjFile, const QString& prjTitle);
328 
329  /*!
330  \brief Set the current project.
331 
332  \param prj Pointer to a current project.
333 
334  */
335 // void set(te::qt::af::Project* prj);
336 
337  /*!
338  \brief Get the current project.
339 
340  \return Pointer to a current project if defined or a null pointer in other case.
341 
342  */
343 // te::qt::af::Project* getProject();
344 
345  /*!
346  \brief Finalize the application framework.
347 
348  \details This method will unload all TerraLib modules, plugins, and dynamic libraries that are loaded.
349 
350  \note Make sure that the application calls this method BEFORE it finishes.
351  */
352  virtual void finalize();
353 
354  /*!
355  \brief Return the QSettings of the application. This can be used to add settings from external sources.
356 
357  \return QSettings being used.
358  */
359  QSettings& getSettings();
360 
361  public slots:
362 
363  /*!
364  \brief Send events in broadcast for all registered components.
365 
366  \param evt Event to be sent.
367  */
368 // void broadcast(te::qt::af::evt::Event* evt);
369 
370  signals:
371 
372  /*!
373  \brief Signal emmited to the aplication framework listeners.
374  */
375  void triggered(te::qt::af::evt::Event*);
376 
377  public:
378 
379 
380  void trigger(te::qt::af::evt::Event*);
381 
382  /*!
383  \brief Returns the application name.
384 
385  \return Application name.
386  */
387  const QString& getAppName() const;
388 
389  /*!
390  \brief Returns the application title.
391 
392  \return Application title.
393  */
394  const QString& getAppTitle() const;
395 
396  /*!
397  \brief Returns the application project extension.
398 
399  \return Application project extension.
400  */
401  //const QString& getAppProjectExtension() const;
402 
403  const QString& getAboutLogo() const;
404 
405  const QString& getTlibLogo() const;
406 
407  /*!
408  \brief Returns the application icon.
409 
410  \return Application icon.
411  */
412  const QString& getAppIconName() const;
413 
414  /*!
415  \brief Returns the plugins file path of application.
416 
417  \return A path of plugins file.
418  */
419  const QString& getAppPluginsPath() const;
420 
421  /*!
422  \brief Returns the most recent project.
423 
424  \return Application most recent opened project.
425  */
426  //QString getMostRecentProject() const;
427 
428  /*!
429  \brief Returns the application default SRID value.
430 
431  \return Application default SRID value.
432  */
433  int getDefaultSRID() const;
434 
435  /*!
436  \brief Returns the application selection color.
437 
438  \return Application selection color.
439  */
440  QColor getSelectionColor() const;
441 
442  /*! \brief Sets the application selection color. */
443  void setSelectionColor(const QColor& c);
444 
445  /*!
446  \brief Returns main window.
447 
448  \return The main window pointer.
449  */
450  QWidget* getMainWindow() const;
451 
452  void setResetTerraLibFlag(const bool& status);
453 
454  const QString& getUserDataDir() const;
455 
456  protected:
457 
458  std::map<QString, QToolBar*> m_toolbars; //!< Toolbars registered.
459  std::vector<QMenu*> m_menus; //!< Menus registered.
460  std::vector<QMenuBar*> m_menuBars; //!< Menu bars registered.
461  std::set<QObject*> m_applicationItems; //!< The list of registered application items.
462  QWidget* m_msgBoxParentWidget; //!< Parent used to show message boxes.
463  std::string m_appConfigFile; //!< The application framework configuration file.
464  QString m_userDataDir; //!< The data dir used to store data files.
465  QString m_appOrganization; //!< Organization name.
466  QString m_appName; //!< Application name.
467  QString m_appTitle; //!< Application title.
468  //QString m_appProjectExtension; //!< Application project extension.
469  QString m_appIconName; //!< Icon used in the application.
470  QString m_aboutLogo;
471  QString m_tLibLogo;
472  //QStringList m_recentProjs; //!< List of the recent projects.
473  //QStringList m_recentProjsTitles; //!< List of the titles of the recent projects.
474  std::string m_appUserSettingsFile; //!< Name of the user settings file.
475  QString m_appPluginsPath; //!< Name of the plugins path.
476  QString m_appHelpFile; //!< Name of the help file.
477  QString m_appIconThemeDir; //!< Directory of the application icon theme.
478  QString m_appDefaultIconTheme; //!< Name of the icon theme to be used.
479  QString m_appToolBarDefaultIconSize; //!< Size of the tool buttons.
480  std::string m_appDatasourcesFile; //!< Name of the file containing datasources used.
481  int m_defaultSRID; //!< Default SRID value.
482  QColor m_selectionColor; //!< Default selection color.
483 
484  bool m_initialized; //!< A flag indicating if the controller is initialized.
485 
486 // Project* m_project; //!< Pointer to current project.
487 
488  QSettings m_appSettings;
489 
491 
492  };
493 
494  class TEQTAFEXPORT AppCtrlSingleton: public te::common::Singleton<ApplicationController>
495  {
496  };
497  } // end namespace af
498  } // end namespace qt
499 } // end namespace te
500 
501 #endif // __TERRALIB_QT_AF_INTERNAL_APPLICATIONCONTROLLER_H
502 
std::string m_appUserSettingsFile
Name of the user settings file.
std::set< QObject * > m_applicationItems
The list of registered application items.
QString m_appIconName
Icon used in the application.
A base class for application events.
Definition: Event.h:59
QColor m_selectionColor
Default selection color.
The base API for TerraLib applications.
std::map< QString, QToolBar * > m_toolbars
Toolbars registered.
Configuration flags for the TerraLib Application Framework.
QString m_appPluginsPath
Name of the plugins path.
QString m_appTitle
Application title.
std::vector< QMenu * > m_menus
Menus registered.
QWidget * m_msgBoxParentWidget
Parent used to show message boxes.
URI C++ Library.
std::string m_appConfigFile
The application framework configuration file.
QString m_appHelpFile
Name of the help file.
#define TEQTAFEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:71
std::string m_appDatasourcesFile
Name of the file containing datasources used.
QString m_appToolBarDefaultIconSize
Size of the tool buttons.
QString m_appIconThemeDir
Directory of the application icon theme.
QString m_appDefaultIconTheme
Name of the icon theme to be used.
std::vector< QMenuBar * > m_menuBars
Menu bars registered.
QString m_appOrganization
Organization name.
bool m_initialized
A flag indicating if the controller is initialized.
Template support for singleton pattern.
Definition: Singleton.h:100
QString m_userDataDir
The data dir used to store data files.