Skip to content

Commit d8f5b8d

Browse files
committed
show warning when user tried to create field 'shape' in shapefile (fix #3201)
1 parent 397e3b4 commit d8f5b8d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/app/qgsaddattrdialog.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
#include "qgsvectordataprovider.h"
2121
#include "qgslogger.h"
2222

23+
#include <QMessageBox>
24+
2325
QgsAddAttrDialog::QgsAddAttrDialog( QgsVectorLayer *vlayer, QWidget *parent, Qt::WFlags fl )
2426
: QDialog( parent, fl )
2527
{
2628
setupUi( this );
2729

2830
//fill data types into the combo box
2931
const QList< QgsVectorDataProvider::NativeType > &typelist = vlayer->dataProvider()->nativeTypes();
32+
mLayerType = vlayer->storageType();
3033

3134
for ( int i = 0; i < typelist.size(); i++ )
3235
{
@@ -70,6 +73,17 @@ void QgsAddAttrDialog::on_mTypeBox_currentIndexChanged( int idx )
7073
mPrec->setValue( mPrec->maximum() );
7174
}
7275

76+
void QgsAddAttrDialog::accept()
77+
{
78+
if ( mLayerType == "ESRI Shapefile" && mNameEdit->text().toLower() == "shape" )
79+
{
80+
QMessageBox::warning( this, tr( "Warning" ),
81+
tr( "Invalid field name. This field name is reserved and cannot be used." ) );
82+
return;
83+
}
84+
QDialog::accept();
85+
}
86+
7387
QgsField QgsAddAttrDialog::field() const
7488
{
7589
QgsDebugMsg( QString( "idx:%1 name:%2 type:%3 typeName:%4 length:%5 prec:%6 comment:%7" )

src/app/qgsaddattrdialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class QgsAddAttrDialog: public QDialog, private Ui::QgsAddAttrDialogBase
3737

3838
public slots:
3939
void on_mTypeBox_currentIndexChanged( int idx );
40+
void accept();
41+
42+
private:
43+
QString mLayerType;
4044

4145
};
4246

0 commit comments

Comments
 (0)