Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add single geometry check
- Loading branch information
Showing
12 changed files
with
471 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.