From f5d01c51f9960a9687e7f7667498984b61a7aeed Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 29 Nov 2024 09:51:40 +1000 Subject: [PATCH 1/2] Move QgsRasterMinMaxOrigin enums to Qgis, promote to enum class --- python/PyQt6/core/auto_additions/qgis.py | 94 +++++++++++++++++++ .../auto_additions/qgsrasterminmaxorigin.py | 9 -- python/PyQt6/core/auto_generated/qgis.sip.in | 21 +++++ .../raster/qgsrasterlayer.sip.in | 8 +- .../raster/qgsrasterminmaxorigin.sip.in | 51 +++------- python/core/auto_additions/qgis.py | 94 +++++++++++++++++++ python/core/auto_generated/qgis.sip.in | 21 +++++ .../raster/qgsrasterlayer.sip.in | 8 +- .../raster/qgsrasterminmaxorigin.sip.in | 51 +++------- src/app/georeferencer/qgsgeorefmainwindow.cpp | 2 +- src/app/options/qgsrasterrenderingoptions.cpp | 6 +- src/app/qgisapp.cpp | 10 +- src/app/qgisapp.h | 2 +- src/core/qgis.h | 45 +++++++++ src/core/raster/qgsrasterlayer.cpp | 40 ++++---- src/core/raster/qgsrasterlayer.h | 16 ++-- src/core/raster/qgsrasterminmaxorigin.cpp | 55 ++++++----- src/core/raster/qgsrasterminmaxorigin.h | 71 ++++---------- src/core/raster/qgsrasterrenderer.cpp | 4 +- .../qgssinglebandpseudocolorrenderer.cpp | 18 ++-- src/gui/raster/qgsrasterminmaxwidget.cpp | 34 +++---- ...qgssinglebandpseudocolorrendererwidget.cpp | 11 +-- tests/src/core/testqgsrasterlayer.cpp | 14 +-- 23 files changed, 428 insertions(+), 257 deletions(-) diff --git a/python/PyQt6/core/auto_additions/qgis.py b/python/PyQt6/core/auto_additions/qgis.py index b5b908eedab2..908fa3ead02c 100644 --- a/python/PyQt6/core/auto_additions/qgis.py +++ b/python/PyQt6/core/auto_additions/qgis.py @@ -2763,6 +2763,100 @@ Qgis.RasterRendererCapabilities = lambda flags=0: Qgis.RasterRendererCapability(flags) Qgis.RasterRendererCapabilities.baseClass = Qgis RasterRendererCapabilities = Qgis # dirty hack since SIP seems to introduce the flags in module +QgsRasterMinMaxOrigin.Limits = Qgis.RasterRangeLimit +# monkey patching scoped based enum +QgsRasterMinMaxOrigin.None_ = Qgis.RasterRangeLimit.NotSet +QgsRasterMinMaxOrigin.Limits.None_ = Qgis.RasterRangeLimit.NotSet +QgsRasterMinMaxOrigin.None_.is_monkey_patched = True +QgsRasterMinMaxOrigin.None_.__doc__ = "User defined" +QgsRasterMinMaxOrigin.MinMax = Qgis.RasterRangeLimit.MinimumMaximum +QgsRasterMinMaxOrigin.Limits.MinMax = Qgis.RasterRangeLimit.MinimumMaximum +QgsRasterMinMaxOrigin.MinMax.is_monkey_patched = True +QgsRasterMinMaxOrigin.MinMax.__doc__ = "Real min-max values" +QgsRasterMinMaxOrigin.StdDev = Qgis.RasterRangeLimit.StdDev +QgsRasterMinMaxOrigin.StdDev.is_monkey_patched = True +QgsRasterMinMaxOrigin.StdDev.__doc__ = "Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]" +QgsRasterMinMaxOrigin.CumulativeCut = Qgis.RasterRangeLimit.CumulativeCut +QgsRasterMinMaxOrigin.CumulativeCut.is_monkey_patched = True +QgsRasterMinMaxOrigin.CumulativeCut.__doc__ = "Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]" +Qgis.RasterRangeLimit.__doc__ = """Describes the limits used to compute raster ranges (min/max values). + +.. note:: + + Prior to QGIS 3.42 this was available as :py:class:`QgsRasterMinMaxOrigin`.Limits + +.. versionadded:: 3.42 + +* ``NotSet``: User defined + + Available as ``QgsRasterMinMaxOrigin.None_`` in older QGIS releases. + +* ``MinimumMaximum``: Real min-max values + + Available as ``QgsRasterMinMaxOrigin.MinMax`` in older QGIS releases. + +* ``StdDev``: Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ] +* ``CumulativeCut``: Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ] + +""" +# -- +Qgis.RasterRangeLimit.baseClass = Qgis +QgsRasterMinMaxOrigin.Extent = Qgis.RasterRangeExtent +# monkey patching scoped based enum +QgsRasterMinMaxOrigin.None_ = Qgis.RasterRangeExtent.WholeRaster +QgsRasterMinMaxOrigin.Extent.None_ = Qgis.RasterRangeExtent.WholeRaster +QgsRasterMinMaxOrigin.None_.is_monkey_patched = True +QgsRasterMinMaxOrigin.None_.__doc__ = "Whole raster is used to compute statistics" +QgsRasterMinMaxOrigin.CurrentCanvas = Qgis.RasterRangeExtent.FixedCanvas +QgsRasterMinMaxOrigin.Extent.CurrentCanvas = Qgis.RasterRangeExtent.FixedCanvas +QgsRasterMinMaxOrigin.CurrentCanvas.is_monkey_patched = True +QgsRasterMinMaxOrigin.CurrentCanvas.__doc__ = "Current extent of the canvas (at the time of computation) is used to compute statistics" +QgsRasterMinMaxOrigin.UpdatedCanvas = Qgis.RasterRangeExtent.UpdatedCanvas +QgsRasterMinMaxOrigin.UpdatedCanvas.is_monkey_patched = True +QgsRasterMinMaxOrigin.UpdatedCanvas.__doc__ = "Constantly updated extent of the canvas is used to compute statistics" +Qgis.RasterRangeExtent.__doc__ = """Describes the extent used to compute raster ranges (min/max values). + +.. note:: + + Prior to QGIS 3.42 this was available as :py:class:`QgsRasterMinMaxOrigin`.Extent + +.. versionadded:: 3.42 + +* ``WholeRaster``: Whole raster is used to compute statistics + + Available as ``QgsRasterMinMaxOrigin.None_`` in older QGIS releases. + +* ``FixedCanvas``: Current extent of the canvas (at the time of computation) is used to compute statistics + + Available as ``QgsRasterMinMaxOrigin.CurrentCanvas`` in older QGIS releases. + +* ``UpdatedCanvas``: Constantly updated extent of the canvas is used to compute statistics + +""" +# -- +Qgis.RasterRangeExtent.baseClass = Qgis +QgsRasterMinMaxOrigin.StatAccuracy = Qgis.RasterRangeAccuracy +# monkey patching scoped based enum +QgsRasterMinMaxOrigin.Exact = Qgis.RasterRangeAccuracy.Exact +QgsRasterMinMaxOrigin.Exact.is_monkey_patched = True +QgsRasterMinMaxOrigin.Exact.__doc__ = "Exact statistics" +QgsRasterMinMaxOrigin.Estimated = Qgis.RasterRangeAccuracy.Estimated +QgsRasterMinMaxOrigin.Estimated.is_monkey_patched = True +QgsRasterMinMaxOrigin.Estimated.__doc__ = "Approximated statistics" +Qgis.RasterRangeAccuracy.__doc__ = """Describes the accuracy used to compute raster ranges (min/max values). + +.. note:: + + Prior to QGIS 3.42 this was available as :py:class:`QgsRasterMinMaxOrigin`.StatAccuracy + +.. versionadded:: 3.42 + +* ``Exact``: Exact statistics +* ``Estimated``: Approximated statistics + +""" +# -- +Qgis.RasterRangeAccuracy.baseClass = Qgis # monkey patching scoped based enum Qgis.RasterAttributeTableFieldUsage.Generic.__doc__ = "Field usage Generic" Qgis.RasterAttributeTableFieldUsage.PixelCount.__doc__ = "Field usage PixelCount" diff --git a/python/PyQt6/core/auto_additions/qgsrasterminmaxorigin.py b/python/PyQt6/core/auto_additions/qgsrasterminmaxorigin.py index 54e570ce2287..2cc34e430046 100644 --- a/python/PyQt6/core/auto_additions/qgsrasterminmaxorigin.py +++ b/python/PyQt6/core/auto_additions/qgsrasterminmaxorigin.py @@ -1,13 +1,4 @@ # The following has been generated automatically from src/core/raster/qgsrasterminmaxorigin.h -QgsRasterMinMaxOrigin.None_ = QgsRasterMinMaxOrigin.Limits.None_ -QgsRasterMinMaxOrigin.MinMax = QgsRasterMinMaxOrigin.Limits.MinMax -QgsRasterMinMaxOrigin.StdDev = QgsRasterMinMaxOrigin.Limits.StdDev -QgsRasterMinMaxOrigin.CumulativeCut = QgsRasterMinMaxOrigin.Limits.CumulativeCut -QgsRasterMinMaxOrigin.WholeRaster = QgsRasterMinMaxOrigin.Extent.WholeRaster -QgsRasterMinMaxOrigin.CurrentCanvas = QgsRasterMinMaxOrigin.Extent.CurrentCanvas -QgsRasterMinMaxOrigin.UpdatedCanvas = QgsRasterMinMaxOrigin.Extent.UpdatedCanvas -QgsRasterMinMaxOrigin.Exact = QgsRasterMinMaxOrigin.StatAccuracy.Exact -QgsRasterMinMaxOrigin.Estimated = QgsRasterMinMaxOrigin.StatAccuracy.Estimated try: QgsRasterMinMaxOrigin.__attribute_docs__ = {'CUMULATIVE_CUT_LOWER': 'Default cumulative cut lower limit', 'CUMULATIVE_CUT_UPPER': 'Default cumulative cut upper limit', 'DEFAULT_STDDEV_FACTOR': 'Default standard deviation factor'} QgsRasterMinMaxOrigin.limitsString = staticmethod(QgsRasterMinMaxOrigin.limitsString) diff --git a/python/PyQt6/core/auto_generated/qgis.sip.in b/python/PyQt6/core/auto_generated/qgis.sip.in index 070a2eb20612..ce406a262163 100644 --- a/python/PyQt6/core/auto_generated/qgis.sip.in +++ b/python/PyQt6/core/auto_generated/qgis.sip.in @@ -852,6 +852,27 @@ The development version typedef QFlags RasterRendererCapabilities; + enum class RasterRangeLimit /BaseType=IntEnum/ + { + NotSet, + MinimumMaximum, + StdDev, + CumulativeCut + }; + + enum class RasterRangeExtent /BaseType=IntEnum/ + { + WholeRaster, + FixedCanvas, + UpdatedCanvas, + }; + + enum class RasterRangeAccuracy /BaseType=IntEnum/ + { + Exact, + Estimated, + }; + enum class RasterAttributeTableFieldUsage /BaseType=IntEnum/ { Generic, diff --git a/python/PyQt6/core/auto_generated/raster/qgsrasterlayer.sip.in b/python/PyQt6/core/auto_generated/raster/qgsrasterlayer.sip.in index 86c4c9c7cf3f..f6fc64b98487 100644 --- a/python/PyQt6/core/auto_generated/raster/qgsrasterlayer.sip.in +++ b/python/PyQt6/core/auto_generated/raster/qgsrasterlayer.sip.in @@ -45,11 +45,11 @@ Sample usage of the :py:class:`QgsRasterLayer` class: static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM; - static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit SINGLE_BAND_MIN_MAX_LIMITS; - static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS; - static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS; QgsRasterLayer(); %Docstring @@ -339,7 +339,7 @@ In a world file, this is normally the first row (without the sign). void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, - QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax, + Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum, const QgsRectangle &extent = QgsRectangle(), int sampleSize = QgsRasterLayer::SAMPLE_SIZE, bool generateLookupTableFlag = true ); diff --git a/python/PyQt6/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in b/python/PyQt6/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in index d06d7fba875e..3604a611e336 100644 --- a/python/PyQt6/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in +++ b/python/PyQt6/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in @@ -28,49 +28,22 @@ itself the min/max values. static const double DEFAULT_STDDEV_FACTOR; - //! \brief This enumerator describes the limits used to compute min/max values - enum Limits /BaseType=IntEnum/ - { - None /PyName=None_/, - MinMax, - StdDev, - CumulativeCut - }; - - enum Extent /BaseType=IntEnum/ - { - //! Whole raster is used to compute statistics. - WholeRaster, - //! Current extent of the canvas (at the time of computation) is used to compute statistics. - CurrentCanvas, - //! Constantly updated extent of the canvas is used to compute statistics. - UpdatedCanvas - }; - - enum StatAccuracy /BaseType=IntEnum/ - { - //! Exact statistics. - Exact, - //! Approximated statistics. - Estimated - }; - QgsRasterMinMaxOrigin(); bool operator ==( const QgsRasterMinMaxOrigin &other ) const; - QgsRasterMinMaxOrigin::Limits limits() const; + Qgis::RasterRangeLimit limits() const; %Docstring Returns the raster limits. %End - QgsRasterMinMaxOrigin::Extent extent() const; + Qgis::RasterRangeExtent extent() const; %Docstring Returns the raster extent. %End - QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const; + Qgis::RasterRangeAccuracy statAccuracy() const; %Docstring Returns the raster statistic accuracy. %End @@ -91,17 +64,17 @@ Returns the factor f so that the min/max range is [ mean - f * stddev , mean + f %End - void setLimits( QgsRasterMinMaxOrigin::Limits limits ); + void setLimits( Qgis::RasterRangeLimit limits ); %Docstring Sets the limits. %End - void setExtent( QgsRasterMinMaxOrigin::Extent extent ); + void setExtent( Qgis::RasterRangeExtent extent ); %Docstring Sets the extent. %End - void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy ); + void setStatAccuracy( Qgis::RasterRangeAccuracy accuracy ); %Docstring Sets the statistics accuracy. %End @@ -133,32 +106,32 @@ Deserialize object. %End - static QString limitsString( Limits limits ); + static QString limitsString( Qgis::RasterRangeLimit limits ); %Docstring Returns a string to serialize Limits %End - static Limits limitsFromString( const QString &limits ); + static Qgis::RasterRangeLimit limitsFromString( const QString &limits ); %Docstring Deserialize Limits %End - static QString extentString( QgsRasterMinMaxOrigin::Extent extent ); + static QString extentString( Qgis::RasterRangeExtent extent ); %Docstring Returns a string to serialize Extent %End - static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent ); + static Qgis::RasterRangeExtent extentFromString( const QString &extent ); %Docstring Deserialize Extent %End - static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy ); + static QString statAccuracyString( Qgis::RasterRangeAccuracy accuracy ); %Docstring Returns a string to serialize StatAccuracy %End - static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy ); + static Qgis::RasterRangeAccuracy statAccuracyFromString( const QString &accuracy ); %Docstring Deserialize StatAccuracy %End diff --git a/python/core/auto_additions/qgis.py b/python/core/auto_additions/qgis.py index 3025143ffffd..fb53c17ecdf2 100644 --- a/python/core/auto_additions/qgis.py +++ b/python/core/auto_additions/qgis.py @@ -2731,6 +2731,100 @@ Qgis.RasterRendererCapability.baseClass = Qgis Qgis.RasterRendererCapabilities.baseClass = Qgis RasterRendererCapabilities = Qgis # dirty hack since SIP seems to introduce the flags in module +QgsRasterMinMaxOrigin.Limits = Qgis.RasterRangeLimit +# monkey patching scoped based enum +QgsRasterMinMaxOrigin.None_ = Qgis.RasterRangeLimit.NotSet +QgsRasterMinMaxOrigin.Limits.None_ = Qgis.RasterRangeLimit.NotSet +QgsRasterMinMaxOrigin.None_.is_monkey_patched = True +QgsRasterMinMaxOrigin.None_.__doc__ = "User defined" +QgsRasterMinMaxOrigin.MinMax = Qgis.RasterRangeLimit.MinimumMaximum +QgsRasterMinMaxOrigin.Limits.MinMax = Qgis.RasterRangeLimit.MinimumMaximum +QgsRasterMinMaxOrigin.MinMax.is_monkey_patched = True +QgsRasterMinMaxOrigin.MinMax.__doc__ = "Real min-max values" +QgsRasterMinMaxOrigin.StdDev = Qgis.RasterRangeLimit.StdDev +QgsRasterMinMaxOrigin.StdDev.is_monkey_patched = True +QgsRasterMinMaxOrigin.StdDev.__doc__ = "Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]" +QgsRasterMinMaxOrigin.CumulativeCut = Qgis.RasterRangeLimit.CumulativeCut +QgsRasterMinMaxOrigin.CumulativeCut.is_monkey_patched = True +QgsRasterMinMaxOrigin.CumulativeCut.__doc__ = "Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]" +Qgis.RasterRangeLimit.__doc__ = """Describes the limits used to compute raster ranges (min/max values). + +.. note:: + + Prior to QGIS 3.42 this was available as :py:class:`QgsRasterMinMaxOrigin`.Limits + +.. versionadded:: 3.42 + +* ``NotSet``: User defined + + Available as ``QgsRasterMinMaxOrigin.None_`` in older QGIS releases. + +* ``MinimumMaximum``: Real min-max values + + Available as ``QgsRasterMinMaxOrigin.MinMax`` in older QGIS releases. + +* ``StdDev``: Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ] +* ``CumulativeCut``: Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ] + +""" +# -- +Qgis.RasterRangeLimit.baseClass = Qgis +QgsRasterMinMaxOrigin.Extent = Qgis.RasterRangeExtent +# monkey patching scoped based enum +QgsRasterMinMaxOrigin.None_ = Qgis.RasterRangeExtent.WholeRaster +QgsRasterMinMaxOrigin.Extent.None_ = Qgis.RasterRangeExtent.WholeRaster +QgsRasterMinMaxOrigin.None_.is_monkey_patched = True +QgsRasterMinMaxOrigin.None_.__doc__ = "Whole raster is used to compute statistics" +QgsRasterMinMaxOrigin.CurrentCanvas = Qgis.RasterRangeExtent.FixedCanvas +QgsRasterMinMaxOrigin.Extent.CurrentCanvas = Qgis.RasterRangeExtent.FixedCanvas +QgsRasterMinMaxOrigin.CurrentCanvas.is_monkey_patched = True +QgsRasterMinMaxOrigin.CurrentCanvas.__doc__ = "Current extent of the canvas (at the time of computation) is used to compute statistics" +QgsRasterMinMaxOrigin.UpdatedCanvas = Qgis.RasterRangeExtent.UpdatedCanvas +QgsRasterMinMaxOrigin.UpdatedCanvas.is_monkey_patched = True +QgsRasterMinMaxOrigin.UpdatedCanvas.__doc__ = "Constantly updated extent of the canvas is used to compute statistics" +Qgis.RasterRangeExtent.__doc__ = """Describes the extent used to compute raster ranges (min/max values). + +.. note:: + + Prior to QGIS 3.42 this was available as :py:class:`QgsRasterMinMaxOrigin`.Extent + +.. versionadded:: 3.42 + +* ``WholeRaster``: Whole raster is used to compute statistics + + Available as ``QgsRasterMinMaxOrigin.None_`` in older QGIS releases. + +* ``FixedCanvas``: Current extent of the canvas (at the time of computation) is used to compute statistics + + Available as ``QgsRasterMinMaxOrigin.CurrentCanvas`` in older QGIS releases. + +* ``UpdatedCanvas``: Constantly updated extent of the canvas is used to compute statistics + +""" +# -- +Qgis.RasterRangeExtent.baseClass = Qgis +QgsRasterMinMaxOrigin.StatAccuracy = Qgis.RasterRangeAccuracy +# monkey patching scoped based enum +QgsRasterMinMaxOrigin.Exact = Qgis.RasterRangeAccuracy.Exact +QgsRasterMinMaxOrigin.Exact.is_monkey_patched = True +QgsRasterMinMaxOrigin.Exact.__doc__ = "Exact statistics" +QgsRasterMinMaxOrigin.Estimated = Qgis.RasterRangeAccuracy.Estimated +QgsRasterMinMaxOrigin.Estimated.is_monkey_patched = True +QgsRasterMinMaxOrigin.Estimated.__doc__ = "Approximated statistics" +Qgis.RasterRangeAccuracy.__doc__ = """Describes the accuracy used to compute raster ranges (min/max values). + +.. note:: + + Prior to QGIS 3.42 this was available as :py:class:`QgsRasterMinMaxOrigin`.StatAccuracy + +.. versionadded:: 3.42 + +* ``Exact``: Exact statistics +* ``Estimated``: Approximated statistics + +""" +# -- +Qgis.RasterRangeAccuracy.baseClass = Qgis # monkey patching scoped based enum Qgis.RasterAttributeTableFieldUsage.Generic.__doc__ = "Field usage Generic" Qgis.RasterAttributeTableFieldUsage.PixelCount.__doc__ = "Field usage PixelCount" diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 31285d7430d7..2f9afc37d003 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -852,6 +852,27 @@ The development version typedef QFlags RasterRendererCapabilities; + enum class RasterRangeLimit + { + NotSet, + MinimumMaximum, + StdDev, + CumulativeCut + }; + + enum class RasterRangeExtent + { + WholeRaster, + FixedCanvas, + UpdatedCanvas, + }; + + enum class RasterRangeAccuracy + { + Exact, + Estimated, + }; + enum class RasterAttributeTableFieldUsage { Generic, diff --git a/python/core/auto_generated/raster/qgsrasterlayer.sip.in b/python/core/auto_generated/raster/qgsrasterlayer.sip.in index 86c4c9c7cf3f..f6fc64b98487 100644 --- a/python/core/auto_generated/raster/qgsrasterlayer.sip.in +++ b/python/core/auto_generated/raster/qgsrasterlayer.sip.in @@ -45,11 +45,11 @@ Sample usage of the :py:class:`QgsRasterLayer` class: static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM; - static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit SINGLE_BAND_MIN_MAX_LIMITS; - static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS; - static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS; QgsRasterLayer(); %Docstring @@ -339,7 +339,7 @@ In a world file, this is normally the first row (without the sign). void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, - QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax, + Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum, const QgsRectangle &extent = QgsRectangle(), int sampleSize = QgsRasterLayer::SAMPLE_SIZE, bool generateLookupTableFlag = true ); diff --git a/python/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in b/python/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in index 07fcc5a095a9..3604a611e336 100644 --- a/python/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in +++ b/python/core/auto_generated/raster/qgsrasterminmaxorigin.sip.in @@ -28,49 +28,22 @@ itself the min/max values. static const double DEFAULT_STDDEV_FACTOR; - //! \brief This enumerator describes the limits used to compute min/max values - enum Limits - { - None /PyName=None_/, - MinMax, - StdDev, - CumulativeCut - }; - - enum Extent - { - //! Whole raster is used to compute statistics. - WholeRaster, - //! Current extent of the canvas (at the time of computation) is used to compute statistics. - CurrentCanvas, - //! Constantly updated extent of the canvas is used to compute statistics. - UpdatedCanvas - }; - - enum StatAccuracy - { - //! Exact statistics. - Exact, - //! Approximated statistics. - Estimated - }; - QgsRasterMinMaxOrigin(); bool operator ==( const QgsRasterMinMaxOrigin &other ) const; - QgsRasterMinMaxOrigin::Limits limits() const; + Qgis::RasterRangeLimit limits() const; %Docstring Returns the raster limits. %End - QgsRasterMinMaxOrigin::Extent extent() const; + Qgis::RasterRangeExtent extent() const; %Docstring Returns the raster extent. %End - QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const; + Qgis::RasterRangeAccuracy statAccuracy() const; %Docstring Returns the raster statistic accuracy. %End @@ -91,17 +64,17 @@ Returns the factor f so that the min/max range is [ mean - f * stddev , mean + f %End - void setLimits( QgsRasterMinMaxOrigin::Limits limits ); + void setLimits( Qgis::RasterRangeLimit limits ); %Docstring Sets the limits. %End - void setExtent( QgsRasterMinMaxOrigin::Extent extent ); + void setExtent( Qgis::RasterRangeExtent extent ); %Docstring Sets the extent. %End - void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy ); + void setStatAccuracy( Qgis::RasterRangeAccuracy accuracy ); %Docstring Sets the statistics accuracy. %End @@ -133,32 +106,32 @@ Deserialize object. %End - static QString limitsString( Limits limits ); + static QString limitsString( Qgis::RasterRangeLimit limits ); %Docstring Returns a string to serialize Limits %End - static Limits limitsFromString( const QString &limits ); + static Qgis::RasterRangeLimit limitsFromString( const QString &limits ); %Docstring Deserialize Limits %End - static QString extentString( QgsRasterMinMaxOrigin::Extent extent ); + static QString extentString( Qgis::RasterRangeExtent extent ); %Docstring Returns a string to serialize Extent %End - static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent ); + static Qgis::RasterRangeExtent extentFromString( const QString &extent ); %Docstring Deserialize Extent %End - static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy ); + static QString statAccuracyString( Qgis::RasterRangeAccuracy accuracy ); %Docstring Returns a string to serialize StatAccuracy %End - static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy ); + static Qgis::RasterRangeAccuracy statAccuracyFromString( const QString &accuracy ); %Docstring Deserialize StatAccuracy %End diff --git a/src/app/georeferencer/qgsgeorefmainwindow.cpp b/src/app/georeferencer/qgsgeorefmainwindow.cpp index 175d851315c0..49650a47dc88 100644 --- a/src/app/georeferencer/qgsgeorefmainwindow.cpp +++ b/src/app/georeferencer/qgsgeorefmainwindow.cpp @@ -889,7 +889,7 @@ void QgsGeoreferencerMainWindow::localHistogramStretch() if ( mLayer && mLayer->type() == Qgis::LayerType::Raster && mCanvas ) { - qobject_cast( mLayer.get() )->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax, rectangle ); + qobject_cast( mLayer.get() )->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, Qgis::RasterRangeLimit::MinimumMaximum, rectangle ); mCanvas->refresh(); } } diff --git a/src/app/options/qgsrasterrenderingoptions.cpp b/src/app/options/qgsrasterrenderingoptions.cpp index b0e5aa022962..ffccac550f94 100644 --- a/src/app/options/qgsrasterrenderingoptions.cpp +++ b/src/app/options/qgsrasterrenderingoptions.cpp @@ -143,11 +143,11 @@ void QgsRasterRenderingOptionsWidget::initMinMaxLimits( QComboBox *cbox, const Q //add items to the color limitsContrast combo boxes cbox->addItem( tr( "Cumulative Pixel Count Cut" ), - QgsRasterMinMaxOrigin::limitsString( QgsRasterMinMaxOrigin::CumulativeCut ) ); + QgsRasterMinMaxOrigin::limitsString( Qgis::RasterRangeLimit::CumulativeCut ) ); cbox->addItem( tr( "Minimum / Maximum" ), - QgsRasterMinMaxOrigin::limitsString( QgsRasterMinMaxOrigin::MinMax ) ); + QgsRasterMinMaxOrigin::limitsString( Qgis::RasterRangeLimit::MinimumMaximum ) ); cbox->addItem( tr( "Mean +/- Standard Deviation" ), - QgsRasterMinMaxOrigin::limitsString( QgsRasterMinMaxOrigin::StdDev ) ); + QgsRasterMinMaxOrigin::limitsString( Qgis::RasterRangeLimit::StdDev ) ); QString contrastLimits = settings.value( "/Raster/defaultContrastEnhancementLimits/" + name, defaultVal ).toString(); cbox->setCurrentIndex( cbox->findData( contrastLimits ) ); diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 587146418e13..84703b00257b 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -12793,25 +12793,25 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString ¤tPage, in void QgisApp::fullHistogramStretch() { - histogramStretch( false, QgsRasterMinMaxOrigin::MinMax ); + histogramStretch( false, Qgis::RasterRangeLimit::MinimumMaximum ); } void QgisApp::localHistogramStretch() { - histogramStretch( true, QgsRasterMinMaxOrigin::MinMax ); + histogramStretch( true, Qgis::RasterRangeLimit::MinimumMaximum ); } void QgisApp::fullCumulativeCutStretch() { - histogramStretch( false, QgsRasterMinMaxOrigin::CumulativeCut ); + histogramStretch( false, Qgis::RasterRangeLimit::CumulativeCut ); } void QgisApp::localCumulativeCutStretch() { - histogramStretch( true, QgsRasterMinMaxOrigin::CumulativeCut ); + histogramStretch( true, Qgis::RasterRangeLimit::CumulativeCut ); } -void QgisApp::histogramStretch( bool visibleAreaOnly, QgsRasterMinMaxOrigin::Limits limits ) +void QgisApp::histogramStretch( bool visibleAreaOnly, Qgis::RasterRangeLimit limits ) { QgsMapLayer *myLayer = mLayerTreeView->currentLayer(); diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index c2ae2b89f2b6..e306b5958aa1 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -2319,7 +2319,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow void refreshProfileMenu(); //! Do histogram stretch for singleband gray / multiband color rasters - void histogramStretch( bool visibleAreaOnly = false, QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax ); + void histogramStretch( bool visibleAreaOnly = false, Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum ); //! Apply raster brightness/contrast void adjustBrightnessContrast( int delta, bool updateBrightness = true ); diff --git a/src/core/qgis.h b/src/core/qgis.h index 383347ee8aee..8d470111f521 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -1425,6 +1425,51 @@ class CORE_EXPORT Qgis Q_DECLARE_FLAGS( RasterRendererCapabilities, RasterRendererCapability ) Q_FLAG( RasterRendererCapabilities ) + /** + * Describes the limits used to compute raster ranges (min/max values). + * + * \note Prior to QGIS 3.42 this was available as QgsRasterMinMaxOrigin::Limits + * + * \since QGIS 3.42 + */ + enum class RasterRangeLimit SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsRasterMinMaxOrigin, Limits ) : int + { + NotSet SIP_MONKEYPATCH_COMPAT_NAME( None_ ), //!< User defined + MinimumMaximum SIP_MONKEYPATCH_COMPAT_NAME( MinMax ), //!< Real min-max values + StdDev, //!< Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ] + CumulativeCut //!< Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ] + }; + Q_ENUM( RasterRangeLimit ) + + /** + * Describes the extent used to compute raster ranges (min/max values). + * + * \note Prior to QGIS 3.42 this was available as QgsRasterMinMaxOrigin::Extent + * + * \since QGIS 3.42 + */ + enum class RasterRangeExtent SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsRasterMinMaxOrigin, Extent ) : int + { + WholeRaster SIP_MONKEYPATCH_COMPAT_NAME( None_ ), //!< Whole raster is used to compute statistics + FixedCanvas SIP_MONKEYPATCH_COMPAT_NAME( CurrentCanvas ), //!< Current extent of the canvas (at the time of computation) is used to compute statistics + UpdatedCanvas, //!< Constantly updated extent of the canvas is used to compute statistics + }; + Q_ENUM( RasterRangeExtent ) + + /** + * Describes the accuracy used to compute raster ranges (min/max values). + * + * \note Prior to QGIS 3.42 this was available as QgsRasterMinMaxOrigin::StatAccuracy + * + * \since QGIS 3.42 + */ + enum class RasterRangeAccuracy SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsRasterMinMaxOrigin, StatAccuracy ): int + { + Exact, //!< Exact statistics + Estimated, //!< Approximated statistics + }; + Q_ENUM( RasterRangeAccuracy ) + /** * \brief The RasterAttributeTableFieldUsage enum represents the usage of a Raster Attribute Table field. * \note Directly mapped from GDALRATFieldUsage enum values. diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 3cf6aa4a9889..3c610b837177 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -100,12 +100,12 @@ QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM = QgsContrastEnh const QgsContrastEnhancement::ContrastEnhancementAlgorithm QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM = QgsContrastEnhancement::StretchToMinimumMaximum; -const QgsRasterMinMaxOrigin::Limits -QgsRasterLayer::SINGLE_BAND_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::MinMax; -const QgsRasterMinMaxOrigin::Limits -QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::MinMax; -const QgsRasterMinMaxOrigin::Limits -QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS = QgsRasterMinMaxOrigin::CumulativeCut; +const Qgis::RasterRangeLimit +QgsRasterLayer::SINGLE_BAND_MIN_MAX_LIMITS = Qgis::RasterRangeLimit::MinimumMaximum; +const Qgis::RasterRangeLimit +QgsRasterLayer::MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS = Qgis::RasterRangeLimit::MinimumMaximum; +const Qgis::RasterRangeLimit +QgsRasterLayer::MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS = Qgis::RasterRangeLimit::CumulativeCut; QgsRasterLayer::QgsRasterLayer() : QgsMapLayer( Qgis::LayerType::Raster ) @@ -1211,7 +1211,7 @@ void QgsRasterLayer::closeDataProvider() void QgsRasterLayer::computeMinMax( int band, const QgsRasterMinMaxOrigin &mmo, - QgsRasterMinMaxOrigin::Limits limits, + Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, double &min, double &max ) @@ -1223,7 +1223,7 @@ void QgsRasterLayer::computeMinMax( int band, if ( !mDataProvider ) return; - if ( limits == QgsRasterMinMaxOrigin::MinMax ) + if ( limits == Qgis::RasterRangeLimit::MinimumMaximum ) { QgsRasterBandStats myRasterBandStats = mDataProvider->bandStatistics( band, Qgis::RasterBandStatistic::Min | Qgis::RasterBandStatistic::Max, extent, sampleSize ); // Check if statistics were actually gathered, None means a failure @@ -1296,13 +1296,13 @@ void QgsRasterLayer::computeMinMax( int band, min = myRasterBandStats.minimumValue; max = myRasterBandStats.maximumValue; } - else if ( limits == QgsRasterMinMaxOrigin::StdDev ) + else if ( limits == Qgis::RasterRangeLimit::StdDev ) { const QgsRasterBandStats myRasterBandStats = mDataProvider->bandStatistics( band, Qgis::RasterBandStatistic::Mean | Qgis::RasterBandStatistic::StdDev, extent, sampleSize ); min = myRasterBandStats.mean - ( mmo.stdDevFactor() * myRasterBandStats.stdDev ); max = myRasterBandStats.mean + ( mmo.stdDevFactor() * myRasterBandStats.stdDev ); } - else if ( limits == QgsRasterMinMaxOrigin::CumulativeCut ) + else if ( limits == Qgis::RasterRangeLimit::CumulativeCut ) { const double myLower = mmo.cumulativeCutLower(); const double myUpper = mmo.cumulativeCutUpper(); @@ -1334,7 +1334,7 @@ QgsMapLayerElevationProperties *QgsRasterLayer::elevationProperties() return mElevationProperties; } -void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, QgsRasterMinMaxOrigin::Limits limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag ) +void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag ) { QGIS_PROTECT_QOBJECT_THREAD_ACCESS @@ -1347,7 +1347,7 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh } void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, - QgsRasterMinMaxOrigin::Limits limits, + Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag, @@ -1355,7 +1355,7 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh { QGIS_PROTECT_QOBJECT_THREAD_ACCESS - QgsDebugMsgLevel( QStringLiteral( "theAlgorithm = %1 limits = %2 extent.isEmpty() = %3" ).arg( algorithm ).arg( limits ).arg( extent.isEmpty() ), 4 ); + QgsDebugMsgLevel( QStringLiteral( "theAlgorithm = %1 limits = %2 extent.isEmpty() = %3" ).arg( algorithm ).arg( qgsEnumValueToKey( limits ) ).arg( extent.isEmpty() ), 4 ); if ( !rasterRenderer || !mDataProvider ) { return; @@ -1483,9 +1483,9 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh myMinMaxOrigin.setLimits( limits ); if ( extent != QgsRectangle() && - myMinMaxOrigin.extent() == QgsRasterMinMaxOrigin::WholeRaster ) + myMinMaxOrigin.extent() == Qgis::RasterRangeExtent::WholeRaster ) { - myMinMaxOrigin.setExtent( QgsRasterMinMaxOrigin::CurrentCanvas ); + myMinMaxOrigin.setExtent( Qgis::RasterRangeExtent::FixedCanvas ); } if ( myRasterRenderer ) { @@ -1520,8 +1520,8 @@ void QgsRasterLayer::refreshContrastEnhancement( const QgsRectangle &extent ) { setContrastEnhancement( ce->contrastEnhancementAlgorithm() == QgsContrastEnhancement::NoEnhancement ? QgsContrastEnhancement::StretchToMinimumMaximum : ce->contrastEnhancementAlgorithm(), - renderer()->minMaxOrigin().limits() == QgsRasterMinMaxOrigin::None ? - QgsRasterMinMaxOrigin::MinMax : renderer()->minMaxOrigin().limits(), + renderer()->minMaxOrigin().limits() == Qgis::RasterRangeLimit::NotSet ? + Qgis::RasterRangeLimit::MinimumMaximum : renderer()->minMaxOrigin().limits(), extent, static_cast( SAMPLE_SIZE ), true, @@ -1530,7 +1530,7 @@ void QgsRasterLayer::refreshContrastEnhancement( const QgsRectangle &extent ) else { QgsContrastEnhancement::ContrastEnhancementAlgorithm myAlgorithm; - QgsRasterMinMaxOrigin::Limits myLimits; + Qgis::RasterRangeLimit myLimits; if ( defaultContrastEnhancementSettings( myAlgorithm, myLimits ) ) { setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, @@ -1609,7 +1609,7 @@ bool QgsRasterLayer::setSubsetString( const QString &subset ) bool QgsRasterLayer::defaultContrastEnhancementSettings( QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, - QgsRasterMinMaxOrigin::Limits &myLimits ) const + Qgis::RasterRangeLimit &myLimits ) const { QGIS_PROTECT_QOBJECT_THREAD_ACCESS @@ -1676,7 +1676,7 @@ void QgsRasterLayer::setDefaultContrastEnhancement() QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 ); QgsContrastEnhancement::ContrastEnhancementAlgorithm myAlgorithm; - QgsRasterMinMaxOrigin::Limits myLimits; + Qgis::RasterRangeLimit myLimits; defaultContrastEnhancementSettings( myAlgorithm, myLimits ); setContrastEnhancement( myAlgorithm, myLimits ); diff --git a/src/core/raster/qgsrasterlayer.h b/src/core/raster/qgsrasterlayer.h index df827cf7625a..30ff754ef3dd 100644 --- a/src/core/raster/qgsrasterlayer.h +++ b/src/core/raster/qgsrasterlayer.h @@ -35,7 +35,6 @@ #include "qgsmaplayer.h" #include "qgsrasterdataprovider.h" #include "qgsrasterviewport.h" -#include "qgsrasterminmaxorigin.h" #include "qgscontrastenhancement.h" #include "qgsabstractprofilesource.h" @@ -50,6 +49,7 @@ class QgsHueSaturationFilter; class QgsRasterLayerElevationProperties; class QgsSettingsEntryBool; class QgsSettingsEntryDouble; +class QgsRasterMinMaxOrigin; class QImage; class QPixmap; @@ -96,13 +96,13 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfile static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM; //! \brief Default enhancement limits for single band raster - static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit SINGLE_BAND_MIN_MAX_LIMITS; //! \brief Default enhancement limits for multiple band raster of type Byte - static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS; //! \brief Default enhancement limits for multiple band raster of type different from Byte - static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS; + static const Qgis::RasterRangeLimit MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS; //! \brief Constructor. Provider is not set. QgsRasterLayer(); @@ -392,7 +392,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfile * \param generateLookupTableFlag Generate lookup table. */ void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, - QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax, + Qgis::RasterRangeLimit limits = Qgis::RasterRangeLimit::MinimumMaximum, const QgsRectangle &extent = QgsRectangle(), int sampleSize = QgsRasterLayer::SAMPLE_SIZE, bool generateLookupTableFlag = true ); @@ -426,7 +426,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfile */ bool defaultContrastEnhancementSettings( QgsContrastEnhancement::ContrastEnhancementAlgorithm &myAlgorithm, - QgsRasterMinMaxOrigin::Limits &myLimits ) const SIP_SKIP; + Qgis::RasterRangeLimit &myLimits ) const SIP_SKIP; //! Sets the default contrast enhancement void setDefaultContrastEnhancement(); @@ -477,7 +477,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfile */ void computeMinMax( int band, const QgsRasterMinMaxOrigin &mmo, - QgsRasterMinMaxOrigin::Limits limits, + Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, double &min, double &max ) SIP_SKIP; @@ -526,7 +526,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfile void setRendererForDrawingStyle( Qgis::RasterDrawingStyle drawingStyle ); void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm, - QgsRasterMinMaxOrigin::Limits limits, + Qgis::RasterRangeLimit limits, const QgsRectangle &extent, int sampleSize, bool generateLookupTableFlag, diff --git a/src/core/raster/qgsrasterminmaxorigin.cpp b/src/core/raster/qgsrasterminmaxorigin.cpp index a9df5c831ad4..b6daa66bd7f8 100644 --- a/src/core/raster/qgsrasterminmaxorigin.cpp +++ b/src/core/raster/qgsrasterminmaxorigin.cpp @@ -43,15 +43,15 @@ bool QgsRasterMinMaxOrigin::operator ==( const QgsRasterMinMaxOrigin &other ) co std::fabs( mStdDevFactor - other.mStdDevFactor ) < 1e-5; } -QString QgsRasterMinMaxOrigin::limitsString( Limits limits ) +QString QgsRasterMinMaxOrigin::limitsString( Qgis::RasterRangeLimit limits ) { switch ( limits ) { - case MinMax: + case Qgis::RasterRangeLimit::MinimumMaximum: return QStringLiteral( "MinMax" ); - case StdDev: + case Qgis::RasterRangeLimit::StdDev: return QStringLiteral( "StdDev" ); - case CumulativeCut: + case Qgis::RasterRangeLimit::CumulativeCut: return QStringLiteral( "CumulativeCut" ); default: break; @@ -59,69 +59,74 @@ QString QgsRasterMinMaxOrigin::limitsString( Limits limits ) return QStringLiteral( "None" ); } -QgsRasterMinMaxOrigin::Limits QgsRasterMinMaxOrigin::limitsFromString( const QString &limits ) +Qgis::RasterRangeLimit QgsRasterMinMaxOrigin::limitsFromString( const QString &limits ) { if ( limits == QLatin1String( "MinMax" ) ) { - return MinMax; + return Qgis::RasterRangeLimit::MinimumMaximum; } else if ( limits == QLatin1String( "StdDev" ) ) { - return StdDev; + return Qgis::RasterRangeLimit::StdDev; } else if ( limits == QLatin1String( "CumulativeCut" ) ) { - return CumulativeCut; + return Qgis::RasterRangeLimit::CumulativeCut; } - return None; + return Qgis::RasterRangeLimit::NotSet; } -QString QgsRasterMinMaxOrigin::extentString( Extent minMaxExtent ) +QString QgsRasterMinMaxOrigin::extentString( Qgis::RasterRangeExtent minMaxExtent ) { switch ( minMaxExtent ) { - case WholeRaster: + case Qgis::RasterRangeExtent::WholeRaster: return QStringLiteral( "WholeRaster" ); - case CurrentCanvas: + case Qgis::RasterRangeExtent::FixedCanvas: return QStringLiteral( "CurrentCanvas" ); - case UpdatedCanvas: + case Qgis::RasterRangeExtent::UpdatedCanvas: return QStringLiteral( "UpdatedCanvas" ); } return QStringLiteral( "WholeRaster" ); } -QgsRasterMinMaxOrigin::Extent QgsRasterMinMaxOrigin::extentFromString( const QString &extent ) +Qgis::RasterRangeExtent QgsRasterMinMaxOrigin::extentFromString( const QString &extent ) { if ( extent == QLatin1String( "WholeRaster" ) ) { - return WholeRaster; + return Qgis::RasterRangeExtent::WholeRaster; } else if ( extent == QLatin1String( "CurrentCanvas" ) ) { - return CurrentCanvas; + return Qgis::RasterRangeExtent::FixedCanvas; } else if ( extent == QLatin1String( "UpdatedCanvas" ) ) { - return UpdatedCanvas; + return Qgis::RasterRangeExtent::UpdatedCanvas; } else { - return WholeRaster; + return Qgis::RasterRangeExtent::WholeRaster; } } -QString QgsRasterMinMaxOrigin::statAccuracyString( StatAccuracy accuracy ) +QString QgsRasterMinMaxOrigin::statAccuracyString( Qgis::RasterRangeAccuracy accuracy ) { - if ( accuracy == Exact ) - return QStringLiteral( "Exact" ); - return QStringLiteral( "Estimated" ); + switch ( accuracy ) + { + case Qgis::RasterRangeAccuracy::Exact: + return QStringLiteral( "Exact" ); + case Qgis::RasterRangeAccuracy::Estimated: + return QStringLiteral( "Estimated" ); + } + BUILTIN_UNREACHABLE } -QgsRasterMinMaxOrigin::StatAccuracy QgsRasterMinMaxOrigin::statAccuracyFromString( const QString &accuracy ) +Qgis::RasterRangeAccuracy QgsRasterMinMaxOrigin::statAccuracyFromString( const QString &accuracy ) { if ( accuracy == QLatin1String( "Exact" ) ) - return Exact; - return Estimated; + return Qgis::RasterRangeAccuracy::Exact; + return Qgis::RasterRangeAccuracy::Estimated; } void QgsRasterMinMaxOrigin::writeXml( QDomDocument &doc, QDomElement &parentElem ) const diff --git a/src/core/raster/qgsrasterminmaxorigin.h b/src/core/raster/qgsrasterminmaxorigin.h index 4df73f6dce43..c574d17b7bd0 100644 --- a/src/core/raster/qgsrasterminmaxorigin.h +++ b/src/core/raster/qgsrasterminmaxorigin.h @@ -23,6 +23,7 @@ #include #include "qgis_core.h" +#include "qgis.h" /** * \ingroup core @@ -43,46 +44,6 @@ class CORE_EXPORT QgsRasterMinMaxOrigin //! \brief Default standard deviation factor static constexpr double DEFAULT_STDDEV_FACTOR = 2.0; -#ifdef SIP_RUN - //! \brief This enumerator describes the limits used to compute min/max values - enum Limits - { - None SIP_PYNAME( None_ ), //!< User defined. - MinMax, //!< Real min-max values - StdDev, //!< Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ] - CumulativeCut //!< Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ] - }; -#else - //! \brief This enumerator describes the limits used to compute min/max values - enum Limits - { - None, //!< User defined. - MinMax, //!< Real min-max values - StdDev, //!< Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ] - CumulativeCut //!< Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ] - }; -#endif - - //! \brief This enumerator describes the extent used to compute min/max values - enum Extent - { - //! Whole raster is used to compute statistics. - WholeRaster, - //! Current extent of the canvas (at the time of computation) is used to compute statistics. - CurrentCanvas, - //! Constantly updated extent of the canvas is used to compute statistics. - UpdatedCanvas - }; - - //! \brief This enumerator describes the accuracy used to compute statistics. - enum StatAccuracy - { - //! Exact statistics. - Exact, - //! Approximated statistics. - Estimated - }; - QgsRasterMinMaxOrigin(); bool operator ==( const QgsRasterMinMaxOrigin &other ) const; @@ -90,13 +51,13 @@ class CORE_EXPORT QgsRasterMinMaxOrigin //////// Getter methods ///////////////////// //! Returns the raster limits. - QgsRasterMinMaxOrigin::Limits limits() const { return mLimits; } + Qgis::RasterRangeLimit limits() const { return mLimits; } //! Returns the raster extent. - QgsRasterMinMaxOrigin::Extent extent() const { return mExtent; } + Qgis::RasterRangeExtent extent() const { return mExtent; } //! Returns the raster statistic accuracy. - QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const { return mAccuracy; } + Qgis::RasterRangeAccuracy statAccuracy() const { return mAccuracy; } //! Returns the lower bound of cumulative cut method (between 0 and 1). double cumulativeCutLower() const { return mCumulativeCutLower; } @@ -110,13 +71,13 @@ class CORE_EXPORT QgsRasterMinMaxOrigin //////// Setter methods ///////////////////// //! Sets the limits. - void setLimits( QgsRasterMinMaxOrigin::Limits limits ) { mLimits = limits; } + void setLimits( Qgis::RasterRangeLimit limits ) { mLimits = limits; } //! Sets the extent. - void setExtent( QgsRasterMinMaxOrigin::Extent extent ) { mExtent = extent; } + void setExtent( Qgis::RasterRangeExtent extent ) { mExtent = extent; } //! Sets the statistics accuracy. - void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy ) { mAccuracy = accuracy; } + void setStatAccuracy( Qgis::RasterRangeAccuracy accuracy ) { mAccuracy = accuracy; } //! Sets the lower bound of cumulative cut method (between 0 and 1). void setCumulativeCutLower( double val ) { mCumulativeCutLower = val; } @@ -138,28 +99,28 @@ class CORE_EXPORT QgsRasterMinMaxOrigin //////// Static methods ///////////////////// //! Returns a string to serialize Limits - static QString limitsString( Limits limits ); + static QString limitsString( Qgis::RasterRangeLimit limits ); //! \brief Deserialize Limits - static Limits limitsFromString( const QString &limits ); + static Qgis::RasterRangeLimit limitsFromString( const QString &limits ); //! Returns a string to serialize Extent - static QString extentString( QgsRasterMinMaxOrigin::Extent extent ); + static QString extentString( Qgis::RasterRangeExtent extent ); //! \brief Deserialize Extent - static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent ); + static Qgis::RasterRangeExtent extentFromString( const QString &extent ); //! Returns a string to serialize StatAccuracy - static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy ); + static QString statAccuracyString( Qgis::RasterRangeAccuracy accuracy ); //! \brief Deserialize StatAccuracy - static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy ); + static Qgis::RasterRangeAccuracy statAccuracyFromString( const QString &accuracy ); private: - Limits mLimits = None; - Extent mExtent = WholeRaster; - StatAccuracy mAccuracy = Estimated; + Qgis::RasterRangeLimit mLimits = Qgis::RasterRangeLimit::NotSet; + Qgis::RasterRangeExtent mExtent = Qgis::RasterRangeExtent::WholeRaster; + Qgis::RasterRangeAccuracy mAccuracy = Qgis::RasterRangeAccuracy::Estimated; double mCumulativeCutLower; double mCumulativeCutUpper; double mStdDevFactor; diff --git a/src/core/raster/qgsrasterrenderer.cpp b/src/core/raster/qgsrasterrenderer.cpp index 287d8ad4d0ee..f9af061c1e03 100644 --- a/src/core/raster/qgsrasterrenderer.cpp +++ b/src/core/raster/qgsrasterrenderer.cpp @@ -248,8 +248,8 @@ bool QgsRasterRenderer::accept( QgsStyleEntityVisitorInterface * ) const bool QgsRasterRenderer::needsRefresh( const QgsRectangle &extent ) const { if ( mLastRectangleUsedByRefreshContrastEnhancementIfNeeded != extent && - mMinMaxOrigin.limits() != QgsRasterMinMaxOrigin::None && - mMinMaxOrigin.extent() == QgsRasterMinMaxOrigin::UpdatedCanvas ) + mMinMaxOrigin.limits() != Qgis::RasterRangeLimit::NotSet && + mMinMaxOrigin.extent() == Qgis::RasterRangeExtent::UpdatedCanvas ) { return true; } diff --git a/src/core/raster/qgssinglebandpseudocolorrenderer.cpp b/src/core/raster/qgssinglebandpseudocolorrenderer.cpp index faeb463d37cd..e203fd2aa034 100644 --- a/src/core/raster/qgssinglebandpseudocolorrenderer.cpp +++ b/src/core/raster/qgssinglebandpseudocolorrenderer.cpp @@ -165,41 +165,41 @@ QgsRasterRenderer *QgsSingleBandPseudoColorRenderer::create( const QDomElement & { if ( minMaxOrigin.contains( QLatin1String( "MinMax" ) ) ) { - r->mMinMaxOrigin.setLimits( QgsRasterMinMaxOrigin::MinMax ); + r->mMinMaxOrigin.setLimits( Qgis::RasterRangeLimit::MinimumMaximum ); } else if ( minMaxOrigin.contains( QLatin1String( "CumulativeCut" ) ) ) { - r->mMinMaxOrigin.setLimits( QgsRasterMinMaxOrigin::CumulativeCut ); + r->mMinMaxOrigin.setLimits( Qgis::RasterRangeLimit::CumulativeCut ); } else if ( minMaxOrigin.contains( QLatin1String( "StdDev" ) ) ) { - r->mMinMaxOrigin.setLimits( QgsRasterMinMaxOrigin::StdDev ); + r->mMinMaxOrigin.setLimits( Qgis::RasterRangeLimit::StdDev ); } else { - r->mMinMaxOrigin.setLimits( QgsRasterMinMaxOrigin::None ); + r->mMinMaxOrigin.setLimits( Qgis::RasterRangeLimit::NotSet ); } if ( minMaxOrigin.contains( QLatin1String( "FullExtent" ) ) ) { - r->mMinMaxOrigin.setExtent( QgsRasterMinMaxOrigin::WholeRaster ); + r->mMinMaxOrigin.setExtent( Qgis::RasterRangeExtent::WholeRaster ); } else if ( minMaxOrigin.contains( QLatin1String( "SubExtent" ) ) ) { - r->mMinMaxOrigin.setExtent( QgsRasterMinMaxOrigin::CurrentCanvas ); + r->mMinMaxOrigin.setExtent( Qgis::RasterRangeExtent::FixedCanvas ); } else { - r->mMinMaxOrigin.setExtent( QgsRasterMinMaxOrigin::WholeRaster ); + r->mMinMaxOrigin.setExtent( Qgis::RasterRangeExtent::WholeRaster ); } if ( minMaxOrigin.contains( QLatin1String( "Estimated" ) ) ) { - r->mMinMaxOrigin.setStatAccuracy( QgsRasterMinMaxOrigin::Estimated ); + r->mMinMaxOrigin.setStatAccuracy( Qgis::RasterRangeAccuracy::Estimated ); } else // if ( minMaxOrigin.contains( QLatin1String( "Exact" ) ) ) { - r->mMinMaxOrigin.setStatAccuracy( QgsRasterMinMaxOrigin::Exact ); + r->mMinMaxOrigin.setStatAccuracy( Qgis::RasterRangeAccuracy::Exact ); } } diff --git a/src/gui/raster/qgsrasterminmaxwidget.cpp b/src/gui/raster/qgsrasterminmaxwidget.cpp index b988aca7078e..dcaacae1776b 100644 --- a/src/gui/raster/qgsrasterminmaxwidget.cpp +++ b/src/gui/raster/qgsrasterminmaxwidget.cpp @@ -103,34 +103,34 @@ void QgsRasterMinMaxWidget::setFromMinMaxOrigin( const QgsRasterMinMaxOrigin &mi { switch ( minMaxOrigin.limits() ) { - case QgsRasterMinMaxOrigin::None: + case Qgis::RasterRangeLimit::NotSet: mUserDefinedRadioButton->setChecked( true ); break; - case QgsRasterMinMaxOrigin::MinMax: + case Qgis::RasterRangeLimit::MinimumMaximum: mMinMaxRadioButton->setChecked( true ); break; - case QgsRasterMinMaxOrigin::StdDev: + case Qgis::RasterRangeLimit::StdDev: mStdDevRadioButton->setChecked( true ); break; - case QgsRasterMinMaxOrigin::CumulativeCut: + case Qgis::RasterRangeLimit::CumulativeCut: mCumulativeCutRadioButton->setChecked( true ); break; } switch ( minMaxOrigin.extent() ) { - case QgsRasterMinMaxOrigin::WholeRaster: + case Qgis::RasterRangeExtent::WholeRaster: mStatisticsExtentCombo->setCurrentIndex( IDX_WHOLE_RASTER ); break; - case QgsRasterMinMaxOrigin::CurrentCanvas: + case Qgis::RasterRangeExtent::FixedCanvas: mStatisticsExtentCombo->setCurrentIndex( IDX_CURRENT_CANVAS ); break; - case QgsRasterMinMaxOrigin::UpdatedCanvas: + case Qgis::RasterRangeExtent::UpdatedCanvas: mStatisticsExtentCombo->setCurrentIndex( IDX_UPDATED_CANVAS ); break; } @@ -139,7 +139,7 @@ void QgsRasterMinMaxWidget::setFromMinMaxOrigin( const QgsRasterMinMaxOrigin &mi mCumulativeCutUpperDoubleSpinBox->setValue( 100.0 * minMaxOrigin.cumulativeCutUpper() ); mStdDevSpinBox->setValue( minMaxOrigin.stdDevFactor() ); - cboAccuracy->setCurrentIndex( minMaxOrigin.statAccuracy() == QgsRasterMinMaxOrigin::Estimated ? 0 : 1 ); + cboAccuracy->setCurrentIndex( minMaxOrigin.statAccuracy() == Qgis::RasterRangeAccuracy::Estimated ? 0 : 1 ); } QgsRasterMinMaxOrigin QgsRasterMinMaxWidget::minMaxOrigin() @@ -147,32 +147,32 @@ QgsRasterMinMaxOrigin QgsRasterMinMaxWidget::minMaxOrigin() QgsRasterMinMaxOrigin minMaxOrigin; if ( mMinMaxRadioButton->isChecked() ) - minMaxOrigin.setLimits( QgsRasterMinMaxOrigin::MinMax ); + minMaxOrigin.setLimits( Qgis::RasterRangeLimit::MinimumMaximum ); else if ( mStdDevRadioButton->isChecked() ) - minMaxOrigin.setLimits( QgsRasterMinMaxOrigin::StdDev ); + minMaxOrigin.setLimits( Qgis::RasterRangeLimit::StdDev ); else if ( mCumulativeCutRadioButton->isChecked() ) - minMaxOrigin.setLimits( QgsRasterMinMaxOrigin::CumulativeCut ); + minMaxOrigin.setLimits( Qgis::RasterRangeLimit::CumulativeCut ); else - minMaxOrigin.setLimits( QgsRasterMinMaxOrigin::None ); + minMaxOrigin.setLimits( Qgis::RasterRangeLimit::NotSet ); switch ( mStatisticsExtentCombo->currentIndex() ) { case IDX_WHOLE_RASTER: default: - minMaxOrigin.setExtent( QgsRasterMinMaxOrigin::WholeRaster ); + minMaxOrigin.setExtent( Qgis::RasterRangeExtent::WholeRaster ); break; case IDX_CURRENT_CANVAS: - minMaxOrigin.setExtent( QgsRasterMinMaxOrigin::CurrentCanvas ); + minMaxOrigin.setExtent( Qgis::RasterRangeExtent::FixedCanvas ); break; case IDX_UPDATED_CANVAS: - minMaxOrigin.setExtent( QgsRasterMinMaxOrigin::UpdatedCanvas ); + minMaxOrigin.setExtent( Qgis::RasterRangeExtent::UpdatedCanvas ); break; } if ( cboAccuracy->currentIndex() == 0 ) - minMaxOrigin.setStatAccuracy( QgsRasterMinMaxOrigin::Estimated ); + minMaxOrigin.setStatAccuracy( Qgis::RasterRangeAccuracy::Estimated ); else - minMaxOrigin.setStatAccuracy( QgsRasterMinMaxOrigin::Exact ); + minMaxOrigin.setStatAccuracy( Qgis::RasterRangeAccuracy::Exact ); minMaxOrigin.setCumulativeCutLower( mCumulativeCutLowerDoubleSpinBox->value() / 100.0 ); diff --git a/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp b/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp index d70d8ff4a634..e35031cb54b9 100644 --- a/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp +++ b/src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp @@ -23,17 +23,10 @@ #include "qgsrastershader.h" #include "qgsrasterminmaxwidget.h" #include "qgsdoublevalidator.h" -#include "qgstreewidgetitem.h" #include "qgssettings.h" #include "qgsmapcanvas.h" #include "qgsguiutils.h" -// for color ramps - todo add rasterStyle and refactor raster vs. vector ramps -#include "qgsstyle.h" -#include "qgscolorramp.h" -#include "qgscolorrampbutton.h" -#include "qgscolordialog.h" - #include #include #include @@ -94,9 +87,9 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() ) { QgsRasterMinMaxOrigin minMaxOrigin = mMinMaxWidget->minMaxOrigin(); - if ( minMaxOrigin.limits() == QgsRasterMinMaxOrigin::None ) + if ( minMaxOrigin.limits() == Qgis::RasterRangeLimit::NotSet ) { - minMaxOrigin.setLimits( QgsRasterMinMaxOrigin::MinMax ); + minMaxOrigin.setLimits( Qgis::RasterRangeLimit::MinimumMaximum ); mMinMaxWidget->setFromMinMaxOrigin( minMaxOrigin ); } mMinMaxWidget->doComputations(); diff --git a/tests/src/core/testqgsrasterlayer.cpp b/tests/src/core/testqgsrasterlayer.cpp index 3f768b1971eb..824c52c0e0e1 100644 --- a/tests/src/core/testqgsrasterlayer.cpp +++ b/tests/src/core/testqgsrasterlayer.cpp @@ -197,7 +197,7 @@ void TestQgsRasterLayer::cleanupTestCase() void TestQgsRasterLayer::isValid() { QVERIFY( mpRasterLayer->isValid() ); - mpRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax ); + mpRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, Qgis::RasterRangeLimit::MinimumMaximum ); mMapSettings->setExtent( mpRasterLayer->extent() ); QVERIFY( render( "raster" ) ); } @@ -346,7 +346,7 @@ void TestQgsRasterLayer::colorRamp4() void TestQgsRasterLayer::landsatBasic() { QVERIFY2( mpLandsatRasterLayer->isValid(), "landsat.tif layer is not valid!" ); - mpLandsatRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax ); + mpLandsatRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, Qgis::RasterRangeLimit::MinimumMaximum ); mMapSettings->setLayers( QList() << mpLandsatRasterLayer ); mMapSettings->setDestinationCrs( mpLandsatRasterLayer->crs() ); mMapSettings->setExtent( mpLandsatRasterLayer->extent() ); @@ -652,7 +652,7 @@ void TestQgsRasterLayer::transparency() QVERIFY( mpFloat32RasterLayer->isValid() ); QgsSingleBandGrayRenderer *renderer = new QgsSingleBandGrayRenderer( mpRasterLayer->dataProvider(), 1 ); mpFloat32RasterLayer->setRenderer( renderer ); - mpFloat32RasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax ); + mpFloat32RasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, Qgis::RasterRangeLimit::MinimumMaximum ); qDebug( "contrastEnhancement.minimumValue = %.17g", renderer->contrastEnhancement()->minimumValue() ); qDebug( "contrastEnhancement.maximumValue = %.17g", renderer->contrastEnhancement()->maximumValue() ); @@ -1004,7 +1004,7 @@ void TestQgsRasterLayer::regression992() void TestQgsRasterLayer::testRefreshRendererIfNeeded() { QVERIFY2( mpLandsatRasterLayer->isValid(), "landsat.tif layer is not valid!" ); - mpLandsatRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, QgsRasterMinMaxOrigin::MinMax ); + mpLandsatRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, Qgis::RasterRangeLimit::MinimumMaximum ); QVERIFY( dynamic_cast( mpLandsatRasterLayer->renderer() ) ); mMapSettings->setLayers( QList() << mpLandsatRasterLayer ); mMapSettings->setExtent( mpLandsatRasterLayer->extent() ); @@ -1021,10 +1021,10 @@ void TestQgsRasterLayer::testRefreshRendererIfNeeded() // Change to UpdatedCanvas QgsRasterMinMaxOrigin mmo = mpLandsatRasterLayer->renderer()->minMaxOrigin(); - mmo.setExtent( QgsRasterMinMaxOrigin::UpdatedCanvas ); - mmo.setStatAccuracy( QgsRasterMinMaxOrigin::Exact ); + mmo.setExtent( Qgis::RasterRangeExtent::UpdatedCanvas ); + mmo.setStatAccuracy( Qgis::RasterRangeAccuracy::Exact ); mpLandsatRasterLayer->renderer()->setMinMaxOrigin( mmo ); - QCOMPARE( mpLandsatRasterLayer->renderer()->minMaxOrigin().extent(), QgsRasterMinMaxOrigin::UpdatedCanvas ); + QCOMPARE( mpLandsatRasterLayer->renderer()->minMaxOrigin().extent(), Qgis::RasterRangeExtent::UpdatedCanvas ); QVERIFY( mpLandsatRasterLayer->renderer()->needsRefresh( newExtent ) ); QList minValues; From 648d53da47eff611f600928c8d29f4e9b7fed4d1 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 29 Nov 2024 10:00:37 +1000 Subject: [PATCH 2/2] Modernize combobox handling --- src/gui/raster/qgsrasterminmaxwidget.cpp | 65 +++++++++--------------- src/ui/qgsrasterminmaxwidgetbase.ui | 33 ++---------- 2 files changed, 26 insertions(+), 72 deletions(-) diff --git a/src/gui/raster/qgsrasterminmaxwidget.cpp b/src/gui/raster/qgsrasterminmaxwidget.cpp index dcaacae1776b..8d594f23de9d 100644 --- a/src/gui/raster/qgsrasterminmaxwidget.cpp +++ b/src/gui/raster/qgsrasterminmaxwidget.cpp @@ -26,10 +26,6 @@ #include "qgsrasterminmaxorigin.h" #include "qgsdoublespinbox.h" -const int IDX_WHOLE_RASTER = 0; -const int IDX_CURRENT_CANVAS = 1; -const int IDX_UPDATED_CANVAS = 2; - QgsRasterMinMaxWidget::QgsRasterMinMaxWidget( QgsRasterLayer *layer, QWidget *parent ) : QWidget( parent ) , mLayer( layer ) @@ -39,6 +35,13 @@ QgsRasterMinMaxWidget::QgsRasterMinMaxWidget( QgsRasterLayer *layer, QWidget *pa QgsDebugMsgLevel( QStringLiteral( "Entered." ), 4 ); setupUi( this ); + mStatisticsExtentCombo->addItem( tr( "Whole Raster" ), QVariant::fromValue( Qgis::RasterRangeExtent::WholeRaster ) ); + mStatisticsExtentCombo->addItem( tr( "Current Canvas" ), QVariant::fromValue( Qgis::RasterRangeExtent::FixedCanvas ) ); + mStatisticsExtentCombo->addItem( tr( "Updated Canvas" ), QVariant::fromValue( Qgis::RasterRangeExtent::UpdatedCanvas ) ); + + cboAccuracy->addItem( tr( "Estimate (faster)" ), QVariant::fromValue( Qgis::RasterRangeAccuracy::Estimated ) ); + cboAccuracy->addItem( tr( "Actual (slower)" ), QVariant::fromValue( Qgis::RasterRangeAccuracy::Exact ) ); + // use maximum value as a clear value for the upper border of the cumulative cut mCumulativeCutUpperDoubleSpinBox->setClearValueMode( QgsDoubleSpinBox::MaximumValue ); @@ -74,9 +77,16 @@ void QgsRasterMinMaxWidget::setBands( const QList &bands ) QgsRectangle QgsRasterMinMaxWidget::extent() { - const int nExtentIdx = mStatisticsExtentCombo->currentIndex(); - if ( nExtentIdx != IDX_CURRENT_CANVAS && nExtentIdx != IDX_UPDATED_CANVAS ) - return QgsRectangle(); + const Qgis::RasterRangeExtent extentType = mStatisticsExtentCombo->currentData().value< Qgis::RasterRangeExtent >(); + switch ( extentType ) + { + case Qgis::RasterRangeExtent::WholeRaster: + return QgsRectangle(); + + case Qgis::RasterRangeExtent::FixedCanvas: + case Qgis::RasterRangeExtent::UpdatedCanvas: + break; + } if ( mLayer && mCanvas ) return mCanvas->mapSettings().outputExtentToLayerExtent( mLayer, mCanvas->extent() ); @@ -89,7 +99,7 @@ QgsRectangle QgsRasterMinMaxWidget::extent() void QgsRasterMinMaxWidget::userHasSetManualMinMaxValues() { mUserDefinedRadioButton->setChecked( true ); - mStatisticsExtentCombo->setCurrentIndex( IDX_WHOLE_RASTER ); + mStatisticsExtentCombo->setCurrentIndex( mStatisticsExtentCombo->findData( QVariant::fromValue( Qgis::RasterRangeExtent::WholeRaster ) ) ); } void QgsRasterMinMaxWidget::mUserDefinedRadioButton_toggled( bool toggled ) @@ -120,26 +130,13 @@ void QgsRasterMinMaxWidget::setFromMinMaxOrigin( const QgsRasterMinMaxOrigin &mi break; } - switch ( minMaxOrigin.extent() ) - { - case Qgis::RasterRangeExtent::WholeRaster: - mStatisticsExtentCombo->setCurrentIndex( IDX_WHOLE_RASTER ); - break; - - case Qgis::RasterRangeExtent::FixedCanvas: - mStatisticsExtentCombo->setCurrentIndex( IDX_CURRENT_CANVAS ); - break; - - case Qgis::RasterRangeExtent::UpdatedCanvas: - mStatisticsExtentCombo->setCurrentIndex( IDX_UPDATED_CANVAS ); - break; - } + mStatisticsExtentCombo->setCurrentIndex( mStatisticsExtentCombo->findData( QVariant::fromValue( minMaxOrigin.extent() ) ) ); mCumulativeCutLowerDoubleSpinBox->setValue( 100.0 * minMaxOrigin.cumulativeCutLower() ); mCumulativeCutUpperDoubleSpinBox->setValue( 100.0 * minMaxOrigin.cumulativeCutUpper() ); mStdDevSpinBox->setValue( minMaxOrigin.stdDevFactor() ); - cboAccuracy->setCurrentIndex( minMaxOrigin.statAccuracy() == Qgis::RasterRangeAccuracy::Estimated ? 0 : 1 ); + cboAccuracy->setCurrentIndex( cboAccuracy->findData( QVariant::fromValue( minMaxOrigin.statAccuracy() ) ) ); } QgsRasterMinMaxOrigin QgsRasterMinMaxWidget::minMaxOrigin() @@ -155,24 +152,8 @@ QgsRasterMinMaxOrigin QgsRasterMinMaxWidget::minMaxOrigin() else minMaxOrigin.setLimits( Qgis::RasterRangeLimit::NotSet ); - switch ( mStatisticsExtentCombo->currentIndex() ) - { - case IDX_WHOLE_RASTER: - default: - minMaxOrigin.setExtent( Qgis::RasterRangeExtent::WholeRaster ); - break; - case IDX_CURRENT_CANVAS: - minMaxOrigin.setExtent( Qgis::RasterRangeExtent::FixedCanvas ); - break; - case IDX_UPDATED_CANVAS: - minMaxOrigin.setExtent( Qgis::RasterRangeExtent::UpdatedCanvas ); - break; - } - - if ( cboAccuracy->currentIndex() == 0 ) - minMaxOrigin.setStatAccuracy( Qgis::RasterRangeAccuracy::Estimated ); - else - minMaxOrigin.setStatAccuracy( Qgis::RasterRangeAccuracy::Exact ); + minMaxOrigin.setExtent( mStatisticsExtentCombo->currentData().value< Qgis::RasterRangeExtent >() ); + minMaxOrigin.setStatAccuracy( cboAccuracy->currentData().value< Qgis::RasterRangeAccuracy >() ); minMaxOrigin.setCumulativeCutLower( mCumulativeCutLowerDoubleSpinBox->value() / 100.0 ); @@ -248,5 +229,5 @@ void QgsRasterMinMaxWidget::doComputations() void QgsRasterMinMaxWidget::hideUpdatedExtent() { - mStatisticsExtentCombo->removeItem( IDX_UPDATED_CANVAS ); + mStatisticsExtentCombo->removeItem( mStatisticsExtentCombo->findData( QVariant::fromValue( Qgis::RasterRangeExtent::UpdatedCanvas ) ) ); } diff --git a/src/ui/qgsrasterminmaxwidgetbase.ui b/src/ui/qgsrasterminmaxwidgetbase.ui index c7fde068fe73..07dca42c493e 100644 --- a/src/ui/qgsrasterminmaxwidgetbase.ui +++ b/src/ui/qgsrasterminmaxwidgetbase.ui @@ -7,7 +7,7 @@ 0 0 324 - 252 + 261 @@ -165,37 +165,10 @@ standard de&viation × - - - - Whole raster - - - - - Current canvas - - - - - Updated canvas - - - + - - - - Estimate (faster) - - - - - Actual (slower) - - - +