Skip to content

Commit

Permalink
[BACKPORT] use native projection selector in New SpatiaLite layer
Browse files Browse the repository at this point in the history
dialog (completely fix #4549)
  • Loading branch information
alexbruy committed Dec 22, 2011
1 parent 4d761d0 commit 270655d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 199 deletions.
4 changes: 1 addition & 3 deletions src/app/CMakeLists.txt
Expand Up @@ -139,7 +139,7 @@ SET(QGIS_APP_SRCS
)

IF (ANDROID)
SET(QGIS_APP_SRCS
SET(QGIS_APP_SRCS
${QGIS_APP_SRCS}
qtmain_android.cpp
)
Expand Down Expand Up @@ -331,11 +331,9 @@ ENDIF (POSTGRES_FOUND)
IF (HAVE_SPATIALITE)
SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
spatialite/qgsnewspatialitelayerdialog.cpp
spatialite/qgsspatialitesridsdialog.cpp
)
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
spatialite/qgsnewspatialitelayerdialog.h
spatialite/qgsspatialitesridsdialog.h
)
ENDIF (HAVE_SPATIALITE)

Expand Down
77 changes: 67 additions & 10 deletions src/app/spatialite/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -20,12 +20,14 @@

#include "qgsnewspatialitelayerdialog.h"

#include "qgsspatialitesridsdialog.h"
#include "qgis.h"
#include "qgsapplication.h"
#include "qgsproviderregistry.h"
#include "qgisapp.h" // <- for theme icons
#include <qgsvectorlayer.h>
#include <qgsmaplayerregistry.h>
#include "qgscoordinatereferencesystem.h"
#include "qgsgenericprojectionselector.h"

#include "qgslogger.h"

Expand Down Expand Up @@ -72,7 +74,12 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
buttonBox->button( QDialogButtonBox::Ok )->setDefault( true );

// Set the SRID box to a default of WGS84
leSRID->setText( "4326" );
QgsCoordinateReferenceSystem srs;
srs.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
srs.validate();
mCrsId = srs.srsid();
leSRID->setText( srs.authid() + " - " + srs.description() );

pbnFindSRID->setEnabled( mDatabaseComboBox->count() );
}

Expand Down Expand Up @@ -176,17 +183,67 @@ void QgsNewSpatialiteLayerDialog::on_mRemoveAttributeButton_clicked()

void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
{
// set the SRID from a list returned from the selected Spatialite database
QgsSpatialiteSridsDialog *sridDlg = new QgsSpatialiteSridsDialog( this );
if ( sridDlg->load( mDatabaseComboBox->currentText() ) )
// first get list of supported SRID from the selected Spatialite database
// to build filter for projection selector
sqlite3 *db = 0;
bool status = true;
if ( !db )
{
int rc = sqlite3_open_v2( mDatabaseComboBox->currentText().toUtf8(), &db, SQLITE_OPEN_READONLY, NULL );
if ( rc != SQLITE_OK )
{
QMessageBox::warning( this, tr( "SpatiaLite Database" ), tr( "Unable to open the database" ) );
return;
}
}

// load up the srid table
const char *pzTail;
sqlite3_stmt *ppStmt;
QString sql = "select auth_srid, auth_name, ref_sys_name from spatial_ref_sys order by srid asc";

QSet<QString> myCRSs;

int rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail );
// XXX Need to free memory from the error msg if one is set
if ( rc == SQLITE_OK )
{
if ( sridDlg->exec() )
// get the first row of the result set
while ( sqlite3_step( ppStmt ) == SQLITE_ROW )
{
// set the srid field to the selection
leSRID->setText( sridDlg->selectedSrid() );
sridDlg->accept();
myCRSs.insert( QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) ) +
":" + QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
}
}
else
{
// XXX query failed -- warn the user some how
QMessageBox::warning( 0, tr( "Error" ), tr( "Failed to load SRIDS: %1" ).arg( sqlite3_errmsg( db ) ) );
status = false;
}
// close the statement
sqlite3_finalize( ppStmt );
sqlite3_close( db );

if ( !status )
{
return;
}

// prepare projection selector
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
mySelector->setMessage();
mySelector->setOgcWmsCrsFilter( myCRSs );

if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs;
srs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
bool ok;
mCrsId = srs.authid().split( ':' ).at( 1 ).toInt( &ok );
leSRID->setText( srs.authid() + " - " + srs.description() );
}
delete mySelector;
}

bool QgsNewSpatialiteLayerDialog::createDb()
Expand Down Expand Up @@ -293,7 +350,7 @@ bool QgsNewSpatialiteLayerDialog::apply()
QString sqlAddGeom = QString( "select AddGeometryColumn(%1,%2,%3,%4,2)" )
.arg( quotedValue( leLayerName->text() ) )
.arg( quotedValue( leGeometryColumn->text() ) )
.arg( leSRID->text().toInt() )
.arg( mCrsId )
.arg( quotedValue( selectedType() ) );
QgsDebugMsg( sqlAddGeom ); // OK

Expand Down
2 changes: 2 additions & 0 deletions src/app/spatialite/qgsnewspatialitelayerdialog.h
Expand Up @@ -60,6 +60,8 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL

static QString quotedIdentifier( QString id );
static QString quotedValue( QString value );

int mCrsId;
};

#endif // QGSNEWVECTORLAYERDIALOG_H
139 changes: 0 additions & 139 deletions src/app/spatialite/qgsspatialitesridsdialog.cpp

This file was deleted.

45 changes: 0 additions & 45 deletions src/app/spatialite/qgsspatialitesridsdialog.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/ui/qgsnewspatialitelayerdialogbase.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<width>450</width>
<height>627</height>
</rect>
</property>
Expand Down Expand Up @@ -216,7 +216,7 @@
<string>Specify the coordinate reference system of the layer's geometry.</string>
</property>
<property name="text">
<string>Find SRID</string>
<string>Specify CRS</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 270655d

Please sign in to comment.