Skip to content
Permalink
Browse files

Add single geometry check

  • Loading branch information
m-kuhn committed Oct 15, 2018
1 parent 574c672 commit f5486ee51670e56a9d259969268cb471d8c1e1ba
@@ -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
@@ -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
@@ -692,6 +698,7 @@ INCLUDE_DIRECTORIES(SYSTEM
INCLUDE_DIRECTORIES(
../analysis/processing
../analysis/raster
../analysis/vector/geometry_checker
../core
../core/annotations
../core/auth
@@ -79,6 +79,7 @@
#include "qgsziputils.h"
#include "qgsbrowsermodel.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsgeometryvalidationservice.h"

#ifdef HAVE_3D
#include "qgsabstract3drenderer.h"
@@ -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"

@@ -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 )
@@ -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 );

@@ -101,6 +101,9 @@ class QgsVectorLayerTools;
class QgsWelcomePage;
class QgsOptionsWidgetFactory;
class QgsStatusBar;
class QgsGeometryValidationService;
class QgsGeometryValidationDock;
class QgsGeometryValidationModel;
class QgsUserProfileManagerWidgetFactory;
class Qgs3DMapCanvasDockWidget;

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

class QgsDecorationItem;
class QgsMessageLogViewer;
class QgsMessageBar;
@@ -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 );
@@ -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 -----------------
@@ -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
@@ -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
@@ -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;
}
@@ -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
@@ -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();
}
@@ -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.
You can’t perform that action at this time.