Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Updates to compile with current master
  • Loading branch information
leyan committed May 4, 2013
1 parent aa93fd8 commit c5a8ab6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 93 deletions.
115 changes: 44 additions & 71 deletions src/app/qgscustomprojectiondialog.cpp
Expand Up @@ -41,6 +41,7 @@ extern "C"
#include <proj_api.h>
}


QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
Expand Down Expand Up @@ -68,8 +69,7 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::WFlag
leNameList->setCurrentItem( leNameList->topLevelItem( 0 ) );
}

//leNameList->hideColumn(QGIS_CRS_ID_COLUMN);
leNameList->header()->setResizeMode( QGIS_CRS_NAME_COLUMN, QHeaderView::Stretch );
leNameList->hideColumn(QGIS_CRS_ID_COLUMN);

}

Expand Down Expand Up @@ -111,7 +111,7 @@ void QgsCustomProjectionDialog::populateList()
name= QString::fromUtf8( ( char* ) sqlite3_column_text( myPreparedStatement, 1 ) );
parameters= QString::fromUtf8( ( char* ) sqlite3_column_text( myPreparedStatement, 2 ) );

crs.createFromProj4( parameters, false );
crs.createFromProj4( parameters );
existingCRSnames[id] = name;
existingCRSparameters[id] = crs;

Expand Down Expand Up @@ -141,7 +141,8 @@ void QgsCustomProjectionDialog::populateList()
}
}

bool QgsCustomProjectionDialog::deleteCRS( QString id ){
bool QgsCustomProjectionDialog::deleteCRS( QString id )
{
sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
Expand Down Expand Up @@ -234,94 +235,67 @@ void QgsCustomProjectionDialog::insertProjection(QString myProjectionAcronym)
sqlite3_close( myDatabase );
}

bool QgsCustomProjectionDialog::saveCRS(QgsCoordinateReferenceSystem myParameters, QString myName, QString myId, bool newEntry)
bool QgsCustomProjectionDialog::saveCRS(QgsCoordinateReferenceSystem myCRS, QString myName, QString myId, bool newEntry)
{

if( ! myParameters.isValid() )
{
QMessageBox::information( this, tr( "QGIS Custom Projection" ),
tr( "The proj4 projection definition for the CRS \"%1\" is not valid." ).arg( myName ) );
// + tr( " Please add a proj= clause before pressing save." ) );
return false;
}

QString myProjectionAcronym = myParameters.projectionAcronym();
QString myEllipsoidAcronym = myParameters.ellipsoidAcronym();

QString mySql;
int return_id;
QString myProjectionAcronym = myCRS.projectionAcronym();
QString myEllipsoidAcronym = myCRS.ellipsoidAcronym();
if( newEntry )
{
if ( existingCRSnames.size()==0 )
{
mySql = "insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
+ QString::number( USER_CRS_START_ID )
+ "," + quotedValue( myName )
+ "," + quotedValue( myProjectionAcronym )
+ "," + quotedValue( myEllipsoidAcronym )
+ "," + quotedValue( myParameters.toProj4() )
+ ",0)"; // <-- is_geo shamelessly hard coded for now
}
return_id=myCRS.saveAsUserCRS(myName);
if(return_id==-1)
return false;
else
{
mySql = "insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values ("
+ quotedValue( myName )
+ "," + quotedValue( myProjectionAcronym )
+ "," + quotedValue( myEllipsoidAcronym )
+ "," + quotedValue( myParameters.toProj4() )
+ ",0)"; // <-- is_geo shamelessly hard coded for now
}
myId = QString::number(return_id);
}
else
{
mySql = "update tbl_srs set description="
+ quotedValue( myName )
+ ",projection_acronym=" + quotedValue( myProjectionAcronym )
+ ",ellipsoid_acronym=" + quotedValue( myEllipsoidAcronym )
+ ",parameters=" + quotedValue( myParameters.toProj4() )
+ ",parameters=" + quotedValue( myCRS.toProj4() )
+ ",is_geo=0" // <--shamelessly hard coded for now
+ " where srs_id=" + quotedValue( myId )
;
}
QgsDebugMsg( mySql );
sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
int myResult;
//check if the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8(), &myDatabase );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( sqlite3_errmsg( myDatabase ) ).arg( QgsApplication::qgisUserDbFilePath() ) );
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
Q_ASSERT( myResult == SQLITE_OK );
}
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
sqlite3_step( myPreparedStatement );
// XXX Need to free memory from the error msg if one is set
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "failed to write to database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
}
QgsDebugMsg( mySql );
sqlite3 *myDatabase;
const char *myTail;
sqlite3_stmt *myPreparedStatement;
int myResult;
//check if the db is available
myResult = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8(), &myDatabase );
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "Can't open database: %1 \n please notify QGIS developers of this error \n %2 (file name) " ).arg( sqlite3_errmsg( myDatabase ) ).arg( QgsApplication::qgisUserDbFilePath() ) );
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
Q_ASSERT( myResult == SQLITE_OK );
}
myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
sqlite3_step( myPreparedStatement );
// XXX Need to free memory from the error msg if one is set
if ( myResult != SQLITE_OK )
{
QgsDebugMsg( QString( "failed to write to database in custom projection dialog: %1 [%2]" ).arg( mySql ).arg( sqlite3_errmsg( myDatabase ) ) );
}

