@@ -1371,8 +1371,6 @@ void QgsRasterLayerProperties::apply()
13711371 // iterate through mColormapTreeWidget and set colormap info of layer
13721372 QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
13731373
1374- bool inserted = false ;
1375- int myCurrentIndex = 0 ;
13761374 int myTopLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
13771375 QTreeWidgetItem* myCurrentItem;
13781376 for ( int i = 0 ; i < myTopLevelItemCount; ++i )
@@ -1386,35 +1384,13 @@ void QgsRasterLayerProperties::apply()
13861384 myNewColorRampItem.value = myCurrentItem->text ( 0 ).toDouble ();
13871385 myNewColorRampItem.color = myCurrentItem->background ( 1 ).color ();
13881386 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 );
14171389 }
1390+
1391+ // sort the shader items
1392+ qSort (myColorRampItems);
1393+
14181394 myRasterShaderFunction->setColorRampItemList ( myColorRampItems );
14191395 // Reload table in GUI because it may have been sorted or contained invalid values
14201396 populateColorMapTable ( myColorRampItems );
0 commit comments