Skip to content
Permalink
Browse files

Allow 0 (infinite) for scale dependent visibility

Fix #15414
  • Loading branch information
m-kuhn committed Oct 17, 2016
1 parent fdc3542 commit 1f1898df1616ce5d3239bf2257470dd2c6b96566
@@ -562,8 +562,8 @@ void QgsVectorLayerProperties::apply()
// set up the scale based layer visibility stuff....
mLayer->setScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
// caution: layer uses scale denoms, widget uses true scales
mLayer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
mLayer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );
mLayer->setMaximumScale( mScaleRangeWidget->maximumScaleDenom() );
mLayer->setMinimumScale( mScaleRangeWidget->minimumScaleDenom() );

// provider-specific options
if ( mLayer->dataProvider() )
@@ -130,7 +130,7 @@ bool QgsScaleComboBox::setScaleString( const QString& scaleTxt )
bool ok;
double newScale = toDouble( scaleTxt, &ok );
double oldScale = mScale;
if ( newScale < mMinScale )
if ( newScale < mMinScale && newScale != 0 )
{
newScale = mMinScale;
}
@@ -246,7 +246,7 @@ double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
void QgsScaleComboBox::setMinScale( double scale )
{
mMinScale = scale;
if ( mScale < scale )
if ( mScale < scale && mScale != 0 )
{
setScale( scale );
}
@@ -55,7 +55,13 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox

public slots:
void updateScales( const QStringList &scales = QStringList() );
//! Function to set the min scale

/**
* Set the minimum allowed scale.
* Anything scale lower than the minimum scale will automatically
* be converted to the minimum scale.
* Except for 0 which is always allowed.
*/
void setMinScale( double scale );

protected:
@@ -90,6 +90,8 @@ void QgsScaleRangeWidget::setMapCanvas( QgsMapCanvas *mapCanvas )

void QgsScaleRangeWidget::setMinimumScale( double scale )
{
if ( isinf( scale ) )
scale = 0;
mMinimumScaleWidget->setScale( scale );
}

@@ -100,6 +102,8 @@ double QgsScaleRangeWidget::minimumScale()

void QgsScaleRangeWidget::setMaximumScale( double scale )
{
if ( isinf( scale ) )
scale = 0;
mMaximumScaleWidget->setScale( scale );
}

@@ -110,12 +114,20 @@ double QgsScaleRangeWidget::maximumScale()

double QgsScaleRangeWidget::minimumScaleDenom()
{
return qRound( 1.0 / maximumScale() );
double scale = maximumScale();
if ( scale == 0 )
return 0;
else
return qRound( 1.0 / scale );
}

double QgsScaleRangeWidget::maximumScaleDenom()
{
return qRound( 1.0 / minimumScale() );
double scale = minimumScale();
if ( scale == 0 )
return 0;
else
return qRound( 1.0 / scale );
}

void QgsScaleRangeWidget::setScaleRange( double min, double max )
@@ -48,18 +48,30 @@ class GUI_EXPORT QgsScaleRangeWidget : public QWidget
//! return the maximum scale
double maximumScale();

//! return the minimum scale denominator ( = 1 / maximum scale )
/**
* Returns the minimum scale denominator ( = 1 / maximum scale )
* In case of maximum scale = 0 it will also return 0
*/
double minimumScaleDenom();

//! return the maximum scale denominator ( = 1 / minimum scale )
/**
* Returns the maximum scale denominator ( = 1 / minimum scale )
* In case of minimum scale = 0 it will also return 0
*/
double maximumScaleDenom();

//! call to reload the project scales and apply them to the 2 scales combo boxes
void reloadProjectScales();

public slots:
/**
* Set the minimum scale. Infinite will be handled equally to 0 internally.
*/
void setMinimumScale( double scale );

/**
* Set the maximum scale. Infinite will be handled equally to 0 internally.
*/
void setMaximumScale( double scale );

void setScaleRange( double min, double max );
@@ -66,5 +66,7 @@ void QgsScaleWidget::setScaleFromCanvas()
setScale( 1 / mCanvas->scale() );
}



void QgsScaleWidget::setScale( double scale )
{
return mScaleComboBox->setScale( scale );
}
@@ -55,7 +55,7 @@ class GUI_EXPORT QgsScaleWidget : public QWidget
//! Function to read the selected scale as double
double scale() const { return mScaleComboBox->scale();}
//! Function to set the selected scale from double
void setScale( double scale ) { return mScaleComboBox->setScale( scale ); }
void setScale( double scale );
//! Function to read the min scale
double minScale() const { return mScaleComboBox->minScale(); }

0 comments on commit 1f1898d

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