Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

omggdalconverter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tim Sutton   *
00003  *   tim@linfiniti.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "omggdalconverter.h"
00022 #include "omggdal.h"
00023 #include "omglayerselector.h"
00024 
00025 //qt includes
00026 #include <QSettings>
00027 #include <QFileDialog>
00028 #include <QString>
00029 #include <QMessageBox>
00030 #include <QListWidget>
00031 #include <QListWidgetItem>
00032 #include <QLineEdit>
00033 
00034 OmgGdalConverter::OmgGdalConverter(QWidget* parent, Qt::WFlags fl)
00035     : QDialog(parent,fl) ,
00036     mpOmgGdal (new OmgGdal()),
00037     mFilterList(QString())
00038 {
00039   //required by Qt4 to initialise the ui
00040   setupUi(this);
00041   readSettings();
00042   connect(mpOmgGdal, SIGNAL(error(QString)), this, SLOT(error(QString)));
00043   connect(mpOmgGdal, SIGNAL(updateProgress(int, int )), this, SLOT(updateProgress(int, int )));
00044   connect(mpOmgGdal, SIGNAL(convertComplete()), this, SLOT(convertComplete()));
00045   mpOmgGdal->buildSupportedRasterFileFilter(mFilterList);
00046 }
00047 
00048 OmgGdalConverter::~OmgGdalConverter()
00049 {
00050   delete mpOmgGdal;
00051 }
00052 
00053 void OmgGdalConverter::accept()
00054 {
00055   writeSettings();
00056   done(1);
00057 }
00058 
00059 void OmgGdalConverter::on_pbnSelectFile_clicked()
00060 {
00061   QStringList myList;
00062   QSettings mySettings;
00063   QString myBaseDir = mySettings.value("gdalconverter/layersDirectory","c:\tmp").toString(); //initial dir
00064   OmgLayerSelector myOmgLayerSelector (myBaseDir, this);
00065   if(myOmgLayerSelector.exec())
00066   {
00067     myList=myOmgLayerSelector.getSelectedLayers();
00068     mySettings.setValue("gdalconverter/layersDirectory",myOmgLayerSelector.getBaseDir());
00069     lstInputFiles->addItems(myList);
00070   }
00071 }
00072 
00073 void OmgGdalConverter::on_pbnSelectDir_clicked()
00074 {
00075   QString myDir = QFileDialog::getExistingDirectory(
00076                     this,
00077                     "Choose a directory",
00078                     mLastDir);
00079 
00080   mLastDir = myDir;
00081   leOutputDir->setText(myDir);
00082 }
00083 
00084 void OmgGdalConverter::on_pbnProcess_clicked()
00085 {
00086   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00087 
00088   // Iterate through file list and process
00089   for ( int myFileInt = 0; myFileInt < lstInputFiles->count(); myFileInt++ )
00090   {
00091     QListWidgetItem *myFileItem = lstInputFiles->item( myFileInt );
00092     if (cboOutputFileType->currentText()=="GeoTiff")
00093     {
00094       qDebug("Converting " + myFileItem->text().toLocal8Bit()
00095           + " to tiff");
00096       mpOmgGdal->convert(myFileItem->text(), leOutputDir->text(), OmgGdal::GeoTiff);
00097     }
00098     else
00099     {
00100       mpOmgGdal->convert(myFileItem->text(), leOutputDir->text(), OmgGdal::ArcInfoAscii);
00101       qDebug("Converting " + myFileItem->text().toLocal8Bit()
00102           + " to ascii");
00103       
00104     }
00105     progressBar->reset();
00106   }
00107   QApplication::restoreOverrideCursor();
00108   QMessageBox::information( this,QString(tr("Conversion result")),QString(tr("File format conversion completed successfully.")));
00109   accept();
00110 }
00111 
00112 void OmgGdalConverter::readSettings()
00113 {
00114   QSettings mySettings;
00115   //leFileName->setText(mySettings.value("gdalconverter/filename", "").toString());
00116   mLastDir=(mySettings.value("gdalconverter/lastdir",".").toString());
00117 }
00118 
00119 void OmgGdalConverter::writeSettings()
00120 {
00121   QSettings mySettings;
00122   //mySettings.setValue("gdalconverter/filename", leFileName->text());
00123   mySettings.setValue("gdalconverter/lastdir",mLastDir);
00124 }
00125 
00126 void OmgGdalConverter::error(QString theError)
00127 {
00128   QMessageBox::warning( this,QString(tr("File Format Converter Error")),theError);
00129 }
00130 
00131 void OmgGdalConverter::updateProgress (int theCurrentValue, int theMaximumValue)
00132 {
00133   progressBar->setMaximum(theMaximumValue);
00134   progressBar->setValue(theCurrentValue);
00135   QApplication::processEvents();
00136 }

Generated on Mon Apr 28 15:07:15 2008 for openModellerDesktop by  doxygen 1.4.1-20050210