void QgsNewSpatialiteLayerDialog::pbnFindSRID_clicked() { // first get list of supported SRID from the selected SpatiaLite database // to build filter for projection selector sqlite3_database_unique_ptr database; bool status = true; int rc = database.open_v2( mDatabaseComboBox->currentText(), SQLITE_OPEN_READONLY, nullptr ); if ( rc != SQLITE_OK ) { QMessageBox::warning( this, tr( "SpatiaLite Database" ), tr( "Unable to open the database" ) ); return; } // load up the srid table sqlite3_statement_unique_ptr statement; QString sql = QStringLiteral( "select auth_name || ':' || auth_srid from spatial_ref_sys order by srid asc" ); QSet<QString> myCRSs; statement = database.prepare( sql, rc ); // XXX Need to free memory from the error msg if one is set if ( rc == SQLITE_OK ) { // get the first row of the result set while ( sqlite3_step( statement.get() ) == SQLITE_ROW ) { myCRSs.insert( statement.columnAsText( 0 ) ); } } else { // XXX query failed -- warn the user some how QMessageBox::warning( nullptr, tr( "Error" ), tr( "Failed to load SRIDS: %1" ).arg( database.errorMessage() ) ); status = false; } if ( status ) { // prepare projection selector QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this ); mySelector->setMessage( QString() ); mySelector->setOgcWmsCrsFilter( myCRSs ); mySelector->setCrs( QgsCoordinateReferenceSystem::fromOgcWmsCrs( mCrsId ) ); if ( mySelector->exec() ) { QgsCoordinateReferenceSystem srs = mySelector->crs(); QString crsId = srs.authid(); if ( crsId != mCrsId ) { mCrsId = crsId; leSRID->setText( srs.authid() + " - " + srs.description() ); } } delete mySelector; } }
void QgsMapCanvasDockWidget::setMapCrs() { QgsProjectionSelectionDialog dlg; dlg.setShowNoProjection( true ); dlg.setCrs( mMapCanvas->mapSettings().destinationCrs() ); if ( dlg.exec() ) { mMapCanvas->setDestinationCrs( dlg.crs() ); } }