mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Some error checking and saving of output file directories in interpolation plugin
git-svn-id: http://svn.osgeo.org/qgis/trunk@11223 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
8a6feaefea
commit
a697e0f456
@ -3073,9 +3073,27 @@ 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;
|
||||
|
@ -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,6 +55,8 @@ 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()
|
||||
@ -61,6 +64,28 @@ 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 )
|
||||
@ -68,7 +93,12 @@ void QgsInterpolationDialog::on_buttonBox_accepted()
|
||||
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,17 +283,29 @@ 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" );
|
||||
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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user