Skip to content

Commit 0ce3021

Browse files
committed
Implement some QGIS 3 TODOs for diagram API
1 parent ff1bbfb commit 0ce3021

10 files changed

Lines changed: 186 additions & 209 deletions

‎doc/api_break.dox‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,15 @@ Use renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiag
772772
- The deprecated diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) method has been removed.
773773
Use diagramSize( const QgsFeature& feature, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is ) instead.
774774

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

776780
QgsDiagramRenderer {#qgis_api_break_3_0_QgsDiagramRenderer}
777781
------------------
778-
779782
- xform, fields were no longer required and are removed.
783+
- referencedFields() no longer takes a QgsFields argument.
780784

781785

782786
QgsDiagramLayerSettings {#qgis_api_break_3_0_QgsDiagramLayerSettings}
@@ -787,7 +791,15 @@ be returned in place of a null pointer.
787791
- setCoordinateTransform() now takes a QgsCoordinateTransform object, not a pointer. Use an invalid QgsCoordinateTransform in
788792
place of a null pointer.
789793
- The ct member has been removed. Use coordinateTransform() and setCoordinateTransform() instead.
790-
794+
- The LinePlacementFlags enum was renamed to LinePlacementFlag
795+
- The placement member variable was removed, and getPlacement() was renamed to placement()
796+
- The placementFlags member variable was removed
797+
- The priority member variable was removed, and getPriority() was renamed to priority()
798+
- The zIndex member variable was removed, and getZIndex() was renamed to zIndex()
799+
- The obstacle member variable was removed. setIsObstacle() and isObstacle() should be used instead.
800+
- The dist member variable was removed. setDistance() and distance() should be used instead.
801+
- The renderer member variable was removed, and getRenderer() was renamed to renderer()
802+
- The showAll member variable was removed. setShowAllDiagrams() and showAllDiagrams() should be used instead.
791803

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

11051117

1118+
QgsLinearlyInterpolatedDiagramRenderer {#qgis_api_break_3_0_QgsLinearlyInterpolatedDiagramRenderer}
1119+
--------------------------------------
1120+
1121+
- The classificationAttribute() and setClassificationAttribute() methods were replace by
1122+
classificationField() and setClassificationField() which use the field names instead of field
1123+
indexes.
1124+
11061125
QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
11071126
------------
11081127

‎python/core/qgsdiagramrenderer.sip‎

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ class QgsDiagramLayerSettings
2525
};
2626

2727
//! Line placement flags for controlling line based placements
28-
enum LinePlacementFlags
28+
enum LinePlacementFlag
2929
{
3030
OnLine,
3131
AboveLine,
3232
BelowLine,
3333
MapOrientation,
3434
};
35+
typedef QFlags<QgsDiagramLayerSettings::LinePlacementFlag> LinePlacementFlags;
3536

3637
QgsDiagramLayerSettings();
3738

@@ -44,8 +45,7 @@ class QgsDiagramLayerSettings
4445
* @see setPlacement()
4546
* @note added in QGIS 2.16
4647
*/
47-
//TODO QGIS 3.0 - rename getter to placement()
48-
Placement getPlacement() const;
48+
Placement placement() const;
4949

5050
/** Sets the diagram placement.
5151
* @param value placement value
@@ -54,28 +54,20 @@ class QgsDiagramLayerSettings
5454
*/
5555
void setPlacement( Placement value );
5656

57-
//! Diagram placement
58-
//TODO QGIS 3.0 - make private, rename to mPlacement
59-
Placement placement;
60-
6157
/** Returns the diagram placement flags. These are only used if the diagram placement
6258
* is set to a line type.
6359
* @see setLinePlacementFlags()
6460
* @note added in QGIS 2.16
6561
*/
66-
unsigned int linePlacementFlags() const;
62+
LinePlacementFlags linePlacementFlags() const;
6763

6864
/** Sets the the diagram placement flags. These are only used if the diagram placement
6965
* is set to a line type.
7066
* @param flags placement value
7167
* @see getPlacement()
7268
* @note added in QGIS 2.16
7369
*/
74-
void setLinePlacementFlags( unsigned int flags );
75-
76-
//! Diagram placement flags
77-
// TODO QGIS 3.0 - make private, rename to mPlacementFlags, use QFlags
78-
unsigned int placementFlags;
70+
void setLinePlacementFlags( LinePlacementFlags flags );
7971

8072
/** Returns the diagram priority.
8173
* @returns diagram priority, where 0 = low and 10 = high
@@ -84,8 +76,7 @@ class QgsDiagramLayerSettings
8476
* @see setPriority()
8577
* @note added in QGIS 2.16
8678
*/
87-
//TODO QGIS 3.0 - rename getter to priority()
88-
int getPriority() const;
79+
int priority() const;
8980

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

97-
//! Placement priority, where 0 = low and 10 = high
98-
//! @note placement priority is shared with labeling, so diagrams with a high priority may displace labels
99-
//! and vice-versa
100-
// TODO QGIS 3.0 - make private, rename to mPriority
101-
int priority;
102-
10388
/** Returns the diagram z-index. Diagrams (or labels) with a higher z-index are drawn over diagrams
10489
* with a lower z-index.
10590
* @note z-index ordering is shared with labeling, so diagrams with a high z-index may be drawn over labels
10691
* with a low z-index and vice-versa
10792
* @see setZIndex()
10893
* @note added in QGIS 2.16
10994
*/
110-
//TODO QGIS 3.0 - rename getter to zIndex()
111-
double getZIndex() const;
95+
double zIndex() const;
11296

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

121-
//! Z-index of diagrams, where diagrams with a higher z-index are drawn on top of diagrams with a lower z-index
122-
// TODO QGIS 3.0 - rename to mZIndex, make private
123-
double zIndex;
124-
125105
/** Returns whether the feature associated with a diagram acts as an obstacle for other labels or diagrams.
126106
* @see setIsObstacle()
127107
* @note added in QGIS 2.16
@@ -135,10 +115,6 @@ class QgsDiagramLayerSettings
135115
*/
136116
void setIsObstacle( bool isObstacle );
137117

138-
//! Whether associated feature acts as an obstacle for other labels or diagrams
139-
// TODO QGIS 3.0 - rename to mObstacle, make private
140-
bool obstacle;
141-
142118
/** Returns the distance between the diagram and the feature (in mm).
143119
* @see setDistance()
144120
* @note added in QGIS 2.16
@@ -152,35 +128,25 @@ class QgsDiagramLayerSettings
152128
*/
153129
void setDistance( double distance );
154130

155-
//! Distance between diagram and the feature (in mm)
156-
// TODO QGIS 3.0 - make private, rename to mDistance
157-
double dist;
158-
159131
/** Returns the diagram renderer associated with the layer.
160132
* @see setRenderer()
161133
* @note added in QGIS 2.16
162134
*/
163-
// TODO QGIS 3.0 - rename to renderer()
164-
QgsDiagramRenderer* getRenderer();
135+
QgsDiagramRenderer* renderer();
165136

166137
/** Returns the diagram renderer associated with the layer.
167138
* @see setRenderer()
168139
* @note added in QGIS 2.16
169140
*/
170-
// TODO QGIS 3.0 - rename to renderer()
171-
//const QgsDiagramRenderer* getRenderer() const;
141+
//const QgsDiagramRenderer* renderer() const;
172142

173143
/** Sets the diagram renderer associated with the layer.
174144
* @param diagramRenderer diagram renderer. Ownership is transferred to the object.
175-
* @see getRenderer()
145+
* @see renderer()
176146
* @note added in QGIS 2.16
177147
*/
178148
void setRenderer( QgsDiagramRenderer* diagramRenderer /Transfer/ );
179149

180-
//! Associated diagram renderer. Owned by this object.
181-
// TODO QGIS 3.0 - make private, rename to mRenderer
182-
QgsDiagramRenderer* renderer;
183-
184150
/** Returns the coordinate transform associated with the layer, or an
185151
* invalid transform if no transformation is required.
186152
* @see setCoordinateTransform()
@@ -214,10 +180,6 @@ class QgsDiagramLayerSettings
214180
*/
215181
void setShowAllDiagrams( bool showAllDiagrams );
216182

217-
//! Whether to show all diagrams, including overlapping diagrams
218-
// TODO QGIS 3.0 - make private, rename to mShowAll
219-
bool showAll;
220-
221183
void readXml( const QDomElement& elem, const QgsVectorLayer* layer );
222184
void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
223185

@@ -329,8 +291,8 @@ class QgsDiagramInterpolationSettings
329291
QSizeF upperSize;
330292
double lowerValue;
331293
double upperValue;
332-
/** Index of the classification attribute*/
333-
int classificationAttribute;
294+
//! Name of the field for classification
295+
QString classificationField;
334296
QString classificationAttributeExpression;
335297
bool classificationAttributeIsExpression;
336298
};
@@ -368,8 +330,7 @@ class QgsDiagramRenderer
368330
* @param fields layer fields
369331
* @note added in QGIS 2.16
370332
*/
371-
//TODO QGIS 3.0 - remove need for fields parameter
372-
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext(), const QgsFields& fields = QgsFields() ) const;
333+
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;
373334

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

