All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GroupingDialog.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/GroupingDialog.cpp
22 
23  \brief A dialog used to build a grouping.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/dataset/DataSetType.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../maptools/DataSetLayer.h"
31 #include "../../../maptools/RasterLayer.h"
32 #include "../../../se/ChannelSelection.h"
33 #include "../../../se/ColorMap.h"
34 #include "../../../se/CoverageStyle.h"
35 #include "../../../se/RasterSymbolizer.h"
36 #include "../../../se/SelectedChannel.h"
37 #include "../../../se/Utils.h"
38 #include "ColorMapWidget.h"
39 #include "GroupingDialog.h"
40 #include "GroupingWidget.h"
41 #include "ui_GroupingDialogForm.h"
42 
43 te::qt::widgets::GroupingDialog::GroupingDialog(QWidget* parent, Qt::WindowFlags f)
44  : QDialog(parent, f),
45  m_ui(new Ui::GroupingDialogForm),
46  m_groupingWidget(0),
47  m_colorMapWidget(0),
48  m_rasterSymb(0)
49 {
50  m_ui->setupUi(this);
51 
52  m_ui->m_okPushButton->setEnabled(false);
53 
54  //connect
55  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onPushButtonClicked()));
56  m_ui->m_helpPushButton->setPageReference("widgets/grouping/grouping.html");
57 }
58 
60 {
61 }
62 
63 void te::qt::widgets::GroupingDialog::setLayers(te::map::AbstractLayerPtr selectedLayer, std::vector<te::map::AbstractLayerPtr> allLayers)
64 {
65  m_layer = selectedLayer;
66  m_allLayers = allLayers;
67 
68  setWindowTitle(windowTitle() + " (" + tr("Layer") + ":" + selectedLayer->getTitle().c_str() +")");
69 
70  //VERIFY LATER
71  std::auto_ptr<te::map::LayerSchema> dsType(selectedLayer->getSchema());
72 
73  if(dsType->hasGeom())
74  {
75  buildVectorialGroupingInteface();
76  }
77  else if(dsType->hasRaster())
78  {
79  buildRasterGroupingInteface();
80 
81  if(selectedLayer->getType() == "DATASETLAYER")
82  {
83  te::map::DataSetLayer* l = dynamic_cast<te::map::DataSetLayer*>(selectedLayer.get());
84 
85  if(l)
86  {
87  m_rasterSymb = te::se::GetRasterSymbolizer(l->getStyle());
88 
89  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
90 
91  if(ds.get())
92  {
93  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
94  m_raster.reset(ds->getRaster(rpos).release());
95  }
96  }
97  }
98  else if(selectedLayer->getType() == "RASTERLAYER")
99  {
100  te::map::RasterLayer* l = dynamic_cast<te::map::RasterLayer*>(selectedLayer.get());
101 
102  if(l)
103  {
104  m_rasterSymb = te::se::GetRasterSymbolizer(l->getStyle());
105 
106  m_raster.reset(l->getRaster());
107  }
108  }
109 
110  if(m_rasterSymb)
111  {
112  if(m_rasterSymb->getColorMap())
113  {
114  m_colorMapWidget->setColorMap(m_rasterSymb->getColorMap());
115  }
116  else
117  {
119 
120  m_colorMapWidget->setColorMap(cm);
121  }
122  }
123 
124  if(m_raster.get())
125  {
126  m_colorMapWidget->setRaster(m_raster.get());
127  }
128  }
129 }
130 
132 {
133  // Fill Widget
134  m_groupingWidget = new te::qt::widgets::GroupingWidget(m_ui->m_widget);
135 
136  m_groupingWidget->setLayers(m_layer, m_allLayers);
137 
138  connect(m_groupingWidget, SIGNAL(applyPushButtonClicked()), this, SLOT(onApplyClicked()));
139 
140  // Adjusting...
141  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
142  layout->setContentsMargins(0,0,0,0);
143  layout->addWidget(m_groupingWidget);
144 }
145 
147 {
148  // Fill Widget
149  m_colorMapWidget = new te::qt::widgets::ColorMapWidget(m_ui->m_widget);
150 
151  m_colorMapWidget->setLayers(m_layer, m_allLayers);
152 
153  connect(m_colorMapWidget, SIGNAL(applyPushButtonClicked()), this, SLOT(onApplyClicked()));
154 
155  // Adjusting...
156  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
157  layout->setContentsMargins(0,0,0,0);
158  layout->addWidget(m_colorMapWidget);
159 }
160 
162 {
163  if(m_groupingWidget)
164  {
165  te::map::Grouping* g = m_groupingWidget->getGrouping().release();
166 
167  m_layer->setGrouping(g);
168  }
169 
170  if(m_colorMapWidget)
171  {
172  te::se::ColorMap* cm = m_colorMapWidget->getColorMap();
173 
174  m_rasterSymb->setColorMap(cm);
175 
176  std::string band = m_colorMapWidget->getCurrentBand();
177 
178  te::se::ChannelSelection* cs = m_rasterSymb->getChannelSelection();
179 
180  if(cs->getGrayChannel())
181  {
182  te::se::SelectedChannel* scGray = cs->getGrayChannel();
183 
184  scGray->setSourceChannelName(band);
185  }
186  else
187  {
189 
190  scGray->setSourceChannelName(band);
191 
192  cs->setGrayChannel(scGray);
193  }
194 
196  }
197 
198  accept();
199 }
200 
202 {
203  m_ui->m_okPushButton->setEnabled(true);
204 }
A selected channel to be display.
A dialog used to build a ColorMap element.
GroupingDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic fill dialog which is a child of parent, with widget flags set to f...
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:371
te::rst::Raster * getRaster() const
void setGrayChannel(SelectedChannel *c)
A dialog used to build a grouping.
A widget used to build.
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
A widget used to build a grouping.
A layer with reference to a raster.
Definition: RasterLayer.h:52
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
void setColorCompositionType(ColorCompositionType cct)
void setLayers(te::map::AbstractLayerPtr selectedLayer, std::vector< te::map::AbstractLayerPtr > allLayers)
void setColorMap(ColorMap *c)
void setSourceChannelName(const std::string &name)
A widget used to build a grouping.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
SelectedChannel * getGrayChannel() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:60
std::auto_ptr< Ui::GroupingDialogForm > m_ui
Dialog form.
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...