mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Swap QgsMapLayer min/max scale API definitions
setMaximumScale() and setMinimumScale(), maximumScale() and minimumScale() had the opposite meaning to other min/max scales in the API, and were the opposite to how these settings were exposed in the GUI. This lead to very confusing API!! Their definitions have now been swapped. setMaximumScale now sets the maximum (i.e. largest scale, or most zoomed in) at which the layer will appear, and setMinimumScale now sets the minimum (i.e. smallest scale, or most zoomed out) at which the layer will appear. The same is true for the maximumScale and minimumScale getters.
This commit is contained in:
parent
0f2a49d9b5
commit
a9a7d3c3d9
@ -1515,6 +1515,9 @@ screenUpdateRequested() were removed. These members have had no effect for a num
|
||||
- readXml() and writeXml() expect QgsReadWriteContext reference as the last argument
|
||||
- the invalidTransformInput() slot was removed - calling this slot had no effect
|
||||
- metadata() was renamed to htmlMetadata()
|
||||
- setMaximumScale() and setMinimumScale(), maximumScale() and minimumScale() had the opposite meaning to other min/max scales in the API, and their definitions have now been swapped. setMaximumScale
|
||||
now sets the maximum (i.e. largest scale, or most zoomed in) at which the layer will appear, and setMinimumScale now sets the minimum (i.e. smallest scale,
|
||||
or most zoomed out) at which the layer will appear. The same is true for the maximumScale and minimumScale getters.
|
||||
|
||||
|
||||
QgsMapLayerActionRegistry {#qgis_api_break_3_0_QgsMapLayerActionRegistry}
|
||||
|
@ -772,9 +772,12 @@ Return pointer to layer's undo stack
|
||||
|
||||
double minimumScale() const;
|
||||
%Docstring
|
||||
Returns the minimum scale denominator at which the layer is visible.
|
||||
Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||
:return: minimum scale denominator at which the layer will render
|
||||
Returns the minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
|
||||
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
A scale of 0 indicates no minimum scale visibility.
|
||||
.. note::
|
||||
|
||||
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
.. seealso:: setMinimumScale()
|
||||
.. seealso:: maximumScale()
|
||||
.. seealso:: hasScaleBasedVisibility()
|
||||
@ -784,9 +787,12 @@ Return pointer to layer's undo stack
|
||||
|
||||
double maximumScale() const;
|
||||
%Docstring
|
||||
Returns the maximum scale denominator at which the layer is visible.
|
||||
Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||
:return: minimum scale denominator at which the layer will render
|
||||
Returns the maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
|
||||
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
A scale of 0 indicates no maximum scale visibility.
|
||||
.. note::
|
||||
|
||||
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
.. seealso:: setMaximumScale()
|
||||
.. seealso:: minimumScale()
|
||||
.. seealso:: hasScaleBasedVisibility()
|
||||
@ -889,22 +895,28 @@ Time stamp of data source in the moment when data/metadata were loaded by provid
|
||||
|
||||
void setMinimumScale( double scale );
|
||||
%Docstring
|
||||
Sets the minimum scale denominator at which the layer will be visible.
|
||||
Scale based visibility is only used if setScaleBasedVisibility is set to true.
|
||||
\param scale minimum scale denominator at which the layer should render
|
||||
.. seealso:: minimumScale
|
||||
.. seealso:: setMaximumScale
|
||||
.. seealso:: setScaleBasedVisibility
|
||||
Sets the minimum map ``scale`` (i.e. most "zoomed out" scale) at which the layer will be visible.
|
||||
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
A ``scale`` of 0 indicates no minimum scale visibility.
|
||||
.. note::
|
||||
|
||||
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
.. seealso:: minimumScale()
|
||||
.. seealso:: setMaximumScale()
|
||||
.. seealso:: setScaleBasedVisibility()
|
||||
%End
|
||||
|
||||
void setMaximumScale( double scale );
|
||||
%Docstring
|
||||
Sets the maximum scale denominator at which the layer will be visible.
|
||||
Scale based visibility is only used if setScaleBasedVisibility is set to true.
|
||||
\param scale maximum scale denominator at which the layer should render
|
||||
.. seealso:: maximumScale
|
||||
.. seealso:: setMinimumScale
|
||||
.. seealso:: setScaleBasedVisibility
|
||||
Sets the maximum map ``scale`` (i.e. most "zoomed in" scale) at which the layer will be visible.
|
||||
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
A ``scale`` of 0 indicates no maximum scale visibility.
|
||||
.. note::
|
||||
|
||||
Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
.. seealso:: maximumScale()
|
||||
.. seealso:: setMinimumScale()
|
||||
.. seealso:: setScaleBasedVisibility()
|
||||
%End
|
||||
|
||||
void setScaleBasedVisibility( const bool enabled );
|
||||
|
@ -8979,8 +8979,8 @@ void QgisApp::setLayerScaleVisibility()
|
||||
if ( layer )
|
||||
{
|
||||
dlg->setScaleVisiblity( layer->hasScaleBasedVisibility() );
|
||||
dlg->setMinimumScale( 1.0 / layer->maximumScale() );
|
||||
dlg->setMaximumScale( 1.0 / layer->minimumScale() );
|
||||
dlg->setMinimumScale( 1.0 / layer->minimumScale() );
|
||||
dlg->setMaximumScale( 1.0 / layer->maximumScale() );
|
||||
}
|
||||
if ( dlg->exec() )
|
||||
{
|
||||
@ -8988,8 +8988,8 @@ void QgisApp::setLayerScaleVisibility()
|
||||
Q_FOREACH ( QgsMapLayer *layer, layers )
|
||||
{
|
||||
layer->setScaleBasedVisibility( dlg->hasScaleVisibility() );
|
||||
layer->setMinimumScale( 1.0 / dlg->maximumScale() );
|
||||
layer->setMaximumScale( 1.0 / dlg->minimumScale() );
|
||||
layer->setMaximumScale( 1.0 / dlg->maximumScale() );
|
||||
layer->setMinimumScale( 1.0 / dlg->minimumScale() );
|
||||
}
|
||||
freezeCanvases( false );
|
||||
refreshMapCanvas();
|
||||
@ -9011,13 +9011,13 @@ void QgisApp::zoomToLayerScale()
|
||||
if ( layer && layer->hasScaleBasedVisibility() )
|
||||
{
|
||||
const double scale = mMapCanvas->scale();
|
||||
if ( scale > layer->maximumScale() )
|
||||
if ( scale > layer->minimumScale() )
|
||||
{
|
||||
mMapCanvas->zoomScale( layer->maximumScale() * Qgis::SCALE_PRECISION );
|
||||
mMapCanvas->zoomScale( layer->minimumScale() * Qgis::SCALE_PRECISION );
|
||||
}
|
||||
else if ( scale <= layer->minimumScale() )
|
||||
else if ( scale <= layer->maximumScale() )
|
||||
{
|
||||
mMapCanvas->zoomScale( layer->minimumScale() );
|
||||
mMapCanvas->zoomScale( layer->maximumScale() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
|
||||
mIncreaseMinimumSizeLabel->setEnabled( false );
|
||||
mBarWidthSpinBox->setValue( 5 );
|
||||
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / layer->minimumScale(), 1.0 / layer->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
|
||||
mShowAllCheckBox->setChecked( true );
|
||||
mCheckBoxAttributeLegend->setChecked( true );
|
||||
mCheckBoxSizeLegend->setChecked( false );
|
||||
@ -266,8 +266,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
|
||||
mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
|
||||
mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
|
||||
// caution: layer uses scale denoms, widget uses true scales
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->maximumScale() ),
|
||||
1.0 / ( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->minimumScale() ) );
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / ( settingList.at( 0 ).maxScaleDenominator > 0 ? settingList.at( 0 ).maxScaleDenominator : layer->minimumScale() ),
|
||||
1.0 / ( settingList.at( 0 ).minScaleDenominator > 0 ? settingList.at( 0 ).minScaleDenominator : layer->maximumScale() ) );
|
||||
mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
|
||||
mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
|
||||
mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );
|
||||
|
@ -141,7 +141,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
|
||||
// set up the scale based layer visibility stuff....
|
||||
mScaleRangeWidget->setMapCanvas( mMapCanvas );
|
||||
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / lyr->maximumScale(), 1.0 / lyr->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / lyr->minimumScale(), 1.0 / lyr->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
|
||||
|
||||
leNoDataValue->setValidator( new QDoubleValidator( -std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), 1000, this ) );
|
||||
|
||||
@ -911,8 +911,8 @@ void QgsRasterLayerProperties::apply()
|
||||
// set up the scale based layer visibility stuff....
|
||||
mRasterLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
|
||||
// caution: layer uses scale denoms, widget uses true scales
|
||||
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
|
||||
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );
|
||||
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->minimumScale() );
|
||||
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->maximumScale() );
|
||||
|
||||
mRasterLayer->setAutoRefreshInterval( mRefreshLayerIntervalSpinBox->value() * 1000.0 );
|
||||
mRasterLayer->setAutoRefreshEnabled( mRefreshLayerCheckBox->isChecked() );
|
||||
|
@ -411,7 +411,7 @@ void QgsVectorLayerProperties::syncToLayer()
|
||||
mDisplayExpressionWidget->setField( mLayer->displayExpression() );
|
||||
|
||||
// set up the scale based layer visibility stuff....
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / mLayer->maximumScale(), 1.0 / mLayer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
|
||||
mScaleRangeWidget->setScaleRange( 1.0 / mLayer->minimumScale(), 1.0 / mLayer->maximumScale() ); // caution: layer uses scale denoms, widget uses true scales
|
||||
mScaleVisibilityGroupBox->setChecked( mLayer->hasScaleBasedVisibility() );
|
||||
mScaleRangeWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );
|
||||
|
||||
@ -510,8 +510,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( mScaleRangeWidget->maximumScaleDenom() );
|
||||
mLayer->setMinimumScale( mScaleRangeWidget->minimumScaleDenom() );
|
||||
mLayer->setMinimumScale( mScaleRangeWidget->maximumScaleDenom() );
|
||||
mLayer->setMaximumScale( mScaleRangeWidget->minimumScaleDenom() );
|
||||
|
||||
// provider-specific options
|
||||
if ( mLayer->dataProvider() )
|
||||
|
@ -3361,9 +3361,9 @@ static QVariant fcnGetLayerProperty( const QVariantList &values, const QgsExpres
|
||||
else if ( QString::compare( layerProperty, QStringLiteral( "source" ), Qt::CaseInsensitive ) == 0 )
|
||||
return layer->publicSource();
|
||||
else if ( QString::compare( layerProperty, QStringLiteral( "min_scale" ), Qt::CaseInsensitive ) == 0 )
|
||||
return layer->minimumScale();
|
||||
else if ( QString::compare( layerProperty, QStringLiteral( "max_scale" ), Qt::CaseInsensitive ) == 0 )
|
||||
return layer->maximumScale();
|
||||
else if ( QString::compare( layerProperty, QStringLiteral( "max_scale" ), Qt::CaseInsensitive ) == 0 )
|
||||
return layer->minimumScale();
|
||||
else if ( QString::compare( layerProperty, QStringLiteral( "crs" ), Qt::CaseInsensitive ) == 0 )
|
||||
return layer->crs().authid();
|
||||
else if ( QString::compare( layerProperty, QStringLiteral( "crs_definition" ), Qt::CaseInsensitive ) == 0 )
|
||||
|
@ -106,8 +106,8 @@ void QgsMapLayer::clone( QgsMapLayer *layer ) const
|
||||
layer->setName( name() );
|
||||
layer->setShortName( shortName() );
|
||||
layer->setExtent( extent() );
|
||||
layer->setMinimumScale( minimumScale() );
|
||||
layer->setMaximumScale( maximumScale() );
|
||||
layer->setMinimumScale( minimumScale() );
|
||||
layer->setScaleBasedVisibility( hasScaleBasedVisibility() );
|
||||
layer->setTitle( title() );
|
||||
layer->setAbstract( abstract() );
|
||||
@ -460,8 +460,17 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, const QgsReadWr
|
||||
|
||||
// use scale dependent visibility flag
|
||||
setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
|
||||
setMinimumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
|
||||
setMaximumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
|
||||
if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
|
||||
{
|
||||
// older element, when scales were reversed
|
||||
setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
|
||||
setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
|
||||
setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
|
||||
}
|
||||
|
||||
setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ), 0 ).toInt() );
|
||||
setAutoRefreshEnabled( layerElement.attribute( QStringLiteral( "autoRefreshEnabled" ), QStringLiteral( "0" ) ).toInt() );
|
||||
@ -564,8 +573,8 @@ bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &docume
|
||||
{
|
||||
// use scale dependent visibility flag
|
||||
layerElement.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
|
||||
layerElement.setAttribute( QStringLiteral( "minimumScale" ), QString::number( minimumScale() ) );
|
||||
layerElement.setAttribute( QStringLiteral( "maximumScale" ), QString::number( maximumScale() ) );
|
||||
layerElement.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
|
||||
layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );
|
||||
|
||||
if ( !mExtent.isNull() )
|
||||
{
|
||||
@ -922,18 +931,18 @@ const QgsLayerMetadata &QgsMapLayer::metadata() const
|
||||
return mMetadata;
|
||||
}
|
||||
|
||||
void QgsMapLayer::setMinimumScale( double scale )
|
||||
void QgsMapLayer::setMaximumScale( double scale )
|
||||
{
|
||||
mMinScale = scale;
|
||||
}
|
||||
|
||||
double QgsMapLayer::minimumScale() const
|
||||
double QgsMapLayer::maximumScale() const
|
||||
{
|
||||
return mMinScale;
|
||||
}
|
||||
|
||||
|
||||
void QgsMapLayer::setMaximumScale( double scale )
|
||||
void QgsMapLayer::setMinimumScale( double scale )
|
||||
{
|
||||
mMaxScale = scale;
|
||||
}
|
||||
@ -943,7 +952,7 @@ void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
|
||||
mScaleBasedVisibility = enabled;
|
||||
}
|
||||
|
||||
double QgsMapLayer::maximumScale() const
|
||||
double QgsMapLayer::minimumScale() const
|
||||
{
|
||||
return mMaxScale;
|
||||
}
|
||||
@ -1191,8 +1200,17 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe
|
||||
|
||||
// use scale dependent visibility flag
|
||||
setScaleBasedVisibility( myRoot.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
|
||||
setMinimumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
|
||||
setMaximumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
|
||||
if ( myRoot.hasAttribute( QStringLiteral( "minimumScale" ) ) )
|
||||
{
|
||||
//older scale element, when min/max were reversed
|
||||
setMaximumScale( myRoot.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
|
||||
setMinimumScale( myRoot.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumScale( myRoot.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
|
||||
setMinimumScale( myRoot.attribute( QStringLiteral( "minScale" ) ).toDouble() );
|
||||
}
|
||||
|
||||
return readSymbology( myRoot, myErrorMessage, QgsReadWriteContext() ); // TODO: support relative paths in QML?
|
||||
}
|
||||
@ -1208,8 +1226,8 @@ void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg ) const
|
||||
myDocument.appendChild( myRootNode );
|
||||
|
||||
myRootNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
|
||||
myRootNode.setAttribute( QStringLiteral( "minimumScale" ), QString::number( minimumScale() ) );
|
||||
myRootNode.setAttribute( QStringLiteral( "maximumScale" ), QString::number( maximumScale() ) );
|
||||
myRootNode.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
|
||||
myRootNode.setAttribute( QStringLiteral( "mincale" ), QString::number( minimumScale() ) );
|
||||
|
||||
if ( !writeSymbology( myRootNode, myDocument, errorMsg, QgsReadWriteContext() ) ) // TODO: support relative paths in QML?
|
||||
{
|
||||
|
@ -689,9 +689,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
|
||||
*/
|
||||
bool isInScaleRange( double scale ) const;
|
||||
|
||||
/** Returns the minimum scale denominator at which the layer is visible.
|
||||
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||
* \returns minimum scale denominator at which the layer will render
|
||||
/**
|
||||
* Returns the minimum map scale (i.e. most "zoomed out" scale) at which the layer will be visible.
|
||||
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
* A scale of 0 indicates no minimum scale visibility.
|
||||
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
* \see setMinimumScale()
|
||||
* \see maximumScale()
|
||||
* \see hasScaleBasedVisibility()
|
||||
@ -699,9 +701,11 @@ class CORE_EXPORT QgsMapLayer : public QObject
|
||||
*/
|
||||
double minimumScale() const;
|
||||
|
||||
/** Returns the maximum scale denominator at which the layer is visible.
|
||||
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||
* \returns minimum scale denominator at which the layer will render
|
||||
/**
|
||||
* Returns the maximum map scale (i.e. most "zoomed in" scale) at which the layer will be visible.
|
||||
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
* A scale of 0 indicates no maximum scale visibility.
|
||||
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
* \see setMaximumScale()
|
||||
* \see minimumScale()
|
||||
* \see hasScaleBasedVisibility()
|
||||
@ -792,21 +796,25 @@ class CORE_EXPORT QgsMapLayer : public QObject
|
||||
|
||||
public slots:
|
||||
|
||||
/** Sets the minimum scale denominator at which the layer will be visible.
|
||||
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
|
||||
* \param scale minimum scale denominator at which the layer should render
|
||||
* \see minimumScale
|
||||
* \see setMaximumScale
|
||||
* \see setScaleBasedVisibility
|
||||
/**
|
||||
* Sets the minimum map \a scale (i.e. most "zoomed out" scale) at which the layer will be visible.
|
||||
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
* A \a scale of 0 indicates no minimum scale visibility.
|
||||
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
* \see minimumScale()
|
||||
* \see setMaximumScale()
|
||||
* \see setScaleBasedVisibility()
|
||||
*/
|
||||
void setMinimumScale( double scale );
|
||||
|
||||
/** Sets the maximum scale denominator at which the layer will be visible.
|
||||
* Scale based visibility is only used if setScaleBasedVisibility is set to true.
|
||||
* \param scale maximum scale denominator at which the layer should render
|
||||
* \see maximumScale
|
||||
* \see setMinimumScale
|
||||
* \see setScaleBasedVisibility
|
||||
/**
|
||||
* Sets the maximum map \a scale (i.e. most "zoomed in" scale) at which the layer will be visible.
|
||||
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
|
||||
* A \a scale of 0 indicates no maximum scale visibility.
|
||||
* \note Scale based visibility is only used if setScaleBasedVisibility() is set to true.
|
||||
* \see maximumScale()
|
||||
* \see setMinimumScale()
|
||||
* \see setScaleBasedVisibility()
|
||||
*/
|
||||
void setMaximumScale( double scale );
|
||||
|
||||
|
@ -2209,7 +2209,7 @@ bool QgsVectorLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
|
||||
QgsStringMap localProps = QgsStringMap( props );
|
||||
if ( hasScaleBasedVisibility() )
|
||||
{
|
||||
QgsSymbolLayerUtils::mergeScaleDependencies( minimumScale(), maximumScale(), localProps );
|
||||
QgsSymbolLayerUtils::mergeScaleDependencies( maximumScale(), minimumScale(), localProps );
|
||||
}
|
||||
|
||||
if ( hasGeometryType() )
|
||||
|
@ -588,12 +588,9 @@ void QgsWmsConfigParser::setLayerIdsToLegendModel( QgsLegendModel *model, const
|
||||
else
|
||||
{
|
||||
QgsMapLayer *layer = nodeLayer->layer();
|
||||
if ( layer->hasScaleBasedVisibility() )
|
||||
if ( !layer->isInScaleRange( scale ) )
|
||||
{
|
||||
if ( layer->minimumScale() > scale )
|
||||
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
|
||||
else if ( layer->maximumScale() < scale )
|
||||
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
|
||||
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1324,19 +1324,19 @@ void QgsWmsProjectParser::addLayers( QDomDocument &doc,
|
||||
double SCALE_TO_SCALEHINT = OGC_PX_M * sqrt( 2.0 );
|
||||
|
||||
QDomElement scaleHintElem = doc.createElement( QStringLiteral( "ScaleHint" ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( currentLayer->minimumScale() * SCALE_TO_SCALEHINT ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( currentLayer->maximumScale() * SCALE_TO_SCALEHINT ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( currentLayer->maximumScale() * SCALE_TO_SCALEHINT ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( currentLayer->minimumScale() * SCALE_TO_SCALEHINT ) );
|
||||
layerElem.appendChild( scaleHintElem );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString minScaleString = QString::number( currentLayer->minimumScale() );
|
||||
QString minScaleString = QString::number( currentLayer->maximumScale() );
|
||||
QDomElement minScaleElem = doc.createElement( QStringLiteral( "MinScaleDenominator" ) );
|
||||
QDomText minScaleText = doc.createTextNode( minScaleString );
|
||||
minScaleElem.appendChild( minScaleText );
|
||||
layerElem.appendChild( minScaleElem );
|
||||
|
||||
QString maxScaleString = QString::number( currentLayer->maximumScale() );
|
||||
QString maxScaleString = QString::number( currentLayer->minimumScale() );
|
||||
QDomElement maxScaleElem = doc.createElement( QStringLiteral( "MaxScaleDenominator" ) );
|
||||
QDomText maxScaleText = doc.createTextNode( maxScaleString );
|
||||
maxScaleElem.appendChild( maxScaleText );
|
||||
@ -1638,8 +1638,8 @@ void QgsWmsProjectParser::addOWSLayers( QDomDocument &doc,
|
||||
//min/max scale denominatormScaleBasedVisibility
|
||||
if ( currentLayer->hasScaleBasedVisibility() )
|
||||
{
|
||||
QString minScaleString = QString::number( currentLayer->minimumScale() );
|
||||
QString maxScaleString = QString::number( currentLayer->maximumScale() );
|
||||
QString minScaleString = QString::number( currentLayer->maximumScale() );
|
||||
QString maxScaleString = QString::number( currentLayer->minimumScale() );
|
||||
QDomElement minScaleElem = doc.createElement( QStringLiteral( "sld:MinScaleDenominator" ) );
|
||||
QDomText minScaleText = doc.createTextNode( minScaleString );
|
||||
minScaleElem.appendChild( minScaleText );
|
||||
|
@ -1002,19 +1002,19 @@ namespace QgsWms
|
||||
double SCALE_TO_SCALEHINT = OGC_PX_M * sqrt( 2.0 );
|
||||
|
||||
QDomElement scaleHintElem = doc.createElement( QStringLiteral( "ScaleHint" ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( l->minimumScale() * SCALE_TO_SCALEHINT ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( l->maximumScale() * SCALE_TO_SCALEHINT ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "min" ), QString::number( l->maximumScale() * SCALE_TO_SCALEHINT ) );
|
||||
scaleHintElem.setAttribute( QStringLiteral( "max" ), QString::number( l->minimumScale() * SCALE_TO_SCALEHINT ) );
|
||||
layerElem.appendChild( scaleHintElem );
|
||||
}
|
||||
else
|
||||
{
|
||||
QString minScaleString = QString::number( l->minimumScale() );
|
||||
QString minScaleString = QString::number( l->maximumScale() );
|
||||
QDomElement minScaleElem = doc.createElement( QStringLiteral( "MinScaleDenominator" ) );
|
||||
QDomText minScaleText = doc.createTextNode( minScaleString );
|
||||
minScaleElem.appendChild( minScaleText );
|
||||
layerElem.appendChild( minScaleElem );
|
||||
|
||||
QString maxScaleString = QString::number( l->maximumScale() );
|
||||
QString maxScaleString = QString::number( l->minimumScale() );
|
||||
QDomElement maxScaleElem = doc.createElement( QStringLiteral( "MaxScaleDenominator" ) );
|
||||
QDomText maxScaleText = doc.createTextNode( maxScaleString );
|
||||
maxScaleElem.appendChild( maxScaleText );
|
||||
|
@ -338,8 +338,8 @@ namespace QgsWms
|
||||
//min/max scale denominatorScaleBasedVisibility
|
||||
if ( l->hasScaleBasedVisibility() )
|
||||
{
|
||||
QString minScaleString = QString::number( l->minimumScale() );
|
||||
QString maxScaleString = QString::number( l->maximumScale() );
|
||||
QString minScaleString = QString::number( l->maximumScale() );
|
||||
QString maxScaleString = QString::number( l->minimumScale() );
|
||||
QDomElement minScaleElem = doc.createElement( QStringLiteral( "sld:MinScaleDenominator" ) );
|
||||
QDomText minScaleText = doc.createTextNode( minScaleString );
|
||||
minScaleElem.appendChild( minScaleText );
|
||||
|
@ -1104,8 +1104,7 @@ namespace QgsWms
|
||||
#endif
|
||||
|
||||
//skip layer if not visible at current map scale
|
||||
bool useScaleConstraint = ( scaleDenominator > 0 && currentLayer->hasScaleBasedVisibility() );
|
||||
if ( useScaleConstraint && ( currentLayer->minimumScale() > scaleDenominator || currentLayer->maximumScale() < scaleDenominator ) )
|
||||
if ( scaleDenominator > 0 && !currentLayer->isInScaleRange( scaleDenominator ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1886,9 +1885,7 @@ namespace QgsWms
|
||||
lName = mapLayer->shortName();
|
||||
QgsMessageLog::logMessage( QStringLiteral( "Checking layer: %1" ).arg( lName ) );
|
||||
//test if layer is visible in requested scale
|
||||
bool useScaleConstraint = ( scaleDenominator > 0 && mapLayer->hasScaleBasedVisibility() );
|
||||
if ( !useScaleConstraint ||
|
||||
( mapLayer->minimumScale() <= scaleDenominator && mapLayer->maximumScale() >= scaleDenominator ) )
|
||||
if ( scaleDenominator == 0 || mapLayer->isInScaleRange( scaleDenominator ) )
|
||||
{
|
||||
layerKeys.push_front( mapLayer->id() );
|
||||
QgsProject::instance()->addMapLayers(
|
||||
|
@ -93,8 +93,8 @@ class TestQgsExpression: public QObject
|
||||
mPointsLayer->setDataUrl( QStringLiteral( "data url" ) );
|
||||
mPointsLayer->setAttribution( QStringLiteral( "layer attribution" ) );
|
||||
mPointsLayer->setAttributionUrl( QStringLiteral( "attribution url" ) );
|
||||
mPointsLayer->setMaximumScale( 500 );
|
||||
mPointsLayer->setMinimumScale( 1000 );
|
||||
mPointsLayer->setMinimumScale( 500 );
|
||||
mPointsLayer->setMaximumScale( 1000 );
|
||||
|
||||
QString rasterFileName = testDataDir + "tenbytenraster.asc";
|
||||
QFileInfo rasterFileInfo( rasterFileName );
|
||||
@ -1086,8 +1086,8 @@ class TestQgsExpression: public QObject
|
||||
QTest::newRow( "layer_property attribution" ) << QStringLiteral( "layer_property('%1','attribution')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->attribution() );
|
||||
QTest::newRow( "layer_property attribution_url" ) << QStringLiteral( "layer_property('%1','attribution_url')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->attributionUrl() );
|
||||
QTest::newRow( "layer_property source" ) << QStringLiteral( "layer_property('%1','source')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->publicSource() );
|
||||
QTest::newRow( "layer_property min_scale" ) << QStringLiteral( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->minimumScale() );
|
||||
QTest::newRow( "layer_property max_scale" ) << QStringLiteral( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->maximumScale() );
|
||||
QTest::newRow( "layer_property min_scale" ) << QStringLiteral( "layer_property('%1','min_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->maximumScale() );
|
||||
QTest::newRow( "layer_property max_scale" ) << QStringLiteral( "layer_property('%1','max_scale')" ).arg( mPointsLayer->name() ) << false << QVariant( mPointsLayer->minimumScale() );
|
||||
QTest::newRow( "layer_property crs" ) << QStringLiteral( "layer_property('%1','crs')" ).arg( mPointsLayer->name() ) << false << QVariant( "EPSG:4326" );
|
||||
QTest::newRow( "layer_property extent" ) << QStringLiteral( "geom_to_wkt(layer_property('%1','extent'))" ).arg( mPointsLayer->name() ) << false << QVariant( "Polygon ((-118.88888889 22.80020704, -83.33333333 22.80020704, -83.33333333 46.87198068, -118.88888889 46.87198068, -118.88888889 22.80020704))" );
|
||||
QTest::newRow( "layer_property type" ) << QStringLiteral( "layer_property('%1','type')" ).arg( mPointsLayer->name() ) << false << QVariant( "Vector" );
|
||||
|
@ -149,8 +149,8 @@ void TestQgsMapLayer::isInScaleRange()
|
||||
QFETCH( double, scale );
|
||||
QFETCH( bool, isInScale );
|
||||
|
||||
mpLayer->setMinimumScale( 2500.0 );
|
||||
mpLayer->setMaximumScale( 5000.0 );
|
||||
mpLayer->setMaximumScale( 2500.0 );
|
||||
mpLayer->setMinimumScale( 5000.0 );
|
||||
mpLayer->setScaleBasedVisibility( true );
|
||||
QCOMPARE( mpLayer->isInScaleRange( scale ), isInScale );
|
||||
//always in scale range if scale based visibility is false
|
||||
@ -160,8 +160,8 @@ void TestQgsMapLayer::isInScaleRange()
|
||||
|
||||
void TestQgsMapLayer::isInScaleRange2()
|
||||
{
|
||||
mpLayer->setMinimumScale( 5000.0 );
|
||||
mpLayer->setMaximumScale( 0.0 );
|
||||
mpLayer->setMaximumScale( 5000.0 );
|
||||
mpLayer->setMinimumScale( 0.0 );
|
||||
mpLayer->setScaleBasedVisibility( true );
|
||||
QVERIFY( !mpLayer->isInScaleRange( 1000 ) );
|
||||
QVERIFY( !mpLayer->isInScaleRange( 1 ) );
|
||||
@ -169,8 +169,8 @@ void TestQgsMapLayer::isInScaleRange2()
|
||||
QVERIFY( mpLayer->isInScaleRange( 5001 ) );
|
||||
QVERIFY( mpLayer->isInScaleRange( 15000 ) );
|
||||
|
||||
mpLayer->setMinimumScale( 0.0 );
|
||||
mpLayer->setMaximumScale( 5000.0 );
|
||||
mpLayer->setMaximumScale( 0.0 );
|
||||
mpLayer->setMinimumScale( 5000.0 );
|
||||
mpLayer->setScaleBasedVisibility( true );
|
||||
QVERIFY( mpLayer->isInScaleRange( 1000 ) );
|
||||
QVERIFY( mpLayer->isInScaleRange( 1 ) );
|
||||
|
@ -417,8 +417,8 @@ class TestQgsSymbolLayerCreateSld(unittest.TestCase):
|
||||
layer = QgsVectorLayer("Point", "addfeat", "memory")
|
||||
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "singleSymbol"))
|
||||
layer.loadNamedStyle(mFilePath)
|
||||
layer.setMinimumScale(1000)
|
||||
layer.setMaximumScale(500000)
|
||||
layer.setMaximumScale(1000)
|
||||
layer.setMinimumScale(500000)
|
||||
layer.setScaleBasedVisibility(True)
|
||||
|
||||
dom, root = self.layerToSld(layer)
|
||||
@ -442,8 +442,8 @@ class TestQgsSymbolLayerCreateSld(unittest.TestCase):
|
||||
layer = QgsVectorLayer("Polygon", "addfeat", "memory")
|
||||
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "categorized"))
|
||||
layer.loadNamedStyle(mFilePath)
|
||||
layer.setMinimumScale(1000)
|
||||
layer.setMaximumScale(500000)
|
||||
layer.setMaximumScale(1000)
|
||||
layer.setMinimumScale(500000)
|
||||
layer.setScaleBasedVisibility(True)
|
||||
|
||||
dom, root = self.layerToSld(layer)
|
||||
@ -484,8 +484,8 @@ class TestQgsSymbolLayerCreateSld(unittest.TestCase):
|
||||
|
||||
mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.qml' % (unitTestDataPath(), "ruleBased"))
|
||||
status = layer.loadNamedStyle(mFilePath) # NOQA
|
||||
layer.setMinimumScale(5000)
|
||||
layer.setMaximumScale(50000000)
|
||||
layer.setMaximumScale(5000)
|
||||
layer.setMinimumScale(50000000)
|
||||
layer.setScaleBasedVisibility(True)
|
||||
|
||||
dom, root = self.layerToSld(layer)
|
||||
|
@ -2176,8 +2176,8 @@ class TestQgsVectorLayer(unittest.TestCase, FeatureSourceTestCase):
|
||||
layer.styleManager().addStyle('style1', style1)
|
||||
layer.setName('MyName')
|
||||
layer.setShortName('MyShortName')
|
||||
layer.setMinimumScale(0.5)
|
||||
layer.setMaximumScale(1.5)
|
||||
layer.setMaximumScale(0.5)
|
||||
layer.setMinimumScale(1.5)
|
||||
layer.setScaleBasedVisibility(True)
|
||||
layer.setTitle('MyTitle')
|
||||
layer.setAbstract('MyAbstract')
|
||||
|
Loading…
x
Reference in New Issue
Block a user