All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
47 
49  m_setLocalGraphic(false), m_graphic(new te::se::Graphic)
50 {
51  QGridLayout* layout = new QGridLayout(this);
52  this->setLayout(layout);
53 
54  QToolBox* tb = new QToolBox(this);
55  layout->addWidget(tb);
56 
57  QtTreePropertyBrowser* graphBrowser = new QtTreePropertyBrowser(this);
58  graphBrowser->setIndentation(10);
59  graphBrowser->setPropertiesWithoutValueMarked(true);
60  graphBrowser->setRootIsDecorated(false);
61  graphBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
62 
64  tb->addItem(graphBrowser, "Graphic Properties");
65 
66  QtTreePropertyBrowser* wkBrowser = new QtTreePropertyBrowser(this);
67  wkBrowser->setIndentation(10);
68  wkBrowser->setPropertiesWithoutValueMarked(true);
69  wkBrowser->setRootIsDecorated(false);
70  wkBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
71 
73  tb->addItem(wkBrowser, "Well Known Mark");
74 
75  QtTreePropertyBrowser* gpBrowser = new QtTreePropertyBrowser(this);
76  gpBrowser->setIndentation(10);
77  gpBrowser->setPropertiesWithoutValueMarked(true);
78  gpBrowser->setRootIsDecorated(false);
79  gpBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
80 
82  tb->addItem(gpBrowser, "Glyph Mark");
83 
84  QtTreePropertyBrowser* liBrowser = new QtTreePropertyBrowser(this);
85  liBrowser->setIndentation(10);
86  liBrowser->setPropertiesWithoutValueMarked(true);
87  liBrowser->setRootIsDecorated(false);
88  liBrowser->setResizeMode(QtTreePropertyBrowser::ResizeToContents);
89 
91  tb->addItem(liBrowser, "Local Image");
92 
93  connect(m_graphp, SIGNAL(graphicChanged()), this, SLOT(onGraphicPropertyChanged()));
94  connect(m_mp, SIGNAL(markChanged()), this, SLOT(onWellKnownMarkChanged()));
95  connect(m_gp, SIGNAL(markChanged()), this, SLOT(onGlyphMarkChanged()));
96  connect(m_li, SIGNAL(externalGraphicChanged()), this, SLOT(onLocalImageChanged()));
97 
98  // Setups initial graphic
100 }
101 
103 {
104 }
105 
107 {
108  assert(graphic);
109 
110  delete m_graphic;
111 
112  m_setLocalGraphic = true;
113 
114  m_graphic = graphic->clone();
115 
116  m_graphp->setGraphic(m_graphic);
117 
118  // Verifying if this widget can deal with the given graphic...
119  const std::vector<te::se::Mark*> marks = m_graphic->getMarks();
120  if(marks.empty() == false)
121  {
122  te::se::Mark* mark = marks[0];
123  const std::string* name = mark->getWellKnownName();
124  if(name != 0)
125  {
126  std::size_t found = name->find("ttf://");
127  if(found != std::string::npos)
128  m_gp->setMark(marks[0]);
129 
130  found = name->find("://");
131  if(found == std::string::npos)
132  m_mp->setMark(marks[0]);
133  }
134  }
135 
136  const std::vector<te::se::ExternalGraphic*> extGraphics = m_graphic->getExternalGraphics();
137  if(extGraphics.empty() == false)
138  {
139  te::se::ExternalGraphic* g = extGraphics[0];
140  const te::xl::SimpleLink* link = g->getOnlineResource();
141  if(link == 0)
142  return false;
143 
144  const std::string href = link->getHref();
145  if(href.empty())
146  return false;
147 
148  QImage img;
149  if(!img.load(href.c_str()))
150  return false;
151 
152  // I know it!
153  m_li->setExternalGraphic(g);
154  }
155 
156  m_setLocalGraphic = false;
157 
158  return true;
159 }
160 
162 {
163  return m_graphic->clone();
164 }
165 
167 {
168  te::se::Graphic* g = m_graphp->getGraphic();
169 
170  if(g->getSize())
171  m_graphic->setSize(g->getSize()->clone());
172 
173  if(g->getRotation())
174  m_graphic->setRotation(g->getRotation()->clone());
175 
176  if(g->getOpacity())
177  m_graphic->setOpacity(g->getOpacity()->clone());
178 
179  if(!m_setLocalGraphic)
180  emit graphicChanged();
181 }
182 
184 {
185  te::se::Mark* mark = m_mp->getMark();
186  if(!mark)
187  return;
188 
189  m_graphic->clear();
190  m_graphic->add(mark);
191 
192 
193  if(!m_setLocalGraphic)
194  emit graphicChanged();
195 }
196 
198 {
199  te::se::Mark* mark = m_gp->getMark();
200  if(!mark)
201  return;
202 
203  m_graphic->clear();
204  m_graphic->add(mark);
205 
206 
207  if(!m_setLocalGraphic)
208  emit graphicChanged();
209 }
210 
212 {
213  te::se::ExternalGraphic* eg = m_li->getExternalGraphic();
214  if(!eg)
215  return;
216 
217  m_graphic->clear();
218  m_graphic->add(eg);
219 
220  if(!m_setLocalGraphic)
221  emit graphicChanged();
222 }
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
A widget used to define a glyph object.
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.
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
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
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
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.
const std::vector< Mark * > getMarks() const
Definition: Graphic.cpp:98
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
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109