All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PolygonSymbolizerWidget.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/PolygonSymbolizerWidget.cpp
22 
23  \brief A widget used to build a polygon symbolizer element.
24 */
25 
26 // TerraLib
27 #include "../../../se/PolygonSymbolizer.h"
28 #include "AbstractFillWidget.h"
30 #include "BasicStrokeWidget.h"
32 #include "ui_PolygonSymbolizerWidgetForm.h"
33 
34 // Qt
35 #include <QStackedWidget>
36 
37 // STL
38 #include <cassert>
39 #include <string>
40 #include <vector>
41 
43  : QWidget(parent, f),
44  m_ui(new Ui::PolygonSymbolizerWidgetForm),
45  m_symb(new te::se::PolygonSymbolizer)
46 {
47  m_ui->setupUi(this);
48 
49  m_ui->m_mainLayout->setAlignment(Qt::AlignTop);
50 
51  // Stack of Fill Widgets
52  m_fillWidgets = new QStackedWidget(this);
53 
54  // Adjusting...
55  QGridLayout* fillLayout = new QGridLayout(m_ui->m_fillGroupBox);
56  fillLayout->addWidget(m_fillWidgets);
57  fillLayout->setAlignment(Qt::AlignTop);
58 
59  // Gets registered fill widgets
60  std::vector<std::string> keys;
62  std::vector<std::string>::iterator it;
63  for(it = keys.begin(); it != keys.end(); ++it)
64  {
66  m_ui->m_polygonSymbolizerTypeComboBox->addItem(fw->getFillType());
67  connect(fw, SIGNAL(fillChanged()), SLOT(onFillChanged()));
68  m_fillWidgets->addWidget(fw);
69  }
70 
71  // Stroke Widget
73 
74  // Adjusting...
75  QGridLayout* strokeLayout = new QGridLayout(m_ui->m_strokeGroupBox);
76  strokeLayout->addWidget(m_strokeWidget);
77  strokeLayout->setAlignment(Qt::AlignTop);
78 
79  // Setups initial polygon symbolizer
81  m_symb->setFill(w->getFill());
83 
84  // Signals & slots
85  connect(m_ui->m_polygonSymbolizerTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onPolygonSymbolizerTypeComboBoxCurrentIndexChanged(int)));
86  connect(m_ui->m_fillGroupBox, SIGNAL(toggled(bool)), this, SLOT(onFillGroupBoxToggled(bool)));
87  connect(m_strokeWidget, SIGNAL(strokeChanged()), SLOT(onStrokeChanged()));
88  connect(m_ui->m_strokeGroupBox, SIGNAL(toggled(bool)), this, SLOT(onStrokeGroupBoxToggled(bool)));
89 }
90 
92 {
93  delete m_symb;
94 }
95 
97 {
98  assert(symb);
99 
100  delete m_symb;
101 
102  m_symb = static_cast<te::se::PolygonSymbolizer*>(symb->clone());
103 
104  updateUi();
105 }
106 
108 {
109  return m_symb->clone();
110 }
111 
113 {
114  const te::se::Stroke* stroke = m_symb->getStroke();
115  if(stroke)
116  {
117  m_strokeWidget->setStroke(stroke);
118  m_ui->m_strokeGroupBox->setChecked(true);
119  }
120  else
121  m_ui->m_strokeGroupBox->setChecked(false);
122 
123  const te::se::Fill* fill = m_symb->getFill();
124  if(fill == 0)
125  {
126  m_ui->m_fillGroupBox->setChecked(false);
127  return;
128  }
129 
130  // Updating UI fill element
131  int i;
132  for(i = 0; i < m_fillWidgets->count(); ++i)
133  {
134  te::qt::widgets::AbstractFillWidget* fw = static_cast<te::qt::widgets::AbstractFillWidget*>(m_fillWidgets->widget(i));
135  if(fw->setFill(fill))
136  break;
137  }
138 
139  if(i == m_fillWidgets->count())
140  return; // TODO: Exception! The polygon symbolizer fill cannot be dealt by any registered graphic widgets.
141 
142  // Updating Ui
143  m_ui->m_polygonSymbolizerTypeComboBox->setCurrentIndex(i);
144  m_fillWidgets->setCurrentIndex(i);
145 }
146 
148 {
149  m_fillWidgets->setCurrentIndex(index);
150 
151  te::qt::widgets::AbstractFillWidget* w = static_cast<te::qt::widgets::AbstractFillWidget*>(m_fillWidgets->currentWidget());
152  m_symb->setFill(w->getFill());
153 
154  emit symbolizerChanged();
155 }
156 
158 {
159  m_symb->setStroke(m_strokeWidget->getStroke());
160  emit symbolizerChanged();
161 }
162 
164 {
165  if(on == false)
166  m_symb->setStroke(0);
167  else
168  m_symb->setStroke(m_strokeWidget->getStroke());
169 
170  emit symbolizerChanged();
171 }
172 
174 {
175  te::qt::widgets::AbstractFillWidget* w = static_cast<te::qt::widgets::AbstractFillWidget*>(m_fillWidgets->currentWidget());
176  m_symb->setFill(w->getFill());
177 
178  emit symbolizerChanged();
179 }
180 
182 {
183  if(on == false)
184  m_symb->setFill(0);
185  else
186  {
187  te::qt::widgets::AbstractFillWidget* w = static_cast<te::qt::widgets::AbstractFillWidget*>(m_fillWidgets->currentWidget());
188  m_symb->setFill(w->getFill());
189  }
190 
191  emit symbolizerChanged();
192 }
std::auto_ptr< Ui::PolygonSymbolizerWidgetForm > m_ui
Widget form.
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
Abstract class that represents a widget that can be used to build a fill element. ...
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
Abstract class that represents a widget that can be used to build a fill element. ...
A widget used to build a basic stroke element.
te::qt::widgets::BasicStrokeWidget * m_strokeWidget
Basic Stroke Widget used to configure the polygon symbolizer stroke element.
virtual QString getFillType() const =0
Pure virtual method that should return a "user friendly" string that informs the fill type that can b...
The abstract factory of widgets used to configure Symbology Enconding Fill element.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
PolygonSymbolizerWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a polygon symbolizer widget which is a child of parent, with widget flags set to f...
static AbstractFillWidget * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
QStackedWidget * m_fillWidgets
Set of Fill Widgets that can be used to configure the polygon symbolizer element. TODO: need review! ...
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
virtual te::se::Fill * getFill() const =0
Gets the configured fill element.
void setStroke(Stroke *stroke)
A Stroke specifies the appearance of a linear geometry.
void setSymbolizer(const te::se::PolygonSymbolizer *symb)
Sets a polygon symbolizer element to this widget.
Symbolizer * clone() const
It creates a new copy of this object.
A widget used to build a basic stroke element.
void setFill(Fill *f)
A Fill specifies the pattern for filling an area geometry.
static void RegisteredWidgets(std::vector< std::string > &keys)
It informs the key of each registered fill widget factory.
te::se::PolygonSymbolizer * m_symb
Polygon symbolizer element that will be configured by this widget.
virtual Symbolizer * clone() const =0
It creates a new copy of this object.
te::se::Stroke * getStroke() const
Gets the configured stroke element.
A widget used to build a polygon symbolizer element.
virtual bool setFill(const te::se::Fill *fill)=0
Sets a fill element to this widget.
void updateUi()
Updates the widget form based on internal polygon symbolizer element.
te::se::Symbolizer * getSymbolizer() const
Gets the configured polygon symbolizer element.