All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SymbolEditorWidget.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/SymbolEditorWidget.cpp
22 
23  \brief A widget used to edit symbols.
24 */
25 
26 // TerraLib
27 #include "../../../common/STLUtils.h"
28 #include "../../../se/Symbolizer.h"
29 #include "LineSymbolizerWidget.h"
30 #include "PointSymbolizerWidget.h"
32 #include "Symbol.h"
33 #include "SymbolEditorWidget.h"
34 #include "SymbolPreviewWidget.h"
35 #include "SymbolTableWidget.h"
36 #include "ui_SymbolEditorWidgetForm.h"
37 
38 // Qt
39 #include <QStackedWidget>
40 
41 // STL
42 #include <cassert>
43 
45  : QWidget(parent),
46  m_ui(new Ui::SymbolEditorWidgetForm),
47  m_symbol(new Symbol),
48  m_type(type)
49 {
50  m_ui->setupUi(this);
51 
52  // Preview
53  m_preview = new SymbolPreviewWidget(QSize(120, 120), this);
54 
55  // Adjusting...
56  QGridLayout* previewLayout = new QGridLayout(m_ui->m_previewGroupBox);
57  previewLayout->addWidget(m_preview);
58 
59  // Layers
60  m_symbolTable = new SymbolTableWidget(QSize(120, 42), this);
61  m_symbolTable->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
62 
63  // Adjusting...
64  QGridLayout* symbolTableLayout = new QGridLayout(m_ui->m_symbolTableFrame);
65  symbolTableLayout->setContentsMargins(0, 0, 0, 0);
66  symbolTableLayout->addWidget(m_symbolTable);
67 
68  // Stacked symbolizers widgets
69  m_symbolizersStackedWidget = new QStackedWidget(this);
70 
71  // Adjusting...
72  QGridLayout* stackedLayout = new QGridLayout(m_ui->m_propertiesGroupBox);
73  stackedLayout->addWidget(m_symbolizersStackedWidget);
74 
75  initialize();
76 
77  // Signals & slots
78  connect(m_ui->m_addToolButton, SIGNAL(clicked()), SLOT(onAddToolButtonClicked()));
79  connect(m_ui->m_removeToolButton, SIGNAL(clicked()), SLOT(onRemoveToolButtonClicked()));
80  connect(m_ui->m_upToolButton, SIGNAL(clicked()), SLOT(onUpToolButtonClicked()));
81  connect(m_ui->m_downToolButton, SIGNAL(clicked()), SLOT(onDownToolButtonClicked()));
82  connect(m_symbolTable, SIGNAL(symbolizerClicked(int)), m_symbolizersStackedWidget, SLOT(setCurrentIndex(int)));
83 }
84 
86 {
87  delete m_symbol;
88 }
89 
91 {
92  // Creating the first symbolizer
93  createNewSymbolizer();
94 
95  // Setup icons
96  m_ui->m_addToolButton->setIcon(QIcon::fromTheme("list-add"));
97  m_ui->m_removeToolButton->setIcon(QIcon::fromTheme("list-remove"));
98  m_ui->m_upToolButton->setIcon(QIcon::fromTheme("go-up"));
99  m_ui->m_downToolButton->setIcon(QIcon::fromTheme("go-down"));
100 }
101 
103 {
104  m_preview->updatePreview(m_symbol);
105  m_symbolTable->updatePreview(m_symbol);
106 }
107 
109 {
110  QWidget* symbolizerWidget = 0;
111  switch(m_type)
112  {
113  case PointSymbol:
114  {
116  m_symbol->addSymbolizer(pts->getSymbolizer());
117  symbolizerWidget = pts;
118  }
119  break;
120 
121  case LineSymbol:
122  {
124  m_symbol->addSymbolizer(ls->getSymbolizer());
125  symbolizerWidget = ls;
126  }
127  break;
128 
129  case PolygonSymbol:
130  {
132  m_symbol->addSymbolizer(ps->getSymbolizer());
133  symbolizerWidget = ps;
134  }
135  break;
136  }
137  // Adding on stack
138  m_symbolizersStackedWidget->addWidget(symbolizerWidget);
139  // Connecting signal & slot
140  connect(symbolizerWidget, SIGNAL(symbolizerChanged()), SLOT(onSymbolizerChanged()));
141  // Makes this new widget the current
142  m_symbolizersStackedWidget->setCurrentIndex(m_symbolizersStackedWidget->count() - 1);
143 
144  // Updating preview
145  updateUi();
146 
147  // Select on symbolizer table
148  m_symbolTable->selectSymbolizer(m_symbol->getSymbolizersCount() - 1);
149 }
150 
151 void te::qt::widgets::SymbolEditorWidget::swapSymbolizers(const int& indexFirst, const int& indexSecond)
152 {
153  // Swap symbolizers
154  m_symbol->swapSymbolizers(indexFirst, indexSecond);
155 
156  // Swap widget symbolizers
157  QWidget* firstWidget = m_symbolizersStackedWidget->widget(indexFirst);
158  QWidget* secondWidget = m_symbolizersStackedWidget->widget(indexSecond);
159  m_symbolizersStackedWidget->insertWidget(indexFirst, secondWidget);
160  m_symbolizersStackedWidget->insertWidget(indexSecond, firstWidget);
161 }
162 
164 {
165  createNewSymbolizer();
166 }
167 
169 {
170  if(m_symbol->getSymbolizersCount() == 1) // We have only one symbolizer. No remove!
171  return;
172 
173  QWidget* w = m_symbolizersStackedWidget->currentWidget();
174 
175  int index = m_symbolizersStackedWidget->indexOf(w);
176  assert(index >= 0 && index < static_cast<int>(m_symbol->getSymbolizersCount()));
177 
178  // Removing symbolizer
179  m_symbol->removeSymbolizer(index);
180 
181  // Removing widget associated with the removed symbolizer
182  m_symbolizersStackedWidget->removeWidget(w);
183  delete w;
184 
185  updateUi();
186 
187  // Selection to upper symbolizer...
188  m_symbolTable->selectSymbolizer(index - 1);
189 }
190 
192 {
193  int index = m_symbolizersStackedWidget->currentIndex();
194  assert(index >= 0 && index < static_cast<int>(m_symbol->getSymbolizersCount()));
195 
196  if(index == 0) // Not go-up a top symbolizer!
197  return;
198 
199  // Swap
200  swapSymbolizers(index, index - 1);
201 
202  updateUi();
203 
204  // Selection to upper symbolizer...
205  m_symbolTable->selectSymbolizer(index - 1);
206 }
207 
209 {
210  int index = m_symbolizersStackedWidget->currentIndex();
211  assert(index >= 0 && index < static_cast<int>(m_symbol->getSymbolizersCount()));
212 
213  if(index == m_symbol->getSymbolizersCount() - 1) // Not go-down a down symbolizer!
214  return;
215 
216  // Swap
217  swapSymbolizers(index, index + 1);
218 
219  updateUi();
220 
221  // Selection to down symbolizer...
222  m_symbolTable->selectSymbolizer(index + 1);
223 }
224 
226 {
227  /* (Uba, 29/06/2012)
228  TODO: We can pass the new symbolizer on signal?!
229  So, we'll have:
230  te::qt::widgets::SymbolEditorWidget::onSymbolizerChanged(te::se::Symbolizer* symb)
231  {
232  int index = m_symbolizersStackedWidget->currentIndex();
233  assert(index >= 0 && index < static_cast<int>(m_symbs.size()));
234  m_symbol->setSymbolizer(index, symb);
235  }
236  */
237 
238  int index = m_symbolizersStackedWidget->currentIndex();
239  assert(index >= 0 && index < static_cast<int>(m_symbol->getSymbolizersCount()));
240 
241  QWidget* w = m_symbolizersStackedWidget->currentWidget();
242  switch(m_type)
243  {
244  case PointSymbol:
245  m_symbol->setSymbolizer(index, static_cast<PointSymbolizerWidget*>(w)->getSymbolizer());
246  break;
247 
248  case LineSymbol:
249  m_symbol->setSymbolizer(index, static_cast<LineSymbolizerWidget*>(w)->getSymbolizer());
250  break;
251 
252  case PolygonSymbol:
253  m_symbol->setSymbolizer(index, static_cast<PolygonSymbolizerWidget*>(w)->getSymbolizer());
254  break;
255  }
256  updateUi();
257 }
Enumeration that indicates the symbol type.
SymbolTableWidget * m_symbolTable
Table Widget used to visualize the symbol as separated visual layers.
A widget used to build a point symbolizer element.
A widget used to preview symbol elements.
This class represents a symbol.
void createNewSymbolizer()
Creates a new symbolizer element.
QStackedWidget * m_symbolizersStackedWidget
Set of symbolizers widgets.
A widget used to build a line symbolizer element.
void swapSymbolizers(const int &indexFirst, const int &indexSecond)
Swap two internal symbolizers.
SymbolPreviewWidget * m_preview
Preview Widget used to visualize the symbol.
std::auto_ptr< Ui::SymbolEditorWidgetForm > m_ui
Widget form.
A widget used to preview a symbol as separated layers.
void updateUi()
Updates the widget form based on internal symbolizers elements.
te::se::Symbolizer * getSymbolizer() const
Gets the configured point symbolizer element.
A widget used to edit symbols.
void initialize()
Internal method to initialize the widget.
A widget used to build a line symbolizer element.
SymbolEditorWidget(const SymbolType &type, QWidget *parent=0)
Constructs a symbol editor, which is a child of parent, with widget flags set to f.
te::se::Symbolizer * getSymbolizer() const
Gets the configured line symbolizer element.
This class represents a symbol. TODO: More description!
Definition: Symbol.h:54
A widget used to build a point symbolizer element.
A widget used to preview a symbol as separated layers.
A widget used to build a polygon symbolizer element.
A widget used to preview symbol elements.
A widget used to build a polygon symbolizer element.
te::se::Symbolizer * getSymbolizer() const
Gets the configured polygon symbolizer element.