QGIS API Documentation  3.27.0-Master (11ef3e5184)
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 }
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:2527