Skip to content

Commit a8dc87f

Browse files
alexbruynyalldawson
authored andcommittedMay 18, 2020
sensible defaults for new fields in the New memory layer dialog
1 parent 5948c3f commit a8dc87f

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed
 

‎src/gui/qgsnewmemorylayerdialog.cpp

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,21 @@ QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFla
7777
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDate.svg" ) ), tr( "Date" ), "date" );
7878
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldTime.svg" ) ), tr( "Time" ), "time" );
7979
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDateTime.svg" ) ), tr( "Date & time" ), "datetime" );
80+
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldBinary.svg" ) ), tr( "Binary (BLOB)" ), "binary" );
81+
mTypeBox_currentIndexChanged( 1 );
8082

8183
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
82-
mPrecision->setValidator( new QIntValidator( 0, 15, this ) );
84+
mPrecision->setValidator( new QIntValidator( 0, 30, this ) );
85+
86+
mAddAttributeButton->setEnabled( false );
87+
mRemoveAttributeButton->setEnabled( false );
8388

8489
mOkButton = mButtonBox->button( QDialogButtonBox::Ok );
8590
mOkButton->setEnabled( false );
8691

8792
connect( mGeometryTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewMemoryLayerDialog::geometryTypeChanged );
8893
connect( mFieldNameEdit, &QLineEdit::textChanged, this, &QgsNewMemoryLayerDialog::fieldNameChanged );
94+
connect( mTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewMemoryLayerDialog::mTypeBox_currentIndexChanged );
8995
connect( mAttributeView, &QTreeWidget::itemSelectionChanged, this, &QgsNewMemoryLayerDialog::selectionChanged );
9096
connect( mAddAttributeButton, &QToolButton::clicked, this, &QgsNewMemoryLayerDialog::mAddAttributeButton_clicked );
9197
connect( mRemoveAttributeButton, &QToolButton::clicked, this, &QgsNewMemoryLayerDialog::mRemoveAttributeButton_clicked );
@@ -123,6 +129,69 @@ void QgsNewMemoryLayerDialog::geometryTypeChanged( int )
123129
mOkButton->setEnabled( ok );
124130
}
125131

132+
void QgsNewMemoryLayerDialog::mTypeBox_currentIndexChanged( int index )
133+
{
134+
switch ( index )
135+
{
136+
case 0: // Text data
137+
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 255 )
138+
mWidth->setText( QStringLiteral( "255" ) );
139+
mPrecision->clear();
140+
mPrecision->setEnabled( false );
141+
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
142+
break;
143+
case 1: // Whole number
144+
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 10 )
145+
mWidth->setText( QStringLiteral( "10" ) );
146+
mPrecision->clear();
147+
mPrecision->setEnabled( false );
148+
mWidth->setValidator( new QIntValidator( 1, 10, this ) );
149+
break;
150+
case 2: // Decimal number
151+
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 30 )
152+
mWidth->setText( QStringLiteral( "30" ) );
153+
if ( mPrecision->text().toInt() < 1 || mPrecision->text().toInt() > 30 )
154+
mPrecision->setText( QStringLiteral( "6" ) );
155+
mPrecision->setEnabled( true );
156+
mWidth->setValidator( new QIntValidator( 1, 20, this ) );
157+
break;
158+
case 3: // Boolean
159+
mWidth->clear();
160+
mWidth->setEnabled( false );
161+
mPrecision->clear();
162+
mPrecision->setEnabled( false );
163+
break;
164+
case 4: // Date
165+
mWidth->clear();
166+
mWidth->setEnabled( false );
167+
mPrecision->clear();
168+
mPrecision->setEnabled( false );
169+
break;
170+
case 5: // Time
171+
mWidth->clear();
172+
mWidth->setEnabled( false );
173+
mPrecision->clear();
174+
mPrecision->setEnabled( false );
175+
break;
176+
case 6: // Datetime
177+
mWidth->clear();
178+
mWidth->setEnabled( false );
179+
mPrecision->clear();
180+
mPrecision->setEnabled( false );
181+
break;
182+
case 7: // Binary
183+
mWidth->clear();
184+
mWidth->setEnabled( false );
185+
mPrecision->clear();
186+
mPrecision->setEnabled( false );
187+
break;
188+
189+
default:
190+
QgsDebugMsg( QStringLiteral( "unexpected index" ) );
191+
break;
192+
}
193+
}
194+
126195
void QgsNewMemoryLayerDialog::setCrs( const QgsCoordinateReferenceSystem &crs )
127196
{
128197
mCrsSelector->setCrs( crs );

‎src/gui/qgsnewmemorylayerdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class GUI_EXPORT QgsNewMemoryLayerDialog: public QDialog, private Ui::QgsNewMemo
8383

8484
void geometryTypeChanged( int index );
8585
void fieldNameChanged( const QString & );
86+
void mTypeBox_currentIndexChanged( int index );
8687
void mAddAttributeButton_clicked();
8788
void mRemoveAttributeButton_clicked();
8889
void selectionChanged();

‎src/gui/qgsnewvectorlayerdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged( int index )
168168
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 20 )
169169
mWidth->setText( QStringLiteral( "20" ) );
170170
if ( mPrecision->text().toInt() < 1 || mPrecision->text().toInt() > 15 )
171-
mPrecision->setText( QStringLiteral( "6" ) )
171+
mPrecision->setText( QStringLiteral( "6" ) );
172172

173173
mPrecision->setEnabled( true );
174174
mWidth->setValidator( new QIntValidator( 1, 20, this ) );

0 commit comments

Comments
 (0)
Please sign in to comment.