Skip to content
Permalink
Browse files
Remove currently unused diagram properties, add data defined
x/y position using properties system
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent c23de08 commit 83139cc40e3e91333c5ac60e27d33b41f97e7e7b
@@ -37,13 +37,13 @@ class QgsDiagramLayerSettings
/** Data definable properties.
* @note added in QGIS 2.16
*/
enum Properties
enum Property
{
Size, /*!< Overall diagram size*/
BackgroundColor, /*!< Diagram background color*/
BackgroundColor, /*!< Diagram background color */
OutlineColor, /*!< Outline color */
OutlineWidth, /*!< Outline width */
Opacity, /*!< Diagram opacity */
PositionX, /*! x-coordinate data defined diagram position */
PositionY, /*! y-coordinate data defined diagram position */
};

QgsDiagramLayerSettings();
@@ -140,11 +140,11 @@ void QgsDiagramLayerSettings::init()
{
if ( sPropertyNameMap.isEmpty() )
{
sPropertyNameMap.insert( Size, "diagramSize" );
sPropertyNameMap.insert( BackgroundColor, "backgroundColor" );
sPropertyNameMap.insert( OutlineColor, "outlineColor" );
sPropertyNameMap.insert( OutlineWidth, "outlineWidth" );
sPropertyNameMap.insert( Opacity, "opacity" );
sPropertyNameMap.insert( PositionX, "positionX" );
sPropertyNameMap.insert( PositionY, "positionY" );
}
}

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

if ( properties.hasActiveProperties() )
{
c.expressionContext().setOriginalValueVariable( s.transparency );
s.transparency = properties.valueAsInt( QgsDiagramLayerSettings::Opacity, c.expressionContext(), s.transparency );
c.expressionContext().setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( s.backgroundColor ) );
s.backgroundColor = properties.valueAsColor( QgsDiagramLayerSettings::BackgroundColor, c.expressionContext(), s.backgroundColor );
c.expressionContext().setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( s.penColor ) );
@@ -78,13 +78,13 @@ class CORE_EXPORT QgsDiagramLayerSettings
/** Data definable properties.
* @note added in QGIS 3.0
*/
enum Properties
enum Property
{
Size, //!< Overall diagram size
BackgroundColor, //!< Diagram background color
OutlineColor, //!< Outline color
OutlineWidth, //!< Outline width
Opacity, //!< Diagram opacity
PositionX, //! x-coordinate data defined diagram position
PositionY, //! y-coordinate data defined diagram position
};

QgsDiagramLayerSettings();
@@ -270,6 +270,19 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea

// feature to the layer
bool alwaysShow = mSettings.showAllDiagrams();

int ddColShow = mSettings.showColumn;
if ( ddColShow >= 0 && ! feat.attribute( ddColShow ).isNull() )
{
bool showOk;
bool ddShow = feat.attribute( ddColShow ).toDouble( &showOk );

if ( showOk && ! ddShow )
return nullptr;
}

// old style data defined position
// TODO - remove when xPosColumn and yPosColumn are removed from QgsDiagramLayerSettings
int ddColX = mSettings.xPosColumn;
int ddColY = mSettings.yPosColumn;
double ddPosX = 0.0;
@@ -284,32 +297,33 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
{
ddPos = false;
}
else
{
QgsCoordinateTransform ct = mSettings.coordinateTransform();
if ( ct.isValid() && !ct.isShortCircuited() )
{
double z = 0;
ct.transformInPlace( ddPosX, ddPosY, z );
}
//data defined diagram position is always centered
ddPosX -= diagramWidth / 2.0;
ddPosY -= diagramHeight / 2.0;
}
}
else
ddPos = false;

int ddColShow = mSettings.showColumn;
if ( ddColShow >= 0 && ! feat.attribute( ddColShow ).isNull() )
// new style data defined position
if ( mSettings.properties().hasProperty( QgsDiagramLayerSettings::PositionX )
&& mSettings.properties().property( QgsDiagramLayerSettings::PositionX )->isActive()
&& mSettings.properties().hasProperty( QgsDiagramLayerSettings::PositionY )
&& mSettings.properties().property( QgsDiagramLayerSettings::PositionY )->isActive() )
{
bool showOk;
bool ddShow = feat.attribute( ddColShow ).toDouble( &showOk );
ddPosX = mSettings.properties().valueAsDouble( QgsDiagramLayerSettings::PositionX, context.expressionContext(), ddPosX );
ddPosY = mSettings.properties().valueAsDouble( QgsDiagramLayerSettings::PositionY, context.expressionContext(), ddPosY );
ddPos = true;
}

if ( showOk && ! ddShow )
return nullptr;
if ( ddPos )
{
QgsCoordinateTransform ct = mSettings.coordinateTransform();
if ( ct.isValid() && !ct.isShortCircuited() )
{
double z = 0;
ct.transformInPlace( ddPosX, ddPosY, z );
}
//data defined diagram position is always centered
ddPosX -= diagramWidth / 2.0;
ddPosY -= diagramHeight / 2.0;
}


QgsDiagramLabelFeature* lf = new QgsDiagramLabelFeature( feat.id(), geomCopy, QSizeF( diagramWidth, diagramHeight ) );
lf->setHasFixedPosition( ddPos );
lf->setFixedPosition( QgsPoint( ddPosX, ddPosY ) );

0 comments on commit 83139cc

Please sign in to comment.