QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgssymbollayerutils.h"
20 #include "qgsapplication.h"
21 #include "qgsprocessingcontext.h"
22 
23 
25  : QgsClassificationMethod( IgnoresClassCount, 0 )
26 {
27  std::unique_ptr< QgsProcessingParameterNumber > param = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "INTERVAL" ), QObject::tr( "Interval size" ), QgsProcessingParameterNumber::Double, 1, false, 0.000000000001 );
28  addParameter( param.release() );
29 }
30 
32 {
34  copyBase( c );
35  return c;
36 }
37 
39 {
40  return QObject::tr( "Fixed Interval" );
41 }
42 
44 {
45  return QStringLiteral( "Fixed" );
46 }
47 
49 {
50  return QgsApplication::getThemeIcon( QStringLiteral( "classification_methods/mClassificationFixedInterval.svg" ) );
51 }
52 
53 QList<double> QgsClassificationFixedInterval::calculateBreaks( double &minimum, double &maximum, const QList<double> &, int )
54 {
55  const QgsProcessingContext context;
56  const QgsProcessingParameterDefinition *def = parameterDefinition( QStringLiteral( "INTERVAL" ) );
57  const double interval = QgsProcessingParameters::parameterAsDouble( def, parameterValues(), context );
58 
59  QList<double> breaks;
60  if ( qgsDoubleNear( interval, 0 ) || interval < 0 )
61  {
62  breaks << maximum;
63  return breaks;
64  }
65 
66  double value = minimum;
67  while ( value < maximum )
68  {
69  value += interval;
70  breaks << value;
71  }
72 
73  return breaks;
74 }
75 
77 {
78  return false;
79 }
QgsClassificationFixedInterval::valuesRequired
bool valuesRequired() const override
Returns if the method requires values to calculate the classes If not, bounds are sufficient.
Definition: qgsclassificationfixedinterval.cpp:76
QgsClassificationFixedInterval::clone
QgsClassificationMethod * clone() const override
Returns a clone of the method.
Definition: qgsclassificationfixedinterval.cpp:31
QgsProcessingParameterNumber::Double
@ Double
Double/float values.
Definition: qgsprocessingparameters.h:2187
QgsClassificationMethod
QgsClassificationMethod is an abstract class for implementations of classification methods.
Definition: qgsclassificationmethod.h:88
qgssymbollayerutils.h
QgsClassificationFixedInterval::name
QString name() const override
The readable and translate name of the method.
Definition: qgsclassificationfixedinterval.cpp:38
QgsClassificationMethod::addParameter
void addParameter(QgsProcessingParameterDefinition *definition)
Add a parameter to the method.
Definition: qgsclassificationmethod.cpp:181
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:334
QgsClassificationMethod::parameterDefinition
const QgsProcessingParameterDefinition * parameterDefinition(const QString &parameterName) const
Returns the parameter from its name.
Definition: qgsclassificationmethod.cpp:186
qgsapplication.h
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsClassificationMethod::copyBase
void copyBase(QgsClassificationMethod *c) const
Copy the parameters (shall be used in clone implementation)
Definition: qgsclassificationmethod.cpp:52
QgsClassificationFixedInterval
Implementation of a fixed interval classification.
Definition: qgsclassificationfixedinterval.h:28
QgsClassificationFixedInterval::icon
QIcon icon() const override
The icon of the method.
Definition: qgsclassificationfixedinterval.cpp:48
qgsclassificationfixedinterval.h
c
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
Definition: porting_processing.dox:1
QgsClassificationFixedInterval::id
QString id() const override
The id of the method as saved in the project, must be unique in registry.
Definition: qgsclassificationfixedinterval.cpp:43
qgsprocessingcontext.h
QgsClassificationFixedInterval::QgsClassificationFixedInterval
QgsClassificationFixedInterval()
Definition: qgsclassificationfixedinterval.cpp:24
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsClassificationMethod::parameterValues
QVariantMap parameterValues() const
Returns the values of the processing parameters.
Definition: qgsclassificationmethod.h:308
QgsProcessingParameters::parameterAsDouble
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
Definition: qgsprocessingparameters.cpp:183