Skip to content

Commit bbe9e60

Browse files
author
ersts
committed
-Paletted image no longer open as faux RGB, but open as single band images with a color map
-Closes ticket #914 -Added a new QgsRasterlayer::readColorTable() that will read RGB/CMYK/HSV color maps from GDAL band -Added load color map(palette) from band to color map tab -QgsColorTable is now largely obsolete - more clean up need to totally remove *Note raster layer type enum are no longer representative of the way layers are rendered and need to be updated git-svn-id: http://svn.osgeo.org/qgis/trunk@9198 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 29b72b4 commit bbe9e60

5 files changed

+297
-210
lines changed

src/app/qgsrasterlayerproperties.cpp

+122-135
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "qgsmaplayerregistry.h"
3030
#include "qgscontrastenhancement.h"
3131
#include "qgsrastertransparency.h"
32-
#include "qgscolorrampshader.h"
32+
3333

3434
#include <QTableWidgetItem>
3535
#include <QHeaderView>
@@ -56,6 +56,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
5656
TRSTRING_NOT_SET( tr( "Not Set" ) ),
5757
mRasterLayer( dynamic_cast<QgsRasterLayer*>( lyr ) )
5858
{
59+
5960
ignoreSpinBoxEvent = false; //Short circuit signal loop between min max field and stdDev spin box
6061
mGrayActualMinimumMaximum = false;
6162
mRGBActualMinimumMaximum = false;
@@ -102,7 +103,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
102103
cboxColorMap->addItem( tr( "Grayscale" ) );
103104
cboxColorMap->addItem( tr( "Pseudocolor" ) );
104105
cboxColorMap->addItem( tr( "Freak Out" ) );
105-
cboxColorMap->addItem( tr( "Custom Colormap" ) );
106+
cboxColorMap->addItem( tr( "Colormap" ) );
106107

107108
//add items to the color stretch combo box
108109
cboxContrastEnhancementAlgorithm->addItem( tr( "No Stretch" ) );
@@ -145,139 +146,108 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
145146
headerLabels << "Label";
146147
mColormapTreeWidget->setHeaderLabels( headerLabels );
147148

148-
//disable Custom colormap tab completely until 'Custom Colormap' is selected (and only for type GRAY_OR_UNDEFINED)
149+
//disable colormap tab completely until 'Colormap' is selected (and only for type GRAY_OR_UNDEFINED)
149150
tabBar->setTabEnabled( tabBar->indexOf( tabPageColormap ), FALSE );
150151

151152
//
152153
// Set up the combo boxes that contain band lists using the qstring list generated above
153154
//
154155

155-
if ( mRasterLayer->getRasterLayerType()
156-
== QgsRasterLayer::PALETTE ) //paletted layers have hard coded color entries
157-
{
158-
cboRed->addItem( tr( "Red" ) );
159-
cboGreen->addItem( tr( "Red" ) );
160-
cboBlue->addItem( tr( "Red" ) );
161-
162-
cboRed->addItem( tr( "Green" ) );
163-
cboGreen->addItem( tr( "Green" ) );
164-
cboBlue->addItem( tr( "Green" ) );
156+
QgsDebugMsg( "Populating band combo boxes" );
165157

166-
cboRed->addItem( tr( "Blue" ) );
167-
cboGreen->addItem( tr( "Blue" ) );
168-
cboBlue->addItem( tr( "Blue" ) );
158+
//
159+
// Get a list of band names
160+
//
161+
QStringList myBandNameList;
169162

170-
cboRed->addItem( TRSTRING_NOT_SET );
171-
cboGreen->addItem( TRSTRING_NOT_SET );
172-
cboBlue->addItem( TRSTRING_NOT_SET );
163+
int myBandCountInt = mRasterLayer->getBandCount();
173164

174-
cboGray->addItem( tr( "Red" ) );
175-
cboGray->addItem( tr( "Green" ) );
176-
cboGray->addItem( tr( "Blue" ) );
177-
cboGray->addItem( TRSTRING_NOT_SET );
165+
QgsDebugMsg( QString( "Looping though %1 image layers to get their names " ).arg( myBandCountInt ) );
178166

179-
lstHistogramLabels->addItem( tr( "Palette" ) );
180-
}
181-
else // all other layer types use band name entries only
167+
for ( int myIteratorInt = 1;
168+
myIteratorInt <= myBandCountInt;
169+
++myIteratorInt )
182170
{
183-
QgsDebugMsg( "Populating combos for non paletted layer" );
184-
171+
//find out the name of this band
172+
QString myRasterBandNameQString = mRasterLayer->getRasterBandName( myIteratorInt ) ;
173+
174+
//add the band to the histogram tab
185175
//
186-
// Get a list of band names
187-
//
188-
QStringList myBandNameList;
176+
QPixmap myPixmap( 10, 10 );
189177

190-
int myBandCountInt = mRasterLayer->getBandCount();
191-
#ifdef QGISDEBIG
192-
QgsDebugMsg( QString( "Looping though %1 image layers to get their names " ).arg( myBandCountInt ) );
193-
#endif
194-
for ( int myIteratorInt = 1;
195-
myIteratorInt <= myBandCountInt;
196-
++myIteratorInt )
178+
if ( myBandCountInt == 1 ) //draw single band images with black
197179
{
198-
//find out the name of this band
199-
QString myRasterBandNameQString = mRasterLayer->getRasterBandName( myIteratorInt ) ;
200-
201-
//
202-
//add the band to the histogram tab
203-
//
204-
QPixmap myPixmap( 10, 10 );
205-
206-
if ( myBandCountInt == 1 ) //draw single band images with black
207-
{
208-
myPixmap.fill( Qt::black );
209-
}
210-
else if ( myIteratorInt == 1 )
211-
{
212-
myPixmap.fill( Qt::red );
213-
}
214-
else if ( myIteratorInt == 2 )
215-
{
216-
myPixmap.fill( Qt::green );
217-
}
218-
else if ( myIteratorInt == 3 )
219-
{
220-
myPixmap.fill( Qt::blue );
221-
}
222-
else if ( myIteratorInt == 4 )
223-
{
224-
myPixmap.fill( Qt::magenta );
225-
}
226-
else if ( myIteratorInt == 5 )
227-
{
228-
myPixmap.fill( Qt::darkRed );
229-
}
230-
else if ( myIteratorInt == 6 )
231-
{
232-
myPixmap.fill( Qt::darkGreen );
233-
}
234-
else if ( myIteratorInt == 7 )
235-
{
236-
myPixmap.fill( Qt::darkBlue );
237-
}
238-
else
239-
{
240-
myPixmap.fill( Qt::gray );
241-
}
242-
lstHistogramLabels->addItem( new QListWidgetItem( myPixmap, myRasterBandNameQString ) );
243-
mGradientHeight = pixHistogram->height() / 2;
244-
mGradientWidth = pixHistogram->width() / 2;
245-
//keep a list of band names for later use
246-
//! @note band names should not be translated!
247-
myBandNameList.append( myRasterBandNameQString );
180+
myPixmap.fill( Qt::black );
248181
}
249-
250-
//select all histogram layers list items by default
251-
for ( int myIteratorInt = 1;
252-
myIteratorInt <= myBandCountInt;
253-
++myIteratorInt )
182+
else if ( myIteratorInt == 1 )
254183
{
255-
QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 );
256-
myItem->setSelected( true );
184+
myPixmap.fill( Qt::red );
257185
}
258-
259-
for ( QStringList::Iterator myIterator = myBandNameList.begin();
260-
myIterator != myBandNameList.end();
261-
++myIterator )
186+
else if ( myIteratorInt == 2 )
262187
{
263-
QString myQString = *myIterator;
264-
#ifdef QGISDEBUG
188+
myPixmap.fill( Qt::green );
189+
}
190+
else if ( myIteratorInt == 3 )
191+
{
192+
myPixmap.fill( Qt::blue );
193+
}
194+
else if ( myIteratorInt == 4 )
195+
{
196+
myPixmap.fill( Qt::magenta );
197+
}
198+
else if ( myIteratorInt == 5 )
199+
{
200+
myPixmap.fill( Qt::darkRed );
201+
}
202+
else if ( myIteratorInt == 6 )
203+
{
204+
myPixmap.fill( Qt::darkGreen );
205+
}
206+
else if ( myIteratorInt == 7 )
207+
{
208+
myPixmap.fill( Qt::darkBlue );
209+
}
210+
else
211+
{
212+
myPixmap.fill( Qt::gray );
213+
}
214+
lstHistogramLabels->addItem( new QListWidgetItem( myPixmap, myRasterBandNameQString ) );
215+
mGradientHeight = pixHistogram->height() / 2;
216+
mGradientWidth = pixHistogram->width() / 2;
217+
//keep a list of band names for later use
218+
//! @note band names should not be translated!
219+
myBandNameList.append( myRasterBandNameQString );
220+
}
265221

