@@ -270,6 +270,19 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
270270
271271 // feature to the layer
272272 bool alwaysShow = mSettings .showAllDiagrams ();
273+
274+ int ddColShow = mSettings .showColumn ;
275+ if ( ddColShow >= 0 && ! feat.attribute ( ddColShow ).isNull () )
276+ {
277+ bool showOk;
278+ bool ddShow = feat.attribute ( ddColShow ).toDouble ( &showOk );
279+
280+ if ( showOk && ! ddShow )
281+ return nullptr ;
282+ }
283+
284+ // old style data defined position
285+ // TODO - remove when xPosColumn and yPosColumn are removed from QgsDiagramLayerSettings
273286 int ddColX = mSettings .xPosColumn ;
274287 int ddColY = mSettings .yPosColumn ;
275288 double ddPosX = 0.0 ;
@@ -284,32 +297,33 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
284297 {
285298 ddPos = false ;
286299 }
287- else
288- {
289- QgsCoordinateTransform ct = mSettings .coordinateTransform ();
290- if ( ct.isValid () && !ct.isShortCircuited () )
291- {
292- double z = 0 ;
293- ct.transformInPlace ( ddPosX, ddPosY, z );
294- }
295- // data defined diagram position is always centered
296- ddPosX -= diagramWidth / 2.0 ;
297- ddPosY -= diagramHeight / 2.0 ;
298- }
299300 }
300- else
301- ddPos = false ;
302301
303- int ddColShow = mSettings .showColumn ;
304- if ( ddColShow >= 0 && ! feat.attribute ( ddColShow ).isNull () )
302+ // new style data defined position
303+ if ( mSettings .properties ().hasProperty ( QgsDiagramLayerSettings::PositionX )
304+ && mSettings .properties ().property ( QgsDiagramLayerSettings::PositionX )->isActive ()
305+ && mSettings .properties ().hasProperty ( QgsDiagramLayerSettings::PositionY )
306+ && mSettings .properties ().property ( QgsDiagramLayerSettings::PositionY )->isActive () )
305307 {
306- bool showOk;
307- bool ddShow = feat.attribute ( ddColShow ).toDouble ( &showOk );
308+ ddPosX = mSettings .properties ().valueAsDouble ( QgsDiagramLayerSettings::PositionX, context.expressionContext (), ddPosX );
309+ ddPosY = mSettings .properties ().valueAsDouble ( QgsDiagramLayerSettings::PositionY, context.expressionContext (), ddPosY );
310+ ddPos = true ;
311+ }
308312
309- if ( showOk && ! ddShow )
310- return nullptr ;
313+ if ( ddPos )
314+ {
315+ QgsCoordinateTransform ct = mSettings .coordinateTransform ();
316+ if ( ct.isValid () && !ct.isShortCircuited () )
317+ {
318+ double z = 0 ;
319+ ct.transformInPlace ( ddPosX, ddPosY, z );
320+ }
321+ // data defined diagram position is always centered
322+ ddPosX -= diagramWidth / 2.0 ;
323+ ddPosY -= diagramHeight / 2.0 ;
311324 }
312325
326+
313327 QgsDiagramLabelFeature* lf = new QgsDiagramLabelFeature ( feat.id (), geomCopy, QSizeF ( diagramWidth, diagramHeight ) );
314328 lf->setHasFixedPosition ( ddPos );
315329 lf->setFixedPosition ( QgsPoint ( ddPosX, ddPosY ) );
0 commit comments