All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterInfoWidget.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/RasterInfoWidget.cpp
22 
23  \brief This file has the RasterInfoWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/datasource/DataSource.h"
28 #include "../../../dataaccess/datasource/DataSourceFactory.h"
29 #include "../utils/ParameterTableWidget.h"
30 #include "../Utils.h"
31 #include "RasterInfoWidget.h"
32 #include "ui_RasterInfoWidgetForm.h"
33 #include "ui_ParameterTableWidgetForm.h"
34 
35 // QT
36 #include <QFileDialog>
37 
38 te::qt::widgets::RasterInfoWidget::RasterInfoWidget(QWidget* parent, Qt::WindowFlags f)
39  : QWidget(parent, f),
40  m_ui(new Ui::RasterInfoWidgetForm),
41  m_dir("")
42 {
43  m_ui->setupUi(this);
44 
45  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
46  m_table.reset( new te::qt::widgets::ParameterTableWidget(m_ui->m_widget));
47  layout->addWidget(m_table.get());
48  layout->setContentsMargins(0,0,0,0);
49 
50  m_table->getForm()->m_parameterTitle->setText(tr("Extra parameters"));
51 
52  //connects
53  connect(m_ui->m_openFileDlgToolButton, SIGNAL(clicked()), this, SLOT(onOpenFileDlgToolButtonClicked()));
54 
55 
56 }
57 
59 {
60 }
61 
62 Ui::RasterInfoWidgetForm* te::qt::widgets::RasterInfoWidget::getForm() const
63 {
64  return m_ui.get();
65 }
66 
68 {
69  if(m_ui->m_fileRadioButton->isChecked())
70  {
71  return "GDAL";
72  }
73  else if(m_ui->m_memRadioButton->isChecked())
74  {
75  return "MEM";
76  }
77  else if(m_ui->m_dsRadioButton->isChecked())
78  {
79  return "";
80  }
81 
82  return "";
83 }
84 
85 std::map<std::string, std::string> te::qt::widgets::RasterInfoWidget::getInfo() const
86 {
87  std::map<std::string, std::string> rinfo;
88 
89  std::string name = getBaseName();
90 
91  if(m_ui->m_fileRadioButton->isChecked())
92  {
93  std::string fileName = m_dir + "/" + name + ".tif";
94 
95  rinfo["URI"] = fileName;
96  }
97  else if(m_ui->m_memRadioButton->isChecked())
98  {
99 
100  }
101  else if(m_ui->m_dsRadioButton->isChecked())
102  {
103 
104  }
105 
106  if(m_ui->m_overightRadioButton->isChecked() == false)
107  {
108  //get extra parameters
109  std::map<std::string, std::string> extra = m_table->getMap();
110 
111  rinfo.insert(extra.begin(), extra.end());
112  }
113 
114  return rinfo;
115 }
116 
117 std::auto_ptr<te::da::DataSource> te::qt::widgets::RasterInfoWidget::getDataSource() const
118 {
119  std::map<std::string, std::string> connInfoRaster;
120  connInfoRaster["SOURCE"] = m_dir + "/";
121 
122  std::auto_ptr< te::da::DataSource > dsPtr( te::da::DataSourceFactory::make("GDAL") );
123  dsPtr->setConnectionInfo( connInfoRaster );
124  dsPtr->open();
125 
126  return dsPtr;
127 }
128 
130 {
131  std::string name = getBaseName();
132 
133  if(m_ui->m_fileRadioButton->isChecked())
134  {
135  name += ".tif";
136  }
137 
138  return name;
139 }
140 
142 {
143  std::string name = "";
144 
145  if(m_ui->m_nameLineEdit->text().isEmpty() == false)
146  name = m_ui->m_nameLineEdit->text().toStdString();
147 
148  return name;
149 }
150 
152 {
153  return ".tif";
154 }
155 
157 {
158  return m_dir + "/";
159 }
160 
162 {
163  return m_ui->m_overightRadioButton->isChecked();
164 }
165 
167 {
168  if(m_ui->m_fileRadioButton->isChecked())
169  {
170  std::string name = getBaseName();
171 
172  std::string fileName = m_dir + "/" + name + ".tif";
173 
174  QFile file(fileName.c_str());
175 
176  return file.exists();
177  }
178 
179  return false;
180 }
181 
183 {
184  std::string name = "";
185 
186  if(m_ui->m_nameLineEdit->text().isEmpty() == false)
187  {
188  name = m_ui->m_nameLineEdit->text().toStdString();
189 
190  QFileInfo file(name.c_str());
191 
192  name = file.baseName().toStdString();
193  }
194 
195  return name;
196 }
197 
199 {
200  QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), te::qt::widgets::GetFilePathFromSettings("rp_raster_info"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
201 
202  if(dir.isEmpty() == false)
203  {
204  m_dir = dir.replace(QRegExp("\\\\"), "/").toStdString();
205 
206  m_ui->m_fileNameLineEdit->setText(m_dir.c_str());
207 
208  te::qt::widgets::AddFilePathToSettings(m_dir.c_str(), "rp_raster_info");
209  }
210 }
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
Definition: Utils.cpp:351
Ui::RasterInfoWidgetForm * getForm() const
std::map< std::string, std::string > getInfo() const
static std::auto_ptr< DataSource > make(const std::string &dsType)
This file has the RasterInfoWidget class.
std::auto_ptr< te::da::DataSource > getDataSource() const
std::auto_ptr< Ui::RasterInfoWidgetForm > m_ui
std::auto_ptr< te::qt::widgets::ParameterTableWidget > m_table
RasterInfoWidget(QWidget *parent=0, Qt::WindowFlags f=0)
TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString &typeFile)
Returns the value of the last saved file path for the typeFile required.
Definition: Utils.cpp:360