Skip to content

Commit

Permalink
Merge pull request #47052 from nirvn/new_gpkg_json_field_missing
Browse files Browse the repository at this point in the history
[ui] Fix missing array & json field types in the new {memory,geopackage} layer dialogs
  • Loading branch information
nirvn committed Jan 30, 2022
2 parents db2288b + d41ed99 commit 81e5e91
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 6 deletions.
4 changes: 4 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,14 @@
<file>themes/default/mIconExpressionPreview.svg</file>
<file>themes/default/mIconExpressionSelect.svg</file>
<file>themes/default/mIconFavorites.svg</file>
<file>themes/default/mIconFieldArrayString.svg</file>
<file>themes/default/mIconFieldArrayInteger.svg</file>
<file>themes/default/mIconFieldArrayFloat.svg</file>
<file>themes/default/mIconFieldDate.svg</file>
<file>themes/default/mIconFieldDateTime.svg</file>
<file>themes/default/mIconFieldFloat.svg</file>
<file>themes/default/mIconFieldInteger.svg</file>
<file>themes/default/mIconFieldJson.svg</file>
<file>themes/default/mIconFieldText.svg</file>
<file>themes/default/mIconFieldTime.svg</file>
<file>themes/default/mIconFile.svg</file>
Expand Down
7 changes: 7 additions & 0 deletions images/themes/default/mIconFieldArray.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/themes/default/mIconFieldArrayFloat.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions images/themes/default/mIconFieldArrayInteger.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions images/themes/default/mIconFieldArrayString.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions images/themes/default/mIconFieldJson.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions src/gui/qgsnewgeopackagelayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ QgsNewGeoPackageLayerDialog::QgsNewGeoPackageLayerDialog( QWidget *parent, Qt::W
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDateTime.svg" ) ), tr( "Date and Time" ), "datetime" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldBool.svg" ) ), tr( "Boolean" ), "bool" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldBinary.svg" ) ), tr( "Binary (BLOB)" ), "binary" );
mFieldTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldJson.svg" ) ), tr( "JSON" ), "json" );

mOkButton = buttonBox->button( QDialogButtonBox::Ok );
mOkButton->setEnabled( false );
Expand Down Expand Up @@ -455,8 +456,8 @@ bool QgsNewGeoPackageLayerDialog::apply()
const QString fieldType( ( *it )->text( 1 ) );
const QString fieldWidth( ( *it )->text( 2 ) );

bool isBool = false;
OGRFieldType ogrType( OFTString );
OGRFieldSubType ogrSubType = OFSTNone;
if ( fieldType == QLatin1String( "text" ) )
ogrType = OFTString;
else if ( fieldType == QLatin1String( "integer" ) )
Expand All @@ -472,18 +473,24 @@ bool QgsNewGeoPackageLayerDialog::apply()
else if ( fieldType == QLatin1String( "bool" ) )
{
ogrType = OFTInteger;
isBool = true;
ogrSubType = OFSTBoolean;
}
else if ( fieldType == QLatin1String( "binary" ) )
ogrType = OFTBinary;
else if ( fieldType == QLatin1String( "json" ) )
{
ogrType = OFTString;
ogrSubType = OFSTJSON;
}

const int ogrWidth = fieldWidth.toInt();

const gdal::ogr_field_def_unique_ptr fld( OGR_Fld_Create( fieldName.toUtf8().constData(), ogrType ) );
if ( ogrSubType != OFSTNone )
OGR_Fld_SetSubType( fld.get(), ogrSubType );

if ( ogrType != OFTBinary )
OGR_Fld_SetWidth( fld.get(), ogrWidth );
if ( isBool )
OGR_Fld_SetSubType( fld.get(), OFSTBoolean );

if ( OGR_L_CreateField( hLayer, fld.get(), true ) != OGRERR_NONE )
{
Expand Down
35 changes: 33 additions & 2 deletions src/gui/qgsnewmemorylayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFla
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldTime.svg" ) ), tr( "Time" ), "time" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldDateTime.svg" ) ), tr( "Date and Time" ), "datetime" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldBinary.svg" ) ), tr( "Binary (BLOB)" ), "binary" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldArrayString.svg" ) ), tr( "String List" ), "stringlist" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldArrayInteger.svg" ) ), tr( "Integer List" ), "integerlist" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldArrayFloat.svg" ) ), tr( "Decimal (real) list" ), "doublelist" );
mTypeBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldArrayInteger.svg" ) ), tr( "Integer (64bit) List" ), "integer64list" );
mTypeBox_currentIndexChanged( 1 );

mWidth->setValidator( new QIntValidator( 1, 255, this ) );
Expand Down Expand Up @@ -192,6 +196,10 @@ void QgsNewMemoryLayerDialog::mTypeBox_currentIndexChanged( int index )
mPrecision->setEnabled( false );
break;
case 7: // Binary
case 8: // Stringlist
case 9: // Integerlist
case 10: // Doublelist
case 11: // Integer64list
mWidth->clear();
mWidth->setEnabled( false );
mPrecision->clear();
Expand Down Expand Up @@ -241,6 +249,7 @@ QgsFields QgsNewMemoryLayerDialog::fields() const
const int width = ( *it )->text( 2 ).toInt();
const int precision = ( *it )->text( 3 ).toInt();
QVariant::Type fieldType = QVariant::Invalid;
QVariant::Type fieldSubType = QVariant::Invalid;
if ( typeName == QLatin1String( "string" ) )
fieldType = QVariant::String;
else if ( typeName == QLatin1String( "integer" ) )
Expand All @@ -255,8 +264,30 @@ QgsFields QgsNewMemoryLayerDialog::fields() const
fieldType = QVariant::Time;
else if ( typeName == QLatin1String( "datetime" ) )
fieldType = QVariant::DateTime;

const QgsField field = QgsField( name, fieldType, typeName, width, precision );
else if ( typeName == QLatin1String( "binary" ) )
fieldType = QVariant::ByteArray;
else if ( typeName == QLatin1String( "stringlist" ) )
{
fieldType = QVariant::StringList;
fieldSubType = QVariant::String;
}
else if ( typeName == QLatin1String( "integerlist" ) )
{
fieldType = QVariant::List;
fieldSubType = QVariant::Int;
}
else if ( typeName == QLatin1String( "doublelist" ) )
{
fieldType = QVariant::List;
fieldSubType = QVariant::Double;
}
else if ( typeName == QLatin1String( "integer64list" ) )
{
fieldType = QVariant::List;
fieldSubType = QVariant::LongLong;
}

const QgsField field = QgsField( name, fieldType, typeName, width, precision, QString(), fieldSubType );
fields.append( field );
++it;
}
Expand Down

0 comments on commit 81e5e91

Please sign in to comment.