Skip to content

Commit

Permalink
Show a warning when loading a project with a transform not available …
Browse files Browse the repository at this point in the history
…locally
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 6ff744a commit 96c2ce1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
7 changes: 6 additions & 1 deletion python/core/qgscoordinatetransformcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ class QgsCoordinateTransformContext
:rtype: QgsCoordinateTransform.TransformPair
%End

void readXml( const QDomElement &element, const QgsReadWriteContext &context );
bool readXml( const QDomElement &element, const QgsReadWriteContext &context, QStringList &missingTransforms /Out/ );
%Docstring
Reads the context's state from a DOM ``element``.

Returns false if transforms stored in the XML are not available. In this case ``missingTransforms`` will be
filled with missing datum transform strings.

.. seealso:: :py:func:`writeXml()`
:rtype: bool
%End

void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const;
Expand Down
6 changes: 6 additions & 0 deletions python/core/qgsproject.sip
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,12 @@ emitted whenever the configuration for snapping has changed

.. versionadded:: 3.0
.. seealso:: :py:func:`transformContext()`
%End

void missingDatumTransforms( const QStringList &missingTransforms );
%Docstring
Emitted when datum transforms stored in the project are not available locally.
.. versionadded:: 3.0
%End

void transactionGroupsChanged();
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,12 @@ void QgisApp::setupConnections()
// project crs connections
connect( QgsProject::instance(), &QgsProject::crsChanged, this, &QgisApp::projectCrsChanged );

connect( QgsProject::instance(), &QgsProject::missingDatumTransforms, this, [ = ]( const QStringList & transforms )
{
QString message = tr( "Transforms are not installed: %1 " ).arg( transforms.join( QStringLiteral( " ," ) ) );
messageBar()->pushWarning( tr( "Missing datum transforms" ), message );
} );

connect( QgsProject::instance(), &QgsProject::labelingEngineSettingsChanged,
this, [ = ]
{
Expand Down
25 changes: 22 additions & 3 deletions src/core/qgscoordinatetransformcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ QgsCoordinateTransform::TransformPair QgsCoordinateTransformContext::calculateDa
#endif
}

void QgsCoordinateTransformContext::readXml( const QDomElement &element, const QgsReadWriteContext & )
bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const QgsReadWriteContext &, QStringList &missingTransforms )
{
d.detach();
d->mLock.lockForWrite();
Expand All @@ -176,9 +176,12 @@ void QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
if ( contextNodes.count() < 1 )
{
d->mLock.unlock();
return;
return true;
}

missingTransforms.clear();
bool result = true;

const QDomElement contextElem = contextNodes.at( 0 ).toElement();

// src/dest transforms
Expand All @@ -194,11 +197,26 @@ void QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q

int datumId1 = -1;
int datumId2 = -1;
//warn if value1 or value2 is non-empty, yet no matching transform was found
if ( !value1.isEmpty() )
{
datumId1 = QgsCoordinateTransform::projStringToDatumTransformId( value1 );
if ( datumId1 < 0 )
{
result = false;
missingTransforms << value1;
}
}
if ( !value2.isEmpty() )
{
datumId2 = QgsCoordinateTransform::projStringToDatumTransformId( value2 );
//TODO - throw warning if value1 or value2 is non-empty, yet no matching transform was found
if ( datumId2 < 0 )
{
result = false;
missingTransforms << value2;
}
}

d->mSourceDestDatumTransforms.insert( qMakePair( key1, key2 ), QgsCoordinateTransform::TransformPair( datumId1, datumId2 ) );
}

Expand Down Expand Up @@ -235,6 +253,7 @@ void QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
#endif

d->mLock.unlock();
return result;
}

void QgsCoordinateTransformContext::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgscoordinatetransformcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ class CORE_EXPORT QgsCoordinateTransformContext

/**
* Reads the context's state from a DOM \a element.
*
* Returns false if transforms stored in the XML are not available. In this case \a missingTransforms will be
* filled with missing datum transform strings.
*
* \see writeXml()
*/
void readXml( const QDomElement &element, const QgsReadWriteContext &context );
bool readXml( const QDomElement &element, const QgsReadWriteContext &context, QStringList &missingTransforms SIP_OUT );

/**
* Writes the context's state to a DOM \a element.
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,11 @@ bool QgsProject::readProjectFile( const QString &filename )
}
mCrs = projectCrs;

mTransformContext.readXml( doc->documentElement(), context );
QStringList datumErrors;
if ( !mTransformContext.readXml( doc->documentElement(), context, datumErrors ) )
{
emit missingDatumTransforms( datumErrors );
}
emit transformContextChanged();

QDomNodeList nl = doc->elementsByTagName( QStringLiteral( "autotransaction" ) );
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void transformContextChanged();

/**
* Emitted when datum transforms stored in the project are not available locally.
* \since QGIS 3.0
*/
void missingDatumTransforms( const QStringList &missingTransforms );

/**
* Emitted whenever a new transaction group has been created or a
* transaction group has been removed.
Expand Down

0 comments on commit 96c2ce1

Please sign in to comment.