29
29
#include " qgsmaplayerregistry.h"
30
30
#include " qgscontrastenhancement.h"
31
31
#include " qgsrastertransparency.h"
32
- # include " qgscolorrampshader.h "
32
+
33
33
34
34
#include < QTableWidgetItem>
35
35
#include < QHeaderView>
@@ -56,6 +56,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
56
56
TRSTRING_NOT_SET( tr( " Not Set" ) ),
57
57
mRasterLayer( dynamic_cast <QgsRasterLayer*>( lyr ) )
58
58
{
59
+
59
60
ignoreSpinBoxEvent = false ; // Short circuit signal loop between min max field and stdDev spin box
60
61
mGrayActualMinimumMaximum = false ;
61
62
mRGBActualMinimumMaximum = false ;
@@ -102,7 +103,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
102
103
cboxColorMap->addItem ( tr ( " Grayscale" ) );
103
104
cboxColorMap->addItem ( tr ( " Pseudocolor" ) );
104
105
cboxColorMap->addItem ( tr ( " Freak Out" ) );
105
- cboxColorMap->addItem ( tr ( " Custom Colormap" ) );
106
+ cboxColorMap->addItem ( tr ( " Colormap" ) );
106
107
107
108
// add items to the color stretch combo box
108
109
cboxContrastEnhancementAlgorithm->addItem ( tr ( " No Stretch" ) );
@@ -145,139 +146,108 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
145
146
headerLabels << " Label" ;
146
147
mColormapTreeWidget ->setHeaderLabels ( headerLabels );
147
148
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)
149
150
tabBar->setTabEnabled ( tabBar->indexOf ( tabPageColormap ), FALSE );
150
151
151
152
//
152
153
// Set up the combo boxes that contain band lists using the qstring list generated above
153
154
//
154
155
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" );
165
157
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;
169
162
170
- cboRed->addItem ( TRSTRING_NOT_SET );
171
- cboGreen->addItem ( TRSTRING_NOT_SET );
172
- cboBlue->addItem ( TRSTRING_NOT_SET );
163
+ int myBandCountInt = mRasterLayer ->getBandCount ();
173
164
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 ) );
178
166
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 )
182
170
{
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
185
175
//
186
- // Get a list of band names
187
- //
188
- QStringList myBandNameList;
176
+ QPixmap myPixmap ( 10 , 10 );
189
177
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
197
179
{
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 );
248
181
}
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 )
254
183
{
255
- QListWidgetItem *myItem = lstHistogramLabels->item ( myIteratorInt - 1 );
256
- myItem->setSelected ( true );
184
+ myPixmap.fill ( Qt::red );
257
185
}
258
-
259
- for ( QStringList::Iterator myIterator = myBandNameList.begin ();
260
- myIterator != myBandNameList.end ();
261
- ++myIterator )
186
+ else if ( myIteratorInt == 2 )
262
187
{
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
+ }
265
221
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
+ }
268
230
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;
274
236
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 );
279
244
}
280
245
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
+
281
251
cboxTransparencyBand->addItem ( TRSTRING_NOT_SET );
282
252
283
253
QIcon myPyramidPixmap ( QgisApp::getThemeIcon ( " /mIconPyramid.png" ) );
@@ -292,6 +262,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QWidget *p
292
262
pbtnMakeBandCombinationDefault->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSave.png" ) );
293
263
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSave.png" ) );
294
264
265
+ pbtnLoadColorMapFromBand->setIcon ( QgisApp::getThemeIcon ( " /mActionNewAttribute.png" ) );
295
266
pbtnExportColorMapToFile->setIcon ( QgisApp::getThemeIcon ( " /mActionFileSave.png" ) );
296
267
pbtnLoadColorMapFromFile->setIcon ( QgisApp::getThemeIcon ( " /mActionFileOpen.png" ) );
297
268
@@ -357,6 +328,21 @@ QgsRasterLayerProperties::~QgsRasterLayerProperties()
357
328
* PUBLIC METHODS
358
329
*
359
330
*/
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
+ }
360
346
void QgsRasterLayerProperties::populateTransparencyTable ()
361
347
{
362
348
// Clear existsing color transparency list
@@ -505,7 +491,7 @@ void QgsRasterLayerProperties::sync()
505
491
labelContrastEnhancement->setEnabled ( false );
506
492
break ;
507
493
case QgsRasterLayer::PALETTED_SINGLE_BAND_PSEUDO_COLOR:
508
- rbtnThreeBand->setEnabled ( true );
494
+ rbtnThreeBand->setEnabled ( false );
509
495
rbtnSingleBand->setEnabled ( true );
510
496
rbtnSingleBand->setChecked ( true );
511
497
rbtnThreeBandMinMax->setEnabled ( false );
@@ -602,7 +588,7 @@ void QgsRasterLayerProperties::sync()
602
588
}
603
589
else if ( mRasterLayer ->getColorShadingAlgorithm () == QgsRasterLayer::COLOR_RAMP )
604
590
{
605
- cboxColorMap->setCurrentIndex ( cboxColorMap->findText ( tr ( " Custom Colormap" ) ) );
591
+ cboxColorMap->setCurrentIndex ( cboxColorMap->findText ( tr ( " Colormap" ) ) );
606
592
}
607
593
else if ( mRasterLayer ->getColorShadingAlgorithm () == QgsRasterLayer::USER_DEFINED )
608
594
{
@@ -783,10 +769,7 @@ void QgsRasterLayerProperties::sync()
783
769
}
784
770
785
771
// restore colormap tab if the layer has custom classification
786
- if ( cboxColorMap->currentText () == tr ( " Custom Colormap" ) )
787
- {
788
- syncColormapTab ();
789
- }
772
+ syncColormapTab ();
790
773
791
774
QgsDebugMsg ( " populate general tab" );
792
775
/*
@@ -873,21 +856,9 @@ void QgsRasterLayerProperties::syncColormapTab()
873
856
return ;
874
857
}
875
858
// 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 ());
889
860
890
- sboxNumberOfEntries->setValue ( myColorRampList. size () );
861
+ sboxNumberOfEntries->setValue ( mColormapTreeWidget -> topLevelItemCount () );
891
862
892
863
// restor state of 'color interpolation' combo box
893
864
if ( QgsColorRampShader::INTERPOLATED == myRasterShaderFunction->getColorRampType () )
@@ -1082,7 +1053,7 @@ void QgsRasterLayerProperties::apply()
1082
1053
{
1083
1054
mRasterLayer ->setColorShadingAlgorithm ( QgsRasterLayer::FREAK_OUT );
1084
1055
}
1085
- else if ( cboxColorMap->currentText () == tr ( " Custom Colormap" ) )
1056
+ else if ( cboxColorMap->currentText () == tr ( " Colormap" ) )
1086
1057
{
1087
1058
mRasterLayer ->setColorShadingAlgorithm ( QgsRasterLayer::COLOR_RAMP );
1088
1059
}
@@ -1379,7 +1350,7 @@ void QgsRasterLayerProperties::apply()
1379
1350
/*
1380
1351
* ColorMap Tab
1381
1352
*/
1382
- if ( cboxColorMap->currentText () == tr ( " Custom Colormap" ) )
1353
+ if ( cboxColorMap->currentText () == tr ( " Colormap" ) )
1383
1354
{
1384
1355
QgsColorRampShader* myRasterShaderFunction = ( QgsColorRampShader* )mRasterLayer ->getRasterShader ()->getRasterShaderFunction ();
1385
1356
if ( myRasterShaderFunction )
@@ -1700,7 +1671,7 @@ void QgsRasterLayerProperties::on_cboxColorMap_currentIndexChanged( const QStrin
1700
1671
cboxContrastEnhancementAlgorithm->setEnabled ( false );
1701
1672
labelContrastEnhancement->setEnabled ( false );
1702
1673
}
1703
- else if ( mRasterLayerIsGdal && theText == tr ( " Custom Colormap" ) )
1674
+ else if ( mRasterLayerIsGdal && theText == tr ( " Colormap" ) )
1704
1675
{
1705
1676
tabBar->setTabEnabled ( tabBar->indexOf ( tabPageColormap ), TRUE );
1706
1677
rbtnSingleBandMinMax->setEnabled ( false );
@@ -2712,6 +2683,22 @@ void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked()
2712
2683
}
2713
2684
}
2714
2685
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
+
2715
2702
void QgsRasterLayerProperties::on_pbtnLoadColorMapFromFile_clicked ()
2716
2703
{
2717
2704
int myLineCounter = 0 ;
0 commit comments