Skip to content

Commit ce4ab58

Browse files
committedApr 15, 2013
Start cleaning data defined symbology code
1 parent 1690d6a commit ce4ab58

File tree

4 files changed

+163
-270
lines changed

4 files changed

+163
-270
lines changed
 

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 58 additions & 245 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ static QPointF _rotatedOffset( const QPointF& offset, double angle )
4848
//////
4949

5050
QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2( QString name, QColor color, QColor borderColor, double size, double angle, QgsSymbolV2::ScaleMethod scaleMethod )
51-
: mOutlineWidth( 0 ), mOutlineWidthUnit( QgsSymbolV2::MM ), mNameExpression( 0 ), mColorExpression( 0 ), mColorBorderExpression( 0 ), mOutlineWidthExpression( 0 ),
52-
mSizeExpression( 0 ), mAngleExpression( 0 ), mOffsetExpression( 0 )
51+
: mOutlineWidth( 0 ), mOutlineWidthUnit( QgsSymbolV2::MM )
5352
{
5453
mName = name;
5554
mColor = color;
@@ -162,15 +161,15 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
162161
mSelPen = QPen( selPenColor );
163162
mSelPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
164163

165-
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation;
166-
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || mSizeExpression;
164+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || dataDefinedProperty( "angle" );
165+
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || dataDefinedProperty( "size" );
167166

168167
// use caching only when:
169168
// - size, rotation, shape, color, border color is not data-defined
170169
// - drawing to screen (not printer)
171170
mUsingCache = !hasDataDefinedRotation && !hasDataDefinedSize && !context.renderContext().forceVectorOutput()
172-
&& !mNameExpression && !mColorExpression && !mColorBorderExpression && !mOutlineWidthExpression &&
173-
!mSizeExpression && !mAngleExpression;
171+
&& !dataDefinedProperty( "name" ) && !dataDefinedProperty( "color" ) && !dataDefinedProperty( "color_border" ) && !dataDefinedProperty( "outline_width" ) &&
172+
!dataDefinedProperty( "size" );
174173

175174
// use either QPolygonF or QPainterPath for drawing
176175
// TODO: find out whether drawing directly doesn't bring overhead - if not, use it for all shapes
@@ -432,9 +431,10 @@ void QgsSimpleMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& conte
432431
offsetX = mOffset.x();
433432
offsetY = mOffset.y();
434433

435-
if ( mOffsetExpression )
434+
QgsExpression* offsetExpression = expression( "offset" );
435+
if ( offsetExpression )
436436
{
437-
QPointF offset = QgsSymbolLayerV2Utils::decodePoint( mOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
437+
QPointF offset = QgsSymbolLayerV2Utils::decodePoint( offsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
438438
offsetX = offset.x();
439439
offsetY = offset.y();
440440
}
@@ -460,17 +460,19 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
460460

461461
//angle
462462
double angle = mAngle;
463-
if ( mAngleExpression )
463+
QgsExpression* angleExpression = expression( "angle" );
464+
if ( angleExpression )
464465
{
465-
angle = mAngleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
466+
angle = angleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
466467
}
467468
if ( angle )
468469
off = _rotatedOffset( off, angle );
469470

470471
//data defined shape?
471-
if ( mNameExpression )
472+
QgsExpression* nameExpression = expression( "name" );
473+
if ( nameExpression )
472474
{
473-
QString name = mNameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
475+
QString name = nameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
474476
if ( !prepareShape( name ) ) // drawing as a polygon
475477
{
476478
preparePath( name ); // drawing as a painter path
@@ -490,8 +492,10 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
490492
{
491493
QMatrix transform;
492494

493-
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || mAngleExpression;
494-
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || mSizeExpression;
495+
496+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || angleExpression;
497+
QgsExpression* sizeExpression = expression( "size" );
498+
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;
495499

496500
// move to the desired position
497501
transform.translate( point.x() + off.x(), point.y() + off.y() );
@@ -500,9 +504,9 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
500504
if ( hasDataDefinedSize )
501505
{
502506
double scaledSize = mSize;
503-
if ( mSizeExpression )
507+
if ( sizeExpression )
504508
{
505-
scaledSize = mSizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
509+
scaledSize = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
506510
}
507511
scaledSize *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
508512

@@ -525,18 +529,21 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
525529
transform.rotate( angle );
526530
}
527531

528-
if ( mColorExpression )
532+
QgsExpression* colorExpression = expression( "color" );
533+
QgsExpression* colorBorderExpression = expression( "color_border" );
534+
QgsExpression* outlineWidthExpression = expression( "outline_width" );
535+
if ( colorExpression )
529536
{
530-
mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( mColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
537+
mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
531538
}
532-
if ( mColorBorderExpression )
539+
if ( colorBorderExpression )
533540
{
534-
mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( mColorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
535-
mSelPen.setColor( QgsSymbolLayerV2Utils::decodeColor( mColorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
541+
mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
542+
mSelPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
536543
}
537-
if ( mOutlineWidthExpression )
544+
if ( outlineWidthExpression )
538545
{
539-
double outlineWidth = mOutlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
546+
double outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
540547
mPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
541548
mSelPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
542549
}
@@ -568,34 +575,27 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
568575
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
569576

570577
//data define properties
571-
if ( mNameExpression )
572-
{
573-
map["name_expression"] = mNameExpression->dump();
574-
}
575-
if ( mColorExpression )
576-
{
577-
map["color_expression"] = mColorExpression->dump();
578-
}
579-
if ( mColorBorderExpression )
580-
{
581-
map["color_border_expression"] = mColorBorderExpression->dump();
582-
}
583-
if ( mOutlineWidthExpression )
584-
{
585-
map["outline_width_expression"] = mOutlineWidthExpression->dump();
586-
}
587-
if ( mSizeExpression )
588-
{
589-
map["size_expression"] = mSizeExpression->dump();
590-
}
591-
if ( mAngleExpression )
592-
{
593-
map["angle_expression"] = mAngleExpression->dump();
594-
}
595-
if ( mOffsetExpression )
596-
{
597-
map["offset_expression"] = mOffsetExpression->dump();
598-
}
578+
const QgsExpression* nameExpression = dataDefinedProperty( "name" );
579+
if ( nameExpression )
580+
map["name_expression"] = nameExpression->dump();
581+
const QgsExpression* colorExpression = dataDefinedProperty( "color" );
582+
if ( colorExpression )
583+
map["color_expression"] = colorExpression->dump();
584+
const QgsExpression* colorBorderExpression = dataDefinedProperty( "color_border" );
585+
if ( colorBorderExpression )
586+
map["color_border_expression"] = colorBorderExpression->dump();
587+
const QgsExpression* outlineWidthExpression = dataDefinedProperty( "outline_width" );
588+
if ( outlineWidthExpression )
589+
map["outline_width_expression"] = outlineWidthExpression->dump();
590+
const QgsExpression* sizeExpression = dataDefinedProperty( "size" );
591+
if ( sizeExpression )
592+
map["size_expression"] = sizeExpression->dump();
593+
const QgsExpression* angleExpression = dataDefinedProperty( "angle" );
594+
if ( angleExpression )
595+
map["angle_expression"] = angleExpression->dump();
596+
const QgsExpression* offsetExpression = dataDefinedProperty( "offset" );
597+
if ( offsetExpression )
598+
map["offset_expression"] = offsetExpression->dump();
599599
return map;
600600
}
601601

@@ -608,35 +608,15 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
608608
m->setOutlineWidth( mOutlineWidth );
609609
m->setOutlineWidthUnit( mOutlineWidthUnit );
610610

611-
//data defined properties
612-
if ( mNameExpression )
613-
{
614-
m->setDataDefinedProperty( "name", mNameExpression->dump() );
615-
}
616-
if ( mColorExpression )
617-
{
618-
m->setDataDefinedProperty( "color", mColorExpression->dump() );
619-
}
620-
if ( mColorBorderExpression )
621-
{
622-
m->setDataDefinedProperty( "color_border", mColorBorderExpression->dump() );
623-
}
624-
if ( mOutlineWidthExpression )
625-
{
626-
m->setDataDefinedProperty( "outline_width", mOutlineWidthExpression->dump() );
627-
}
628-
if ( mSizeExpression )
629-
{
630-
m->setDataDefinedProperty( "size", mSizeExpression->dump() );
631-
}
632-
if ( mAngleExpression )
611+
QMap< QString, QgsExpression* >::const_iterator ddIt = mDataDefinedProperties.constBegin();
612+
for ( ; ddIt != mDataDefinedProperties.constEnd(); ++ddIt )
633613
{
634-
m->setDataDefinedProperty( "angle", mAngleExpression->dump() );
635-
}
636-
if ( mOffsetExpression )
637-
{
638-
m->setDataDefinedProperty( "offset", mOffsetExpression->dump() );
614+
if ( ddIt.value() )
615+
{
616+
m->setDataDefinedProperty( ddIt.key(), ddIt.value()->dump() );
617+
}
639618
}
619+
640620
return m;
641621
}
642622

@@ -728,149 +708,6 @@ QString QgsSimpleMarkerSymbolLayerV2::ogrFeatureStyle( double mmScaleFactor, dou
728708
return ogrString;
729709
}
730710

731-
const QgsExpression* QgsSimpleMarkerSymbolLayerV2::dataDefinedProperty( const QString& property ) const
732-
{
733-
if ( property == "name" )
734-
{
735-
return mNameExpression;
736-
}
737-
else if ( property == "color" )
738-
{
739-
return mColorExpression;
740-
}
741-
else if ( property == "color_border" )
742-
{
743-
return mColorBorderExpression;
744-
}
745-
else if ( property == "outline_width" )
746-
{
747-
return mOutlineWidthExpression;
748-
}
749-
else if ( property == "size" )
750-
{
751-
return mSizeExpression;
752-
}
753-
else if ( property == "angle" )
754-
{
755-
return mAngleExpression;
756-
}
757-
else if ( property == "offset" )
758-
{
759-
return mOffsetExpression;
760-
}
761-
return 0;
762-
}
763-
764-
QString QgsSimpleMarkerSymbolLayerV2::dataDefinedPropertyString( const QString& property ) const
765-
{
766-
const QgsExpression* ex = dataDefinedProperty( property );
767-
return ex ? ex->dump() : QString();
768-
}
769-
770-
void QgsSimpleMarkerSymbolLayerV2::setDataDefinedProperty( const QString& property, const QString& expressionString )
771-
{
772-
if ( property == "name" )
773-
{
774-
delete mNameExpression; mNameExpression = new QgsExpression( expressionString );
775-
}
776-
else if ( property == "color" )
777-
{
778-
delete mColorExpression; mColorExpression = new QgsExpression( expressionString );
779-
}
780-
else if ( property == "color_border" )
781-
{
782-
delete mColorBorderExpression; mColorBorderExpression = new QgsExpression( expressionString );
783-
}
784-
else if ( property == "outline_width" )
785-
{
786-
delete mOutlineWidthExpression; mOutlineWidthExpression = new QgsExpression( expressionString );
787-
}
788-
else if ( property == "size" )
789-
{
790-
delete mSizeExpression; mSizeExpression = new QgsExpression( expressionString );
791-
}
792-
else if ( property == "angle" )
793-
{
794-
delete mAngleExpression; mAngleExpression = new QgsExpression( expressionString );
795-
}
796-
else if ( property == "offset" )
797-
{
798-
delete mOffsetExpression; mOffsetExpression = new QgsExpression( expressionString );
799-
}
800-
}
801-
802-
void QgsSimpleMarkerSymbolLayerV2::removeDataDefinedProperty( const QString& property )
803-
{
804-
if ( property == "name" )
805-
{
806-
delete mNameExpression; mNameExpression = 0;
807-
}
808-
else if ( property == "color" )
809-
{
810-
delete mColorExpression; mColorExpression = 0;
811-
}
812-
else if ( property == "color_border" )
813-
{
814-
delete mColorBorderExpression; mColorBorderExpression = 0;
815-
}
816-
else if ( property == "outline_width" )
817-
{
818-
delete mOutlineWidthExpression; mOutlineWidthExpression = 0;
819-
}
820-
else if ( property == "size" )
821-
{
822-
delete mSizeExpression; mSizeExpression = 0;
823-
}
824-
else if ( property == "angle" )
825-
{
826-
delete mAngleExpression; mAngleExpression = 0;
827-
}
828-
else if ( property == "offset" )
829-
{
830-
delete mOffsetExpression; mOffsetExpression = 0;
831-
}
832-
}
833-
834-
void QgsSimpleMarkerSymbolLayerV2::removeDataDefinedProperties()
835-
{
836-
delete mNameExpression; mNameExpression = 0;
837-
delete mColorExpression; mColorExpression = 0;
838-
delete mColorBorderExpression; mColorBorderExpression = 0;
839-
delete mOutlineWidthExpression; mOutlineWidthExpression = 0;
840-
delete mSizeExpression; mSizeExpression = 0;
841-
delete mAngleExpression; mAngleExpression = 0;
842-
delete mOffsetExpression; mOffsetExpression = 0;
843-
}
844-
845-
QSet<QString> QgsSimpleMarkerSymbolLayerV2::usedAttributes() const
846-
{
847-
QSet<QString> attributes;
848-
849-
//add data defined attributes
850-
QStringList columns;
851-
if ( mNameExpression )
852-
columns.append( mNameExpression->referencedColumns() );
853-
if ( mColorExpression )
854-
columns.append( mColorExpression->referencedColumns() );
855-
if ( mColorBorderExpression )
856-
columns.append( mColorBorderExpression->referencedColumns() );
857-
if ( mOutlineWidthExpression )
858-
columns.append( mOutlineWidthExpression->referencedColumns() );
859-
if ( mSizeExpression )
860-
columns.append( mSizeExpression->referencedColumns() );
861-
if ( mAngleExpression )
862-
columns.append( mAngleExpression->referencedColumns() );
863-
if ( mOffsetExpression )
864-
columns.append( mOffsetExpression->referencedColumns() );
865-
866-
QStringList::const_iterator it = columns.constBegin();
867-
for ( ; it != columns.constEnd(); ++it )
868-
{
869-
attributes.insert( *it );
870-
}
871-
return attributes;
872-
}
873-
874711
QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::createFromSld( QDomElement &element )
875712
{
876713
QgsDebugMsg( "Entered." );
@@ -919,30 +756,6 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
919756
}
920757
}
921758

922-
void QgsSimpleMarkerSymbolLayerV2::prepareExpressions( const QgsVectorLayer* vl )
923-
{
924-
if ( !vl )
925-
{
926-
return;
927-
}
928-
929-
const QgsFields& fields = vl->pendingFields();
930-
if ( mNameExpression )
931-
mNameExpression->prepare( fields );
932-
if ( mColorExpression )
933-
mColorExpression->prepare( fields );
934-
if ( mColorBorderExpression )
935-
mColorBorderExpression->prepare( fields );
936-
if ( mOutlineWidthExpression )
937-
mOutlineWidthExpression->prepare( fields );
938-
if ( mSizeExpression )
939-
mSizeExpression->prepare( fields );
940-
if ( mAngleExpression )
941-
mAngleExpression->prepare( fields );
942-
if ( mOffsetExpression )
943-
mOffsetExpression->prepare( fields );
944-
}
945-
946759
//////////
947760

948761

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
7777
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
7878
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
7979

80-
const QgsExpression* dataDefinedProperty( const QString& property ) const;
81-
QString dataDefinedPropertyString( const QString& property ) const;
82-
void setDataDefinedProperty( const QString& property, const QString& expressionString );
83-
void removeDataDefinedProperty( const QString& property );
84-
void removeDataDefinedProperties();
85-
86-
QSet<QString> usedAttributes() const;
87-
8880
protected:
8981

9082
void drawMarker( QPainter* p, QgsSymbolV2RenderContext& context );
@@ -108,18 +100,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
108100
QImage mSelCache;
109101
bool mUsingCache;
110102

111-
//data defined properties
112-
QgsExpression* mNameExpression;
113-
QgsExpression* mColorExpression;
114-
QgsExpression* mColorBorderExpression;
115-
QgsExpression* mOutlineWidthExpression;
116-
QgsExpression* mSizeExpression;
117-
QgsExpression* mAngleExpression;
118-
QgsExpression* mOffsetExpression;
119-
120103
private:
121-
//helper functions for data defined symbology
122-
void prepareExpressions( const QgsVectorLayer* vl );
123104
void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
124105
};
125106

‎src/core/symbology-ng/qgssymbollayerv2.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,108 @@
1515

1616
#include "qgssymbollayerv2.h"
1717
#include "qgsclipper.h"
18+
#include "qgsexpression.h"
1819
#include "qgsrendercontext.h"
20+
#include "qgsvectorlayer.h"
1921

2022
#include <QSize>
2123
#include <QPainter>
2224
#include <QPointF>
2325
#include <QPolygonF>
2426

27+
const QgsExpression* QgsSymbolLayerV2::dataDefinedProperty( const QString& property ) const
28+
{
29+
QMap< QString, QgsExpression* >::const_iterator it = mDataDefinedProperties.find( property );
30+
if ( it != mDataDefinedProperties.constEnd() )
31+
{
32+
return it.value();
33+
}
34+
return 0;
35+
}
36+
37+
QgsExpression* QgsSymbolLayerV2::expression( const QString& property )
38+
{
39+
QMap< QString, QgsExpression* >::iterator it = mDataDefinedProperties.find( property );
40+
if ( it != mDataDefinedProperties.end() )
41+
{
42+
return it.value();
43+
}
44+
return 0;
45+
}
46+
47+
QString QgsSymbolLayerV2::dataDefinedPropertyString( const QString& property ) const
48+
{
49+
const QgsExpression* ex = dataDefinedProperty( property );
50+
return ex ? ex->dump() : QString();
51+
}
52+
53+
void QgsSymbolLayerV2::setDataDefinedProperty( const QString& property, const QString& expressionString )
54+
{
55+
removeDataDefinedProperty( property );
56+
mDataDefinedProperties.insert( property, new QgsExpression( expressionString ) );
57+
}
58+
59+
void QgsSymbolLayerV2::removeDataDefinedProperty( const QString& property )
60+
{
61+
QMap< QString, QgsExpression* >::iterator it = mDataDefinedProperties.find( property );
62+
if ( it != mDataDefinedProperties.end() )
63+
{
64+
delete( it.value() );
65+
mDataDefinedProperties.erase( it );
66+
}
67+
}
68+
69+
void QgsSymbolLayerV2::removeDataDefinedProperties()
70+
{
71+
QMap< QString, QgsExpression* >::iterator it = mDataDefinedProperties.begin();
72+
for ( ; it != mDataDefinedProperties.constEnd(); ++it )
73+
{
74+
delete( it.value() );
75+
}
76+
mDataDefinedProperties.clear();
77+
}
78+
79+
void QgsSymbolLayerV2::prepareExpressions( const QgsVectorLayer* vl )
80+
{
81+
if ( !vl )
82+
{
83+
return;
84+
}
85+
86+
const QgsFields& fields = vl->pendingFields();
87+
QMap< QString, QgsExpression* >::iterator it = mDataDefinedProperties.begin();
88+
for ( ; it != mDataDefinedProperties.end(); ++it )
89+
{
90+
if ( it.value() )
91+
{
92+
it.value()->prepare( fields );
93+
}
94+
}
95+
}
96+
97+
QSet<QString> QgsSymbolLayerV2::usedAttributes() const
98+
{
99+
QSet<QString> attributes;
100+
QStringList columns;
101+
102+
QMap< QString, QgsExpression* >::const_iterator ddIt = mDataDefinedProperties.constBegin();
103+
for ( ; ddIt != mDataDefinedProperties.constEnd(); ++ddIt )
104+
{
105+
if ( ddIt.value() )
106+
{
107+
columns.append( ddIt.value()->referencedColumns() );
108+
}
109+
}
110+
111+
QStringList::const_iterator it = columns.constBegin();
112+
for ( ; it != columns.constEnd(); ++it )
113+
{
114+
attributes.insert( *it );
115+
}
116+
return attributes;
117+
}
118+
119+
25120
QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
26121
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM )
27122
{

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class CORE_EXPORT QgsSymbolLayerV2
7878
int renderingPass() const { return mRenderingPass; }
7979

8080
// symbol layers normally only use additional attributes to provide data defined settings
81-
virtual QSet<QString> usedAttributes() const { return QSet<QString>(); }
81+
virtual QSet<QString> usedAttributes() const;
8282

83-
virtual const QgsExpression* dataDefinedProperty( const QString& property ) const { Q_UNUSED( property ); return 0; } //= 0;
84-
virtual QString dataDefinedPropertyString( const QString& property ) const { Q_UNUSED( property ); return QString(); } //= 0;
85-
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString ) { Q_UNUSED( property ); Q_UNUSED( expressionString ); } //=0;
86-
virtual void removeDataDefinedProperty( const QString& property ) { Q_UNUSED( property ); } //=0;
87-
virtual void removeDataDefinedProperties() {} //=0;
83+
virtual const QgsExpression* dataDefinedProperty( const QString& property ) const;
84+
virtual QString dataDefinedPropertyString( const QString& property ) const;
85+
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
86+
virtual void removeDataDefinedProperty( const QString& property );
87+
virtual void removeDataDefinedProperties();
8888

8989
protected:
9090
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
@@ -95,11 +95,15 @@ class CORE_EXPORT QgsSymbolLayerV2
9595
QColor mColor;
9696
int mRenderingPass;
9797

98+
QMap< QString, QgsExpression* > mDataDefinedProperties;
99+
98100
// Configuration of selected symbology implementation
99101
static const bool selectionIsOpaque = true; // Selection ignores symbol alpha
100102
static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
101103
static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
102104

105+
virtual void prepareExpressions( const QgsVectorLayer* vl );
106+
virtual QgsExpression* expression( const QString& property );
103107
};
104108

105109
//////////////////////

0 commit comments

Comments
 (0)
Please sign in to comment.