QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsvaliditycheckregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvaliditycheckregistry.cpp
3 ----------------------------
4 begin : November 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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
17#include "qgsfeedback.h"
18
22
24{
25 qDeleteAll( mChecks );
26}
27
28QList<const QgsAbstractValidityCheck *> QgsValidityCheckRegistry::checks() const
29{
30 QList<const QgsAbstractValidityCheck *> results;
31 for ( const QgsAbstractValidityCheck *check : mChecks )
32 {
33 if ( check )
34 results.append( check );
35 }
36 return results;
37}
38
39QList<const QgsAbstractValidityCheck *> QgsValidityCheckRegistry::checks( int type ) const
40{
41 QList< const QgsAbstractValidityCheck * > results;
42 for ( const QgsAbstractValidityCheck *check : mChecks )
43 {
44 if ( check && check->checkType() == type )
45 results << check;
46 }
47 return results;
48}
49
51{
52 mChecks.append( check );
53}
54
56{
57 const int index = mChecks.indexOf( check );
58 if ( index >= 0 )
59 delete mChecks.takeAt( index );
60}
61
62QList<QgsValidityCheckResult> QgsValidityCheckRegistry::runChecks( int type, const QgsValidityCheckContext *context, QgsFeedback *feedback ) const
63{
64 QList<QgsValidityCheckResult> result;
65 const std::vector<std::unique_ptr<QgsAbstractValidityCheck> > toCheck = createChecks( type );
66 int i = 0;
67 for ( const std::unique_ptr< QgsAbstractValidityCheck > &check : toCheck )
68 {
69 if ( feedback && feedback->isCanceled() )
70 break;
71
72 if ( !check->prepareCheck( context, feedback ) )
73 {
74 if ( feedback )
75 {
76 feedback->setProgress( static_cast< double >( i ) / toCheck.size() * 100 );
77 }
78 continue;
79 }
80
81 const QList< QgsValidityCheckResult > checkResults = check->runCheck( context, feedback );
82 for ( QgsValidityCheckResult checkResult : checkResults )
83 {
84 checkResult.checkId = check->id();
85 result << checkResult;
86 }
87 i++;
88 if ( feedback )
89 {
90 feedback->setProgress( static_cast< double >( i ) / toCheck.size() * 100 );
91 }
92 }
93 return result;
94}
95
96std::vector<std::unique_ptr<QgsAbstractValidityCheck> > QgsValidityCheckRegistry::createChecks( int type ) const
97{
98 const QList< const QgsAbstractValidityCheck *> toCheck = checks( type );
99 std::vector<std::unique_ptr<QgsAbstractValidityCheck> > results;
100 results.reserve( toCheck.size() );
101 for ( const QgsAbstractValidityCheck *check : toCheck )
102 {
103 results.emplace_back( std::unique_ptr< QgsAbstractValidityCheck >( check->create() ) );
104 }
105 return results;
106}
Abstract base class for individual validity checks.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
Base class for validity check contexts.
QList< QgsValidityCheckResult > runChecks(int type, const QgsValidityCheckContext *context, QgsFeedback *feedback) const
Runs all checks of the specified type and returns a list of results.
QList< const QgsAbstractValidityCheck * > checks() const
Returns the list of available checks.
void removeCheck(QgsAbstractValidityCheck *check)
Removes a check from the registry.
void addCheck(QgsAbstractValidityCheck *check)
Adds a check to the registry.
Represents an individual result from a validity check run by a QgsAbstractValidityCheck subclass.