All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GraphicPropertyItem.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 "../../../maptools/Utils.h"
28 #include "../../../se.h"
29 #include "../../../xlink/SimpleLink.h"
30 #include "GraphicPropertyItem.h"
32 
33 // Qt
34 #include "../../../../../third-party/qt/propertybrowser/qtpropertybrowser.h"
35 
36 // STL
37 #include <cassert>
38 
39 
40 te::qt::widgets::GraphicPropertyItem::GraphicPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
41  m_setLocalGraphic(false), m_graphic(new te::se::Graphic)
42 {
43  //build property browser basic stroke
44  QtProperty* generalProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Graphic"));
45 
46  //size
47  m_sizeProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->addProperty(tr("Size"));
50  te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->setMaximum(m_sizeProperty, 1024);
51  te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->setSingleStep(m_sizeProperty, 1);
53  generalProperty->addSubProperty(m_sizeProperty);
54 
55  //angle
56  m_angleProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->addProperty(tr("Angle"));
60  te::qt::widgets::AbstractPropertyManager::getInstance().m_doubleManager->setSingleStep(m_angleProperty, 10);
62  generalProperty->addSubProperty(m_angleProperty);
63 
64  //opacity
65  m_opacityProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->addProperty(tr("Opacity"));
68  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setMaximum(m_opacityProperty, 100);
69  te::qt::widgets::AbstractPropertyManager::getInstance().m_intSliderManager->setSingleStep(m_opacityProperty, 10);
70  generalProperty->addSubProperty(m_opacityProperty);
71 
72  ////displacement
73  //m_displacementProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->addProperty(tr("Displacement"));
74  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_displacementProperty, QPointF(0., 0.));
75  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setDecimals(m_displacementProperty, 2);
76  //generalProperty->addSubProperty(m_displacementProperty);
77 
78  ////anchor
79  //m_anchorProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->addProperty(tr("Anchor"));
80  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setValue(m_anchorProperty, QPointF(0.5, 0.5));
81  //te::qt::widgets::AbstractPropertyManager::getInstance().m_pointFManager->setDecimals(m_anchorProperty, 2);
82  //generalProperty->addSubProperty(m_anchorProperty);
83 
84  addProperty(generalProperty, tr("Graphic"), QColor(210, 210, 210));
85 }
86 
88 {
89 }
90 
92 {
93  assert(graphic);
94 
95  delete m_graphic;
96 
97  m_setLocalGraphic = true;
98 
99  m_graphic = graphic->clone();
100 
101  updateUi();
102 
103  m_setLocalGraphic = false;
104 
105  return true;
106 }
107 
109 {
110  return m_graphic->clone();
111 }
112 
114 {
115  if(m_setLocalGraphic)
116  return;
117 
118  if(p == m_opacityProperty)
119  {
120  double opacity = value / 100.0;
121  m_graphic->setOpacity(new te::se::ParameterValue(QString::number(opacity, 'g', 2).toStdString()));
122  emit graphicChanged();
123  }
124 }
125 
126 void te::qt::widgets::GraphicPropertyItem::valueChanged(QtProperty *p, double value)
127 {
128  if(m_setLocalGraphic)
129  return;
130 
131  QString valueStr;
132  valueStr.setNum(value);
133 
134  if(p == m_sizeProperty)
135  {
136  m_graphic->setSize(new te::se::ParameterValue(valueStr.toStdString()));
137  emit graphicChanged();
138  }
139  else if(p == m_angleProperty)
140  {
141  m_graphic->setRotation(new te::se::ParameterValue(valueStr.toStdString()));
142  emit graphicChanged();
143  }
144 }
145 
146 void te::qt::widgets::GraphicPropertyItem::valueChanged(QtProperty* p, const QPointF &value)
147 {
148  if(m_setLocalGraphic)
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.toStdString()));
159  // disp->setDisplacementY(new te::se::ParameterValue(yStr.toStdString()));
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.toStdString()));
168  // ac->setAnchorPointY(new te::se::ParameterValue(yStr.toStdString()));
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)
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 
TEMAPEXPORT double GetDouble(const te::se::ParameterValue *param)
Gets the parameter value as double.
Definition: Utils.cpp:127
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
bool setGraphic(const te::se::Graphic *graphic)
void updateUi()
Updates the widget form based on internal graphic element.
A widget used to define the main property items that can be used to describe a se object...
virtual void valueChanged(QtProperty *p, int value)
void addProperty(QtProperty *property, const QString &id, QColor c)
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
GraphicPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
The &quot;ParameterValueType&quot; uses WFS-Filter expressions to give values for SE graphic parameters...
A widget used to define the general properties of a se object.