OutputRasterWidget.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/OutputRasterWidget.cpp
22 
23  \brief This file has the OutputRasterWidget class.
24 */
25 
26 // TerraLib
27 #include "OutputRasterWidget.h"
28 #include "../../../core/filesystem/FileSystem.h"
29 #include "../../../dataaccess/datasource/DataSourceInfo.h"
30 #include "../datasource/selector/DataSourceSelectorDialog.h"
31 #include "../utils/FileDialog.h"
32 #include "../Utils.h"
33 #include "ui_OutputRasterWidgetForm.h"
34 
35 // BOOST Includes
36 #include <boost/filesystem.hpp>
37 
38 // QT
39 #include <QFileDialog>
40 #include <QMessageBox>
41 
42 
44  : QWidget(parent, f),
45  m_ui(new Ui::OutputRasterWidgetForm)
46 {
47  m_ui->setupUi(this);
48 
49  connect(m_ui->m_targetFileToolButton, SIGNAL(clicked()), this, SLOT(onTargetFileToolButtonClicked()));
50 }
51 
53 
54 Ui::OutputRasterWidgetForm* te::qt::widgets::OutputRasterWidget::getForm() const
55 {
56  return m_ui.get();
57 }
58 
60 {
61  std::string outputRaster;
62  if (!m_ui->m_repositoryLineEdit->text().isEmpty())
63  outputRaster = m_ui->m_repositoryLineEdit->text().toUtf8().data();
64 
65  return outputRaster;
66 }
67 
69 {
70  boost::filesystem::path path(m_ui->m_repositoryLineEdit->text().toUtf8().data());
71  return te::core::FileSystem::exists(path.string());
72 }
73 
75 {
76  return "GDAL";
77 }
78 
79 std::map<std::string, std::string> te::qt::widgets::OutputRasterWidget::getInfo() const
80 {
81  std::map<std::string, std::string> rinfo;
82 
83  rinfo["URI"] = m_ui->m_repositoryLineEdit->text().toUtf8().data();
84 
85  return rinfo;
86 }
87 
89 {
90  if (m_ui->m_repositoryLineEdit->text().isEmpty())
91  return "";
92 
93  QFileInfo info(m_ui->m_repositoryLineEdit->text());
94 
95  std::string filePath = info.path().toUtf8().data();
96  std::string baseName = info.baseName().toUtf8().data();
97  std::string fileName = filePath + "/" + baseName;
98 
99  return fileName;
100 }
101 
103 {
104  if (m_ui->m_repositoryLineEdit->text().isEmpty())
105  return "";
106 
107  QFileInfo info(m_ui->m_repositoryLineEdit->text());
108 
109  return info.suffix().toUtf8().data();
110 }
111 
113 {
114  m_ui->m_newLayerNameLineEdit->clear();
115  m_ui->m_repositoryLineEdit->clear();
116 
117  te::qt::widgets::FileDialog fileDialog(this, te::qt::widgets::FileDialog::RASTER, "rp_raster_info");
118 
119  try {
120  fileDialog.exec();
121  }
122  catch (te::common::Exception& ex) {
123  QMessageBox::warning(this, tr("File information"), ex.what());
124  return;
125  }
126 
127  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
128  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
129 
130  m_ui->m_newLayerNameLineEdit->setEnabled(false);
131 }
OutputRasterWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Defines a component for choose a file.
Definition: FileDialog.h:52
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
Definition: FileSystem.cpp:142
virtual const char * what() const
It outputs the exception message.
Ui::OutputRasterWidgetForm * getForm() const
This file has the OutputRasterWidget class.
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::map< std::string, std::string > getInfo() const
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
std::unique_ptr< Ui::OutputRasterWidgetForm > m_ui
std::string getFileName()
This method will return the file name.
Definition: FileDialog.cpp:113