Skip to content

Commit dae3134

Browse files
committed
Put check registry into use
1 parent abda865 commit dae3134

4 files changed

+82
-22
lines changed

src/app/qgsgeometryvalidationmodel.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "qgsgeometryvalidationmodel.h"
22

33
#include "qgsvectorlayer.h"
4+
#include "qgssinglegeometrycheck.h"
45

56
#include <QIcon>
67

@@ -55,7 +56,7 @@ QVariant QgsGeometryValidationModel::data( const QModelIndex &index, int role )
5556
if ( featureItem.errors.count() > 1 )
5657
return tr( "%1: %n Errors", "", featureItem.errors.count() ).arg( featureTitle );
5758
else if ( featureItem.errors.count() == 1 )
58-
return tr( "%1: %2" ).arg( featureTitle, featureItem.errors.at( 0 ).what() );
59+
return tr( "%1: %2" ).arg( featureTitle, featureItem.errors.at( 0 )->description() );
5960
#if 0
6061
else
6162
return tr( "%1: No Errors" ).arg( featureTitle );
@@ -101,7 +102,7 @@ void QgsGeometryValidationModel::setCurrentLayer( QgsVectorLayer *currentLayer )
101102
endResetModel();
102103
}
103104

104-
void QgsGeometryValidationModel::onGeometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<QgsGeometry::Error> &errors )
105+
void QgsGeometryValidationModel::onGeometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors )
105106
{
106107
auto &layerErrors = mErrorStorage[layer];
107108

src/app/qgsgeometryvalidationmodel.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QgsGeometryValidationModel : public QAbstractItemModel
2525
void setCurrentLayer( QgsVectorLayer *currentLayer );
2626

2727
private slots:
28-
void onGeometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<QgsGeometry::Error> &errors );
28+
void onGeometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError> > &errors );
2929
void onGeometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
3030

3131
private:
@@ -39,7 +39,7 @@ class QgsGeometryValidationModel : public QAbstractItemModel
3939
{}
4040

4141
QgsFeatureId fid; // TODO INITIALIZE PROPERLY
42-
QList<QgsGeometry::Error> errors;
42+
QList<std::shared_ptr<QgsSingleGeometryCheckError>> errors;
4343
};
4444

4545
int errorsForFeature( QgsVectorLayer *layer, QgsFeatureId fid );

src/app/qgsgeometryvalidationservice.cpp

+67-10
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,15 @@ email : matthias@opengis.ch
1717
#include "qgsgeometryvalidationservice.h"
1818
#include "qgsproject.h"
1919
#include "qgsvectorlayer.h"
20-
21-
// TODO: Replace with registry
22-
#include "qgsisvalidgeometrycheck.h"
20+
#include "qgsgeometryoptions.h"
21+
#include "qgsanalysis.h"
22+
#include "qgsgeometrycheckregistry.h"
23+
#include "qgsgeometrycheckfactory.h"
2324

2425
QgsGeometryValidationService::QgsGeometryValidationService( QgsProject *project )
26+
: mProject( project )
2527
{
2628
connect( project, &QgsProject::layersAdded, this, &QgsGeometryValidationService::onLayersAdded );
27-
// TODO: should not provide a nullptr context
28-
mIsValidGeometryCheck = new QgsIsValidGeometryCheck( nullptr, QVariantMap() );
29-
}
30-
31-
QgsGeometryValidationService::~QgsGeometryValidationService()
32-
{
3329
}
3430

3531
bool QgsGeometryValidationService::validationActive( QgsVectorLayer *layer, QgsFeatureId feature ) const
@@ -56,6 +52,8 @@ void QgsGeometryValidationService::onLayersAdded( const QList<QgsMapLayer *> &la
5652
{
5753
onFeatureDeleted( vectorLayer, fid );
5854
} );
55+
56+
enableLayerChecks( vectorLayer );
5957
}
6058
}
6159
}
@@ -78,6 +76,50 @@ void QgsGeometryValidationService::onFeatureDeleted( QgsVectorLayer *layer, QgsF
7876
cancelChecks( layer, fid );
7977
}
8078

