All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GroupingDialog.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/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 
64 {
65  m_layer = layer;
66 
67  //VERIFY LATER
68  std::auto_ptr<te::map::LayerSchema> dsType(layer->getSchema());
69 
70  if(dsType->hasGeom())
71  {
72  buildVectorialGroupingInteface();
73 
74  m_groupingWidget->setLayer(layer);
75  }
76  else if(dsType->hasRaster())
77  {
78  buildRasterGroupingInteface();
79 
80  if(layer->getType() == "DATASETLAYER")
81  {
82  te::map::DataSetLayer* l = dynamic_cast<te::map::DataSetLayer*>(layer.get());
83 
84  if(l)
85  {
86  m_rasterSymb = te::se::GetRasterSymbolizer(l->getStyle());
87 
88  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
89 
90  if(ds.get())
91  {
92  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
93  m_raster.reset(ds->getRaster(rpos).release());
94  }
95  }
96  }
97  else if(layer->getType() == "RASTERLAYER")
98  {
99  te::map::RasterLayer* l = dynamic_cast<te::map::RasterLayer*>(layer.get());
100 
101  if(l)
102  {
103  m_rasterSymb = te::se::GetRasterSymbolizer(l->getStyle());
104 
105  m_raster.reset(l->getRaster());
106  }
107  }
108 
109  if(m_rasterSymb)
110  {
111  if(m_rasterSymb->getColorMap())
112  {
113  m_colorMapWidget->setColorMap(m_rasterSymb->getColorMap());
114  }
115  else
116  {
118 
119  m_colorMapWidget->setColorMap(cm);
120  }
121  }
122 
123  if(m_raster.get())
124  {
125  m_colorMapWidget->setRaster(m_raster.get());
126  }
127  }
128 }
129 
131 {
132  // Fill Widget
133  m_groupingWidget = new te::qt::widgets::GroupingWidget(m_ui->m_widget);
134 
135  connect(m_groupingWidget, SIGNAL(applyPushButtonClicked()), this, SLOT(onApplyClicked()));
136 
137  // Adjusting...
138  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
139  layout->setContentsMargins(0,0,0,0);
140  layout->addWidget(m_groupingWidget);
141 }
142 
144 {
145  // Fill Widget
146  m_colorMapWidget = new te::qt::widgets::ColorMapWidget(m_ui->m_widget);
147 
148  connect(m_colorMapWidget, SIGNAL(applyPushButtonClicked()), this, SLOT(onApplyClicked()));
149 
150  // Adjusting...
151  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
152  layout->setContentsMargins(0,0,0,0);
153  layout->addWidget(m_colorMapWidget);
154 }
155 
157 {
158  if(m_groupingWidget)
159  {
160  te::map::Grouping* g = m_groupingWidget->getGrouping().release();
161 
162  m_layer->setGrouping(g);
163  }
164 
165  if(m_colorMapWidget)
166  {
167  te::se::ColorMap* cm = m_colorMapWidget->getColorMap();
168 
169  m_rasterSymb->setColorMap(cm);
170 
171  std::string band = m_colorMapWidget->getCurrentBand();
172 
173  te::se::ChannelSelection* cs = m_rasterSymb->getChannelSelection();
174 
175  if(cs->getGrayChannel())
176  {
177  te::se::SelectedChannel* scGray = cs->getGrayChannel();
178 
179  scGray->setSourceChannelName(band);
180  }
181  else
182  {
184 
185  scGray->setSourceChannelName(band);
186 
187  cs->setGrayChannel(scGray);
188  }
189 
191  }
192 
193  accept();
194 }
195 
197 {
198  m_ui->m_okPushButton->setEnabled(true);
199 }
void setSourceChannelName(const std::string &name)
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
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...
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
A selected channel to be display.
A dialog used to build a grouping.
void setColorMap(ColorMap *c)
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:60
void setLayer(te::map::AbstractLayerPtr layer)
A dialog used to build a ColorMap element.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:428
std::auto_ptr< Ui::GroupingDialogForm > m_ui
Dialog form.
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:369
void setGrayChannel(SelectedChannel *c)
te::rst::Raster * getRaster() const
A widget used to build.
SelectedChannel * getGrayChannel() const
void setColorCompositionType(ColorCompositionType cct)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A widget used to build a grouping.
A layer with reference to a raster.
Definition: RasterLayer.h:52
A widget used to build a grouping.