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