ContrastAction.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/plugins/rp/ContrastAction.cpp
22 
23  \brief This file defines the Contrast class
24 */
25 
26 // Terralib
27 #include "../../../dataaccess/utils/Utils.h"
28 #include "../../../raster/BandProperty.h"
29 #include "../../../raster/RasterProperty.h"
30 #include "../../af/events/LayerEvents.h"
31 #include "../../af/ApplicationController.h"
32 #include "../../af/BaseApplication.h"
33 #include "ContrastAction.h"
34 
35 // Qt
36 #include <QObject>
37 #include <QMessageBox>
38 #include <QApplication>
39 
40 // STL
41 #include <memory>
42 
43 te::qt::plugins::rp::ContrastAction::ContrastAction(QMenu* menu, QMenu* popupMenu):te::qt::plugins::rp::AbstractAction(menu, popupMenu)
44 {
45  createAction(tr("Contrast...").toUtf8().data(), "histogram");
46 
47  m_action->setObjectName("Processing.Raster Processing.Contrast");
48 }
49 
51 
53 {
55 
56  if(!layer.get())
57  {
58  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("There is no selected raster layer."));
59  return;
60  }
61 
62  QApplication::setOverrideCursor(Qt::WaitCursor);
63 
64  if(layer->getVisibility() != te::map::VISIBLE)
65  {
66  QApplication::restoreOverrideCursor();
67  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("The layer is not checked!"));
68  return;
69  }
70 
71  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
72 
73  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
74 
75  if (rasterProp->getBandProperties().empty())
76  {
77  QApplication::restoreOverrideCursor();
78  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("Layers without Band information!"));
79  return;
80  }
81 
82  if(rasterProp->getBandProperties()[0]->m_colorInterp == te::rst::PaletteIdxCInt)
83  {
84  QApplication::restoreOverrideCursor();
85  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("Layers with raster palette are not able to apply contrast!"));
86  return;
87  }
88 
89  // Register the application framework listener
91 
93 
95  connect(m_contrastDlg.get(), SIGNAL(closeTool()), this, SLOT(closeTool()));
96 
98 
99  QActionGroup* mapEditionTools = te::qt::af::AppCtrlSingleton::getInstance().findActionGroup("Map.ToolsGroup");
100  assert(mapEditionTools);
101 
102  m_contrastDlg->setModal(false);
103  m_contrastDlg->setMapDisplay(ba->getMapDisplay());
104  m_contrastDlg->setActionGroup(mapEditionTools);
105  m_contrastDlg->set(layer);
106  m_contrastDlg->setConfigurations();
107 
108  QApplication::restoreOverrideCursor();
109 
110  m_contrastDlg->show();
111 }
112 
114  bool /*checked*/)
115 {
117 
118  if(layer.get())
119  {
121 
122  dlg.set(layer);
123 
124  dlg.exec();
125  }
126  else
127  {
128  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("The layer selected is invalid or does not have an raster representation."));
129  }
130 }
131 
133 {
134  switch (e->m_id)
135  {
137  {
139 
140  te::map::AbstractLayerPtr layer = evt->m_layer;
141  assert(layer);
142 
143  if(!layer)
144  return;
145 
146  if(layer->getVisibility() != te::map::VISIBLE)
147  {
148  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("The layer is not checked!"));
149  return ;
150  }
151 
152  if(m_contrastDlg)
153  m_contrastDlg->resetWindow(layer);
154  }
155  break;
156 
158  {
159  m_contrastDlg->onMapDisplayExtentChanged();
160  }
161  break;
162 
163  default:
164  break;
165  }
166 }
167 
169 {
170  //add new layer
171  addNewLayer(outputLayer);
172 }
173 
175 {
176  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
177 
178  m_contrastDlg.reset(nullptr);
179 }
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
Palette indexes color interpretation.
This is an abstract class used to register actions into rp pluging.
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for contrast operation.
A base class for application events.
std::unique_ptr< te::qt::widgets::ContrastDialogForm > m_contrastDlg
te::map::AbstractLayerPtr m_layer
Pointer to the selected layer.
Definition: LayerEvents.h:196
void addLayer(te::map::AbstractLayerPtr outputLayer)
void onApplicationTriggered(te::qt::af::evt::Event *e)
Raster property.
ContrastAction(QMenu *menu, QMenu *popupMenu)
This file defines the Contrast class.
This event indicates that the layer has been selected.
Definition: LayerEvents.h:183
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void createAction(std::string name, std::string pixmap="")
Create and set the actions parameters.
te::map::AbstractLayerPtr getCurrentLayer()
Get the selected layer from layer explorer in app.
URI C++ Library.
Definition: Attributes.h:37
QAction * m_action
Action used to call the process.
This class is GUI used to define the contrast parameters for the RP constast operation.
virtual void onPopUpActionActivated(bool checked)
void addNewLayer(te::map::AbstractLayerPtr layer)
Add a new layer into layer explorer widget.
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual void onActionActivated(bool checked)