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