Skip to content

Commit

Permalink
Remove currently unused diagram properties, add data defined
Browse files Browse the repository at this point in the history
x/y position using properties system
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent c23de08 commit 83139cc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
8 changes: 4 additions & 4 deletions python/core/qgsdiagramrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions src/core/qgsdiagramrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
}

Expand Down Expand Up @@ -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 ) );
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsdiagramrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
54 changes: 34 additions & 20 deletions src/core/qgsvectorlayerdiagramprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ) );
Expand Down

0 comments on commit 83139cc

Please sign in to comment.