Skip to content
Permalink
Browse files

sensible defaults for new fields in the New memory layer dialog

  • Loading branch information
alexbruy authored and nyalldawson committed May 18, 2020
1 parent 5948c3f commit a8dc87f0745e428781585bf58b5cc251c4750cb2
Showing with 72 additions and 2 deletions.
  1. +70 −1 src/gui/qgsnewmemorylayerdialog.cpp
  2. +1 −0 src/gui/qgsnewmemorylayerdialog.h
  3. +1 −1 src/gui/qgsnewvectorlayerdialog.cpp
@@ -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 );
@@ -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 );
@@ -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();
@@ -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 ) );

0 comments on commit a8dc87f

Please sign in to comment.
You can’t perform that action at this time.