Skip to content

Commit ee2123e

Browse files
author
jef
committed
add sanity checks to new vector dialog and some cleanups
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13079 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 92daba6 commit ee2123e

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/app/qgsnewvectorlayerdialog.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WFlags fl
5757

5858
mCrsId = srs.srsid();
5959
leSpatialRefSys->setText( srs.toProj4() );
60+
61+
connect( mNameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( nameChanged( QString ) ) );
62+
connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );
63+
64+
mAddAttributeButton->setEnabled( false );
65+
mRemoveAttributeButton->setEnabled( false );
6066
}
6167

6268
QgsNewVectorLayerDialog::~QgsNewVectorLayerDialog()
@@ -69,23 +75,24 @@ void QgsNewVectorLayerDialog::on_mTypeBox_currentIndexChanged( int index )
6975
switch ( index )
7076
{
7177
case 0: // Text data
72-
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
78+
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 255 )
79+
mWidth->setText( "80" );
7380
mPrecision->setEnabled( false );
81+
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
7482
break;
7583

7684
case 1: // Whole number
77-
if ( mWidth->text().toInt() > 10 )
85+
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 10 )
7886
mWidth->setText( "10" );
7987
mPrecision->setEnabled( false );
8088
mWidth->setValidator( new QIntValidator( 1, 10, this ) );
8189
break;
8290

8391
case 2: // Decimal number
84-
if ( mWidth->text().toInt() > 20 )
92+
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 20 )
8593
mWidth->setText( "20" );
86-
mPrecision->setEnabled( false );
87-
mWidth->setValidator( new QIntValidator( 1, 20, this ) );
8894
mPrecision->setEnabled( true );
95+
mWidth->setValidator( new QIntValidator( 1, 20, this ) );
8996
break;
9097

9198
default:
@@ -176,3 +183,13 @@ QString QgsNewVectorLayerDialog::selectedFileFormat() const
176183
QString myType = mFileFormatComboBox->itemData( mFileFormatComboBox->currentIndex(), Qt::UserRole ).toString();
177184
return myType;
178185
}
186+
187+
void QgsNewVectorLayerDialog::nameChanged( QString name )
188+
{
189+
mAddAttributeButton->setDisabled( name.isEmpty() || mAttributeView->findItems( name, Qt::MatchExactly ).size() > 0 );
190+
}
191+
192+
void QgsNewVectorLayerDialog::selectionChanged()
193+
{
194+
mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().size() == 0 );
195+
}

src/app/qgsnewvectorlayerdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class QgsNewVectorLayerDialog: public QDialog, private Ui::QgsNewVectorLayerDial
4646
void on_mTypeBox_currentIndexChanged( int index );
4747
void on_pbnChangeSpatialRefSys_clicked();
4848
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
49+
void nameChanged( QString );
50+
void selectionChanged();
4951

5052
private:
5153
QPushButton *mOkButton;

0 commit comments

Comments
 (0)