VolumeResultDialog.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/mnt/qt/VolumeResultDialog.cpp
22 
23 \brief A dialog Show Calculate Volume Results
24 */
25 
26 #include "VolumeResultDialog.h"
27 #include "../../core/filesystem/FileSystem.h"
28 #include "ui_VolumeResultDialogForm.h"
29 
30 // Qt
31 #include <QFileDialog>
32 #include <QMessageBox>
33 
34 // BOOST
35 #include <boost/filesystem.hpp>
36 #include <boost/property_tree/json_parser.hpp>
37 
38 
39 te::mnt::VolumeResultDialog::VolumeResultDialog(std::vector<std::string> &polyvec,
40  std::vector<std::string> &cortevec,
41  std::vector<std::string> &aterrovec,
42  std::vector<std::string> &areavec,
43  std::vector<std::string> &iquotavec,
44  std::string &attr,
45  QWidget* parent,
46  Qt::WindowFlags f)
47  : QDialog(parent, f),
48  m_ui(new Ui::VolumeResultDialogForm)
49 {
50  // add controls
51  m_ui->setupUi(this);
52 
53  connect(m_ui->m_savePushButton, SIGNAL(clicked()), this, SLOT(onSavePushButtonClicked()));
54  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
55 
56  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
57  m_ui->m_helpPushButton->setPageReference("plugins/mnt/DTM_VolumeResult.html");
58 
59  m_ui->m_resultTableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(QString(attr.c_str())));
60 
61  size_t nrows = polyvec.size();
62  m_ui->m_resultTableWidget->setRowCount((int)nrows);
63  for (size_t i = 0; i < nrows; i++)
64  {
65  QTableWidgetItem *item1 = new QTableWidgetItem(QString(polyvec[i].c_str()));
66  QTableWidgetItem *item2 = new QTableWidgetItem(QString(cortevec[i].c_str()));
67  QTableWidgetItem *item3 = new QTableWidgetItem(QString(aterrovec[i].c_str()));
68  QTableWidgetItem *item4 = new QTableWidgetItem(QString(areavec[i].c_str()));
69  QTableWidgetItem *item5 = new QTableWidgetItem(QString(iquotavec[i].c_str()));
70  m_ui->m_resultTableWidget->setItem((int)i, 0, item1);
71  m_ui->m_resultTableWidget->setItem((int)i, 1, item2);
72  m_ui->m_resultTableWidget->setItem((int)i, 2, item3);
73  m_ui->m_resultTableWidget->setItem((int)i, 3, item4);
74  m_ui->m_resultTableWidget->setItem((int)i, 4, item5);
75  }
76 }
77 
79 
81 {
82  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
83  QString(), tr("txt (*.txt *.TXT);;"), nullptr);
84 
85 
86  if (fileName.isEmpty())
87  return;
88 
89  try
90  {
91  te::core::FileSystem::remove(fileName.toUtf8().data());
92  }
93  catch (const std::exception& e)
94  {
95  QMessageBox::information(this, tr("TIN Generation"), e.what());
96  return;
97  }
98 
99  saveVolume(fileName.toUtf8().data());
100 
101  accept();
102 }
103 
105 {
106  reject();
107 }
108 
109 void te::mnt::VolumeResultDialog::saveVolume(const std::string& path)
110 {
111  int rowCount = m_ui->m_resultTableWidget->rowCount();
112  int colCount = m_ui->m_resultTableWidget->columnCount();
113 
114  if (rowCount < 1)
115  return;
116 
117  if (path.empty())
118  return;
119 
120  boost::property_tree::ptree itens;
121  for (int r = 0; r < rowCount; r++)
122  {
123  boost::property_tree::ptree item;
124  for (int i = 0; i < colCount; i++)
125  {
126  QTableWidgetItem *res = m_ui->m_resultTableWidget->horizontalHeaderItem(i);
127  if (res)
128  item.add(res->text().toUtf8().data(), m_ui->m_resultTableWidget->item(r, i)->text().toUtf8().data());
129  }
130  itens.add_child("Polygon", item);
131  }
132 
133  boost::property_tree::ptree pt;
134  pt.add_child("Volume", itens);
135  boost::property_tree::write_json(path, pt);
136 
137  QMessageBox::warning(this, tr("Volume"), tr("File was saved succesfully!"));
138 
139 }
VolumeResultDialog(std::vector< std::string > &polyvec, std::vector< std::string > &cortevec, std::vector< std::string > &aterrovec, std::vector< std::string > &areavec, std::vector< std::string > &iquotavec, std::string &attr, QWidget *parent=0, Qt::WindowFlags f=0)
std::unique_ptr< Ui::VolumeResultDialogForm > m_ui
void saveVolume(const std::string &path)
A dialog Show Calculate Volume Results.
static bool remove(const std::string &path)
Removes a file or directory from a given path in UTF-8.
Definition: FileSystem.cpp:166