Skip to content

Commit

Permalink
Modernize combobox handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 29, 2024
1 parent bb6919a commit c31d4dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 72 deletions.
65 changes: 23 additions & 42 deletions src/gui/raster/qgsrasterminmaxwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 );

Expand Down Expand Up @@ -74,9 +77,16 @@ void QgsRasterMinMaxWidget::setBands( const QList<int> &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() );
Expand All @@ -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 )
Expand Down Expand Up @@ -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()
Expand All @@ -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 );
Expand Down Expand Up @@ -248,5 +229,5 @@ void QgsRasterMinMaxWidget::doComputations()

void QgsRasterMinMaxWidget::hideUpdatedExtent()
{
mStatisticsExtentCombo->removeItem( IDX_UPDATED_CANVAS );
mStatisticsExtentCombo->removeItem( mStatisticsExtentCombo->findData( QVariant::fromValue( Qgis::RasterRangeExtent::UpdatedCanvas ) ) );
}
33 changes: 3 additions & 30 deletions src/ui/qgsrasterminmaxwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>324</width>
<height>252</height>
<height>261</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -165,37 +165,10 @@ standard de&amp;viation ×</string>
</widget>
</item>
<item row="4" column="1" colspan="3">
<widget class="QComboBox" name="mStatisticsExtentCombo">
<item>
<property name="text">
<string>Whole raster</string>
</property>
</item>
<item>
<property name="text">
<string>Current canvas</string>
</property>
</item>
<item>
<property name="text">
<string>Updated canvas</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="mStatisticsExtentCombo"/>
</item>
<item row="5" column="1" colspan="3">
<widget class="QComboBox" name="cboAccuracy">
<item>
<property name="text">
<string>Estimate (faster)</string>
</property>
</item>
<item>
<property name="text">
<string>Actual (slower)</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="cboAccuracy"/>
</item>
</layout>
</item>
Expand Down

0 comments on commit c31d4dc

Please sign in to comment.