266-
QgsDebugMsg( QString( "Inserting : %1" ).arg( myQString ) );
267-
#endif
222+
//select all histogram layers list items by default
223+
for ( int myIteratorInt = 1;
224+
myIteratorInt <= myBandCountInt;
225+
++myIteratorInt )
226+
{
227+
QListWidgetItem *myItem = lstHistogramLabels->item( myIteratorInt - 1 );
228+
myItem->setSelected( true );
229+
}
268230

269-
cboGray->addItem( myQString );
270-
cboRed->addItem( myQString );
271-
cboGreen->addItem( myQString );
272-
cboBlue->addItem( myQString );
273-
}
231+
for ( QStringList::Iterator myIterator = myBandNameList.begin();
232+
myIterator != myBandNameList.end();
233+
++myIterator )
234+
{
235+
QString myQString = *myIterator;
274236

275-
cboRed->addItem( TRSTRING_NOT_SET );
276-
cboGreen->addItem( TRSTRING_NOT_SET );
277-
cboBlue->addItem( TRSTRING_NOT_SET );
278-
cboGray->addItem( TRSTRING_NOT_SET );
237+
QgsDebugMsg( QString( "Inserting : %1" ).arg( myQString ) );
238+
239+
cboGray->addItem( myQString );
240+
cboRed->addItem( myQString );
241+
cboGreen->addItem( myQString );
242+
cboBlue->addItem( myQString );
243+
cboxColorMapBand->addItem( myQString );
279244
}
280245

