Skip to content
Permalink
Browse files
Remove deprecated diagram field properties
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 336b603 commit 4018863d3758e01bb6c0074ad7493009f9b5a143
@@ -832,6 +832,17 @@ place of a null pointer.
- 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.
- The xPosColumn, yPosColumn and showColumn attributes were removed. Use setProperties() for setting data defined properties 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.
- referencedFields() no longer requires a QgsFields argument.

QgsDiagramSettings {#qgis_api_break_3_0_QgsDiagramSettings}
------------------
@@ -180,12 +180,6 @@ class QgsDiagramLayerSettings
*/
void setCoordinateTransform( const QgsCoordinateTransform& transform );

//! Attribute index for x coordinate (or -1 if position not data defined)
int xPosColumn;

//! Attribute index for y coordinate (or -1 if position not data defined)
int yPosColumn;

/** Returns whether the layer should show all diagrams, including overlapping diagrams
* @see setShowAllDiagrams()
* @note added in QGIS 2.16
@@ -204,11 +198,9 @@ class QgsDiagramLayerSettings

/** Returns the set of any fields referenced by the layer's diagrams.
* @param context expression context the diagrams will be drawn using
* @param fields layer fields
* @note added in QGIS 2.16
*/
//TODO QGIS 3.0 - remove need for fields parameter
QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext(), const QgsFields& fields = QgsFields() ) const;
QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;

