@@ -138,6 +138,76 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
138
138
return new QgsSingleBandPseudoColorRenderer ( mRasterLayer ->dataProvider (), bandNumber, rasterShader );
139
139
}
140
140
141
+ void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_clicked ()
142
+ {
143
+ QTreeWidgetItem* newItem = new QTreeWidgetItem ( mColormapTreeWidget );
144
+ newItem->setText ( 0 , " 0.0" );
145
+ newItem->setBackground ( 1 , QBrush ( QColor ( Qt::magenta ) ) );
146
+ newItem->setText ( 2 , tr ( " Custom color map entry" ) );
147
+ }
148
+
149
+ void QgsSingleBandPseudoColorRendererWidget::on_mDeleteEntryButton_clicked ()
150
+ {
151
+ QTreeWidgetItem* currentItem = mColormapTreeWidget ->currentItem ();
152
+ if ( currentItem )
153
+ {
154
+ delete currentItem;
155
+ }
156
+ }
157
+
158
+ void QgsSingleBandPseudoColorRendererWidget::on_mSortButton_clicked ()
159
+ {
160
+ bool inserted = false ;
161
+ int myCurrentIndex = 0 ;
162
+ int myTopLevelItemCount = mColormapTreeWidget ->topLevelItemCount ();
163
+ QTreeWidgetItem* myCurrentItem;
164
+ QList<QgsColorRampShader::ColorRampItem> myColorRampItems;
165
+ for ( int i = 0 ; i < myTopLevelItemCount; ++i )
166
+ {
167
+ myCurrentItem = mColormapTreeWidget ->topLevelItem ( i );
168
+ // If the item is null or does not have a pixel values set, skip
169
+ if ( !myCurrentItem || myCurrentItem->text ( 0 ) == " " )
170
+ {
171
+ continue ;
172
+ }
173
+
174
+ // Create a copy of the new Color ramp Item
175
+ QgsColorRampShader::ColorRampItem myNewColorRampItem;
176
+ myNewColorRampItem.value = myCurrentItem->text ( 0 ).toDouble ();
177
+ myNewColorRampItem.color = myCurrentItem->background ( 1 ).color ();
178
+ myNewColorRampItem.label = myCurrentItem->text ( 2 );
179
+
180
+ // Simple insertion sort - speed is not a huge factor here
181
+ inserted = false ;
182
+ myCurrentIndex = 0 ;
183
+ while ( !inserted )
184
+ {
185
+ if ( 0 == myColorRampItems.size () || myCurrentIndex == myColorRampItems.size () )
186
+ {
187
+ myColorRampItems.push_back ( myNewColorRampItem );
188
+ inserted = true ;
189
+ }
190
+ else if ( myColorRampItems[myCurrentIndex].value > myNewColorRampItem.value )
191
+ {
192
+ myColorRampItems.insert ( myCurrentIndex, myNewColorRampItem );
193
+ inserted = true ;
194
+ }
195
+ else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myCurrentIndex == myColorRampItems.size () - 1 )
196
+ {
197
+ myColorRampItems.push_back ( myNewColorRampItem );
198
+ inserted = true ;
199
+ }
200
+ else if ( myColorRampItems[myCurrentIndex].value <= myNewColorRampItem.value && myColorRampItems[myCurrentIndex+1 ].value > myNewColorRampItem.value )
201
+ {
202
+ myColorRampItems.insert ( myCurrentIndex + 1 , myNewColorRampItem );
203
+ inserted = true ;
204
+ }
205
+ myCurrentIndex++;
206
+ }
207
+ }
208
+ populateColormapTreeWidget ( myColorRampItems );
209
+ }
210
+
141
211
void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked ()
142
212
{
143
213
int bandComboIndex = mBandComboBox ->currentIndex ();
0 commit comments