246+
cboRed->addItem( TRSTRING_NOT_SET );
247+
cboGreen->addItem( TRSTRING_NOT_SET );
248+
cboBlue->addItem( TRSTRING_NOT_SET );
249+
cboGray->addItem( TRSTRING_NOT_SET );
250+
281251
cboxTransparencyBand->addItem( TRSTRING_NOT_SET );
282252

283253
QIcon myPyramidPixmap( QgisApp::getThemeIcon( "/mIconPyramid.png" ) );
@@ -292,6 +262,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
292262
pbtnMakeBandCombinationDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
293263
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
294264

265+
pbtnLoadColorMapFromBand->setIcon( QgisApp::getThemeIcon( "/mActionNewAttribute.png" ) );
295266
pbtnExportColorMapToFile->setIcon( QgisApp::getThemeIcon( "/mActionFileSave.png" ) );
296267
pbtnLoadColorMapFromFile->setIcon( QgisApp::getThemeIcon( "/mActionFileOpen.png" ) );
297268

@@ -357,6 +328,21 @@ QgsRasterLayerProperties::~QgsRasterLayerProperties()
357328
* PUBLIC METHODS
358329
*
359330
*/
331+
void QgsRasterLayerProperties::populateColorMapTable(const QList<QgsColorRampShader::ColorRampItem>& theColorRampList)
332+
{
333+
if ( theColorRampList.size() > 0 )
334+
{
335+
mColormapTreeWidget->clear();
336+
QList<QgsColorRampShader::ColorRampItem>::const_iterator it;
337+
for ( it = theColorRampList.begin(); it != theColorRampList.end(); ++it )
338+
{
339+
QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
340+
newItem->setText( 0, QString::number( it->value, 'f' ) );
341+
newItem->setBackground( 1, QBrush( it->color ) );
342+
newItem->setText( 2, it->label );
343+
}
344+
}
345+
}
360346
void QgsRasterLayerProperties::populateTransparencyTable()
361347
{
362348
//Clear existsing color transparency list
@@ -505,7 +491,7 @@ void QgsRasterLayerProperties::sync()
505491
labelContrastEnhancement->setEnabled( false );
506492
break;
507493
case QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR:
508-
rbtnThreeBand->setEnabled( true );
494+
rbtnThreeBand->setEnabled( false );
509495
rbtnSingleBand->setEnabled( true );
510496
rbtnSingleBand->setChecked( true );
511497
rbtnThreeBandMinMax->setEnabled( false );
@@ -602,7 +588,7 @@ void QgsRasterLayerProperties::sync()
602588
}
603589
else if ( mRasterLayer->getColorShadingAlgorithm() == QgsRasterLayer::COLOR_RAMP )
604590
{
605-
cboxColorMap->setCurrentIndex( cboxColorMap->findText( tr( "Custom Colormap" ) ) );
591+
cboxColorMap->setCurrentIndex( cboxColorMap->findText( tr( "Colormap" ) ) );
606592
}
607593
else if ( mRasterLayer->getColorShadingAlgorithm() == QgsRasterLayer::USER_DEFINED )
608594
{
@@ -783,10 +769,7 @@ void QgsRasterLayerProperties::sync()
783769
}
784770

