Skip to content
Permalink
Browse files

Add layout validity check for map crs

  • Loading branch information
nyalldawson committed Nov 30, 2018
1 parent 102f075 commit ec5530484a5dfde7e50aae9d1470b8c2f023c973
@@ -204,6 +204,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutscalebarwidget.cpp
layout/qgslayoutshapewidget.cpp
layout/qgslayouttablebackgroundcolorsdialog.cpp
layout/qgslayoutvaliditychecks.cpp
layout/qgsreportfieldgroupsectionwidget.cpp
layout/qgsreportlayoutsectionwidget.cpp
layout/qgsreportorganizerwidget.cpp
@@ -433,6 +434,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutscalebarwidget.h
layout/qgslayoutshapewidget.h
layout/qgslayouttablebackgroundcolorsdialog.h
layout/qgslayoutvaliditychecks.h
layout/qgsreportfieldgroupsectionwidget.h
layout/qgsreportlayoutsectionwidget.h
layout/qgsreportorganizerwidget.h
@@ -0,0 +1,44 @@
/***************************************************************************
qgslayoutvaliditychecks.cpp
---------------------------
begin : November 2018
copyright : (C) 2018 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 "qgslayoutvaliditychecks.h"
#include "qgsvaliditycheckcontext.h"
#include "qgslayoutitemmap.h"
#include "qgslayout.h"

QList<QgsValidityCheckResult> QgsLayoutMapCrsValidityCheck::runCheck( const QgsValidityCheckContext *context, QgsFeedback * ) const
{
QList<QgsValidityCheckResult> results;
const QgsLayoutValidityCheckContext *layoutContext = dynamic_cast< const QgsLayoutValidityCheckContext * >( context );
if ( !layoutContext )
return results;

QList< QgsLayoutItemMap * > mapItems;
layoutContext->layout->layoutItems( mapItems );
for ( QgsLayoutItemMap *map : qgis::as_const( mapItems ) )
{
if ( map->crs().authid() == QStringLiteral( "EPSG:3857" ) )
{
QgsValidityCheckResult res;
res.type = QgsValidityCheckResult::Warning;
res.title = tr( "Map projection is misleading" );
res.detailedDescription = tr( "The projection for the map item %1 is set to <i>Web Mercator (EPSG:3857)</i> which misrepresents areas and shapes. Consider using an appropriate local projection instead." ).arg( map->displayName() );
results.append( res );
}
}

return results;
}
@@ -0,0 +1,33 @@
/***************************************************************************
qgslayoutvaliditychecks.h
---------------------------
begin : November 2018
copyright : (C) 2018 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 "qgsabstractvaliditycheck.h"

class QgsLayoutMapCrsValidityCheck : public QgsAbstractValidityCheck
{
Q_OBJECT

public:

QString id() const override { return "map_crs_check"; }
int checkType() const override { return QgsAbstractValidityCheck::TypeLayoutCheck; }
QString name() const override { return "Map CRS Check"; }
QList< QgsValidityCheckResult > runCheck( const QgsValidityCheckContext *context, QgsFeedback *feedback ) const override;




};
@@ -328,6 +328,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsgui.h"
#include "qgsdatasourcemanagerdialog.h"
#include "qgsappwindowmanager.h"
#include "qgsvaliditycheckregistry.h"

#include "qgsuserprofilemanager.h"
#include "qgsuserprofile.h"
@@ -422,6 +423,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsgeometryvalidationmodel.h"
#include "qgsgeometryvalidationdock.h"
#include "qgsmaptooltrimextendfeature.h"
#include "qgslayoutvaliditychecks.h"

#include "vertextool/qgsvertextool.h"

@@ -1231,6 +1233,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
setIconSizes( size );
}

QgsApplication::validityCheckRegistry()->addCheck( new QgsLayoutMapCrsValidityCheck() );

mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();

0 comments on commit ec55304

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