All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
90 }
91 
93 {
94  assert(graphic);
95 
96  delete m_graphic;
97 
98  m_setLocalGraphic = true;
99 
100  m_graphic = graphic->clone();
101 
102  updateUi();
103 
104  m_setLocalGraphic = false;
105 
106  return true;
107 }
108 
110 {
111  return m_graphic->clone();
112 }
113 
115 {
116  if(m_setLocalGraphic)
117  return;
118 
119  if(p == m_opacityProperty)
120  {
121  double opacity = value / 100.0;
122  m_graphic->setOpacity(new te::se::ParameterValue(QString::number(opacity, 'g', 2).toStdString()));
123  emit graphicChanged();
124  }
125 }
126 
127 void te::qt::widgets::GraphicPropertyItem::valueChanged(QtProperty *p, double value)
128 {
129  if(m_setLocalGraphic)
130  return;
131 
132  QString valueStr;
133  valueStr.setNum(value);
134 
135  if(p == m_sizeProperty)
136  {
137  m_graphic->setSize(new te::se::ParameterValue(valueStr.toStdString()));
138  emit graphicChanged();
139  }
140  else if(p == m_angleProperty)
141  {
142  m_graphic->setRotation(new te::se::ParameterValue(valueStr.toStdString()));
143  emit graphicChanged();
144  }
145 }
146 
147 void te::qt::widgets::GraphicPropertyItem::valueChanged(QtProperty* p, const QPointF &value)
148 {
149  if(m_setLocalGraphic)
150  return;
151 
152  QString xStr, yStr;
153  xStr.setNum(value.x());
154  yStr.setNum(value.y());
155 
156  //if(p == m_displacementProperty)
157  //{
158  // te::se::Displacement* disp = new te::se::Displacement;
159  // disp->setDisplacementX(new te::se::ParameterValue(xStr.toStdString()));
160  // disp->setDisplacementY(new te::se::ParameterValue(yStr.toStdString()));
161  // m_graphic->setDisplacement(disp);
162 
163  // emit graphicChanged();
164  //}
165  //else if(p == m_anchorProperty)
166  //{
167  // te::se::AnchorPoint* ac = new te::se::AnchorPoint;
168  // ac->setAnchorPointX(new te::se::ParameterValue(xStr.toStdString()));
169  // ac->setAnchorPointY(new te::se::ParameterValue(yStr.toStdString()));
170  // m_graphic->setAnchorPoint(ac);
171 
172  // emit graphicChanged();
173  //}
174 }
175 
177 {
178  // Size
179  const te::se::ParameterValue* size = m_graphic->getSize();
180  if(size)
182 
183  // Rotation
184  const te::se::ParameterValue* rotation = m_graphic->getRotation();
185  if(rotation)
187 
188  // Opacity
189  const te::se::ParameterValue* opacity = m_graphic->getOpacity();
190  if(opacity)
192 
193  //// Displacement
194  //const te::se::Displacement* disp = m_graphic->getDisplacement();
195  //if(disp)
196  //{
197  // const te::se::ParameterValue* dispx = disp->getDisplacementX();
198  // const te::se::ParameterValue* dispy = disp->getDisplacementY();
199  // if(dispx && dispy)
200  // te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_displacementProperty,
201  // QPointF(te::map::GetDouble(dispx), te::map::GetDouble(dispy)));
202  //}
203 
204  //// Anchor Point
205  //const te::se::AnchorPoint* ac = m_graphic->getAnchorPoint();
206  //if(ac)
207  //{
208  // const te::se::ParameterValue* acx = ac->getAnchorPointX();
209  // const te::se::ParameterValue* acy = ac->getAnchorPointY();
210  // if(acx && acy)
211  // te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_anchorProperty,
212  // QPointF(te::map::GetDouble(acx), te::map::GetDouble(acy)));
213  //}
214 }
215 
A widget used to define the main property items that can be used to describe a se object...
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
Definition: Utils.cpp:448
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.
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)