Skip to content
Permalink
Browse files

Fix geometry checker cannot export errors to gpkg

Fixes #18128

Also exposes other format choices in dialog
  • Loading branch information
nyalldawson committed Feb 19, 2018
1 parent 605ea37 commit 627a590c9b826b33fe067974319daaf877fa89a3
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/plugins/geometry_checker/qgsgeometrycheckerresulttab.cpp
@@ -27,6 +27,7 @@
#include "qgsgeometrychecker.h"
#include "qgsgeometrycheck.h"
#include "qgsfeaturepool.h"
#include "qgsfileutils.h"

#include "qgsgeometry.h"
#include "qgisinterface.h"
@@ -226,14 +227,17 @@ void QgsGeometryCheckerResultTab::exportErrors()
initialdir = dir.absolutePath();
}

QString file = QFileDialog::getSaveFileName( this, tr( "Select Output File" ), initialdir, tr( "GeoPackage (*.gpkg);;" ) );
QString selectedFilter;
QString file = QFileDialog::getSaveFileName( this, tr( "Select Output File" ), initialdir, QgsVectorFileWriter::fileFilterString(), &selectedFilter );
if ( file.isEmpty() )
{
return;
}

file = QgsFileUtils::addExtensionFromFilter( file, selectedFilter );
if ( !exportErrorsDo( file ) )
{
QMessageBox::critical( this, tr( "Error" ), tr( "Failed to export errors to shapefile." ) );
QMessageBox::critical( this, tr( "Export Errors" ), tr( "Failed to export errors to %1." ).arg( QDir::toNativeSeparators( file ) ) );
}
}

@@ -244,6 +248,10 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString &file )
attributes.append( qMakePair( QStringLiteral( "FeatureID" ), QStringLiteral( "String;10;" ) ) );
attributes.append( qMakePair( QStringLiteral( "ErrorDesc" ), QStringLiteral( "String;80;" ) ) );

QFileInfo fi( file );
QString ext = fi.suffix();
QString driver = QgsVectorFileWriter::driverForExtension( ext );

QLibrary ogrLib( QgsProviderRegistry::instance()->library( QStringLiteral( "ogr" ) ) );
if ( !ogrLib.load() )
{
@@ -255,7 +263,7 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString &file )
{
return false;
}
if ( !createEmptyDataSource( file, QStringLiteral( "ESRI Shapefile" ), "UTF-8", QgsWkbTypes::Point, attributes, QgsProject::instance()->crs() ) )
if ( !createEmptyDataSource( file, driver, "UTF-8", QgsWkbTypes::Point, attributes, QgsProject::instance()->crs() ) )
{
return false;
}

0 comments on commit 627a590

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