All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
69 }
70 
72 {
73  assert(graphic);
74 
75  delete m_graphic;
76 
77  m_graphic = graphic->clone();
78 
79  // Verifying if this widget can deal with the given graphic...
80  const std::vector<te::se::ExternalGraphic*> extGraphics = m_graphic->getExternalGraphics();
81  if(extGraphics.empty())
82  return false;
83 
84  te::se::ExternalGraphic* g = extGraphics[0];
85  const te::xl::SimpleLink* link = g->getOnlineResource();
86  if(link == 0)
87  return false;
88 
89  const std::string href = link->getHref();
90  if(href.empty())
91  return false;
92 
93  QImage img;
94  if(!img.load(href.c_str()))
95  return false;
96 
97  // I know it!
98  m_localImageWidget->setExternalGraphic(g);
99 
100  updateUi();
101 
102  return true;
103 }
104 
106 {
107  return tr("Local Image");
108 }
109 
111 {
112  const std::vector<te::se::ExternalGraphic*> extGraphics = m_graphic->getExternalGraphics();
113  if(extGraphics.empty())
114  return QIcon();
115 
116  te::se::ExternalGraphic* g = extGraphics[0];
117  const te::xl::SimpleLink* link = g->getOnlineResource();
118  if(link == 0)
119  return QIcon();
120 
121  const std::string href = link->getHref();
122  if(href.empty())
123  return QIcon();
124 
125  QImage img;
126  if(!img.load(href.c_str()))
127  return QIcon();
128 
129  return QIcon(QPixmap::fromImage(img.scaledToWidth(size.width(), Qt::SmoothTransformation)));
130 }
131 
133 {
134  m_graphic->setExternalGraphic(0, m_localImageWidget->getExternalGraphic());
135  // Updating graphic size
136  m_ui->m_graphicSizeDoubleSpinBox->setValue(size.height());
137 }
138 
140 {
141  setGraphicDisplacement(m_ui->m_displacementXDoubleSpinBox->text(), m_ui->m_displacementXDoubleSpinBox->text());
142 }
143 
145 {
146  setGraphicAnchorPoint(m_ui->m_anchorPointXDoubleSpinBox->text(), m_ui->m_anchorPointYDoubleSpinBox->text());
147 }
148 
150 {
151  // Size
152  const te::se::ParameterValue* size = m_graphic->getSize();
153  if(size)
154  m_ui->m_graphicSizeDoubleSpinBox->setValue(te::se::GetDouble(size));
155 
156  // Rotation
157  const te::se::ParameterValue* rotation = m_graphic->getRotation();
158  if(rotation)
159  m_ui->m_graphicAngleDoubleSpinBox->setValue(te::se::GetDouble(rotation));
160 
161  // Opacity
162  const te::se::ParameterValue* opacity = m_graphic->getOpacity();
163  if(opacity)
164  m_ui->m_graphicOpacitySlider->setValue(te::se::GetDouble(opacity) * 100);
165 
166  // Displacement
167  const te::se::Displacement* disp = m_graphic->getDisplacement();
168  if(disp)
169  {
170  const te::se::ParameterValue* dispx = disp->getDisplacementX();
171  if(dispx)
172  m_ui->m_displacementXDoubleSpinBox->setValue(te::se::GetDouble(dispx));
173 
174  const te::se::ParameterValue* dispy = disp->getDisplacementY();
175  if(dispy)
176  m_ui->m_displacementYDoubleSpinBox->setValue(te::se::GetDouble(dispy));
177  }
178 
179  // Anchor Point
180  const te::se::AnchorPoint* ac = m_graphic->getAnchorPoint();
181  if(ac)
182  {
183  const te::se::ParameterValue* acx = ac->getAnchorPointX();
184  if(acx)
185  m_ui->m_anchorPointXDoubleSpinBox->setValue(te::se::GetDouble(acx));
186 
187  const te::se::ParameterValue* acy = ac->getAnchorPointY();
188  if(acy)
189  m_ui->m_anchorPointYDoubleSpinBox->setValue(te::se::GetDouble(acy));
190  }
191 }
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
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.
Definition: Utils.cpp:448
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...
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 'anchor' for positioning it r...
Definition: AnchorPoint.h:63
const ParameterValue * getDisplacementY() const
const te::xl::SimpleLink * getOnlineResource() const
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.
std::auto_ptr< Ui::LocalGraphicWidgetForm > m_ui
Widget form.
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...
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.
QString getGraphicType() const
Pure virtual method that should return a "user friendly" string that informs the graphic type that ca...