Skip to content
Permalink
Browse files
Rework paletted raster renderer widget
- Switch to a real model
- Allow adding new rows and deleting multiple selected rows
- Allow changing colors inline in style dock (no modal color picker)
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent a157db7 commit b7cd9dcb56cdaa34be265a417ac157e95d9efe22
@@ -32,6 +32,7 @@ class QgsPalettedRasterRenderer : QgsRasterRenderer
void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems /Out/ ) const;

QList<int> usesBands() const;
static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );

private:

@@ -255,6 +255,18 @@ QList<int> QgsPalettedRasterRenderer::usesBands() const
return bandList;
}

QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table )
{
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = table.constBegin();
QgsPalettedRasterRenderer::ClassData classes;
for ( ; colorIt != table.constEnd(); ++colorIt )
{
int idx = ( int )( colorIt->value );
classes.insert( idx, QgsPalettedRasterRenderer::Class( colorIt->color, colorIt->label ) );
}
return classes;
}

void QgsPalettedRasterRenderer::updateArrays()
{
// find maximum color index
@@ -263,6 +275,7 @@ void QgsPalettedRasterRenderer::updateArrays()
{
mMaxColorIndex = qMax( mMaxColorIndex, mIt.key() );
}
mMaxColorIndex = qMax( 0, mMaxColorIndex );

delete [] mColors;
delete [] mIsNoData;
@@ -22,6 +22,7 @@
#include <QVector>

#include "qgsrasterrenderer.h"
#include "qgscolorrampshader.h"

class QColor;
class QDomElement;
@@ -89,6 +90,12 @@ class CORE_EXPORT QgsPalettedRasterRenderer: public QgsRasterRenderer

QList<int> usesBands() const override;

/**
* Converts a raster color \a table to paletted renderer class data.
* @note added in QGIS 3.0
*/
static QgsPalettedRasterRenderer::ClassData colorTableToClassData( const QList<QgsColorRampShader::ColorRampItem> &table );

private:

int mBand;
@@ -100,8 +107,6 @@ class CORE_EXPORT QgsPalettedRasterRenderer: public QgsRasterRenderer
QRgb *mColors = nullptr;
bool *mIsNoData = nullptr;
void updateArrays();


};

#endif // QGSPALETTEDRASTERRENDERER_H
@@ -122,16 +122,7 @@ QgsRasterRenderer *QgsRasterRendererRegistry::defaultRendererForDrawingStyle( Qg
case QgsRaster::PalettedColor:
{
int grayBand = 1; //reasonable default
QList<QgsColorRampShader::ColorRampItem> colorEntries = provider->colorTable( grayBand );

QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin();
QgsPalettedRasterRenderer::ClassData classes;
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
int idx = ( int )( colorIt->value );
classes.insert( idx, QgsPalettedRasterRenderer::Class( colorIt->color, colorIt->label ) );
}

QgsPalettedRasterRenderer::ClassData classes = QgsPalettedRasterRenderer::colorTableToClassData( provider->colorTable( grayBand ) );
renderer = new QgsPalettedRasterRenderer( provider,
grayBand,
classes );
Loading

0 comments on commit b7cd9dc

Please sign in to comment.