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