All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WellKnownMarkPropertyItem.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/WellKnownMarkPropertyItem.cpp
22 
23  \brief A widget used to define the mark se properties.
24 */
25 
26 // TerraLib
27 #include "../../../se/Mark.h"
28 #include "../../../maptools/MarkRendererManager.h"
29 #include "../propertybrowser/AbstractPropertyManager.h"
30 #include "BasicFillPropertyItem.h"
33 
34 // STL
35 #include <cassert>
36 
37 
38 te::qt::widgets::WellKnownMarkPropertyItem::WellKnownMarkPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c) ,
39  m_mark(new te::se::Mark), m_setLocalMark(false)
40 {
41  //build property browser basic fill
42  QtProperty* markProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("WellKnown Mark"));
43 
44  //color
45  m_typeProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->addProperty(tr("Type"));
47  markProperty->addSubProperty(m_typeProperty);
48 
49  addProperty(markProperty, tr("Mark"), QColor(255, 175, 175));
50 
53 
54  connect(m_bf, SIGNAL(fillChanged()), SLOT(onFillChanged()));
55  connect(m_bs, SIGNAL(strokeChanged()), SLOT(onStrokeChanged()));
56 
57  // Setups initial mark
58  m_mark->setWellKnownName(new std::string(m_supportedMarks[0]));
61 
62 }
63 
65 {
66 }
67 
69 {
70  assert(mark);
71 
72  delete m_mark;
73 
74  m_mark = mark->clone();
75 
76  m_setLocalMark = true;
77 
78  updateUi();
79 
80  m_setLocalMark = false;
81 }
82 
84 {
85  return m_mark->clone();
86 }
87 
89 {
90  const std::string* name = m_mark->getWellKnownName();
91  assert(name); // TODO: Exception?
92 
93  std::map<int, std::string>::iterator it = m_supportedMarksMap.begin();
94 
95  while(it != m_supportedMarksMap.end())
96  {
97  if(it->second == *name)
98  {
99  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setValue(m_typeProperty, it->first);
100  break;
101  }
102  ++it;
103  }
104 
105  const te::se::Stroke* stroke = m_mark->getStroke();
106  if(stroke)
107  m_bs->setStroke(stroke);
108 
109  const te::se::Fill* fill = m_mark->getFill();
110  if(fill)
111  m_bf->setFill(fill);
112 }
113 
115 {
116  if(p == m_typeProperty)
117  {
118  m_mark->setWellKnownName(new std::string(m_supportedMarksMap[value]));
119 
120  if(!m_setLocalMark)
121  emit markChanged();
122  }
123 }
124 
126 {
127  QStringList l;
128 
129  te::map::MarkRendererManager::getInstance().getAllSupportedMarks(m_supportedMarks);
130 
131  for(std::size_t i = 0; i < m_supportedMarks.size(); ++i)
132  {
133  l << m_supportedMarks[i].c_str();
134 
135  m_supportedMarksMap.insert(std::map<int, std::string>::value_type(i, m_supportedMarks[i]));
136  }
137 
138  return l;
139 }
140 
142 {
143  m_mark->setStroke(m_bs->getStroke());
144 
145  if(!m_setLocalMark)
146  emit markChanged();
147 }
148 
150 {
151  m_mark->setFill(m_bf->getFill());
152 
153  if(!m_setLocalMark)
154  emit markChanged();
155 }
void setMark(const te::se::Mark *mark)
Sets a mark element to this widget.
std::vector< std::string > m_supportedMarks
Names of supported marks.
te::se::Mark * getMark() const
Gets the configured mark element.
A widget used to define the main property items that can be used to describe a se object...
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
void setFill(Fill *f)
Definition: Mark.cpp:108
WellKnownMarkPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
te::se::Mark * m_mark
Mark element that will be configured by this widget.
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
A widget used to define the basic fill se object.
te::se::Stroke * getStroke() const
Gets the configured stroke element.
A widget used to define the mark se properties.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
te::qt::widgets::BasicStrokePropertyItem * m_bs
void addProperty(QtProperty *property, const QString &id, QColor c)
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
void setStroke(Stroke *s)
Definition: Mark.cpp:119
te::qt::widgets::BasicFillPropertyItem * m_bf
Mark * clone() const
It creates a new copy of this object.
Definition: Mark.cpp:130
A widget used to define the basic fill se object.
void setWellKnownName(std::string *name)
The WellKnownName element gives the well-known name of the shape of the mark.
Definition: Mark.cpp:54
A widget used to define the basic fill se object.
virtual void valueChanged(QtProperty *p, int value)
void updateUi()
Updates the widget form based on internal mark element.