GeoPackagePublisherDialog.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 src/terraMobilePlugin/qt/GeoPackagePublisherDialog.cpp
22 
23 \brief This interface is used to get the input parameters for GeoPackage Publisher operation.
24 */
25 
26 // TerraLib
27 #include "../../../../common/progress/ProgressManager.h"
28 #include "../../../../common/progress/TaskProgress.h"
29 #include "../../../../common/STLUtils.h"
30 #include "../../../../qt/widgets/progress/ProgressViewerDialog.h"
31 #include "../../../../qt/widgets/utils/ScopedCursor.h"
32 #include "../core/GeopackagePublisher.h"
34 #include "ui_GeoPackagePublisherDialogForm.h"
35 
36 // Qt
37 #include <QFileDialog>
38 #include <QMessageBox>
39 
40 
42 
44  : QDialog(parent, f),
45  m_ui(new Ui::GeoPackagePublisherDialogForm)
46 {
47  // add controls
48  m_ui->setupUi(this);
49 
50  //connects
51  connect(m_ui->m_importSearchPushButton, SIGNAL(clicked()), this, SLOT(onImportSearchPushButtonClicked()));
52  connect(m_ui->m_importOutputPushButton, SIGNAL(clicked()), this, SLOT(onImportOutputPushButtonClicked()));
53  connect(m_ui->m_importPushButton, SIGNAL(clicked()), this, SLOT(onImportPushButtonClicked()));
54  connect(m_ui->m_exportFilePushButton, SIGNAL(clicked()), this, SLOT(onExportFilePushButtonClicked()));
55  connect(m_ui->m_exportPushButton, SIGNAL(clicked()), this, SLOT(onExportPushButtonClicked()));
56 
57  m_task = 0;
58 }
59 
61 {
62  delete m_task;
63 }
64 
66 {
67  if (m_ui->m_importURLLineEdit->text().isEmpty())
68  {
69  m_ui->m_importTableWidget->setRowCount(0);
70 
71  QMessageBox::warning(this, tr("Warning"), tr("Server not defined."));
72  return;
73  }
74 
75  m_ui->m_importTableWidget->setRowCount(0);
76 
77  te::qt::widgets::ScopedCursor c(Qt::WaitCursor);
78 
79  //fill list
80  GeopackagePublisher gpkgPub;
81 
82  GeopackageFiles gpkgFiles = gpkgPub.getGeopackageFiles(m_ui->m_importURLLineEdit->text().toUtf8().data());
83 
84  for (std::size_t t = 0; t < gpkgFiles.size(); ++t)
85  {
86  int row = m_ui->m_importTableWidget->rowCount();
87  m_ui->m_importTableWidget->insertRow(row);
88 
89  GeopackageFile gpkgFile = gpkgFiles[t];
90 
91  QTableWidgetItem* nameItem = new QTableWidgetItem(gpkgFile.m_name.c_str());
92  nameItem->setFlags(Qt::ItemIsSelectable);
93  m_ui->m_importTableWidget->setItem(row, 0, nameItem);
94 
95  QTableWidgetItem* objIdItem = new QTableWidgetItem(gpkgFile.m_objId.c_str());
96  objIdItem->setFlags(Qt::ItemIsSelectable);
97  m_ui->m_importTableWidget->setItem(row, 1, objIdItem);
98 
99  QTableWidgetItem* descItem = new QTableWidgetItem(gpkgFile.m_desc.c_str());
100  descItem->setFlags(Qt::ItemIsSelectable);
101  m_ui->m_importTableWidget->setItem(row, 2, descItem);
102  }
103 
104  m_ui->m_importTableWidget->resizeColumnsToContents();
105 
106 #if (QT_VERSION >= 0x050000)
107  m_ui->m_importTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
108 #else
109  m_ui->m_importTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
110 #endif
111 }
112 
114 {
115  QString dirName = QFileDialog::getExistingDirectory(this, tr("Output GeoPackage File location"));
116 
117  if (dirName.isEmpty())
118  m_ui->m_importOutputLineEdit->clear();
119  else
120  {
121  QString path = dirName.replace(QRegExp("\\\\"), "/");
122 
123  m_ui->m_importOutputLineEdit->setText(path);
124  }
125 }
126 
128 {
129  if (m_ui->m_importOutputLineEdit->text().isEmpty())
130  {
131  QMessageBox::warning(this, tr("Warning"), tr("Output directory not defined."));
132  return;
133  }
134 
135  std::string dir = m_ui->m_importOutputLineEdit->text().toUtf8().data();
136 
137  QItemSelectionModel* select = m_ui->m_importTableWidget->selectionModel();
138 
139  if (select->selectedRows().isEmpty())
140  {
141  QMessageBox::warning(this, tr("Warning"), tr("Select at least one geopackage file to import."));
142  return;
143  }
144 
145  std::string url = m_ui->m_importURLLineEdit->text().toUtf8().data();
146 
147  te::qt::widgets::ScopedCursor c(Qt::WaitCursor);
148 
151 
152  //import
153  GeopackagePublisher gpkgPub;
154 
155  connect(&gpkgPub, SIGNAL(setCurrentStep(double, double, std::string)), this, SLOT(onSetCurrentStep(double, double, std::string)));
156 
157  for (int i = 0; i < m_ui->m_importTableWidget->rowCount(); ++i)
158  {
159  if (m_ui->m_importTableWidget->item(i, 0)->isSelected())
160  {
161  GeopackageFile gpkgFile;
162 
163  gpkgFile.m_name = m_ui->m_importTableWidget->item(i, 0)->text().toUtf8().data();
164  gpkgFile.m_objId = m_ui->m_importTableWidget->item(i, 1)->text().toUtf8().data();
165  gpkgFile.m_desc = m_ui->m_importTableWidget->item(i, 2)->text().toUtf8().data();
166 
167  try
168  {
169  gpkgPub.downloadGeopackageFile(url, gpkgFile, dir);
170  }
171  catch (std::exception const& e)
172  {
173  QMessageBox::warning(this, tr("Warning"), e.what());
174  return;
175  }
176  catch (...)
177  {
178  QMessageBox::warning(this, tr("Warning"), gpkgPub.getErrorMessage().c_str());
179  return;
180  }
181  }
182  }
183 
185 
186  QMessageBox::information(this, tr("Information"), tr("Downloaded Successfully"));
187 }
188 
190 {
191  QString fileName = QFileDialog::getOpenFileName(this, tr("Open GeoPackage File"), "", tr("GeoPackage File (*.gpkg *.GPKG)"));
192 
193  if (fileName.isEmpty())
194  m_ui->m_exportFileLineEdit->clear();
195  else
196  m_ui->m_exportFileLineEdit->setText(fileName);
197 }
198 
200 {
201  if (m_ui->m_exportFileLineEdit->text().isEmpty())
202  {
203  QMessageBox::warning(this, tr("Warning"), tr("Geopackage File not selected."));
204  return;
205  }
206 
207  std::string pathFile = m_ui->m_exportFileLineEdit->text().toUtf8().data();
208 
209  if (m_ui->m_exportServerLineEdit->text().isEmpty())
210  {
211  QMessageBox::warning(this, tr("Warning"), tr("Server not defined."));
212  return;
213  }
214 
215  std::string url = m_ui->m_exportServerLineEdit->text().toUtf8().data();
216 
217 
218  QFileInfo file(m_ui->m_exportFileLineEdit->text());
219 
220  te::qt::widgets::ScopedCursor c(Qt::WaitCursor);
221 
224 
225  //export gpkg
226  GeopackagePublisher gpkgPub;
227 
228  connect(&gpkgPub, SIGNAL(setCurrentStep(double, double, std::string)), this, SLOT(onSetCurrentStep(double, double, std::string)));
229 
230  try
231  {
232  gpkgPub.uploadGeopackageFile(url, pathFile, file.fileName().toUtf8().data());
233  }
234  catch (std::exception const& e)
235  {
236  QMessageBox::warning(this, tr("Warning"), e.what());
237  return;
238  }
239  catch (...)
240  {
241  QMessageBox::warning(this, tr("Warning"), gpkgPub.getErrorMessage().c_str());
242  return;
243  }
244 
246 
247  QMessageBox::information(this, tr("Information"), tr("Uploaded Successfully"));
248 }
249 
250 void te::qt::plugins::terramobile::GeoPackagePublisherDialog::onSetCurrentStep(double curStep, double totalStep, std::string msg)
251 {
252  if (curStep == 0.)
253  return;
254 
255  if (!m_task)
256  {
257  m_task = new te::common::TaskProgress(msg);
258  m_task->setTotalSteps(100);
259  }
260 
261  int nStep = (100. * curStep) / totalStep;
262 
263  m_task->setCurrentStep(nStep);
264 
265  if (curStep == totalStep)
266  {
267  delete m_task;
268  m_task = 0;
269  }
270 }
271 
272 
void uploadGeopackageFile(std::string url, std::string filePath, std::string fileName)
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
std::auto_ptr< Ui::GeoPackagePublisherDialogForm > m_ui
void setTotalSteps(int value)
Set the task total stepes.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
void removeViewer(int viewerId)
Dettach a progress viewer (AbstractProgressViewer destructor calls this method).
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
void downloadGeopackageFile(std::string url, GeopackageFile gpkgFile, std::string pathDir)
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
void setCurrentStep(int value)
Set the task current step.
std::vector< GeopackageFile > GeopackageFiles
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
GeoPackagePublisherDialog(QWidget *parent=0, Qt::WindowFlags f=0)
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
void onSetCurrentStep(double curStep, double totalStep, std::string msg)