@@ -511,7 +472,7 @@ class QgsLinearlyInterpolatedDiagramRenderer : QgsDiagramRenderer
511472

512473
QList<QString> diagramAttributes() const;
513474

514-
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext(), const QgsFields& fields = QgsFields() ) const;
475+
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;
515476

516477
QString rendererName() const;
517478

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

530-
int classificationAttribute() const;
531-
void setClassificationAttribute( int index );
491+
/**
492+
* Returns the field name used for interpolating the diagram size.
493+
* @see setClassificationField()
494+
* @note added in QGIS 3.0
495+
*/
496+
QString classificationField() const;
497+
498+
/**
499+
* Sets the field name used for interpolating the diagram size.
500+
* @see classificationField()
501+
* @note added in QGIS 3.0
502+
*/
503+
void setClassificationField( const QString& field );
532504

533505
QString classificationAttributeExpression() const;
534506
void setClassificationAttributeExpression( const QString& expression );

‎src/app/qgsdiagramproperties.cpp‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
370370
}
371371
else
372372
{
373-
mSizeFieldExpressionWidget->setField( mLayer->fields().at( lidr->classificationAttribute() ).name() );
373+
mSizeFieldExpressionWidget->setField( lidr->classificationField() );
374374
}
375375
}
376376
}
@@ -379,15 +379,15 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
379379
if ( dls )
380380
{
381381
mDiagramDistanceSpinBox->setValue( dls->distance() );
382-
mPrioritySlider->setValue( dls->getPriority() );
383-
mZIndexSpinBox->setValue( dls->getZIndex() );
382+
mPrioritySlider->setValue( dls->priority() );
383+
mZIndexSpinBox->setValue( dls->zIndex() );
384384
mDataDefinedXComboBox->setCurrentIndex( mDataDefinedXComboBox->findData( dls->xPosColumn ) );
385385
mDataDefinedYComboBox->setCurrentIndex( mDataDefinedYComboBox->findData( dls->yPosColumn ) );
386386
if ( dls->xPosColumn != -1 || dls->yPosColumn != -1 )
387387
{
388388
mDataDefinedPositionGroupBox->setChecked( true );
389389
}
390-
mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( dls->getPlacement() ) );
390+
mPlacementComboBox->setCurrentIndex( mPlacementComboBox->findData( dls->placement() ) );
391391

