QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsclassificationfixedinterval.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsclassificationfixedinterval.cpp
3 ---------------------
4 begin : May 2022
5 copyright : (C) 2022 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 <QObject>
17
19#include "qgsapplication.h"
21
22
24 : QgsClassificationMethod( IgnoresClassCount, 0 )
25{
26 std::unique_ptr< QgsProcessingParameterNumber > param = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "INTERVAL" ), QObject::tr( "Interval size" ), Qgis::ProcessingNumberParameterType::Double, 1, false, 0.000000000001 );
27 addParameter( param.release() );
28}
29
36
38{
39 return QObject::tr( "Fixed Interval" );
40}
41
43{
44 return QStringLiteral( "Fixed" );
45}
46
48{
49 return QgsApplication::getThemeIcon( QStringLiteral( "classification_methods/mClassificationFixedInterval.svg" ) );
50}
51
52QList<double> QgsClassificationFixedInterval::calculateBreaks( double &minimum, double &maximum, const QList<double> &, int )
53{
54 const QgsProcessingContext context;
55 const QgsProcessingParameterDefinition *def = parameterDefinition( QStringLiteral( "INTERVAL" ) );
56 const double interval = QgsProcessingParameters::parameterAsDouble( def, parameterValues(), context );
57
58 QList<double> breaks;
59 if ( qgsDoubleNear( interval, 0 ) || interval < 0 )
60 {
61 breaks << maximum;
62 return breaks;
63 }
64
65 double value = minimum;
66 while ( value < maximum )
67 {
68 value += interval;
69 breaks << value;
70 }
71
72 return breaks;
73}
74
76{
77 return false;
78}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Implementation of a fixed interval classification.
QgsClassificationMethod * clone() const override
Returns a clone of the method.
QIcon icon() const override
The icon of the method.
QString name() const override
The readable and translate name of the method.
QString id() const override
The id of the method as saved in the project, must be unique in registry.
bool valuesRequired() const override
Returns if the method requires values to calculate the classes If not, bounds are sufficient.
QgsClassificationMethod is an abstract class for implementations of classification methods.
QVariantMap parameterValues() const
Returns the values of the processing parameters.
void addParameter(QgsProcessingParameterDefinition *definition)
Add a parameter to the method.
const QgsProcessingParameterDefinition * parameterDefinition(const QString &parameterName) const
Returns the parameter from its name.
void copyBase(QgsClassificationMethod *c) const
Copy the parameters (shall be used in clone implementation)
Contains information about the context in which a processing algorithm is executed.
Base class for the definition of processing parameters.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5144