LocalGraphicWidget.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/LocalGraphicWidget.cpp
22 
23  \brief A widget used to build a graphic associated with an external graphic element that references a local image. e.g. a SVG file, a PNG file, etc.
24 */
25 
26 // TerraLib
27 #include "../../../se/ExternalGraphic.h"
28 #include "../../../se/AnchorPoint.h"
29 #include "../../../se/Displacement.h"
30 #include "../../../se/Graphic.h"
31 #include "../../../se/Utils.h"
32 #include "../../../xlink/SimpleLink.h"
33 #include "LocalGraphicWidget.h"
34 #include "LocalImageWidget.h"
35 #include "ui_LocalGraphicWidgetForm.h"
36 
37 // STL
38 #include <cassert>
39 
41  : AbstractGraphicWidget(parent, f),
42  m_ui(new Ui::LocalGraphicWidgetForm)
43 {
44  m_ui->setupUi(this);
45 
46  // Local Image Widget
48 
49  // Adjusting...
50  QGridLayout* layout = new QGridLayout(m_ui->m_imageGroupBox);
51  layout->addWidget(m_localImageWidget);
52 
53  // Setups initial graphic
55 
56  // Signals & slots
57  connect(m_ui->m_graphicSizeDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(setGraphicSize(const QString&)));
58  connect(m_ui->m_graphicAngleDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(setGraphicAngle(const QString&)));
59  connect(m_ui->m_graphicOpacitySlider, SIGNAL(valueChanged(int)), SLOT(setGraphicOpacity(int)));
60  connect(m_ui->m_displacementXDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicDisplacementChanged(const QString&)));
61  connect(m_ui->m_displacementYDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicDisplacementChanged(const QString&)));
62  connect(m_ui->m_anchorPointXDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicAnchorPointChanged(const QString&)));
63  connect(m_ui->m_anchorPointYDoubleSpinBox, SIGNAL(valueChanged(const QString&)), SLOT(onGraphicAnchorPointChanged(const QString&)));
64  connect(m_localImageWidget, SIGNAL(externalGraphicChanged(const QSize&)), SLOT(onExternalGraphicChanged(const QSize&)));
65 }
66 
68 
70 {
71  assert(graphic);
72 
73  // Verifying if this widget can deal with the given graphic...
74  const std::vector<te::se::ExternalGraphic*> extGraphics = graphic->getExternalGraphics();
75  if(extGraphics.empty())
76  return false;
77 
78  te::se::ExternalGraphic* g = extGraphics[0];
80  if(link == nullptr)
81  return false;
82 
83  const std::string href = link->getHref();
84  if(href.empty())
85  return false;
86 
87  QImage img;
88  if(!img.load(href.c_str()))
89  return false;
90 
91  // I know it!
93 
94  delete m_graphic;
95 
96  m_graphic = graphic->clone();
97 
98  updateUi();
99 
100  return true;
101 }
102 
104 {
105  return tr("Local Image");
106 }
107 
109 {
110  const std::vector<te::se::ExternalGraphic*> extGraphics = m_graphic->getExternalGraphics();
111  if(extGraphics.empty())
112  return QIcon();
113 
114  te::se::ExternalGraphic* g = extGraphics[0];
116  if(link == nullptr)
117  return QIcon();
118 
119  const std::string href = link->getHref();
120  if(href.empty())
121  return QIcon();
122 
123  QImage img;
124  if(!img.load(href.c_str()))
125  return QIcon();
126 
127  return QIcon(QPixmap::fromImage(img.scaledToWidth(size.width(), Qt::SmoothTransformation)));
128 }
129 
131 {
133  // Updating graphic size
134  m_ui->m_graphicSizeDoubleSpinBox->setValue(size.height());
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
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
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 }
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
const ParameterValue * getDisplacementX() const
bool setGraphic(const te::se::Graphic *graphic)
Sets a graphic element to this widget.
void onExternalGraphicChanged(const QSize &size)
te::se::Graphic * m_graphic
Graphic element that will be configured by this widget.
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
const std::vector< ExternalGraphic * > getExternalGraphics() const
Definition: Graphic.cpp:76
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...
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
A widget used to build a graphic associated with an external graphic element that references a local ...
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
A widget used to build an external graphic element that references a local image. e...
void setExternalGraphic(std::size_t index, ExternalGraphic *g)
Definition: Graphic.cpp:65
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
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
const te::xl::SimpleLink * getOnlineResource() const
std::unique_ptr< Ui::LocalGraphicWidgetForm > m_ui
Widget form.
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
void updateUi()
Updates the widget form based on internal graphic element.
who udp maintains data bases showing who s shell tcp cmd syslog udp printer tcp spooler printer udp spooler videotex tcp videotex videotex udp videotex talk tcp like tenex link
A widget used to build an external graphic element that references a local image. e...
void onGraphicAnchorPointChanged(const QString &text)
const ParameterValue * getAnchorPointX() const
Definition: AnchorPoint.cpp:48
LocalGraphicWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a local graphic widget which is a child of parent, with widget flags set to f...
void setExternalGraphic(const te::se::ExternalGraphic *eg)
Sets an external graphic element to this widget.
const Displacement * getDisplacement() const
Definition: Graphic.cpp:153
void setGraphicDisplacement(const QString &dx, const QString &dy)
te::se::ExternalGraphic * getExternalGraphic() const
Gets the configured external graphic element.
void onGraphicDisplacementChanged(const QString &text)
const ParameterValue * getAnchorPointY() const
Definition: AnchorPoint.cpp:59
te::qt::widgets::LocalImageWidget * m_localImageWidget
Local image widget used to configure the external 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
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109
QString getGraphicType() const
Pure virtual method that should return a "user friendly" string that informs the graphic type that ca...