@@ -50,11 +50,32 @@ QgsPropertyTransformer::QgsPropertyTransformer( double minValue, double maxValue
50
50
, mMaxValue( maxValue )
51
51
{}
52
52
53
+ QgsPropertyTransformer::QgsPropertyTransformer ( const QgsPropertyTransformer& other )
54
+ : mMinValue( other.mMinValue )
55
+ , mMaxValue( other.mMaxValue )
56
+ , mCurveTransform( other.mCurveTransform ? new QgsCurveTransform( *other.mCurveTransform ) : nullptr )
57
+ {}
58
+
59
+ QgsPropertyTransformer& QgsPropertyTransformer::operator =( const QgsPropertyTransformer & other )
60
+ {
61
+ mMinValue = other.mMinValue ;
62
+ mMaxValue = other.mMaxValue ;
63
+ mCurveTransform .reset ( other.mCurveTransform ? new QgsCurveTransform ( *other.mCurveTransform ) : nullptr );
64
+ return *this ;
65
+ }
66
+
53
67
bool QgsPropertyTransformer::writeXml ( QDomElement& transformerElem, QDomDocument& doc ) const
54
68
{
55
69
Q_UNUSED ( doc );
56
70
transformerElem.setAttribute ( " minValue" , QString::number ( mMinValue ) );
57
71
transformerElem.setAttribute ( " maxValue" , QString::number ( mMaxValue ) );
72
+
73
+ if ( mCurveTransform )
74
+ {
75
+ QDomElement curveElement = doc.createElement ( " curve" );
76
+ mCurveTransform ->writeXml ( curveElement, doc );
77
+ transformerElem.appendChild ( curveElement );
78
+ }
58
79
return true ;
59
80
}
60
81
@@ -69,11 +90,35 @@ QgsPropertyTransformer* QgsPropertyTransformer::fromExpression( const QString& e
69
90
return nullptr ;
70
91
}
71
92
93
+ double QgsPropertyTransformer::transformNumeric ( double input ) const
94
+ {
95
+ if ( !mCurveTransform )
96
+ return input;
97
+
98
+ if ( qgsDoubleNear ( mMaxValue , mMinValue ) )
99
+ return input;
100
+
101
+ // convert input into target range
102
+ double scaledInput = ( input - mMinValue ) / ( mMaxValue - mMinValue );
103
+
104
+ return mMinValue + ( mMaxValue - mMinValue ) * mCurveTransform ->y ( scaledInput );
105
+ }
106
+
72
107
bool QgsPropertyTransformer::readXml ( const QDomElement &transformerElem, const QDomDocument &doc )
73
108
{
74
109
Q_UNUSED ( doc );
75
110
mMinValue = transformerElem.attribute ( " minValue" , " 0.0" ).toDouble ();
76
111
mMaxValue = transformerElem.attribute ( " maxValue" , " 1.0" ).toDouble ();
112
+ mCurveTransform .reset ( nullptr );
113
+
114
+ QDomNodeList curveNodeList = transformerElem.elementsByTagName ( " curve" );
115
+ if ( !curveNodeList.isEmpty () )
116
+ {
117
+ QDomElement curveElem = curveNodeList.at ( 0 ).toElement ();
118
+ mCurveTransform .reset ( new QgsCurveTransform () );
119
+ mCurveTransform ->readXml ( curveElem, doc );
120
+ }
121
+
77
122
return true ;
78
123
}
79
124
@@ -89,14 +134,35 @@ QgsGenericNumericTransformer::QgsGenericNumericTransformer( double minValue, dou
89
134
, mExponent( exponent )
90
135
{}
91
136
137
+ QgsGenericNumericTransformer::QgsGenericNumericTransformer ( const QgsGenericNumericTransformer& other )
138
+ : QgsPropertyTransformer( other )
139
+ , mMinOutput( other.mMinOutput )
140
+ , mMaxOutput( other.mMaxOutput )
141
+ , mNullOutput( other.mNullOutput )
142
+ , mExponent( other.mExponent )
143
+ {}
144
+
145
+ QgsGenericNumericTransformer& QgsGenericNumericTransformer::operator =( const QgsGenericNumericTransformer & other )
146
+ {
147
+ QgsPropertyTransformer::operator =( other );
148
+ mMinOutput = other.mMinOutput ;
149
+ mMaxOutput = other.mMaxOutput ;
150
+ mNullOutput = other.mNullOutput ;
151
+ mExponent = other.mExponent ;
152
+ return *this ;
153
+ }
154
+
92
155
QgsGenericNumericTransformer *QgsGenericNumericTransformer::clone ()
93
156
{
94
- return new QgsGenericNumericTransformer ( mMinValue ,
95
- mMaxValue ,
96
- mMinOutput ,
97
- mMaxOutput ,
98
- mNullOutput ,
99
- mExponent );
157
+ std::unique_ptr< QgsGenericNumericTransformer > t ( new QgsGenericNumericTransformer ( mMinValue ,
158
+ mMaxValue ,
159
+ mMinOutput ,
160
+ mMaxOutput ,
161
+ mNullOutput ,
162
+ mExponent ) );
163
+ if ( mCurveTransform )
164
+ t->setCurveTransform ( new QgsCurveTransform ( *mCurveTransform ) );
165
+ return t.release ();
100
166
}
101
167
102
168
bool QgsGenericNumericTransformer::writeXml ( QDomElement &transformerElem, QDomDocument &doc ) const
@@ -145,7 +211,7 @@ QVariant QgsGenericNumericTransformer::transform( const QgsExpressionContext& co
145
211
if ( ok )
146
212
{
147
213
// apply scaling to value
148
- return value ( dblValue );
214
+ return value ( transformNumeric ( dblValue ) );
149
215
}
150
216
else
151
217
{
@@ -257,15 +323,38 @@ QgsSizeScaleTransformer::QgsSizeScaleTransformer( ScaleType type, double minValu
257
323
setType ( type );
258
324
}
259
325
326
+ QgsSizeScaleTransformer::QgsSizeScaleTransformer ( const QgsSizeScaleTransformer& other )
327
+ : QgsPropertyTransformer( other )
328
+ , mType( other.mType )
329
+ , mMinSize( other.mMinSize )
330
+ , mMaxSize( other.mMaxSize )
331
+ , mNullSize( other.mNullSize )
332
+ , mExponent( other.mExponent )
333
+ {}
334
+
335
+ QgsSizeScaleTransformer& QgsSizeScaleTransformer::operator =( const QgsSizeScaleTransformer & other )
336
+ {
337
+ QgsPropertyTransformer::operator =( other );
338
+ mType = other.mType ;
339
+ mMinSize = other.mMinSize ;
340
+ mMaxSize = other.mMaxSize ;
341
+ mNullSize = other.mNullSize ;
342
+ mExponent = other.mExponent ;
343
+ return *this ;
344
+ }
345
+
260
346
QgsSizeScaleTransformer *QgsSizeScaleTransformer::clone ()
261
347
{
262
- return new QgsSizeScaleTransformer ( mType ,
263
- mMinValue ,
264
- mMaxValue ,
265
- mMinSize ,
266
- mMaxSize ,
267
- mNullSize ,
268
- mExponent );
348
+ std::unique_ptr< QgsSizeScaleTransformer > t ( new QgsSizeScaleTransformer ( mType ,
349
+ mMinValue ,
350
+ mMaxValue ,
351
+ mMinSize ,
352
+ mMaxSize ,
353
+ mNullSize ,
354
+ mExponent ) );
355
+ if ( mCurveTransform )
356
+ t->setCurveTransform ( new QgsCurveTransform ( *mCurveTransform ) );
357
+ return t.release ();
269
358
}
270
359
271
360
bool QgsSizeScaleTransformer::writeXml ( QDomElement &transformerElem, QDomDocument &doc ) const
@@ -344,7 +433,7 @@ QVariant QgsSizeScaleTransformer::transform( const QgsExpressionContext& context
344
433
if ( ok )
345
434
{
346
435
// apply scaling to value
347
- return size ( dblValue );
436
+ return size ( transformNumeric ( dblValue ) );
348
437
}
349
438
else
350
439
{
@@ -483,6 +572,7 @@ QgsColorRampTransformer::QgsColorRampTransformer( const QgsColorRampTransformer
483
572
484
573
QgsColorRampTransformer &QgsColorRampTransformer::operator =( const QgsColorRampTransformer & other )
485
574
{
575
+ QgsPropertyTransformer::operator =( other );
486
576
mMinValue = other.mMinValue ;
487
577
mMaxValue = other.mMaxValue ;
488
578
mGradientRamp .reset ( other.mGradientRamp ? other.mGradientRamp ->clone () : nullptr );
@@ -493,11 +583,13 @@ QgsColorRampTransformer &QgsColorRampTransformer::operator=( const QgsColorRampT
493
583
494
584
QgsColorRampTransformer* QgsColorRampTransformer::clone ()
495
585
{
496
- QgsColorRampTransformer* c = new QgsColorRampTransformer ( mMinValue , mMaxValue ,
586
+ std::unique_ptr< QgsColorRampTransformer > c ( new QgsColorRampTransformer ( mMinValue , mMaxValue ,
497
587
mGradientRamp ? mGradientRamp ->clone () : nullptr ,
498
- mNullColor );
588
+ mNullColor ) ) ;
499
589
c->setRampName ( mRampName );
500
- return c;
590
+ if ( mCurveTransform )
591
+ c->setCurveTransform ( new QgsCurveTransform ( *mCurveTransform ) );
592
+ return c.release ();
501
593
}
502
594
503
595
bool QgsColorRampTransformer::writeXml ( QDomElement &transformerElem, QDomDocument &doc ) const
@@ -546,7 +638,7 @@ QVariant QgsColorRampTransformer::transform( const QgsExpressionContext &context
546
638
if ( ok )
547
639
{
548
640
// apply scaling to value
549
- return color ( dblValue );
641
+ return color ( transformNumeric ( dblValue ) );
550
642
}
551
643
else
552
644
{
0 commit comments