Skip to content

Commit

Permalink
Implement some QGIS 3 TODOs for diagram API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 4, 2017
1 parent ff1bbfb commit 0ce3021
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 209 deletions.
23 changes: 21 additions & 2 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,15 @@ Use renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiag
- The deprecated diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) method has been removed.
Use diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) instead.

QgsDiagramInterpolationSettings {#qgis_api_break_3_0_QgsDiagramInterpolationSettings}
-------------------------------
- The classificationAttribute member variable was removed, and has been replaced by the classificationField variable which stores the string name.


QgsDiagramRenderer {#qgis_api_break_3_0_QgsDiagramRenderer}
------------------

- xform, fields were no longer required and are removed.
- referencedFields() no longer takes a QgsFields argument.


QgsDiagramLayerSettings {#qgis_api_break_3_0_QgsDiagramLayerSettings}
Expand All @@ -787,7 +791,15 @@ be returned in place of a null pointer.
- setCoordinateTransform() now takes a QgsCoordinateTransform object, not a pointer. Use an invalid QgsCoordinateTransform in
place of a null pointer.
- The ct member has been removed. Use coordinateTransform() and setCoordinateTransform() instead.

- The LinePlacementFlags enum was renamed to LinePlacementFlag
- The placement member variable was removed, and getPlacement() was renamed to placement()
- The placementFlags member variable was removed
- The priority member variable was removed, and getPriority() was renamed to priority()
- The zIndex member variable was removed, and getZIndex() was renamed to zIndex()
- The obstacle member variable was removed. setIsObstacle() and isObstacle() should be used instead.
- The dist member variable was removed. setDistance() and distance() should be used instead.
- The renderer member variable was removed, and getRenderer() was renamed to renderer()
- The showAll member variable was removed. setShowAllDiagrams() and showAllDiagrams() should be used instead.

QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
------------------
Expand Down Expand Up @@ -1103,6 +1115,13 @@ and the new ramp can be retrieved after executing the dialog by calling ramp().
- Some internal methods which were previously public or protected were made private.


QgsLinearlyInterpolatedDiagramRenderer {#qgis_api_break_3_0_QgsLinearlyInterpolatedDiagramRenderer}
--------------------------------------

- The classificationAttribute() and setClassificationAttribute() methods were replace by
classificationField() and setClassificationField() which use the field names instead of field
indexes.

QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
------------

Expand Down
82 changes: 27 additions & 55 deletions python/core/qgsdiagramrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class QgsDiagramLayerSettings
};

//! Line placement flags for controlling line based placements
enum LinePlacementFlags
enum LinePlacementFlag
{
OnLine,
AboveLine,
BelowLine,
MapOrientation,
};
typedef QFlags<QgsDiagramLayerSettings::LinePlacementFlag> LinePlacementFlags;

QgsDiagramLayerSettings();

Expand All @@ -44,8 +45,7 @@ class QgsDiagramLayerSettings
* @see setPlacement()
* @note added in QGIS 2.16
*/
//TODO QGIS 3.0 - rename getter to placement()
Placement getPlacement() const;
Placement placement() const;

/** Sets the diagram placement.
* @param value placement value
Expand All @@ -54,28 +54,20 @@ class QgsDiagramLayerSettings
*/
void setPlacement( Placement value );

//! Diagram placement
//TODO QGIS 3.0 - make private, rename to mPlacement
Placement placement;

/** Returns the diagram placement flags. These are only used if the diagram placement
* is set to a line type.
* @see setLinePlacementFlags()
* @note added in QGIS 2.16
*/
unsigned int linePlacementFlags() const;
LinePlacementFlags linePlacementFlags() const;

/** Sets the the diagram placement flags. These are only used if the diagram placement
* is set to a line type.
* @param flags placement value
* @see getPlacement()
* @note added in QGIS 2.16
*/
void setLinePlacementFlags( unsigned int flags );

//! Diagram placement flags
// TODO QGIS 3.0 - make private, rename to mPlacementFlags, use QFlags
unsigned int placementFlags;
void setLinePlacementFlags( LinePlacementFlags flags );

/** Returns the diagram priority.
* @returns diagram priority, where 0 = low and 10 = high
Expand All @@ -84,8 +76,7 @@ class QgsDiagramLayerSettings
* @see setPriority()
* @note added in QGIS 2.16
*/
//TODO QGIS 3.0 - rename getter to priority()
int getPriority() const;
int priority() const;

/** Sets the diagram priority.
* @param value priority, where 0 = low and 10 = high
Expand All @@ -94,21 +85,14 @@ class QgsDiagramLayerSettings
*/
void setPriority( int value );

//! Placement priority, where 0 = low and 10 = high
//! @note placement priority is shared with labeling, so diagrams with a high priority may displace labels
//! and vice-versa
// TODO QGIS 3.0 - make private, rename to mPriority
int priority;

/** Returns the diagram z-index. Diagrams (or labels) with a higher z-index are drawn over diagrams
* with a lower z-index.
* @note z-index ordering is shared with labeling, so diagrams with a high z-index may be drawn over labels
* with a low z-index and vice-versa
* @see setZIndex()
* @note added in QGIS 2.16
*/
//TODO QGIS 3.0 - rename getter to zIndex()
double getZIndex() const;
double zIndex() const;

/** Sets the diagram z-index. Diagrams (or labels) with a higher z-index are drawn over diagrams
* with a lower z-index.
Expand All @@ -118,10 +102,6 @@ class QgsDiagramLayerSettings
*/
void setZIndex( double index );

//! Z-index of diagrams, where diagrams with a higher z-index are drawn on top of diagrams with a lower z-index
// TODO QGIS 3.0 - rename to mZIndex, make private
double zIndex;

/** Returns whether the feature associated with a diagram acts as an obstacle for other labels or diagrams.
* @see setIsObstacle()
* @note added in QGIS 2.16
Expand All @@ -135,10 +115,6 @@ class QgsDiagramLayerSettings
*/
void setIsObstacle( bool isObstacle );

//! Whether associated feature acts as an obstacle for other labels or diagrams
// TODO QGIS 3.0 - rename to mObstacle, make private
bool obstacle;

/** Returns the distance between the diagram and the feature (in mm).
* @see setDistance()
* @note added in QGIS 2.16
Expand All @@ -152,35 +128,25 @@ class QgsDiagramLayerSettings
*/
void setDistance( double distance );

//! Distance between diagram and the feature (in mm)
// TODO QGIS 3.0 - make private, rename to mDistance
double dist;

/** Returns the diagram renderer associated with the layer.
* @see setRenderer()
* @note added in QGIS 2.16
*/
// TODO QGIS 3.0 - rename to renderer()
QgsDiagramRenderer* getRenderer();
QgsDiagramRenderer* renderer();

/** Returns the diagram renderer associated with the layer.
* @see setRenderer()
* @note added in QGIS 2.16
*/
// TODO QGIS 3.0 - rename to renderer()
//const QgsDiagramRenderer* getRenderer() const;
//const QgsDiagramRenderer* renderer() const;

/** Sets the diagram renderer associated with the layer.
* @param diagramRenderer diagram renderer. Ownership is transferred to the object.
* @see getRenderer()
* @see renderer()
* @note added in QGIS 2.16
*/
void setRenderer( QgsDiagramRenderer* diagramRenderer /Transfer/ );

//! Associated diagram renderer. Owned by this object.
// TODO QGIS 3.0 - make private, rename to mRenderer
QgsDiagramRenderer* renderer;

/** Returns the coordinate transform associated with the layer, or an
* invalid transform if no transformation is required.
* @see setCoordinateTransform()
Expand Down Expand Up @@ -214,10 +180,6 @@ class QgsDiagramLayerSettings
*/
void setShowAllDiagrams( bool showAllDiagrams );

//! Whether to show all diagrams, including overlapping diagrams
// TODO QGIS 3.0 - make private, rename to mShowAll
bool showAll;

void readXml( const QDomElement& elem, const QgsVectorLayer* layer );
void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;

Expand Down Expand Up @@ -329,8 +291,8 @@ class QgsDiagramInterpolationSettings
QSizeF upperSize;
double lowerValue;
double upperValue;
/** Index of the classification attribute*/
int classificationAttribute;
//! Name of the field for classification
QString classificationField;
QString classificationAttributeExpression;
bool classificationAttributeIsExpression;
};
Expand Down Expand Up @@ -368,8 +330,7 @@ class QgsDiagramRenderer
* @param fields layer fields
* @note added in QGIS 2.16
*/
//TODO QGIS 3.0 - remove need for fields parameter
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext(), const QgsFields& fields = QgsFields() ) const;
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;

void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, QPointF pos );

