Skip to content
Permalink
Browse files

Some error checking and saving of output file directories in interpol…

…ation plugin

git-svn-id: http://svn.osgeo.org/qgis/trunk@11223 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jul 31, 2009
1 parent 8a6feae commit a697e0f456f252410e04bb94951f7ab9a3bde6f8
@@ -3073,16 +3073,34 @@ QList<int>* DualEdgeTriangulation::getPointsAroundEdge( double x, double y )

bool DualEdgeTriangulation::saveAsShapefile( const QString& fileName ) const
{
QString shapeFileName = fileName;

QgsFieldMap fields;
fields.insert( 0, QgsField( "type", QVariant::String, "String" ) );
QgsVectorFileWriter writer( fileName, "Utf-8", fields, QGis::WKBLineString, 0 );

// add the extension if not present
if ( shapeFileName.indexOf( ".shp" ) == -1 )
{
shapeFileName += ".shp";
}

//delete already existing files
if ( QFile::exists( shapeFileName ) )
{
if ( !QgsVectorFileWriter::deleteShapeFile( shapeFileName ) )
{
return false;
}
}

QgsVectorFileWriter writer( shapeFileName, "Utf-8", fields, QGis::WKBLineString, 0 );
if ( writer.hasError() != QgsVectorFileWriter::NoError )
{
return false;
}

bool *alreadyVisitedEdges = new bool[mHalfEdge.size()];
if( !alreadyVisitedEdges )
if ( !alreadyVisitedEdges )
{
QgsDebugMsg( "out of memory" );
return false;
@@ -28,6 +28,7 @@
#include <QComboBox>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>


QgsInterpolationDialog::QgsInterpolationDialog( QWidget* parent, QgisInterface* iface ): QDialog( parent ), mIface( iface ), mInterpolatorDialog( 0 )
@@ -54,21 +55,50 @@ QgsInterpolationDialog::QgsInterpolationDialog( QWidget* parent, QgisInterface*
//only inverse distance weighting available for now
mInterpolationMethodComboBox->insertItem( 0, tr( "Triangular interpolation (TIN)" ) );
mInterpolationMethodComboBox->insertItem( 1, tr( "Inverse Distance Weighting (IDW)" ) );

enableOrDisableOkButton();
}

QgsInterpolationDialog::~QgsInterpolationDialog()
{

}

void QgsInterpolationDialog::enableOrDisableOkButton()
{
bool enabled = true;

//no input data
if ( mLayersTreeWidget->topLevelItemCount() < 1 )
{
enabled = false;
}
else
{
QString fileName = mOutputFileLineEdit->text();
QFileInfo theFileInfo( fileName );
if ( fileName.isEmpty() || !theFileInfo.dir().exists() )
{
enabled = false;
}
}

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}

void QgsInterpolationDialog::on_buttonBox_accepted()
{
if ( !mInterpolatorDialog )
{
return;
}

//todo: test if an input layer is there and warn the user if not
//warn the user if there isn't any input layer
if ( mLayersTreeWidget->topLevelItemCount() < 1 )
{
QMessageBox::information( 0, tr( "No input data for interpolation" ), tr( "Please add one or more input layers" ) );
return;
}

//read file name
QString fileName = mOutputFileLineEdit->text();
@@ -241,6 +271,8 @@ void QgsInterpolationDialog::on_mAddPushButton_clicked()
typeComboBox->addItem( tr( "Break lines" ) );
typeComboBox->setCurrentIndex( 0 );
mLayersTreeWidget->setItemWidget( newLayerItem, 2, typeComboBox );

enableOrDisableOkButton();
}

void QgsInterpolationDialog::on_mRemovePushButton_clicked()
@@ -251,16 +283,28 @@ void QgsInterpolationDialog::on_mRemovePushButton_clicked()
return;
}
delete currentItem;
enableOrDisableOkButton();
}


void QgsInterpolationDialog::on_mOutputFileButton_clicked()
{
QString rasterFileName = QFileDialog::getSaveFileName( 0 );
//get last output file dir
QSettings s;
QString lastOutputDir = s.value( "/Interpolation/lastOutputDir", "" ).toString();

QString rasterFileName = QFileDialog::getSaveFileName( 0, tr( "Save interpolated raster as..." ), lastOutputDir );
if ( !rasterFileName.isEmpty() )
{
mOutputFileLineEdit->setText( rasterFileName );
QFileInfo rasterFileInfo( rasterFileName );
QDir fileDir = rasterFileInfo.absoluteDir();
if ( fileDir.exists() )
{
s.setValue( "/Interpolation/lastOutputDir", rasterFileInfo.absolutePath() );
}
}
enableOrDisableOkButton();
}

void QgsInterpolationDialog::on_mConfigureInterpolationButton_clicked()
@@ -50,6 +50,8 @@ class QgsInterpolationDialog: public QDialog, private Ui::QgsInterpolationDialog
/**Returns the vector layer object with the given name
Returns a pointer to the vector layer or 0 in case of error.*/
QgsVectorLayer* vectorLayerFromName( const QString& name );
/**Enables or disables the Ok button depending on the availability of input layers and the output file*/
void enableOrDisableOkButton();
};

#endif
@@ -18,6 +18,7 @@
#include "qgstininterpolatordialog.h"
#include "qgstininterpolator.h"
#include <QFileDialog>
#include <QSettings>

QgsTINInterpolatorDialog::QgsTINInterpolatorDialog( QWidget* parent, QgisInterface* iface ): QgsInterpolatorDialog( parent, iface )
{
@@ -69,6 +70,20 @@ void QgsTINInterpolatorDialog::on_mExportTriangulationCheckBox_stateChanged( int

void QgsTINInterpolatorDialog::on_mTriangulationFileButton_clicked()
{
QString filename = QFileDialog::getSaveFileName( 0, tr( "Save triangulation to file" ), QString(), "*shp" );
mTriangulationFileEdit->setText( filename );
QSettings s;
//read last triangulation directory
QString lastTriangulationDir = s.value( "/Interpolation/lastTriangulationDir", "" ).toString();
QString filename = QFileDialog::getSaveFileName( 0, tr( "Save triangulation to file" ), lastTriangulationDir, "*shp" );
if ( !filename.isEmpty() )
{
mTriangulationFileEdit->setText( filename );

//and save triangulation directory
QFileInfo triangulationFileInfo( filename );
QDir fileDir = triangulationFileInfo.absoluteDir();
if ( fileDir.exists() )
{
s.setValue( "/Interpolation/lastTriangulationDir", triangulationFileInfo.absolutePath() );
}
}
}

0 comments on commit a697e0f

Please sign in to comment.
You can’t perform that action at this time.