All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterHistogramWidget.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/rp/RasterHistogramWidget.cpp
22 
23  \brief This file has the RasterHistogramWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/utils/Utils.h"
29 #include "../../../raster/Raster.h"
30 #include "../../../se/Fill.h"
31 #include "../../../se/Stroke.h"
32 #include "../../../se/Utils.h"
33 #include "../charts/ChartDisplay.h"
34 #include "../charts/ChartStyle.h"
35 #include "../charts/Histogram.h"
36 #include "../charts/HistogramChart.h"
37 #include "../charts/HistogramStyle.h"
38 #include "../charts/Utils.h"
39 #include "RasterHistogramWidget.h"
40 #include "ui_RasterHistogramWidgetForm.h"
41 
42 // Qt
43 #include <QGridLayout>
44 
45 //STL
46 #include <memory>
47 
49  : QWidget(parent, f),
50  m_ui(new Ui::RasterHistogramWidgetForm)
51 {
52  m_ui->setupUi(this);
53 
54  m_ui->m_redToolButton->setIcon(QIcon::fromTheme("bullet-red"));
55  m_ui->m_greenToolButton->setIcon(QIcon::fromTheme("bullet-green"));
56  m_ui->m_blueToolButton->setIcon(QIcon::fromTheme("bullet-blue"));
57  m_ui->m_monoToolButton->setIcon(QIcon::fromTheme("bullet-black"));
58 
59  connect(m_ui->m_redToolButton, SIGNAL(toggled(bool)), this, SLOT(onRedToolButtonToggled(bool)));
60  connect(m_ui->m_greenToolButton, SIGNAL(toggled(bool)), this, SLOT(onGreenToolButtonToggled(bool)));
61  connect(m_ui->m_blueToolButton, SIGNAL(toggled(bool)), this, SLOT(onBlueToolButtonToggled(bool)));
62  connect(m_ui->m_monoToolButton, SIGNAL(toggled(bool)), this, SLOT(onMonoToolButtonToggled(bool)));
63 
64  //Creating and adjusting the chart Display's style.
66  m_chartStyle->setTitle(tr(""));
67  m_chartStyle->setAxisX(tr("Gray Level"));
68  m_chartStyle->setAxisY(tr("Frequency"));
69 
70  //build form
71  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
72 
73  //Creating and adjusting the chart Display
74  m_chartDisplay = new te::qt::widgets::ChartDisplay(m_ui->m_widget, QString::fromStdString(""), m_chartStyle);
76  m_chartDisplay->show();
77  m_chartDisplay->replot();
78 
79  layout->addWidget(m_chartDisplay, 0, 0);
80  layout->setContentsMargins(0,0,0,0);
81 }
82 
84 {
85 }
86 
87 Ui::RasterHistogramWidgetForm* te::qt::widgets::RasterHistogramWidget::getForm() const
88 {
89  return m_ui.get();
90 }
91 
93 {
94  m_layer = layer;
95 
96  //list bands
97  m_ui->m_redComboBox->clear();
98  m_ui->m_greenComboBox->clear();
99  m_ui->m_blueComboBox->clear();
100  m_ui->m_monoComboBox->clear();
101 
102  std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
103  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
104  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
105 
106  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
107  {
108  QString strBand;
109  strBand.setNum(i);
110 
111  m_ui->m_redComboBox->addItem(strBand);
112  m_ui->m_greenComboBox->addItem(strBand);
113  m_ui->m_blueComboBox->addItem(strBand);
114  m_ui->m_monoComboBox->addItem(strBand);
115  }
116 }
117 
119 {
120  int band = m_ui->m_redComboBox->currentText().toInt();
121 
122  std::auto_ptr<te::da::DataSet> ds(m_layer->getData());
123  std::auto_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
124 
125  te::qt::widgets::Histogram* hist = te::qt::widgets::createHistogram(ds.get(), dsType.get(), band);
126 
127 // te::se::Fill* fill = te::se::CreateFill("#009900", "1.0");
128 
129 // te::se::Stroke* stroke = te::se::CreateStroke("#000000", "1");
130 
132 
133  m_chartDisplay->adjustDisplay();
134  histChart->attach(m_chartDisplay);
135  m_chartDisplay->show();
136  m_chartDisplay->replot();
137 
138  // delete histChart;
139 }
140 
142 {
143 }
144 
146 {
147 }
148 
150 {
151 }
This file has the RasterHistogramWidget class.
void adjustDisplay()
Updates the general display settings according to the ChartStyle. The adjusted properties are: Title;...
te::qt::widgets::ChartDisplay * m_chartDisplay
void set(te::map::AbstractLayerPtr layer)
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices)
Histogram Creator.
Definition: Utils.cpp:291
A class to represent a Histogram.
Definition: Histogram.h:56
void setTitle(QString newTitle)
It sets the style's title.
Definition: ChartStyle.cpp:71
Ui::RasterHistogramWidgetForm * getForm() const
std::auto_ptr< Ui::RasterHistogramWidgetForm > m_ui
void setAxisY(QString newAxisY)
It sets the style's y axis label.
Definition: ChartStyle.cpp:101
A class to represent a chart display.
Definition: ChartDisplay.h:65
void setAxisX(QString newAxisX)
It sets the style's x axis label.
Definition: ChartStyle.cpp:91
te::qt::widgets::ChartStyle * m_chartStyle
RasterHistogramWidget(QWidget *parent=0, Qt::WindowFlags f=0)
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:432
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr