All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StyleControllerWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 "SymbolPreviewWidget.h"
33 
34 // Qt
35 #include <QtGui/QMessageBox>
36 
37 // STL
38 #include <cassert>
39 
41  : QWidget(parent, f),
42  m_ui(new Ui::StyleControllerWidgetForm)
43 {
44  m_ui->setupUi(this);
45 
46  // Add the StyleExplorer
47  m_explorer = new te::qt::widgets::StyleExplorer(m_ui->m_explorerFrame);
48  QGridLayout* le = new QGridLayout(m_ui->m_explorerFrame);
49  le->setContentsMargins(0, 0, 0, 0);
50  le->addWidget(m_explorer);
51 
52  // Signals & slots
53  connect(m_ui->m_iconSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(changeLegendIconSize(int)));
54  connect(m_ui->m_addSymbToolButton, SIGNAL(clicked()), this, SLOT(onAddSymbolizerClicked()));
55  connect(m_ui->m_removeSymbToolButton, SIGNAL(clicked()), this, SLOT(onRemoveSymbolizerClicked()));
56  connect(m_ui->m_upSymbToolButton, SIGNAL(clicked()), this, SLOT(onUpSymbolizerClicked()));
57  connect(m_ui->m_downSymbToolButton, SIGNAL(clicked()), this, SLOT(onDownSymbolizerClicked()));
58  connect(m_ui->m_mapRefreshToolButton, SIGNAL(clicked()), this, SLOT(onMapRefreshClicked()));
59 
60  updateUi();
61 }
62 
64 {
65 }
66 
68 {
69  m_explorer->setStyle(style);
70 }
71 
73 {
74  return m_explorer;
75 }
76 
78 {
79  m_ui->m_upSymbToolButton->setIcon(QIcon::fromTheme("go-up").pixmap(16,16));
80  m_ui->m_downSymbToolButton->setIcon(QIcon::fromTheme("go-down").pixmap(16,16));
81  m_ui->m_addSymbToolButton->setIcon(QIcon::fromTheme("list-add").pixmap(16,16));
82  m_ui->m_removeSymbToolButton->setIcon(QIcon::fromTheme("list-remove").pixmap(16,16));
83  m_ui->m_mapRefreshToolButton->setIcon(QIcon::fromTheme("map-draw").pixmap(16,16));
84 }
85 
87 {
88  te::se::Rule* rule = m_explorer->getCurrentRule();
89 
90  if(rule == 0)
91  {
92  QMessageBox::information(this, tr("Style"), tr("Select a rule first."));
93  return;
94  }
95 
96  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
97 
98  if(symb)
99  rule->push_back(symb->clone());
100  else
101  {
102  assert(!rule->getSymbolizers().empty());
103 
104  const te::se::Symbolizer* symb = rule->getSymbolizer(0);
105  assert(symb);
106 
107  rule->push_back(symb->clone());
108  }
109 
110  m_explorer->updateStyleTree();
111 }
112 
114 {
115  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
116 
117  if(symb == 0)
118  {
119  QMessageBox::information(this, tr("Style"), tr("Select a symbol first."));
120  return;
121  }
122 
123  te::se::Rule* rule = m_explorer->getCurrentRule();
124  assert(rule);
125 
126  if(rule->getSymbolizers().size() == 1)
127  {
128  QMessageBox::information(this, tr("Style"), tr("The rule must have at least one symbol."));
129  return;
130  }
131 
132  for(std::size_t i = 0; i < rule->getSymbolizers().size(); ++i)
133  {
134  if(rule->getSymbolizer(i) == symb)
135  {
136  rule->removeSymbolizer(i);
137  break;
138  }
139  }
140 
141  m_explorer->updateStyleTree();
142 }
143 
145 {
146  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
147 
148  if(symb == 0)
149  {
150  QMessageBox::information(this, tr("Style"), tr("Select a symbol first."));
151  return;
152  }
153 
154  m_explorer->goUpSymbolizer();
155 }
156 
158 {
159  te::se::Symbolizer* symb = m_explorer->getCurrentSymbolizer();
160 
161  if(symb == 0)
162  {
163  QMessageBox::information(this, tr("Style"), tr("Select a symbol first."));
164  return;
165  }
166 
167  m_explorer->goDownSymbolizer();
168 }
169 
171 {
172  emit mapRefresh();
173 }
174 
176 {
177  m_explorer->setLegendIconSize(size);
178 }
void push_back(Symbolizer *s)
Definition: Rule.cpp:138
const Symbolizer * getSymbolizer(std::size_t i) const
Definition: Rule.cpp:157
StyleControllerWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a StyleControllerWidget which is a child of parent, with widget flags set to f...
void setStyle(te::se::Style *style)
Sets a style element to this widget.
A widget used to preview symbol elements.
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:152
void removeSymbolizer(std::size_t i)
Definition: Rule.cpp:163
A widget used to explore a style.
A widget used to explore a style.
Definition: StyleExplorer.h:60
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.
virtual Symbolizer * clone() const =0
It creates a new copy of this object.
te::qt::widgets::StyleExplorer * m_explorer
A style explorer used to explore the style.
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 controll the style se element.
std::auto_ptr< Ui::StyleControllerWidgetForm > m_ui
Widget form.