ScalePropertyWidget.cpp
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/widgets/canvas/ScalePropertyWidget.cpp
22 */
23 
24 #include "ScalePropertyWidget.h"
25 #include "ScaleWidget.h"
26 
27 // TerraLib
28 #include "../propertybrowser/AbstractPropertyManager.h"
29 
30 // Qt
31 #include <QLayout>
32 
33 
35 QDockWidget(nullptr),
36 m_editAction(editScale),
37  m_scaleStatus(true)
38 {
39  QWidget* w = new QWidget(this);
40 
41  QtTreePropertyBrowser* pb = new QtTreePropertyBrowser(w);
42  pb->setPropertiesWithoutValueMarked(true);
43  pb->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
44 
45  new ScalePropertyBrowser(pb, wid);
46 
47  QGridLayout* lay = new QGridLayout(w);
48  lay->addWidget(pb);
49 
50  setWidget(w);
51 
52  connect(wid, SIGNAL(aboutToBeclosed()), SLOT(scaleWidgetClosed()));
53 
54  setAttribute(Qt::WA_DeleteOnClose, true);
55 
56  m_editAction->setEnabled(false);
57 }
58 
60 {
61  m_editAction->setEnabled(m_scaleStatus);
62 }
63 
65 {
66  m_scaleStatus = false;
67  close();
68 }
69 
70 
72 te::qt::widgets::AbstractPropertyItem(pb)
73 {
74  QMap<int, QIcon> ics;
75  QStringList ics_names;
76  QStringList units;
77 
78  units << tr("Degrees")
79  << tr("Kilometers")
80  << tr("Meters")
81  << tr("Feet");
82 
83  GetScalesIcons(ics, ics_names, wid, wid->getRulerColor());
84 
85  QtProperty* scale_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Scale properties"));
86 
87  QtProperty* header_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Header properties"));
88  QtProperty* ruler_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Ruler properties"));
89  QtProperty* footer_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Footer properties"));
90 
91 
92  // Properties of header
93  // ===================
94  // Intermediary values visible
95  QtProperty* visAll_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_boolManager->addProperty(tr("Intermediary values visible"));
96  te::qt::widgets::AbstractPropertyManager::getInstance().m_boolManager->setValue(visAll_prop, wid->getAllHeaderIsVisible());
97  header_prop->addSubProperty(visAll_prop);
98 
99  // font
100  QtProperty* hfont_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->addProperty(tr("Header font"));
101  te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->setValue(hfont_prop, wid->getHeaderFont());
102  header_prop->addSubProperty(hfont_prop);
103 
104  // color
105  QtProperty* hcolor_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->addProperty(tr("Header color"));
106  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(hcolor_prop, wid->getHeaderColor());
107  header_prop->addSubProperty(hcolor_prop);
108  // ===================
109 
110  // Properties of ruler
111  // ===================
112  // Height in millimeters
113  QtProperty* width_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->addProperty(tr("Height in millimeters"));
114  te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->setValue(width_prop, wid->getRulerHeightMM());
115  te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->setMinimum(width_prop, 1);
116  ruler_prop->addSubProperty(width_prop);
117 
118  // Intervals
119  QtProperty* intervals_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->addProperty(tr("Number of intervals"));
120  te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->setValue(intervals_prop, wid->getNumberOfIntervals());
121  te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->setMinimum(intervals_prop, 1);
122  ruler_prop->addSubProperty(intervals_prop);
123 
124  // Units per gap
125  QtProperty* unitsPerGap_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->addProperty(tr("Units per gap"));
126  te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->setValue(unitsPerGap_prop, wid->getUnitsPerGap());
127  te::qt::widgets::AbstractPropertyManager::getInstance().m_intManager->setMinimum(unitsPerGap_prop, 1);
128  ruler_prop->addSubProperty(unitsPerGap_prop);
129 
130  // color
131  QtProperty* rulerColor_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->addProperty(tr("Ruler color"));
132  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(rulerColor_prop, wid->getRulerColor());
133  ruler_prop->addSubProperty(rulerColor_prop);
134 
135  // scale type
136  QtProperty* type_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->addProperty(tr("Scale type"));
137  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setEnumIcons(type_prop, ics);
138  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setEnumNames(type_prop, ics_names);
139  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setValue(type_prop, wid->getScaleType());
140  ruler_prop->addSubProperty(type_prop);
141  // ===================
142 
143  // Properties of footer
144  // ===================
145  // numeric scale visible
146  QtProperty* num_vis_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_boolManager->addProperty(tr("Numeric scale visible"));
147  te::qt::widgets::AbstractPropertyManager::getInstance().m_boolManager->setValue(num_vis_prop, wid->getNumericScaleIsVisible());
148  footer_prop->addSubProperty(num_vis_prop);
149 
150  // font
151  QtProperty* ffont_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->addProperty(tr("Footer font"));
152  te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->setValue(ffont_prop, wid->getFooterFont());
153  footer_prop->addSubProperty(ffont_prop);
154 
155  // color
156  QtProperty* fcolor_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->addProperty(tr("Footer color"));
157  te::qt::widgets::AbstractPropertyManager::getInstance().m_colorManager->setValue(fcolor_prop, wid->getFooterColor());
158  footer_prop->addSubProperty(fcolor_prop);
159  // ===================
160 
161  // unit
162  QtProperty* unit_prop = te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->addProperty(tr("Unit"));
163  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setEnumNames(unit_prop, units);
164  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setValue(unit_prop, units.indexOf(wid->getUnit()));
165 
166  scale_prop->addSubProperty(unit_prop);
167  scale_prop->addSubProperty(header_prop);
168  scale_prop->addSubProperty(ruler_prop);
169  scale_prop->addSubProperty(footer_prop);
170 
171  addProperty(scale_prop, tr("Scale"), QColor(175, 255, 175));
172 
173  wid->connect(this, SIGNAL(interactHandleChanged(const bool&)), SLOT(setInteractionHandle(const bool&)));
174 
175  wid->connect(this, SIGNAL(headerColorChanged(const QColor&)), SLOT(setHeaderColor(const QColor&)));
176  wid->connect(this, SIGNAL(rulerColorChanged(const QColor&)), SLOT(setRulerColor(const QColor&)));
177  wid->connect(this, SIGNAL(footerColorChanged(const QColor&)), SLOT(setFooterColor(const QColor&)));
178 
179  wid->connect(this, SIGNAL(headerFontChanged(const QFont&)), SLOT(setHeaderFont(const QFont&)));
180  wid->connect(this, SIGNAL(footerFontChanged(const QFont&)), SLOT(setFooterFont(const QFont&)));
181 
182  wid->connect(this, SIGNAL(scaleTypeChanged(const int&)), SLOT(setScaleType(const int&)));
183  wid->connect(this, SIGNAL(numericScaleVisibilityChanged(const bool&)), SLOT(setNumericScaleVisble(const bool&)));
184  wid->connect(this, SIGNAL(unitChanged(const QString&)), SLOT(setUnit(const QString&)));
185 
186  wid->connect(this, SIGNAL(allIntermediaryValuesChanged(const bool&)), SLOT(setAllHeaderVisible(const bool&)));
187  wid->connect(this, SIGNAL(rulerHeightChanged(const int&)), SLOT(setRulerHeightMM(const int&)));
188  wid->connect(this, SIGNAL(numberOfIntervalsChanged(const int&)), SLOT(setNumberOfIntervals(const int&)));
189  wid->connect(this, SIGNAL(unitsPerGapChanged(const int&)), SLOT(setUnitsPerGap(const int&)));
190 }
191 
193 
195 {
196  if (p->propertyName() == tr("Interaction enabled"))
197  emit interactHandleChanged(value);
198  else if (p->propertyName() == tr("Intermediary values visible"))
199  emit allIntermediaryValuesChanged(value);
200  else
201  emit numericScaleVisibilityChanged(value);
202 }
203 
204 void te::qt::widgets::ScalePropertyBrowser::valueChanged(QtProperty* p, const QColor& value)
205 {
206  if (p->propertyName() == tr("Header color"))
207  emit headerColorChanged(value);
208  else if (p->propertyName() == tr("Ruler color"))
209  emit rulerColorChanged(value);
210  else
211  emit footerColorChanged(value);
212 }
213 
214 void te::qt::widgets::ScalePropertyBrowser::valueChanged(QtProperty* p, const QFont& value)
215 {
216  if (p->propertyName() == tr("Header font"))
217  emit headerFontChanged(value);
218  else
219  emit footerFontChanged(value);
220 }
221 
223 {
224  if (p->propertyName() == tr("Unit"))
225  emit unitChanged(p->valueText());
226  else if (p->propertyName() == tr("Height in millimeters"))
227  emit rulerHeightChanged(value);
228  else if (p->propertyName() == tr("Number of intervals"))
229  emit numberOfIntervalsChanged(value);
230  else if (p->propertyName() == tr("Units per gap"))
231  emit unitsPerGapChanged(value);
232  else
233  emit scaleTypeChanged(value);
234 }
QString getUnit() const
Returns the unit being used to present the graphic scale.
A widget that shows the graphic scale associated with a display.
Definition: ScaleWidget.h:99
QFont getFooterFont() const
Returns the value of the font of the footer.
A widget used to define the main property items that can be used to describe a se object...
void unitsPerGapChanged(const int &)
Emmited when the units per interval was changed.
ScalePropertyBrowser(QtTreePropertyBrowser *pb, ScaleWidget *wid)
Constructor.
void numericScaleVisibilityChanged(const bool &)
Emmited when the footer visibility was changed.
Widget with propeties of a ScaleWidget for the users to change the presentation of the graphic scale...
bool m_scaleStatus
Scale widget enabling status.
void rulerColorChanged(const QColor &)
Emmited when the ruler color was changed.
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...
int getScaleType() const
Returns the ruler type being used.
QFont getHeaderFont() const
Returns the value of the font of the header.
QColor getFooterColor() const
Returns the value of the color of the footer.
void footerColorChanged(const QColor &)
Emmited when the footer color was changed.
void unitChanged(const QString &)
Emmited when the unit of measure of the graphic scale was changed.
ScalePropertyWidget(ScaleWidget *wid, QAction *editScale)
Constructor.
void valueChanged(QtProperty *p, bool value)
Called when a property of boolean type changed.
void allIntermediaryValuesChanged(const bool &)
Emmited when the visibility of the intermediary values of the header was changed. ...
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
QColor getHeaderColor() const
Returns the value of the color of the header.
int getUnitsPerGap() const
Returns the number of units used in each gap.
URI C++ Library.
Definition: Attributes.h:37
bool getAllHeaderIsVisible() const
Returns the visibilty of the intermediary values on the header section.
Defines a class that presents a widget with the graphic scale properties to be edited.
te::gm::Polygon * p
void scaleWidgetClosed()
This function must be called when the Grid related to it was closed.
void scaleTypeChanged(const int &)
Emmited when the ruler type was changed.
void addProperty(QtProperty *property, const QString &id, QColor c)
void rulerHeightChanged(const int &)
Emmited when the height of the ruler was changed.
bool getNumericScaleIsVisible() const
Returns the visibility of the footer section.
int getNumberOfIntervals() const
Returns the number of intervals being used by ruler.
QAction * m_editAction
Action used to show the widget.
void headerFontChanged(const QFont &)
Emmited when the header font was changed.
void footerFontChanged(const QFont &)
Emmited when the footer font was changed.
QColor getRulerColor() const
Returns the value of the color of the ruler.
void interactHandleChanged(const bool &)
Emmited when the interaction mode was changed.
void headerColorChanged(const QColor &)
Emmited when the header color was changed.
void numberOfIntervalsChanged(const int &)
Emmited when the number of intervals in the ruler was changed.
int getRulerHeightMM() const
Returns the lenght of the ruler in millimeters.
Contains an implementation of a graphic scale.