32
32
QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget ( QgsRasterLayer* layer, const QgsRectangle &extent ):
33
33
QgsRasterRendererWidget( layer, extent )
34
34
{
35
+ QSettings settings;
36
+
35
37
setupUi ( this );
36
38
37
39
mColormapTreeWidget ->setColumnWidth ( 1 , 50 );
38
40
41
+ QString defaultPalette = settings.value ( " /Raster/defaultPalette" , " Spectral" ).toString ();
42
+
39
43
mColorRampComboBox ->populate ( QgsStyleV2::defaultStyle () );
40
44
45
+ QgsDebugMsg ( " defaultPalette = " + defaultPalette );
46
+ mColorRampComboBox ->setCurrentIndex ( mColorRampComboBox ->findText ( defaultPalette ) );
47
+
41
48
if ( !mRasterLayer )
42
49
{
43
50
return ;
@@ -74,13 +81,22 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
74
81
mColorInterpolationComboBox ->addItem ( tr ( " Linear" ), 1 );
75
82
mColorInterpolationComboBox ->addItem ( tr ( " Exact" ), 2 );
76
83
mColorInterpolationComboBox ->setCurrentIndex ( 1 );
77
- mClassificationModeComboBox ->addItem ( tr ( " Equal interval" ) );
84
+ mClassificationModeComboBox ->addItem ( tr ( " Continuous" ), Continuous );
85
+ mClassificationModeComboBox ->addItem ( tr ( " Equal interval" ), EqualInterval );
78
86
// quantile would be nice as well
79
87
80
88
mNumberOfEntriesSpinBox ->setValue ( 5 ); // some default
81
89
82
90
setFromRenderer ( layer->renderer () );
83
91
92
+ // If there is currently no min/max, load default with user current default options
93
+ if ( mMinLineEdit ->text ().isEmpty () || mMaxLineEdit ->text ().isEmpty () )
94
+ {
95
+ mMinMaxWidget ->load ();
96
+ }
97
+
98
+ on_mClassificationModeComboBox_currentIndexChanged ( 0 );
99
+
84
100
resetClassifyButton ();
85
101
}
86
102
@@ -92,6 +108,7 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
92
108
{
93
109
QgsRasterShader* rasterShader = new QgsRasterShader ();
94
110
QgsColorRampShader* colorRampShader = new QgsColorRampShader ();
111
+ colorRampShader->setClip ( mClipCheckBox ->isChecked () );
95
112
96
113
// iterate through mColormapTreeWidget and set colormap info of layer
97
114
QList<QgsColorRampShader::ColorRampItem> colorRampItems;
@@ -217,16 +234,31 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
217
234
218
235
// int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
219
236
// QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
220
- int numberOfEntries = mNumberOfEntriesSpinBox -> value () ;
237
+ int numberOfEntries = 0 ;
221
238
222
239
QList<double > entryValues;
223
240
QList<QColor> entryColors;
224
241
225
242
double min = lineEditValue ( mMinLineEdit );
226
243
double max = lineEditValue ( mMaxLineEdit );
227
244
228
- if ( mClassificationModeComboBox ->currentText () == tr ( " Equal interval" ) )
245
+ QgsVectorColorRampV2* colorRamp = mColorRampComboBox ->currentColorRamp ();
246
+
247
+ if ( mClassificationModeComboBox ->itemData ( mClassificationModeComboBox ->currentIndex () ).toInt () == Continuous )
248
+ {
249
+ if ( colorRamp )
250
+ {
251
+ numberOfEntries = colorRamp->count ();
252
+ for ( int i = 0 ; i < colorRamp->count (); ++i )
253
+ {
254
+ double value = colorRamp->value ( i );
255
+ entryValues.push_back ( min + value * ( max - min ) );
256
+ }
257
+ }
258
+ }
259
+ else // EqualInterval
229
260
{
261
+ numberOfEntries = mNumberOfEntriesSpinBox ->value ();
230
262
// double currentValue = myRasterBandStats.minimumValue;
231
263
double currentValue = min;
232
264
double intervalDiff;
@@ -265,7 +297,6 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
265
297
}
266
298
#endif
267
299
268
- QgsVectorColorRampV2* colorRamp = mColorRampComboBox ->currentColorRamp ();
269
300
if ( ! colorRamp )
270
301
{
271
302
// hard code color range from blue -> red (previous default)
@@ -307,6 +338,18 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
307
338
}
308
339
}
309
340
341
+ void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged ( int index )
342
+ {
343
+ mNumberOfEntriesSpinBox ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () == EqualInterval );
344
+ }
345
+
346
+ void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged ( int index )
347
+ {
348
+ Q_UNUSED ( index );
349
+ QSettings settings;
350
+ settings.setValue ( " /Raster/defaultPalette" , mColorRampComboBox ->currentText () );
351
+ }
352
+
310
353
void QgsSingleBandPseudoColorRendererWidget::populateColormapTreeWidget ( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems )
311
354
{
312
355
mColormapTreeWidget ->clear ();
@@ -545,6 +588,7 @@ void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRen
545
588
newItem->setBackground ( 1 , QBrush ( it->color ) );
546
589
newItem->setText ( 2 , it->label );
547
590
}
591
+ mClipCheckBox ->setChecked ( colorRampShader->clip () );
548
592
}
549
593
}
550
594
setLineEditValue ( mMinLineEdit , pr->classificationMin () );
0 commit comments