Skip to content

Commit

Permalink
Merge pull request #5827 from nirvn/spatialite_zm
Browse files Browse the repository at this point in the history
[spatialite provider] Fix ZM support
  • Loading branch information
nirvn committed Dec 11, 2017
2 parents 2ec1a0f + 1da0f8e commit 3d1d82e
Show file tree
Hide file tree
Showing 6 changed files with 692 additions and 456 deletions.
33 changes: 28 additions & 5 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -56,10 +56,10 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
restoreGeometry( settings.value( QStringLiteral( "Windows/NewSpatiaLiteLayer/geometry" ) ).toByteArray() );

mGeometryTypeBox->addItem( tr( "Point" ), QStringLiteral( "POINT" ) );
mGeometryTypeBox->addItem( tr( "Line" ), QStringLiteral( "LINE" ) );
mGeometryTypeBox->addItem( tr( "Line" ), QStringLiteral( "LINESTRING" ) );
mGeometryTypeBox->addItem( tr( "Polygon" ), QStringLiteral( "POLYGON" ) );
mGeometryTypeBox->addItem( tr( "MultiPoint" ), QStringLiteral( "MULTIPOINT" ) );
mGeometryTypeBox->addItem( tr( "MultiLine" ), QStringLiteral( "MULTILINE" ) );
mGeometryTypeBox->addItem( tr( "MultiLine" ), QStringLiteral( "MULTILINESTRING" ) );
mGeometryTypeBox->addItem( tr( "MultiPolygon" ), QStringLiteral( "MULTIPOLYGON" ) );

mAddAttributeButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewAttribute.svg" ) ) );
Expand Down Expand Up @@ -147,6 +147,24 @@ QString QgsNewSpatialiteLayerDialog::selectedType() const
return mGeometryTypeBox->currentData( Qt::UserRole ).toString();
}

QString QgsNewSpatialiteLayerDialog::selectedZM() const
{
if ( mGeometryWithZCheckBox->isChecked() && !mGeometryWithMCheckBox->isChecked() )
{
return QStringLiteral( "XYZ" );
}
else if ( !mGeometryWithZCheckBox->isChecked() && mGeometryWithMCheckBox->isChecked() )
{
return QStringLiteral( "XYM" );
}
else if ( mGeometryWithZCheckBox->isChecked() && mGeometryWithMCheckBox->isChecked() )
{
return QStringLiteral( "XYZM" );
}

return QStringLiteral( "XY" );
}

void QgsNewSpatialiteLayerDialog::checkOk()
{
bool created = !leLayerName->text().isEmpty() &&
Expand Down Expand Up @@ -320,7 +338,8 @@ bool QgsNewSpatialiteLayerDialog::createDb()
settings.setValue( QStringLiteral( "SpatiaLite/connections/selected" ), fi.fileName() + tr( "@" ) + fi.canonicalFilePath() );
settings.setValue( key, fi.canonicalFilePath() );

QMessageBox::information( nullptr, tr( "SpatiaLite Database" ), tr( "Registered new database!" ) );
// Reload connections to refresh browser panel
QgisApp::instance()->reloadConnections();
}

pbnFindSRID->setEnabled( true );
Expand Down Expand Up @@ -366,11 +385,12 @@ bool QgsNewSpatialiteLayerDialog::apply()

QgsDebugMsg( sql ); // OK

QString sqlAddGeom = QStringLiteral( "select AddGeometryColumn(%1,%2,%3,%4,2)" )
QString sqlAddGeom = QStringLiteral( "select AddGeometryColumn(%1,%2,%3,%4,%5)" )
.arg( quotedValue( leLayerName->text() ),
quotedValue( leGeometryColumn->text() ) )
.arg( mCrsId.split( ':' ).value( 1, QStringLiteral( "0" ) ).toInt() )
.arg( quotedValue( selectedType() ) );
.arg( quotedValue( selectedType() ) )
.arg( quotedValue( selectedZM() ) );
QgsDebugMsg( sqlAddGeom ); // OK

QString sqlCreateIndex = QStringLiteral( "select CreateSpatialIndex(%1,%2)" )
Expand Down Expand Up @@ -426,6 +446,9 @@ bool QgsNewSpatialiteLayerDialog::apply()
leGeometryColumn->text() ), leLayerName->text(), QStringLiteral( "spatialite" ) );
if ( layer->isValid() )
{
// Reload connections to refresh browser panel
QgisApp::instance()->reloadConnections();

// register this layer with the central layers registry
QList<QgsMapLayer *> myList;
myList << layer;
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsnewspatialitelayerdialog.h
Expand Up @@ -55,6 +55,8 @@ class APP_EXPORT QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNew
private:
//! Returns the selected geometry type
QString selectedType() const;
//! Returns the selected Z dimension and/or M measurement
QString selectedZM() const;

//! Create a new database
bool createDb();
Expand Down

0 comments on commit 3d1d82e

Please sign in to comment.