All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WellKnownGraphicWidget.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/WellKnownGraphicWidget.cpp
22 
23  \brief A widget used to build a graphic associate with a well-known mark element.
24 */
25 
26 // TerraLib
27 #include "../../../common/STLUtils.h"
28 #include "../../../maptools/MarkRendererManager.h"
29 #include "../../../se/AnchorPoint.h"
30 #include "../../../se/Displacement.h"
31 #include "../../../se/Graphic.h"
32 #include "../../../se/Mark.h"
33 #include "../../../se/Utils.h"
34 #include "../Utils.h"
35 #include "WellKnownGraphicWidget.h"
36 #include "WellKnownMarkWidget.h"
37 #include "ui_WellKnownGraphicWidgetForm.h"
38 
39 // Qt
40 #include <QGridLayout>
41 
42 // STL
43 #include <cassert>
44 
46  : AbstractGraphicWidget(parent, f),
47  m_ui(new Ui::WellKnownGraphicWidgetForm)
48 {
49  m_ui->setupUi(this);
50 
51  // Well known mark Widget
53 
54  // Adjusting...
55  QGridLayout* layout = new QGridLayout(m_ui->m_markGroupBox);
56  layout->addWidget(m_markWidget);
57 
58  // Setups initial graphic
60 
61  // Signals & slots
62  connect(m_ui->m_graphicSizeDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(setGraphicSize(const QString&)));
63  connect(m_ui->m_graphicAngleDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(setGraphicAngle(const QString&)));
64  connect(m_ui->m_graphicOpacitySlider, SIGNAL(valueChanged(int)), SLOT(setGraphicOpacity(int)));
65  connect(m_ui->m_displacementXDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicDisplacementChanged(const QString&)));
66  connect(m_ui->m_displacementYDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicDisplacementChanged(const QString&)));
67  connect(m_ui->m_anchorPointXDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicAnchorPointChanged(const QString&)));
68  connect(m_ui->m_anchorPointYDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicAnchorPointChanged(const QString&)));
69  connect(m_markWidget, SIGNAL(markChanged()), SLOT(onMarkChanged()));
70 }
71 
73 {
74 }
75 
77 {
78  assert(graphic);
79 
80  delete m_graphic;
81 
82  m_graphic = graphic->clone();
83 
84  // Verifying if this widget can deal with the given graphic...
85  const std::vector<te::se::Mark*> marks = m_graphic->getMarks();
86  if(marks.empty())
87  return false;
88 
89  te::se::Mark* mark = marks[0];
90  if(mark == 0)
91  return false;
92 
93  const std::string* name = mark->getWellKnownName();
94  if(name == 0)
95  return false;
96 
97  std::size_t found = name->find("://");
98  if(found != std::string::npos)
99  return false;
100 
101  // I know it!
102  m_markWidget->setMark(marks[0]);
103 
104  updateUi();
105 
106  return true;
107 }
108 
110 {
111  return tr("Well Known Marker");
112 }
113 
115 {
116  te::se::Mark* mark = m_markWidget->getMark();
117 
118  int dimension = size.width();
119  te::color::RGBAColor** rgba = te::map::MarkRendererManager::getInstance().render(mark, dimension);
120  QImage* img = te::qt::widgets::GetImage(rgba, dimension, dimension);
121 
122  QIcon icon = QIcon(QPixmap::fromImage(img->scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
123 
124  delete img;
125  te::common::Free(rgba, dimension);
126  delete mark;
127 
128  return icon;
129 }
130 
132 {
133  m_graphic->setMark(0, m_markWidget->getMark());
134  emit graphicChanged();
135 }
136 
138 {
139  setGraphicDisplacement(m_ui->m_displacementXDoubleSpinBox->text(), m_ui->m_displacementXDoubleSpinBox->text());
140 }
141 
143 {
144  setGraphicAnchorPoint(m_ui->m_anchorPointXDoubleSpinBox->text(), m_ui->m_anchorPointYDoubleSpinBox->text());
145 }
146 
148 {
149  // Size
150  const te::se::ParameterValue* size = m_graphic->getSize();
151  if(size)
152  m_ui->m_graphicSizeDoubleSpinBox->setValue(te::se::GetDouble(size));
153 
154  // Rotation
155  const te::se::ParameterValue* rotation = m_graphic->getRotation();
156  if(rotation)
157  m_ui->m_graphicAngleDoubleSpinBox->setValue(te::se::GetDouble(rotation));
158 
159  // Opacity
160  const te::se::ParameterValue* opacity = m_graphic->getOpacity();
161  if(opacity)
162  m_ui->m_graphicOpacitySlider->setValue(te::se::GetDouble(opacity) * 100);
163 
164  // Displacement
165  const te::se::Displacement* disp = m_graphic->getDisplacement();
166  if(disp)
167  {
168  const te::se::ParameterValue* dispx = disp->getDisplacementX();
169  if(dispx)
170  m_ui->m_displacementXDoubleSpinBox->setValue(te::se::GetDouble(dispx));
171 
172  const te::se::ParameterValue* dispy = disp->getDisplacementY();
173  if(dispy)
174  m_ui->m_displacementYDoubleSpinBox->setValue(te::se::GetDouble(dispy));
175  }
176 
177  // Anchor Point
178  const te::se::AnchorPoint* ac = m_graphic->getAnchorPoint();
179  if(ac)
180  {
181  const te::se::ParameterValue* acx = ac->getAnchorPointX();
182  if(acx)
183  m_ui->m_anchorPointXDoubleSpinBox->setValue(te::se::GetDouble(acx));
184 
185  const te::se::ParameterValue* acy = ac->getAnchorPointY();
186  if(acy)
187  m_ui->m_anchorPointYDoubleSpinBox->setValue(te::se::GetDouble(acy));
188  }
189 }
A widget used to build a well known mark element.
const ParameterValue * getDisplacementX() const
te::se::Graphic * m_graphic
Graphic element that will be configured by this widget.
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
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::qt::widgets::WellKnownMarkWidget * m_markWidget
Well known mark Widget used to configure the mark element.
QIcon getGraphicIcon(const QSize &size) const
Pure virtual method that should return a QIcon that represents the graphic. i.e. a simple preview...
te::se::Mark * getMark() const
Gets the configured mark element.
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...
A widget used to build a graphic associate with a well-known mark element.
void add(ExternalGraphic *g)
Graphics can either be referenced from an external URL in a common format (such as GIF or SVG)...
Definition: Graphic.cpp:59
An AnchorPoint identifies the location inside of a text label to use an 'anchor' for positioning it r...
Definition: AnchorPoint.h:63
const ParameterValue * getDisplacementY() const
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
Definition: STLUtils.h:131
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
bool setGraphic(const te::se::Graphic *graphic)
Sets a graphic element to this widget.
const ParameterValue * getAnchorPointX() const
Definition: AnchorPoint.cpp:48
const std::string * getWellKnownName() const
Definition: Mark.cpp:60
QString getGraphicType() const
Pure virtual method that should return a "user friendly" string that informs the graphic type that ca...
const std::vector< Mark * > getMarks() const
Definition: Graphic.cpp:98
TEQTWIDGETSEXPORT QImage * GetImage(te::color::RGBAColor **img, int width, int height)
It creates a QImage from an RGBA color array.
Definition: Utils.cpp:69
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
const ParameterValue * getAnchorPointY() const
Definition: AnchorPoint.cpp:59
void onGraphicDisplacementChanged(const QString &text)
A widget used to build a well known mark element.
void updateUi()
Updates the widget form based on internal graphic element.
std::auto_ptr< Ui::WellKnownGraphicWidgetForm > m_ui
Widget form.
Abstract class that represents a widget that can be used to build a graphic element.
WellKnownGraphicWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a well known graphic widget which is a child of parent, with widget flags set to f...