TextPropertyItem.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/TextPropertyItem.cpp
22 
23  \brief A widget used to define the text se object.
24 */
25 
26 
27 #include "../../../common/StringUtils.h"
28 #include "../../../se/SvgParameter.h"
29 #include "../../../se/TextSymbolizer.h"
30 #include "../../../se/Utils.h"
31 #include "../propertybrowser/AbstractPropertyManager.h"
32 #include "BasicFillPropertyItem.h"
33 #include "TextPropertyItem.h"
34 
35 // STL
36 #include <cassert>
37 
38 // QtPropertyBrowser
39 
40 
41 te::qt::widgets::TextPropertyItem::TextPropertyItem(QtTreePropertyBrowser* pb, QColor c) : te::qt::widgets::AbstractPropertyItem(pb, c),
42  m_textSymbolizer(new te::se::TextSymbolizer)
43 {
44  //build property browser basic fill
45  QtProperty* textProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_groupManager->addProperty(tr("Text Properties"));
46 
47  //label
48  QStringList emptyList;
49  m_labelProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->addProperty(tr("Label"));
50  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setEnumNames(m_labelProperty, emptyList);
51  textProperty->addSubProperty(m_labelProperty);
52 
53  //font
54  m_fontProperty = te::qt::widgets::AbstractPropertyManager::getInstance().m_fontManager->addProperty(tr("Font"));
55  textProperty->addSubProperty(m_fontProperty);
56 
57  addProperty(textProperty, tr("Text Properties"), QColor(89, 230, 226));
58 
60 
61  connect(m_bf, SIGNAL(fillChanged()), SLOT(onFillChanged()));
62 
63  // Setups initial fill
65 
66  m_update = true;
67 }
68 
70 {
71  delete m_textSymbolizer;
72 }
73 
75 {
76  if (!m_update)
77  return;
78 
79  if (p == m_labelProperty)
80  {
81  m_update = false;
82 
84 
85  emit textChanged();
86  m_update = true;
87  }
88 }
89 
90 void te::qt::widgets::TextPropertyItem::valueChanged(QtProperty* p, const QFont &value)
91 {
92  if (!m_update)
93  return;
94 
95  if (p == m_fontProperty)
96  {
97  m_update = false;
98 
99  QFont f = value;
100 
101  int fontStyle = f.style();
102  int weightStyle = f.weight();
103 
104  // Updating text
105  te::se::Font* font = new te::se::Font();
106  font->setFamily(f.family().toUtf8().data());
107  font->setSize(te::common::Convert2String(f.pointSize()));
108  font->setStyle((te::se::Font::FontStyleType)fontStyle);
109  font->setWeight((te::se::Font::FontWeightType)weightStyle);
110 
111  m_textSymbolizer->setFont(font);
112 
113  emit textChanged();
114  m_update = true;
115  }
116 }
117 
119 {
121 
122  emit textChanged();
123 }
124 
126 {
127  assert(ts);
128 
129  // Verifying if this widget can deal with the given fill...
130  delete m_textSymbolizer;
131 
132  m_textSymbolizer = dynamic_cast<te::se::TextSymbolizer*>(ts->clone());
133 
134  updateUi();
135  m_update = true;
136 }
137 
138 void te::qt::widgets::TextPropertyItem::setLabels(std::vector<std::string> labels)
139 {
140  m_labels = labels;
141 
142  QStringList list;
143 
144  for (std::size_t i = 0; i < labels.size(); ++i)
145  {
146  list << labels[i].c_str();
147  }
148 
149  m_update = false;
150  te::qt::widgets::AbstractPropertyManager::getInstance().m_enumManager->setEnumNames(m_labelProperty, list);
151  m_update = true;
152 }
153 
155 {
156  return dynamic_cast<te::se::TextSymbolizer*>(m_textSymbolizer->clone());
157 }
158 
160 {
161  m_update = true;
162 
163  //update font
164  const te::se::Font* f = m_textSymbolizer->getFont();
165 
166  QFont font;
167  font.setFamily(te::se::GetString(f->getFamily()).c_str());
168  font.setPointSize(te::se::GetDouble(f->getSize()));
169  font.setStyle((QFont::Style)te::se::GetInt(f->getStyle()));
170 
171  std::string weightValue = te::se::GetString(f->getWeight());
172 
173  if (weightValue == "light")
174  font.setWeight(QFont::Light);
175  else if (weightValue == "normal")
176  font.setWeight(QFont::Normal);
177  else if (weightValue == "demibold")
178  font.setWeight(QFont::DemiBold);
179  else if (weightValue == "bold")
180  font.setWeight(QFont::Bold);
181  else if (weightValue == "black")
182  font.setWeight(QFont::Black);
183 
185 
186  //update label
187  std::string label = te::se::GetString(m_textSymbolizer->getLabel());
188 
189  for (std::size_t t = 0; t < m_labels.size(); ++t)
190  {
191  if (m_labels[t] == label)
192  {
194  break;
195  }
196  }
197 
198  //update fill
199  if (m_textSymbolizer->getFill())
201 
202  m_update = false;
203 }
204 
A TextSymbolizer is used to render text labels according to various graphical parameters.
std::vector< std::string > m_labels
void setLabels(std::vector< std::string > labels)
A widget used to define the main property items that can be used to describe a se object...
virtual void valueChanged(QtProperty *p, int value)
te::qt::widgets::BasicFillPropertyItem * m_bf
void setTextSymbolizer(const te::se::TextSymbolizer *ts)
const SvgParameter * getFamily() const
Definition: Font.cpp:88
void setSize(const std::string &size)
Definition: Font.cpp:83
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
te::se::TextSymbolizer * m_textSymbolizer
Fill element that will be configured by this widget.
const SvgParameter * getWeight() const
Definition: Font.cpp:98
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
const SvgParameter * getSize() const
Definition: Font.cpp:103
Symbolizer * clone() const
It creates a new copy of this object.
static AbstractPropertyManager & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
A Font specifies the text font to use in a text symbolizer.
Definition: Font.h:63
A widget used to define the text se object.
te::gm::Polygon * p
FontStyleType
It defines the style to use for a font.
Definition: Font.h:72
const Font * getFont() const
void addProperty(QtProperty *property, const QString &id, QColor c)
TextPropertyItem(QtTreePropertyBrowser *pb, QColor c=QColor())
Constructor.
void setWeight(const FontWeightType &weight)
Definition: Font.cpp:78
void setLabel(ParameterValue *l)
const ParameterValue * getLabel() const
void setFamily(const std::string &family)
Definition: Font.cpp:68
TESEEXPORT int GetInt(const te::se::ParameterValue *param)
It gets the parameter value as an integer.
const SvgParameter * getStyle() const
Definition: Font.cpp:93
void updateUi()
Updates the widget form based on internal fill element.
const Fill * getFill() const
A widget used to define the basic fill se object.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
void setStyle(const FontStyleType &style)
Definition: Font.cpp:73
FontWeightType
It gives the amount of weight or boldness to use for a font.
Definition: Font.h:84
A widget used to define the basic fill se object.
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
te::se::TextSymbolizer * getTextSymbolizer() const