Skip to content
Permalink
Browse files

Merge pull request #1556 from leyan/convertToRuleBasedSymbology

[FEATURE] Keep renderer settings when changing renderer type (where it is possible)
  • Loading branch information
wonder-sk committed Sep 13, 2014
2 parents 2313be9 + ced5ae4 commit c3db6d09889fe6d8bc96a5471c28110a4dc5d9ef
Showing with 419 additions and 83 deletions.
  1. +6 −1 python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip
  2. +5 −2 python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
  3. +7 −1 python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
  4. +6 −1 python/core/symbology-ng/qgspointdisplacementrenderer.sip
  5. +1 −1 python/core/symbology-ng/qgsrendererv2.sip
  6. +9 −1 python/core/symbology-ng/qgsrulebasedrendererv2.sip
  7. +6 −1 python/core/symbology-ng/qgssinglesymbolrendererv2.sip
  8. +22 −1 src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
  9. +7 −2 src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
  10. +21 −1 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
  11. +9 −4 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
  12. +18 −1 src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
  13. +7 −1 src/core/symbology-ng/qgsinvertedpolygonrenderer.h
  14. +19 −1 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  15. +7 −2 src/core/symbology-ng/qgspointdisplacementrenderer.h
  16. +2 −1 src/core/symbology-ng/qgsrendererv2.cpp
  17. +1 −1 src/core/symbology-ng/qgsrendererv2.h
  18. +2 −1 src/core/symbology-ng/qgsrendererv2registry.cpp
  19. +176 −4 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  20. +9 −1 src/core/symbology-ng/qgsrulebasedrendererv2.h
  21. +23 −1 src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
  22. +8 −1 src/core/symbology-ng/qgssinglesymbolrendererv2.h
  23. +4 −7 src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
  24. +4 −7 src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
  25. +8 −15 src/gui/symbology-ng/qgsinvertedpolygonrendererwidget.cpp
  26. +4 −3 src/gui/symbology-ng/qgspointdisplacementrendererwidget.cpp
  27. +13 −2 src/gui/symbology-ng/qgsrendererv2propertiesdialog.cpp
  28. +9 −9 src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
  29. +6 −9 src/gui/symbology-ng/qgssinglesymbolrendererv2widget.cpp
@@ -55,7 +55,7 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2

virtual QString dump() const;

virtual QgsFeatureRendererV2* clone() /Factory/;
virtual QgsFeatureRendererV2* clone() const /Factory/;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

@@ -147,6 +147,11 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
// @note added in 2.5
virtual void checkLegendSymbolItem( QString key, bool state = true );

//! creates a QgsCategorizedSymbolRendererV2 from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsCategorizedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer ) /Factory/;

protected:
void rebuildHash();

@@ -59,7 +59,7 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2

virtual QString dump() const;

virtual QgsFeatureRendererV2* clone() /Factory/;
virtual QgsFeatureRendererV2* clone() const /Factory/;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

@@ -173,7 +173,10 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
// @note added in 2.5
virtual void checkLegendSymbolItem( QString key, bool state = true );


//! creates a QgsGraduatedSymbolRendererV2 from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsGraduatedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer ) /Factory/;

protected:
QgsSymbolV2* symbolForValue( double value );
@@ -12,7 +12,7 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
virtual ~QgsInvertedPolygonRenderer();

/** Used to clone this feature renderer.*/
virtual QgsFeatureRendererV2* clone() /Factory/;
virtual QgsFeatureRendererV2* clone() const /Factory/;

virtual void startRender( QgsRenderContext& context, const QgsFields& fields );

@@ -81,4 +81,10 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
This will involve some CPU-demanding computations and is thus disabled by default.
*/
void setPreprocessingEnabled( bool enabled );

/** creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
@note added in 2.5
@returns a new renderer if the conversion was possible, otherwise 0.
*/
static QgsInvertedPolygonRenderer* convertFromRenderer( const QgsFeatureRendererV2* renderer ) /Factory/;
};
@@ -7,7 +7,7 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
QgsPointDisplacementRenderer( const QString& labelAttributeName = "" );
~QgsPointDisplacementRenderer();

QgsFeatureRendererV2* clone() /Factory/;
QgsFeatureRendererV2* clone() const /Factory/;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

@@ -69,6 +69,11 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
void setTolerance( double t );
double tolerance() const;

//! creates a QgsPointDisplacementRenderer from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsPointDisplacementRenderer* convertFromRenderer(const QgsFeatureRendererV2 *renderer ) /Factory/;

private:
QgsPointDisplacementRenderer( const QgsPointDisplacementRenderer & );
QgsPointDisplacementRenderer & operator=( const QgsPointDisplacementRenderer & );
@@ -71,7 +71,7 @@ class QgsFeatureRendererV2

virtual ~QgsFeatureRendererV2();

virtual QgsFeatureRendererV2* clone() = 0 /Factory/;
virtual QgsFeatureRendererV2* clone() const = 0 /Factory/;

virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );

@@ -166,7 +166,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

virtual QList<QString> usedAttributes();

virtual QgsFeatureRendererV2* clone() /Factory/;
virtual QgsFeatureRendererV2* clone() const /Factory/;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

@@ -233,6 +233,14 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
//! take a rule and create a list of new rules with intervals of scales given by the passed scale denominators
static void refineRuleScales( QgsRuleBasedRendererV2::Rule* initialRule, QList<int> scales );

//! creates a QgsRuleBasedRendererV2 from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsRuleBasedRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer ) /Factory/;

//! helper function to convert the size scale and rotation fields present in some other renderers to data defined symbology
static void convertToDataDefinedSymbology( QgsSymbolV2* symbol, QString sizeScaleField, QString rotationField );

private:
QgsRuleBasedRendererV2( const QgsRuleBasedRendererV2 & );
QgsRuleBasedRendererV2 & operator=( const QgsRuleBasedRendererV2 & );
@@ -37,7 +37,7 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2

virtual QString dump() const;

virtual QgsFeatureRendererV2* clone() /Factory/;
virtual QgsFeatureRendererV2* clone() const /Factory/;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
static QgsFeatureRendererV2* createFromSld( QDomElement& element, QGis::GeometryType geomType );
@@ -66,6 +66,11 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2
//! @note added in 2.6
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const;

//! creates a QgsSingleSymbolRendererV2 from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsSingleSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer ) /Factory/;

private:
QgsSingleSymbolRendererV2( const QgsSingleSymbolRendererV2 & );
QgsSingleSymbolRendererV2 & operator=( const QgsSingleSymbolRendererV2 & );
@@ -19,6 +19,8 @@
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsvectorcolorrampv2.h"
#include "qgspointdisplacementrenderer.h"
#include "qgsinvertedpolygonrenderer.h"

#include "qgsfeature.h"
#include "qgsvectorlayer.h"
@@ -462,7 +464,7 @@ QString QgsCategorizedSymbolRendererV2::dump() const
return s;
}

QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone()
QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone() const
{
QgsCategorizedSymbolRendererV2* r = new QgsCategorizedSymbolRendererV2( mAttrName, mCategories );
if ( mSourceSymbol.data() )
@@ -758,3 +760,22 @@ void QgsCategorizedSymbolRendererV2::checkLegendSymbolItem( QString key, bool st
}

QgsMarkerSymbolV2 QgsCategorizedSymbolRendererV2::sSkipRender;

QgsCategorizedSymbolRendererV2* QgsCategorizedSymbolRendererV2::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
if ( renderer->type() == "categorizedSymbol" )
{
return dynamic_cast<QgsCategorizedSymbolRendererV2*>( renderer->clone() );
}
if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}
return 0;
}
@@ -85,7 +85,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QString dump() const;

virtual QgsFeatureRendererV2* clone();
virtual QgsFeatureRendererV2* clone() const;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

@@ -166,7 +166,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }

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

//! item in symbology was checked
@@ -181,6 +181,11 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
//! @note added in 2.6
virtual QString legendClassificationAttribute() const { return classAttribute(); }

//! creates a QgsCategorizedSymbolRendererV2 from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsCategorizedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer );

protected:
QString mAttrName;
QgsCategoryList mCategories;
@@ -17,6 +17,8 @@
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsvectorcolorrampv2.h"
#include "qgspointdisplacementrenderer.h"
#include "qgsinvertedpolygonrenderer.h"

#include "qgsfeature.h"
#include "qgsvectorlayer.h"
@@ -357,7 +359,7 @@ QString QgsGraduatedSymbolRendererV2::dump() const
return s;
}

QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone()
QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone() const
{
QgsGraduatedSymbolRendererV2* r = new QgsGraduatedSymbolRendererV2( mAttrName, mRanges );
r->setMode( mMode );
@@ -1311,3 +1313,21 @@ void QgsGraduatedSymbolRendererV2::sortByLabel( Qt::SortOrder order )
}
}

QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
if ( renderer->type() == "graduatedSymbol" )
{
return dynamic_cast<QgsGraduatedSymbolRendererV2*>( renderer->clone() );
}
if ( renderer->type() == "pointDisplacement" )
{
const QgsPointDisplacementRenderer* pointDisplacementRenderer = dynamic_cast<const QgsPointDisplacementRenderer*>( renderer );
return convertFromRenderer( pointDisplacementRenderer->embeddedRenderer() );
}
if ( renderer->type() == "invertedPolygonRenderer" )
{
const QgsInvertedPolygonRenderer* invertedPolygonRenderer = dynamic_cast<const QgsInvertedPolygonRenderer*>( renderer );
return convertFromRenderer( invertedPolygonRenderer->embeddedRenderer() );
}
return 0;
}
@@ -83,7 +83,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QString dump() const;

