Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Add optional (not on by default) layer tree warning icon
for layers with CRS inaccuracies If the new "Show CRS accuracy warnings for layers in project legend" is checked by a user, then any layers with a CRS with accuracy issues (i.e. a dynamic crs with no coordinate epoch available, or a crs based on a datum ensemble with accuracy exceeding the user-set limit) will have a new warning icon reflecting that the layer is a low-accuracy layer. This is entirely opt-in, and designed for use in engineering/BIM/... industries where inaccuracies of meter/submeter level are very dangerous.
- Loading branch information
1 parent
93e48cf
commit eb5fd48
Showing
9 changed files
with
215 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/*************************************************************************** | ||
qgslayertreeviewlowaccuracyindicator.cpp | ||
-------------------------------------- | ||
Date : May 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayertreeviewlowaccuracyindicator.h" | ||
#include "qgsdatums.h" | ||
#include "qgssettings.h" | ||
#include "qgsgui.h" | ||
|
||
QgsLayerTreeViewLowAccuracyIndicatorProvider::QgsLayerTreeViewLowAccuracyIndicatorProvider( QgsLayerTreeView *view ) | ||
: QgsLayerTreeViewIndicatorProvider( view ) | ||
{ | ||
} | ||
|
||
void QgsLayerTreeViewLowAccuracyIndicatorProvider::connectSignals( QgsMapLayer *layer ) | ||
{ | ||
QgsLayerTreeViewIndicatorProvider::connectSignals( layer ); | ||
connect( layer, &QgsMapLayer::crsChanged, this, &QgsLayerTreeViewLowAccuracyIndicatorProvider::onLayerChanged ); | ||
} | ||
|
||
void QgsLayerTreeViewLowAccuracyIndicatorProvider::disconnectSignals( QgsMapLayer *layer ) | ||
{ | ||
QgsLayerTreeViewIndicatorProvider::disconnectSignals( layer ); | ||
disconnect( layer, &QgsMapLayer::crsChanged, this, &QgsLayerTreeViewLowAccuracyIndicatorProvider::onLayerChanged ); | ||
} | ||
|
||
void QgsLayerTreeViewLowAccuracyIndicatorProvider::onIndicatorClicked( const QModelIndex & ) | ||
{ | ||
|
||
} | ||
|
||
QString QgsLayerTreeViewLowAccuracyIndicatorProvider::iconName( QgsMapLayer * ) | ||
{ | ||
return QStringLiteral( "/mIndicatorLowAccuracy.svg" ); | ||
} | ||
|
||
QString QgsLayerTreeViewLowAccuracyIndicatorProvider::tooltipText( QgsMapLayer *layer ) | ||
{ | ||
if ( !layer ) | ||
return QString(); | ||
|
||
const QgsCoordinateReferenceSystem crs = layer->crs(); | ||
if ( !crs.isValid() ) | ||
return QString(); | ||
|
||
// based on datum ensemble? | ||
try | ||
{ | ||
const QgsDatumEnsemble ensemble = crs.datumEnsemble(); | ||
if ( ensemble.isValid() ) | ||
{ | ||
QString id; | ||
if ( !ensemble.code().isEmpty() ) | ||
id = QStringLiteral( "<i>%1</i> (%2:%3)" ).arg( ensemble.name(), ensemble.authority(), ensemble.code() ); | ||
else | ||
id = QStringLiteral( "<i>%</i>”" ).arg( ensemble.name() ); | ||
|
||
if ( ensemble.accuracy() > 0 ) | ||
{ | ||
return tr( "Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg( id ).arg( ensemble.accuracy() ); | ||
} | ||
else | ||
{ | ||
return tr( "Based on %1, which has a limited accuracy." ).arg( id ); | ||
} | ||
} | ||
} | ||
catch ( QgsNotSupportedException & ) | ||
{ | ||
|
||
} | ||
|
||
// dynamic crs with no epoch? | ||
if ( crs.isDynamic() && std::isnan( crs.coordinateEpoch() ) ) | ||
{ | ||
return tr( "%1 is a dynamic CRS, but no coordinate epoch is set. Coordinates are ambiguous and of limited accuracy." ).arg( crs.userFriendlyIdentifier() ); | ||
} | ||
|
||
return QString(); | ||
} | ||
|
||
bool QgsLayerTreeViewLowAccuracyIndicatorProvider::acceptLayer( QgsMapLayer *layer ) | ||
{ | ||
QgsSettings settings; | ||
if ( !settings.value( QStringLiteral( "/projections/crsAccuracyIndicator" ), false, QgsSettings::App ).toBool() ) | ||
return false; | ||
|
||
if ( !layer->isValid() ) | ||
return false; | ||
|
||
const QgsCoordinateReferenceSystem crs = layer->crs(); | ||
if ( !crs.isValid() ) | ||
return false; | ||
|
||
// dynamic crs with no epoch? | ||
if ( crs.isDynamic() && std::isnan( crs.coordinateEpoch() ) ) | ||
{ | ||
return true; | ||
} | ||
|
||
// based on datum ensemble? | ||
try | ||
{ | ||
const QgsDatumEnsemble ensemble = crs.datumEnsemble(); | ||
if ( ensemble.isValid() ) | ||
{ | ||
if ( ensemble.accuracy() > 0 ) | ||
{ | ||
if ( ensemble.accuracy() >= settings.value( QStringLiteral( "/projections/crsAccuracyWarningThreshold" ), 0.0, QgsSettings::App ).toDouble() ) | ||
return true; | ||
} | ||
else | ||
{ | ||
// unknown accuracy, always show warning | ||
return true; | ||
} | ||
} | ||
} | ||
catch ( QgsNotSupportedException & ) | ||
{ | ||
|
||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*************************************************************************** | ||
qgslayertreeviewlowaccuracyindicator.h | ||
-------------------------------------- | ||
Date : May 2021 | ||
Copyright : (C) 2021 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSLAYERTREEVIEWLOWACCURACYINDICATOR_H | ||
#define QGSLAYERTREEVIEWLOWACCURACYINDICATOR_H | ||
|
||
#include "qgslayertreeviewindicatorprovider.h" | ||
#include "qgsmaplayer.h" | ||
|
||
#include <QObject> | ||
#include <QPointer> | ||
|
||
//! Indicators for low accuracy layers | ||
class QgsLayerTreeViewLowAccuracyIndicatorProvider : public QgsLayerTreeViewIndicatorProvider | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit QgsLayerTreeViewLowAccuracyIndicatorProvider( QgsLayerTreeView *view ); | ||
|
||
protected: | ||
void connectSignals( QgsMapLayer *layer ) override ; | ||
void disconnectSignals( QgsMapLayer *layer ) override; | ||
|
||
protected slots: | ||
void onIndicatorClicked( const QModelIndex &index ) override; | ||
|
||
private: | ||
QString iconName( QgsMapLayer *layer ) override; | ||
QString tooltipText( QgsMapLayer *layer ) override; | ||
bool acceptLayer( QgsMapLayer *layer ) override; | ||
|
||
}; | ||
|
||
#endif // QGSLAYERTREEVIEWLOWACCURACYINDICATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters