Skip to content
Permalink
Browse files
Merge pull request #2061 from vmora/convert_old_size_scale
remove SizeScale and Rotation from Advanced Menu
  • Loading branch information
nyalldawson committed May 22, 2015
2 parents f81d808 + e0098a5 commit f337d4137aaa312fea46756a631fa3040901409a
@@ -494,7 +494,7 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::clone() const
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setRotationField( rotationField() );
r->setSizeScaleField( sizeScaleField() );
r->setScaleMethod( scaleMethod() );
//r->setScaleMethod( scaleMethod() );

copyPaintEffect( r );
return r;
@@ -586,14 +586,35 @@ QgsFeatureRendererV2* QgsCategorizedSymbolRendererV2::create( QDomElement& eleme
}

QDomElement rotationElem = element.firstChildElement( "rotation" );
if ( !rotationElem.isNull() )
r->setRotationField( rotationElem.attribute( "field" ) );
if ( !rotationElem.isNull() && !rotationElem.attribute( "field" ).isEmpty() )
{
QgsCategoryList::iterator it = r->mCategories.begin();
for ( ; it != r->mCategories.end(); ++it )
{
convertSymbolRotation( it->symbol(), rotationElem.attribute( "field" ) );
}
if ( r->mSourceSymbol.data() )
{
convertSymbolRotation( r->mSourceSymbol.data(), rotationElem.attribute( "field" ) );
}
}

QDomElement sizeScaleElem = element.firstChildElement( "sizescale" );
if ( !sizeScaleElem.isNull() )
if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( "field" ).isEmpty() )
{
r->setSizeScaleField( sizeScaleElem.attribute( "field" ) );
r->setScaleMethod( QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ) );
QgsCategoryList::iterator it = r->mCategories.begin();
for ( ; it != r->mCategories.end(); ++it )
{
convertSymbolSizeScale( it->symbol(),
QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ),
sizeScaleElem.attribute( "field" ) );
}
if ( r->mSourceSymbol.data() && r->mSourceSymbol->type() == QgsSymbolV2::Marker )
{
convertSymbolSizeScale( r->mSourceSymbol.data(),
QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ),
sizeScaleElem.attribute( "field" ) );
}
}

// TODO: symbol levels
@@ -519,7 +519,7 @@ QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::clone() const
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setRotationField( rotationField() );
r->setSizeScaleField( sizeScaleField() );
r->setScaleMethod( scaleMethod() );
//r->setScaleMethod( scaleMethod() );
r->setLabelFormat( labelFormat() );
r->setGraduatedMethod( graduatedMethod() );
copyPaintEffect( r );
@@ -937,7 +937,6 @@ void QgsGraduatedSymbolRendererV2::updateClasses( QgsVectorLayer *vlayer, Mode m
updateColorRamp( 0, mInvertedColorRamp );
}


QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::create( QDomElement& element )
{
QDomElement symbolsElem = element.firstChildElement( "symbols" );
@@ -1027,13 +1026,34 @@ QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2::create( QDomElement& element
}

QDomElement rotationElem = element.firstChildElement( "rotation" );
if ( !rotationElem.isNull() )
r->setRotationField( rotationElem.attribute( "field" ) );
if ( !rotationElem.isNull() && !rotationElem.attribute( "field" ).isEmpty() )
{
for ( QgsRangeList::iterator it = r->mRanges.begin(); it != r->mRanges.end(); ++it )
{
convertSymbolRotation( it->symbol(), rotationElem.attribute( "field" ) );
}
if ( r->mSourceSymbol.data() )
{
convertSymbolRotation( r->mSourceSymbol.data(), rotationElem.attribute( "field" ) );
}
}

QDomElement sizeScaleElem = element.firstChildElement( "sizescale" );
if ( !sizeScaleElem.isNull() )
r->setSizeScaleField( sizeScaleElem.attribute( "field" ) );
r->setScaleMethod( QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ) );
if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( "field" ).isEmpty() )
{
for ( QgsRangeList::iterator it = r->mRanges.begin(); it != r->mRanges.end(); ++it )
{
convertSymbolSizeScale( it->symbol(),
QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ),
sizeScaleElem.attribute( "field" ) );
}
if ( r->mSourceSymbol.data() && r->mSourceSymbol->type() == QgsSymbolV2::Marker )
{
convertSymbolSizeScale( r->mSourceSymbol.data(),
QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ),
sizeScaleElem.attribute( "field" ) );
}
}

QDomElement labelFormatElem = element.firstChildElement( "labelformat" );
if ( ! labelFormatElem.isNull() )
@@ -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, QgsSymbolV2::ScaleMethod 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 );
}
}
@@ -19,6 +19,7 @@
#include "qgis.h"
#include "qgsrectangle.h"
#include "qgsrendercontext.h"
#include "qgssymbolv2.h"

#include <QList>
#include <QString>
@@ -28,7 +29,6 @@
#include <QDomDocument>
#include <QDomElement>

class QgsSymbolV2;
class QgsFeature;
class QgsFields;
class QgsVectorLayer;
@@ -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, QgsSymbolV2::ScaleMethod 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 )
};
@@ -185,7 +185,7 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone() const
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setRotationField( rotationField() );
r->setSizeScaleField( sizeScaleField() );
r->setScaleMethod( scaleMethod() );
//r->setScaleMethod( scaleMethod() );
copyPaintEffect( r );
return r;
}
@@ -216,6 +216,7 @@ QgsSymbolV2List QgsSingleSymbolRendererV2::symbols()
return lst;
}


QgsFeatureRendererV2* QgsSingleSymbolRendererV2::create( QDomElement& element )
{
QDomElement symbolsElem = element.firstChildElement( "symbols" );
@@ -233,14 +234,17 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::create( QDomElement& element )
QgsSymbolLayerV2Utils::clearSymbolMap( symbolMap );

QDomElement rotationElem = element.firstChildElement( "rotation" );
if ( !rotationElem.isNull() )
r->setRotationField( rotationElem.attribute( "field" ) );
if ( !rotationElem.isNull() && !rotationElem.attribute( "field" ).isEmpty() )
{
convertSymbolRotation( r->mSymbol.data(), rotationElem.attribute( "field" ) );
}

QDomElement sizeScaleElem = element.firstChildElement( "sizescale" );
if ( !sizeScaleElem.isNull() )
if ( !sizeScaleElem.isNull() && !sizeScaleElem.attribute( "field" ).isEmpty() )
{
r->setSizeScaleField( sizeScaleElem.attribute( "field" ) );
r->setScaleMethod( QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ) );
convertSymbolSizeScale( r->mSymbol.data(),
QgsSymbolLayerV2Utils::decodeScaleMethod( sizeScaleElem.attribute( "scalemethod" ) ),
sizeScaleElem.attribute( "field" ) );
}

// TODO: symbol levels
@@ -241,8 +241,11 @@ QgsRendererV2DataDefinedMenus::QgsRendererV2DataDefinedMenus( QMenu* menu, QgsVe

mSizeScaleMenu->addActions( mSizeMethodActionGroup->actions() );

menu->addMenu( mRotationMenu );
menu->addMenu( mSizeScaleMenu );
//@todo cleanup the class since Rotation and SizeScale are now
//defined using QgsDataDefinedButton
//
//menu->addMenu( mRotationMenu );
//menu->addMenu( mSizeScaleMenu );

connect( mSizeMethodActionGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( scaleMethodSelected( QAction* ) ) );
connect( mRotationAttributeActionGroup, SIGNAL( triggered( QAction* ) ), this, SLOT( rotationFieldSelected( QAction* ) ) );

0 comments on commit f337d41

Please sign in to comment.