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

omgclimateconverter.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 "omgclimateconverter.h"
00022 #include <omgclimateimporter.h>
00023 //qt includes
00024 #include <QSettings>
00025 #include <QFileDialog>
00026 #include <QString>
00027 #include <QMessageBox>
00028 #include <QListWidget>
00029 #include <QListWidgetItem>
00030 #include <QLineEdit>
00031 
00032 OmgClimateConverter::OmgClimateConverter(QWidget* parent, Qt::WFlags fl)
00033     : QDialog(parent,fl) ,
00034     mpOmgClimateImporter(new OmgClimateImporter())
00035 {
00036   //required by Qt4 to initialise the ui
00037   setupUi(this);
00038   readSettings();
00039   connect(mpOmgClimateImporter, SIGNAL(error(QString)), this, SLOT(error(QString)));
00040   connect(mpOmgClimateImporter, SIGNAL(message(QString)), this, SLOT(message(QString)));
00041   connect(mpOmgClimateImporter, SIGNAL(updateProgress(int, int )), this, SLOT(updateProgress(int, int )));
00042 }
00043 
00044 OmgClimateConverter::~OmgClimateConverter()
00045 {}
00046 
00047 void OmgClimateConverter::accept()
00048 {
00049   writeSettings();
00050   done(1);
00051 }
00052 
00053 void OmgClimateConverter::on_pbnSelectFile_clicked()
00054 {
00055   QSettings mySettings;
00056   QString myBaseDir = mySettings.value("climateconverter/inputLayersDirectory","/tmp").toString(); //initial dir
00057   QStringList myFileNameQStringList = QFileDialog::getOpenFileNames(
00058                                         this,
00059                                         "Select one or more files",
00060                                         myBaseDir, //initial dir
00061                                         "Climate Climate Data (*.asc *.mea *.dat)"  //filters to select
00062                                       );
00063   lstInputFiles->addItems(myFileNameQStringList);
00064   QFileInfo myFileInfo(myFileNameQStringList.at(0));
00065   QString myBaseString = myFileInfo.dir().path()+QString("/");
00066   mySettings.setValue("climateconverter/inputLayersDirectory",myBaseString);
00067 }
00068 
00069 void OmgClimateConverter::on_pbnSelectDir_clicked()
00070 {
00071   QString myDir = QFileDialog::getExistingDirectory(
00072                     this,
00073                     "Choose a directory",
00074                     mLastDir);
00075 
00076   mLastDir = myDir;
00077   leOutputDir->setText(myDir);
00078 }
00079 
00080 void OmgClimateConverter::on_pbnProcess_clicked()
00081 {
00082   writeSettings();
00083   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
00084   progressTotal->setMaximum(lstInputFiles->count());
00085   progressTotal->setValue(0);
00086   // Iterate through file list and process
00087   for ( int myFileInt = 0; myFileInt < lstInputFiles->count(); myFileInt++ )
00088   {
00089     QListWidgetItem *myFileItem = lstInputFiles->item( myFileInt );
00090     mpOmgClimateImporter->import(myFileItem->text(), leOutputDir->text(), cboInputFormat->currentText());
00091     progressTask->reset();
00092     qDebug(myFileItem->text().toLocal8Bit()  + " import completed");
00093     progressTotal->setValue(myFileInt+1);
00094   }
00095   QApplication::restoreOverrideCursor();
00096   
00097 }
00098 
00099 void OmgClimateConverter::readSettings()
00100 {
00101   QSettings mySettings;
00102   //leFileName->setText(mySettings.value("climateconverter/filename", "").toString());
00103   mLastDir=(mySettings.value("climateconverter/lastdir",".").toString());
00104   leOutputDir->setText(mLastDir);
00105 }
00106 
00107 void OmgClimateConverter::writeSettings()
00108 {
00109   QSettings mySettings;
00110   //mySettings.setValue("climateconverter/filename", leFileName->text());
00111   mySettings.setValue("climateconverter/lastdir",mLastDir);
00112 }
00113 
00114 void OmgClimateConverter::error(QString theError)
00115 {
00116   QMessageBox::warning( this,QString(tr("File Format Converter Error")),theError);
00117 }
00118 
00119 void OmgClimateConverter::message(QString theMessage)
00120 {
00121   lblMessage->setText(theMessage);
00122 }
00123 
00124 void OmgClimateConverter::updateProgress (int theCurrentValue, int theMaximumValue)
00125 {
00126   progressTask->setMaximum(theMaximumValue);
00127   progressTask->setValue(theCurrentValue);
00128   QApplication::processEvents();
00129 }

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