@@ -56,6 +56,7 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
56
56
mWidth ->setValidator ( new QIntValidator ( 1 , 255 , this ) );
57
57
mPrecision ->setValidator ( new QIntValidator ( 0 , 15 , this ) );
58
58
59
+ mGeometryTypeBox ->addItem ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mIconTableLayer.svg" ) ), tr ( " No Geometry" ), QgsWkbTypes::NoGeometry );
59
60
mGeometryTypeBox ->addItem ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mIconPointLayer.svg" ) ), tr ( " Point" ), QgsWkbTypes::Point );
60
61
mGeometryTypeBox ->addItem ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mIconPointLayer.svg" ) ), tr ( " MultiPoint" ), QgsWkbTypes::MultiPoint );
61
62
mGeometryTypeBox ->addItem ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mIconLineLayer.svg" ) ), tr ( " Line" ), QgsWkbTypes::LineString );
@@ -99,7 +100,23 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
99
100
mAttributeView ->addTopLevelItem ( new QTreeWidgetItem ( QStringList () << QStringLiteral ( " id" ) << QStringLiteral ( " Integer" ) << QStringLiteral ( " 10" ) << QString () ) );
100
101
connect ( mNameEdit , &QLineEdit::textChanged, this , &QgsNewVectorLayerDialog::nameChanged );
101
102
connect ( mAttributeView , &QTreeWidget::itemSelectionChanged, this , &QgsNewVectorLayerDialog::selectionChanged );
102
- connect ( mGeometryTypeBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , &QgsNewVectorLayerDialog::checkOk );
103
+ connect ( mGeometryTypeBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this , [ = ]( int index )
104
+ {
105
+ QString fileName = mFileName ->filePath ();
106
+ if ( !fileName.isEmpty () )
107
+ {
108
+ if ( index == 0 )
109
+ {
110
+ fileName = fileName.replace ( fileName.lastIndexOf ( QLatin1String ( " .shp" ), -1 , Qt::CaseInsensitive ), 4 , QLatin1String ( " .dbf" ) );
111
+ }
112
+ else
113
+ {
114
+ fileName = fileName.replace ( fileName.lastIndexOf ( QLatin1String ( " .dbf" ), -1 , Qt::CaseInsensitive ), 4 , QLatin1String ( " .shp" ) );
115
+ }
116
+ mFileName ->setFilePath ( fileName );
117
+ }
118
+ checkOk ();
119
+ } );
103
120
104
121
mAddAttributeButton ->setEnabled ( false );
105
122
mRemoveAttributeButton ->setEnabled ( false );
@@ -290,8 +307,15 @@ QString QgsNewVectorLayerDialog::execAndCreateLayer( QString &errorMessage, QWid
290
307
291
308
QgsSettings settings;
292
309
QString fileName = geomDialog.filename ();
293
- if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && ! fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) )
310
+ if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && ( geometrytype != QgsWkbTypes::NoGeometry && ! fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) ) )
294
311
fileName += QLatin1String ( " .shp" );
312
+ else if ( fileformat == QLatin1String ( " ESRI Shapefile" ) && ( geometrytype == QgsWkbTypes::NoGeometry && !fileName.endsWith ( QLatin1String ( " .dbf" ), Qt::CaseInsensitive ) ) )
313
+ {
314
+ if ( fileName.endsWith ( QLatin1String ( " .shp" ), Qt::CaseInsensitive ) )
315
+ fileName = fileName.replace ( fileName.lastIndexOf ( QLatin1String ( " .shp" ), -1 , Qt::CaseInsensitive ), 4 , QLatin1String ( " .dbf" ) );
316
+ else
317
+ fileName += QLatin1String ( " .dbf" );
318
+ }
295
319
296
320
settings.setValue ( QStringLiteral ( " UI/lastVectorFileFilterDir" ), QFileInfo ( fileName ).absolutePath () );
297
321
settings.setValue ( QStringLiteral ( " UI/encoding" ), enc );
0 commit comments