Quantum GIS API Documentation  master-ce49b66
src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                          qgssinglebandpseudocolorrendererwidget.cpp
00003                          ------------------------------------------
00004     begin                : February 2012
00005     copyright            : (C) 2012 by Marco Hugentobler
00006     email                : marco at sourcepole dot ch
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qgssinglebandpseudocolorrendererwidget.h"
00019 #include "qgssinglebandpseudocolorrenderer.h"
00020 #include "qgsrasterlayer.h"
00021 
00022 // for color ramps - todo add rasterStyle and refactor raster vs. vector ramps
00023 #include "qgsstylev2.h"
00024 #include "qgsvectorcolorrampv2.h"
00025 
00026 #include <QColorDialog>
00027 #include <QFileDialog>
00028 #include <QMessageBox>
00029 #include <QSettings>
00030 #include <QTextStream>
00031 
00032 QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent ):
00033     QgsRasterRendererWidget( layer, extent )
00034 {
00035   QSettings settings;
00036 
00037   setupUi( this );
00038 
00039   mColormapTreeWidget->setColumnWidth( 1, 50 );
00040 
00041   QString defaultPalette = settings.value( "/Raster/defaultPalette", "Spectral" ).toString();
00042 
00043   mColorRampComboBox->populate( QgsStyleV2::defaultStyle() );
00044 
00045   QgsDebugMsg( "defaultPalette = " + defaultPalette );
00046   mColorRampComboBox->setCurrentIndex( mColorRampComboBox->findText( defaultPalette ) );
00047 
00048   if ( !mRasterLayer )
00049   {
00050     return;
00051   }
00052 
00053   QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
00054   if ( !provider )
00055   {
00056     return;
00057   }
00058 
00059   // Must be before adding items to mBandComboBox (signal)
00060   mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) );
00061   mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) );
00062 
00063   mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
00064   mMinMaxWidget->setExtent( extent );
00065   QHBoxLayout *layout = new QHBoxLayout();
00066   layout->setContentsMargins( 0, 0, 0, 0 );
00067   mMinMaxContainerWidget->setLayout( layout );
00068   layout->addWidget( mMinMaxWidget );
00069   connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ),
00070            this, SLOT( loadMinMax( int, double, double, int ) ) );
00071 
00072 
00073   //fill available bands into combo box
00074   int nBands = provider->bandCount();
00075   for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
00076   {
00077     mBandComboBox->addItem( displayBandName( i ), i );
00078   }
00079 
00080   mColorInterpolationComboBox->addItem( tr( "Discrete" ), 0 );
00081   mColorInterpolationComboBox->addItem( tr( "Linear" ), 1 );
00082   mColorInterpolationComboBox->addItem( tr( "Exact" ), 2 );
00083   mColorInterpolationComboBox->setCurrentIndex( 1 );
00084   mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous );
00085   mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval );
00086   //quantile would be nice as well
00087 
00088   mNumberOfEntriesSpinBox->setValue( 5 ); // some default
00089 
00090   setFromRenderer( layer->renderer() );
00091 
00092   // If there is currently no min/max, load default with user current default options
00093   if ( mMinLineEdit->text().isEmpty() || mMaxLineEdit->text().isEmpty() )
00094   {
00095     mMinMaxWidget->load();
00096   }
00097 
00098   on_mClassificationModeComboBox_currentIndexChanged( 0 );
00099 
00100   resetClassifyButton();
00101 }
00102 
00103 QgsSingleBandPseudoColorRendererWidget::~QgsSingleBandPseudoColorRendererWidget()
00104 {
00105 }
00106 
00107 QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
00108 {
00109   QgsRasterShader* rasterShader = new QgsRasterShader();
00110   QgsColorRampShader* colorRampShader = new QgsColorRampShader();
00111   colorRampShader->setClip( mClipCheckBox->isChecked() );
00112 
00113   //iterate through mColormapTreeWidget and set colormap info of layer
00114   QList<QgsColorRampShader::ColorRampItem> colorRampItems;
00115   int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
00116   QTreeWidgetItem* currentItem;
00117   for ( int i = 0; i < topLevelItemCount; ++i )
00118   {
00119     currentItem = mColormapTreeWidget->topLevelItem( i );
00120     if ( !currentItem )
00121     {
00122       continue;
00123     }
00124     QgsColorRampShader::ColorRampItem newColorRampItem;
00125     newColorRampItem.value = currentItem->text( 0 ).toDouble();
00126     newColorRampItem.color = currentItem->background( 1 ).color();
00127     newColorRampItem.label = currentItem->text( 2 );
00128     colorRampItems.append( newColorRampItem );
00129   }
00130   // sort the shader items
00131   qSort( colorRampItems );
00132   colorRampShader->setColorRampItemList( colorRampItems );
00133 
00134   if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
00135   {
00136     colorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
00137   }
00138   else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
00139   {
00140     colorRampShader->setColorRampType( QgsColorRampShader::DISCRETE );
00141   }
00142   else
00143   {
00144     colorRampShader->setColorRampType( QgsColorRampShader::EXACT );
00145   }
00146   rasterShader->setRasterShaderFunction( colorRampShader );
00147 
00148   int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
00149   QgsSingleBandPseudoColorRenderer *renderer = new QgsSingleBandPseudoColorRenderer( mRasterLayer->dataProvider(), bandNumber, rasterShader );
00150 
00151   renderer->setClassificationMin( lineEditValue( mMinLineEdit ) );
00152   renderer->setClassificationMax( lineEditValue( mMaxLineEdit ) );
00153   renderer->setClassificationMinMaxOrigin( mMinMaxOrigin );
00154   return renderer;
00155 }
00156 
00157 void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_clicked()
00158 {
00159   QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
00160   newItem->setText( 0, "0.0" );
00161   newItem->setBackground( 1, QBrush( QColor( Qt::magenta ) ) );
00162   newItem->setText( 2, tr( "Custom color map entry" ) );
00163 }
00164 
00165 void QgsSingleBandPseudoColorRendererWidget::on_mDeleteEntryButton_clicked()
00166 {
00167   QTreeWidgetItem* currentItem = mColormapTreeWidget->currentItem();
00168   if ( currentItem )
00169   {
00170     delete currentItem;
00171   }
00172 }
00173 
00174 void QgsSingleBandPseudoColorRendererWidget::on_mSortButton_clicked()
00175 {
00176   bool inserted = false;
00177   int myCurrentIndex = 0;
00178   int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
00179   QTreeWidgetItem* myCurrentItem;
00180   QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
00181   for ( int i = 0; i < myTopLevelItemCount; ++i )
00182   {
00183     myCurrentItem = mColormapTreeWidget->topLevelItem( i );
00184     //If the item is null or does not have a pixel values set, skip
00185     if ( !myCurrentItem || myCurrentItem->text( 0 ) == "" )
00186     {
00187       continue;
00188     }
00189 
00190     //Create a copy of the new Color ramp Item
00191     QgsColorRampShader::ColorRampItem myNewColorRampItem;
00192     myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble();
00193     myNewColorRampItem.color = myCurrentItem->background( 1 ).color();
00194     myNewColorRampItem.label = myCurrentItem->text( 2 );
00195 
00196     //Simple insertion sort - speed is not a huge factor here
00197     inserted = false;
00198     myCurrentIndex = 0;
00199     while ( !inserted )
00200     {
00201       if ( 0 == myColorRampItems.size() || myCurrentIndex == myColorRampItems.size() )
00202       {
00203         myColorRampItems.push_back( myNewColorRampItem );
00204         inserted = true;
00205       }
00206       else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
00207       {
00208         myColorRampItems.insert( myCurrentIndex, myNewColorRampItem );
00209         inserted = true;
00210       }
00211       else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value  && myCurrentIndex == myColorRampItems.size() - 1 )
00212       {
00213         myColorRampItems.push_back( myNewColorRampItem );
00214         inserted = true;
00215       }
00216       else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1].value > myNewColorRampItem.value )
00217       {
00218         myColorRampItems.insert( myCurrentIndex + 1, myNewColorRampItem );
00219         inserted = true;
00220       }
00221       myCurrentIndex++;
00222     }
00223   }
00224   populateColormapTreeWidget( myColorRampItems );
00225 }
00226 
00227 void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
00228 {
00229   int bandComboIndex = mBandComboBox->currentIndex();
00230   if ( bandComboIndex == -1 || !mRasterLayer )
00231   {
00232     return;
00233   }
00234 
00235   //int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
00236   //QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
00237   int numberOfEntries = 0;
00238 
00239   QList<double> entryValues;
00240   QList<QColor> entryColors;
00241 
00242   double min = lineEditValue( mMinLineEdit );
00243   double max = lineEditValue( mMaxLineEdit );
00244 
00245   QgsVectorColorRampV2* colorRamp = mColorRampComboBox->currentColorRamp();
00246 
00247   if ( mClassificationModeComboBox->itemData( mClassificationModeComboBox->currentIndex() ).toInt() == Continuous )
00248   {
00249     if ( colorRamp )
00250     {
00251       numberOfEntries = colorRamp->count();
00252       for ( int i = 0; i < colorRamp->count(); ++i )
00253       {
00254         double value = colorRamp->value( i );
00255         entryValues.push_back( min + value * ( max - min ) );
00256       }
00257     }
00258   }
00259   else // EqualInterval
00260   {
00261     numberOfEntries = mNumberOfEntriesSpinBox->value();
00262     //double currentValue = myRasterBandStats.minimumValue;
00263     double currentValue = min;
00264     double intervalDiff;
00265     if ( numberOfEntries > 1 )
00266     {
00267       //because the highest value is also an entry, there are (numberOfEntries - 1)
00268       //intervals
00269       //intervalDiff = ( myRasterBandStats.maximumValue - myRasterBandStats.minimumValue ) /
00270       intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
00271     }
00272     else
00273     {
00274       //intervalDiff = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
00275       intervalDiff = max - min;
00276     }
00277 
00278     for ( int i = 0; i < numberOfEntries; ++i )
00279     {
00280       entryValues.push_back( currentValue );
00281       currentValue += intervalDiff;
00282     }
00283   }
00284 
00285 #if 0
00286   //hard code color range from blue -> red for now. Allow choice of ramps in future
00287   int colorDiff = 0;
00288   if ( numberOfEntries != 0 )
00289   {
00290     colorDiff = ( int )( 255 / numberOfEntries );
00291   }
00292   for ( int i = 0; i < numberOfEntries; ++i )
00293   {
00294     QColor currentColor;
00295     currentColor.setRgb( colorDiff*i, 0, 255 - colorDiff * i );
00296     entryColors.push_back( currentColor );
00297   }
00298 #endif
00299 
00300   if ( ! colorRamp )
00301   {
00302     //hard code color range from blue -> red (previous default)
00303     int colorDiff = 0;
00304     if ( numberOfEntries != 0 )
00305     {
00306       colorDiff = ( int )( 255 / numberOfEntries );
00307     }
00308 
00309     for ( int i = 0; i < numberOfEntries; ++i )
00310     {
00311       QColor currentColor;
00312       int idx = mInvertCheckBox->isChecked() ? numberOfEntries - i - 1 : i;
00313       currentColor.setRgb( colorDiff*idx, 0, 255 - colorDiff * idx );
00314       entryColors.push_back( currentColor );
00315     }
00316   }
00317   else
00318   {
00319     for ( int i = 0; i < numberOfEntries; ++i )
00320     {
00321       int idx = mInvertCheckBox->isChecked() ? numberOfEntries - i - 1 : i;
00322       entryColors.push_back( colorRamp->color((( double ) idx ) / numberOfEntries ) );
00323     }
00324   }
00325 
00326   mColormapTreeWidget->clear();
00327 
00328   QList<double>::const_iterator value_it = entryValues.begin();
00329   QList<QColor>::const_iterator color_it = entryColors.begin();
00330 
00331   for ( ; value_it != entryValues.end(); ++value_it, ++color_it )
00332   {
00333     QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
00334     newItem->setText( 0, QString::number( *value_it, 'f' ) );
00335     newItem->setBackground( 1, QBrush( *color_it ) );
00336     newItem->setText( 2, QString::number( *value_it, 'f' ) );
00337     newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
00338   }
00339 }
00340 
00341 void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index )
00342 {
00343   mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() == EqualInterval );
00344 }
00345 
00346 void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index )
00347 {
00348   Q_UNUSED( index );
00349   QSettings settings;
00350   settings.setValue( "/Raster/defaultPalette", mColorRampComboBox->currentText() );
00351 }
00352 
00353 void QgsSingleBandPseudoColorRendererWidget::populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems )
00354 {
00355   mColormapTreeWidget->clear();
00356   QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItems.constBegin();
00357   for ( ; it != colorRampItems.constEnd(); ++it )
00358   {
00359     QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
00360     newItem->setText( 0, QString::number( it->value, 'f' ) );
00361     newItem->setBackground( 1, QBrush( it->color ) );
00362     newItem->setText( 2, it->label );
00363   }
00364 }
00365 
00366 void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked()
00367 {
00368   if ( !mRasterLayer || !mRasterLayer->dataProvider() )
00369   {
00370     return;
00371   }
00372 
00373   int bandIndex = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
00374 
00375 
00376   QList<QgsColorRampShader::ColorRampItem> colorRampList = mRasterLayer->dataProvider()->colorTable( bandIndex );
00377   if ( colorRampList.size() > 0 )
00378   {
00379     populateColormapTreeWidget( colorRampList );
00380     mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
00381   }
00382   else
00383   {
00384     QMessageBox::warning( this, tr( "Load Color Map" ), tr( "The color map for band %1 has no entries" ).arg( bandIndex ) );
00385   }
00386 }
00387 
00388 void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromFileButton_clicked()
00389 {
00390   int lineCounter = 0;
00391   bool importError = false;
00392   QString badLines;
00393   QSettings settings;
00394   QString lastDir = settings.value( "lastRasterFileFilterDir", "" ).toString();
00395   QString fileName = QFileDialog::getOpenFileName( this, tr( "Open file" ), lastDir, tr( "Textfile (*.txt)" ) );
00396   QFile inputFile( fileName );
00397   if ( inputFile.open( QFile::ReadOnly ) )
00398   {
00399     //clear the current tree
00400     mColormapTreeWidget->clear();
00401 
00402     QTextStream inputStream( &inputFile );
00403     QString inputLine;
00404     QStringList inputStringComponents;
00405     QList<QgsColorRampShader::ColorRampItem> colorRampItems;
00406 
00407     //read through the input looking for valid data
00408     while ( !inputStream.atEnd() )
00409     {
00410       lineCounter++;
00411       inputLine = inputStream.readLine();
00412       if ( !inputLine.isEmpty() )
00413       {
00414         if ( !inputLine.simplified().startsWith( "#" ) )
00415         {
00416           if ( inputLine.contains( "INTERPOLATION", Qt::CaseInsensitive ) )
00417           {
00418             inputStringComponents = inputLine.split( ":" );
00419             if ( inputStringComponents.size() == 2 )
00420             {
00421               if ( inputStringComponents[1].trimmed().toUpper().compare( "INTERPOLATED", Qt::CaseInsensitive ) == 0 )
00422               {
00423                 mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
00424               }
00425               else if ( inputStringComponents[1].trimmed().toUpper().compare( "DISCRETE", Qt::CaseInsensitive ) == 0 )
00426               {
00427                 mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
00428               }
00429               else
00430               {
00431                 mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
00432               }
00433             }
00434             else
00435             {
00436               importError = true;
00437               badLines = badLines + QString::number( lineCounter ) + ":\t[" + inputLine + "]\n";
00438             }
00439           }
00440           else
00441           {
00442             inputStringComponents = inputLine.split( "," );
00443             if ( inputStringComponents.size() == 6 )
00444             {
00445               QgsColorRampShader::ColorRampItem currentItem( inputStringComponents[0].toDouble(),
00446                   QColor::fromRgb( inputStringComponents[1].toInt(), inputStringComponents[2].toInt(),
00447                                    inputStringComponents[3].toInt(), inputStringComponents[4].toInt() ),
00448                   inputStringComponents[5] );
00449               colorRampItems.push_back( currentItem );
00450             }
00451             else
00452             {
00453               importError = true;
00454               badLines = badLines + QString::number( lineCounter ) + ":\t[" + inputLine + "]\n";
00455             }
00456           }
00457         }
00458       }
00459       lineCounter++;
00460     }
00461     populateColormapTreeWidget( colorRampItems );
00462 
00463     if ( importError )
00464     {
00465       QMessageBox::warning( this, tr( "Import Error" ), tr( "The following lines contained errors\n\n" ) + badLines );
00466     }
00467   }
00468   else if ( !fileName.isEmpty() )
00469   {
00470     QMessageBox::warning( this, tr( "Read access denied" ), tr( "Read access denied. Adjust the file permissions and try again.\n\n" ) );
00471   }
00472 }
00473 
00474 void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
00475 {
00476   QSettings settings;
00477   QString lastDir = settings.value( "lastRasterFileFilterDir", "" ).toString();
00478   QString fileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), lastDir, tr( "Textfile (*.txt)" ) );
00479   if ( !fileName.isEmpty() )
00480   {
00481     if ( !fileName.endsWith( ".txt", Qt::CaseInsensitive ) )
00482     {
00483       fileName = fileName + ".txt";
00484     }
00485 
00486     QFile outputFile( fileName );
00487     if ( outputFile.open( QFile::WriteOnly ) )
00488     {
00489       QTextStream outputStream( &outputFile );
00490       outputStream << "# " << tr( "QGIS Generated Color Map Export File" ) << "\n";
00491       outputStream << "INTERPOLATION:";
00492       if ( mColorInterpolationComboBox->currentText() == tr( "Linear" ) )
00493       {
00494         outputStream << "INTERPOLATED\n";
00495       }
00496       else if ( mColorInterpolationComboBox->currentText() == tr( "Discrete" ) )
00497       {
00498         outputStream << "DISCRETE\n";
00499       }
00500       else
00501       {
00502         outputStream << "EXACT\n";
00503       }
00504 
00505       int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
00506       QTreeWidgetItem* currentItem;
00507       QColor color;
00508       for ( int i = 0; i < topLevelItemCount; ++i )
00509       {
00510         currentItem = mColormapTreeWidget->topLevelItem( i );
00511         if ( !currentItem )
00512         {
00513           continue;
00514         }
00515         color = currentItem->background( 1 ).color();
00516         outputStream << currentItem->text( 0 ).toDouble() << ",";
00517         outputStream << color.red() << "," << color.green() << "," << color.blue() << "," << color.alpha() << ",";
00518         if ( currentItem->text( 2 ) == "" )
00519         {
00520           outputStream << "Color entry " << i + 1 << "\n";
00521         }
00522         else
00523         {
00524           outputStream << currentItem->text( 2 ) << "\n";
00525         }
00526       }
00527       outputStream.flush();
00528       outputFile.close();
00529     }
00530     else
00531     {
00532       QMessageBox::warning( this, tr( "Write access denied" ), tr( "Write access denied. Adjust the file permissions and try again.\n\n" ) );
00533     }
00534   }
00535 }
00536 
00537 void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column )
00538 {
00539   if ( !item )
00540   {
00541     return;
00542   }
00543 
00544   if ( column == 1 ) //change item color
00545   {
00546     item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
00547     QColor newColor = QColorDialog::getColor( item->background( column ).color() );
00548     if ( newColor.isValid() )
00549     {
00550       item->setBackground( 1, QBrush( newColor ) );
00551     }
00552   }
00553   else
00554   {
00555     item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
00556   }
00557 }
00558 
00559 void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRenderer* r )
00560 {
00561   const QgsSingleBandPseudoColorRenderer* pr = dynamic_cast<const QgsSingleBandPseudoColorRenderer*>( r );
00562   if ( pr )
00563   {
00564     const QgsRasterShader* rasterShader = pr->shader();
00565     if ( rasterShader )
00566     {
00567       const QgsColorRampShader* colorRampShader = dynamic_cast<const QgsColorRampShader*>( rasterShader->rasterShaderFunction() );
00568       if ( colorRampShader )
00569       {
00570         if ( colorRampShader->colorRampType() == QgsColorRampShader::INTERPOLATED )
00571         {
00572           mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Linear" ) ) );
00573         }
00574         else if ( colorRampShader->colorRampType() == QgsColorRampShader::DISCRETE )
00575         {
00576           mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Discrete" ) ) );
00577         }
00578         else
00579         {
00580           mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findText( tr( "Exact" ) ) );
00581         }
00582 
00583         const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
00584         QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
00585         for ( ; it != colorRampItemList.end(); ++it )
00586         {
00587           QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
00588           newItem->setText( 0, QString::number( it->value, 'f' ) );
00589           newItem->setBackground( 1, QBrush( it->color ) );
00590           newItem->setText( 2, it->label );
00591         }
00592         mClipCheckBox->setChecked( colorRampShader->clip() );
00593       }
00594     }
00595     setLineEditValue( mMinLineEdit, pr->classificationMin() );
00596     setLineEditValue( mMaxLineEdit, pr->classificationMax() );
00597     mMinMaxOrigin = pr->classificationMinMaxOrigin();
00598     showMinMaxOrigin();
00599   }
00600 }
00601 
00602 void QgsSingleBandPseudoColorRendererWidget::on_mBandComboBox_currentIndexChanged( int index )
00603 {
00604   QList<int> myBands;
00605   myBands.append( mBandComboBox->itemData( index ).toInt() );
00606   mMinMaxWidget->setBands( myBands );
00607 }
00608 
00609 void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
00610 {
00611   Q_UNUSED( theBandNo );
00612   QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );
00613 
00614   if ( qIsNaN( theMin ) )
00615   {
00616     mMinLineEdit->clear();
00617   }
00618   else
00619   {
00620     mMinLineEdit->setText( QString::number( theMin ) );
00621   }
00622 
00623   if ( qIsNaN( theMax ) )
00624   {
00625     mMaxLineEdit->clear();
00626   }
00627   else
00628   {
00629     mMaxLineEdit->setText( QString::number( theMax ) );
00630   }
00631 
00632   mMinMaxOrigin = theOrigin;
00633   showMinMaxOrigin();
00634 }
00635 
00636 void QgsSingleBandPseudoColorRendererWidget::showMinMaxOrigin()
00637 {
00638   mMinMaxOriginLabel->setText( QgsRasterRenderer::minMaxOriginLabel( mMinMaxOrigin ) );
00639 }
00640 
00641 void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit * theLineEdit, double theValue )
00642 {
00643   QString s;
00644   if ( !qIsNaN( theValue ) )
00645   {
00646     s = QString::number( theValue );
00647   }
00648   theLineEdit->setText( s );
00649 }
00650 
00651 double QgsSingleBandPseudoColorRendererWidget::lineEditValue( const QLineEdit * theLineEdit ) const
00652 {
00653   if ( theLineEdit->text().isEmpty() )
00654   {
00655     return std::numeric_limits<double>::quiet_NaN();
00656   }
00657 
00658   return theLineEdit->text().toDouble();
00659 }
00660 
00661 void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
00662 {
00663   mClassifyButton->setEnabled( true );
00664   double min = lineEditValue( mMinLineEdit );
00665   double max = lineEditValue( mMaxLineEdit );
00666   if ( qIsNaN( min ) || qIsNaN( max ) || min >= max )
00667   {
00668     mClassifyButton->setEnabled( false );
00669   }
00670 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines