Skip to content

Commit

Permalink
Allow 0 (infinite) for scale dependent visibility
Browse files Browse the repository at this point in the history
Fix #15414
  • Loading branch information
m-kuhn committed Oct 21, 2016
1 parent 35f9aa2 commit 2475ee5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -486,8 +486,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() )
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsscalecombobox.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 );
}
Expand Down
8 changes: 7 additions & 1 deletion src/gui/qgsscalecombobox.h
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions src/gui/qgsscalerangewidget.cpp
Expand Up @@ -90,6 +90,8 @@ void QgsScaleRangeWidget::setMapCanvas( QgsMapCanvas *mapCanvas )

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

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

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

Expand All @@ -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 )
Expand Down
16 changes: 14 additions & 2 deletions src/gui/qgsscalerangewidget.h
Expand Up @@ -46,18 +46,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 );
Expand Down
6 changes: 4 additions & 2 deletions src/gui/qgsscalewidget.cpp
Expand Up @@ -66,5 +66,7 @@ void QgsScaleWidget::setScaleFromCanvas()
setScale( 1 / mCanvas->scale() );
}



void QgsScaleWidget::setScale( double scale )
{
return mScaleComboBox->setScale( scale );
}
2 changes: 1 addition & 1 deletion src/gui/qgsscalewidget.h
Expand Up @@ -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(); }

Expand Down

0 comments on commit 2475ee5

Please sign in to comment.