virtual QgsFeatureRendererV2* clone();
virtual QgsFeatureRendererV2* clone() const;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

@@ -96,7 +96,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
QString classAttribute() const { return mAttrName; }
void setClassAttribute( QString attr ) { mAttrName = attr; }

const QgsRangeList& ranges() { return mRanges; }
const QgsRangeList& ranges() const { return mRanges; }

bool updateRangeSymbol( int rangeIndex, QgsSymbolV2* symbol );
bool updateRangeLabel( int rangeIndex, QString label );
@@ -168,7 +168,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
*/
void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );

/** Update the all symbols but leave breaks and colors. */
/** Update all the symbols but leave breaks and colors. */
void updateSymbols( QgsSymbolV2* sym );

//! @note added in 1.6
@@ -187,7 +187,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
QgsSymbolV2::ScaleMethod scaleMethod() const { return mScaleMethod; }

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

//! item in symbology was checked
@@ -202,6 +202,11 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
//! @note added in 2.6
virtual QString legendClassificationAttribute() const { return classAttribute(); }

//! creates a QgsGraduatedSymbolRendererV2 from an existing renderer.
//! @note added in 2.5
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsGraduatedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer );

protected:
QString mAttrName;
QgsRangeList mRanges;
@@ -325,7 +325,7 @@ QString QgsInvertedPolygonRenderer::dump() const
return "INVERTED [" + mSubRenderer->dump() + "]";
}

QgsFeatureRendererV2* QgsInvertedPolygonRenderer::clone()
QgsFeatureRendererV2* QgsInvertedPolygonRenderer::clone() const
{
QgsInvertedPolygonRenderer* newRenderer;
if ( mSubRenderer.isNull() )
@@ -440,3 +440,20 @@ bool QgsInvertedPolygonRenderer::willRenderFeature( QgsFeature& feat )
return mSubRenderer->willRenderFeature( feat );
}

QgsInvertedPolygonRenderer* QgsInvertedPolygonRenderer::convertFromRenderer( const QgsFeatureRendererV2 *renderer )
{
if ( renderer->type() == "invertedPolygonRenderer" )
{
return dynamic_cast<QgsInvertedPolygonRenderer*>( renderer->clone() );
}

if ( renderer->type() == "singleSymbol" ||
renderer->type() == "categorizedSymbol" ||
renderer->type() == "graduatedSymbol" ||
renderer->type() == "ruleRenderer" )
{
return new QgsInvertedPolygonRenderer( renderer->clone() );
}
return 0;
}

@@ -48,7 +48,7 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
virtual ~QgsInvertedPolygonRenderer();

/** Used to clone this feature renderer.*/
virtual QgsFeatureRendererV2* clone();
virtual QgsFeatureRendererV2* clone() const;

virtual void startRender( QgsRenderContext& context, const QgsFields& fields );

@@ -118,6 +118,12 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
*/
void setPreprocessingEnabled( bool enabled ) { mPreprocessingEnabled = enabled; }

/** creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
@note added in 2.5
@returns a new renderer if the conversion was possible, otherwise 0.
*/
static QgsInvertedPolygonRenderer* convertFromRenderer( const QgsFeatureRendererV2* renderer );

private:
/** Private copy constructor. @see clone() */
QgsInvertedPolygonRenderer( const QgsInvertedPolygonRenderer& );
@@ -22,6 +22,7 @@
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsvectorlayer.h"
#include "qgssinglesymbolrendererv2.h"

#include <QDomElement>
#include <QPainter>
@@ -49,7 +50,7 @@ QgsPointDisplacementRenderer::~QgsPointDisplacementRenderer()
delete mRenderer;
}

QgsFeatureRendererV2* QgsPointDisplacementRenderer::clone()
QgsFeatureRendererV2* QgsPointDisplacementRenderer::clone() const
{
QgsPointDisplacementRenderer* r = new QgsPointDisplacementRenderer( mLabelAttributeName );
r->setEmbeddedRenderer( mRenderer->clone() );
@@ -517,4 +518,21 @@ QgsSymbolV2* QgsPointDisplacementRenderer::firstSymbolForFeature( QgsFeatureRend
return symbolList.at( 0 );
}

QgsPointDisplacementRenderer* QgsPointDisplacementRenderer::convertFromRenderer( const QgsFeatureRendererV2* renderer )
{
if ( renderer->type() == "pointDisplacement" )
{
return dynamic_cast<QgsPointDisplacementRenderer*>( renderer->clone() );
}

if ( renderer->type() == "singleSymbol" ||
renderer->type() == "categorizedSymbol" ||
renderer->type() == "graduatedSymbol" ||
renderer->type() == "ruleRenderer" )
{
QgsPointDisplacementRenderer* pointRenderer = new QgsPointDisplacementRenderer();
pointRenderer->setEmbeddedRenderer( renderer->clone() );
return pointRenderer;
}
return 0;
}

0 comments on commit c3db6d0

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