Skip to content
Permalink
Browse files
Add render state support for graduated renderer
Add check state role for graduated renderer

Sync sip bindings
  • Loading branch information
NathanW2 committed Jul 6, 2014
1 parent 9dc536a commit d4b8c407ce00019691da15ec15206ef717239c84
@@ -5,7 +5,7 @@ class QgsRendererRangeV2
%End

public:
QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol /Transfer/, QString label );
QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol /Transfer/, QString label, bool render = true );
QgsRendererRangeV2( const QgsRendererRangeV2& range );

// default dtor is ok
@@ -22,6 +22,10 @@ class QgsRendererRangeV2
void setLowerValue( double lowerValue );
void setUpperValue( double upperValue );

// @note added in 2.5
bool renderState() const;
void setRenderState( bool render );

// debugging
QString dump() const;

@@ -74,6 +78,8 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
bool updateRangeLabel( int rangeIndex, QString label );
bool updateRangeUpperValue( int rangeIndex, double value );
bool updateRangeLowerValue( int rangeIndex, double value );
//! @note added in 2.5
bool updateRangeRenderState( int rangeIndex, bool render );

void addClass( QgsSymbolV2* symbol );
//! @note available in python bindings as addClassRange
@@ -155,6 +161,19 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
//! @note added in 2.0
QgsSymbolV2::ScaleMethod scaleMethod() const;

//! items of symbology items in legend should be checkable
// @note added in 2.5
virtual bool legendSymbolItemsCheckable() const;

//! item in symbology was checked
// @note added in 2.5
virtual bool legendSymbolItemChecked( int index );

//! item in symbology was checked
// @note added in 2.5
virtual void checkLegendSymbolItem( int index, bool state = true );



protected:
QgsSymbolV2* symbolForValue( double value );
@@ -35,11 +35,12 @@ QgsRendererRangeV2::QgsRendererRangeV2()
{
}

QgsRendererRangeV2::QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label )
QgsRendererRangeV2::QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label, bool render )
: mLowerValue( lowerValue )
, mUpperValue( upperValue )
, mSymbol( symbol )
, mLabel( label )
, mRender( render )
{
}

@@ -48,6 +49,7 @@ QgsRendererRangeV2::QgsRendererRangeV2( const QgsRendererRangeV2& range )
, mUpperValue( range.mUpperValue )
, mSymbol( range.mSymbol.data() ? range.mSymbol->clone() : NULL )
, mLabel( range.mLabel )
, mRender( range.mRender )
{
}

@@ -106,6 +108,16 @@ void QgsRendererRangeV2::setLowerValue( double lowerValue )
mLowerValue = lowerValue;
}

bool QgsRendererRangeV2::renderState() const
{
return mRender;
}

void QgsRendererRangeV2::setRenderState( bool render )
{
mRender = render;
}

QString QgsRendererRangeV2::dump() const
{
return QString( "%1 - %2::%3::%4\n" ).arg( mLowerValue ).arg( mUpperValue ).arg( mLabel ).arg( mSymbol->dump() );
@@ -164,7 +176,12 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForValue( double value )
for ( QgsRangeList::iterator it = mRanges.begin(); it != mRanges.end(); ++it )
{
if ( it->lowerValue() <= value && it->upperValue() >= value )
return it->symbol();
{
if ( it->renderState() )
return it->symbol();
else
return NULL;
}
}
// the value is out of the range: return NULL instead of symbol
return NULL;
@@ -322,6 +339,14 @@ bool QgsGraduatedSymbolRendererV2::updateRangeLowerValue( int rangeIndex, double
return true;
}

bool QgsGraduatedSymbolRendererV2::updateRangeRenderState( int rangeIndex, bool value )
{
if ( rangeIndex < 0 || rangeIndex >= mRanges.size() )
return false;
mRanges[rangeIndex].setRenderState( value );
return true;
}

QString QgsGraduatedSymbolRendererV2::dump() const
{
QString s = QString( "GRADUATED: attr %1\n" ).arg( mAttrName );
@@ -1017,6 +1042,7 @@ QDomElement QgsGraduatedSymbolRendererV2::save( QDomDocument& doc )
rangeElem.setAttribute( "upper", QString::number( range.upperValue(), 'f' ) );
rangeElem.setAttribute( "symbol", symbolName );
rangeElem.setAttribute( "label", range.label() );
rangeElem.setAttribute( "render", range.renderState() ? "true" : "false" );
rangesElem.appendChild( rangeElem );
i++;
}
@@ -1200,6 +1226,25 @@ void QgsGraduatedSymbolRendererV2::setScaleMethod( QgsSymbolV2::ScaleMethod scal
}
}

