QGIS API Documentation  2.10.1-Pisa
 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 );
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
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;
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  QgsVectorColorRampV2* ramp = mColorRampComboBox->currentColorRamp();
355  if ( !ramp )
356  return;
357 
358  bool enableContinuous = ( ramp->count() > 0 );
359  mClassificationModeComboBox->setEnabled( enableContinuous );
360  if ( !enableContinuous )
361  {
362  mClassificationModeComboBox->setCurrentIndex( mClassificationModeComboBox->findData( EqualInterval ) );
363  }
364 }
365 
366 void QgsSingleBandPseudoColorRendererWidget::populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems )
367 {
368  mColormapTreeWidget->clear();
370  for ( ; it != colorRampItems.constEnd(); ++it )
371  {
372  QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
373  newItem->setText( 0, QString::number( it->value, 'f' ) );
374  newItem->setBackground( 1, QBrush( it->color ) );
375  newItem->setText( 2, it->label );
376  }
377 }
378 
379 void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked()
380 {
381  if ( !mRasterLayer || !mRasterLayer->dataProvider() )
382  {
383  return;
384  }
385 
386  int bandIndex = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
387 
388 
390  if ( colorRampList.size() > 0 )
391  {
392  populateColormapTreeWidget( colorRampList );
393  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
394  }
395  else
396  {
397  QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries" ).arg( bandIndex ) );
398  }
399 }
400 
401 void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromFileButton_clicked()
402 {
403  int lineCounter = 0;
404  bool importError = false;
405  QString badLines;
406  QSettings settings;
407  QString lastDir = settings.value( "lastRasterFileFilterDir", "" ).toString();
408  QString fileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), lastDir, tr( "Textfile (*.txt)" ) );
409  QFile inputFile( fileName );
410  if ( inputFile.open( QFile::ReadOnly ) )
411  {
412  //clear the current tree
413  mColormapTreeWidget->clear();
414 
415  QTextStream inputStream( &inputFile );
416  QString inputLine;
417  QStringList inputStringComponents;
419 
420  //read through the input looking for valid data
421  while ( !inputStream.atEnd() )
422  {
423  lineCounter++;
424  inputLine = inputStream.readLine();
425  if ( !inputLine.isEmpty() )
426  {
427  if ( !inputLine.simplified().startsWith( "#" ) )
428  {
429  if ( inputLine.contains( "INTERPOLATION", Qt::CaseInsensitive ) )
430  {
431  inputStringComponents = inputLine.split( ":" );
432  if ( inputStringComponents.size() == 2 )
433  {
434  if ( inputStringComponents[1].trimmed().toUpper().compare( "INTERPOLATED", Qt::CaseInsensitive ) == 0 )
435  {
436  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
437  }
438  else if ( inputStringComponents[1].trimmed().toUpper().compare( "DISCRETE", Qt::CaseInsensitive ) == 0 )
439  {
440  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
441  }
442  else
443  {
444  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
445  }
446  }
447  else
448  {
449  importError = true;
450  badLines = badLines + QString::number( lineCounter ) + ":\t[" + inputLine + "]\n";
451  }
452  }
453  else
454  {
455  inputStringComponents = inputLine.split( "," );
456  if ( inputStringComponents.size() == 6 )
457  {
458  QgsColorRampShader::ColorRampItem currentItem( inputStringComponents[0].toDouble(),
459  QColor::fromRgb( inputStringComponents[1].toInt(), inputStringComponents[2].toInt(),
460  inputStringComponents[3].toInt(), inputStringComponents[4].toInt() ),
461  inputStringComponents[5] );
462  colorRampItems.push_back( currentItem );
463  }
464  else
465  {
466  importError = true;
467  badLines = badLines + QString::number( lineCounter ) + ":\t[" + inputLine + "]\n";
468  }
469  }
470  }
471  }
472  lineCounter++;
473  }
474  populateColormapTreeWidget( colorRampItems );
475 
476  if ( importError )
477  {
478  QMessageBox::warning( this, tr( "Import Error" ), tr( "The following lines contained errors\n\n" ) + badLines );
479  }
480  }
481  else if ( !fileName.isEmpty() )
482  {
483  QMessageBox::warning( this, tr( "Read access denied" ), tr( "Read access denied. Adjust the file permissions and try again.\n\n" ) );
484  }
485 }
486 
487 void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
488 {
489  QSettings settings;
490  QString lastDir = settings.value( "lastRasterFileFilterDir", "" ).toString();
491  QString fileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), lastDir, tr( "Textfile (*.txt)" ) );
492  if ( !fileName.isEmpty() )
493  {
494  if ( !fileName.endsWith( ".txt", Qt::CaseInsensitive ) )
495  {
496  fileName = fileName + ".txt";
497  }
498 
499  QFile outputFile( fileName );
500  if ( outputFile.open( QFile::WriteOnly ) )
501  {
502  QTextStream outputStream( &outputFile );
503  outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << "\n";
504  outputStream << "INTERPOLATION:";
505  if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
506  {
507  outputStream << "INTERPOLATED\n";
508  }
509  else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
510  {
511  outputStream << "DISCRETE\n";
512  }
513  else
514  {
515  outputStream << "EXACT\n";
516  }
517 
518  int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
519  QTreeWidgetItem* currentItem;
520  QColor color;
521  for ( int i = 0; i < topLevelItemCount; ++i )
522  {
523  currentItem = mColormapTreeWidget->topLevelItem( i );
524  if ( !currentItem )
525  {
526  continue;
527  }
528  color = currentItem->background( 1 ).color();
529  outputStream << currentItem->text( 0 ).toDouble() << ",";
530  outputStream << color.red() << "," << color.green() << "," << color.blue() << "," << color.alpha() << ",";
531  if ( currentItem->text( 2 ) == "" )
532  {
533  outputStream << "Color entry " << i + 1 << "\n";
534  }
535  else
536  {
537  outputStream << currentItem->text( 2 ) << "\n";
538  }
539  }
540  outputStream.flush();
541  outputFile.close();
542  }
543  else
544  {
545  QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
546  }
547  }
548 }
549 
550 void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
551 {
552  if ( !item )
553  {
554  return;
555  }
556 
557  if ( column == 1 ) //change item color
558  {
559  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
560  QColor newColor = QgsColorDialogV2::getColor( item->background( column ).color(), this, "Change color", true );
561  if ( newColor.isValid() )
562  {
563  item->setBackground( 1, QBrush( newColor ) );
564  }
565  }
566  else
567  {
568  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
569  }
570 }
571 
573 {
574  const QgsSingleBandPseudoColorRenderer* pr = dynamic_cast<const QgsSingleBandPseudoColorRenderer*>( r );
575  if ( pr )
576  {
577  mBandComboBox->setCurrentIndex( mBandComboBox->findData( pr->band() ) );
578 
579  const QgsRasterShader* rasterShader = pr->shader();
580  if ( rasterShader )
581  {
582  const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
583  if ( colorRampShader )
584  {
585  if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED )
586  {
587  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
588  }
589  else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
590  {
591  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
592  }
593  else
594  {
595  mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
596  }
597 
598  const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
600  for ( ; it != colorRampItemList.end(); ++it )
601  {
602  QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
603  newItem->setText( 0, QString::number( it->value, 'f' ) );
604  newItem->setBackground( 1, QBrush( it->color ) );
605  newItem->setText( 2, it->label );
606  }
607  mClipCheckBox->setChecked( colorRampShader->clip() );
608  }
609  }
610  setLineEditValue( mMinLineEdit, pr->classificationMin() );
611  setLineEditValue( mMaxLineEdit, pr->classificationMax() );
612  mMinMaxOrigin = pr->classificationMinMaxOrigin();
613  showMinMaxOrigin();
614  }
615 }
616 
617 void QgsSingleBandPseudoColorRendererWidget::on_mBandComboBox_currentIndexChanged( int index )
618 {
619  QList<int> myBands;
620  myBands.append( mBandComboBox->itemData( index ).toInt() );
621  mMinMaxWidget->setBands( myBands );
622 }
623 
624 void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
625 {
626  Q_UNUSED( theBandNo );
627  QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );
628 
629  if ( qIsNaN( theMin ) )
630  {
631  mMinLineEdit->clear();
632  }
633  else
634  {
635  mMinLineEdit->setText( QString::number( theMin ) );
636  }
637 
638  if ( qIsNaN( theMax ) )
639  {
640  mMaxLineEdit->clear();
641  }
642  else
643  {
644  mMaxLineEdit->setText( QString::number( theMax ) );
645  }
646 
647  mMinMaxOrigin = theOrigin;
648  showMinMaxOrigin();
649 }
650 
651 void QgsSingleBandPseudoColorRendererWidget::showMinMaxOrigin()
652 {
653  mMinMaxOriginLabel->setText( QgsRasterRenderer::minMaxOriginLabel( mMinMaxOrigin ) );
654 }
655 
656 void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit * theLineEdit, double theValue )
657 {
658  QString s;
659  if ( !qIsNaN( theValue ) )
660  {
661  s = QString::number( theValue );
662  }
663  theLineEdit->setText( s );
664 }
665 
666 double QgsSingleBandPseudoColorRendererWidget::lineEditValue( const QLineEdit * theLineEdit ) const
667 {
668  if ( theLineEdit->text().isEmpty() )
669  {
670  return std::numeric_limits<double>::quiet_NaN();
671  }
672 
673  return theLineEdit->text().toDouble();
674 }
675 
676 void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
677 {
678  mClassifyButton->setEnabled( true );
679  double min = lineEditValue( mMinLineEdit );
680  double max = lineEditValue( mMaxLineEdit );
681  if ( qIsNaN( min ) || qIsNaN( max ) || min >= max )
682  {
683  mClassifyButton->setEnabled( false );
684  }
685 }
QLayout * layout() const
virtual int bandCount() const =0
Get number of bands.
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Interface for all raster shaders.
void setBackground(int column, const QBrush &brush)
void setContentsMargins(int left, int top, int right, int bottom)
void setupUi(QWidget *widget)
void push_back(const T &value)
void setText(const QString &)
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
void setBands(const QList< int > &theBands)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString simplified() const
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &theList)
Set custom colormap.
void setClip(bool clip)
void setRgb(int r, int g, int b, int a)
double toDouble(bool *ok) const
QString tr(const char *sourceText, const char *disambiguation, int n)
void loadMinMax(int theBandNo, double theMin, double theMax, int theOrigin)
int size() const
T value(int i) const
const QColor & color() const
void setValue(const QString &key, const QVariant &value)
QList< QgsColorRampShader::ColorRampItem > colorRampItemList() const
Get the custom colormap.
void setFlags(QFlags< Qt::ItemFlag > flags)
QColor fromRgb(QRgb rgb)
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString number(int n, int base)
void append(const T &value)
QgsColorRampShader::ColorRamp_TYPE colorRampType() const
Get the color ramp type.
virtual QString min(int index=0)
QgsRasterRenderer * renderer() const
void setExtent(const QgsRectangle &theExtent)
virtual double value(int index) const =0
Returns relative value between [0,1] of color at specified index.
int red() const
int band() const
Returns the band used by the renderer.
QgsRasterShaderFunction * rasterShaderFunction()
static QgsStyleV2 * defaultStyle()
return default application-wide style
Definition: qgsstylev2.cpp:51
bool isEmpty() const
static QString minMaxOriginLabel(int theOrigin)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Raster renderer pipe for single band pseudocolor.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void setRasterShaderFunction(QgsRasterShaderFunction *)
A public method that allows the user to set their own shader function.
int alpha() const
void setColorRampType(QgsColorRampShader::ColorRamp_TYPE theColorRampType)
Set the color ramp type.
virtual QColor color(double value) const =0
int green() const
iterator end()
bool contains(QChar ch, Qt::CaseSensitivity cs) const
int blue() const
QString displayBandName(int band) const
Returns a band name for display.
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual int count() const =0
Returns number of defined colors, or -1 if undefined.
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), const bool allowAlpha=false)
Return a color selection from a color dialog.
void insert(int i, const T &value)
QgsSingleBandPseudoColorRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())
void setText(int column, const QString &text)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
virtual QString max(int index=0)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
const_iterator constEnd() const
const_iterator constBegin() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
QString toString() const
QString text(int column) const
iterator begin()
Raster renderer pipe that applies colors to a raster.
QBrush background(int column) const
bool isValid() const
Base class for raster data providers.