Skip to content
Permalink
Browse files
Use index to render legend symbol items
  • Loading branch information
NathanW2 committed Jul 4, 2014
1 parent d8eee4e commit b4edd9d3640244b7f0928806ac2929efe745d92b
@@ -141,11 +141,11 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2

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

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

protected:
void rebuildHash();
@@ -133,11 +133,11 @@ class QgsFeatureRendererV2

//! items of symbology items in legend is checked
//! @node added in 2.5
virtual bool legendSymbolItemChecked( QString key );
virtual bool legendSymbolItemChecked( int index );

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

//! return a list of item text / symbol
//! @note: this method was added in version 1.5
@@ -750,16 +750,12 @@ bool QgsCategorizedSymbolRendererV2::legendSymbolItemsCheckable() const
return true;
}

bool QgsCategorizedSymbolRendererV2::legendSymbolItemChecked( QString key )
bool QgsCategorizedSymbolRendererV2::legendSymbolItemChecked( int index )
{
int idx = categoryIndexForLabel( key );
return idx < 0 ? true : mCategories[ idx ].renderState();
return index < 0 ? true : mCategories[ index ].renderState();
}

void QgsCategorizedSymbolRendererV2::checkLegendSymbolItem( QString key, bool state )
void QgsCategorizedSymbolRendererV2::checkLegendSymbolItem( int index, bool state )
{
int idx = categoryIndexForLabel( key );
if ( idx < 0 )
return;
updateCategoryRenderState( idx, state );
updateCategoryRenderState( index, state );
}
@@ -171,11 +171,11 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

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

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

protected:
QString mAttrName;
@@ -518,15 +518,15 @@ bool QgsFeatureRendererV2::legendSymbolItemsCheckable() const
return false;
}

bool QgsFeatureRendererV2::legendSymbolItemChecked( QString item )
bool QgsFeatureRendererV2::legendSymbolItemChecked( int index )
{
Q_UNUSED( item );
Q_UNUSED( index );
return false;
}

void QgsFeatureRendererV2::checkLegendSymbolItem( QString item, bool state )
void QgsFeatureRendererV2::checkLegendSymbolItem(int index, bool state )
{
Q_UNUSED( item );
Q_UNUSED( index );
Q_UNUSED( state );
}

@@ -156,11 +156,11 @@ class CORE_EXPORT QgsFeatureRendererV2

//! items of symbology items in legend is checked
//! @note added in 2.5
virtual bool legendSymbolItemChecked( QString key );
virtual bool legendSymbolItemChecked( int key );

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

//! return a list of item text / symbol
//! @note: this method was added in version 1.5
@@ -175,7 +175,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
if ( !r )
return QVariant();

return r->legendSymbolItemChecked( sym->name() ) ? Qt::Checked : Qt::Unchecked;
return r->legendSymbolItemChecked( index.row() ) ? Qt::Checked : Qt::Unchecked;
}
return QVariant();
}
@@ -342,7 +342,7 @@ bool QgsLayerTreeModel::setData( const QModelIndex& index, const QVariant& value
if ( !r )
return false;

r->checkLegendSymbolItem( sym->name(), value == Qt::Checked );
r->checkLegendSymbolItem( index.row(), value == Qt::Checked );

emit dataChanged( index, index );

0 comments on commit b4edd9d

Please sign in to comment.