@@ -48,8 +48,7 @@ static QPointF _rotatedOffset( const QPointF& offset, double angle )
48
48
// ////
49
49
50
50
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 )
53
52
{
54
53
mName = name;
55
54
mColor = color;
@@ -162,15 +161,15 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
162
161
mSelPen = QPen ( selPenColor );
163
162
mSelPen .setWidthF ( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context.renderContext (), mOutlineWidthUnit ) );
164
163
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 " ) ;
167
166
168
167
// use caching only when:
169
168
// - size, rotation, shape, color, border color is not data-defined
170
169
// - drawing to screen (not printer)
171
170
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 " ) ;
174
173
175
174
// use either QPolygonF or QPainterPath for drawing
176
175
// 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
432
431
offsetX = mOffset .x ();
433
432
offsetY = mOffset .y ();
434
433
435
- if ( mOffsetExpression )
434
+ QgsExpression* offsetExpression = expression ( " offset" );
435
+ if ( offsetExpression )
436
436
{
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 () );
438
438
offsetX = offset.x ();
439
439
offsetY = offset.y ();
440
440
}
@@ -460,17 +460,19 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
460
460
461
461
// angle
462
462
double angle = mAngle ;
463
- if ( mAngleExpression )
463
+ QgsExpression* angleExpression = expression ( " angle" );
464
+ if ( angleExpression )
464
465
{
465
- angle = mAngleExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toDouble ();
466
+ angle = angleExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toDouble ();
466
467
}
467
468
if ( angle )
468
469
off = _rotatedOffset ( off, angle );
469
470
470
471
// data defined shape?
471
- if ( mNameExpression )
472
+ QgsExpression* nameExpression = expression ( " name" );
473
+ if ( nameExpression )
472
474
{
473
- QString name = mNameExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toString ();
475
+ QString name = nameExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toString ();
474
476
if ( !prepareShape ( name ) ) // drawing as a polygon
475
477
{
476
478
preparePath ( name ); // drawing as a painter path
@@ -490,8 +492,10 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
490
492
{
491
493
QMatrix transform;
492
494
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;
495
499
496
500
// move to the desired position
497
501
transform.translate ( point.x () + off.x (), point.y () + off.y () );
@@ -500,9 +504,9 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
500
504
if ( hasDataDefinedSize )
501
505
{
502
506
double scaledSize = mSize ;
503
- if ( mSizeExpression )
507
+ if ( sizeExpression )
504
508
{
505
- scaledSize = mSizeExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toDouble ();
509
+ scaledSize = sizeExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toDouble ();
506
510
}
507
511
scaledSize *= QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context.renderContext (), mSizeUnit );
508
512
@@ -525,18 +529,21 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
525
529
transform.rotate ( angle );
526
530
}
527
531
528
- if ( mColorExpression )
532
+ QgsExpression* colorExpression = expression ( " color" );
533
+ QgsExpression* colorBorderExpression = expression ( " color_border" );
534
+ QgsExpression* outlineWidthExpression = expression ( " outline_width" );
535
+ if ( colorExpression )
529
536
{
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 () ) );
531
538
}
532
- if ( mColorBorderExpression )
539
+ if ( colorBorderExpression )
533
540
{
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 () ) );
536
543
}
537
- if ( mOutlineWidthExpression )
544
+ if ( outlineWidthExpression )
538
545
{
539
- double outlineWidth = mOutlineWidthExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toDouble ();
546
+ double outlineWidth = outlineWidthExpression ->evaluate ( const_cast <QgsFeature*>( context.feature () ) ).toDouble ();
540
547
mPen .setWidthF ( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context.renderContext (), mOutlineWidthUnit ) );
541
548
mSelPen .setWidthF ( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context.renderContext (), mOutlineWidthUnit ) );
542
549
}
@@ -568,34 +575,27 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
568
575
map[" outline_width_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mOutlineWidthUnit );
569
576
570
577
// 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 ();
599
599
return map;
600
600
}
601
601
@@ -608,35 +608,15 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
608
608
m->setOutlineWidth ( mOutlineWidth );
609
609
m->setOutlineWidthUnit ( mOutlineWidthUnit );
610
610
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 )
633
613
{
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
+ }
639
618
}
619
+
640
620
return m;
641
621
}
642
622
@@ -728,149 +708,6 @@ QString QgsSimpleMarkerSymbolLayerV2::ogrFeatureStyle( double mmScaleFactor, dou
728
708
return ogrString;
729
709
}
730
710
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
-
874
711
QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::createFromSld ( QDomElement &element )
875
712
{
876
713
QgsDebugMsg ( " Entered." );
@@ -919,30 +756,6 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
919
756
}
920
757
}
921
758
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
-
946
759
// ////////
947
760
948
761
0 commit comments