Skip to content

Commit f5486ee

Browse files
committed
Add single geometry check
1 parent 574c672 commit f5486ee

12 files changed

+471
-13
lines changed

src/app/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ SET(QGIS_APP_SRCS
4848
qgsdisplayangle.cpp
4949
qgsfieldcalculator.cpp
5050
qgsfirstrundialog.cpp
51+
qgsgeometryvalidationservice.cpp
52+
qgsgeometryvalidationdock.cpp
53+
qgsgeometryvalidationmodel.cpp
5154
qgssourcefieldsproperties.cpp
5255
qgsattributesformproperties.cpp
5356
qgsidentifyresultsdialog.cpp
@@ -276,6 +279,9 @@ SET (QGIS_APP_MOC_HDRS
276279
qgsattributesformproperties.h
277280
qgsformannotationdialog.h
278281
qgsguivectorlayertools.h
282+
qgsgeometryvalidationservice.h
283+
qgsgeometryvalidationdock.h
284+
qgsgeometryvalidationmodel.h
279285
qgshtmlannotationdialog.h
280286
qgsidentifyresultsdialog.h
281287
qgslabelengineconfigdialog.h
@@ -692,6 +698,7 @@ INCLUDE_DIRECTORIES(SYSTEM
692698
INCLUDE_DIRECTORIES(
693699
../analysis/processing
694700
../analysis/raster
701+
../analysis/vector/geometry_checker
695702
../core
696703
../core/annotations
697704
../core/auth

src/app/qgisapp.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include "qgsziputils.h"
8080
#include "qgsbrowsermodel.h"
8181
#include "qgsvectorlayerjoinbuffer.h"
82+
#include "qgsgeometryvalidationservice.h"
8283

8384
#ifdef HAVE_3D
8485
#include "qgsabstract3drenderer.h"
@@ -406,6 +407,8 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
406407
#include "qgsmaptoolrotatelabel.h"
407408
#include "qgsmaptoolchangelabelproperties.h"
408409
#include "qgsmaptoolreverseline.h"
410+
#include "qgsgeometryvalidationmodel.h"
411+
#include "qgsgeometryvalidationdock.h"
409412

410413
#include "vertextool/qgsvertextool.h"
411414

@@ -778,7 +781,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
778781
// what type of project to auto-open
779782
mProjOpen = settings.value( QStringLiteral( "qgis/projOpenAtLaunch" ), 0 ).toInt();
780783

781-
782784
startProfile( QStringLiteral( "Welcome page" ) );
783785
mWelcomePage = new QgsWelcomePage( skipVersionCheck );
784786
connect( mWelcomePage, &QgsWelcomePage::projectRemoved, this, [ this ]( int row )
@@ -919,6 +921,14 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
919921
functionProfile( &QgisApp::initNativeProcessing, this, QStringLiteral( "Initialize native processing" ) );
920922
functionProfile( &QgisApp::initLayouts, this, QStringLiteral( "Initialize layouts support" ) );
921923

924+
startProfile( QStringLiteral( "Geometry validation" ) );
925+
mGeometryValidationService = qgis::make_unique<QgsGeometryValidationService>( QgsProject::instance() );
926+
mGeometryValidationDock = new QgsGeometryValidationDock( tr( "Geometry Validation" ) );
927+
mGeometryValidationModel = new QgsGeometryValidationModel( mGeometryValidationService.get(), mGeometryValidationDock );
928+
mGeometryValidationDock->setGeometryValidationModel( mGeometryValidationModel );
929+
addDockWidget( Qt::RightDockWidgetArea, mGeometryValidationDock );
930+
endProfile();
931+
922932
QgsApplication::annotationRegistry()->addAnnotationType( QgsAnnotationMetadata( QStringLiteral( "FormAnnotationItem" ), &QgsFormAnnotation::create ) );
923933
connect( QgsProject::instance()->annotationManager(), &QgsAnnotationManager::annotationAdded, this, &QgisApp::annotationCreated );
924934

src/app/qgisapp.h

+5-12
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class QgsVectorLayerTools;
101101
class QgsWelcomePage;
102102
class QgsOptionsWidgetFactory;
103103
class QgsStatusBar;
104+
class QgsGeometryValidationService;
105+
class QgsGeometryValidationDock;
106+
class QgsGeometryValidationModel;
104107
class QgsUserProfileManagerWidgetFactory;
105108
class Qgs3DMapCanvasDockWidget;
106109

@@ -114,6 +117,7 @@ class QgsAdvancedDigitizingDockWidget;
114117
class QgsGpsInformationWidget;
115118
class QgsStatisticalSummaryDockWidget;
116119
class QgsMapCanvasTracer;
120+
117121
class QgsDecorationItem;
118122
class QgsMessageLogViewer;
119123
class QgsMessageBar;
@@ -690,13 +694,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
690694
//! Returns pointer to the identify map tool - used by identify tool in 3D view
691695
QgsMapToolIdentifyAction *identifyMapTool() const { return mMapTools.mIdentify; }
692696

693-
/**
694-
* Take screenshots for user documentation
695-
* @param saveDirectory path were the screenshots will be saved
696-
* @param categories an int as a flag value of QgsAppScreenShots::Categories
697-
*/
698-
void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 );
699-
700697
public slots:
701698
//! save current vector layer
702699
void saveAsFile( QgsMapLayer *layer = nullptr, bool onlySelected = false );
@@ -1970,9 +1967,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
19701967
//! Populates project "load from" / "save to" menu based on project storages (when the menu is about to be shown)
19711968
void populateProjectStorageMenu( QMenu *menu, bool saving );
19721969

1973-
//! Create the option dialog
1974-
QgsOptions *createOptionsDialog( QWidget *parent = nullptr );
1975-
19761970
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
19771971

19781972
// actions for menus and toolbars -----------------
@@ -2145,6 +2139,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
21452139

21462140
//! interface to QgisApp for plugins
21472141
QgisAppInterface *mQgisInterface = nullptr;
2142+
friend class QgisAppInterface;
21482143

21492144
QSplashScreen *mSplash = nullptr;
21502145
//! list of recently opened/saved project files
@@ -2311,8 +2306,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
23112306
bool mBlockActiveLayerChanged = false;
23122307

23132308
friend class TestQgisAppPython;
2314-
friend class QgisAppInterface;
2315-
friend class QgsAppScreenShots;
23162309
};
23172310

23182311
#ifdef ANDROID

src/app/qgsgeometryvalidationdock.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/***************************************************************************
2+
qgsgeometryvalidationdock.cpp
3+
--------------------------------------
4+
Date : 7.9.2018
5+
Copyright : (C) 2018 by Matthias Kuhn
6+
email : matthias@opengis.ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsgeometryvalidationdock.h"
17+
#include "qgsgeometryvalidationmodel.h"
18+
19+
QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QWidget *parent, Qt::WindowFlags flags )
20+
: QgsDockWidget( title, parent, flags )
21+
{
22+
setupUi( this );
23+
}
24+
25+
QgsGeometryValidationModel *QgsGeometryValidationDock::geometryValidationModel() const
26+
{
27+
return mGeometryValidationModel;
28+
}
29+
30+
void QgsGeometryValidationDock::setGeometryValidationModel( QgsGeometryValidationModel *geometryValidationModel )
31+
{
32+
mGeometryValidationModel = geometryValidationModel;
33+
}

src/app/qgsgeometryvalidationdock.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/***************************************************************************
2+
qgsgeometryvalidationdock.h
3+
--------------------------------------
4+
Date : 7.9.2018
5+
Copyright : (C) 2018 by Matthias Kuhn
6+
email : matthias@opengis.ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSGEOMETRYVALIDATIONPANEL_H
17+
#define QGSGEOMETRYVALIDATIONPANEL_H
18+
19+
#include "ui_qgsgeometryvalidationdockbase.h"
20+
#include "qgsdockwidget.h"
21+
22+
class QgsGeometryValidationModel;
23+
24+
/**
25+
* @brief The QgsGeometryValidationDock class
26+
*/
27+
class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryValidationDockBase
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
QgsGeometryValidationDock( const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr );
33+
34+
QgsGeometryValidationModel *geometryValidationModel() const;
35+
void setGeometryValidationModel( QgsGeometryValidationModel *geometryValidationModel );
36+
37+
private:
38+
QgsGeometryValidationModel *mGeometryValidationModel = nullptr;
39+
};
40+
41+
#endif // QGSGEOMETRYVALIDATIONPANEL_H
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "qgsgeometryvalidationmodel.h"
2+
3+
#include "qgsvectorlayer.h"
4+
5+
QgsGeometryValidationModel::QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent )
6+
: QAbstractItemModel( parent )
7+
, mGeometryValidationService( geometryValidationService )
8+
{
9+
10+
}
11+
12+
QModelIndex QgsGeometryValidationModel::index( int row, int column, const QModelIndex &parent ) const
13+
{
14+
Q_UNUSED( parent )
15+
return createIndex( row, column );
16+
}
17+
18+
QModelIndex QgsGeometryValidationModel::parent( const QModelIndex &child ) const
19+
{
20+
Q_UNUSED( child )
21+
return QModelIndex();
22+
}
23+
24+
int QgsGeometryValidationModel::rowCount( const QModelIndex &parent ) const
25+
{
26+
Q_UNUSED( parent )
27+
return mGeometryValidationService->featureErrors( mCurrentLayer ).size();
28+
}
29+
30+
int QgsGeometryValidationModel::columnCount( const QModelIndex &parent ) const
31+
{
32+
Q_UNUSED( parent )
33+
return 1;
34+
}
35+
36+
QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role ) const
37+
{
38+
switch ( role )
39+
{
40+
case Qt::DisplayRole:
41+
QgsGeometryValidationService::FeatureError error = mGeometryValidationService->featureError( mCurrentLayer, index.row() );
42+
QgsFeature feature = mCurrentLayer->getFeature( error.featureId );
43+
mExpressionContext.setFeature( feature );
44+
QString featureTitle = mDisplayExpression.evaluate( &mExpressionContext ).toString();
45+
return QStringLiteral( "<b>%1</b>: %2" ).arg( featureTitle, error.error.what() );
46+
}
47+
48+
return QVariant();
49+
}
50+
51+
QgsVectorLayer *QgsGeometryValidationModel::currentLayer() const
52+
{
53+
return mCurrentLayer;
54+
}
55+
56+
void QgsGeometryValidationModel::setCurrentLayer( QgsVectorLayer *currentLayer )
57+
{
58+
if ( mCurrentLayer == currentLayer )
59+
return;
60+
61+
beginResetModel();
62+
mCurrentLayer = currentLayer;
63+
mDisplayExpression = mCurrentLayer->displayExpression();
64+
mExpressionContext = QgsExpressionContext( QgsExpressionContextUtils::globalProjectLayerScopes( mCurrentLayer ) );
65+
mDisplayExpression.prepare( &mExpressionContext );
66+
endResetModel();
67+
}

