Skip to content
Permalink
Browse files

Fix categorised renderer does not store changes to the source symbol

Avoids the frustrating situation where changes to a symbol in the
categorised renderer are lost when the layer properties window
is reopened

Also improve docs and fix a leak in the Python bindings
  • Loading branch information
nyalldawson committed Jan 26, 2016
1 parent 1eedb06 commit 3744ac2fc4c65dd42fa78cfbc6f4df46a6d72722
@@ -74,6 +74,12 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2

//! @note available in python as symbols2
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) /PyName=symbols2/;

/** Update all the symbols but leave categories and colors. This method also sets the source
* symbol for the renderer.
* @param sym source symbol to use for categories. Ownership is not transferred.
* @see setSourceSymbol()
*/
void updateSymbols( QgsSymbolV2 * sym );

const QgsCategoryList& categories() const;
@@ -123,13 +129,31 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2

virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );

/** Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying
* the categories' color.
* @see setSourceSymbol()
* @see sourceColorRamp()
*/
QgsSymbolV2* sourceSymbol();

/** Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbol before applying
* the categories' color.
* @param sym source symbol, ownership is transferred to the renderer
* @see sourceSymbol()
* @see setSourceColorRamp()
*/
void setSourceSymbol( QgsSymbolV2* sym /Transfer/ );

/** Returns the source color ramp, from which each categories' color is derived.
* @see setSourceColorRamp()
* @see sourceSymbol()
*/
QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
* @see sourceColorRamp()
* @see setSourceSymbol()
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp /Transfer/ );

@@ -226,14 +226,30 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2

virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );

/** Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol before applying
* the classes' color.
* @see setSourceSymbol()
* @see sourceColorRamp()
*/
QgsSymbolV2* sourceSymbol();

/** Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol before applying
* the classes' color.
* @param sym source symbol, ownership is transferred to the renderer
* @see sourceSymbol()
* @see setSourceColorRamp()
*/
void setSourceSymbol( QgsSymbolV2* sym /Transfer/ );

/** Returns the source color ramp, from which each classes' color is derived.
* @see setSourceColorRamp()
* @see sourceSymbol()
*/
QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
*/
* @param ramp color ramp. Ownership is transferred to the renderer
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp /Transfer/ );

//! @note added in 2.1
@@ -247,8 +263,12 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
*/
void updateColorRamp( QgsVectorColorRampV2* ramp /Transfer/ = 0, bool inverted = false );

/** Update all the symbols but leave breaks and colors. */
void updateSymbols( QgsSymbolV2* sym /Transfer/ );
/** Update all the symbols but leave breaks and colors. This method also sets the source
* symbol for the renderer.
* @param sym source symbol to use for classes. Ownership is not transferred.
* @see setSourceSymbol()
*/
void updateSymbols( QgsSymbolV2* sym );

//! set varying symbol size for classes
//! @note the classes must already be set so that symbols exist
@@ -969,6 +969,7 @@ void QgsCategorizedSymbolRendererV2::updateSymbols( QgsSymbolV2 * sym )
updateCategorySymbol( i, symbol );
++i;
}
setSourceSymbol( sym->clone() );
}

void QgsCategorizedSymbolRendererV2::setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod )
@@ -103,6 +103,12 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

//! @note available in python as symbols2
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) override;

/** Update all the symbols but leave categories and colors. This method also sets the source
* symbol for the renderer.
* @param sym source symbol to use for categories. Ownership is not transferred.
* @see setSourceSymbol()
*/
void updateSymbols( QgsSymbolV2 * sym );

const QgsCategoryList& categories() const { return mCategories; }
@@ -152,13 +158,31 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context ) override;

/** Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying
* the categories' color.
* @see setSourceSymbol()
* @see sourceColorRamp()
*/
QgsSymbolV2* sourceSymbol();

/** Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbol before applying
* the categories' color.
* @param sym source symbol, ownership is transferred to the renderer
* @see sourceSymbol()
* @see setSourceColorRamp()
*/
void setSourceSymbol( QgsSymbolV2* sym );

/** Returns the source color ramp, from which each categories' color is derived.
* @see setSourceColorRamp()
* @see sourceSymbol()
*/
QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
* @see sourceColorRamp()
* @see setSourceSymbol()
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp );

@@ -259,9 +259,25 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context ) override;

/** Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol before applying
* the classes' color.
* @see setSourceSymbol()
* @see sourceColorRamp()
*/
QgsSymbolV2* sourceSymbol();

/** Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol before applying
* the classes' color.
* @param sym source symbol, ownership is transferred to the renderer
* @see sourceSymbol()
* @see setSourceColorRamp()
*/
void setSourceSymbol( QgsSymbolV2* sym );

/** Returns the source color ramp, from which each classes' color is derived.
* @see setSourceColorRamp()
* @see sourceSymbol()
*/
QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
@@ -280,7 +296,11 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
*/
void updateColorRamp( QgsVectorColorRampV2* ramp = nullptr, bool inverted = false );

/** Update all the symbols but leave breaks and colors. */
/** Update all the symbols but leave breaks and colors. This method also sets the source
* symbol for the renderer.
* @param sym source symbol to use for classes. Ownership is not transferred.
* @see setSourceSymbol()
*/
void updateSymbols( QgsSymbolV2* sym );

//! set varying symbol size for classes
@@ -495,8 +495,8 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV

QgsCategorizedSymbolRendererV2Widget::~QgsCategorizedSymbolRendererV2Widget()
{
if ( mRenderer ) delete mRenderer;
if ( mModel ) delete mModel;
delete mRenderer;
delete mModel;
delete mCategorizedSymbol;
}

@@ -579,7 +579,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()

QgsSymbolV2SelectorDialog dlg( newSymbol, mStyle, mLayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( !dlg.exec() )
if ( !dlg.exec() || !newSymbol )
{
delete newSymbol;
return;

0 comments on commit 3744ac2

Please sign in to comment.
You can’t perform that action at this time.