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) 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/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/DataSourceCapabilities.h"
29 #include "../../../dataaccess/datasource/DataSourceFactory.h"
30 #include "../utils/ParameterTableWidget.h"
31 #include "../Utils.h"
32 #include "RasterInfoWidget.h"
33 #include "ui_RasterInfoWidgetForm.h"
34 #include "ui_ParameterTableWidgetForm.h"
35 
36 // QT
37 #include <QFileDialog>
38 
39 // BOOST Includes
40 #include <boost/tokenizer.hpp>
41 #include <boost/lexical_cast.hpp>
42 
43 
44 te::qt::widgets::RasterInfoWidget::RasterInfoWidget(QWidget* parent, Qt::WindowFlags f)
45  : QWidget(parent, f),
46  m_ui(new Ui::RasterInfoWidgetForm),
47  m_dir("")
48 {
49  m_ui->setupUi(this);
50 
51  QGridLayout* layout = new QGridLayout(m_ui->m_widget);
52  m_table.reset( new te::qt::widgets::ParameterTableWidget(m_ui->m_widget));
53  layout->addWidget(m_table.get());
54  layout->setContentsMargins(0,0,0,0);
55 
56  m_ui->m_openFileDlgToolButton->setIcon(QIcon::fromTheme("folder"));
57  m_ui->m_openDSDlgToolButton->setIcon(QIcon::fromTheme("datasource"));
58 
59  m_table->getForm()->m_parameterTitle->setText(tr("Extra parameters"));
60 
61  //connects
62  connect(m_ui->m_openFileDlgToolButton, SIGNAL(clicked()), this, SLOT(onOpenFileDlgToolButtonClicked()));
63 
65 }
66 
68 {
69 }
70 
71 Ui::RasterInfoWidgetForm* te::qt::widgets::RasterInfoWidget::getForm() const
72 {
73  return m_ui.get();
74 }
75 
77 {
78  if(m_ui->m_fileRadioButton->isChecked())
79  {
80  return "GDAL";
81  }
82  else if(m_ui->m_memRadioButton->isChecked())
83  {
84  return "MEM";
85  }
86  else if(m_ui->m_dsRadioButton->isChecked())
87  {
88  return "";
89  }
90 
91  return "";
92 }
93 
94 std::map<std::string, std::string> te::qt::widgets::RasterInfoWidget::getInfo() const
95 {
96  std::map<std::string, std::string> rinfo;
97 
98  std::string name = getBaseName();
99 
100  if(m_ui->m_fileRadioButton->isChecked())
101  {
102  std::string fileName = m_dir + "/" + name + getExtension();
103 
104  rinfo["URI"] = fileName;
105  }
106  else if(m_ui->m_memRadioButton->isChecked())
107  {
108 
109  }
110  else if(m_ui->m_dsRadioButton->isChecked())
111  {
112 
113  }
114 
115  if(m_ui->m_overightRadioButton->isChecked() == false)
116  {
117  //get extra parameters
118  std::map<std::string, std::string> extra = m_table->getMap();
119 
120  rinfo.insert(extra.begin(), extra.end());
121  }
122 
123  return rinfo;
124 }
125 
126 std::map<std::string, std::string> te::qt::widgets::RasterInfoWidget::getInfo(int count) const
127 {
128  std::map<std::string, std::string> rinfo;
129 
130  std::string name = getBaseName();
131 
132  if(m_ui->m_fileRadioButton->isChecked())
133  {
134  std::string str = boost::lexical_cast< std::string >( count );
135  std::string fileName = m_dir + "/" + name + "_" + str + getExtension();
136 
137  rinfo["URI"] = fileName;
138  }
139  else if(m_ui->m_memRadioButton->isChecked())
140  {
141 
142  }
143  else if(m_ui->m_dsRadioButton->isChecked())
144  {
145 
146  }
147 
148  if(m_ui->m_overightRadioButton->isChecked() == false)
149  {
150  //get extra parameters
151  std::map<std::string, std::string> extra = m_table->getMap();
152 
153  rinfo.insert(extra.begin(), extra.end());
154  }
155 
156  return rinfo;
157 }
158 
159 std::auto_ptr<te::da::DataSource> te::qt::widgets::RasterInfoWidget::getDataSource() const
160 {
161  std::map<std::string, std::string> connInfoRaster;
162  connInfoRaster["SOURCE"] = m_dir + "/";
163 
164  std::auto_ptr< te::da::DataSource > dsPtr( te::da::DataSourceFactory::make("GDAL") );
165  dsPtr->setConnectionInfo( connInfoRaster );
166  dsPtr->open();
167 
168  return dsPtr;
169 }
170 
172 {
173  std::string name = getBaseName();
174 
175  if(m_ui->m_fileRadioButton->isChecked())
176  {
177  name += getExtension();
178  }
179 
180  return name;
181 }
182 
184 {
185  std::string name = "";
186 
187  if(m_ui->m_nameLineEdit->text().isEmpty() == false)
188  name = m_ui->m_nameLineEdit->text().toStdString();
189 
190  std::size_t pos = name.find(".");
191  if(pos != std::string::npos)
192  {
193  name = name.substr(0, pos);
194  }
195 
196  return name;
197 }
198 
200 {
201  std::string ext = "." + m_ui->m_extComboBox->currentText().toStdString();
202 
203  return ext;
204 }
205 
207 {
208  return m_dir + "/";
209 }
210 
212 {
213  return m_ui->m_overightRadioButton->isChecked();
214 }
215 
217 {
218  if(m_ui->m_fileRadioButton->isChecked())
219  {
220  std::string name = getBaseName();
221 
222  std::string fileName = m_dir + "/" + name + getExtension();
223 
224  QFile file(fileName.c_str());
225 
226  return file.exists();
227  }
228 
229  return false;
230 }
231 
233 {
234  std::string name = "";
235 
236  if(m_ui->m_nameLineEdit->text().isEmpty() == false)
237  {
238  name = m_ui->m_nameLineEdit->text().toStdString();
239 
240  QFileInfo file(name.c_str());
241 
242  name = file.baseName().toStdString();
243  }
244 
245  return name;
246 }
247 
249 {
250  //fill extensions
251  m_ui->m_extComboBox->clear();
252 
253  std::auto_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("GDAL");
254 
255  if(!ds.get())
256  return;
257 
258  te::da::DataSourceCapabilities dsCap = ds->getCapabilities();
259 
260  std::map<std::string, std::string> mapSpecCap = dsCap.getSpecificCapabilities();
261 
262  std::string exts = mapSpecCap["SUPPORTED_EXTENSIONS"];
263 
264 //create boost tokenizer
265  typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer;
266  boost::escaped_list_separator<char> sep('\\', ';', '\"');
267 
268  std::vector<std::string> extVec;
269 
270  Tokenizer tok(exts, sep);
271  extVec.assign(tok.begin(), tok.end());
272 
273  int curIdx = 0;
274 
275  for(std::size_t t = 0; t < extVec.size(); ++t)
276  {
277  m_ui->m_extComboBox->addItem(extVec[t].c_str());
278 
279  if(extVec[t] == "tif")
280  curIdx = (int)t;
281  }
282 
283  m_ui->m_extComboBox->setCurrentIndex(curIdx);
284 }
285 
287 {
288  QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), te::qt::widgets::GetFilePathFromSettings("rp_raster_info"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
289 
290  if(dir.isEmpty() == false)
291  {
292  m_dir = dir.replace(QRegExp("\\\\"), "/").toStdString();
293 
294  m_ui->m_fileNameLineEdit->setText(m_dir.c_str());
295 
296  te::qt::widgets::AddFilePathToSettings(m_dir.c_str(), "rp_raster_info");
297  }
298 }
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
Definition: Utils.cpp:367
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
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:376
const std::map< std::string, std::string > & getSpecificCapabilities() const