Skip to content

Commit

Permalink
remove SizeScale and Rotation from Advanced Menu
Browse files Browse the repository at this point in the history
The expressions used in old project are converted to symbol level
DadaDefined size and angle

Note that sice the aspect of a composite marker is fixed for symbol size
and angle, the aspect of the scaled symbol will change for symbols with
offsets and composite markers.
  • Loading branch information
vmora committed May 22, 2015
1 parent a32ac3d commit 0bab3ca
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 20 deletions.
74 changes: 68 additions & 6 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -525,6 +525,46 @@ 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 Expand Up @@ -586,14 +626,36 @@ 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() )
{
const QgsDataDefined dd( rotationElem.attribute( "field" ) );
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
Expand Down
73 changes: 67 additions & 6 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -937,6 +937,45 @@ 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 )
{
Expand Down Expand Up @@ -1027,13 +1066,35 @@ 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() )
{
const QgsDataDefined dd( rotationElem.attribute( "field" ) );
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() )
Expand Down
55 changes: 49 additions & 6 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -216,6 +216,46 @@ 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 )
{
QDomElement symbolsElem = element.firstChildElement( "symbols" );
Expand All @@ -233,14 +273,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
Expand Down
7 changes: 5 additions & 2 deletions src/gui/symbology-ng/qgsrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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* ) ) );
Expand Down

0 comments on commit 0bab3ca

Please sign in to comment.