Skip to content

Commit

Permalink
Add layout validity check for map crs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 2, 2019
1 parent 102f075 commit ec55304
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions src/app/layout/qgslayoutvaliditychecks.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
33 changes: 33 additions & 0 deletions src/app/layout/qgslayoutvaliditychecks.h
Original file line number Diff line number Diff line change
@@ -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;




};
4 changes: 4 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit ec55304

Please sign in to comment.