src/app/qgsgeometryvalidationmodel.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef QGSGEOMETRYVALIDATIONMODEL_H
2+
#define QGSGEOMETRYVALIDATIONMODEL_H
3+
4+
#include <QAbstractItemModel>
5+
#include "qgsgeometryvalidationservice.h"
6+
#include "qgsexpression.h"
7+
#include "qgsexpressioncontext.h"
8+
9+
class QgsGeometryValidationModel : public QAbstractItemModel
10+
{
11+
Q_OBJECT
12+
13+
public:
14+
QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent = nullptr );
15+
QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
16+
QModelIndex parent( const QModelIndex &child ) const override;
17+
int rowCount( const QModelIndex &parent ) const override;
18+
int columnCount( const QModelIndex &parent ) const override;
19+
QVariant data( const QModelIndex &index, int role ) const override;
20+
QgsVectorLayer *currentLayer() const;
21+
void setCurrentLayer( QgsVectorLayer *currentLayer );
22+
23+
private:
24+
QgsGeometryValidationService *mGeometryValidationService = nullptr;
25+
QgsVectorLayer *mCurrentLayer = nullptr;
26+
mutable QgsExpression mDisplayExpression;
27+
mutable QgsExpressionContext mExpressionContext;
28+
};
29+
30+
#endif // QGSGEOMETRYVALIDATIONMODEL_H

0 commit comments

Comments
 (0)