From f03667b506edad9394502d013845c813ac7f9aab Mon Sep 17 00:00:00 2001 From: ersts Date: Thu, 28 Aug 2008 13:58:22 +0000 Subject: [PATCH] -Added ability to add new single entry to color map -Added ability to sort color map -Reorder controls on the Colormap tab git-svn-id: http://svn.osgeo.org/qgis/trunk@9200 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/app/qgsrasterlayerproperties.cpp | 56 +++++++ src/app/qgsrasterlayerproperties.h | 5 +- src/ui/qgsrasterlayerpropertiesbase.ui | 195 +++++++++++++------------ 3 files changed, 164 insertions(+), 92 deletions(-) diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index 8e25da79eee..c569dd9a61b 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -2622,6 +2622,14 @@ void QgsRasterLayerProperties::handleColormapTreeWidgetDoubleClick( QTreeWidgetI } } +void QgsRasterLayerProperties::on_pbtnAddColorMapEntry_clicked() +{ + QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget ); + newItem->setText( 0, "0.0"); + newItem->setBackground( 1, QBrush( QColor(Qt::magenta) ) ); + newItem->setText( 2, tr("Custom color map entry")); +} + void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked() { QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) ); @@ -2883,6 +2891,54 @@ void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_cl } } +void QgsRasterLayerProperties::on_pbtnSortColorMap_clicked() +{ + bool inserted = false; + int myCurrentIndex = 0; + int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount(); + QTreeWidgetItem* myCurrentItem; + QList myColorRampItems; + for ( int i = 0; i < myTopLevelItemCount; ++i ) + { + myCurrentItem = mColormapTreeWidget->topLevelItem( i ); + //If the item is null or does not have a pixel values set, skip + if(!myCurrentItem || myCurrentItem->text(0) == "") + { + continue; + } + + //Create a copy of the new Color ramp Item + QgsColorRampShader::ColorRampItem myNewColorRampItem; + myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble(); + myNewColorRampItem.color = myCurrentItem->background( 1 ).color(); + myNewColorRampItem.label = myCurrentItem->text( 2 ); + + //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++; + } + } + populateColorMapTable(myColorRampItems); +} + QLinearGradient QgsRasterLayerProperties::redGradient() { //define a gradient diff --git a/src/app/qgsrasterlayerproperties.h b/src/app/qgsrasterlayerproperties.h index cdc7c236dbf..75d79bbd8b7 100644 --- a/src/app/qgsrasterlayerproperties.h +++ b/src/app/qgsrasterlayerproperties.h @@ -108,6 +108,8 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope void on_mDeleteEntryButton_clicked(); /**Callback for double clicks on the colormap entry widget*/ void handleColormapTreeWidgetDoubleClick( QTreeWidgetItem* item, int column ); + /**This slot adds a new row to the color map table */ + void on_pbtnAddColorMapEntry_clicked(); /**This slots saves the current color map to a file */ void on_pbtnExportColorMapToFile_clicked(); /**This slots loads the current color map from a band */ @@ -120,7 +122,8 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope void on_pbtnMakeBandCombinationDefault_clicked(); /**This slot sets the default contrast enhancement varaible to current contrast enhancement algorithm */ void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked(); - + /**This slot will sort the color map in ascending order*/ + void on_pbtnSortColorMap_clicked(); /** Load the default style when appriate button is pressed. */ void on_pbnLoadDefaultStyle_clicked(); /** Save the default style when appriate button is pressed. */ diff --git a/src/ui/qgsrasterlayerpropertiesbase.ui b/src/ui/qgsrasterlayerpropertiesbase.ui index e9ad34a4001..9d2ef44e0f9 100644 --- a/src/ui/qgsrasterlayerpropertiesbase.ui +++ b/src/ui/qgsrasterlayerpropertiesbase.ui @@ -6,7 +6,7 @@ 0 0 596 - 610 + 658 @@ -1199,56 +1199,7 @@ Colormap - - - - 11 - - - 11 - - - 11 - - - 11 - - - - - Number of entries - - - - - - - - 0 - 0 - - - - 256 - - - - - - - - - Qt::Horizontal - - - - 71 - 20 - - - - - + 11 @@ -1274,73 +1225,54 @@ - + Qt::Horizontal - 61 - 20 + 321 + 45 - - - - 11 - - - 11 - - - 11 - - - 11 - - - - - Classification mode - - - - - - - - - - + + - Classify + Add entry - + Delete entry - + + + + Sort + + + + Qt::Horizontal - 211 + 41 27 - + 11 @@ -1363,11 +1295,14 @@ - + Qt::Horizontal + + QSizePolicy::Minimum + 20 @@ -1376,7 +1311,7 @@ - + Load color map from file @@ -1389,7 +1324,7 @@ - + Export color map to file @@ -1402,7 +1337,7 @@ - + 3 @@ -1424,6 +1359,84 @@ + + + + Generate new color map + + + + + + 11 + + + 11 + + + 11 + + + 11 + + + + + Number of entries + + + + + + + + 0 + 0 + + + + 256 + + + + + + + + + 11 + + + 11 + + + 11 + + + 11 + + + + + Classification mode + + + + + + + + + + + + Classify + + + + + +