All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GraphicProperty.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 "../../../../../third-party/qt/propertybrowser/qtpropertybrowser.h"
38 #include <QtGui/QGridLayout>
39 #include <QtGui/QToolBox>
40 
41 // STL
42 #include <cassert>
43 
44 
46  m_setLocalGraphic(false), m_graphic(new te::se::Graphic)
47 {
48  QGridLayout* layout = new QGridLayout(this);
49  this->setLayout(layout);
50 
51  QToolBox* tb = new QToolBox(this);
52  layout->addWidget(tb);
53 
54  QtTreePropertyBrowser* graphBrowser = new QtTreePropertyBrowser(this);
55  graphBrowser->setIndentation(10);
56  graphBrowser->setPropertiesWithoutValueMarked(true);
57  graphBrowser->setRootIsDecorated(false);
58  graphBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
59 
61  tb->addItem(graphBrowser, "Graphic Properties");
62 
63  QtTreePropertyBrowser* wkBrowser = new QtTreePropertyBrowser(this);
64  wkBrowser->setIndentation(10);
65  wkBrowser->setPropertiesWithoutValueMarked(true);
66  wkBrowser->setRootIsDecorated(false);
67  wkBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
68 
70  tb->addItem(wkBrowser, "Well Known Mark");
71 
72  QtTreePropertyBrowser* gpBrowser = new QtTreePropertyBrowser(this);
73  gpBrowser->setIndentation(10);
74  gpBrowser->setPropertiesWithoutValueMarked(true);
75  gpBrowser->setRootIsDecorated(false);
76  gpBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
77 
79  tb->addItem(gpBrowser, "Glyph Mark");
80 
81  QtTreePropertyBrowser* liBrowser = new QtTreePropertyBrowser(this);
82  liBrowser->setIndentation(10);
83  liBrowser->setPropertiesWithoutValueMarked(true);
84  liBrowser->setRootIsDecorated(false);
85  liBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
86 
88  tb->addItem(liBrowser, "Local Image");
89 
90  connect(m_graphp, SIGNAL(graphicChanged()), this, SLOT(onGraphicPropertyChanged()));
91  connect(m_mp, SIGNAL(markChanged()), this, SLOT(onWellKnownMarkChanged()));
92  connect(m_gp, SIGNAL(markChanged()), this, SLOT(onGlyphMarkChanged()));
93  connect(m_li, SIGNAL(externalGraphicChanged()), this, SLOT(onLocalImageChanged()));
94 
95  // Setups initial graphic
97 }
98 
100 {
101 }
102 
104 {
105  assert(graphic);
106 
107  delete m_graphic;
108 
109  m_setLocalGraphic = true;
110 
111  m_graphic = graphic->clone();
112 
113  m_graphp->setGraphic(m_graphic);
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 != 0)
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];
137  const te::xl::SimpleLink* link = g->getOnlineResource();
138  if(link == 0)
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!
150  m_li->setExternalGraphic(g);
151  }
152 
153  m_setLocalGraphic = false;
154 
155  return true;
156 }
157 
159 {
160  return m_graphic->clone();
161 }
162 
164 {
165  te::se::Graphic* g = m_graphp->getGraphic();
166 
167  if(g->getSize())
168  m_graphic->setSize(g->getSize()->clone());
169 
170  if(g->getRotation())
171  m_graphic->setRotation(g->getRotation()->clone());
172 
173  if(g->getOpacity())
174  m_graphic->setOpacity(g->getOpacity()->clone());
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 {
210  te::se::ExternalGraphic* eg = m_li->getExternalGraphic();
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 te::xl::SimpleLink * getOnlineResource() const
ParameterValue * clone() const
It creates a new copy of this object.
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::se::Mark * getMark() const
Gets the configured mark element.
A widget used to define the general properties of a se object.
A widget used to define a glyph object.
te::se::Graphic * getGraphic() const
const std::string & getHref() const
Definition: SimpleLink.cpp:50
A widget used to define the mark se properties.
GraphicProperty(QWidget *parent)
Constructor.
const std::string * getWellKnownName() const
Definition: Mark.cpp:60
The ExternalGraphic allows a reference to be made to an external graphic file with a Web URL or to in...
te::qt::widgets::LocalImagePropertyItem * m_li
Simple link.
Definition: SimpleLink.h:48
bool setGraphic(const te::se::Graphic *graphic)
A widget used to define a local image graphic for a se symbolizer.
Graphic * clone() const
It creates a new copy of this object.
Definition: Graphic.cpp:167
te::qt::widgets::GlyphMarkPropertyItem * m_gp
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109
A widget used to define a glyph object.
const ParameterValue * getSize() const
Definition: Graphic.cpp:120
A widget used to define a local image graphic for a se symbolizer.
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
te::qt::widgets::WellKnownMarkPropertyItem * m_mp
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
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
te::qt::widgets::GraphicPropertyItem * m_graphp
A widget used to define the general properties of a se object.
A widget used to define the mark se properties.
const std::vector< Mark * > getMarks() const
Definition: Graphic.cpp:98
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84