Skip to content
Permalink
Browse files

[BACKPORT] use native projection selector in New SpatiaLite layer

dialog (completely fix #4549)
  • Loading branch information
alexbruy committed Dec 22, 2011
1 parent b628146 commit c1eea9062aa34ffdcc852d05cc14c6b3312f69da
@@ -304,13 +304,11 @@ IF (HAVE_SPATIALITE)
SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
spatialite/qgsspatialitesourceselect.cpp
spatialite/qgsnewspatialitelayerdialog.cpp
spatialite/qgsspatialitesridsdialog.cpp
spatialite/qgsspatialitetablemodel.cpp
)
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
spatialite/qgsspatialitesourceselect.h
spatialite/qgsnewspatialitelayerdialog.h
spatialite/qgsspatialitesridsdialog.h
spatialite/qgsspatialitetablemodel.h
)
ENDIF (HAVE_SPATIALITE)
@@ -21,11 +21,13 @@

#include "qgsnewspatialitelayerdialog.h"

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

#include "qgslogger.h"

@@ -71,7 +73,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() );
}

@@ -174,17 +181,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;
}

void QgsNewSpatialiteLayerDialog::initializeSpatialMetadata( sqlite3 *sqlite_handle )
@@ -348,7 +405,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

@@ -64,6 +64,8 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL

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

int mCrsId;
};

#endif // QGSNEWVECTORLAYERDIALOG_H

This file was deleted.

This file was deleted.

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<width>450</width>
<height>627</height>
</rect>
</property>
@@ -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>

0 comments on commit c1eea90

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