Skip to content
Permalink
Browse files

Fix for #8052, QGIS 2.0 does not respect labels' scale-based visibili…

…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 d547b25c17365be99f43d7de38a4cf392f99677e
Showing with 62 additions and 10 deletions.
  1. +6 −2 src/app/qgslabelinggui.cpp
  2. +48 −6 src/core/qgspallabeling.cpp
  3. +8 −2 src/ui/qgslabelingguibase.ui
@@ -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() );
@@ -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
@@ -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() )
{
@@ -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();
@@ -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;
}
@@ -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;
}
@@ -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>
@@ -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>

0 comments on commit d547b25

Please sign in to comment.
You can’t perform that action at this time.