Skip to content

Commit 75cf6c9

Browse files
author
ersts
committed
-Prevent text from being entered in color cell in the color map tree
-Stort / reload color map table on apply git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9284 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c17ccca commit 75cf6c9

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/app/qgsrasterlayerproperties.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,12 @@ void QgsRasterLayerProperties::apply()
13671367
if ( myRasterShaderFunction )
13681368
{
13691369
//iterate through mColormapTreeWidget and set colormap info of layer
1370-
QList<QgsColorRampShader::ColorRampItem> mColorRampItems;
1370+
QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
13711371

1372+
bool inserted = false;
1373+
int myCurrentIndex = 0;
13721374
int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
13731375
QTreeWidgetItem* myCurrentItem;
1374-
13751376
for ( int i = 0; i < myTopLevelItemCount; ++i )
13761377
{
13771378
myCurrentItem = mColormapTreeWidget->topLevelItem( i );
@@ -1383,9 +1384,33 @@ void QgsRasterLayerProperties::apply()
13831384
myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble();
13841385
myNewColorRampItem.color = myCurrentItem->background( 1 ).color();
13851386
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+
}
13871410
}
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 );
13891414

13901415
if ( cboxColorInterpolation->currentText() == tr( "Linear" ) )
13911416
{
@@ -2610,6 +2635,7 @@ void QgsRasterLayerProperties::handleColormapTreeWidgetDoubleClick( QTreeWidgetI
26102635
{
26112636
if ( column == 1 )
26122637
{
2638+
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
26132639
//show color dialog
26142640
QColor newColor = QColorDialog::getColor();
26152641
if ( newColor.isValid() )

0 commit comments

Comments
 (0)