Skip to content
Permalink
Browse files
Bring back temporarily disabled projects upgrade + fix a loading bug
Loading bug: on the first project load, data-defined properties for diagram layer settings were not read
as the default constructor did not populate the list of data-defined property definitions.
  • Loading branch information
wonder-sk committed May 13, 2017
1 parent 93bfa94 commit 8dd58864f25154ebd2289fd734cb4c30323f9742
Showing with 50 additions and 1 deletion.
  1. +5 −0 src/core/qgsdiagramrenderer.cpp
  2. +1 −1 src/core/qgsdiagramrenderer.h
  3. +44 −0 src/core/qgsvectorlayer.cpp
@@ -55,6 +55,11 @@ const QgsPropertiesDefinition &QgsDiagramLayerSettings::propertyDefinitions()
return sPropertyDefinitions;
}

QgsDiagramLayerSettings::QgsDiagramLayerSettings()
{
initPropertyDefinitions();
}

QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings &rh )
: mCt( rh.mCt )
, mPlacement( rh.mPlacement )
@@ -106,7 +106,7 @@ class CORE_EXPORT QgsDiagramLayerSettings
/**
* Constructor for QgsDiagramLayerSettings.
*/
QgsDiagramLayerSettings() = default;
QgsDiagramLayerSettings();

//! Copy constructor
QgsDiagramLayerSettings( const QgsDiagramLayerSettings &rh );
@@ -1834,6 +1834,14 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
QDomElement linearDiagramElem = node.firstChildElement( QStringLiteral( "LinearlyInterpolatedDiagramRenderer" ) );
if ( !linearDiagramElem.isNull() )
{
if ( linearDiagramElem.hasAttribute( QStringLiteral( "classificationAttribute" ) ) )
{
// fix project from before QGIS 3.0
int idx = linearDiagramElem.attribute( QStringLiteral( "classificationAttribute" ) ).toInt();
if ( idx >= 0 && idx < mFields.count() )
linearDiagramElem.setAttribute( "classificationField", mFields.at( idx ).name() );
}

mDiagramRenderer = new QgsLinearlyInterpolatedDiagramRenderer();
mDiagramRenderer->readXml( linearDiagramElem, context );
}
@@ -1843,6 +1851,42 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
QDomElement diagramSettingsElem = node.firstChildElement( QStringLiteral( "DiagramLayerSettings" ) );
if ( !diagramSettingsElem.isNull() )
{
bool oldXPos = diagramSettingsElem.hasAttribute( QStringLiteral( "xPosColumn" ) );
bool oldYPos = diagramSettingsElem.hasAttribute( QStringLiteral( "yPosColumn" ) );
bool oldShow = diagramSettingsElem.hasAttribute( QStringLiteral( "showColumn" ) );
if ( oldXPos || oldYPos || oldShow )
{
// fix project from before QGIS 3.0
QgsPropertyCollection ddp;
if ( oldXPos )
{
int xPosColumn = diagramSettingsElem.attribute( QStringLiteral( "xPosColumn" ) ).toInt();
if ( xPosColumn >= 0 && xPosColumn < mFields.count() )
ddp.setProperty( QgsDiagramLayerSettings::PositionX, QgsProperty::fromField( mFields.at( xPosColumn ).name(), true ) );
}
if ( oldYPos )
{
int yPosColumn = diagramSettingsElem.attribute( QStringLiteral( "yPosColumn" ) ).toInt();
if ( yPosColumn >= 0 && yPosColumn < mFields.count() )
ddp.setProperty( QgsDiagramLayerSettings::PositionY, QgsProperty::fromField( mFields.at( yPosColumn ).name(), true ) );
}
if ( oldShow )
{
int showColumn = diagramSettingsElem.attribute( QStringLiteral( "showColumn" ) ).toInt();
if ( showColumn >= 0 && showColumn < mFields.count() )
ddp.setProperty( QgsDiagramLayerSettings::Show, QgsProperty::fromField( mFields.at( showColumn ).name(), true ) );
}
QDomElement propertiesElem = diagramSettingsElem.ownerDocument().createElement( "properties" );
QgsPropertiesDefinition defs = QgsPropertiesDefinition
{
{ QgsDiagramLayerSettings::PositionX, QgsPropertyDefinition( "positionX", QObject::tr( "Position (X)" ), QgsPropertyDefinition::Double ) },
{ QgsDiagramLayerSettings::PositionY, QgsPropertyDefinition( "positionY", QObject::tr( "Position (Y)" ), QgsPropertyDefinition::Double ) },
{ QgsDiagramLayerSettings::Show, QgsPropertyDefinition( "show", QObject::tr( "Show diagram" ), QgsPropertyDefinition::Boolean ) },
};
ddp.writeXml( propertiesElem, defs );
diagramSettingsElem.appendChild( propertiesElem );
}

delete mDiagramLayerSettings;
mDiagramLayerSettings = new QgsDiagramLayerSettings();
mDiagramLayerSettings->readXml( diagramSettingsElem );

0 comments on commit 8dd5886

Please sign in to comment.