79+
void QgsGeometryValidationService::enableLayerChecks( QgsVectorLayer *layer )
80+
{
81+
// TODO: finish all ongoing checks
82+
qDeleteAll( mSingleFeatureChecks.value( layer ) );
83+
84+
// TODO: ownership and lifetime of the context!!
85+
auto context = new QgsGeometryCheckContext( 1, mProject->crs(), mProject->transformContext() );
86+
QList<QgsGeometryCheck *> layerChecks;
87+
88+
QgsGeometryCheckRegistry *checkRegistry = QgsAnalysis::instance()->geometryCheckRegistry();
89+
90+
const QStringList activeChecks = layer->geometryOptions()->geometryChecks();
91+
92+
const QList<QgsGeometryCheckFactory *> singleCheckFactories = checkRegistry->geometryCheckFactories( layer, QgsGeometryCheck::SingleGeometryCheck );
93+
94+
for ( QgsGeometryCheckFactory *factory : singleCheckFactories )
95+
{
96+
const QString checkId = factory->id();
97+
if ( activeChecks.contains( checkId ) )
98+
{
99+
const QVariantMap checkConfiguration = layer->geometryOptions()->checkConfiguration( checkId );
100+
layerChecks.append( factory->createGeometryCheck( context, checkConfiguration ) );
101+
}
102+
}
103+
104+
QList<QgsSingleGeometryCheck *> singleGeometryChecks;
105+
for ( QgsGeometryCheck *check : qgis::as_const( layerChecks ) )
106+
{
107+
Q_ASSERT( dynamic_cast<QgsSingleGeometryCheck *>( check ) );
108+
singleGeometryChecks.append( dynamic_cast<QgsSingleGeometryCheck *>( check ) );
109+
}
110+
111+
mSingleFeatureChecks.insert( layer, singleGeometryChecks );
112+
113+
#if 0
114+
const QList<QgsGeometryCheckFactory *> topologyCheckFactories = checkRegistry->geometryCheckFactories( layer, QgsGeometryCheck::SingleLayerTopologyCheck );
115+
116+
for ( const QString &check : activeChecks )
117+
{
118+
checkRegistry->geometryCheckFactories( layer, QgsGeometryCheck::SingleLayerTopologyCheck );
119+
}
120+
#endif
121+
}
122+
81123
void QgsGeometryValidationService::cancelChecks( QgsVectorLayer *layer, QgsFeatureId fid )
82124
{
83125

@@ -88,7 +130,22 @@ void QgsGeometryValidationService::processFeature( QgsVectorLayer *layer, QgsFea
88130
emit geometryCheckStarted( layer, fid );
89131

90132
QgsFeature feature = layer->getFeature( fid );
133+
134+
const auto &checks = mSingleFeatureChecks.value( layer );
135+
136+
// The errors are going to be sent out via a signal. We cannot keep ownership in here (or can we?)
137+
// nor can we be sure that a single slot is connected to the signal. So make it a shared_ptr.
138+
QList<std::shared_ptr<QgsSingleGeometryCheckError>> allErrors;
139+
for ( QgsSingleGeometryCheck *check : checks )
140+
{
141+
const auto errors = check->processGeometry( feature.geometry() );
142+
143+
for ( auto error : errors )
144+
allErrors.append( std::shared_ptr<QgsSingleGeometryCheckError>( error ) );
145+
}
146+
147+
emit geometryCheckCompleted( layer, fid, allErrors );
91148
// TODO: this is a bit hardcore
92-
const auto errors = mIsValidGeometryCheck->processGeometry( feature.geometry() );
149+
// const auto errors = mIsValidGeometryCheck->processGeometry( feature.geometry() );
93150
// emit geometryCheckCompleted( layer, fid, errors );
94151
}

src/app/qgsgeometryvalidationservice.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ email : matthias@opengis.ch
2424
class QgsProject;
2525
class QgsMapLayer;
2626
class QgsVectorLayer;
27-
// TODO: Should be retrieved from registry!!
28-
class QgsIsValidGeometryCheck;
27+
class QgsGeometryCheck;
28+
class QgsSingleGeometryCheck;
29+
class QgsSingleGeometryCheckError;
30+
2931

3032

3133
/**
@@ -52,7 +54,7 @@ class QgsGeometryValidationService : public QObject
5254
typedef QList<FeatureError> FeatureErrors;
5355

5456
QgsGeometryValidationService( QgsProject *project );
55-
~QgsGeometryValidationService();
57+
~QgsGeometryValidationService() = default;
5658

5759
/**
5860
* Returns if a validation is active for the specified \a feature on
@@ -62,7 +64,7 @@ class QgsGeometryValidationService : public QObject
6264

6365
signals:
6466
void geometryCheckStarted( QgsVectorLayer *layer, QgsFeatureId fid );
65-
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<QgsGeometry::Error> &errors );
67+
void geometryCheckCompleted( QgsVectorLayer *layer, QgsFeatureId fid, const QList<std::shared_ptr<QgsSingleGeometryCheckError>> &errors );
6668

6769
private slots:
6870
void onLayersAdded( const QList<QgsMapLayer *> &layers );
@@ -71,15 +73,15 @@ class QgsGeometryValidationService : public QObject
7173
void onFeatureDeleted( QgsVectorLayer *layer, QgsFeatureId fid );
7274

7375
private:
76+
void enableLayerChecks( QgsVectorLayer *layer );
77+
7478
void cancelChecks( QgsVectorLayer *layer, QgsFeatureId fid );
7579

7680
void processFeature( QgsVectorLayer *layer, QgsFeatureId fid );
7781

78-
QgsIsValidGeometryCheck *mIsValidGeometryCheck;
79-
80-
QgsProject *mProject;
82+
QgsProject *mProject = nullptr;
8183

82-
QMap<QgsVectorLayer *, bool> mActiveChecks;
84+
QHash<QgsVectorLayer *, QList< QgsSingleGeometryCheck * > > mSingleFeatureChecks;
8385
};
8486

8587
#endif // QGSGEOMETRYVALIDATIONSERVICE_H

0 commit comments

Comments
 (0)