Loading...
Searching...
No Matches
ScaleWidget.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5TerraLib is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 3 of the License,
8or (at your option) any later version.
9
10TerraLib is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License
16along with TerraLib. See COPYING. If not, write to
17TerraLib Team at <terralib-team@terralib.org>.
18*/
19
20/*!
21\file terralib/qt/widgets/canvas/ScaleWidget.h
22
23\brief Contains an implementation of a graphic scale.
24*/
25
26#ifndef __TERRALIB_QT_WIDGETS_INTERNAL_SCALEWIDGET_H
27#define __TERRALIB_QT_WIDGETS_INTERNAL_SCALEWIDGET_H
28
29//TerraLib
30#include "../Config.h"
31
32// Qt
33#include <QFrame>
34
35// STL
36#include <vector>
37
38// Forward Declarations
39class QPixmap;
40class QFont;
41
42/*!
43\brief Returns icons and the respective names for the types of rulers that can be used to present the graphic scale.
44\param[out] icons Generated icons.
45\param[out] typesNames Generated names.
46\param device The device being used.
47\param color The color of the ruler.
48*/
49void GetScalesIcons(QMap<int, QIcon>& icons, QStringList& typesNames, const QPaintDevice* device, const QColor& color);
50
51namespace te
52{
53 namespace qt
54 {
55 namespace widgets
56 {
57 // Forward declaration
58 class MapDisplay;
59
60 /*!
61 \class ScaleWidget
62
63 \brief A widget that shows the graphic scale associated with a display.
64
65 The widget shows the graphic scale being used by some display. You can change some attributes for a customized presentation. Divided in sections you can set the following attributes:
66
67 <ol>
68 <li>The unit to be showed.</li>
69 <li>Header:
70 <ul>
71 <li>Font.</li>
72 <li>Color.</li>
73 <li>Visibility of the intermediary values.</li>
74 </ul>
75 </li>
76 <li>Ruler:
77 <ul>
78 <li>Color.</li>
79 <li>Units per interval.</li>
80 <li>Number of intervals.</li>
81 <li>Height in millimeters.</li>
82 <li>Type of ruler for presentation pourposes.</li>
83 </ul>
84 </li>
85 <li>Footer:
86 <ul>
87 <li>Font.</li>
88 <li>Color.</li>
89 <li>Visibility</li>
90 </ul>
91 </li>
92 </ol>
93
94 The object is divided into three sections: header, ruler and footer. The header shows the values of each interval on the ruler. Ruler is the picture of the ruler itself,
95 and the footer shows the numeric scale showing the scale factor and the unit of measure being used.
96
97 \ingroup widgets
98 */
99 class TEQTWIDGETSEXPORT ScaleWidget : public QFrame
100 {
101 Q_OBJECT
102
103 public:
104 /*!
105 \enum ScaleTypes
106 \brief Defines the different types of rulers we can use to present the graphical scale.
107 */
109 {
110 RULER, //!< As a ruler.
111 DASHED, //!< Alternated rectangles and alternated colors, beginning with a white one.
112 DASHED_BEGIN_BLACK, //!< Alternated rectangles and alternated colors, beginning with a colored one.
113 DOUBLE_DASHED, //!< Alternated rectangles and alternated colors, beginning with a white one, whith two rulers.
114 DOUBLE_DASHED_BEGIN_BLACK, //!< Alternated rectangles and alternated colors, beginning with a colored one, whith two rulers.
115 CUSTOM //!< Customized.
116 };
117
118 /** @name Constructor and destructor methods.
119 * Methods related to instantiation and destruction.
120 */
121 //@{
122
123 /*!
124 \brief Constructor.
125 \param parent The display over what the scale will reflect.
126 \param interactive Turn on / off interaction mode. If /a true you will can change the scale position on the display.
127 */
128 ScaleWidget(MapDisplay* parent, const bool& interactive=false);
129
130 /*!
131 \brief Destuctor.
132 */
134 //@}
135
136 /** @name Public methods
137 * Methods to access the internal attributes of the class.
138 */
139 //@{
140
141 /*!
142 \brief Returns the value of the interaction mode.
143 \return Value of the interaction mode.
144 */
146
147 /*!
148 \brief Returns the value of the color of the header.
149 \return Value of the color of the header.
150 */
151 QColor getHeaderColor() const;
152
153 /*!
154 \brief Returns the value of the color of the ruler.
155 \return Value of the color of the ruler.
156 */
157 QColor getRulerColor() const;
158
159 /*!
160 \brief Returns the value of the color of the footer.
161 \return Value of the color of the footer.
162 */
163 QColor getFooterColor() const;
164
165 /*!
166 \brief Returns the value of the font of the header.
167 \return Value of the font of the header.
168 */
169 QFont getHeaderFont() const;
170
171 /*!
172 \brief Returns the value of the font of the footer.
173 \return Value of the font of the footer.
174 */
175 QFont getFooterFont() const;
176
177 /*!
178 \brief Returns the unit being used to present the graphic scale.
179 \return Unit being used to present the graphic scale.
180 */
181 QString getUnit() const;
182
183 /*!
184 \brief Returns the ruler type being used.
185 \return Ruler type being used.
186 */
187 int getScaleType() const;
188
189 /*!
190 \brief Returns the visibility of the footer section.
191 \return Visibility of the footer section.
192 */
194
195 /*!
196 \brief Returns the visibilty of the intermediary values on the header section.
197 \return Visibilty of the intermediary values on the header section.
198 */
200
201 /*!
202 \brief Returns the number of units used in each gap.
203 \return Number of units used in each gap.
204 */
205 int getUnitsPerGap() const;
206
207 /*!
208 \brief Returns the lenght of the ruler in millimeters.
209 \return Lenght of the ruler in millimeters.
210 */
211 int getRulerHeightMM() const;
212
213 /*!
214 \brief Returns the number of intervals being used by ruler.
215 \return Number of intervals being used by ruler.
216 */
218
219 /*!
220 \brief Changes the current position of the widget, centralizing it in the display.
221 */
223
224 /*!
225 \brief Sets the unit using SRID.
226 \param SRID The display SRID.
227 */
228 void setUnit(const int& SRID);
229 //@}
230
231 public slots:
232
233 /** @name Public slots.
234 * Methods to update the internal attributes of the class, using the signal-slot mechanism of QT.
235 */
236 //@{
237
238 /*!
239 \brief Enable / disable the interaction mode.
240
241 If enabled the user can change the scale position on the MapDisplay.
242
243 \param state True for enabling of the interaction mode, false to disable it.
244 */
245 void setInteractionHandle(const bool& state);
246
247 /*!
248 \brief Updates the scale values.
249
250 This method must be called when the visualized area changes on the display, to the ScaleWidget be adjusted to the new visualized area.
251 */
253
254 /*!
255 \brief Changes the color of the header.
256 \param color The new color to be used.
257 */
258 void setHeaderColor(const QColor& color);
259
260 /*!
261 \brief Changes the color of the ruler.
262 \param color The new color to be used.
263 */
264 void setRulerColor(const QColor& color);
265
266 /*!
267 \brief Changes the color of the footer.
268 \param color The new color to be used.
269 */
270 void setFooterColor(const QColor& color);
271
272 /*!
273 \brief Changes the color of the background.
274
275 The initial background color is set to transparent.
276
277 \param color The new color to be used.
278 */
279 void setBackgroundColor(const QColor& color);
280
281 /*!
282 \brief Changes the font of the header.
283 \param font The new font to be used.
284 */
285 void setHeaderFont(const QFont& font);
286
287 /*!
288 \brief Changes the font of the footer.
289 \param font The new font to be used.
290 */
291 void setFooterFont(const QFont& font);
292
293 /*!
294 \brief Sets the unit of measure to be used by the graphic scale.
295
296 Available units of measure:
297
298 <ul>
299 <li>Meters.</li>
300 <li>Kilometers.</li>
301 <li>Feet.</li>
302 <li>Degrees.</li>
303 </ul>
304
305 \param unit The new unit of measure to be used.
306 */
307 void setUnit(const QString& unit);
308
309 /*!
310 \brief Sets the type of ruler to be presented.
311
312 See the definition of \a ScaleTypes enumeration to see details.
313
314 \param type The new type of ruler to be presented.
315 */
316 void setScaleType(const int& type);
317
318 /*!
319 \brief Enable / disable the visibility of the footer or the \a numeric \a scale.
320 \param visible The new visibility of the footer section.
321 */
322 void setNumericScaleVisble(const bool& visible);
323
324 /*!
325 \brief Enable / disable intermediary values of the header.
326
327 The first and last elements are alaways visible. But the intermediary values can be hidden / showed.
328
329 \param visible \a True if the intermediary values must be showed and \a false otherwise.
330 */
331 void setAllHeaderVisible(const bool& visible);
332
333 /*!
334 \brief Changes the number of units to used per interval.
335
336 \ An unit is a value greater then measure corresponding to 1cm that is a better value to be presented. For example, if the display shows a data in a scale 1 : 2924mt, in the ruler
337 we should use intervals of 3000mt, then each unit represents 3000mts.
338
339 \param units Number of units to be used in each interval.
340 */
341 void setUnitsPerGap(const int& units);
342
343 /*!
344 \brief Updates the heightness of the ruler.
345 \param hMM The new height of the ruler in millimeters.
346 \note The \a hMM parameter must be a value of a measure in millimeters.
347 */
348 void setRulerHeightMM(const int& hMM);
349
350 /*!
351 \brief Updates the number of intervals of the ruler.
352 \param v Number of intervals of the ruler.
353 */
354 void setNumberOfIntervals(const int& v);
355 //@}
356
357 signals:
358
359 /** @name Signals
360 * Signals emmited by the widget.
361 */
362 //@{
363
364 /*!
365 * Signal emmited when the widget is about to be closed.
366 */
368 //@}
369
370 protected:
371
372 /** @name Protected methods
373 * Methods used internally by the object.
374 */
375 //@{
376
377 /*!
378 \brief Recalculates and redraw the graphic scale based on the values of its internal attributes.
379 */
381
382 /*!
383 \brief Reimplementation of the QFrame method.
384 \param event The event generated.
385 */
386 void paintEvent(QPaintEvent* event);
387
388 /*!
389 * \brief Reimplementation of the QFrame method.
390 *
391 * \param event The event generated.
392 */
393 void closeEvent(QCloseEvent *event);
394 //@}
395
396 QPixmap* m_bckGround; //!< Background pixmap.
397 QFont m_footerFont; //!< Font of the footer section.
398 bool m_showNumericScale; //!< Flag for enabling / disabling visibility of the footer section.
399 double m_factor; //!< Factor of scaling being used.
400 QString m_unit; //!< Unit of measure being used.
401 std::vector<double> m_intervals; //!< Values of the intervals in millimeters.
402 std::vector<double> m_values; //!< Values of the intervals in the selected unit of measure.
403 int m_numberOfIntervals; //!< Number of intervals of the ruler.
404 ScaleTypes m_type; //!< Type of the ruler to be presented.
405 QColor m_rulerColor; //!< Color of the ruler section.
406 QColor m_bckGrd; //!< Background color.
407 bool m_interactionEnabled; //!< Flag for enabling / disabling the interactive mode.
408 MapDisplay* m_display; //!< Pointer to the display where to present the widget.
409 QColor m_headerColor; //!< Color of the header section.
410 QFont m_headerFont; //!< Font of the header section.
411 bool m_headerAllVisible; //!< Flag do enabling / disabling of the intermediary values of the header.
412 int m_unitsPerGap; //!< Number of units to be used by each interval.
413 QColor m_footerColor; //!< Color of the footer section.
414 int m_rulerHeightMM; //!< Height of the ruler in millimeters.
415 };
416 }
417 }
418}
419
420#endif //__TERRALIB_QT_WIDGETS_INTERNAL_SCALEWIDGET_H
void GetScalesIcons(QMap< int, QIcon > &icons, QStringList &typesNames, const QPaintDevice *device, const QColor &color)
Returns icons and the respective names for the types of rulers that can be used to present the graphi...
A widget to control the display of a set of layers.
Definition: MapDisplay.h:72
A widget that shows the graphic scale associated with a display.
Definition: ScaleWidget.h:100
QColor m_rulerColor
Color of the ruler section.
Definition: ScaleWidget.h:405
bool getInteractionHandle() const
Returns the value of the interaction mode.
QFont m_footerFont
Font of the footer section.
Definition: ScaleWidget.h:397
QFont m_headerFont
Font of the header section.
Definition: ScaleWidget.h:410
void setFooterColor(const QColor &color)
Changes the color of the footer.
void paintEvent(QPaintEvent *event)
Reimplementation of the QFrame method.
bool getNumericScaleIsVisible() const
Returns the visibility of the footer section.
int m_rulerHeightMM
Height of the ruler in millimeters.
Definition: ScaleWidget.h:414
void updateScaleFactor()
Updates the scale values.
void setHeaderColor(const QColor &color)
Changes the color of the header.
void setHeaderFont(const QFont &font)
Changes the font of the header.
ScaleTypes
Defines the different types of rulers we can use to present the graphical scale.
Definition: ScaleWidget.h:109
@ DOUBLE_DASHED_BEGIN_BLACK
Alternated rectangles and alternated colors, beginning with a colored one, whith two rulers.
Definition: ScaleWidget.h:114
@ DASHED
Alternated rectangles and alternated colors, beginning with a white one.
Definition: ScaleWidget.h:111
@ DOUBLE_DASHED
Alternated rectangles and alternated colors, beginning with a white one, whith two rulers.
Definition: ScaleWidget.h:113
@ DASHED_BEGIN_BLACK
Alternated rectangles and alternated colors, beginning with a colored one.
Definition: ScaleWidget.h:112
void updateScalePosition()
Changes the current position of the widget, centralizing it in the display.
int getScaleType() const
Returns the ruler type being used.
void closeEvent(QCloseEvent *event)
Reimplementation of the QFrame method.
ScaleTypes m_type
Type of the ruler to be presented.
Definition: ScaleWidget.h:404
double m_factor
Factor of scaling being used.
Definition: ScaleWidget.h:399
MapDisplay * m_display
Pointer to the display where to present the widget.
Definition: ScaleWidget.h:408
QColor m_bckGrd
Background color.
Definition: ScaleWidget.h:406
void setInteractionHandle(const bool &state)
Enable / disable the interaction mode.
void setRulerColor(const QColor &color)
Changes the color of the ruler.
void setFooterFont(const QFont &font)
Changes the font of the footer.
void setUnit(const QString &unit)
Sets the unit of measure to be used by the graphic scale.
QColor m_footerColor
Color of the footer section.
Definition: ScaleWidget.h:413
int getUnitsPerGap() const
Returns the number of units used in each gap.
QFont getHeaderFont() const
Returns the value of the font of the header.
QColor getHeaderColor() const
Returns the value of the color of the header.
QColor getFooterColor() const
Returns the value of the color of the footer.
bool m_interactionEnabled
Flag for enabling / disabling the interactive mode.
Definition: ScaleWidget.h:407
QString m_unit
Unit of measure being used.
Definition: ScaleWidget.h:400
int m_numberOfIntervals
Number of intervals of the ruler.
Definition: ScaleWidget.h:403
QColor m_headerColor
Color of the header section.
Definition: ScaleWidget.h:409
bool getAllHeaderIsVisible() const
Returns the visibilty of the intermediary values on the header section.
std::vector< double > m_values
Values of the intervals in the selected unit of measure.
Definition: ScaleWidget.h:402
void setNumberOfIntervals(const int &v)
Updates the number of intervals of the ruler.
void setAllHeaderVisible(const bool &visible)
Enable / disable intermediary values of the header.
bool m_headerAllVisible
Flag do enabling / disabling of the intermediary values of the header.
Definition: ScaleWidget.h:411
ScaleWidget(MapDisplay *parent, const bool &interactive=false)
Constructor.
QString getUnit() const
Returns the unit being used to present the graphic scale.
void setNumericScaleVisble(const bool &visible)
Enable / disable the visibility of the footer or the numeric scale.
void setRulerHeightMM(const int &hMM)
Updates the heightness of the ruler.
void setScaleType(const int &type)
Sets the type of ruler to be presented.
int getNumberOfIntervals() const
Returns the number of intervals being used by ruler.
std::vector< double > m_intervals
Values of the intervals in millimeters.
Definition: ScaleWidget.h:401
void setBackgroundColor(const QColor &color)
Changes the color of the background.
void setUnitsPerGap(const int &units)
Changes the number of units to used per interval.
bool m_showNumericScale
Flag for enabling / disabling visibility of the footer section.
Definition: ScaleWidget.h:398
int m_unitsPerGap
Number of units to be used by each interval.
Definition: ScaleWidget.h:412
QPixmap * m_bckGround
Background pixmap.
Definition: ScaleWidget.h:396
QFont getFooterFont() const
Returns the value of the font of the footer.
void setUnit(const int &SRID)
Sets the unit using SRID.
QColor getRulerColor() const
Returns the value of the color of the ruler.
void redoWidget()
Recalculates and redraw the graphic scale based on the values of its internal attributes.
int getRulerHeightMM() const
Returns the lenght of the ruler in millimeters.
TerraLib.
#define slots
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63