/** Returns a reference to the diagram's property collection, used for data defined overrides.
* @note added in QGIS 2.16
@@ -147,16 +147,11 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mScaleDependencyComboBox->addItem( tr( "Area" ), true );
mScaleDependencyComboBox->addItem( tr( "Diameter" ), false );

mDataDefinedXComboBox->addItem( tr( "None" ), -1 );
mDataDefinedYComboBox->addItem( tr( "None" ), -1 );

mAngleOffsetComboBox->addItem( tr( "Top" ), 90 * 16 );
mAngleOffsetComboBox->addItem( tr( "Right" ), 0 );
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 270 * 16 );
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 * 16 );

mDataDefinedVisibilityComboBox->addItem( tr( "None" ), -1 );

QSettings settings;

// reset horiz stretch of left side of options splitter (set to 1 for previewing in Qt Designer)
@@ -192,10 +187,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
newItem->setText( 0, name );
newItem->setData( 0, RoleAttributeExpression, name );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );

mDataDefinedXComboBox->addItem( layerFields.at( idx ).name(), idx );
mDataDefinedYComboBox->addItem( layerFields.at( idx ).name(), idx );
mDataDefinedVisibilityComboBox->addItem( layerFields.at( idx ).name(), idx );
}

const QgsDiagramRenderer* dr = layer->diagramRenderer();
@@ -217,7 +208,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
mShowAllCheckBox->setChecked( true );
mDataDefinedVisibilityGroupBox->setChecked( false );
mCheckBoxAttributeLegend->setChecked( true );
mCheckBoxSizeLegend->setChecked( false );
mSizeLegendSymbol.reset( QgsMarkerSymbol::createSimple( QgsStringMap() ) );
@@ -383,12 +373,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mDiagramDistanceSpinBox->setValue( dls->distance() );
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->placement() ) );

chkLineAbove->setChecked( dls->linePlacementFlags() & QgsDiagramLayerSettings::AboveLine );
@@ -398,11 +382,6 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
chkLineOrientationDependent->setChecked( true );

mShowAllCheckBox->setChecked( dls->showAllDiagrams() );
mDataDefinedVisibilityComboBox->setCurrentIndex( mDataDefinedVisibilityComboBox->findData( dls->showColumn ) );
if ( dls->showColumn != -1 )
{
mDataDefinedVisibilityGroupBox->setChecked( true );
}
}

if ( dr->diagram() )
@@ -819,24 +798,6 @@ void QgsDiagramProperties::apply()
dls.setPriority( mPrioritySlider->value() );
dls.setZIndex( mZIndexSpinBox->value() );
dls.setShowAllDiagrams( mShowAllCheckBox->isChecked() );
if ( mDataDefinedVisibilityGroupBox->isChecked() )
{
dls.showColumn = mDataDefinedVisibilityComboBox->currentData().toInt();
}
else
{
dls.showColumn = -1;
}
if ( mDataDefinedPositionGroupBox->isChecked() )
{
dls.xPosColumn = mDataDefinedXComboBox->currentData().toInt();
dls.yPosColumn = mDataDefinedYComboBox->currentData().toInt();
}
else
{
dls.xPosColumn = -1;
dls.yPosColumn = -1;
}
dls.setPlacement(( QgsDiagramLayerSettings::Placement )mPlacementComboBox->currentData().toInt() );

QgsDiagramLayerSettings::LinePlacementFlags flags = 0;
@@ -570,11 +570,25 @@ bool QgsMapToolLabel::diagramMoveable( QgsVectorLayer* vlayer, int& xCol, int& y
if ( vlayer && vlayer->diagramsEnabled() )
{
const QgsDiagramLayerSettings *dls = vlayer->diagramLayerSettings();
if ( dls && dls->xPosColumn >= 0 && dls->yPosColumn >= 0 )
if ( dls )
{
xCol = dls->xPosColumn;
yCol = dls->yPosColumn;
return true;
xCol = -1;
if ( const QgsFieldBasedProperty* ddX = dynamic_cast< const QgsFieldBasedProperty* >( dls->properties().property( QgsDiagramLayerSettings::PositionX ) ) )
{
if ( ddX->isActive() )
{
xCol = vlayer->fields().lookupField( ddX->field() );
}
}
yCol = -1;
if ( const QgsFieldBasedProperty* ddY = dynamic_cast< const QgsFieldBasedProperty* >( dls->properties().property( QgsDiagramLayerSettings::PositionY ) ) )
{
if ( ddY->isActive() )
{
yCol = vlayer->fields().lookupField( ddY->field() );
}
}
return xCol >= 0 && yCol >= 0;
}
}
return false;
@@ -657,20 +671,23 @@ bool QgsMapToolLabel::isPinned()

bool QgsMapToolLabel::diagramCanShowHide( QgsVectorLayer* vlayer, int& showCol ) const
{
bool rc = false;
showCol = -1;

if ( vlayer && vlayer->isEditable() && vlayer->diagramsEnabled() )
{
const QgsDiagramLayerSettings *dls = vlayer->diagramLayerSettings();

if ( dls && dls->showColumn >= 0 )
if ( const QgsDiagramLayerSettings *dls = vlayer->diagramLayerSettings() )
{
showCol = dls->showColumn;
rc = true;
if ( const QgsFieldBasedProperty* ddShow = dynamic_cast< const QgsFieldBasedProperty* >( dls->properties().property( QgsDiagramLayerSettings::Show ) ) )
{
if ( ddShow->isActive() )
{
showCol = vlayer->fields().lookupField( ddShow->field() );
}
}
}
}

return rc;
return showCol >= 0;
}

//
@@ -25,20 +25,15 @@
#include <QDomElement>
#include <QPainter>

QMap< int, QString > QgsDiagramLayerSettings::sPropertyNameMap;

QgsDiagramLayerSettings::QgsDiagramLayerSettings()
: xPosColumn( -1 )
, yPosColumn( -1 )
, showColumn( -1 )
, mRenderer( nullptr )
{
init();
}

QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings& rh )
: xPosColumn( rh.xPosColumn )
, yPosColumn( rh.yPosColumn )
, showColumn( rh.showColumn )
, mCt( rh.mCt )
: mCt( rh.mCt )
, mPlacement( rh.mPlacement )
, mPlacementFlags( rh.mPlacementFlags )
, mPriority( rh.mPriority )
@@ -62,9 +57,6 @@ QgsDiagramLayerSettings&QgsDiagramLayerSettings::operator=( const QgsDiagramLaye
mDistance = rh.mDistance;
mRenderer = rh.mRenderer ? rh.mRenderer->clone() : nullptr;
mCt = rh.mCt;
xPosColumn = rh.xPosColumn;
yPosColumn = rh.yPosColumn;
showColumn = rh.showColumn;
mShowAll = rh.mShowAll;
mProperties = rh.mProperties;
return *this;
@@ -109,9 +101,27 @@ void QgsDiagramLayerSettings::readXml( const QDomElement& elem, const QgsVectorL
mZIndex = elem.attribute( QStringLiteral( "zIndex" ) ).toDouble();
mObstacle = elem.attribute( QStringLiteral( "obstacle" ) ).toInt();
mDistance = elem.attribute( QStringLiteral( "dist" ) ).toDouble();
xPosColumn = elem.attribute( QStringLiteral( "xPosColumn" ) ).toInt();
yPosColumn = elem.attribute( QStringLiteral( "yPosColumn" ) ).toInt();
showColumn = elem.attribute( QStringLiteral( "showColumn" ) ).toInt();
if ( elem.hasAttribute( QStringLiteral( "xPosColumn" ) ) )
{
// upgrade old project
int xPosColumn = elem.attribute( QStringLiteral( "xPosColumn" ) ).toInt();
if ( xPosColumn >= 0 && xPosColumn < layer->fields().count() )
mProperties.setProperty( PositionX, new QgsFieldBasedProperty( layer->fields().at( xPosColumn ).name(), true ) );
}
if ( elem.hasAttribute( QStringLiteral( "yPosColumn" ) ) )
{
// upgrade old project
int yPosColumn = elem.attribute( QStringLiteral( "yPosColumn" ) ).toInt();
if ( yPosColumn >= 0 && yPosColumn < layer->fields().count() )
mProperties.setProperty( PositionY, new QgsFieldBasedProperty( layer->fields().at( yPosColumn ).name(), true ) );
}
if ( elem.hasAttribute( QStringLiteral( "showColumn" ) ) )
{
// upgrade old project
int showColumn = elem.attribute( QStringLiteral( "showColumn" ) ).toInt();
if ( showColumn >= 0 && showColumn < layer->fields().count() )
mProperties.setProperty( Show, new QgsFieldBasedProperty( layer->fields().at( showColumn ).name(), true ) );
}
mShowAll = ( elem.attribute( QStringLiteral( "showAll" ), QStringLiteral( "0" ) ) != QLatin1String( "0" ) );
}

@@ -129,9 +139,6 @@ void QgsDiagramLayerSettings::writeXml( QDomElement& layerElem, QDomDocument& do
diagramLayerElem.setAttribute( QStringLiteral( "zIndex" ), mZIndex );
diagramLayerElem.setAttribute( QStringLiteral( "obstacle" ), mObstacle );
diagramLayerElem.setAttribute( QStringLiteral( "dist" ), QString::number( mDistance ) );
diagramLayerElem.setAttribute( QStringLiteral( "xPosColumn" ), xPosColumn );
diagramLayerElem.setAttribute( QStringLiteral( "yPosColumn" ), yPosColumn );
diagramLayerElem.setAttribute( QStringLiteral( "showColumn" ), showColumn );
diagramLayerElem.setAttribute( QStringLiteral( "showAll" ), mShowAll );
layerElem.appendChild( diagramLayerElem );
}
@@ -164,16 +171,6 @@ QSet<QString> QgsDiagramLayerSettings::referencedFields( const QgsExpressionCont
//add the ones needed for data defined settings
referenced.unite( mProperties.referencedFields( context ) );

//and the ones needed for data defined diagram positions
if ( xPosColumn >= 0 && xPosColumn < fieldsParameter.count() )
referenced << fieldsParameter.at( xPosColumn ).name();
if ( yPosColumn >= 0 && yPosColumn < fieldsParameter.count() )
referenced << fieldsParameter.at( yPosColumn ).name();

// and the ones needed for data defined diagram visibility
if ( showColumn >= 0 && showColumn < fieldsParameter.count() )
referenced << fieldsParameter.at( showColumn ).name();

return referenced;
}

@@ -148,7 +148,6 @@ class CORE_EXPORT QgsDiagramLayerSettings
*/
void setPriority( int value ) { mPriority = value; }


