@@ -1371,8 +1371,6 @@ void QgsRasterLayerProperties::apply()
1371
1371
// iterate through mColormapTreeWidget and set colormap info of layer
1372
1372
QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
1373
1373
1374
- bool inserted = false ;
1375
- int myCurrentIndex = 0 ;
1376
1374
int myTopLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
1377
1375
QTreeWidgetItem* myCurrentItem;
1378
1376
for ( int i = 0 ; i < myTopLevelItemCount; ++i )
@@ -1386,35 +1384,13 @@ void QgsRasterLayerProperties::apply()
1386
1384
myNewColorRampItem.value = myCurrentItem->text ( 0 ).toDouble ();
1387
1385
myNewColorRampItem.color = myCurrentItem->background ( 1 ).color ();
1388
1386
myNewColorRampItem.label = myCurrentItem->text ( 2 );
1389
-
1390
- // Simple insertion sort - speed is not a huge factor here
1391
- inserted = false ;
1392
- myCurrentIndex = 0 ;
1393
- while ( !inserted )
1394
- {
1395
- if ( 0 == myColorRampItems.size () || myCurrentIndex == myColorRampItems.size () )
1396
- {
1397
- myColorRampItems.push_back ( myNewColorRampItem );
1398
- inserted = true ;
1399
- }
1400
- else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
1401
- {
1402
- myColorRampItems.insert ( myCurrentIndex, myNewColorRampItem );
1403
- inserted = true ;
1404
- }
1405
- else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size () - 1 )
1406
- {
1407
- myColorRampItems.push_back ( myNewColorRampItem );
1408
- inserted = true ;
1409
- }
1410
- else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1 ].value > myNewColorRampItem.value )
1411
- {
1412
- myColorRampItems.insert ( myCurrentIndex + 1 , myNewColorRampItem );
1413
- inserted = true ;
1414
- }
1415
- myCurrentIndex++;
1416
- }
1387
+
1388
+ myColorRampItems.append ( myNewColorRampItem );
1417
1389
}
1390
+
1391
+ // sort the shader items
1392
+ qSort (myColorRampItems);
1393
+
1418
1394
myRasterShaderFunction->setColorRampItemList ( myColorRampItems );
1419
1395
// Reload table in GUI because it may have been sorted or contained invalid values
1420
1396
populateColorMapTable ( myColorRampItems );
0 commit comments