Skip to content

Commit

Permalink
Fix labeling unit types incorrectly restored as map units from old pr…
Browse files Browse the repository at this point in the history
…ojects
  • Loading branch information
nyalldawson committed Feb 17, 2017
1 parent f46b25b commit 7c4f879
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/core/qgstextrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
Q_GUI_EXPORT extern int qt_defaultDpiX();
Q_GUI_EXPORT extern int qt_defaultDpiY();

QgsUnitTypes::RenderUnit convertFromOldLabelUnit( int val )
{
if ( val == 0 )
return QgsUnitTypes::RenderPoints;
else if ( val == 1 )
return QgsUnitTypes::RenderMillimeters;
else if ( val == 2 )
return QgsUnitTypes::RenderMapUnits;
else if ( val == 3 )
return QgsUnitTypes::RenderPercentage;
else
return QgsUnitTypes::RenderMillimeters;
}

static void _fixQPictureDPI( QPainter* p )
{
// QPicture makes an assumption that we drawing to it with system DPI.
Expand Down Expand Up @@ -581,8 +595,7 @@ void QgsTextBackgroundSettings::readFromLayer( QgsVectorLayer* layer )

if ( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnit" ) ).toString().isEmpty() )
{
d->sizeUnits = layer->customProperty( QStringLiteral( "labeling/shapeSizeUnits" ), 0 ).toUInt() == 0 ?
QgsUnitTypes::RenderMillimeters : QgsUnitTypes::RenderMapUnits;
d->sizeUnits = convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnits" ), 0 ).toUInt() );
}
else
{
Expand All @@ -606,8 +619,7 @@ void QgsTextBackgroundSettings::readFromLayer( QgsVectorLayer* layer )

if ( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnit" ) ).toString().isEmpty() )
{
d->offsetUnits = layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnits" ), 0 ).toUInt() == 0 ?
QgsUnitTypes::RenderMillimeters : QgsUnitTypes::RenderMapUnits;
d->offsetUnits = convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnits" ), 0 ).toUInt() );
}
else
{
Expand All @@ -630,8 +642,7 @@ void QgsTextBackgroundSettings::readFromLayer( QgsVectorLayer* layer )

if ( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnit" ) ).toString().isEmpty() )
{
d->radiiUnits = layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnits" ), 0 ).toUInt() == 0 ?
QgsUnitTypes::RenderMillimeters : QgsUnitTypes::RenderMapUnits;
d->radiiUnits = convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnits" ), 0 ).toUInt() );
}
else
{
Expand All @@ -653,8 +664,7 @@ void QgsTextBackgroundSettings::readFromLayer( QgsVectorLayer* layer )
d->borderWidth = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidth" ), QVariant( .0 ) ).toDouble();
if ( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnit" ) ).toString().isEmpty() )
{
d->borderWidthUnits = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnits" ), 0 ).toUInt() == 0 ?
QgsUnitTypes::RenderMillimeters : QgsUnitTypes::RenderMapUnits;
d->borderWidthUnits = convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnits" ), 0 ).toUInt() );
}
else
{
Expand Down Expand Up @@ -726,8 +736,7 @@ void QgsTextBackgroundSettings::readXml( const QDomElement& elem )

if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeSizeUnit" ) ) )
{
d->sizeUnits = backgroundElem.attribute( QStringLiteral( "shapeSizeUnits" ) ).toUInt() == 0 ? QgsUnitTypes::RenderMillimeters
: QgsUnitTypes::RenderMapUnits;
d->sizeUnits = convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeSizeUnits" ) ).toUInt() );
}
else
{
Expand All @@ -751,8 +760,7 @@ void QgsTextBackgroundSettings::readXml( const QDomElement& elem )

if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOffsetUnit" ) ) )
{
d->offsetUnits = backgroundElem.attribute( QStringLiteral( "shapeOffsetUnits" ) ).toUInt() == 0 ? QgsUnitTypes::RenderMillimeters
: QgsUnitTypes::RenderMapUnits;
d->offsetUnits = convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeOffsetUnits" ) ).toUInt() );
}
else
{
Expand All @@ -774,8 +782,7 @@ void QgsTextBackgroundSettings::readXml( const QDomElement& elem )

if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeRadiiUnit" ) ) )
{
d->radiiUnits = backgroundElem.attribute( QStringLiteral( "shapeRadiiUnits" ) ).toUInt() == 0 ? QgsUnitTypes::RenderMillimeters
: QgsUnitTypes::RenderMapUnits;
d->radiiUnits = convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeRadiiUnits" ) ).toUInt() );
}
else
{
Expand All @@ -797,8 +804,7 @@ void QgsTextBackgroundSettings::readXml( const QDomElement& elem )

if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeBorderWidthUnit" ) ) )
{
d->borderWidthUnits = backgroundElem.attribute( QStringLiteral( "shapeBorderWidthUnits" ) ).toUInt() == 0 ? QgsUnitTypes::RenderMillimeters
: QgsUnitTypes::RenderMapUnits;
d->borderWidthUnits = convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthUnits" ) ).toUInt() );
}
else
{
Expand Down Expand Up @@ -1048,8 +1054,7 @@ void QgsTextShadowSettings::readFromLayer( QgsVectorLayer* layer )

if ( layer->customProperty( QStringLiteral( "labeling/shadowOffsetUnit" ) ).toString().isEmpty() )
{
d->offsetUnits = layer->customProperty( QStringLiteral( "labeling/shadowOffsetUnits" ), 0 ).toUInt() == 0 ?
QgsUnitTypes::RenderMillimeters : QgsUnitTypes::RenderMapUnits;
d->offsetUnits = convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shadowOffsetUnits" ), 0 ).toUInt() );
}
else
{
Expand All @@ -1070,8 +1075,7 @@ void QgsTextShadowSettings::readFromLayer( QgsVectorLayer* layer )

if ( layer->customProperty( QStringLiteral( "labeling/shadowRadiusUnit" ) ).toString().isEmpty() )
{
d->radiusUnits = layer->customProperty( QStringLiteral( "labeling/shadowRadiusUnits" ), 0 ).toUInt() == 0 ?
QgsUnitTypes::RenderMillimeters : QgsUnitTypes::RenderMapUnits;
d->radiusUnits = convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shadowRadiusUnits" ), 0 ).toUInt() );
}
else
{
Expand Down Expand Up @@ -1132,8 +1136,7 @@ void QgsTextShadowSettings::readXml( const QDomElement& elem )

if ( !shadowElem.hasAttribute( QStringLiteral( "shadowOffsetUnit" ) ) )
{
d->offsetUnits = shadowElem.attribute( QStringLiteral( "shadowOffsetUnits" ) ).toUInt() == 0 ? QgsUnitTypes::RenderMillimeters
: QgsUnitTypes::RenderMapUnits;
d->offsetUnits = convertFromOldLabelUnit( shadowElem.attribute( QStringLiteral( "shadowOffsetUnits" ) ).toUInt() );
}
else
{
Expand All @@ -1155,8 +1158,7 @@ void QgsTextShadowSettings::readXml( const QDomElement& elem )

if ( !shadowElem.hasAttribute( QStringLiteral( "shadowRadiusUnit" ) ) )
{
d->radiusUnits = shadowElem.attribute( QStringLiteral( "shadowRadiusUnits" ) ).toUInt() == 0 ? QgsUnitTypes::RenderMillimeters
: QgsUnitTypes::RenderMapUnits;
d->radiusUnits = convertFromOldLabelUnit( shadowElem.attribute( QStringLiteral( "shadowRadiusUnits" ) ).toUInt() );
}
else
{
Expand Down

0 comments on commit 7c4f879

Please sign in to comment.