QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
processing
qgsalgorithmtruncatetable.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsalgorithmtruncatetable.cpp
3
---------------------
4
begin : December 2019
5
copyright : (C) 2019 by Alexander Bruy
6
email : alexander dot bruy at gmail dot com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsalgorithmtruncatetable.h
"
19
20
#include "
qgsvectorlayer.h
"
21
22
#include <QString>
23
24
using namespace
Qt::StringLiterals;
25
27
28
QString QgsTruncateTableAlgorithm::name()
const
29
{
30
return
u
"truncatetable"
_s;
31
}
32
33
QString QgsTruncateTableAlgorithm::displayName()
const
34
{
35
return
QObject::tr(
"Truncate table"
);
36
}
37
38
QStringList QgsTruncateTableAlgorithm::tags()
const
39
{
40
return
QObject::tr(
"empty,delete,layer,clear,features"
).split(
','
);
41
}
42
43
QString QgsTruncateTableAlgorithm::group()
const
44
{
45
return
QObject::tr(
"Vector general"
);
46
}
47
48
QString QgsTruncateTableAlgorithm::groupId()
const
49
{
50
return
u
"vectorgeneral"
_s;
51
}
52
53
QString QgsTruncateTableAlgorithm::shortHelpString()
const
54
{
55
return
QObject::tr(
"This algorithm truncates a layer, by deleting all features from within the layer."
)
56
+ u
"\n\n"
_s
57
+ QObject::tr(
"Warning — this algorithm modifies the layer in place, and deleted features cannot be restored!"
);
58
}
59
60
QString QgsTruncateTableAlgorithm::shortDescription()
const
61
{
62
return
QObject::tr(
"Truncates a layer, by deleting all features from within the layer."
);
63
}
64
65
Qgis::ProcessingAlgorithmFlags
QgsTruncateTableAlgorithm::flags()
const
66
{
67
return
QgsProcessingAlgorithm::flags
() |
Qgis::ProcessingAlgorithmFlag::NoThreading
;
68
}
69
70
QgsTruncateTableAlgorithm *QgsTruncateTableAlgorithm::createInstance()
const
71
{
72
return
new
QgsTruncateTableAlgorithm();
73
}
74
75
void
QgsTruncateTableAlgorithm::initAlgorithm(
const
QVariantMap & )
76
{
77
addParameter(
new
QgsProcessingParameterVectorLayer
( u
"INPUT"
_s, QObject::tr(
"Input layer"
), QList<int>() <<
static_cast<
int
>
(
Qgis::ProcessingSourceType::Vector
) ) );
78
addOutput(
new
QgsProcessingOutputVectorLayer
( u
"OUTPUT"
_s, QObject::tr(
"Truncated layer"
) ) );
79
}
80
81
QVariantMap QgsTruncateTableAlgorithm::processAlgorithm(
const
QVariantMap ¶meters,
QgsProcessingContext
&context,
QgsProcessingFeedback
* )
82
{
83
QGS_MARK_ALGORITHM_SOURCE
84
85
QgsVectorLayer
*layer = parameterAsVectorLayer( parameters, u
"INPUT"
_s, context );
86
87
if
( !layer )
88
throw
QgsProcessingException
( QObject::tr(
"Invalid input layer"
) );
89
90
if
( !layer->dataProvider()->truncate() )
91
{
92
throw
QgsProcessingException
( QObject::tr(
"Could not truncate table."
) );
93
}
94
95
QVariantMap outputs;
96
outputs.insert( u
"OUTPUT"
_s, layer->id() );
97
return
outputs;
98
}
99
Qgis::ProcessingSourceType::Vector
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition
qgis.h:3777
Qgis::ProcessingAlgorithmFlags
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition
qgis.h:3848
Qgis::ProcessingAlgorithmFlag::NoThreading
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
Definition
qgis.h:3827
QgsProcessingAlgorithm::flags
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Definition
qgsprocessingalgorithm.cpp:160
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition
qgsprocessingcontext.h:45
QgsProcessingException
Custom exception class for processing related exceptions.
Definition
qgsexception.h:76
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition
qgsprocessingfeedback.h:40
QgsProcessingOutputVectorLayer
A vector layer output for processing algorithms.
Definition
qgsprocessingoutputs.h:236
QgsProcessingParameterVectorLayer
A vector layer (with or without geometry) parameter for processing algorithms.
Definition
qgsprocessingparameters.h:3274
QgsVectorLayer
Represents a vector layer which manages a vector based dataset.
Definition
qgsvectorlayer.h:414
qgsalgorithmtruncatetable.h
qgsvectorlayer.h
Generated on
for QGIS API Documentation by
1.17.0