Skip to content

Commit

Permalink
Fix categorised renderer does not store changes to the source symbol
Browse files Browse the repository at this point in the history
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 3744ac2
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 8 deletions.
24 changes: 24 additions & 0 deletions python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip
Expand Up @@ -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;
Expand Down Expand Up @@ -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/ );

Expand Down
28 changes: 24 additions & 4 deletions python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -969,6 +969,7 @@ void QgsCategorizedSymbolRendererV2::updateSymbols( QgsSymbolV2 * sym )
updateCategorySymbol( i, symbol );
++i;
}
setSourceSymbol( sym->clone() );
}

void QgsCategorizedSymbolRendererV2::setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod )
Expand Down
24 changes: 24 additions & 0 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 );

Expand Down
22 changes: 21 additions & 1 deletion src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Expand Up @@ -495,8 +495,8 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV

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

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3744ac2

Please sign in to comment.