Skip to content

Commit

Permalink
Fix for #8052, QGIS 2.0 does not respect labels' scale-based visibili…
Browse files Browse the repository at this point in the history
…ty in projects from previous version

- Also fix long standing unreported bug where scales closer than 1:1, e.g. 5:1, could not be set
  • Loading branch information
dakcarto committed Jun 13, 2013
1 parent fecf6af commit d547b25
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -1006,13 +1006,17 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
mCoordRotationDDBtn->setUsageInfo( ddPlaceInfo );

// rendering
QString ddScaleVisInfo = tr( "Value &lt; 0 represents a scale closer than 1:1, e.g. -10 = 10:1<br>"
"Value of 0 toggles off specific limit" );
mScaleBasedVisibilityDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ScaleVisibility ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::boolDesc() );
mScaleBasedVisibilityDDBtn->registerCheckedWidget( mScaleBasedVisibilityChkBx );
mScaleBasedVisibilityMinDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::MinScale ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intPosOneDesc() );
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intDesc() );
mScaleBasedVisibilityMinDDBtn->setUsageInfo( ddScaleVisInfo );
mScaleBasedVisibilityMaxDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::MaxScale ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intPosOneDesc() );
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intDesc() );
mScaleBasedVisibilityMaxDDBtn->setUsageInfo( ddScaleVisInfo );

mFontLimitPixelDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::FontLimitPixel ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::boolDesc() );
Expand Down
54 changes: 48 additions & 6 deletions src/core/qgspallabeling.cpp
Expand Up @@ -768,6 +768,13 @@ void QgsPalLayerSettings::readDataDefinedProperty( QgsVectorLayer* layer,
bufferDraw = true;
layer->setCustomProperty( "labeling/bufferDraw", true );
}

// fix for scale visibility limits triggered off of just its data defined values in the past (<2.0)
if ( oldIndx == 16 || oldIndx == 17 ) // old minScale and maxScale enums
{
scaleVisibility = true;
layer->setCustomProperty( "labeling/scaleVisibility", true );
}
}

// remove old-style field index-based property
Expand Down Expand Up @@ -853,7 +860,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
// text buffer
double bufSize = layer->customProperty( "labeling/bufferSize", QVariant( 0.0 ) ).toDouble();

// fix for buffer being keyed off of just its size in the past
// fix for buffer being keyed off of just its size in the past (<2.0)
QVariant drawBuffer = layer->customProperty( "labeling/bufferDraw", QVariant() );
if ( drawBuffer.isValid() )
{
Expand Down Expand Up @@ -937,9 +944,30 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
priority = layer->customProperty( "labeling/priority" ).toInt();

// rendering
scaleVisibility = layer->customProperty( "labeling/scaleVisibility" ).toBool();
scaleMin = layer->customProperty( "labeling/scaleMin", QVariant( 1 ) ).toInt();
scaleMax = layer->customProperty( "labeling/scaleMax", QVariant( 10000000 ) ).toInt();
int scalemn = layer->customProperty( "labeling/scaleMin", QVariant( 0 ) ).toInt();
int scalemx = layer->customProperty( "labeling/scaleMax", QVariant( 0 ) ).toInt();

// fix for scale visibility limits being keyed off of just its values in the past (<2.0)
QVariant scalevis = layer->customProperty( "labeling/scaleVisibility", QVariant() );
if ( scalevis.isValid() )
{
scaleVisibility = scalevis.toBool();
scaleMin = scalemn;
scaleMax = scalemx;
}
else if ( scalemn > 0 || scalemx > 0 )
{
scaleVisibility = true;
scaleMin = scalemn;
scaleMax = scalemx;
}
else
{
// keep scaleMin and scaleMax at new 1.0 defaults (1 and 10000000, were 0 and 0)
scaleVisibility = false;
}


fontLimitPixelSize = layer->customProperty( "labeling/fontLimitPixelSize", QVariant( false ) ).toBool();
fontMinPixelSize = layer->customProperty( "labeling/fontMinPixelSize", QVariant( 0 ) ).toInt();
fontMaxPixelSize = layer->customProperty( "labeling/fontMaxPixelSize", QVariant( 10000 ) ).toInt();
Expand Down Expand Up @@ -1496,7 +1524,14 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
minScale = mins;
}
}
if ( context.rendererScale() < minScale )

// scales closer than 1:1
if ( minScale < 0 )
{
minScale = 1 / qAbs( minScale );
}

if ( minScale != 0 && context.rendererScale() < minScale )
{
return;
}
Expand All @@ -1513,7 +1548,14 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
maxScale = maxs;
}
}
if ( context.rendererScale() > maxScale )

// scales closer than 1:1
if ( maxScale < 0 )
{
maxScale = 1 / qAbs( maxScale );
}

if ( maxScale != 0 && context.rendererScale() > maxScale )
{
return;
}
Expand Down
10 changes: 8 additions & 2 deletions src/ui/qgslabelingguibase.ui
Expand Up @@ -5030,11 +5030,14 @@ font-style: italic;</string>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Value &amp;lt; 0 represents a scale closer than 1:1, e.g. -10 = 10:1.&lt;br&gt;Value of 0 toggles off specific limit.</string>
</property>
<property name="prefix">
<string>Minimum </string>
</property>
<property name="minimum">
<number>1</number>
<number>-999999999</number>
</property>
<property name="maximum">
<number>999999999</number>
Expand All @@ -5056,11 +5059,14 @@ font-style: italic;</string>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Value &amp;lt; 0 represents a scale closer than 1:1, e.g. -10 = 10:1.&lt;br&gt;Value of 0 toggles off specific limit.</string>
</property>
<property name="prefix">
<string>Maximum </string>
</property>
<property name="minimum">
<number>1</number>
<number>-999999999</number>
</property>
<property name="maximum">
<number>999999999</number>
Expand Down

0 comments on commit d547b25

Please sign in to comment.