Skip to content

Commit 3531fb9

Browse files
author
ersts
committed
-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/qgis@9200 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7ff6c86 commit 3531fb9

File tree

3 files changed

+164
-92
lines changed

3 files changed

+164
-92
lines changed

src/app/qgsrasterlayerproperties.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,14 @@ void QgsRasterLayerProperties::handleColormapTreeWidgetDoubleClick( QTreeWidgetI
26222622
}
26232623
}
26242624

2625+
void QgsRasterLayerProperties::on_pbtnAddColorMapEntry_clicked()
2626+
{
2627+
QTreeWidgetItem* newItem = new QTreeWidgetItem( mColormapTreeWidget );
2628+
newItem->setText( 0, "0.0");
2629+
newItem->setBackground( 1, QBrush( QColor(Qt::magenta) ) );
2630+
newItem->setText( 2, tr("Custom color map entry"));
2631+
}
2632+
26252633
void QgsRasterLayerProperties::on_pbtnExportColorMapToFile_clicked()
26262634
{
26272635
QString myFileName = QFileDialog::getSaveFileName( this, tr( "Save file" ), "/", tr( "Textfile (*.txt)" ) );
@@ -2883,6 +2891,54 @@ void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_cl
28832891
}
28842892
}
28852893

2894+
void QgsRasterLayerProperties::on_pbtnSortColorMap_clicked()
2895+
{
2896+
bool inserted = false;
2897+
int myCurrentIndex = 0;
2898+
int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
2899+
QTreeWidgetItem* myCurrentItem;
2900+
QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
2901+
for ( int i = 0; i < myTopLevelItemCount; ++i )
2902+
{
2903+
myCurrentItem = mColormapTreeWidget->topLevelItem( i );
2904+
//If the item is null or does not have a pixel values set, skip
2905+
if(!myCurrentItem || myCurrentItem->text(0) == "")
2906+
{
2907+
continue;
2908+
}
2909+
2910+
//Create a copy of the new Color ramp Item
2911+
QgsColorRampShader::ColorRampItem myNewColorRampItem;
2912+
myNewColorRampItem.value = myCurrentItem->text( 0 ).toDouble();
2913+
myNewColorRampItem.color = myCurrentItem->background( 1 ).color();
2914+
myNewColorRampItem.label = myCurrentItem->text( 2 );
2915+
2916+
//Simple insertion sort - speed is not a huge factor here
2917+
inserted = false;
2918+
myCurrentIndex = 0;
2919+
while(!inserted)
2920+
{
2921+
if(0 == myColorRampItems.size() || myCurrentIndex == myColorRampItems.size())
2922+
{
2923+
myColorRampItems.push_back( myNewColorRampItem );
2924+
inserted = true;
2925+
}
2926+
else if(myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size() - 1)
2927+
{
2928+
myColorRampItems.push_back( myNewColorRampItem );
2929+
inserted = true;
2930+
}
2931+
else if(myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1].value > myNewColorRampItem.value)
2932+
{
2933+
myColorRampItems.insert(myCurrentIndex+1,myNewColorRampItem );
2934+
inserted = true;
2935+
}
2936+
myCurrentIndex++;
2937+
}
2938+
}
2939+
populateColorMapTable(myColorRampItems);
2940+
}
2941+
28862942
QLinearGradient QgsRasterLayerProperties::redGradient()
28872943
{
28882944
//define a gradient

src/app/qgsrasterlayerproperties.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
108108
void on_mDeleteEntryButton_clicked();
109109
/**Callback for double clicks on the colormap entry widget*/
110110
void handleColormapTreeWidgetDoubleClick( QTreeWidgetItem* item, int column );
111+
/**This slot adds a new row to the color map table */
112+
void on_pbtnAddColorMapEntry_clicked();
111113
/**This slots saves the current color map to a file */
112114
void on_pbtnExportColorMapToFile_clicked();
113115
/**This slots loads the current color map from a band */
@@ -120,7 +122,8 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
120122
void on_pbtnMakeBandCombinationDefault_clicked();
121123
/**This slot sets the default contrast enhancement varaible to current contrast enhancement algorithm */
122124
void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked();
123-
125+
/**This slot will sort the color map in ascending order*/
126+
void on_pbtnSortColorMap_clicked();
124127
/** Load the default style when appriate button is pressed. */
125128
void on_pbnLoadDefaultStyle_clicked();
126129
/** Save the default style when appriate button is pressed. */

src/ui/qgsrasterlayerpropertiesbase.ui

+104-91
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<x>0</x>
77
<y>0</y>
88
<width>596</width>
9-
<height>610</height>
9+
<height>658</height>
1010
</rect>
1111
</property>
1212
<property name="windowTitle" >
@@ -1199,56 +1199,7 @@
11991199
<string>Colormap</string>
12001200
</attribute>
12011201
<layout class="QGridLayout" >
1202-
<item row="0" column="0" colspan="2" >
1203-
<layout class="QHBoxLayout" >
1204-
<property name="leftMargin" >
1205-
<number>11</number>
1206-
</property>
1207-
<property name="topMargin" >
1208-
<number>11</number>
1209-
</property>
1210-
<property name="rightMargin" >
1211-
<number>11</number>
1212-
</property>
1213-
<property name="bottomMargin" >
1214-
<number>11</number>
1215-
</property>
1216-
<item>
1217-
<widget class="QLabel" name="mNumberOfEntriesLabel" >
1218-
<property name="text" >
1219-
<string>Number of entries</string>
1220-
</property>
1221-
</widget>
1222-
</item>
1223-
<item>
1224-
<widget class="QSpinBox" name="sboxNumberOfEntries" >
1225-
<property name="sizePolicy" >
1226-
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
1227-
<horstretch>0</horstretch>
1228-
<verstretch>0</verstretch>
1229-
</sizepolicy>
1230-
</property>
1231-
<property name="maximum" >
1232-
<number>256</number>
1233-
</property>
1234-
</widget>
1235-
</item>
1236-
</layout>
1237-
</item>
1238-
<item row="0" column="2" >
1239-
<spacer>
1240-
<property name="orientation" >
1241-
<enum>Qt::Horizontal</enum>
1242-
</property>
1243-
<property name="sizeHint" >
1244-
<size>
1245-
<width>71</width>
1246-
<height>20</height>
1247-
</size>
1248-
</property>
1249-
</spacer>
1250-
</item>
1251-
<item row="0" column="3" colspan="4" >
1202+
<item row="0" column="0" colspan="3" >
12521203
<layout class="QHBoxLayout" >
12531204
<property name="leftMargin" >
12541205
<number>11</number>
@@ -1274,73 +1225,54 @@
12741225
</item>
12751226
</layout>
12761227
</item>
1277-
<item row="1" column="0" colspan="3" >
1228+
<item row="0" column="3" colspan="6" >
12781229
<spacer>
12791230
<property name="orientation" >
12801231
<enum>Qt::Horizontal</enum>
12811232
</property>
12821233
<property name="sizeHint" >
12831234
<size>
1284-
<width>61</width>
1285-
<height>20</height>
1235+
<width>321</width>
1236+
<height>45</height>
12861237
</size>
12871238
</property>
12881239
</spacer>
12891240
</item>
1290-
<item row="1" column="3" colspan="4" >
1291-
<layout class="QHBoxLayout" >
1292-
<property name="leftMargin" >
1293-
<number>11</number>
1294-
</property>
1295-
<property name="topMargin" >
1296-
<number>11</number>
1297-
</property>
1298-
<property name="rightMargin" >
1299-
<number>11</number>
1300-
</property>
1301-
<property name="bottomMargin" >
1302-
<number>11</number>
1303-
</property>
1304-
<item>
1305-
<widget class="QLabel" name="mClassificationModeLabel" >
1306-
<property name="text" >
1307-
<string>Classification mode</string>
1308-
</property>
1309-
</widget>
1310-
</item>
1311-
<item>
1312-
<widget class="QComboBox" name="cboxClassificationMode" />
1313-
</item>
1314-
</layout>
1315-
</item>
1316-
<item row="2" column="0" >
1317-
<widget class="QPushButton" name="mClassifyButton" >
1241+
<item row="1" column="0" >
1242+
<widget class="QPushButton" name="pbtnAddColorMapEntry" >
13181243
<property name="text" >
1319-
<string>Classify</string>
1244+
<string>Add entry</string>
13201245
</property>
13211246
</widget>
13221247
</item>
1323-
<item row="2" column="1" >
1248+
<item row="1" column="1" >
13241249
<widget class="QPushButton" name="mDeleteEntryButton" >
13251250
<property name="text" >
13261251
<string>Delete entry</string>
13271252
</property>
13281253
</widget>
13291254
</item>
1330-
<item row="2" column="2" >
1255+
<item row="1" column="2" colspan="2" >
1256+
<widget class="QPushButton" name="pbtnSortColorMap" >
1257+
<property name="text" >
1258+
<string>Sort</string>
1259+
</property>
1260+
</widget>
1261+
</item>
1262+
<item row="1" column="4" >
13311263
<spacer>
13321264
<property name="orientation" >
13331265
<enum>Qt::Horizontal</enum>
13341266
</property>
13351267
<property name="sizeHint" >
13361268
<size>
1337-
<width>211</width>
1269+
<width>41</width>
13381270
<height>27</height>
13391271
</size>
13401272
</property>
13411273
</spacer>
13421274
</item>
1343-
<item row="2" column="3" >
1275+
<item row="1" column="5" >
13441276
<layout class="QHBoxLayout" >
13451277
<property name="leftMargin" >
13461278
<number>11</number>
@@ -1363,11 +1295,14 @@
13631295
</item>
13641296
</layout>
13651297
</item>
1366-
<item row="2" column="4" >
1298+
<item row="1" column="6" >
13671299
<spacer>
13681300
<property name="orientation" >
13691301
<enum>Qt::Horizontal</enum>
13701302
</property>
1303+
<property name="sizeType" >
1304+
<enum>QSizePolicy::Minimum</enum>
1305+
</property>
13711306
<property name="sizeHint" >
13721307
<size>
13731308
<width>20</width>
@@ -1376,7 +1311,7 @@
13761311
</property>
13771312
</spacer>
13781313
</item>
1379-
<item row="2" column="5" >
1314+
<item row="1" column="7" >
13801315
<widget class="QToolButton" name="pbtnLoadColorMapFromFile" >
13811316
<property name="toolTip" >
13821317
<string>Load color map from file</string>
@@ -1389,7 +1324,7 @@
13891324
</property>
13901325
</widget>
13911326
</item>
1392-
<item row="2" column="6" >
1327+
<item row="1" column="8" >
13931328
<widget class="QToolButton" name="pbtnExportColorMapToFile" >
13941329
<property name="toolTip" >
13951330
<string>Export color map to file</string>
@@ -1402,7 +1337,7 @@
14021337
</property>
14031338
</widget>
14041339
</item>
1405-
<item row="3" column="0" colspan="7" >
1340+
<item row="2" column="0" colspan="9" >
14061341
<widget class="QTreeWidget" name="mColormapTreeWidget" >
14071342
<property name="columnCount" >
14081343
<number>3</number>
@@ -1424,6 +1359,84 @@
14241359
</column>
14251360
</widget>
14261361
</item>
1362+
<item row="3" column="0" colspan="9" >
1363+
<widget class="QGroupBox" name="groupBox_9" >
1364+
<property name="title" >
1365+
<string>Generate new color map</string>
1366+
</property>
1367+
<layout class="QHBoxLayout" >
1368+
<item>
1369+
<layout class="QHBoxLayout" >
1370+
<property name="leftMargin" >
1371+
<number>11</number>
1372+
</property>
1373+
<property name="topMargin" >
1374+
<number>11</number>
1375+
</property>
1376+
<property name="rightMargin" >
1377+
<number>11</number>
1378+
</property>
1379+
<property name="bottomMargin" >
1380+
<number>11</number>
1381+
</property>
1382+
<item>
1383+
<widget class="QLabel" name="mNumberOfEntriesLabel" >
1384+
<property name="text" >
1385+
<string>Number of entries</string>
1386+
</property>
1387+
</widget>
1388+
</item>
1389+
<item>
1390+
<widget class="QSpinBox" name="sboxNumberOfEntries" >
1391+
<property name="sizePolicy" >
1392+
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
1393+
<horstretch>0</horstretch>
1394+
<verstretch>0</verstretch>
1395+
</sizepolicy>
1396+
</property>
1397+
<property name="maximum" >
1398+
<number>256</number>
1399+
</property>
1400+
</widget>
1401+
</item>
1402+
</layout>
1403+
</item>
1404+
<item>
1405+
<layout class="QHBoxLayout" >
1406+
<property name="leftMargin" >
1407+
<number>11</number>
1408+
</property>
1409+
<property name="topMargin" >
1410+
<number>11</number>
1411+
</property>
1412+
<property name="rightMargin" >
1413+
<number>11</number>
1414+
</property>
1415+
<property name="bottomMargin" >
1416+
<number>11</number>
1417+
</property>
1418+
<item>
1419+
<widget class="QLabel" name="mClassificationModeLabel" >
1420+
<property name="text" >
1421+
<string>Classification mode</string>
1422+
</property>
1423+
</widget>
1424+
</item>
1425+
<item>
1426+
<widget class="QComboBox" name="cboxClassificationMode" />
1427+
</item>
1428+
</layout>
1429+
</item>
1430+
<item>
1431+
<widget class="QPushButton" name="mClassifyButton" >
1432+
<property name="text" >
1433+
<string>Classify</string>
1434+
</property>
1435+
</widget>
1436+
</item>
1437+
</layout>
1438+
</widget>
1439+
</item>
14271440
</layout>
14281441
</widget>
14291442
<widget class="QWidget" name="tabPageGeneral" >

0 commit comments

Comments
 (0)