Expand Down Expand Up @@ -511,7 +472,7 @@ class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRenderer

QList<QString> diagramAttributes() const;

virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext(), const QgsFields& fields = QgsFields() ) const;
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;

QString rendererName() const;

Expand All @@ -527,8 +488,19 @@ class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRenderer
void setUpperSize( QSizeF s );
QSizeF upperSize() const;

int classificationAttribute() const;
void setClassificationAttribute( int index );
/**
* Returns the field name used for interpolating the diagram size.
* @see setClassificationField()
* @note added in QGIS 3.0
*/
QString classificationField() const;

/**
* Sets the field name used for interpolating the diagram size.
* @see classificationField()
* @note added in QGIS 3.0
*/
void setClassificationField( const QString& field );

QString classificationAttributeExpression() const;
void setClassificationAttributeExpression( const QString& expression );
Expand Down
13 changes: 6 additions & 7 deletions src/app/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
}
else
{
mSizeFieldExpressionWidget->setField( mLayer->fields().at( lidr->classificationAttribute() ).name() );
mSizeFieldExpressionWidget->setField( lidr->classificationField() );
}
}
}
Expand All @@ -379,15 +379,15 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
if ( dls )
{
mDiagramDistanceSpinBox->setValue( dls->distance() );
mPrioritySlider->setValue( dls->getPriority() );
mZIndexSpinBox->setValue( dls->getZIndex() );
mPrioritySlider->setValue( dls->priority() );
mZIndexSpinBox->setValue( dls->zIndex() );
mDataDefinedXComboBox->setCurrentIndex( mDataDefinedXComboBox->findData( dls->xPosColumn ) );
mDataDefinedYComboBox->setCurrentIndex( mDataDefinedYComboBox->findData( dls->yPosColumn ) );
if ( dls->xPosColumn != -1 || dls->yPosColumn != -1 )
{
mDataDefinedPositionGroupBox->setChecked( true );
}
mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( dls->getPlacement() ) );
mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( dls->placement() ) );

