Skip to content

Commit 627a590

Browse files
committed
Fix geometry checker cannot export errors to gpkg
Fixes #18128 Also exposes other format choices in dialog
1 parent 605ea37 commit 627a590

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/plugins/geometry_checker/qgsgeometrycheckerresulttab.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qgsgeometrychecker.h"
2828
#include "qgsgeometrycheck.h"
2929
#include "qgsfeaturepool.h"
30+
#include "qgsfileutils.h"
3031

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

229-
QString file = QFileDialog::getSaveFileName( this, tr( "Select Output File" ), initialdir, tr( "GeoPackage (*.gpkg);;" ) );
230+
QString selectedFilter;
231+
QString file = QFileDialog::getSaveFileName( this, tr( "Select Output File" ), initialdir, QgsVectorFileWriter::fileFilterString(), &selectedFilter );
230232
if ( file.isEmpty() )
231233
{
232234
return;
233235
}
236+
237+
file = QgsFileUtils::addExtensionFromFilter( file, selectedFilter );
234238
if ( !exportErrorsDo( file ) )
235239
{
236-
QMessageBox::critical( this, tr( "Error" ), tr( "Failed to export errors to shapefile." ) );
240+
QMessageBox::critical( this, tr( "Export Errors" ), tr( "Failed to export errors to %1." ).arg( QDir::toNativeSeparators( file ) ) );
237241
}
238242
}
239243

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

251+
QFileInfo fi( file );
252+
QString ext = fi.suffix();
253+
QString driver = QgsVectorFileWriter::driverForExtension( ext );
254+
247255
QLibrary ogrLib( QgsProviderRegistry::instance()->library( QStringLiteral( "ogr" ) ) );
248256
if ( !ogrLib.load() )
249257
{
@@ -255,7 +263,7 @@ bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString &file )
255263
{
256264
return false;
257265
}
258-
if ( !createEmptyDataSource( file, QStringLiteral( "ESRI Shapefile" ), "UTF-8", QgsWkbTypes::Point, attributes, QgsProject::instance()->crs() ) )
266+
if ( !createEmptyDataSource( file, driver, "UTF-8", QgsWkbTypes::Point, attributes, QgsProject::instance()->crs() ) )
259267
{
260268
return false;
261269
}

0 commit comments

Comments
 (0)