392392
chkLineAbove->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::AboveLine );
393393
chkLineBelow->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::BelowLine );
@@ -801,8 +801,7 @@ void QgsDiagramProperties::apply()
801801
}
802802
else
803803
{
804-
int attributeNumber = mLayer->fields().lookupField( sizeFieldNameOrExp );
805-
dr->setClassificationAttribute( attributeNumber );
804+
dr->setClassificationField( sizeFieldNameOrExp );
806805
}
807806
dr->setDiagramSettings( ds );
808807
renderer = dr;
@@ -838,7 +837,7 @@ void QgsDiagramProperties::apply()
838837
}
839838
dls.setPlacement(( QgsDiagramLayerSettings::Placement )mPlacementComboBox->currentData().toInt() );
840839

841-
unsigned int flags = 0;
840+
QgsDiagramLayerSettings::LinePlacementFlags flags = 0;
842841
if ( chkLineAbove->isChecked() )
843842
flags |= QgsDiagramLayerSettings::AboveLine;
844843
if ( chkLineBelow->isChecked() )

‎src/core/diagram/qgspiediagram.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ QSizeF QgsPieDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCon
4848
}
4949
else
5050
{
51-
attrVal = feature.attributes().at( is.classificationAttribute );
51+
attrVal = feature.attribute( is.classificationField );
5252
}
5353

5454
bool ok = false;

‎src/core/diagram/qgstextdiagram.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ QSizeF QgsTextDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCo
4747
}
4848
else
4949
{
50-
attrVal = feature.attributes().at( is.classificationAttribute );
50+
attrVal = feature.attribute( is.classificationField );
5151
}
5252

5353
bool ok = false;

0 commit comments

Comments
 (0)