Skip to content

Commit

Permalink
sensible defaults for new fields in the New memory layer dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed May 18, 2020
1 parent 5948c3f commit a8dc87f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
71 changes: 70 additions & 1 deletion src/gui/qgsnewmemorylayerdialog.cpp
Expand Up @@ -77,15 +77,21 @@ QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFla
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDate.svg" ) ), tr( "Date" ), "date" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldTime.svg" ) ), tr( "Time" ), "time" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDateTime.svg" ) ), tr( "Date & time" ), "datetime" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldBinary.svg" ) ), tr( "Binary (BLOB)" ), "binary" );
mTypeBox_currentIndexChanged( 1 );

mWidth->setValidator( new QIntValidator( 1, 255, this ) );
mPrecision->setValidator( new QIntValidator( 0, 15, this ) );
mPrecision->setValidator( new QIntValidator( 0, 30, this ) );

mAddAttributeButton->setEnabled( false );
mRemoveAttributeButton->setEnabled( false );

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

connect( mGeometryTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewMemoryLayerDialog::geometryTypeChanged );
connect( mFieldNameEdit, &QLineEdit::textChanged, this, &QgsNewMemoryLayerDialog::fieldNameChanged );
connect( mTypeBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewMemoryLayerDialog::mTypeBox_currentIndexChanged );
connect( mAttributeView, &QTreeWidget::itemSelectionChanged, this, &QgsNewMemoryLayerDialog::selectionChanged );
connect( mAddAttributeButton, &QToolButton::clicked, this, &QgsNewMemoryLayerDialog::mAddAttributeButton_clicked );
connect( mRemoveAttributeButton, &QToolButton::clicked, this, &QgsNewMemoryLayerDialog::mRemoveAttributeButton_clicked );
Expand Down Expand Up @@ -123,6 +129,69 @@ void QgsNewMemoryLayerDialog::geometryTypeChanged( int )
mOkButton->setEnabled( ok );
}

void QgsNewMemoryLayerDialog::mTypeBox_currentIndexChanged( int index )
{
switch ( index )
{
case 0: // Text data
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 255 )
mWidth->setText( QStringLiteral( "255" ) );
mPrecision->clear();
mPrecision->setEnabled( false );
mWidth->setValidator( new QIntValidator( 1, 255, this ) );
break;
case 1: // Whole number
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 10 )
mWidth->setText( QStringLiteral( "10" ) );
mPrecision->clear();
mPrecision->setEnabled( false );
mWidth->setValidator( new QIntValidator( 1, 10, this ) );
break;
case 2: // Decimal number
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 30 )
mWidth->setText( QStringLiteral( "30" ) );
if ( mPrecision->text().toInt() < 1 || mPrecision->text().toInt() > 30 )
mPrecision->setText( QStringLiteral( "6" ) );
mPrecision->setEnabled( true );
mWidth->setValidator( new QIntValidator( 1, 20, this ) );
break;
case 3: // Boolean
mWidth->clear();
mWidth->setEnabled( false );
mPrecision->clear();
mPrecision->setEnabled( false );
break;
case 4: // Date
mWidth->clear();
mWidth->setEnabled( false );
mPrecision->clear();
mPrecision->setEnabled( false );
break;
case 5: // Time
mWidth->clear();
mWidth->setEnabled( false );
mPrecision->clear();
mPrecision->setEnabled( false );
break;
case 6: // Datetime
mWidth->clear();
mWidth->setEnabled( false );
mPrecision->clear();
mPrecision->setEnabled( false );
break;
case 7: // Binary
mWidth->clear();
mWidth->setEnabled( false );
mPrecision->clear();
mPrecision->setEnabled( false );
break;

default:
QgsDebugMsg( QStringLiteral( "unexpected index" ) );
break;
}
}

void QgsNewMemoryLayerDialog::setCrs( const QgsCoordinateReferenceSystem &crs )
{
mCrsSelector->setCrs( crs );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsnewmemorylayerdialog.h
Expand Up @@ -83,6 +83,7 @@ class GUI_EXPORT QgsNewMemoryLayerDialog: public QDialog, private Ui::QgsNewMemo

void geometryTypeChanged( int index );
void fieldNameChanged( const QString & );
void mTypeBox_currentIndexChanged( int index );
void mAddAttributeButton_clicked();
void mRemoveAttributeButton_clicked();
void selectionChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsnewvectorlayerdialog.cpp
Expand Up @@ -168,7 +168,7 @@ void QgsNewVectorLayerDialog::mTypeBox_currentIndexChanged( int index )
if ( mWidth->text().toInt() < 1 || mWidth->text().toInt() > 20 )
mWidth->setText( QStringLiteral( "20" ) );
if ( mPrecision->text().toInt() < 1 || mPrecision->text().toInt() > 15 )
mPrecision->setText( QStringLiteral( "6" ) )
mPrecision->setText( QStringLiteral( "6" ) );

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

0 comments on commit a8dc87f

Please sign in to comment.