QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
validity
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
16
#include "
qgsvaliditycheckregistry.h
"
17
18
#include "
qgsfeedback.h
"
19
20
QgsValidityCheckRegistry::QgsValidityCheckRegistry
()
21
{}
22
23
QgsValidityCheckRegistry::~QgsValidityCheckRegistry
()
24
{
25
qDeleteAll( mChecks );
26
}
27
28
QList<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
39
QList<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
50
void
QgsValidityCheckRegistry::addCheck
(
QgsAbstractValidityCheck
*check )
51
{
52
mChecks.append( check );
53
}
54
55
void
QgsValidityCheckRegistry::removeCheck
(
QgsAbstractValidityCheck
*check )
56
{
57
const
int
index = mChecks.indexOf( check );
58
if
( index >= 0 )
59
delete
mChecks.takeAt( index );
60
}
61
62
QList<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
96
std::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
}
QgsAbstractValidityCheck
Abstract base class for individual validity checks.
Definition
qgsabstractvaliditycheck.h:92
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition
qgsfeedback.h:44
QgsFeedback::isCanceled
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition
qgsfeedback.h:56
QgsFeedback::setProgress
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition
qgsfeedback.h:65
QgsValidityCheckContext
Base class for validity check contexts.
Definition
qgsvaliditycheckcontext.h:36
QgsValidityCheckRegistry::runChecks
QList< QgsValidityCheckResult > runChecks(int type, const QgsValidityCheckContext *context, QgsFeedback *feedback) const
Runs all checks of the specified type and returns a list of results.
Definition
qgsvaliditycheckregistry.cpp:62
QgsValidityCheckRegistry::checks
QList< const QgsAbstractValidityCheck * > checks() const
Returns the list of available checks.
Definition
qgsvaliditycheckregistry.cpp:28
QgsValidityCheckRegistry::removeCheck
void removeCheck(QgsAbstractValidityCheck *check)
Removes a check from the registry.
Definition
qgsvaliditycheckregistry.cpp:55
QgsValidityCheckRegistry::addCheck
void addCheck(QgsAbstractValidityCheck *check)
Adds a check to the registry.
Definition
qgsvaliditycheckregistry.cpp:50
QgsValidityCheckRegistry::~QgsValidityCheckRegistry
~QgsValidityCheckRegistry()
Definition
qgsvaliditycheckregistry.cpp:23
QgsValidityCheckRegistry::QgsValidityCheckRegistry
QgsValidityCheckRegistry()
Definition
qgsvaliditycheckregistry.cpp:20
QgsValidityCheckResult
Represents an individual result from a validity check run by a QgsAbstractValidityCheck subclass.
Definition
qgsabstractvaliditycheck.h:39
qgsfeedback.h
qgsvaliditycheckregistry.h
Generated on
for QGIS API Documentation by
1.17.0