785771
//restore colormap tab if the layer has custom classification
786-
if ( cboxColorMap->currentText() == tr( "Custom Colormap" ) )
787-
{
788-
syncColormapTab();
789-
}
772+
syncColormapTab();
790773

791774
QgsDebugMsg( "populate general tab" );
792775
/*
@@ -873,21 +856,9 @@ void QgsRasterLayerProperties::syncColormapTab()
873856
return;
874857
}
875858
//restore the colormap tab if layer has custom symbology
876-
QList<QgsColorRampShader::ColorRampItem> myColorRampList = myRasterShaderFunction->getColorRampItemList();
877-
if ( myColorRampList.size() > 0 )
878-
{
879-
QList<QgsColorRampShader::ColorRampItem>::const_iterator it;
880-
for ( it = myColorRampList.begin(); it != myColorRampList.end(); ++it )
881-
{
882-
//restore state of colormap tab
883-
QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
884-
newItem->setText( 0, QString::number( it->value, 'f' ) );
885-
newItem->setBackground( 1, QBrush( it->color ) );
886-
newItem->setText( 2, it->label );
887-
}
888-
}
859+
populateColorMapTable(myRasterShaderFunction->getColorRampItemList());
889860

890-
sboxNumberOfEntries->setValue( myColorRampList.size() );
861+
sboxNumberOfEntries->setValue( mColormapTreeWidget->topLevelItemCount() );
891862

892863
//restor state of 'color interpolation' combo box
893864
if ( QgsColorRampShader::INTERPOLATED == myRasterShaderFunction->getColorRampType() )
@@ -1082,7 +1053,7 @@ void QgsRasterLayerProperties::apply()
10821053
{
10831054
mRasterLayer->setColorShadingAlgorithm( QgsRasterLayer::FREAK_OUT );
10841055
}
1085-
else if ( cboxColorMap->currentText() == tr( "Custom Colormap" ) )
1056+
else if ( cboxColorMap->currentText() == tr( "Colormap" ) )
10861057
{
10871058
mRasterLayer->setColorShadingAlgorithm( QgsRasterLayer::COLOR_RAMP );
10881059
}
@@ -1379,7 +1350,7 @@ void QgsRasterLayerProperties::apply()
13791350
/*
13801351
* ColorMap Tab
13811352
*/
1382-
if ( cboxColorMap->currentText() == tr( "Custom Colormap" ) )
1353+
if ( cboxColorMap->currentText() == tr( "Colormap" ) )
13831354
{
13841355
QgsColorRampShader* myRasterShaderFunction = ( QgsColorRampShader* )mRasterLayer->getRasterShader()->getRasterShaderFunction();
13851356
if ( myRasterShaderFunction )
@@ -1700,7 +1671,7 @@ void QgsRasterLayerProperties::on_cboxColorMap_currentIndexChanged( const QStrin
17001671
cboxContrastEnhancementAlgorithm->setEnabled( false );
17011672
labelContrastEnhancement->setEnabled( false );
17021673
}
1703-
else if ( mRasterLayerIsGdal && theText == tr( "Custom Colormap" ) )
1674+
else if ( mRasterLayerIsGdal && theText == tr( "Colormap" ) )
17041675
{
17051676
tabBar->setTabEnabled( tabBar->indexOf( tabPageColormap ), TRUE );
17061677
rbtnSingleBandMinMax->setEnabled( false );
@@ -2712,6 +2683,22 @@ void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked()
27122683
}
27132684
}
27142685

2686+
void QgsRasterLayerProperties::on_pbtnLoadColorMapFromBand_clicked()
2687+
{
2688+
QList<QgsColorRampShader::ColorRampItem> myColorRampList;
2689+
if(mRasterLayer->readColorTable(cboxColorMapBand->currentIndex()+1, &myColorRampList))
2690+
{
2691+
populateColorMapTable(myColorRampList);
2692+
cboxColorInterpolation->setCurrentIndex( cboxColorInterpolation->findText( tr( "Exact" ) ) );
2693+
QgsDebugMsg("Color map loaded");
2694+
}
2695+
else
2696+
{
2697+
QMessageBox::warning(this, tr("Load Color Map"), tr("The color map for Band %n failed to load", "", cboxColorMapBand->currentIndex()+1));
2698+
QgsDebugMsg("Color map failed to load");
2699+
}
2700+
}
2701+
27152702
void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked()
27162703
{
27172704
int myLineCounter = 0;

0 commit comments

Comments
 (0)