[QGIS Commit] r9284 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Sep 8 09:42:21 EDT 2008


Author: ersts
Date: 2008-09-08 09:42:21 -0400 (Mon, 08 Sep 2008)
New Revision: 9284

Modified:
   trunk/qgis/src/app/qgsrasterlayerproperties.cpp
Log:
-Prevent text from being entered in color cell in the color map tree
-Stort / reload color map table on apply

Modified: trunk/qgis/src/app/qgsrasterlayerproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-09-08 10:12:27 UTC (rev 9283)
+++ trunk/qgis/src/app/qgsrasterlayerproperties.cpp	2008-09-08 13:42:21 UTC (rev 9284)
@@ -1367,11 +1367,12 @@
     if ( myRasterShaderFunction )
     {
       //iterate through mColormapTreeWidget and set colormap info of layer
-      QList<QgsColorRampShader::ColorRampItem> mColorRampItems;
+      QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
 
+      bool inserted = false;
+      int myCurrentIndex = 0;
       int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
       QTreeWidgetItem* myCurrentItem;
-
       for ( int i = 0; i < myTopLevelItemCount; ++i )
       {
         myCurrentItem = mColormapTreeWidget->topLevelItem( i );
@@ -1383,9 +1384,33 @@
         myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble();
         myNewColorRampItem.color = myCurrentItem->background( 1 ).color();
         myNewColorRampItem.label = myCurrentItem->text( 2 );
-        mColorRampItems.push_back( myNewColorRampItem );
+        
+        //Simple insertion sort - speed is not a huge factor here
+        inserted = false;
+        myCurrentIndex = 0;
+        while ( !inserted )
+        {
+          if ( 0 == myColorRampItems.size() || myCurrentIndex == myColorRampItems.size() )
+          {
+            myColorRampItems.push_back( myNewColorRampItem );
+            inserted = true;
+          }
+          else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value  && myCurrentIndex == myColorRampItems.size() - 1 )
+          {
+            myColorRampItems.push_back( myNewColorRampItem );
+            inserted = true;
+          }
+          else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1].value > myNewColorRampItem.value )
+          {
+            myColorRampItems.insert( myCurrentIndex + 1, myNewColorRampItem );
+            inserted = true;
+          }
+          myCurrentIndex++;
+        }
       }
-      myRasterShaderFunction->setColorRampItemList( mColorRampItems );
+      myRasterShaderFunction->setColorRampItemList( myColorRampItems );
+      //Reload table in GUI because it may have been sorted or contained invalid values
+      populateColorMapTable( myColorRampItems );
 
       if ( cboxColorInterpolation->currentText() == tr( "Linear" ) )
       {
@@ -2610,6 +2635,7 @@
   {
     if ( column == 1 )
     {
+      item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
       //show color dialog
       QColor newColor = QColorDialog::getColor();
       if ( newColor.isValid() )



More information about the QGIS-commit mailing list