Skip to content

Commit

Permalink
avoid duplication of function
Browse files Browse the repository at this point in the history
  • Loading branch information
vmora committed May 22, 2015
1 parent 0bab3ca commit 9589a18
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 119 deletions.
40 changes: 0 additions & 40 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
40 changes: 0 additions & 40 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
37 changes: 37 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsrulebasedrendererv2.h"
#include "qgsdatadefined.h"

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

Expand Down Expand Up @@ -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 );
}
}
9 changes: 9 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
};
Expand Down
39 changes: 0 additions & 39 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down

0 comments on commit 9589a18

Please sign in to comment.