bool QgsGraduatedSymbolRendererV2::legendSymbolItemsCheckable() const
{
return true;
}

bool QgsGraduatedSymbolRendererV2::legendSymbolItemChecked( int index )
{
if( index >= 0 && index < mRanges.size() )
return mRanges[ index ].renderState();
else
return true;
}

void QgsGraduatedSymbolRendererV2::checkLegendSymbolItem( int index, bool state )
{
updateRangeRenderState( index, state );
}


void QgsGraduatedSymbolRendererV2::addClass( QgsSymbolV2* symbol )
{
QgsSymbolV2* newSymbol = symbol->clone();
@@ -24,7 +24,7 @@ class CORE_EXPORT QgsRendererRangeV2
{
public:
QgsRendererRangeV2();
QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label );
QgsRendererRangeV2( double lowerValue, double upperValue, QgsSymbolV2* symbol, QString label, bool render = true );
QgsRendererRangeV2( const QgsRendererRangeV2& range );

// default dtor is ok
@@ -41,6 +41,10 @@ class CORE_EXPORT QgsRendererRangeV2
void setLowerValue( double lowerValue );
void setUpperValue( double upperValue );

// @note added in 2.5
bool renderState() const;
void setRenderState( bool render );

// debugging
QString dump() const;

@@ -50,6 +54,7 @@ class CORE_EXPORT QgsRendererRangeV2
double mLowerValue, mUpperValue;
QScopedPointer<QgsSymbolV2> mSymbol;
QString mLabel;
bool mRender;

// for cpy+swap idiom
void swap( QgsRendererRangeV2 & other );
@@ -97,6 +102,9 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
bool updateRangeLabel( int rangeIndex, QString label );
bool updateRangeUpperValue( int rangeIndex, double value );
bool updateRangeLowerValue( int rangeIndex, double value );
//! @note added in 2.5
bool updateRangeRenderState( int rangeIndex, bool render );


void addClass( QgsSymbolV2* symbol );
//! @note available in python bindings as addClassRange
@@ -178,6 +186,17 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
//! @note added in 2.0
QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }

//! items of symbology items in legend should be checkable
// @note added in 2.5
virtual bool legendSymbolItemsCheckable() const;

//! item in symbology was checked
// @note added in 2.5
virtual bool legendSymbolItemChecked( int index );

//! item in symbology was checked
// @note added in 2.5
virtual void checkLegendSymbolItem( int index, bool state = true );

protected:
QString mAttrName;
@@ -98,7 +98,7 @@ Qt::ItemFlags QgsGraduatedSymbolRendererV2Model::flags( const QModelIndex & inde
return Qt::ItemIsDropEnabled;
}

Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;

if ( index.column() == 2 )
{
@@ -120,7 +120,11 @@ QVariant QgsGraduatedSymbolRendererV2Model::data( const QModelIndex &index, int
const QgsRendererRangeV2 range = mRenderer->ranges().value( index.row() );
QString rangeStr = QString::number( range.lowerValue(), 'f', 4 ) + " - " + QString::number( range.upperValue(), 'f', 4 );

if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
if ( role == Qt::CheckStateRole && index.column() == 0 )
{
return range.renderState() ? Qt::Checked : Qt::Unchecked;
}
else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
{
switch ( index.column() )
{
@@ -152,7 +156,17 @@ QVariant QgsGraduatedSymbolRendererV2Model::data( const QModelIndex &index, int

bool QgsGraduatedSymbolRendererV2Model::setData( const QModelIndex & index, const QVariant & value, int role )
{
if ( !index.isValid() || role != Qt::EditRole )
if ( !index.isValid() )
return false;

if ( index.column() == 0 && role == Qt::CheckStateRole )
{
mRenderer->updateRangeRenderState( index.row(), value == Qt::Checked );
emit dataChanged( index, index );
return true;
}

if ( role != Qt::EditRole )
return false;

switch ( index.column() )

0 comments on commit d4b8c40

Please sign in to comment.