chkLineAbove->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::AboveLine );
chkLineBelow->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::BelowLine );
Expand Down Expand Up @@ -801,8 +801,7 @@ void QgsDiagramProperties::apply()
}
else
{
int attributeNumber = mLayer->fields().lookupField( sizeFieldNameOrExp );
dr->setClassificationAttribute( attributeNumber );
dr->setClassificationField( sizeFieldNameOrExp );
}
dr->setDiagramSettings( ds );
renderer = dr;
Expand Down Expand Up @@ -838,7 +837,7 @@ void QgsDiagramProperties::apply()
}
dls.setPlacement(( QgsDiagramLayerSettings::Placement )mPlacementComboBox->currentData().toInt() );

unsigned int flags = 0;
QgsDiagramLayerSettings::LinePlacementFlags flags = 0;
if ( chkLineAbove->isChecked() )
flags |= QgsDiagramLayerSettings::AboveLine;
if ( chkLineBelow->isChecked() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/diagram/qgspiediagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ QSizeF QgsPieDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCon
}
else
{
attrVal = feature.attributes().at( is.classificationAttribute );
attrVal = feature.attribute( is.classificationField );
}

bool ok = false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/diagram/qgstextdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ QSizeF QgsTextDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCo
}
else
{
attrVal = feature.attributes().at( is.classificationAttribute );
attrVal = feature.attribute( is.classificationField );
}

bool ok = false;
Expand Down
Loading

0 comments on commit 0ce3021

Please sign in to comment.