Skip to content
Permalink
Browse files
avoid duplication of function
  • Loading branch information
vmora committed May 22, 2015
1 parent 0bab3ca commit 9589a189301299ea8251b37451a2ddf07145e164
@@ -525,46 +525,6 @@ QgsSymbolV2List QgsCategorizedSymbolRendererV2::symbols()
return lst;
}

//!@note this function is duplicated in 3 cpp files, it's used to convert
//! old sizeScale expresssions to symbol level DataDefined size
inline void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
if ( QgsSymbolV2::ScaleArea == method )
{
const QgsDataDefined dd( "sqrt(" + QString::number( s->size() ) + " * (" + field + "))" );
s->setDataDefinedSize( dd );
}
else
{
const QgsDataDefined dd( QString::number( s->size() ) + " * (" + field + ")" );
s->setDataDefinedSize( dd );
}
}
else if ( symbol->type() == QgsSymbolV2::Line )
{
QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
const QgsDataDefined dd( QString::number( s->width() ) + " * (" + field + ")" );
s->setDataDefinedWidth( dd );
}
}

//!@note this function is duplicated in 3 cpp files, it's used to convert
//! old rotations expresssions to symbol level DataDefined angle
inline void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
const QgsDataDefined dd(( s->angle()
? QString::number( s->angle() ) + " + "
: QString() ) + field );
s->setDataDefinedAngle( dd );
}
}

QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::create( QDomElement& element )
{
QDomElement symbolsElem = element.firstChildElement( "symbols" );
@@ -937,46 +937,6 @@ void QgsGraduatedSymbolRendererV2::updateClasses( QgsVectorLayer *vlayer, Mode m
updateColorRamp( 0, mInvertedColorRamp );
}

//!@note this function is duplicated in 3 cpp files, it's used to convert
//! old sizeScale expresssions to symbol level DataDefined size
inline void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
if ( QgsSymbolV2::ScaleArea == method )
{
const QgsDataDefined dd( "sqrt(" + QString::number( s->size() ) + " * (" + field + "))" );
s->setDataDefinedSize( dd );
}
else
{
const QgsDataDefined dd( QString::number( s->size() ) + " * (" + field + ")" );
s->setDataDefinedSize( dd );
}
}
else if ( symbol->type() == QgsSymbolV2::Line )
{
QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
const QgsDataDefined dd( QString::number( s->width() ) + " * (" + field + ")" );
s->setDataDefinedWidth( dd );
}
}

//!@note this function is duplicated in 3 cpp files, it's used to convert
//! old rotations expresssions to symbol level DataDefined angle
inline void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
const QgsDataDefined dd(( s->angle()
? QString::number( s->angle() ) + " + "
: QString() ) + field );
s->setDataDefinedAngle( dd );
}
}

QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::create( QDomElement& element )
{
QDomElement symbolsElem = element.firstChildElement( "symbols" );
@@ -17,6 +17,7 @@
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsrulebasedrendererv2.h"
#include "qgsdatadefined.h"

#include "qgssinglesymbolrendererv2.h" // for default renderer

@@ -640,3 +641,39 @@ void QgsFeatureRendererV2::setPaintEffect( QgsPaintEffect *effect )
delete mPaintEffect;
mPaintEffect = effect;
}

void QgsFeatureRendererV2::convertSymbolSizeScale( QgsSymbolV2 * symbol, int method, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
if ( QgsSymbolV2::ScaleArea == QgsSymbolV2::ScaleMethod( method ) )
{
const QgsDataDefined dd( "sqrt(" + QString::number( s->size() ) + " * (" + field + "))" );
s->setDataDefinedSize( dd );
}
else
{
const QgsDataDefined dd( QString::number( s->size() ) + " * (" + field + ")" );
s->setDataDefinedSize( dd );
}
}
else if ( symbol->type() == QgsSymbolV2::Line )
{
QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
const QgsDataDefined dd( QString::number( s->width() ) + " * (" + field + ")" );
s->setDataDefinedWidth( dd );
}
}

void QgsFeatureRendererV2::convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
const QgsDataDefined dd(( s->angle()
? QString::number( s->angle() ) + " + "
: QString() ) + field );
s->setDataDefinedAngle( dd );
}
}
@@ -272,6 +272,15 @@ class CORE_EXPORT QgsFeatureRendererV2

QgsPaintEffect* mPaintEffect;

/**@note this function is used to convert old sizeScale expresssions to symbol
* level DataDefined size
*/
static void convertSymbolSizeScale( QgsSymbolV2 * symbol, int method, const QString & field );
/**@note this function is used to convert old rotations expresssions to symbol
* level DataDefined angle
*/
static void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field );

private:
Q_DISABLE_COPY( QgsFeatureRendererV2 )
};
@@ -216,45 +216,6 @@ QgsSymbolV2List QgsSingleSymbolRendererV2::symbols()
return lst;
}

//!@note this function is duplicated in 3 cpp files, it's used to convert
//! old sizeScale expresssions to symbol level DataDefined size
inline void convertSymbolSizeScale( QgsSymbolV2 * symbol, QgsSymbolV2::ScaleMethod method, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
if ( QgsSymbolV2::ScaleArea == method )
{
const QgsDataDefined dd( "sqrt(" + QString::number( s->size() ) + " * (" + field + "))" );
s->setDataDefinedSize( dd );
}
else
{
const QgsDataDefined dd( QString::number( s->size() ) + " * (" + field + ")" );
s->setDataDefinedSize( dd );
}
}
else if ( symbol->type() == QgsSymbolV2::Line )
{
QgsLineSymbolV2 * s = static_cast<QgsLineSymbolV2 *>( symbol );
const QgsDataDefined dd( QString::number( s->width() ) + " * (" + field + ")" );
s->setDataDefinedWidth( dd );
}
}

//!@note this function is duplicated in 3 cpp files, it's used to convert
//! old rotations expresssions to symbol level DataDefined angle
inline void convertSymbolRotation( QgsSymbolV2 * symbol, const QString & field )
{
if ( symbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2 * s = static_cast<QgsMarkerSymbolV2 *>( symbol );
const QgsDataDefined dd(( s->angle()
? QString::number( s->angle() ) + " + "
: QString() ) + field );
s->setDataDefinedAngle( dd );
}
}

QgsFeatureRendererV2* QgsSingleSymbolRendererV2::create( QDomElement& element )
{

0 comments on commit 9589a18

Please sign in to comment.