All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 QtUtils.h
22 
23  \brief This file contains utility functions for dealing with Qt controls.
24  */
25 
26 #ifndef __TERRALIB_QTWIDGETS_INTERNAL_UTILS_H
27 #define __TERRALIB_QTWIDGETS_INTERNAL_UTILS_H
28 
29 // TerraLib
30 #include "../../color/RGBAColor.h"
31 #include "../../geometry/Enums.h"
32 #include "../../maptools/Enums.h"
33 #include "Config.h"
34 #include "Globals.h"
35 
36 // Qt
37 #include <QtCore/QObject>
38 #include <QtGui/QColor>
39 #include <QtGui/QPixmap>
40 
41 // Forward declarations
42 class QAction;
43 class QImage;
44 class QMenu;
45 class QMenuBar;
46 class QTreeWidgetItem;
47 
48 namespace te
49 {
50  namespace map
51  {
52  class Canvas;
53  }
54 
55  namespace qt
56  {
57  namespace widgets
58  {
59  /*!
60  \brief It sets the check state for the children of a item.
61  */
62  TEQTWIDGETSEXPORT void SetChildrenCheckState(QTreeWidgetItem* item, int column, Qt::CheckState state);
63 
64  /*!
65  \brief It returns the file format as a NULL terminated string.
66 
67  \return The file format as a NULL terminated string.
68  */
69  inline const char* GetFormat(te::map::ImageType t)
70  {
71  switch(t)
72  {
73  case te::map::PNG:
74  return Globals::sm_pngFmt;
75 
76  case te::map::JPEG:
77  return Globals::sm_jpegFmt;
78 
79  case te::map::GIF:
80  return Globals::sm_gifFmt;
81 
82  case te::map::BMP:
83  return Globals::sm_bmpFmt;
84 
85  case te::map::XPM:
86  return Globals::sm_xpmFmt;
87 
88  case te::map::XBM:
89  return Globals::sm_xbmFmt;
90 
91  default:
93  };
94  }
95 
96  /*!
97  \brief It creates a QImage from an RGBA color array.
98 
99  \param img Image - a square matrix of int's where each position corresponds to a RGBA color.
100  \param width The image width.
101  \param height The image height.
102 
103  \return A pointer to a QImage.
104 
105  \note The caller of this method will take the ownership of the returned pointer.
106  */
107  TEQTWIDGETSEXPORT QImage* GetImage(te::color::RGBAColor** img, int width, int height);
108 
109  /*!
110  \brief It creates a RGBA color array from a QImage.
111 
112  \param img QImage that will be converted.
113 
114  \return Image - a square matrix of int's where each position corresponds to a RGBA color.
115 
116  \note The caller of this method will take the ownership of the returned pointer.
117  */
119 
120  /*!
121  \brief Finds a menu item in the \a mnu object.
122 
123  Use this function to find menus and submenus. There is a sintaxe that is for required sub-menus. Use the names separated by \".\" character,
124  e.g to return a menu named \"Layers\" inside another menu named \"Add\" calls this function using "Add.Layers" as the value of the
125  \a mnuText argument.
126 
127  \note Pay attention on the translations.
128 
129  \param mnuText Name of the QMenu searched.
130 
131  \param mnu The menu where the submenu must be searched.
132 
133  \return The pointer to the QMenu object or NULL if it do not exists.
134  */
135  TEQTWIDGETSEXPORT QMenu* FindMenu(const QString& mnuText, QMenu* mnu);
136 
137  /*!
138  \overload QMenu* findMenu(const QString& mnuText, QMenuBar* bar)
139 
140  The difference for the above function is that this will search in all QMenu objects contained in the \a bar.
141  */
142  TEQTWIDGETSEXPORT QMenu* FindMenu(const QString& mnuText, QMenuBar* bar);
143 
144  /*!
145  \brief Gets a menu or submenu contained in the \a mnu object.
146 
147  This function searches by the menu exactly as the FindMenu function. The difference is that if the menu do not exists,
148  this function will create it, in all levels that may be required. Use the syntax described above to the search / create the submenus desired.
149 
150  \param mnuText Name of the menu. (This will be used as texts of the menus.)
151 
152  \param mnu The menu that will used in search.
153 
154  \return A pointer to a QMenu object.
155  */
156  TEQTWIDGETSEXPORT QMenu* GetMenu(const QString& mnuText, QMenu* mnu);
157 
158  /*!
159  \overload QMenu* getMenu(const QString& mnuText, QMenuBar* bar)
160 
161  The difference for the above function is that it will search in all QMenu objects contained in the \a bar.
162  */
163  TEQTWIDGETSEXPORT QMenu* GetMenu(const QString& mnuText, QMenuBar* bar);
164 
165  /*!
166  \brief
167 
168  \param
169  \param
170 
171  \return
172  */
173  TEQTWIDGETSEXPORT QAction* FindAction(const QString& actText, QMenu* mnu);
174 
175  /*!
176  \brief
177 
178  \param
179  \param
180 
181  \return
182  */
183  TEQTWIDGETSEXPORT QAction* FindAction(const QString& actText, QMenuBar* mnuBar);
184 
185  /*!
186  \brief It converts a Qt Color to TerraLib Color.
187 
188  \param color The Qt Color that will be converted.
189  */
191 
192  /*!
193  \brief It converts a TerraLib Color to Qt Color.
194 
195  \param color The TerraLib Color that will be converted.
196  */
198 
199  /*!
200  \brief It configs (i.e. prepares) the given canvas to draw polygons.
201 
202  \param canvas The canvas that will be configured. Do not pass NULL!
203  \param fillColor The color that will be used to fill the polygons.
204  \param contourColor The color that will be used to contour the polygons.
205  \param contourWidth The width that will be used to contour the polygons.
206  */
207  TEQTWIDGETSEXPORT void Config2DrawPolygons(te::map::Canvas* canvas, const QColor& fillColor, const QColor& contourColor, const std::size_t& contourWidth = 1);
208 
209  /*!
210  \brief It configs (i.e. prepares) the given canvas to draw lines.
211 
212  \param canvas The canvas that will be configured. Do not pass NULL!
213  \param color The color that will be used to draw the lines.
214  \param width The width that will be used to draw the lines.
215  */
216  TEQTWIDGETSEXPORT void Config2DrawLines(te::map::Canvas* canvas, const QColor& color, const std::size_t& width = 1);
217 
218  /*!
219  \brief It configs (i.e. prepares) the given canvas to draw points.
220 
221  \param canvas The canvas that will be configured. Do not pass NULL!
222  \param color The color that will be used to draw the points.
223  \param width The width that will be used to draw the points.
224  */
225  TEQTWIDGETSEXPORT void Config2DrawPoints(te::map::Canvas* canvas, const QColor& color, const std::size_t& width = 1);
226 
227  /*!
228  \brief It configs (i.e. prepares) the given canvas to draw points.
229 
230  \param canvas The canvas that will be configured. Do not pass NULL!
231  \param markName The mark name that will be used to draw the points.
232  \param size The size that will be used to draw the points.
233  \param fillColor The color that will be used to fill the mark.
234  \param contourColor The color that will be used to contour the mark.
235  \param contourWidth The width that will be used to contour the mark.
236  */
237  TEQTWIDGETSEXPORT void Config2DrawPoints(te::map::Canvas* canvas, const QString& markName, const std::size_t& size,
238  const QColor& fillColor, const QColor& contourColor, const std::size_t& contourWidth = 1);
239 
240  /*!
241  \brief It configs (i.e. prepares) the given canvas to draw a layer selection.
242 
243  \param canvas The canvas that will be configured. Do not pass NULL!
244  \param selectionColor The color that will be used to draw the selection.
245  \param type The geometry type that will be drawn.
246  */
247  TEQTWIDGETSEXPORT void Config2DrawLayerSelection(te::map::Canvas* canvas, const QColor& selectionColor, const te::gm::GeomType& type);
248 
249  /*!
250  \brief It creates a pixmap to use as icon (to be used as legend icon).
251 
252  \param size The height and width for the pixmap.
253  \param penColor The color that will be used to set the pen.
254  \param brushColor The color that will be used to set the brush.
255  \param contourSize The countour size.
256  */
257  TEQTWIDGETSEXPORT QPixmap CreatePixmapIcon(const int& size, const QColor& penColor, const QColor& brushColor, const int& contourSize);
258 
259  /*!
260  \brief Save last used path in QSettings.
261 
262  \param path The path to last used file.
263 
264  \param typeFile The type of file opened. Actually we assume three values: "vector", "raster", "database". Any other value may be not used in the system.
265 
266  \note The params are case sensitive. It means that a "Vector" value for the argument \a typeFile is unkowned by application.
267  */
268  TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString& path, const QString& typeFile);
269 
270  /*!
271  \brief Returns the value of the last saved file path for the \a typeFile required.
272 
273  \param typeFile The type of file opened. Actually we assume three values: "vector", "raster", "database". Any other value may be not used in the system.
274 
275  \return The path if encountered or a null QString.
276  */
277  TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString& typeFile);
278 
279  } // end namespace widgets
280  } // end namespace qt
281 } // end namespace te
282 
283 #endif // __TERRALIB_QTWIDGETS_INTERNAL_UTILS_H
static const char * sm_pngFmt
Definition: Globals.h:52
TEQTWIDGETSEXPORT void Config2DrawLines(te::map::Canvas *canvas, const QColor &color, const std::size_t &width=1)
It configs (i.e. prepares) the given canvas to draw lines.
Definition: Utils.cpp:230
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:101
TEQTWIDGETSEXPORT te::color::RGBAColor Convert2TerraLib(const QColor &color)
It converts a Qt Color to TerraLib Color.
Definition: Utils.cpp:211
static const char * sm_xbmFmt
Definition: Globals.h:57
static const char * sm_unknownFmt
Definition: Globals.h:58
static const char * sm_bmpFmt
Definition: Globals.h:55
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString &typeFile)
Returns the value of the last saved file path for the typeFile required.
Definition: Utils.cpp:360
Configuration flags for the TerraLib Qt Widgets.
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
Definition: Utils.cpp:351
TEQTWIDGETSEXPORT QAction * FindAction(const QString &actText, QMenu *mnu)
Definition: Utils.cpp:131
ImageType
This enum specifies the possible input and output image formats supported by the canvas API...
Definition: Enums.h:38
TEQTWIDGETSEXPORT QPixmap CreatePixmapIcon(const int &size, const QColor &penColor, const QColor &brushColor, const int &contourSize)
It creates a pixmap to use as icon (to be used as legend icon).
Definition: Utils.cpp:324
static const char * sm_xpmFmt
Definition: Globals.h:56
static const char * sm_jpegFmt
Definition: Globals.h:53
TEQTWIDGETSEXPORT void SetChildrenCheckState(QTreeWidgetItem *item, int column, Qt::CheckState state)
It sets the check state for the children of a item.
Definition: Utils.cpp:48
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
TEQTWIDGETSEXPORT QMenu * GetMenu(const QString &mnuText, QMenu *mnu)
Gets a menu or submenu contained in the mnu object.
Definition: Utils.cpp:176
const char * GetFormat(te::map::ImageType t)
It returns the file format as a NULL terminated string.
Definition: Utils.h:69
static const char * sm_gifFmt
Definition: Globals.h:54
TEQTWIDGETSEXPORT void Config2DrawPoints(te::map::Canvas *canvas, const QColor &color, const std::size_t &width=1)
It configs (i.e. prepares) the given canvas to draw points.
Definition: Utils.cpp:236
TEQTWIDGETSEXPORT QColor Convert2Qt(const te::color::RGBAColor &color)
It converts a TerraLib Color to Qt Color.
Definition: Utils.cpp:216
TEQTWIDGETSEXPORT void Config2DrawLayerSelection(te::map::Canvas *canvas, const QColor &selectionColor, const te::gm::GeomType &type)
It configs (i.e. prepares) the given canvas to draw a layer selection.
Definition: Utils.cpp:264
TEQTWIDGETSEXPORT void Config2DrawPolygons(te::map::Canvas *canvas, const QColor &fillColor, const QColor &contourColor, const std::size_t &contourWidth=1)
It configs (i.e. prepares) the given canvas to draw polygons.
Definition: Utils.cpp:223
TEQTWIDGETSEXPORT QMenu * FindMenu(const QString &mnuText, QMenu *mnu)
Finds a menu item in the mnu object.
Definition: Utils.cpp:121
TEQTWIDGETSEXPORT QImage * GetImage(te::color::RGBAColor **img, int width, int height)
It creates a QImage from an RGBA color array.
Definition: Utils.cpp:63