@@ -115,10 +115,10 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
115
115
mBandComboBox ->addItem ( displayBandName ( i ), i );
116
116
}
117
117
118
- mColorInterpolationComboBox ->addItem ( tr ( " Discrete" ), 0 );
119
- mColorInterpolationComboBox ->addItem ( tr ( " Linear" ), 1 );
120
- mColorInterpolationComboBox ->addItem ( tr ( " Exact" ), 2 );
121
- mColorInterpolationComboBox ->setCurrentIndex ( 1 );
118
+ mColorInterpolationComboBox ->addItem ( tr ( " Discrete" ), QgsColorRampShader::DISCRETE );
119
+ mColorInterpolationComboBox ->addItem ( tr ( " Linear" ), QgsColorRampShader::INTERPOLATED );
120
+ mColorInterpolationComboBox ->addItem ( tr ( " Exact" ), QgsColorRampShader::EXACT );
121
+ mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox -> findData ( QgsColorRampShader::INTERPOLATED ) );
122
122
mClassificationModeComboBox ->addItem ( tr ( " Continuous" ), Continuous );
123
123
mClassificationModeComboBox ->addItem ( tr ( " Equal interval" ), EqualInterval );
124
124
mClassificationModeComboBox ->addItem ( tr ( " Quantile" ), Quantile );
@@ -178,18 +178,8 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
178
178
qSort ( colorRampItems );
179
179
colorRampShader->setColorRampItemList ( colorRampItems );
180
180
181
- if ( mColorInterpolationComboBox ->currentText () == tr ( " Linear" ) )
182
- {
183
- colorRampShader->setColorRampType ( QgsColorRampShader::INTERPOLATED );
184
- }
185
- else if ( mColorInterpolationComboBox ->currentText () == tr ( " Discrete" ) )
186
- {
187
- colorRampShader->setColorRampType ( QgsColorRampShader::DISCRETE );
188
- }
189
- else
190
- {
191
- colorRampShader->setColorRampType ( QgsColorRampShader::EXACT );
192
- }
181
+ QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast < QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox ->itemData ( mColorInterpolationComboBox ->currentIndex () ).toInt () );
182
+ colorRampShader->setColorRampType ( interpolation );
193
183
rasterShader->setRasterShaderFunction ( colorRampShader );
194
184
195
185
int bandNumber = mBandComboBox ->itemData ( mBandComboBox ->currentIndex () ).toInt ();
@@ -207,7 +197,8 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
207
197
*/
208
198
void QgsSingleBandPseudoColorRendererWidget::autoLabel ()
209
199
{
210
- bool discrete = mColorInterpolationComboBox ->currentText () == tr ( " Discrete" );
200
+ QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast < QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox ->itemData ( mColorInterpolationComboBox ->currentIndex () ).toInt () );
201
+ bool discrete = interpolation == QgsColorRampShader::DISCRETE;
211
202
QString unit = mUnitLineEdit ->text ();
212
203
QString label;
213
204
int topLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
@@ -252,7 +243,8 @@ void QgsSingleBandPseudoColorRendererWidget::autoLabel()
252
243
/* * Extract the unit out of the current labels and set the unit field. */
253
244
void QgsSingleBandPseudoColorRendererWidget::setUnitFromLabels ()
254
245
{
255
- bool discrete = mColorInterpolationComboBox ->currentText () == tr ( " Discrete" );
246
+ QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast < QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox ->itemData ( mColorInterpolationComboBox ->currentIndex () ).toInt () );
247
+ bool discrete = interpolation == QgsColorRampShader::DISCRETE;
256
248
QStringList allSuffixes;
257
249
QString label;
258
250
int topLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
@@ -353,7 +345,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
353
345
// QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
354
346
int numberOfEntries;
355
347
356
- bool discrete = mColorInterpolationComboBox ->currentText () == tr ( " Discrete" );
348
+ QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast < QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox ->itemData ( mColorInterpolationComboBox ->currentIndex () ).toInt () );
349
+ bool discrete = interpolation == QgsColorRampShader::DISCRETE;
357
350
358
351
QList<double > entryValues;
359
352
QVector<QColor> entryColors;
@@ -531,9 +524,10 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
531
524
532
525
void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged ( int index )
533
526
{
534
- mNumberOfEntriesSpinBox ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () != Continuous );
535
- mMinLineEdit ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () != Quantile );
536
- mMaxLineEdit ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () != Quantile );
527
+ Mode mode = static_cast < Mode >( mClassificationModeComboBox ->itemData ( index ).toInt () );
528
+ mNumberOfEntriesSpinBox ->setEnabled ( mode != Continuous );
529
+ mMinLineEdit ->setEnabled ( mode != Quantile );
530
+ mMaxLineEdit ->setEnabled ( mode != Quantile );
537
531
}
538
532
539
533
void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged ( int index )
@@ -585,7 +579,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromBandButton_clicked()
585
579
if ( !colorRampList.isEmpty () )
586
580
{
587
581
populateColormapTreeWidget ( colorRampList );
588
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Linear " ) ) );
582
+ mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findData ( QgsColorRampShader::INTERPOLATED ) );
589
583
}
590
584
else
591
585
{
@@ -629,15 +623,15 @@ void QgsSingleBandPseudoColorRendererWidget::on_mLoadFromFileButton_clicked()
629
623
{
630
624
if ( inputStringComponents[1 ].trimmed ().toUpper ().compare ( " INTERPOLATED" , Qt::CaseInsensitive ) == 0 )
631
625
{
632
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Linear " ) ) );
626
+ mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findData ( QgsColorRampShader::INTERPOLATED ) );
633
627
}
634
628
else if ( inputStringComponents[1 ].trimmed ().toUpper ().compare ( " DISCRETE" , Qt::CaseInsensitive ) == 0 )
635
629
{
636
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Discrete " ) ) );
630
+ mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findData ( QgsColorRampShader::DISCRETE ) );
637
631
}
638
632
else
639
633
{
640
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Exact " ) ) );
634
+ mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findData ( QgsColorRampShader::EXACT ) );
641
635
}
642
636
}
643
637
else
@@ -702,17 +696,18 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
702
696
QTextStream outputStream ( &outputFile );
703
697
outputStream << " # " << tr ( " QGIS Generated Color Map Export File" ) << ' \n ' ;
704
698
outputStream << " INTERPOLATION:" ;
705
- if ( mColorInterpolationComboBox ->currentText () == tr ( " Linear" ) )
699
+ QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast < QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox ->itemData ( mColorInterpolationComboBox ->currentIndex () ).toInt () );
700
+ switch ( interpolation )
706
701
{
707
- outputStream << " INTERPOLATED\n " ;
708
- }
709
- else if ( mColorInterpolationComboBox -> currentText () == tr ( " Discrete " ) )
710
- {
711
- outputStream << " DISCRETE\n " ;
712
- }
713
- else
714
- {
715
- outputStream << " EXACT \n " ;
702
+ case QgsColorRampShader:: INTERPOLATED:
703
+ outputStream << " INTERPOLATED \n " ;
704
+ break ;
705
+ case QgsColorRampShader::DISCRETE:
706
+ outputStream << " DISCRETE\n " ;
707
+ break ;
708
+ case QgsColorRampShader::EXACT:
709
+ outputStream << " EXACT \n " ;
710
+ break ;
716
711
}
717
712
718
713
int topLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
@@ -750,10 +745,6 @@ void QgsSingleBandPseudoColorRendererWidget::on_mExportToFileButton_clicked()
750
745
}
751
746
}
752
747
753
- void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged ()
754
- {
755
- }
756
-
757
748
void QgsSingleBandPseudoColorRendererWidget::on_mColormapTreeWidget_itemDoubleClicked ( QTreeWidgetItem* item, int column )
758
749
{
759
750
if ( !item )
@@ -812,18 +803,7 @@ void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRen
812
803
const QgsColorRampShader* colorRampShader = dynamic_cast <const QgsColorRampShader*>( rasterShader->rasterShaderFunction () );
813
804
if ( colorRampShader )
814
805
{
815
- if ( colorRampShader->colorRampType () == QgsColorRampShader::INTERPOLATED )
816
- {
817
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Linear" ) ) );
818
- }
819
- else if ( colorRampShader->colorRampType () == QgsColorRampShader::DISCRETE )
820
- {
821
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Discrete" ) ) );
822
- }
823
- else
824
- {
825
- mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findText ( tr ( " Exact" ) ) );
826
- }
806
+ mColorInterpolationComboBox ->setCurrentIndex ( mColorInterpolationComboBox ->findData ( colorRampShader->colorRampType () ) );
827
807
828
808
const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList ();
829
809
QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin ();
@@ -857,8 +837,32 @@ void QgsSingleBandPseudoColorRendererWidget::on_mBandComboBox_currentIndexChange
857
837
858
838
void QgsSingleBandPseudoColorRendererWidget::on_mColorInterpolationComboBox_currentIndexChanged ( int index )
859
839
{
860
- Q_UNUSED ( index );
861
- mClipCheckBox ->setEnabled ( mColorInterpolationComboBox ->currentText () == tr ( " Linear" ) );
840
+ QgsColorRampShader::ColorRamp_TYPE interpolation = static_cast < QgsColorRampShader::ColorRamp_TYPE >( mColorInterpolationComboBox ->itemData ( index ).toInt () );
841
+
842
+ mClipCheckBox ->setEnabled ( interpolation == QgsColorRampShader::INTERPOLATED );
843
+
844
+ QString valueLabel;
845
+ QString valueToolTip;
846
+ switch ( interpolation )
847
+ {
848
+ case QgsColorRampShader::INTERPOLATED:
849
+ valueLabel = tr ( " Value" );
850
+ valueToolTip = tr ( " Value for color stop" );
851
+ break ;
852
+ case QgsColorRampShader::DISCRETE:
853
+ valueLabel = tr ( " Value <=" );
854
+ valueToolTip = tr ( " Maximum value for class" );
855
+ break ;
856
+ case QgsColorRampShader::EXACT:
857
+ valueLabel = tr ( " Value =" );
858
+ valueToolTip = tr ( " Value for color" );
859
+ break ;
860
+ }
861
+
862
+ QTreeWidgetItem* header = mColormapTreeWidget ->headerItem ();
863
+ header->setText ( ValueColumn, valueLabel );
864
+ header->setToolTip ( ValueColumn, valueToolTip );
865
+
862
866
autoLabel ();
863
867
}
864
868
0 commit comments