Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add single geometry check
  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent 574c672 commit f5486ee
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -48,6 +48,9 @@ SET(QGIS_APP_SRCS
qgsdisplayangle.cpp
qgsfieldcalculator.cpp
qgsfirstrundialog.cpp
qgsgeometryvalidationservice.cpp
qgsgeometryvalidationdock.cpp
qgsgeometryvalidationmodel.cpp
qgssourcefieldsproperties.cpp
qgsattributesformproperties.cpp
qgsidentifyresultsdialog.cpp
Expand Down Expand Up @@ -276,6 +279,9 @@ SET (QGIS_APP_MOC_HDRS
qgsattributesformproperties.h
qgsformannotationdialog.h
qgsguivectorlayertools.h
qgsgeometryvalidationservice.h
qgsgeometryvalidationdock.h
qgsgeometryvalidationmodel.h
qgshtmlannotationdialog.h
qgsidentifyresultsdialog.h
qgslabelengineconfigdialog.h
Expand Down Expand Up @@ -692,6 +698,7 @@ INCLUDE_DIRECTORIES(SYSTEM
INCLUDE_DIRECTORIES(
../analysis/processing
../analysis/raster
../analysis/vector/geometry_checker
../core
../core/annotations
../core/auth
Expand Down
12 changes: 11 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -79,6 +79,7 @@
#include "qgsziputils.h"
#include "qgsbrowsermodel.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsgeometryvalidationservice.h"

#ifdef HAVE_3D
#include "qgsabstract3drenderer.h"
Expand Down Expand Up @@ -406,6 +407,8 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmaptoolrotatelabel.h"
#include "qgsmaptoolchangelabelproperties.h"
#include "qgsmaptoolreverseline.h"
#include "qgsgeometryvalidationmodel.h"
#include "qgsgeometryvalidationdock.h"

#include "vertextool/qgsvertextool.h"

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


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

startProfile( QStringLiteral( "Geometry validation" ) );
mGeometryValidationService = qgis::make_unique<QgsGeometryValidationService>( QgsProject::instance() );
mGeometryValidationDock = new QgsGeometryValidationDock( tr( "Geometry Validation" ) );
mGeometryValidationModel = new QgsGeometryValidationModel( mGeometryValidationService.get(), mGeometryValidationDock );
mGeometryValidationDock->setGeometryValidationModel( mGeometryValidationModel );
addDockWidget( Qt::RightDockWidgetArea, mGeometryValidationDock );
endProfile();

QgsApplication::annotationRegistry()->addAnnotationType( QgsAnnotationMetadata( QStringLiteral( "FormAnnotationItem" ), &QgsFormAnnotation::create ) );
connect( QgsProject::instance()->annotationManager(), &QgsAnnotationManager::annotationAdded, this, &QgisApp::annotationCreated );

Expand Down
17 changes: 5 additions & 12 deletions src/app/qgisapp.h
Expand Up @@ -101,6 +101,9 @@ class QgsVectorLayerTools;
class QgsWelcomePage;
class QgsOptionsWidgetFactory;
class QgsStatusBar;
class QgsGeometryValidationService;
class QgsGeometryValidationDock;
class QgsGeometryValidationModel;
class QgsUserProfileManagerWidgetFactory;
class Qgs3DMapCanvasDockWidget;

Expand All @@ -114,6 +117,7 @@ class QgsAdvancedDigitizingDockWidget;
class QgsGpsInformationWidget;
class QgsStatisticalSummaryDockWidget;
class QgsMapCanvasTracer;

class QgsDecorationItem;
class QgsMessageLogViewer;
class QgsMessageBar;
Expand Down Expand Up @@ -690,13 +694,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Returns pointer to the identify map tool - used by identify tool in 3D view
QgsMapToolIdentifyAction *identifyMapTool() const { return mMapTools.mIdentify; }

/**
* Take screenshots for user documentation
* @param saveDirectory path were the screenshots will be saved
* @param categories an int as a flag value of QgsAppScreenShots::Categories
*/
void takeAppScreenShots( const QString &saveDirectory, const int categories = 0 );

public slots:
//! save current vector layer
void saveAsFile( QgsMapLayer *layer = nullptr, bool onlySelected = false );
Expand Down Expand Up @@ -1970,9 +1967,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Populates project "load from" / "save to" menu based on project storages (when the menu is about to be shown)
void populateProjectStorageMenu( QMenu *menu, bool saving );

//! Create the option dialog
QgsOptions *createOptionsDialog( QWidget *parent = nullptr );

QgisAppStyleSheet *mStyleSheetBuilder = nullptr;

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

//! interface to QgisApp for plugins
QgisAppInterface *mQgisInterface = nullptr;
friend class QgisAppInterface;

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

friend class TestQgisAppPython;
friend class QgisAppInterface;
friend class QgsAppScreenShots;
};

#ifdef ANDROID
Expand Down
33 changes: 33 additions & 0 deletions src/app/qgsgeometryvalidationdock.cpp
@@ -0,0 +1,33 @@
/***************************************************************************
qgsgeometryvalidationdock.cpp
--------------------------------------
Date : 7.9.2018
Copyright : (C) 2018 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* 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 "qgsgeometryvalidationdock.h"
#include "qgsgeometryvalidationmodel.h"

QgsGeometryValidationDock::QgsGeometryValidationDock( const QString &title, QWidget *parent, Qt::WindowFlags flags )
: QgsDockWidget( title, parent, flags )
{
setupUi( this );
}

QgsGeometryValidationModel *QgsGeometryValidationDock::geometryValidationModel() const
{
return mGeometryValidationModel;
}

void QgsGeometryValidationDock::setGeometryValidationModel( QgsGeometryValidationModel *geometryValidationModel )
{
mGeometryValidationModel = geometryValidationModel;
}
41 changes: 41 additions & 0 deletions src/app/qgsgeometryvalidationdock.h
@@ -0,0 +1,41 @@
/***************************************************************************
qgsgeometryvalidationdock.h
--------------------------------------
Date : 7.9.2018
Copyright : (C) 2018 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* 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 QGSGEOMETRYVALIDATIONPANEL_H
#define QGSGEOMETRYVALIDATIONPANEL_H

#include "ui_qgsgeometryvalidationdockbase.h"
#include "qgsdockwidget.h"

class QgsGeometryValidationModel;

/**
* @brief The QgsGeometryValidationDock class
*/
class QgsGeometryValidationDock : public QgsDockWidget, public Ui_QgsGeometryValidationDockBase
{
Q_OBJECT

public:
QgsGeometryValidationDock( const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr );

QgsGeometryValidationModel *geometryValidationModel() const;
void setGeometryValidationModel( QgsGeometryValidationModel *geometryValidationModel );

private:
QgsGeometryValidationModel *mGeometryValidationModel = nullptr;
};

#endif // QGSGEOMETRYVALIDATIONPANEL_H
67 changes: 67 additions & 0 deletions src/app/qgsgeometryvalidationmodel.cpp
@@ -0,0 +1,67 @@
#include "qgsgeometryvalidationmodel.h"

#include "qgsvectorlayer.h"

QgsGeometryValidationModel::QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent )
: QAbstractItemModel( parent )
, mGeometryValidationService( geometryValidationService )
{

}

QModelIndex QgsGeometryValidationModel::index( int row, int column, const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return createIndex( row, column );
}

QModelIndex QgsGeometryValidationModel::parent( const QModelIndex &child ) const
{
Q_UNUSED( child )
return QModelIndex();
}

int QgsGeometryValidationModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return mGeometryValidationService->featureErrors( mCurrentLayer ).size();
}

int QgsGeometryValidationModel::columnCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return 1;
}

QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role ) const
{
switch ( role )
{
case Qt::DisplayRole:
QgsGeometryValidationService::FeatureError error = mGeometryValidationService->featureError( mCurrentLayer, index.row() );
QgsFeature feature = mCurrentLayer->getFeature( error.featureId );
mExpressionContext.setFeature( feature );
QString featureTitle = mDisplayExpression.evaluate( &mExpressionContext ).toString();
return QStringLiteral( "<b>%1</b>: %2" ).arg( featureTitle, error.error.what() );
}

return QVariant();
}

QgsVectorLayer *QgsGeometryValidationModel::currentLayer() const
{
return mCurrentLayer;
}

void QgsGeometryValidationModel::setCurrentLayer( QgsVectorLayer *currentLayer )
{
if ( mCurrentLayer == currentLayer )
return;

beginResetModel();
mCurrentLayer = currentLayer;
mDisplayExpression = mCurrentLayer->displayExpression();
mExpressionContext = QgsExpressionContext( QgsExpressionContextUtils::globalProjectLayerScopes( mCurrentLayer ) );
mDisplayExpression.prepare( &mExpressionContext );
endResetModel();
}
30 changes: 30 additions & 0 deletions src/app/qgsgeometryvalidationmodel.h
@@ -0,0 +1,30 @@
#ifndef QGSGEOMETRYVALIDATIONMODEL_H
#define QGSGEOMETRYVALIDATIONMODEL_H

#include <QAbstractItemModel>
#include "qgsgeometryvalidationservice.h"
#include "qgsexpression.h"
#include "qgsexpressioncontext.h"

class QgsGeometryValidationModel : public QAbstractItemModel
{
Q_OBJECT

public:
QgsGeometryValidationModel( QgsGeometryValidationService *geometryValidationService, QObject *parent = nullptr );
QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
QModelIndex parent( const QModelIndex &child ) const override;
int rowCount( const QModelIndex &parent ) const override;
int columnCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
QgsVectorLayer *currentLayer() const;
void setCurrentLayer( QgsVectorLayer *currentLayer );

private:
QgsGeometryValidationService *mGeometryValidationService = nullptr;
QgsVectorLayer *mCurrentLayer = nullptr;
mutable QgsExpression mDisplayExpression;
mutable QgsExpressionContext mExpressionContext;
};

#endif // QGSGEOMETRYVALIDATIONMODEL_H

0 comments on commit f5486ee

Please sign in to comment.