Skip to content
Permalink
Browse files
Add code for add/delete/sort buttons in singleband pseudocolor widget
  • Loading branch information
mhugent committed Apr 14, 2012
1 parent ba66ca6 commit b4d7a30d4474c07c520f0a3ad2fe1f44bf20d26f
@@ -138,6 +138,76 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
return new QgsSingleBandPseudoColorRenderer( mRasterLayer->dataProvider(), bandNumber, rasterShader );
}

void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_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 QgsSingleBandPseudoColorRendererWidget::on_mDeleteEntryButton_clicked()
{
QTreeWidgetItem* currentItem = mColormapTreeWidget->currentItem();
if ( currentItem )
{
delete currentItem;
}
}

void QgsSingleBandPseudoColorRendererWidget::on_mSortButton_clicked()
{
bool inserted = false;
int myCurrentIndex = 0;
int myTopLevelItemCount = mColormapTreeWidget->topLevelItemCount();
QTreeWidgetItem* myCurrentItem;
QList<QgsColorRampShader::ColorRampItem> 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 )
{
myColorRampItems.insert( myCurrentIndex, 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++;
}
}
populateColormapTreeWidget( myColorRampItems );
}

void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
{
int bandComboIndex = mBandComboBox->currentIndex();
@@ -37,6 +37,9 @@ class QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendererWidget,
void populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems );

private slots:
void on_mAddEntryButton_clicked();
void on_mDeleteEntryButton_clicked();
void on_mSortButton_clicked();
void on_mClassifyButton_clicked();
void on_mLoadFromBandButton_clicked();
void on_mLoadFromFileButton_clicked();

0 comments on commit b4d7a30

Please sign in to comment.