Skip to content
Permalink
Browse files

Show a warning when loading a project with a transform not available …

…locally
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 6ff744a commit 96c2ce18bdd7a6719ae7b14f58780d68dd346435
@@ -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;
@@ -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();
@@ -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, [ = ]
{
@@ -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();
@@ -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
@@ -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 ) );
}

@@ -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
@@ -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.
@@ -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" ) );
@@ -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.

0 comments on commit 96c2ce1

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