Skip to content

Commit

Permalink
Removed asking to validate projections of raster file, when reading a…
Browse files Browse the repository at this point in the history
… project.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9403 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Sep 24, 2008
1 parent 17ed363 commit 317291f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -270,7 +270,7 @@ static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )
//it in the ctor of the layer projection selector

QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
mySelector->setMessage(); //shows a generic message
mySelector->setMessage( srs->validationHint() ); //shows a generic message, if not speficied
proj4String = QgsProject::instance()->readEntry( "SpatialRefSys", "//ProjectCRSProj4String", GEOPROJ4 );
QgsCoordinateReferenceSystem defaultCRS;
if ( defaultCRS.createFromProj4( proj4String ) )
Expand Down
25 changes: 22 additions & 3 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -45,14 +45,16 @@ CUSTOM_CRS_VALIDATION QgsCoordinateReferenceSystem::mCustomSrsValidation = NULL;

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem()
: mMapUnits( QGis::UNKNOWN ),
mIsValidFlag( 0 )
mIsValidFlag( 0 ),
mValidationHint ( 0 )
{
mCRS = OSRNewSpatialReference( NULL );
}

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( QString theWkt )
: mMapUnits( QGis::UNKNOWN ),
mIsValidFlag( 0 )
mIsValidFlag( 0 ),
mValidationHint ( 0 )
{
mCRS = OSRNewSpatialReference( NULL );
createFromWkt( theWkt );
Expand All @@ -61,7 +63,8 @@ QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( QString theWkt )

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem( const long theId, CRS_TYPE theType )
: mMapUnits( QGis::UNKNOWN ),
mIsValidFlag( 0 )
mIsValidFlag( 0 ),
mValidationHint ( 0 )
{
mCRS = OSRNewSpatialReference( NULL );
createFromId( theId, theType );
Expand Down Expand Up @@ -138,6 +141,7 @@ QgsCoordinateReferenceSystem& QgsCoordinateReferenceSystem::operator=( const Qgs
mSRID = srs.mSRID;
mEpsg = srs.mEpsg;
mIsValidFlag = srs.mIsValidFlag;
mValidationHint = srs.mValidationHint;
if ( mIsValidFlag )
{
OSRDestroySpatialReference( mCRS );
Expand Down Expand Up @@ -1099,6 +1103,11 @@ void QgsCoordinateReferenceSystem::setCustomSrsValidation( CUSTOM_CRS_VALIDATION
mCustomSrsValidation = f;
}

CUSTOM_CRS_VALIDATION QgsCoordinateReferenceSystem::customSrsValidation()
{
return mCustomSrsValidation;
}

void QgsCoordinateReferenceSystem::debugPrint()
{
QgsDebugMsg( "***SpatialRefSystem***" );
Expand All @@ -1107,3 +1116,13 @@ void QgsCoordinateReferenceSystem::debugPrint()
QgsDebugMsg( "* Proj4 : " + proj4String() );
QgsDebugMsg( "* Desc. : " + mDescription );
}

void QgsCoordinateReferenceSystem::setValidationHint( QString html )
{
mValidationHint = html;
}

QString QgsCoordinateReferenceSystem::validationHint()
{
return mValidationHint;
}
14 changes: 14 additions & 0 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -248,6 +248,10 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
static void setCustomSrsValidation( CUSTOM_CRS_VALIDATION f );

/** Gets custom function
*/
static CUSTOM_CRS_VALIDATION customSrsValidation();

// Accessors -----------------------------------

/*! Get the SrsId - if possible
Expand Down Expand Up @@ -336,6 +340,14 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
/*! Print the description if debugging
*/
void debugPrint();

/*! Set user hint for validation
*/
void setValidationHint( QString html );

/*! Get user hint for validation
*/
QString validationHint();
private:
// Open SQLite db and show message if ccannot be opened
// returns the same code as sqlite3_open
Expand Down Expand Up @@ -367,6 +379,8 @@ class CORE_EXPORT QgsCoordinateReferenceSystem

bool loadFromDb( QString db, QString field, long id );

QString mValidationHint;

static CUSTOM_CRS_VALIDATION mCustomSrsValidation;
};

Expand Down
28 changes: 22 additions & 6 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -140,6 +140,10 @@ void QgsMapLayer::drawLabels( QgsRenderContext& rendererContext )

bool QgsMapLayer::readXML( QDomNode & layer_node )
{
QgsCoordinateReferenceSystem savedCRS;
CUSTOM_CRS_VALIDATION savedValidation;
bool layerError;

QDomElement element = layer_node.toElement();

// XXX not needed? QString type = element.attribute("type");
Expand All @@ -149,15 +153,31 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
QDomElement mne = mnl.toElement();
mDataSource = mne.text();

// Set the CRS so that we don't ask the user.
// Set the CRS from project file, asking the user if necessary.
// Make it the saved CRS to have WMS layer projected correctly.
// We will still overwrite whatever GDAL etc picks up anyway
// further down this function.
QDomNode srsNode = layer_node.namedItem( "srs" );
mCRS->readXML( srsNode );
mCRS->validate();
savedCRS = *mCRS;

// Do not validate any projections in children, they will be overwritten anyway.
// No need to ask the user for a projections when it is overwritten, is there?
savedValidation = QgsCoordinateReferenceSystem::customSrsValidation();
QgsCoordinateReferenceSystem::setCustomSrsValidation( NULL );

// now let the children grab what they need from the Dom node.
if ( !readXml( layer_node ) )
layerError = !readXml( layer_node );

// overwrite CRS with what we read from project file before the raster/vector
// file readnig functions changed it. They will if projections is specfied in the file.
// FIXME: is this necessary?
QgsCoordinateReferenceSystem::setCustomSrsValidation( savedValidation );
*mCRS = savedCRS;

// Abort if any error in layer, such as not found.
if ( layerError )
{
return false;
}
Expand Down Expand Up @@ -195,10 +215,6 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
mne = mnl.toElement();
setLayerName( mne.text() );

// overwrite srs
// FIXME: is this necessary?
mCRS->readXML( srsNode );

//read transparency level
QDomNode transparencyNode = layer_node.namedItem( "transparencyLevelInt" );
if ( ! transparencyNode.isNull() )
Expand Down

0 comments on commit 317291f

Please sign in to comment.