GraphicProperty.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/GraphicPropertyItem.cpp
22 
23  \brief A widget used to define the general properties of a se object.
24 */
25 
26 // Terralib
27 #include "../../../maptools/Utils.h"
28 #include "../../../se.h"
29 #include "../../../xlink/SimpleLink.h"
30 #include "GraphicProperty.h"
31 #include "GraphicPropertyItem.h"
32 #include "GlyphMarkPropertyItem.h"
33 #include "LocalImagePropertyItem.h"
35 
36 // Qt
37 #include <QGridLayout>
38 #include <QToolBox>
39 
40 // QtPropertyBrowser
41 #include <QtPropertyBrowser/QtTreePropertyBrowser>
42 #include <QtPropertyBrowser/QtVariantPropertyManager>
43 
44 // STL
45 #include <cassert>
46 
48  : m_setLocalGraphic(false), m_graphic(new te::se::Graphic)
49 {
50  QGridLayout* layout = new QGridLayout(this);
51  this->setLayout(layout);
52 
53  QToolBox* tb = new QToolBox(this);
54  layout->addWidget(tb);
55 
56  QtTreePropertyBrowser* graphBrowser = new QtTreePropertyBrowser(this);
57  graphBrowser->setIndentation(10);
58  graphBrowser->setPropertiesWithoutValueMarked(true);
59  graphBrowser->setRootIsDecorated(false);
60  graphBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
61 
63  tb->addItem(graphBrowser, "Graphic Properties");
64 
65  QtTreePropertyBrowser* wkBrowser = new QtTreePropertyBrowser(this);
66  wkBrowser->setIndentation(10);
67  wkBrowser->setPropertiesWithoutValueMarked(true);
68  wkBrowser->setRootIsDecorated(false);
69  wkBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
70 
72  tb->addItem(wkBrowser, "Well Known Mark");
73 
74  QtTreePropertyBrowser* gpBrowser = new QtTreePropertyBrowser(this);
75  gpBrowser->setIndentation(10);
76  gpBrowser->setPropertiesWithoutValueMarked(true);
77  gpBrowser->setRootIsDecorated(false);
78  gpBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
79 
81  tb->addItem(gpBrowser, "Glyph Mark");
82 
83  QtTreePropertyBrowser* liBrowser = new QtTreePropertyBrowser(this);
84  liBrowser->setIndentation(10);
85  liBrowser->setPropertiesWithoutValueMarked(true);
86  liBrowser->setRootIsDecorated(false);
87  liBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
88 
90  tb->addItem(liBrowser, "Local Image");
91 
92  connect(m_graphp, SIGNAL(graphicChanged()), this, SLOT(onGraphicPropertyChanged()));
93  connect(m_mp, SIGNAL(markChanged()), this, SLOT(onWellKnownMarkChanged()));
94  connect(m_gp, SIGNAL(markChanged()), this, SLOT(onGlyphMarkChanged()));
95  connect(m_li, SIGNAL(externalGraphicChanged()), this, SLOT(onLocalImageChanged()));
96 
97  // Setups initial graphic
99 }
100 
102 
104 {
105  assert(graphic);
106 
107  delete m_graphic;
108 
109  m_setLocalGraphic = true;
110 
111  m_graphic = graphic->clone();
112 
114 
115  // Verifying if this widget can deal with the given graphic...
116  const std::vector<te::se::Mark*> marks = m_graphic->getMarks();
117  if(marks.empty() == false)
118  {
119  te::se::Mark* mark = marks[0];
120  const std::string* name = mark->getWellKnownName();
121  if(name != nullptr)
122  {
123  std::size_t found = name->find("ttf://");
124  if(found != std::string::npos)
125  m_gp->setMark(marks[0]);
126 
127  found = name->find("://");
128  if(found == std::string::npos)
129  m_mp->setMark(marks[0]);
130  }
131  }
132 
133  const std::vector<te::se::ExternalGraphic*> extGraphics = m_graphic->getExternalGraphics();
134  if(extGraphics.empty() == false)
135  {
136  te::se::ExternalGraphic* g = extGraphics[0];
138  if(link == nullptr)
139  return false;
140 
141  const std::string href = link->getHref();
142  if(href.empty())
143  return false;
144 
145  QImage img;
146  if(!img.load(href.c_str()))
147  return false;
148 
149  // I know it!
151  }
152 
153  m_setLocalGraphic = false;
154 
155  return true;
156 }
157 
159 {
160  return m_graphic->clone();
161 }
162 
164 {
166 
167  if(g->getSize())
168  m_graphic->setSize(g->getSize()->clone());
169 
170  if(g->getRotation())
172 
173  if(g->getOpacity())
175 
176  if(!m_setLocalGraphic)
177  emit graphicChanged();
178 }
179 
181 {
182  te::se::Mark* mark = m_mp->getMark();
183  if(!mark)
184  return;
185 
186  m_graphic->clear();
187  m_graphic->add(mark);
188 
189 
190  if(!m_setLocalGraphic)
191  emit graphicChanged();
192 }
193 
195 {
196  te::se::Mark* mark = m_gp->getMark();
197  if(!mark)
198  return;
199 
200  m_graphic->clear();
201  m_graphic->add(mark);
202 
203 
204  if(!m_setLocalGraphic)
205  emit graphicChanged();
206 }
207 
209 {
211  if(!eg)
212  return;
213 
214  m_graphic->clear();
215  m_graphic->add(eg);
216 
217  if(!m_setLocalGraphic)
218  emit graphicChanged();
219 }
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
A widget used to define a glyph object.
void setRotation(ParameterValue *value)
The Rotation element gives the rotation of a graphic in the clockwise direction about its center poin...
Definition: Graphic.cpp:125
A widget used to define the general properties of a se object.
te::se::Mark * getMark() const
Gets the configured mark element.
A widget used to define the mark se properties.
void setOpacity(ParameterValue *value)
The Opacity element gives the opacity to use for rendering the graphic. It has the same semantics as ...
Definition: Graphic.cpp:103
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
const std::vector< ExternalGraphic * > getExternalGraphics() const
Definition: Graphic.cpp:76
te::qt::widgets::WellKnownMarkPropertyItem * m_mp
A widget used to define a local image graphic for a se symbolizer.
void setSize(ParameterValue *value)
The Size element gives the absolute size of the graphic in uoms encoded as a floating-point number...
Definition: Graphic.cpp:114
void clear()
Clears the marks and the external graphics of this graphic.
Definition: Graphic.cpp:158
te::se::Mark * getMark() const
Gets the configured mark element.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
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
A widget used to define a glyph object.
const te::xl::SimpleLink * getOnlineResource() const
A widget used to define the general properties of a se object.
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
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
te::se::ExternalGraphic * getExternalGraphic() const
Gets the configured mark element.
URI C++ Library.
Definition: Attributes.h:37
A widget used to define the mark se properties.
const std::string * getWellKnownName() const
Definition: Mark.cpp:60
ParameterValue * clone() const
It creates a new copy of this object.
GraphicProperty(QWidget *parent)
Constructor.
bool setGraphic(const te::se::Graphic *graphic)
const std::vector< Mark * > getMarks() const
Definition: Graphic.cpp:98
void setExternalGraphic(const te::se::ExternalGraphic *eg)
Sets a mark element to this widget.
te::qt::widgets::GraphicPropertyItem * m_graphp
te::se::Graphic * getGraphic() const
bool setGraphic(const te::se::Graphic *graphic)
te::qt::widgets::LocalImagePropertyItem * m_li
A widget used to define a local image graphic for a se symbolizer.
const ParameterValue * getSize() const
Definition: Graphic.cpp:120
te::qt::widgets::GlyphMarkPropertyItem * m_gp
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109