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  if (!m_supportedMarks.empty())
59  m_mark->setWellKnownName(new std::string(m_supportedMarks[0]));
60 
63 
64 }
65 
67  default;
68 
70 {
71  assert(mark);
72 
73  delete m_mark;
74 
75  m_mark = mark->clone();
76 
77  m_setLocalMark = true;
78 
79  updateUi();
80 
81  m_setLocalMark = false;
82 }
83 
85 {
86  return m_mark->clone();
87 }
88 
90 {
91  const std::string* name = m_mark->getWellKnownName();
92  assert(name); // TODO: Exception?
93 
94  std::map<int, std::string>::iterator it = m_supportedMarksMap.begin();
95 
96  while(it != m_supportedMarksMap.end())
97  {
98  if(it->second == *name)
99  {
100  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setValue(m_typeProperty, it->first);
101  break;
102  }
103  ++it;
104  }
105 
106  const te::se::Stroke* stroke = m_mark->getStroke();
107  if(stroke)
108  m_bs->setStroke(stroke);
109 
110  const te::se::Fill* fill = m_mark->getFill();
111  if(fill)
112  m_bf->setFill(fill);
113 }
114 
116 {
117  if(p == m_typeProperty)
118  {
119  m_mark->setWellKnownName(new std::string(m_supportedMarksMap[value]));
120 
121  if(!m_setLocalMark)
122  emit markChanged();
123  }
124 }
125 
127 {
128  QStringList l;
129 
131 
132  for(std::size_t i = 0; i < m_supportedMarks.size(); ++i)
133  {
134  l << m_supportedMarks[i].c_str();
135 
136  m_supportedMarksMap.insert(std::map<int, std::string>::value_type(static_cast<int>(i), m_supportedMarks[i]));
137  }
138 
139  return l;
140 }
141 
143 {
145 
146  if(!m_setLocalMark)
147  emit markChanged();
148 }
149 
151 {
152  m_mark->setFill(m_bf->getFill());
153 
154  if(!m_setLocalMark)
155  emit markChanged();
156 }
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.
URI C++ Library.
Definition: Attributes.h:37
te::se::Stroke * getStroke() const
Gets the configured stroke element.
te::gm::Polygon * p
A widget used to define the mark se properties.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
const std::string * getWellKnownName() const
Definition: Mark.cpp:60
te::qt::widgets::BasicStrokePropertyItem * m_bs
const Stroke * getStroke() const
Definition: Mark.cpp:125
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.
void setStroke(const te::se::Stroke *stroke)
Sets a stroke element to this widget.
virtual void valueChanged(QtProperty *p, int value)
void updateUi()
Updates the widget form based on internal mark element.
const Fill * getFill() const
Definition: Mark.cpp:114