Skip to content

Commit 83139cc

Browse files
committedJan 23, 2017
Remove currently unused diagram properties, add data defined
x/y position using properties system
1 parent c23de08 commit 83139cc

File tree

4 files changed

+43
-31
lines changed

4 files changed

+43
-31
lines changed
 

‎python/core/qgsdiagramrenderer.sip

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class QgsDiagramLayerSettings
3737
/** Data definable properties.
3838
* @note added in QGIS 2.16
3939
*/
40-
enum Properties
40+
enum Property
4141
{
42-
Size, /*!< Overall diagram size*/
43-
BackgroundColor, /*!< Diagram background color*/
42+
BackgroundColor, /*!< Diagram background color */
4443
OutlineColor, /*!< Outline color */
4544
OutlineWidth, /*!< Outline width */
46-
Opacity, /*!< Diagram opacity */
45+
PositionX, /*! x-coordinate data defined diagram position */
46+
PositionY, /*! y-coordinate data defined diagram position */
4747
};
4848

4949
QgsDiagramLayerSettings();

‎src/core/qgsdiagramrenderer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ void QgsDiagramLayerSettings::init()
140140
{
141141
if ( sPropertyNameMap.isEmpty() )
142142
{
143-
sPropertyNameMap.insert( Size, "diagramSize" );
144143
sPropertyNameMap.insert( BackgroundColor, "backgroundColor" );
145144
sPropertyNameMap.insert( OutlineColor, "outlineColor" );
146145
sPropertyNameMap.insert( OutlineWidth, "outlineWidth" );
147-
sPropertyNameMap.insert( Opacity, "opacity" );
146+
sPropertyNameMap.insert( PositionX, "positionX" );
147+
sPropertyNameMap.insert( PositionY, "positionY" );
148148
}
149149
}
150150

@@ -444,8 +444,6 @@ void QgsDiagramRenderer::renderDiagram( const QgsFeature& feature, QgsRenderCont
444444

445445
if ( properties.hasActiveProperties() )
446446
{
447-
c.expressionContext().setOriginalValueVariable( s.transparency );
448-
s.transparency = properties.valueAsInt( QgsDiagramLayerSettings::Opacity, c.expressionContext(), s.transparency );
449447
c.expressionContext().setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( s.backgroundColor ) );
450448
s.backgroundColor = properties.valueAsColor( QgsDiagramLayerSettings::BackgroundColor, c.expressionContext(), s.backgroundColor );
451449
c.expressionContext().setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( s.penColor ) );

‎src/core/qgsdiagramrenderer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class CORE_EXPORT QgsDiagramLayerSettings
7878
/** Data definable properties.
7979
* @note added in QGIS 3.0
8080
*/
81-
enum Properties
81+
enum Property
8282
{
83-
Size, //!< Overall diagram size
8483
BackgroundColor, //!< Diagram background color
8584
OutlineColor, //!< Outline color
8685
OutlineWidth, //!< Outline width
87-
Opacity, //!< Diagram opacity
86+
PositionX, //! x-coordinate data defined diagram position
87+
PositionY, //! y-coordinate data defined diagram position
8888
};
8989

9090
QgsDiagramLayerSettings();

‎src/core/qgsvectorlayerdiagramprovider.cpp

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
Please sign in to comment.