QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssinglebandpseudocolorrendererwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssinglebandpseudocolorrendererwidget.cpp
3  ------------------------------------------
4  begin : February 2012
5  copyright : (C) 2012 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
20 #include "qgsrasterlayer.h"
21 
22 // for color ramps - todo add rasterStyle and refactor raster vs. vector ramps
23 #include "qgsstylev2.h"
24 #include "qgsvectorcolorrampv2.h"
25 #include "qgscolordialog.h"
26 
27 #include <QFileDialog>
28 #include <QMessageBox>
29 #include <QSettings>
30 #include <QTextStream>
31 
33  : QgsRasterRendererWidget( layer, extent )
34  , mMinMaxWidget( NULL )
35  , mMinMaxOrigin( 0 )
36 {
37  QSettings settings;
38 
39  setupUi( this );
40 
41  mColormapTreeWidget->setColumnWidth( 1, 50 );
42 
43  QString defaultPalette = settings.value( "/Raster/defaultPalette", "Spectral" ).toString();
44 
45  mColorRampComboBox->populate( QgsStyleV2::defaultStyle() );
46 
47  QgsDebugMsg( "defaultPalette = " + defaultPalette );
48  mColorRampComboBox->setCurrentIndex( mColorRampComboBox->findText( defaultPalette ) );
49 
50  if ( !mRasterLayer )
51  {
52  return;
53  }
54 
56  if ( !provider )
57  {
58  return;
59  }
60 
61  // Must be before adding items to mBandComboBox (signal)
62  mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) );
63  mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) );
64 
65  mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
66  mMinMaxWidget->setExtent( extent );
67  QHBoxLayout *layout = new QHBoxLayout();
68  layout->setContentsMargins( 0, 0, 0, 0 );
69  mMinMaxContainerWidget->setLayout( layout );
70  layout->addWidget( mMinMaxWidget );
71  connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ),
72  this, SLOT( loadMinMax( int, double, double, int ) ) );
73 
74 
75  //fill available bands into combo box
76  int nBands = provider->bandCount();
77  for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
78  {
79  mBandComboBox->addItem( displayBandName( i ), i );
80  }
81 
82  mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 );
83  mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 );
84  mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 );
85  mColorInterpolationComboBox->setCurrentIndex( 1 );
86  mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous );
87  mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval );
88  //quantile would be nice as well
89 
90  mNumberOfEntriesSpinBox->setValue( 5 ); // some default
91 
92  setFromRenderer( layer->renderer() );
93 
94  // If there is currently no min/max, load default with user current default options
95  if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() )
96  {
97  mMinMaxWidget->load();
98  }
99 
100  on_mClassificationModeComboBox_currentIndexChanged( 0 );
101 
102  resetClassifyButton();
103 }
104 
106 {
107 }
108 
110 {
111  QgsRasterShader* rasterShader = new QgsRasterShader();
112  QgsColorRampShader* colorRampShader = new QgsColorRampShader();
113  colorRampShader->setClip( mClipCheckBox->isChecked() );
114 
115  //iterate through mColormapTreeWidget and set colormap info of layer
116  QList<QgsColorRampShader::ColorRampItem> colorRampItems;
117  int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
118  QTreeWidgetItem* currentItem;
119  for ( int i = 0; i < topLevelItemCount; ++i )
120  {
121  currentItem = mColormapTreeWidget->topLevelItem( i );
122  if ( !currentItem )
123  {
124  continue;
125  }
126  QgsColorRampShader::ColorRampItem newColorRampItem;
127  newColorRampItem.value = currentItem->text( 0 ).toDouble();
128  newColorRampItem.color = currentItem->background( 1 ).color();
129  newColorRampItem.label = currentItem->text( 2 );
130  colorRampItems.append( newColorRampItem );
131  }
132  // sort the shader items
133  qSort( colorRampItems );
134  colorRampShader->setColorRampItemList( colorRampItems );
135 
136  if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
137  {
139  }
140  else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
141  {
143  }
144  else
145  {
146  colorRampShader->setColorRampType( QgsColorRampShader::EXACT );
147  }
148  rasterShader->setRasterShaderFunction( colorRampShader );
149 
150  int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
152 
153  renderer->setClassificationMin( lineEditValue( mMinLineEdit ) );
154  renderer->setClassificationMax( lineEditValue( mMaxLineEdit ) );
155  renderer->setClassificationMinMaxOrigin( mMinMaxOrigin );
156  return renderer;
157 }
158 
159 void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_clicked()
160 {
161  QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
162  newItem->setText( 0, "0.0" );
163  newItem->setBackground( 1, QBrush( QColor( Qt::magenta ) ) );
164  newItem->setText( 2, tr( "Custom color map entry" ) );
165 }
166 
167 void QgsSingleBandPseudoColorRendererWidget::on_mDeleteEntryButton_clicked()
168 {
169  QTreeWidgetItem* currentItem = mColormapTreeWidget->currentItem();
170  if ( currentItem )
171  {
172  delete currentItem;
173  }
174 }
175 
176 void QgsSingleBandPseudoColorRendererWidget::on_mSortButton_clicked()
177 {
178  bool inserted = false;
179  int myCurrentIndex = 0;
180  int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
181  QTreeWidgetItem* myCurrentItem;
182  QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
183  for ( int i = 0; i < myTopLevelItemCount; ++i )
184  {
185  myCurrentItem = mColormapTreeWidget->topLevelItem( i );
186  //If the item is null or does not have a pixel values set, skip
187  if ( !myCurrentItem || myCurrentItem->text( 0 ) == "" )
188  {
189  continue;
190  }
191 
192  //Create a copy of the new Color ramp Item
193  QgsColorRampShader::ColorRampItem myNewColorRampItem;
194  myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble();
195  myNewColorRampItem.color = myCurrentItem->background( 1 ).color();
196  myNewColorRampItem.label = myCurrentItem->text( 2 );
197 
198  //Simple insertion sort - speed is not a huge factor here
199  inserted = false;
200  myCurrentIndex = 0;
201  while ( !inserted )
202  {
203  if ( 0 == myColorRampItems.size() || myCurrentIndex == myColorRampItems.size() )
204  {
205  myColorRampItems.push_back( myNewColorRampItem );
206  inserted = true;
207  }
208  else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
209  {
210  myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
211  inserted = true;
212  }
213  else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1 )
214  {
215  myColorRampItems.push_back( myNewColorRampItem );
216  inserted = true;
217  }
218  else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1].value > myNewColorRampItem.value )
219  {
220  myColorRampItems.insert( myCurrentIndex + 1, myNewColorRampItem );
221  inserted = true;
222  }
223  myCurrentIndex++;
224  }
225  }
226  populateColormapTreeWidget( myColorRampItems );
227 }
228 
229 void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
230 {
231  int bandComboIndex = mBandComboBox->currentIndex();
232  if ( bandComboIndex == -1 || !mRasterLayer )
233  {
234  return;
235  }
236 
237  //int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
238  //QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
239  int numberOfEntries = 0;
240 
241  QList<double> entryValues;
242  QList<QColor> entryColors;
243 
244  double min = lineEditValue( mMinLineEdit );
245  double max = lineEditValue( mMaxLineEdit );
246 
247  QgsVectorColorRampV2* colorRamp = mColorRampComboBox->currentColorRamp();
248 
249  if ( mClassificationModeComboBox->itemData( mClassificationModeComboBox->currentIndex() ).toInt() == Continuous )
250  {
251  if ( colorRamp )
252  {
253  numberOfEntries = colorRamp->count();
254  for ( int i = 0; i < colorRamp->count(); ++i )
255  {
256  double value = colorRamp->value( i );
257  entryValues.push_back( min + value * ( max - min ) );
258  }
259  }
260  }
261  else // EqualInterval
262  {
263  numberOfEntries = mNumberOfEntriesSpinBox->value();
264  //double currentValue = myRasterBandStats.minimumValue;
265  double currentValue = min;
266  double intervalDiff;
267  if ( numberOfEntries > 1 )
268  {
269  //because the highest value is also an entry, there are (numberOfEntries - 1)
270  //intervals
271  //intervalDiff = ( myRasterBandStats.maximumValue - myRasterBandStats.minimumValue ) /
272  intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
273  }
274  else
275  {
276  //intervalDiff = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
277  intervalDiff = max - min;
278  }
279 
280  for ( int i = 0; i < numberOfEntries; ++i )
281  {
282  entryValues.push_back( currentValue );
283  currentValue += intervalDiff;
284  }
285  }
286 
287 #if 0
288  //hard code color range from blue -> red for now. Allow choice of ramps in future
289  int colorDiff = 0;
290  if ( numberOfEntries != 0 )
291  {
292  colorDiff = ( int )( 255 / numberOfEntries );
293  }
294  for ( int i = 0; i < numberOfEntries; ++i )
295  {
296  QColor currentColor;
297  currentColor.setRgb( colorDiff*i, 0, 255 - colorDiff * i );
298  entryColors.push_back( currentColor );
299  }
300 #endif
301 
302  if ( ! colorRamp )
303  {
304  //hard code color range from blue -> red (previous default)
305  int colorDiff = 0;
306  if ( numberOfEntries != 0 )
307  {
308  colorDiff = ( int )( 255 / numberOfEntries );
309  }
310 
311  for ( int i = 0; i < numberOfEntries; ++i )
312  {
313  QColor currentColor;
314  int idx = mInvertCheckBox->isChecked() ? numberOfEntries - i - 1 : i;
315  currentColor.setRgb( colorDiff*idx, 0, 255 - colorDiff * idx );
316  entryColors.push_back( currentColor );
317  }
318  }
319  else
320  {
321  for ( int i = 0; i < numberOfEntries; ++i )
322  {
323  int idx = mInvertCheckBox->isChecked() ? numberOfEntries - i - 1 : i;
324  entryColors.push_back( colorRamp->color((( double ) idx ) / ( numberOfEntries - 1 ) ) );
325  }
326  }
327 
328  mColormapTreeWidget->clear();
329 
330  QList<double>::const_iterator value_it = entryValues.begin();
331  QList<QColor>::const_iterator color_it = entryColors.begin();
332 
333  for ( ; value_it != entryValues.end(); ++value_it, ++color_it )
334  {
335  QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
336  newItem->setText( 0, QString::number( *value_it, 'f' ) );
337  newItem->setBackground( 1, QBrush( *color_it ) );
338  newItem->setText( 2, QString::number( *value_it, 'f' ) );
339  newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
340  }
341 }
342 
343 void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index )
344 {
345  mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() == EqualInterval );
346 }
347 
348 void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index )
349 {
350  Q_UNUSED( index );
351  QSettings settings;
352  settings.setValue( "/Raster/defaultPalette", mColorRampComboBox->currentText() );
353 }
354 
355 void QgsSingleBandPseudoColorRendererWidget::populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems )
356 {
357  mColormapTreeWidget->clear();
358  QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItems.constBegin();
359  for ( ; it != colorRampItems.constEnd(); ++it )
360  {
361  QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
362  newItem->setText( 0, QString::number( it->value, 'f' ) );
363  newItem->setBackground( 1, QBrush( it->color ) );
364  newItem->setText( 2, it->label );
365  }
366 }
367 
368 void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked()
369 {
370  if ( !mRasterLayer || !mRasterLayer->dataProvider() )
371  {
372  return;
373  }
374 
375  int bandIndex = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
376 
377 
378  QList<QgsColorRampShader::ColorRampItem> colorRampList = mRasterLayer->dataProvider()->colorTable( bandIndex );
379  if ( colorRampList.size() > 0 )
380  {
381  populateColormapTreeWidget( colorRampList );
382  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
383  }
384  else
385  {
386  QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries" ).arg( bandIndex ) );
387  }
388 }
389 
390 void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromFileButton_clicked()
391 {
392  int lineCounter = 0;
393  bool importError = false;
394  QString badLines;
395  QSettings settings;
396  QString lastDir = settings.value( "lastRasterFileFilterDir", "" ).toString();
397  QString fileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), lastDir, tr( "Textfile (*.txt)" ) );
398  QFile inputFile( fileName );
399  if ( inputFile.open( QFile::ReadOnly ) )
400  {
401  //clear the current tree
402  mColormapTreeWidget->clear();
403 
404  QTextStream inputStream( &inputFile );
405  QString inputLine;
406  QStringList inputStringComponents;
407  QList<QgsColorRampShader::ColorRampItem> colorRampItems;
408 
409  //read through the input looking for valid data
410  while ( !inputStream.atEnd() )
411  {
412  lineCounter++;
413  inputLine = inputStream.readLine();
414  if ( !inputLine.isEmpty() )
415  {
416  if ( !inputLine.simplified().startsWith( "#" ) )
417  {
418  if ( inputLine.contains( "INTERPOLATION", Qt::CaseInsensitive ) )
419  {
420  inputStringComponents = inputLine.split( ":" );
421  if ( inputStringComponents.size() == 2 )
422  {
423  if ( inputStringComponents[1].trimmed().toUpper().compare( "INTERPOLATED", Qt::CaseInsensitive ) == 0 )
424  {
425  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
426  }
427  else if ( inputStringComponents[1].trimmed().toUpper().compare( "DISCRETE", Qt::CaseInsensitive ) == 0 )
428  {
429  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
430  }
431  else
432  {
433  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
434  }
435  }
436  else
437  {
438  importError = true;
439  badLines = badLines + QString::number( lineCounter ) + ":\t[" + inputLine + "]\n";
440  }
441  }
442  else
443  {
444  inputStringComponents = inputLine.split( "," );
445  if ( inputStringComponents.size() == 6 )
446  {
447  QgsColorRampShader::ColorRampItem currentItem( inputStringComponents[0].toDouble(),
448  QColor::fromRgb( inputStringComponents[1].toInt(), inputStringComponents[2].toInt(),
449  inputStringComponents[3].toInt(), inputStringComponents[4].toInt() ),
450  inputStringComponents[5] );
451  colorRampItems.push_back( currentItem );
452  }
453  else
454  {
455  importError = true;
456  badLines = badLines + QString::number( lineCounter ) + ":\t[" + inputLine + "]\n";
457  }
458  }
459  }
460  }
461  lineCounter++;
462  }
463  populateColormapTreeWidget( colorRampItems );
464 
465  if ( importError )
466  {
467  QMessageBox::warning( this, tr( "Import Error" ), tr( "The following lines contained errors\n\n" ) + badLines );
468  }
469  }
470  else if ( !fileName.isEmpty() )
471  {
472  QMessageBox::warning( this, tr( "Read access denied" ), tr( "Read access denied. Adjust the file permissions and try again.\n\n" ) );
473  }
474 }
475 
476 void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
477 {
478  QSettings settings;
479  QString lastDir = settings.value( "lastRasterFileFilterDir", "" ).toString();
480  QString fileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), lastDir, tr( "Textfile (*.txt)" ) );
481  if ( !fileName.isEmpty() )
482  {
483  if ( !fileName.endsWith( ".txt", Qt::CaseInsensitive ) )
484  {
485  fileName = fileName + ".txt";
486  }
487 
488  QFile outputFile( fileName );
489  if ( outputFile.open( QFile::WriteOnly ) )
490  {
491  QTextStream outputStream( &outputFile );
492  outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << "\n";
493  outputStream << "INTERPOLATION:";
494  if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
495  {
496  outputStream << "INTERPOLATED\n";
497  }
498  else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
499  {
500  outputStream << "DISCRETE\n";
501  }
502  else
503  {
504  outputStream << "EXACT\n";
505  }
506 
507  int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
508  QTreeWidgetItem* currentItem;
509  QColor color;
510  for ( int i = 0; i < topLevelItemCount; ++i )
511  {
512  currentItem = mColormapTreeWidget->topLevelItem( i );
513  if ( !currentItem )
514  {
515  continue;
516  }
517  color = currentItem->background( 1 ).color();
518  outputStream << currentItem->text( 0 ).toDouble() << ",";
519  outputStream << color.red() << "," << color.green() << "," << color.blue() << "," << color.alpha() << ",";
520  if ( currentItem->text( 2 ) == "" )
521  {
522  outputStream << "Color entry " << i + 1 << "\n";
523  }
524  else
525  {
526  outputStream << currentItem->text( 2 ) << "\n";
527  }
528  }
529  outputStream.flush();
530  outputFile.close();
531  }
532  else
533  {
534  QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
535  }
536  }
537 }
538 
539 void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
540 {
541  if ( !item )
542  {
543  return;
544  }
545 
546  if ( column == 1 ) //change item color
547  {
548  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
549  QColor newColor = QgsColorDialogV2::getColor( item->background( column ).color(), this, "Change color", true );
550  if ( newColor.isValid() )
551  {
552  item->setBackground( 1, QBrush( newColor ) );
553  }
554  }
555  else
556  {
557  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
558  }
559 }
560 
562 {
563  const QgsSingleBandPseudoColorRenderer* pr = dynamic_cast<const QgsSingleBandPseudoColorRenderer*>( r );
564  if ( pr )
565  {
566  mBandComboBox->setCurrentIndex( mBandComboBox->findData( pr->band() ) );
567 
568  const QgsRasterShader* rasterShader = pr->shader();
569  if ( rasterShader )
570  {
571  const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
572  if ( colorRampShader )
573  {
574  if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED )
575  {
576  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
577  }
578  else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
579  {
580  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
581  }
582  else
583  {
584  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
585  }
586 
587  const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
588  QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
589  for ( ; it != colorRampItemList.end(); ++it )
590  {
591  QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
592  newItem->setText( 0, QString::number( it->value, 'f' ) );
593  newItem->setBackground( 1, QBrush( it->color ) );
594  newItem->setText( 2, it->label );
595  }
596  mClipCheckBox->setChecked( colorRampShader->clip() );
597  }
598  }
599  setLineEditValue( mMinLineEdit, pr->classificationMin() );
600  setLineEditValue( mMaxLineEdit, pr->classificationMax() );
601  mMinMaxOrigin = pr->classificationMinMaxOrigin();
602  showMinMaxOrigin();
603  }
604 }
605 
606 void QgsSingleBandPseudoColorRendererWidget::on_mBandComboBox_currentIndexChanged( int index )
607 {
608  QList<int> myBands;
609  myBands.append( mBandComboBox->itemData( index ).toInt() );
610  mMinMaxWidget->setBands( myBands );
611 }
612 
613 void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
614 {
615  Q_UNUSED( theBandNo );
616  QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );
617 
618  if ( qIsNaN( theMin ) )
619  {
620  mMinLineEdit->clear();
621  }
622  else
623  {
624  mMinLineEdit->setText( QString::number( theMin ) );
625  }
626 
627  if ( qIsNaN( theMax ) )
628  {
629  mMaxLineEdit->clear();
630  }
631  else
632  {
633  mMaxLineEdit->setText( QString::number( theMax ) );
634  }
635 
636  mMinMaxOrigin = theOrigin;
637  showMinMaxOrigin();
638 }
639 
640 void QgsSingleBandPseudoColorRendererWidget::showMinMaxOrigin()
641 {
642  mMinMaxOriginLabel->setText( QgsRasterRenderer::minMaxOriginLabel( mMinMaxOrigin ) );
643 }
644 
645 void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit * theLineEdit, double theValue )
646 {
647  QString s;
648  if ( !qIsNaN( theValue ) )
649  {
650  s = QString::number( theValue );
651  }
652  theLineEdit->setText( s );
653 }
654 
655 double QgsSingleBandPseudoColorRendererWidget::lineEditValue( const QLineEdit * theLineEdit ) const
656 {
657  if ( theLineEdit->text().isEmpty() )
658  {
659  return std::numeric_limits<double>::quiet_NaN();
660  }
661 
662  return theLineEdit->text().toDouble();
663 }
664 
665 void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
666 {
667  mClassifyButton->setEnabled( true );
668  double min = lineEditValue( mMinLineEdit );
669  double max = lineEditValue( mMaxLineEdit );
670  if ( qIsNaN( min ) || qIsNaN( max ) || min >= max )
671  {
672  mClassifyButton->setEnabled( false );
673  }
674 }