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 
75 {
76  assert(graphic);
77 
78  // Verifying if this widget can deal with the given graphic...
79  const std::vector<te::se::Mark*> marks = graphic->getMarks();
80  if(marks.empty())
81  return false;
82 
83  te::se::Mark* mark = marks[0];
84  if(mark == nullptr)
85  return false;
86 
87  const std::string* name = mark->getWellKnownName();
88  if(name == nullptr)
89  return false;
90 
91  std::size_t found = name->find("://");
92  if(found != std::string::npos)
93  return false;
94 
95  // I know it!
96  m_markWidget->setMark(marks[0]);
97 
98  delete m_graphic;
99 
100  m_graphic = graphic->clone();
101 
102  updateUi();
103 
104  return true;
105 }
106 
108 {
109  return tr("Well Known Marker");
110 }
111 
113 {
114  te::se::Mark* mark = m_markWidget->getMark();
115 
116  int dimension = size.width();
117  te::color::RGBAColor** rgba = te::map::MarkRendererManager::getInstance().render(mark, dimension);
118  QImage* img = te::qt::widgets::GetImage(rgba, dimension, dimension);
119 
120  QIcon icon = QIcon(QPixmap::fromImage(img->scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
121 
122  delete img;
123  te::common::Free(rgba, dimension);
124  delete mark;
125 
126  return icon;
127 }
128 
130 {
132  emit graphicChanged();
133 }
134 
136 {
137  setGraphicDisplacement(m_ui->m_displacementXDoubleSpinBox->text(), m_ui->m_displacementXDoubleSpinBox->text());
138 }
139 
141 {
142  setGraphicAnchorPoint(m_ui->m_anchorPointXDoubleSpinBox->text(), m_ui->m_anchorPointYDoubleSpinBox->text());
143 }
144 
146 {
147  // Size
148  const te::se::ParameterValue* size = m_graphic->getSize();
149  if(size)
150  m_ui->m_graphicSizeDoubleSpinBox->setValue(te::se::GetDouble(size));
151 
152  // Rotation
153  const te::se::ParameterValue* rotation = m_graphic->getRotation();
154  if(rotation)
155  m_ui->m_graphicAngleDoubleSpinBox->setValue(te::se::GetDouble(rotation));
156 
157  // Opacity
158  const te::se::ParameterValue* opacity = m_graphic->getOpacity();
159  if(opacity)
160  m_ui->m_graphicOpacitySlider->setValue(te::se::GetDouble(opacity) * 100);
161 
162  // Displacement
164  if(disp)
165  {
166  const te::se::ParameterValue* dispx = disp->getDisplacementX();
167  if(dispx)
168  m_ui->m_displacementXDoubleSpinBox->setValue(te::se::GetDouble(dispx));
169 
170  const te::se::ParameterValue* dispy = disp->getDisplacementY();
171  if(dispy)
172  m_ui->m_displacementYDoubleSpinBox->setValue(te::se::GetDouble(dispy));
173  }
174 
175  // Anchor Point
177  if(ac)
178  {
179  const te::se::ParameterValue* acx = ac->getAnchorPointX();
180  if(acx)
181  m_ui->m_anchorPointXDoubleSpinBox->setValue(te::se::GetDouble(acx));
182 
183  const te::se::ParameterValue* acy = ac->getAnchorPointY();
184  if(acy)
185  m_ui->m_anchorPointYDoubleSpinBox->setValue(te::se::GetDouble(acy));
186  }
187 }
A widget used to build a well known mark element.
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
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
void setMark(std::size_t index, Mark *m)
Definition: Graphic.cpp:87
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.
void setGraphicAnchorPoint(const QString &ax, const QString &ay)
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.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
const AnchorPoint * getAnchorPoint() const
Definition: Graphic.cpp:142
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.
std::unique_ptr< Ui::WellKnownGraphicWidgetForm > m_ui
Widget form.
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 &#39;anchor&#39; 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 Displacement * getDisplacement() const
Definition: Graphic.cpp:153
const std::vector< Mark * > getMarks() const
Definition: Graphic.cpp:98
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
TEQTWIDGETSEXPORT QImage * GetImage(te::color::RGBAColor **img, int width, int height)
It creates a QImage from an RGBA color array.
void setGraphicDisplacement(const QString &dx, const QString &dy)
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.
Abstract class that represents a widget that can be used to build a graphic element.
const ParameterValue * getSize() const
Definition: Graphic.cpp:120
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...
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109