GlyphGraphicWidget.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/GlyphGraphicWidget.cpp
22 
23  \brief A widget used to build a graphic associate with a glyph 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 "GlyphGraphicWidget.h"
36 #include "GlyphMarkWidget.h"
37 #include "ui_GlyphGraphicWidgetForm.h"
38 
39 // STL
40 #include <cassert>
41 
43  : AbstractGraphicWidget(parent, f),
44  m_ui(new Ui::GlyphGraphicWidgetForm)
45 {
46  m_ui->setupUi(this);
47 
48  // Glyph Mark Widget
50 
51  // Adjusting...
52  QGridLayout* layout = new QGridLayout(m_ui->m_glyphGroupBox);
53  layout->addWidget(m_glyphMarkWidget);
54 
55  // Setups initial graphic
57 
58  // Signals & slots
59  connect(m_ui->m_graphicSizeDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(setGraphicSize(const QString&)));
60  connect(m_ui->m_graphicAngleDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(setGraphicAngle(const QString&)));
61  connect(m_ui->m_displacementXDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicDisplacementChanged(const QString&)));
62  connect(m_ui->m_displacementYDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicDisplacementChanged(const QString&)));
63  connect(m_ui->m_anchorPointXDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicAnchorPointChanged(const QString&)));
64  connect(m_ui->m_anchorPointYDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicAnchorPointChanged(const QString&)));
65  connect(m_glyphMarkWidget, SIGNAL(markChanged()), SLOT(onMarkChanged()));
66 }
67 
69 
71 {
72  assert(graphic);
73 
74  // Verifying if this widget can deal with the given graphic...
75  const std::vector<te::se::Mark*> marks = graphic->getMarks();
76  if(marks.empty())
77  return false;
78 
79  te::se::Mark* mark = marks[0];
80  const std::string* name = mark->getWellKnownName();
81  if(name == nullptr)
82  return false;
83 
84  std::size_t found = name->find("ttf://");
85  if(found == std::string::npos)
86  return false;
87 
88  // I know it!
89  m_glyphMarkWidget->setMark(marks[0]);
90 
91  delete m_graphic;
92 
93  m_graphic = graphic->clone();
94 
95  updateUi();
96 
97  return true;
98 }
99 
101 {
102  return tr("Glyph Marker");
103 }
104 
106 {
108 
109  int dimension = size.width();
110  te::color::RGBAColor** rgba = te::map::MarkRendererManager::getInstance().render(mark, dimension);
111  QImage* img = te::qt::widgets::GetImage(rgba, dimension, dimension);
112 
113  QIcon icon = QIcon(QPixmap::fromImage(img->scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
114 
115  delete img;
116  te::common::Free(rgba, dimension);
117  delete mark;
118 
119  return icon;
120 }
121 
123 {
125  emit graphicChanged();
126 }
127 
129 {
130  setGraphicDisplacement(m_ui->m_displacementXDoubleSpinBox->text(), m_ui->m_displacementXDoubleSpinBox->text());
131 }
132 
134 {
135  setGraphicAnchorPoint(m_ui->m_anchorPointXDoubleSpinBox->text(), m_ui->m_anchorPointYDoubleSpinBox->text());
136 }
137 
139 {
140  // Size
141  const te::se::ParameterValue* size = m_graphic->getSize();
142  if(size)
143  m_ui->m_graphicSizeDoubleSpinBox->setValue(te::se::GetDouble(size));
144 
145  // Rotation
146  const te::se::ParameterValue* rotation = m_graphic->getRotation();
147  if(rotation)
148  m_ui->m_graphicAngleDoubleSpinBox->setValue(te::se::GetDouble(rotation));
149 
150  // Displacement
152  if(disp)
153  {
154  const te::se::ParameterValue* dispx = disp->getDisplacementX();
155  if(dispx)
156  m_ui->m_displacementXDoubleSpinBox->setValue(te::se::GetDouble(dispx));
157 
158  const te::se::ParameterValue* dispy = disp->getDisplacementY();
159  if(dispy)
160  m_ui->m_displacementYDoubleSpinBox->setValue(te::se::GetDouble(dispy));
161  }
162 
163  // Anchor Point
165  if(ac)
166  {
167  const te::se::ParameterValue* acx = ac->getAnchorPointX();
168  if(acx)
169  m_ui->m_anchorPointXDoubleSpinBox->setValue(te::se::GetDouble(acx));
170 
171  const te::se::ParameterValue* acy = ac->getAnchorPointY();
172  if(acy)
173  m_ui->m_anchorPointYDoubleSpinBox->setValue(te::se::GetDouble(acy));
174  }
175 }
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
const ParameterValue * getDisplacementX() const
GlyphGraphicWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a glyph graphic widget which is a child of parent, with widget flags set to f...
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
QString getGraphicType() const
Pure virtual method that should return a "user friendly" string that informs the graphic type that ca...
void setGraphicAnchorPoint(const QString &ax, const QString &ay)
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...
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
te::qt::widgets::GlyphMarkWidget * m_glyphMarkWidget
Glyph mark widget used to configure the glyph mark element.
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
bool setGraphic(const te::se::Graphic *graphic)
Sets a graphic element to this widget.
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
void onGraphicDisplacementChanged(const QString &text)
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
A widget used to build a mark element represented by a glyph.
void onGraphicAnchorPointChanged(const QString &text)
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
const ParameterValue * getAnchorPointX() const
Definition: AnchorPoint.cpp:48
const std::string * getWellKnownName() const
Definition: Mark.cpp:60
QIcon getGraphicIcon(const QSize &size) const
Pure virtual method that should return a QIcon that represents the graphic. i.e. a simple preview...
const Displacement * getDisplacement() const
Definition: Graphic.cpp:153
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.
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
void updateUi()
Updates the widget form based on internal graphic element.
std::unique_ptr< Ui::GlyphGraphicWidgetForm > m_ui
Widget form.
const ParameterValue * getAnchorPointY() const
Definition: AnchorPoint.cpp:59
A widget used to build a mark element represented by a glyph.
A widget used to build a graphic associate with a glyph mark element.
Abstract class that represents a widget that can be used to build a graphic element.
const ParameterValue * getSize() const
Definition: Graphic.cpp:120
te::se::Mark * getMark() const
Gets the configured mark element.