PointPlacementPropertyItem.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/se/PointPlacementPropertyItem.cpp
22 
23 \brief A widget used to define the PointPlacement se object.
24 */
25 
26 
27 #include "../../../common/StringUtils.h"
28 #include "../../../se/AnchorPoint.h"
29 #include "../../../se/Displacement.h"
30 #include "../../../se/SvgParameter.h"
31 #include "../../../se/PointPlacement.h"
32 #include "../../../se/Utils.h"
33 #include "../propertybrowser/AbstractPropertyManager.h"
35 
36 // STL
37 #include <cassert>
38 
39 // QtPropertyBrowser
40 
41 
42 te::qt::widgets::PointPlacementPropertyItem::PointPlacementPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
43  m_pointPlacement(new te::se::PointPlacement)
44 {
45  //build property browser basic fill
46  QtProperty* pointPlacementProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Point Placement"));
47 
48  //anchor
49  m_anchorProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->addProperty(tr("Anchor"));
50  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setMinimum(m_anchorProperty, QSize(0, 0));
51  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setMaximum(m_anchorProperty, QSize(100, 100));
52  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setValue(m_anchorProperty, QSize(50, 50));
53  pointPlacementProperty->addSubProperty(m_anchorProperty);
54 
55  //displacement
56  m_displacementProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->addProperty(tr("Displacement"));
57  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setMinimum(m_displacementProperty, QSize(-100, -100));
58  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setMaximum(m_displacementProperty, QSize(100, 100));
60  pointPlacementProperty->addSubProperty(m_displacementProperty);
61 
62  //rotation
63  m_rotationProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->addProperty(tr("Rotation"));
64  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setMinimum(m_rotationProperty, -180);
67  pointPlacementProperty->addSubProperty(m_rotationProperty);
68 
69  addProperty(pointPlacementProperty, tr("Point Placement"), QColor(241, 165, 61));
70 
71  m_update = true;
72 }
73 
75 {
76  delete m_pointPlacement;
77 }
78 
80 {
81  if (!m_update)
82  return;
83 
84  if (p == m_rotationProperty)
85  {
86  m_update = false;
87 
88  m_pointPlacement->setRotation(new te::se::ParameterValue(QString::number(value).toUtf8().data()));
89 
90  emit pointPlacementChanged();
91  m_update = true;
92  }
93 }
94 
95 void te::qt::widgets::PointPlacementPropertyItem::valueChanged(QtProperty* p, const QSize &value)
96 {
97  if (!m_update)
98  return;
99 
100  if (p == m_displacementProperty)
101  {
102  m_update = false;
103 
105  disp->setDisplacementX(new te::se::ParameterValue(QString::number(value.width()).toUtf8().data()));
106  disp->setDisplacementY(new te::se::ParameterValue(QString::number(value.height()).toUtf8().data()));
107 
109 
110  emit pointPlacementChanged();
111  m_update = true;
112  }
113 
114  if (p == m_anchorProperty)
115  {
116  m_update = false;
117 
118  double x = value.width() / 100.;
119  double y = value.height() / 100.;
120 
122  ap->setAnchorPointX(new te::se::ParameterValue(QString::number(x).toUtf8().data()));
123  ap->setAnchorPointY(new te::se::ParameterValue(QString::number(y).toUtf8().data()));
124 
126 
127  emit pointPlacementChanged();
128  m_update = true;
129  }
130 }
131 
133 {
134  assert(pp);
135 
136  // Verifying if this widget can deal with the given fill...
137  delete m_pointPlacement;
138 
139  m_pointPlacement = dynamic_cast<te::se::PointPlacement*>(pp->clone());
140 
141  updateUi();
142 
143  m_update = true;
144 }
145 
147 {
148  return dynamic_cast<te::se::PointPlacement*>(m_pointPlacement->clone());
149 }
150 
152 {
153  //reset anchor value
154  QSize anchorSize(50, 50);
155  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setValue(m_anchorProperty, anchorSize);
156 
157  //reset displacement value
158  QSize dispSize(0, 0);
160 
161  //reset rotation value
162  int rotationValue = 0;
163  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_rotationProperty, rotationValue);
164 }
165 
167 {
168  m_update = true;
169 
170  //update anchor
172 
173  QSize anchorSize(50, 50);
174 
175  if (ap)
176  {
177  int x = (int)(te::se::GetDouble(ap->getAnchorPointX()) * 100.);
178  int y = (int)(te::se::GetDouble(ap->getAnchorPointY()) * 100.);
179 
180  anchorSize.setWidth(x);
181  anchorSize.setHeight(y);
182  }
183 
184  te::qt::widgets::AbstractPropertyManager::getInstance().m_sizeManager->setValue(m_anchorProperty, anchorSize);
185 
186  //update displacement
188 
189  QSize dispSize (0, 0);
190 
191  if (disp)
192  {
193  dispSize.setWidth(te::se::GetInt(disp->getDisplacementX()));
194  dispSize.setHeight(te::se::GetInt(disp->getDisplacementY()));
195  }
196 
198 
199  //update rotation
200  int rotationValue = 0;
201 
203  rotationValue = te::se::GetInt(m_pointPlacement->getRotation());
204 
205  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_rotationProperty, rotationValue);
206 
207 
208  m_update = false;
209 }
210 
void setDisplacement(Displacement *d)
const ParameterValue * getDisplacementX() const
const AnchorPoint * getAnchorPoint() const
void setRotation(ParameterValue *r)
A widget used to define the main property items that can be used to describe a se object...
A Displacement gives X and Y offset displacements to use for rendering a text label, graphic or other Symbolizer near a point.
Definition: Displacement.h:58
te::se::PointPlacement * m_pointPlacement
Fill element that will be configured by this widget.
const Displacement * getDisplacement() const
void setPointPlacement(const te::se::PointPlacement *pp)
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
void setAnchorPoint(AnchorPoint *a)
PointPlacement * clone() const
It creates a new copy of this object.
const ParameterValue * getRotation() const
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
An AnchorPoint identifies the location inside of a text label to use an &#39;anchor&#39; for positioning it r...
Definition: AnchorPoint.h:63
const ParameterValue * getDisplacementY() const
A widget used to define the PointPlacement se object.
void setAnchorPointX(ParameterValue *x)
Definition: AnchorPoint.cpp:42
void setDisplacementY(ParameterValue *y)
virtual void valueChanged(QtProperty *p, int value)
A PointPlacement specifies how a text label should be rendered relative to a geometric point...
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
void setAnchorPointY(ParameterValue *y)
Definition: AnchorPoint.cpp:53
URI C++ Library.
Definition: Attributes.h:37
te::gm::Polygon * p
const ParameterValue * getAnchorPointX() const
Definition: AnchorPoint.cpp:48
void addProperty(QtProperty *property, const QString &id, QColor c)
PointPlacementPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
void setDisplacementX(ParameterValue *x)
void updateUi()
Updates the widget form based on internal fill element.
TESEEXPORT int GetInt(const te::se::ParameterValue *param)
It gets the parameter value as an integer.
const ParameterValue * getAnchorPointY() const
Definition: AnchorPoint.cpp:59