@@ -1367,11 +1367,12 @@ void QgsRasterLayerProperties::apply()
1367
1367
if ( myRasterShaderFunction )
1368
1368
{
1369
1369
// iterate through mColormapTreeWidget and set colormap info of layer
1370
- QList<QgsColorRampShader::ColorRampItem> mColorRampItems ;
1370
+ QList<QgsColorRampShader::ColorRampItem> myColorRampItems ;
1371
1371
1372
+ bool inserted = false ;
1373
+ int myCurrentIndex = 0 ;
1372
1374
int myTopLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
1373
1375
QTreeWidgetItem* myCurrentItem;
1374
-
1375
1376
for ( int i = 0 ; i < myTopLevelItemCount; ++i )
1376
1377
{
1377
1378
myCurrentItem = mColormapTreeWidget ->topLevelItem ( i );
@@ -1383,9 +1384,33 @@ void QgsRasterLayerProperties::apply()
1383
1384
myNewColorRampItem.value = myCurrentItem->text ( 0 ).toDouble ();
1384
1385
myNewColorRampItem.color = myCurrentItem->background ( 1 ).color ();
1385
1386
myNewColorRampItem.label = myCurrentItem->text ( 2 );
1386
- mColorRampItems .push_back ( myNewColorRampItem );
1387
+
1388
+ // Simple insertion sort - speed is not a huge factor here
1389
+ inserted = false ;
1390
+ myCurrentIndex = 0 ;
1391
+ while ( !inserted )
1392
+ {
1393
+ if ( 0 == myColorRampItems.size () || myCurrentIndex == myColorRampItems.size () )
1394
+ {
1395
+ myColorRampItems.push_back ( myNewColorRampItem );
1396
+ inserted = true ;
1397
+ }
1398
+ else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size () - 1 )
1399
+ {
1400
+ myColorRampItems.push_back ( myNewColorRampItem );
1401
+ inserted = true ;
1402
+ }
1403
+ else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1 ].value > myNewColorRampItem.value )
1404
+ {
1405
+ myColorRampItems.insert ( myCurrentIndex + 1 , myNewColorRampItem );
1406
+ inserted = true ;
1407
+ }
1408
+ myCurrentIndex++;
1409
+ }
1387
1410
}
1388
- myRasterShaderFunction->setColorRampItemList ( mColorRampItems );
1411
+ myRasterShaderFunction->setColorRampItemList ( myColorRampItems );
1412
+ // Reload table in GUI because it may have been sorted or contained invalid values
1413
+ populateColorMapTable ( myColorRampItems );
1389
1414
1390
1415
if ( cboxColorInterpolation->currentText () == tr ( " Linear" ) )
1391
1416
{
@@ -2610,6 +2635,7 @@ void QgsRasterLayerProperties::handleColormapTreeWidgetDoubleClick( QTreeWidgetI
2610
2635
{
2611
2636
if ( column == 1 )
2612
2637
{
2638
+ item->setFlags ( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
2613
2639
// show color dialog
2614
2640
QColor newColor = QColorDialog::getColor ();
2615
2641
if ( newColor.isValid () )
0 commit comments