All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StyleControllerWidget.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/StyleControllerWidget.cpp
22 
23  \brief A widget used to controll the style se element.
24 */
25 
26 // TerraLib
27 #include "../../../se/Rule.h"
28 #include "../../../se/Symbolizer.h"
29 #include "ui_StyleControllerWidgetForm.h"
30 #include "StyleControllerWidget.h"
31 #include "StyleExplorer.h"
32 #include "Symbol.h"
33 #include "SymbolPreviewWidget.h"
34 #include "SymbolSelectorDialog.h"
35 
36 // Qt
37 #include <QMessageBox>
38 
39 // STL
40 #include <cassert>
41 
43  : QWidget(parent, f),
44  m_ui(new Ui::StyleControllerWidgetForm)
45 {
46  m_ui->setupUi(this);
47 
48  // Add the StyleExplorer
49  m_explorer = new te::qt::widgets::StyleExplorer(m_ui->m_explorerFrame);
50  QGridLayout* le = new QGridLayout(m_ui->m_explorerFrame);
51  le->setContentsMargins(0, 0, 0, 0);
52  le->addWidget(m_explorer);
53 
54  // Signals & slots
55  connect(m_ui->m_iconSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(changeLegendIconSize(int)));
56  connect(m_ui->m_addSymbToolButton, SIGNAL(clicked()), this, SLOT(onAddSymbolizerClicked()));
57  connect(m_ui->m_removeSymbToolButton, SIGNAL(clicked()), this, SLOT(onRemoveSymbolizerClicked()));
58  connect(m_ui->m_upSymbToolButton, SIGNAL(clicked()), this, SLOT(onUpSymbolizerClicked()));
59  connect(m_ui->m_downSymbToolButton, SIGNAL(clicked()), this, SLOT(onDownSymbolizerClicked()));
60  connect(m_ui->m_libManagerToolButton, SIGNAL(clicked()), this, SLOT(onLibraryManagerClicked()));
61  connect(m_ui->m_mapRefreshToolButton, SIGNAL(clicked()), this, SLOT(onMapRefreshClicked()));
62 
63  updateUi();
64 }
65 
67 {
68 }
69 
71 {
72  m_explorer->setStyle(style);
73 }
74 
76 {
77  return m_explorer;
78 }
79 
81 {
82  m_ui->m_upSymbToolButton->setIcon(QIcon::fromTheme("go-up").pixmap(16,16));
83  m_ui->m_downSymbToolButton->setIcon(QIcon::fromTheme("go-down").pixmap(16,16));
84  m_ui->m_addSymbToolButton->setIcon(QIcon::fromTheme("list-add").pixmap(16,16));
85  m_ui->m_removeSymbToolButton->setIcon(QIcon::fromTheme("list-remove").pixmap(16,16));
86  m_ui->m_libManagerToolButton->setIcon(QIcon::fromTheme("library").pixmap(16,16));
87  m_ui->m_mapRefreshToolButton->setIcon(QIcon::fromTheme("map-draw").pixmap(16,16));
88 }
89 
91 {
92  te::se::Rule* rule = m_explorer->getCurrentRule();
93 
94  if(rule == 0)
95  {
96  QMessageBox::information(this, tr("Style"), tr("Select a rule first."));
97  return;
98  }
99 
100  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
101 
102  if(symb)
103  rule->push_back(symb->clone());
104  else
105  {
106  assert(!rule->getSymbolizers().empty());
107 
108  const te::se::Symbolizer* symb = rule->getSymbolizer(0);
109  assert(symb);
110 
111  rule->push_back(symb->clone());
112  }
113 
114  m_explorer->updateStyleTree();
115 }
116 
118 {
119  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
120 
121  if(symb == 0)
122  {
123  QMessageBox::information(this, tr("Style"), tr("Select a symbol first."));
124  return;
125  }
126 
127  te::se::Rule* rule = m_explorer->getCurrentRule();
128  assert(rule);
129 
130  if(rule->getSymbolizers().size() == 1)
131  {
132  QMessageBox::information(this, tr("Style"), tr("The rule must have at least one symbol."));
133  return;
134  }
135 
136  for(std::size_t i = 0; i < rule->getSymbolizers().size(); ++i)
137  {
138  if(rule->getSymbolizer(i) == symb)
139  {
140  rule->removeSymbolizer(i);
141  break;
142  }
143  }
144 
145  m_explorer->updateStyleTree();
146 }
147 
149 {
150  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
151 
152  if(symb == 0)
153  {
154  QMessageBox::information(this, tr("Style"), tr("Select a symbol first."));
155  return;
156  }
157 
158  m_explorer->goUpSymbolizer();
159 }
160 
162 {
163  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
164 
165  if(symb == 0)
166  {
167  QMessageBox::information(this, tr("Style"), tr("Select a symbol first."));
168  return;
169  }
170 
171  m_explorer->goDownSymbolizer();
172 }
173 
175 {
176  te::se::Rule* rule = m_explorer->getCurrentRule();
177 
178  if(!rule)
179  {
180  QMessageBox::information(this, tr("Style"), tr("Select a rule first."));
181  return;
182  }
183 
184  Symbol* symbol = te::qt::widgets::SymbolSelectorDialog::getSymbol(this, tr("Symbol Selector"));
185  if(symbol == 0)
186  return;
187 
188  std::vector<te::se::Symbolizer*> symbolizers;
189  for(std::size_t i = 0; i < symbol->getSymbolizersCount(); ++i)
190  symbolizers.push_back(symbol->getSymbolizer(i)->clone());
191 
192  rule->setSymbolizers(symbolizers);
193 
194  m_explorer->updateStyleTree();
195 }
196 
198 {
199  emit mapRefresh();
200 }
201 
203 {
204  m_explorer->setLegendIconSize(size);
205 }
te::se::Symbolizer * getSymbolizer(const std::size_t &i) const
It returns the n-th Symbolizer.
Definition: Symbol.cpp:65
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
A widget used to preview symbol elements.
This class represents a symbol.
std::size_t getSymbolizersCount() const
It returns the number of Symbolizers that compose of the symbol.
Definition: Symbol.cpp:60
std::auto_ptr< Ui::StyleControllerWidgetForm > m_ui
Widget form.
A widget used to explore a style.
Definition: StyleExplorer.h:60
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
void push_back(Symbolizer *s)
Definition: Rule.cpp:138
A dialog used to select a specific symbol.
A widget used to explore a style.
Symbol * getSymbol() const
Gets the selected symbol.
StyleControllerWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a StyleControllerWidget which is a child of parent, with widget flags set to f...
A widget used to controll the style se element.
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
void setSymbolizers(const std::vector< Symbolizer * > &symbs)
Definition: Rule.cpp:152
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:158
void removeSymbolizer(std::size_t i)
Definition: Rule.cpp:169
void setStyle(te::se::Style *style)
Sets a style element to this widget.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:78
void updateUi()
Updates the widget form based on internal mark element.
te::qt::widgets::StyleExplorer * m_explorer
A style explorer used to explore the style.
virtual Symbolizer * clone() const =0
It creates a new copy of this object.
const Symbolizer * getSymbolizer(std::size_t i) const
Definition: Rule.cpp:163