/** 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
@@ -225,15 +224,6 @@ class CORE_EXPORT QgsDiagramLayerSettings
*/
void setCoordinateTransform( const QgsCoordinateTransform& transform );

//! Attribute index for x coordinate (or -1 if position not data defined)
int xPosColumn;

//! Attribute index for y coordinate (or -1 if position not data defined)
int yPosColumn;

//! Attribute index for visibility (or -1 if visibility not data defined)
int showColumn;

/** Returns whether the layer should show all diagrams, including overlapping diagrams
* @see setShowAllDiagrams()
* @note added in QGIS 2.16
@@ -252,11 +242,9 @@ class CORE_EXPORT QgsDiagramLayerSettings

/** Returns the set of any fields referenced by the layer's diagrams.
* @param context expression context the diagrams will be drawn using
* @param fields layer fields
* @note added in QGIS 2.16
*/
//TODO QGIS 3.0 - remove need for fields parameter
QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext(), const QgsFields& fields = QgsFields() ) const;
QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;

/** Returns a reference to the diagram's property collection, used for data defined overrides.
* @note added in QGIS 3.0
@@ -465,6 +453,9 @@ class CORE_EXPORT QgsDiagramRenderer
*/
virtual QSet< QString > referencedFields( const QgsExpressionContext& context = QgsExpressionContext() ) const;

/**
* Renders the diagram for a specified feature at a specific position in the passed render context.
*/
void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, QPointF pos, const QgsPropertyCollection& properties = QgsPropertyCollection() ) const;

void setDiagram( QgsDiagram* d );
@@ -473,7 +464,18 @@ class CORE_EXPORT QgsDiagramRenderer
//! Returns list with all diagram settings in the renderer
virtual QList<QgsDiagramSettings> diagramSettings() const = 0;

/**
* Reads diagram state from a DOM element. Subclasses should ensure that _readXml() is called
* by their readXml implementation to restore the general QgsDiagramRenderer settings.
* @see writeXml()
*/
virtual void readXml( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;

/**
* Writes diagram state to a DOM element. Subclasses should ensure that _writeXml() is called
* by their writeXml implementation to save the general QgsDiagramRenderer settings.
* @see readXml()
*/
virtual void writeXml( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;

/** Returns list of legend nodes for the diagram
@@ -550,7 +552,17 @@ class CORE_EXPORT QgsDiagramRenderer
static int dpiPaintDevice( const QPainter* );

//read / write diagram

/**
* Reads internal QgsDiagramRenderer state from a DOM element.
* @see _writeXml()
*/
void _readXml( const QDomElement& elem, const QgsVectorLayer* layer );

/**
* Writes internal QgsDiagramRenderer diagram state to a DOM element.
* @see _readXml()
*/
void _writeXml( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;

//! Reference to the object that does the real diagram rendering

0 comments on commit 4018863

Please sign in to comment.