Skip to content

Commit bd28407

Browse files
committedDec 2, 2020
Auto set nice ranges for point cloud RGB renderers after selecting attributes
1 parent 9822fe0 commit bd28407

File tree

2 files changed

+79
-6
lines changed

2 files changed

+79
-6
lines changed
 

‎src/gui/pointcloud/qgspointcloudrgbrendererwidget.cpp

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,20 @@ QgsPointCloudRgbRendererWidget::QgsPointCloudRgbRendererWidget( QgsPointCloudLay
5555
}
5656

5757
connect( mRedAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
58-
this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
58+
this, &QgsPointCloudRgbRendererWidget::redAttributeChanged );
5959
connect( mGreenAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
60-
this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
60+
this, &QgsPointCloudRgbRendererWidget::greenAttributeChanged );
6161
connect( mBlueAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged,
62-
this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
62+
this, &QgsPointCloudRgbRendererWidget::blueAttributeChanged );
6363
connect( mContrastEnhancementAlgorithmComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsPointCloudRgbRendererWidget::emitWidgetChanged );
64+
65+
if ( layer )
66+
{
67+
// set nice initial values
68+
redAttributeChanged();
69+
greenAttributeChanged();
70+
blueAttributeChanged();
71+
}
6472
}
6573

6674
QgsPointCloudRendererWidget *QgsPointCloudRgbRendererWidget::create( QgsPointCloudLayer *layer, QgsStyle *style, QgsPointCloudRenderer * )
@@ -200,6 +208,66 @@ void QgsPointCloudRgbRendererWidget::emitWidgetChanged()
200208
emit widgetChanged();
201209
}
202210

211+
void QgsPointCloudRgbRendererWidget::redAttributeChanged()
212+
{
213+
if ( mLayer && mLayer->dataProvider() )
214+
{
215+
const QVariant max = mLayer->dataProvider()->metadataStatistic( mRedAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Max );
216+
if ( max.isValid() )
217+
{
218+
const int maxValue = max.toInt();
219+
mDisableMinMaxWidgetRefresh++;
220+
mRedMinLineEdit->setText( QLocale().toString( 0 ) );
221+
222+
// 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
223+
// likely to be 8 bit or 16 bit color values
224+
mRedMaxLineEdit->setText( QLocale().toString( maxValue > 255 ? 65024 : 255 ) );
225+
mDisableMinMaxWidgetRefresh--;
226+
emitWidgetChanged();
227+
}
228+
}
229+
}
230+
231+
void QgsPointCloudRgbRendererWidget::greenAttributeChanged()
232+
{
233+
if ( mLayer && mLayer->dataProvider() )
234+
{
235+
const QVariant max = mLayer->dataProvider()->metadataStatistic( mGreenAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Max );
236+
if ( max.isValid() )
237+
{
238+
const int maxValue = max.toInt();
239+
mDisableMinMaxWidgetRefresh++;
240+
mGreenMinLineEdit->setText( QLocale().toString( 0 ) );
241+
242+
// 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
243+
// likely to be 8 bit or 16 bit color values
244+
mGreenMaxLineEdit->setText( QLocale().toString( maxValue > 255 ? 65024 : 255 ) );
245+
mDisableMinMaxWidgetRefresh--;
246+
emitWidgetChanged();
247+
}
248+
}
249+
}
250+
251+
void QgsPointCloudRgbRendererWidget::blueAttributeChanged()
252+
{
253+
if ( mLayer && mLayer->dataProvider() )
254+
{
255+
const QVariant max = mLayer->dataProvider()->metadataStatistic( mBlueAttributeComboBox->currentAttribute(), QgsStatisticalSummary::Max );
256+
if ( max.isValid() )
257+
{
258+
const int maxValue = max.toInt();
259+
mDisableMinMaxWidgetRefresh++;
260+
mBlueMinLineEdit->setText( QLocale().toString( 0 ) );
261+
262+
// 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
263+
// likely to be 8 bit or 16 bit color values
264+
mBlueMaxLineEdit->setText( QLocale().toString( maxValue > 255 ? 65024 : 255 ) );
265+
mDisableMinMaxWidgetRefresh--;
266+
emitWidgetChanged();
267+
}
268+
}
269+
}
270+
203271
void QgsPointCloudRgbRendererWidget::minMaxModified()
204272
{
205273
if ( !mDisableMinMaxWidgetRefresh )
@@ -246,11 +314,11 @@ void QgsPointCloudRgbRendererWidget::setFromRenderer( const QgsPointCloudRendere
246314
mGreenAttributeComboBox->setAttribute( mbcr->greenAttribute() );
247315
mBlueAttributeComboBox->setAttribute( mbcr->blueAttribute() );
248316

249-
mDisableMinMaxWidgetRefresh = true;
317+
mDisableMinMaxWidgetRefresh++;
250318
setMinMaxValue( mbcr->redContrastEnhancement(), mRedMinLineEdit, mRedMaxLineEdit );
251319
setMinMaxValue( mbcr->greenContrastEnhancement(), mGreenMinLineEdit, mGreenMaxLineEdit );
252320
setMinMaxValue( mbcr->blueContrastEnhancement(), mBlueMinLineEdit, mBlueMaxLineEdit );
253-
mDisableMinMaxWidgetRefresh = false;
321+
mDisableMinMaxWidgetRefresh--;
254322
}
255323
else
256324
{

‎src/gui/pointcloud/qgspointcloudrgbrendererwidget.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class GUI_EXPORT QgsPointCloudRgbRendererWidget: public QgsPointCloudRendererWid
5252

5353
void emitWidgetChanged();
5454

55+
void redAttributeChanged();
56+
void greenAttributeChanged();
57+
void blueAttributeChanged();
58+
5559
private:
5660
void setFromRenderer( const QgsPointCloudRenderer *r );
5761

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

6569
bool mBlockChangedSignal = false;
66-
bool mDisableMinMaxWidgetRefresh = false;
70+
int mDisableMinMaxWidgetRefresh = 0;
71+
6772
};
6873

6974
///@endcond

0 commit comments

Comments
 (0)
Please sign in to comment.