Skip to content

Commit

Permalink
calculate reasonable number of decimals on classify
Browse files Browse the repository at this point in the history
  • Loading branch information
pierstitus authored and nyalldawson committed Jun 2, 2016
1 parent 47e178a commit 61a4c48
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,14 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
QList<double>::const_iterator value_it = entryValues.begin();
QVector<QColor>::const_iterator color_it = entryColors.begin();

// calculate a reasonable number of decimals to display
double maxabs = log10( std::max<double>( std::fabs( max ), std::fabs( min ) ) );
int nDecimals = round( std::max<double>( 3.0 + maxabs - log10( max - min ), maxabs <= 6.0 ? maxabs + 0.49 : 0.0 ) );

for ( ; value_it != entryValues.end(); ++value_it, ++color_it )
{
QgsTreeWidgetItem* newItem = new QgsTreeWidgetItem( mColormapTreeWidget );
newItem->setText( 0, QString::number( *value_it, 'g' ) );
newItem->setText( 0, QString::number( *value_it, 'g', nDecimals ) );
newItem->setBackground( 1, QBrush( *color_it ) );
newItem->setText( 2, "" );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
Expand Down

0 comments on commit 61a4c48

Please sign in to comment.