27 QgsProcessingParameterEnum *param =
new QgsProcessingParameterEnum( QStringLiteral(
"ZERO_NEG_VALUES_HANDLE" ), QObject::tr(
"Handling of 0 or negative values" ), QStringList() << QObject::tr(
"no handling (faster)" ) << QObject::tr(
"discard (slower)" ) << QObject::tr(
"prepend range (slower)" ),
false, 0 );
41 return QObject::tr(
"Logarithmic Scale" );
46 return QStringLiteral(
"Logarithmic" );
54QList<double> QgsClassificationLogarithmic::calculateBreaks(
double &minimum,
double &maximum,
const QList<double> &values,
int nclasses, QString &error )
61 double positiveMinimum = std::numeric_limits<double>::max();
64 Q_ASSERT( values.count() );
67 for (
int i = 0; i < values.count(); i++ )
69 if ( values.at( i ) > 0 )
70 positiveMinimum = std::min( positiveMinimum, values.at( i ) );
73 if ( positiveMinimum == std::numeric_limits<double>::max() )
77 return QList<double>( {0} );
79 return QList<double>();
85 if ( positiveMinimum != std::numeric_limits<double>::max() )
88 breaks << std::floor( std::log10( positiveMinimum ) );
90 minimum = positiveMinimum;
94 positiveMinimum = minimum;
98 const double actualLogMin { std::log10( positiveMinimum ) };
99 double logMin = std::floor( actualLogMin );
100 const double logMax = std::ceil( std::log10( maximum ) );
106 while ( ! prettyBreaks.isEmpty() && prettyBreaks.first() < actualLogMin )
112 breaks.append( prettyBreaks );
115 for (
int i = 0; i < breaks.count(); i++ )
117 breaks[i] = std::pow( 10, breaks.at( i ) );
123QString QgsClassificationLogarithmic::valueToLabel(
double value )
const
127 return QLocale().toString( value );
131 if ( std::isnan( value ) )
133 return QObject::tr(
"invalid (0 or negative values in the data)" );
137 return QString( QStringLiteral(
"10^%L1" ) ).arg( std::log10( value ) );
145 const QString upperLabel = valueToLabel( upperValue );
154 lowerLabel = valueToLabel( lowerValue );
158 return labelFormat().arg( lowerLabel, upperLabel );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Implementation of a logarithmic scale method.
bool valuesRequired() const override
Returns if the method requires values to calculate the classes If not, bounds are sufficient.
NegativeValueHandling
Handling of negative and 0 values in the method.
@ PrependBreak
Prepend an extra break to include negative values - this will require all values.
@ Discard
Negative values are discarded - this will require all values.
QString labelForRange(double lowerValue, double upperValue, ClassPosition position) const override
Returns the label for a range.
QString id() const override
The id of the method as saved in the project, must be unique in registry.
QString name() const override
The readable and translate name of the method.
QgsClassificationMethod * clone() const override
Returns a clone of the method.
QIcon icon() const override
The icon of the method.
QgsClassificationLogarithmic()
QgsClassificationMethod is an abstract class for implementations of classification methods.
QVariantMap parameterValues() const
Returns the values of the processing parameters.
ClassPosition
Defines the class position.
@ LowerBound
The class is at the lower bound.
@ UpperBound
The class is at the upper bound.
@ Inner
The class is not at a bound.
void addParameter(QgsProcessingParameterDefinition *definition)
Add a parameter to the method.
QString labelFormat() const
Returns the format of the label for the classes.
const QgsProcessingParameterDefinition * parameterDefinition(const QString ¶meterName) const
Returns the parameter from its name.
QString formatNumber(double value) const
Format the number according to label properties.
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.
An enum based parameter for processing algorithms, allowing for selection from predefined values.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
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