Skip to content

Commit d547b25

Browse files
committedJun 13, 2013
Fix for #8052, QGIS 2.0 does not respect labels' scale-based visibility 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
1 parent fecf6af commit d547b25

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed
 

‎src/app/qgslabelinggui.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,17 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
10061006
mCoordRotationDDBtn->setUsageInfo( ddPlaceInfo );
10071007

10081008
// rendering
1009+
QString ddScaleVisInfo = tr( "Value &lt; 0 represents a scale closer than 1:1, e.g. -10 = 10:1<br>"
1010+
"Value of 0 toggles off specific limit" );
10091011
mScaleBasedVisibilityDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::ScaleVisibility ),
10101012
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::boolDesc() );
10111013
mScaleBasedVisibilityDDBtn->registerCheckedWidget( mScaleBasedVisibilityChkBx );
10121014
mScaleBasedVisibilityMinDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::MinScale ),
1013-
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intPosOneDesc() );
1015+
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intDesc() );
1016+
mScaleBasedVisibilityMinDDBtn->setUsageInfo( ddScaleVisInfo );
10141017
mScaleBasedVisibilityMaxDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::MaxScale ),
1015-
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intPosOneDesc() );
1018+
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::intDesc() );
1019+
mScaleBasedVisibilityMaxDDBtn->setUsageInfo( ddScaleVisInfo );
10161020

10171021
mFontLimitPixelDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::FontLimitPixel ),
10181022
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::boolDesc() );

‎src/core/qgspallabeling.cpp

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ void QgsPalLayerSettings::readDataDefinedProperty( QgsVectorLayer* layer,
768768
bufferDraw = true;
769769
layer->setCustomProperty( "labeling/bufferDraw", true );
770770
}
771+
772+
// fix for scale visibility limits triggered off of just its data defined values in the past (<2.0)
773+
if ( oldIndx == 16 || oldIndx == 17 ) // old minScale and maxScale enums
774+
{
775+
scaleVisibility = true;
776+
layer->setCustomProperty( "labeling/scaleVisibility", true );
777+
}
771778
}
772779

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

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

939946
// rendering
940-
scaleVisibility = layer->customProperty( "labeling/scaleVisibility" ).toBool();
941-
scaleMin = layer->customProperty( "labeling/scaleMin", QVariant( 1 ) ).toInt();
942-
scaleMax = layer->customProperty( "labeling/scaleMax", QVariant( 10000000 ) ).toInt();
947+
int scalemn = layer->customProperty( "labeling/scaleMin", QVariant( 0 ) ).toInt();
948+
int scalemx = layer->customProperty( "labeling/scaleMax", QVariant( 0 ) ).toInt();
949+
950+
// fix for scale visibility limits being keyed off of just its values in the past (<2.0)
951+
QVariant scalevis = layer->customProperty( "labeling/scaleVisibility", QVariant() );
952+
if ( scalevis.isValid() )
953+
{
954+
scaleVisibility = scalevis.toBool();
955+
scaleMin = scalemn;
956+
scaleMax = scalemx;
957+
}
958+
else if ( scalemn > 0 || scalemx > 0 )
959+
{
960+
scaleVisibility = true;
961+
scaleMin = scalemn;
962+
scaleMax = scalemx;
963+
}
964+
else
965+
{
966+
// keep scaleMin and scaleMax at new 1.0 defaults (1 and 10000000, were 0 and 0)
967+
scaleVisibility = false;
968+
}
969+
970+
943971
fontLimitPixelSize = layer->customProperty( "labeling/fontLimitPixelSize", QVariant( false ) ).toBool();
944972
fontMinPixelSize = layer->customProperty( "labeling/fontMinPixelSize", QVariant( 0 ) ).toInt();
945973
fontMaxPixelSize = layer->customProperty( "labeling/fontMaxPixelSize", QVariant( 10000 ) ).toInt();
@@ -1496,7 +1524,14 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
14961524
minScale = mins;
14971525
}
14981526
}
1499-
if ( context.rendererScale() < minScale )
1527+
1528+
// scales closer than 1:1
1529+
if ( minScale < 0 )
1530+
{
1531+
minScale = 1 / qAbs( minScale );
1532+
}
1533+
1534+
if ( minScale != 0 && context.rendererScale() < minScale )
15001535
{
15011536
return;
15021537
}
@@ -1513,7 +1548,14 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
15131548
maxScale = maxs;
15141549
}
15151550
}
1516-
if ( context.rendererScale() > maxScale )
1551+
1552+
// scales closer than 1:1
1553+
if ( maxScale < 0 )
1554+
{
1555+
maxScale = 1 / qAbs( maxScale );
1556+
}
1557+
1558+
if ( maxScale != 0 && context.rendererScale() > maxScale )
15171559
{
15181560
return;
15191561
}

‎src/ui/qgslabelingguibase.ui

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5030,11 +5030,14 @@ font-style: italic;</string>
50305030
<verstretch>0</verstretch>
50315031
</sizepolicy>
50325032
</property>
5033+
<property name="toolTip">
5034+
<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>
5035+
</property>
50335036
<property name="prefix">
50345037
<string>Minimum </string>
50355038
</property>
50365039
<property name="minimum">
5037-
<number>1</number>
5040+
<number>-999999999</number>
50385041
</property>
50395042
<property name="maximum">
50405043
<number>999999999</number>
@@ -5056,11 +5059,14 @@ font-style: italic;</string>
50565059
<verstretch>0</verstretch>
50575060
</sizepolicy>
50585061
</property>
5062+
<property name="toolTip">
5063+
<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>
5064+
</property>
50595065
<property name="prefix">
50605066
<string>Maximum </string>
50615067
</property>
50625068
<property name="minimum">
5063-
<number>1</number>
5069+
<number>-999999999</number>
50645070
</property>
50655071
<property name="maximum">
50665072
<number>999999999</number>

0 commit comments

Comments
 (0)
Please sign in to comment.