sqlite3_finalize( myPreparedStatement );
if( newEntry )
{
int return_id = sqlite3_last_insert_rowid( myDatabase );
myId = QString::number( return_id );
sqlite3_finalize( myPreparedStatement );
// close sqlite3 db
sqlite3_close( myDatabase );
if(myResult != SQLITE_OK)
return false;
}
// close sqlite3 db
sqlite3_close( myDatabase );

existingCRSparameters[myId] = myParameters;
existingCRSparameters[myId] = myCRS;
existingCRSnames[myId] = myName;

// If we have a projection acronym not in the user db previously, add it.
// This is a must, or else we can't select it from the vw_srs table.
// Actually, add it always and let the SQL PRIMARY KEY remove duplicates.
insertProjection( myProjectionAcronym );

return myResult == SQLITE_OK;
return true;
}


Expand Down Expand Up @@ -360,7 +334,6 @@ void QgsCustomProjectionDialog::on_pbnRemove_clicked()
customCRSparameters.erase( customCRSparameters.begin() + i );
}


void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * previous )
{
//Store the modifications made to the current element before moving on
Expand All @@ -369,7 +342,7 @@ void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetIte
{
previousIndex = leNameList->indexOfTopLevelItem( previous );
customCRSnames[previousIndex] = leName->text();
customCRSparameters[previousIndex].createFromProj4( teParameters->toPlainText(), false);
customCRSparameters[previousIndex].createFromProj4( teParameters->toPlainText() );
previous->setText( QGIS_CRS_NAME_COLUMN, leName->text() );
previous->setText( QGIS_CRS_PARAMETERS_COLUMN, teParameters->toPlainText() );
}
Expand Down Expand Up @@ -418,7 +391,7 @@ void QgsCustomProjectionDialog::on_buttonBox_accepted()
if(i != -1)
{
customCRSnames[i] = leName->text();
customCRSparameters[i].createFromProj4( teParameters->toPlainText(), false );
customCRSparameters[i].createFromProj4( teParameters->toPlainText() );
}

QgsDebugMsg( "We save the modified CRS." );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgscustomprojectiondialog.h
Expand Up @@ -36,7 +36,7 @@ class QgsCustomProjectionDialog : public QDialog, private Ui::QgsCustomProjectio
QgsCustomProjectionDialog( QWidget *parent = 0, Qt::WFlags fl = 0 );
~QgsCustomProjectionDialog();

public slots:
public slots:
void on_pbnCalculate_clicked();
void on_pbnAdd_clicked();
void on_pbnRemove_clicked();
Expand Down
27 changes: 24 additions & 3 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -27,6 +27,7 @@
#include <QRegExp>
#include <QTextStream>
#include <QFile>
#include <QSettings>

#include "qgsapplication.h"
#include "qgscrscache.h"
Expand Down Expand Up @@ -494,7 +495,7 @@ bool QgsCoordinateReferenceSystem::isValid() const
return mIsValidFlag;
}

bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String, bool save )
bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String )
{
//
// Examples:
Expand Down Expand Up @@ -1472,8 +1473,28 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )

QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );

// XXX Need to free memory from the error msg if one is set
return myResult == SQLITE_OK;
int return_id;
if(myResult == SQLITE_OK)
{
return_id = sqlite3_last_insert_rowid( myDatabase );
setInternalId(return_id);

//We add the just created user CRS to the list of recently used CRS
QSettings settings;
//QStringList recentProjections = settings.value( "/UI/recentProjections" ).toStringList();
QStringList projectionsProj4 = settings.value( "/UI/recentProjectionsProj4" ).toStringList();
QStringList projectionsAuthId = settings.value( "/UI/recentProjectionsAuthId" ).toStringList();
//recentProjections.append();
//settings.setValue( "/UI/recentProjections", recentProjections );
projectionsProj4.append(toProj4());
projectionsAuthId.append(authid());
settings.setValue( "/UI/recentProjectionsProj4", projectionsProj4 );
settings.setValue( "/UI/recentProjectionsAuthId", projectionsAuthId );

}
else
return_id = -1;
return return_id;
}

long QgsCoordinateReferenceSystem::getRecordCount()
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -134,7 +134,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* in the parameters member. The reason for this is so that we
* can easily present the user with 'natural language' representation
* of the projection and ellipsoid by looking them up in the srs.bs sqlite
* database. Also having the ellpse and proj elements stripped out
* database. Also having the ellipse and proj elements stripped out
* is helpful to speed up globbing queries (see below).
*
* We try to match the proj string to and srsid using the following logic:
Expand All @@ -154,7 +154,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* @param theProjString A proj4 format string
* @return bool TRUE if success else false
*/
bool createFromProj4( const QString theProjString, bool save=true );
bool createFromProj4( const QString theProjString );

/*! Set up this srs from a string definition, by default a WKT definition. Otherwise
* the string defines a authority, followed by a colon, followed by the definition.
Expand Down
17 changes: 4 additions & 13 deletions src/gui/qgsprojectionselector.cpp
Expand Up @@ -81,19 +81,10 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
// No? Skip this entry
continue;
}
else
//If the CRS can be created but do not correspond to a CRS in the database, skip it (for example a deleted custom CRS)
if ( crs.srsid() == 0 )
{
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if ( crs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( crs.toProj4() );
crs.saveAsUserCRS( myName );
}
continue;
}
}
mRecentProjections << QString::number( crs.srsid() );
Expand Down Expand Up @@ -277,7 +268,7 @@ void QgsProjectionSelector::applySelection( int column, QString value )
}
else
{
QgsDebugMsg( "nothing found" );
QgsDebugMsg( QString("nothing found for %1,%2" ).arg( column ).arg( value ) );
// unselect the selected item to avoid confusing the user
lstCoordinateSystems->clearSelection();
lstRecent->clearSelection();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wcs/qgswcsprovider.cpp
Expand Up @@ -556,7 +556,7 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
// It may happen (Geoserver) that if requested BBOX is larger than coverage
// extent, the returned data cover intersection of requested BBOX and coverage
// extent scaled to requested WIDTH/HEIGHT => check extent
// Unfortunately if received raster does not hac CRS, the extent is raster size
// Unfortunately if the received raster does not have a CRS, the extent is the raster size
// and in that case it cannot be used to verify extent
QgsCoordinateReferenceSystem cacheCrs;
if ( !cacheCrs.createFromWkt( GDALGetProjectionRef( mCachedGdalDataset ) ) &&
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgsprojectionselectorbase.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>574</width>
<height>390</height>
<width>820</width>
<height>591</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down

0 comments on commit c5a8ab6

Please sign in to comment.