Skip to content
Permalink
Browse files

Implement some QGIS 3 TODOs for diagram API

  • Loading branch information
nyalldawson committed Jan 4, 2017
1 parent ff1bbfb commit 0ce30217f179b6a5e6a9cb732b555001c5e1efbd
@@ -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}
@@ -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}
------------------
@@ -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}
------------

@@ -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();

@@ -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
@@ -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
@@ -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
@@ -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.
@@ -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
@@ -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
@@ -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()
@@ -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;

@@ -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;
};
@@ -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 );

@@ -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;

@@ -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 );
@@ -370,7 +370,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
}
else
{
mSizeFieldExpressionWidget->setField( mLayer->fields().at( lidr->classificationAttribute() ).name() );
mSizeFieldExpressionWidget->setField( lidr->classificationField() );
}
}
}
@@ -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 );
@@ -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;
@@ -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() )
@@ -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;
@@ -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;

0 comments on commit 0ce3021

Please sign in to comment.
You can’t perform that action at this time.