GraphicPropertyItem.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/GraphicPropertyItem.cpp
22 
23  \brief A widget used to define the general properties of a se object.
24 */
25 
26 // TerraLib
27 #include "../../../se/Utils.h"
28 #include "../../../se.h"
29 #include "../../../xlink/SimpleLink.h"
30 #include "../propertybrowser/AbstractPropertyManager.h"
31 #include "GraphicPropertyItem.h"
32 
33 // QtPropertyBrowser
34 #include <QtPropertyBrowser/QtTreePropertyBrowser>
35 #include <QtPropertyBrowser/QtVariantPropertyManager>
36 
37 // STL
38 #include <cassert>
39 
40 
41 te::qt::widgets::GraphicPropertyItem::GraphicPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
42  m_setLocalGraphic(false), m_graphic(new te::se::Graphic)
43 {
44  //build property browser basic stroke
45  QtProperty* generalProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Graphic"));
46 
47  //size
48  m_sizeProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->addProperty(tr("Size"));
51  te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->setMaximum(m_sizeProperty, 1024);
52  te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->setSingleStep(m_sizeProperty, 1);
54  generalProperty->addSubProperty(m_sizeProperty);
55 
56  //angle
57  m_angleProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->addProperty(tr("Angle"));
61  te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->setSingleStep(m_angleProperty, 10);
63  generalProperty->addSubProperty(m_angleProperty);
64 
65  //opacity
66  m_opacityProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->addProperty(tr("Opacity"));
69  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setMaximum(m_opacityProperty, 100);
70  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setSingleStep(m_opacityProperty, 10);
71  generalProperty->addSubProperty(m_opacityProperty);
72 
73  ////displacement
74  //m_displacementProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->addProperty(tr("Displacement"));
75  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_displacementProperty, QPointF(0., 0.));
76  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setDecimals(m_displacementProperty, 2);
77  //generalProperty->addSubProperty(m_displacementProperty);
78 
79  ////anchor
80  //m_anchorProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->addProperty(tr("Anchor"));
81  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_anchorProperty, QPointF(0.5, 0.5));
82  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setDecimals(m_anchorProperty, 2);
83  //generalProperty->addSubProperty(m_anchorProperty);
84 
85  addProperty(generalProperty, tr("Graphic"), QColor(210, 210, 210));
86 }
87 
89 
91 {
92  assert(graphic);
93 
94  delete m_graphic;
95 
96  m_setLocalGraphic = true;
97 
98  m_graphic = graphic->clone();
99 
100  updateUi();
101 
102  m_setLocalGraphic = false;
103 
104  return true;
105 }
106 
108 {
109  return m_graphic->clone();
110 }
111 
113 {
115  return;
116 
117  if(p == m_opacityProperty)
118  {
119  double opacity = value / 100.0;
120  m_graphic->setOpacity(new te::se::ParameterValue(QString::number(opacity, 'g', 2).toUtf8().data()));
121  emit graphicChanged();
122  }
123 }
124 
126 {
128  return;
129 
130  QString valueStr;
131  valueStr.setNum(value);
132 
133  if(p == m_sizeProperty)
134  {
135  m_graphic->setSize(new te::se::ParameterValue(valueStr.toUtf8().data()));
136  emit graphicChanged();
137  }
138  else if(p == m_angleProperty)
139  {
140  m_graphic->setRotation(new te::se::ParameterValue(valueStr.toUtf8().data()));
141  emit graphicChanged();
142  }
143 }
144 
146  const QPointF& value)
147 {
149  return;
150 
151  QString xStr, yStr;
152  xStr.setNum(value.x());
153  yStr.setNum(value.y());
154 
155  //if(p == m_displacementProperty)
156  //{
157  // te::se::Displacement* disp = new te::se::Displacement;
158  // disp->setDisplacementX(new te::se::ParameterValue(xStr.toUtf8().data()));
159  // disp->setDisplacementY(new te::se::ParameterValue(yStr.toUtf8().data()));
160  // m_graphic->setDisplacement(disp);
161 
162  // emit graphicChanged();
163  //}
164  //else if(p == m_anchorProperty)
165  //{
166  // te::se::AnchorPoint* ac = new te::se::AnchorPoint;
167  // ac->setAnchorPointX(new te::se::ParameterValue(xStr.toUtf8().data()));
168  // ac->setAnchorPointY(new te::se::ParameterValue(yStr.toUtf8().data()));
169  // m_graphic->setAnchorPoint(ac);
170 
171  // emit graphicChanged();
172  //}
173 }
174 
176 {
177  // Size
178  const te::se::ParameterValue* size = m_graphic->getSize();
179  if(size)
181 
182  // Rotation
183  const te::se::ParameterValue* rotation = m_graphic->getRotation();
184  if(rotation)
186 
187  // Opacity
188  const te::se::ParameterValue* opacity = m_graphic->getOpacity();
189  if(opacity)
190  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setValue(m_opacityProperty, te::se::GetDouble(opacity) * 100);
191 
192  //// Displacement
193  //const te::se::Displacement* disp = m_graphic->getDisplacement();
194  //if(disp)
195  //{
196  // const te::se::ParameterValue* dispx = disp->getDisplacementX();
197  // const te::se::ParameterValue* dispy = disp->getDisplacementY();
198  // if(dispx && dispy)
199  // te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_displacementProperty,
200  // QPointF(te::map::GetDouble(dispx), te::map::GetDouble(dispy)));
201  //}
202 
203  //// Anchor Point
204  //const te::se::AnchorPoint* ac = m_graphic->getAnchorPoint();
205  //if(ac)
206  //{
207  // const te::se::ParameterValue* acx = ac->getAnchorPointX();
208  // const te::se::ParameterValue* acy = ac->getAnchorPointY();
209  // if(acx && acy)
210  // te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_anchorProperty,
211  // QPointF(te::map::GetDouble(acx), te::map::GetDouble(acy)));
212  //}
213 }
214 
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
void setRotation(ParameterValue *value)
The Rotation element gives the rotation of a graphic in the clockwise direction about its center poin...
Definition: Graphic.cpp:125
A widget used to define the main property items that can be used to describe a se object...
void setOpacity(ParameterValue *value)
The Opacity element gives the opacity to use for rendering the graphic. It has the same semantics as ...
Definition: Graphic.cpp:103
void setSize(ParameterValue *value)
The Size element gives the absolute size of the graphic in uoms encoded as a floating-point number...
Definition: Graphic.cpp:114
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
void updateUi()
Updates the widget form based on internal graphic element.
A widget used to define the general properties of a se object.
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
te::gm::Polygon * p
GraphicPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
void addProperty(QtProperty *property, const QString &id, QColor c)
virtual void valueChanged(QtProperty *p, int value)
bool setGraphic(const te::se::Graphic *graphic)
const ParameterValue * getSize() const
Definition: Graphic.cpp:120
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109