Skip to content

Commit

Permalink
Auto set nice ranges for point cloud RGB renderers after selecting at…
Browse files Browse the repository at this point in the history
…tributes
  • Loading branch information
nyalldawson committed Dec 2, 2020
1 parent 9822fe0 commit bd28407
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 6 deletions.
78 changes: 73 additions & 5 deletions src/gui/pointcloud/qgspointcloudrgbrendererwidget.cpp
Expand Up @@ -55,12 +55,20 @@ QgsPointCloudRgbRendererWidget::QgsPointCloudRgbRendererWidget( QgsPointCloudLay
}

connect( mRedAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
this, &QgsPointCloudRgbRendererWidget::redAttributeChanged );
connect( mGreenAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
this, &QgsPointCloudRgbRendererWidget::greenAttributeChanged );
connect( mBlueAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
this, &QgsPointCloudRgbRendererWidget::blueAttributeChanged );
connect( mContrastEnhancementAlgorithmComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );

if ( layer )
{
// set nice initial values
redAttributeChanged();
greenAttributeChanged();
blueAttributeChanged();
}
}

QgsPointCloudRendererWidget *QgsPointCloudRgbRendererWidget::create( QgsPointCloudLayer *layer, QgsStyle *style, QgsPointCloudRenderer * )
Expand Down Expand Up @@ -200,6 +208,66 @@ void QgsPointCloudRgbRendererWidget::emitWidgetChanged()
emit widgetChanged();
}

void QgsPointCloudRgbRendererWidget::redAttributeChanged()
{
if ( mLayer && mLayer->dataProvider() )
{
const QVariant max = mLayer->dataProvider()->metadataStatistic( mRedAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Max );
if ( max.isValid() )
{
const int maxValue = max.toInt();
mDisableMinMaxWidgetRefresh++;
mRedMinLineEdit->setText( QLocale().toString( 0 ) );

// try and guess suitable range from input max values -- we don't just take the provider max value directly here, but rather see if it's
// likely to be 8 bit or 16 bit color values
mRedMaxLineEdit->setText( QLocale().toString( maxValue > 255 ? 65024 : 255 ) );
mDisableMinMaxWidgetRefresh--;
emitWidgetChanged();
}
}
}

void QgsPointCloudRgbRendererWidget::greenAttributeChanged()
{
if ( mLayer && mLayer->dataProvider() )
{
const QVariant max = mLayer->dataProvider()->metadataStatistic( mGreenAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Max );
if ( max.isValid() )
{
const int maxValue = max.toInt();
mDisableMinMaxWidgetRefresh++;
mGreenMinLineEdit->setText( QLocale().toString( 0 ) );

// try and guess suitable range from input max values -- we don't just take the provider max value directly here, but rather see if it's
// likely to be 8 bit or 16 bit color values
mGreenMaxLineEdit->setText( QLocale().toString( maxValue > 255 ? 65024 : 255 ) );
mDisableMinMaxWidgetRefresh--;
emitWidgetChanged();
}
}
}

void QgsPointCloudRgbRendererWidget::blueAttributeChanged()
{
if ( mLayer && mLayer->dataProvider() )
{
const QVariant max = mLayer->dataProvider()->metadataStatistic( mBlueAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Max );
if ( max.isValid() )
{
const int maxValue = max.toInt();
mDisableMinMaxWidgetRefresh++;
mBlueMinLineEdit->setText( QLocale().toString( 0 ) );

// try and guess suitable range from input max values -- we don't just take the provider max value directly here, but rather see if it's
// likely to be 8 bit or 16 bit color values
mBlueMaxLineEdit->setText( QLocale().toString( maxValue > 255 ? 65024 : 255 ) );
mDisableMinMaxWidgetRefresh--;
emitWidgetChanged();
}
}
}

void QgsPointCloudRgbRendererWidget::minMaxModified()
{
if ( !mDisableMinMaxWidgetRefresh )
Expand Down Expand Up @@ -246,11 +314,11 @@ void QgsPointCloudRgbRendererWidget::setFromRenderer( const QgsPointCloudRendere
mGreenAttributeComboBox->setAttribute( mbcr->greenAttribute() );
mBlueAttributeComboBox->setAttribute( mbcr->blueAttribute() );

mDisableMinMaxWidgetRefresh = true;
mDisableMinMaxWidgetRefresh++;
setMinMaxValue( mbcr->redContrastEnhancement(), mRedMinLineEdit, mRedMaxLineEdit );
setMinMaxValue( mbcr->greenContrastEnhancement(), mGreenMinLineEdit, mGreenMaxLineEdit );
setMinMaxValue( mbcr->blueContrastEnhancement(), mBlueMinLineEdit, mBlueMaxLineEdit );
mDisableMinMaxWidgetRefresh = false;
mDisableMinMaxWidgetRefresh--;
}
else
{
Expand Down
7 changes: 6 additions & 1 deletion src/gui/pointcloud/qgspointcloudrgbrendererwidget.h
Expand Up @@ -52,6 +52,10 @@ class GUI_EXPORT QgsPointCloudRgbRendererWidget: public QgsPointCloudRendererWid

void emitWidgetChanged();

void redAttributeChanged();
void greenAttributeChanged();
void blueAttributeChanged();

private:
void setFromRenderer( const QgsPointCloudRenderer *r );

Expand All @@ -63,7 +67,8 @@ class GUI_EXPORT QgsPointCloudRgbRendererWidget: public QgsPointCloudRendererWid
void minMaxModified();

bool mBlockChangedSignal = false;
bool mDisableMinMaxWidgetRefresh = false;
int mDisableMinMaxWidgetRefresh = 0;

};

///@endcond
Expand Down

0 comments on commit bd28407

Please sign in to comment.