Skip to content

Commit

Permalink
Bring back temporarily disabled projects upgrade + fix a loading bug
Browse files Browse the repository at this point in the history
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 8dd5886
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/core/qgsdiagramrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const QgsPropertiesDefinition &QgsDiagramLayerSettings::propertyDefinitions()
return sPropertyDefinitions;
}

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

QgsDiagramLayerSettings::QgsDiagramLayerSettings( const QgsDiagramLayerSettings &rh )
: mCt( rh.mCt )
, mPlacement( rh.mPlacement )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdiagramrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CORE_EXPORT QgsDiagramLayerSettings
/**
* Constructor for QgsDiagramLayerSettings.
*/
QgsDiagramLayerSettings() = default;
QgsDiagramLayerSettings();

//! Copy constructor
QgsDiagramLayerSettings( const QgsDiagramLayerSettings &rh );
Expand Down
44 changes: 44 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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 );
Expand Down

0 comments on commit 8dd5886

Please sign in to comment.