Skip to content

Commit 96c2ce1

Browse files
committed
Show a warning when loading a project with a transform not available locally
1 parent 6ff744a commit 96c2ce1

File tree

7 files changed

+56
-6
lines changed

7 files changed

+56
-6
lines changed

python/core/qgscoordinatetransformcontext.sip

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ class QgsCoordinateTransformContext
137137
:rtype: QgsCoordinateTransform.TransformPair
138138
%End
139139

140-
void readXml( const QDomElement &element, const QgsReadWriteContext &context );
140+
bool readXml( const QDomElement &element, const QgsReadWriteContext &context, QStringList &missingTransforms /Out/ );
141141
%Docstring
142142
Reads the context's state from a DOM ``element``.
143+
144+
Returns false if transforms stored in the XML are not available. In this case ``missingTransforms`` will be
145+
filled with missing datum transform strings.
146+
143147
.. seealso:: :py:func:`writeXml()`
148+
:rtype: bool
144149
%End
145150

146151
void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const;

python/core/qgsproject.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,12 @@ emitted whenever the configuration for snapping has changed
943943

944944
.. versionadded:: 3.0
945945
.. seealso:: :py:func:`transformContext()`
946+
%End
947+
948+
void missingDatumTransforms( const QStringList &missingTransforms );
949+
%Docstring
950+
Emitted when datum transforms stored in the project are not available locally.
951+
.. versionadded:: 3.0
946952
%End
947953

948954
void transactionGroupsChanged();

src/app/qgisapp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,6 +3186,12 @@ void QgisApp::setupConnections()
31863186
// project crs connections
31873187
connect( QgsProject::instance(), &QgsProject::crsChanged, this, &QgisApp::projectCrsChanged );
31883188

3189+
connect( QgsProject::instance(), &QgsProject::missingDatumTransforms, this, [ = ]( const QStringList & transforms )
3190+
{
3191+
QString message = tr( "Transforms are not installed: %1 " ).arg( transforms.join( QStringLiteral( " ," ) ) );
3192+
messageBar()->pushWarning( tr( "Missing datum transforms" ), message );
3193+
} );
3194+
31893195
connect( QgsProject::instance(), &QgsProject::labelingEngineSettingsChanged,
31903196
this, [ = ]
31913197
{

src/core/qgscoordinatetransformcontext.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ QgsCoordinateTransform::TransformPair QgsCoordinateTransformContext::calculateDa
161161
#endif
162162
}
163163

164-
void QgsCoordinateTransformContext::readXml( const QDomElement &element, const QgsReadWriteContext & )
164+
bool QgsCoordinateTransformContext::readXml( const QDomElement &element, const QgsReadWriteContext &, QStringList &missingTransforms )
165165
{
166166
d.detach();
167167
d->mLock.lockForWrite();
@@ -176,9 +176,12 @@ void QgsCoordinateTransformContext::readXml( const QDomElement &element, const Q
176176
if ( contextNodes.count() < 1 )
177177
{
178178
d->mLock.unlock();
179-
return;
179+
return true;
180180
}
181181

182+
missingTransforms.clear();
183+
bool result = true;
184+
182185
const QDomElement contextElem = contextNodes.at( 0 ).toElement();
183186

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

195198
int datumId1 = -1;
196199
int datumId2 = -1;
200+
//warn if value1 or value2 is non-empty, yet no matching transform was found
197201
if ( !value1.isEmpty() )
202+
{
198203
datumId1 = QgsCoordinateTransform::projStringToDatumTransformId( value1 );
204+
if ( datumId1 < 0 )
205+
{
206+
result = false;
207+
missingTransforms << value1;
208+
}
209+
}
199210
if ( !value2.isEmpty() )
211+
{
200212
datumId2 = QgsCoordinateTransform::projStringToDatumTransformId( value2 );
201-
//TODO - throw warning if value1 or value2 is non-empty, yet no matching transform was found
213+
if ( datumId2 < 0 )
214+
{
215+
result = false;
216+
missingTransforms << value2;
217+
}
218+
}
219+
202220
d->mSourceDestDatumTransforms.insert( qMakePair( key1, key2 ), QgsCoordinateTransform::TransformPair( datumId1, datumId2 ) );
203221
}
204222

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

237255
d->mLock.unlock();
256+
return result;
238257
}
239258

240259
void QgsCoordinateTransformContext::writeXml( QDomElement &element, const QgsReadWriteContext & ) const

src/core/qgscoordinatetransformcontext.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,13 @@ class CORE_EXPORT QgsCoordinateTransformContext
233233

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

240244
/**
241245
* Writes the context's state to a DOM \a element.

src/core/qgsproject.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,11 @@ bool QgsProject::readProjectFile( const QString &filename )
925925
}
926926
mCrs = projectCrs;
927927

928-
mTransformContext.readXml( doc->documentElement(), context );
928+
QStringList datumErrors;
929+
if ( !mTransformContext.readXml( doc->documentElement(), context, datumErrors ) )
930+
{
931+
emit missingDatumTransforms( datumErrors );
932+
}
929933
emit transformContextChanged();
930934

931935
QDomNodeList nl = doc->elementsByTagName( QStringLiteral( "autotransaction" ) );

src/core/qgsproject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
933933
*/
934934
void transformContextChanged();
935935

936+
/**
937+
* Emitted when datum transforms stored in the project are not available locally.
938+
* \since QGIS 3.0
939+
*/
940+
void missingDatumTransforms( const QStringList &missingTransforms );
941+
936942
/**
937943
* Emitted whenever a new transaction group has been created or a
938944
* transaction group has been removed.

0 commit comments

Comments
 (0)