All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
70 }
71 
73 {
74  assert(graphic);
75 
76  delete m_graphic;
77 
78  m_graphic = graphic->clone();
79 
80  // Verifying if this widget can deal with the given graphic...
81  const std::vector<te::se::Mark*> marks = m_graphic->getMarks();
82  if(marks.empty())
83  return false;
84 
85  te::se::Mark* mark = marks[0];
86  const std::string* name = mark->getWellKnownName();
87  if(name == 0)
88  return false;
89 
90  std::size_t found = name->find("ttf://");
91  if(found == std::string::npos)
92  return false;
93 
94  // I know it!
95  m_glyphMarkWidget->setMark(marks[0]);
96 
97  updateUi();
98 
99  return true;
100 }
101 
103 {
104  return tr("Glyph Marker");
105 }
106 
108 {
109  te::se::Mark* mark = m_glyphMarkWidget->getMark();
110 
111  int dimension = size.width();
112  te::color::RGBAColor** rgba = te::map::MarkRendererManager::getInstance().render(mark, dimension);
113  QImage* img = te::qt::widgets::GetImage(rgba, dimension, dimension);
114 
115  QIcon icon = QIcon(QPixmap::fromImage(img->scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
116 
117  delete img;
118  te::common::Free(rgba, dimension);
119  delete mark;
120 
121  return icon;
122 }
123 
125 {
126  m_graphic->setMark(0, m_glyphMarkWidget->getMark());
127  emit graphicChanged();
128 }
129 
131 {
132  setGraphicDisplacement(m_ui->m_displacementXDoubleSpinBox->text(), m_ui->m_displacementXDoubleSpinBox->text());
133 }
134 
136 {
137  setGraphicAnchorPoint(m_ui->m_anchorPointXDoubleSpinBox->text(), m_ui->m_anchorPointYDoubleSpinBox->text());
138 }
139 
141 {
142  // Size
143  const te::se::ParameterValue* size = m_graphic->getSize();
144  if(size)
145  m_ui->m_graphicSizeDoubleSpinBox->setValue(te::se::GetDouble(size));
146 
147  // Rotation
148  const te::se::ParameterValue* rotation = m_graphic->getRotation();
149  if(rotation)
150  m_ui->m_graphicAngleDoubleSpinBox->setValue(te::se::GetDouble(rotation));
151 
152  // Displacement
153  const te::se::Displacement* disp = m_graphic->getDisplacement();
154  if(disp)
155  {
156  const te::se::ParameterValue* dispx = disp->getDisplacementX();
157  if(dispx)
158  m_ui->m_displacementXDoubleSpinBox->setValue(te::se::GetDouble(dispx));
159 
160  const te::se::ParameterValue* dispy = disp->getDisplacementY();
161  if(dispy)
162  m_ui->m_displacementYDoubleSpinBox->setValue(te::se::GetDouble(dispy));
163  }
164 
165  // Anchor Point
166  const te::se::AnchorPoint* ac = m_graphic->getAnchorPoint();
167  if(ac)
168  {
169  const te::se::ParameterValue* acx = ac->getAnchorPointX();
170  if(acx)
171  m_ui->m_anchorPointXDoubleSpinBox->setValue(te::se::GetDouble(acx));
172 
173  const te::se::ParameterValue* acy = ac->getAnchorPointY();
174  if(acy)
175  m_ui->m_anchorPointYDoubleSpinBox->setValue(te::se::GetDouble(acy));
176  }
177 }
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
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...
std::auto_ptr< Ui::GlyphGraphicWidgetForm > m_ui
Widget form.
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 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 'anchor' 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)
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 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
void updateUi()
Updates the widget form based on internal graphic element.
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.
te::se::Mark * getMark() const
Gets the configured mark element.