mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Followup 01f615d
This commit is contained in:
parent
01f615d0d0
commit
3b4638ab83
@ -230,6 +230,11 @@ class QgsLayerTreeModel : QAbstractItemModel
|
||||
|
||||
//! emit dataChanged() for layer tree node items
|
||||
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
|
||||
|
||||
/** Updates layer data for scale dependent layers, should be called when map scale changes.
|
||||
* Emits dataChanged() for all scale dependent layers.
|
||||
* @note added in QGIS 2.16
|
||||
*/
|
||||
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );
|
||||
|
||||
static const QIcon& iconGroup();
|
||||
|
@ -492,34 +492,42 @@ class QgsMapLayer : QObject
|
||||
*/
|
||||
QgsMapLayerStyleManager* styleManager() const;
|
||||
|
||||
/**
|
||||
/** Tests whether the layer should be visible at the specified scale.
|
||||
* @param scale scale denominator to test
|
||||
* @returns true if the layer is visible at the given scale.
|
||||
* @note added in QGIS 2.16
|
||||
* @see minimumScale()
|
||||
* @see maximumScale()
|
||||
* @see hasScaleBasedVisibility()
|
||||
*/
|
||||
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
|
||||
* @see setMinimumScale
|
||||
* @see maximumScale
|
||||
* @see hasScaleBasedVisibility
|
||||
* @see setMinimumScale()
|
||||
* @see maximumScale()
|
||||
* @see hasScaleBasedVisibility()
|
||||
* @see isInScaleRange()
|
||||
*/
|
||||
float 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
|
||||
* @see setMaximumScale
|
||||
* @see minimumScale
|
||||
* @see hasScaleBasedVisibility
|
||||
* @see setMaximumScale()
|
||||
* @see minimumScale()
|
||||
* @see hasScaleBasedVisibility()
|
||||
* @see isInScaleRange()
|
||||
*/
|
||||
float maximumScale() const;
|
||||
|
||||
/** Returns whether scale based visibility is enabled for the layer.
|
||||
* @returns true if scale based visibility is enabled
|
||||
* @see minimumScale
|
||||
* @see maximumScale
|
||||
* @see setScaleBasedVisibility
|
||||
* @see minimumScale()
|
||||
* @see maximumScale()
|
||||
* @see setScaleBasedVisibility()
|
||||
* @see isInScaleRange()
|
||||
*/
|
||||
bool hasScaleBasedVisibility() const;
|
||||
|
||||
|
@ -742,8 +742,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
||||
void removeLayer();
|
||||
//! Duplicate map layer(s) in legend
|
||||
void duplicateLayers( const QList<QgsMapLayer *>& lyrList = QList<QgsMapLayer *>() );
|
||||
//! Set Scale visibility of selected layers
|
||||
//! Set scale visibility of selected layers
|
||||
void setLayerScaleVisibility();
|
||||
//! Zoom to nearest scale such that current layer is visible
|
||||
void zoomToLayerScale();
|
||||
//! Set CRS of a layer
|
||||
void setLayerCRS();
|
||||
|
@ -107,10 +107,10 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
||||
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
|
||||
|
||||
if ( !vlayer->isInScaleRange( mCanvas->scale() ) )
|
||||
menu->addAction( tr( "&Zoom to Layer Scale" ), QgisApp::instance(), SLOT( zoomToLayerScale() ) );
|
||||
menu->addAction( tr( "Zoom to Layer Scale" ), QgisApp::instance(), SLOT( zoomToLayerScale() ) );
|
||||
|
||||
// set layer crs
|
||||
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
|
||||
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
|
||||
|
||||
// assign layer crs to project
|
||||
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
|
||||
|
@ -254,7 +254,11 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
|
||||
|
||||
//! emit dataChanged() for layer tree node items
|
||||
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
|
||||
//! emit dataChanged() for scale dependent layers
|
||||
|
||||
/** Updates layer data for scale dependent layers, should be called when map scale changes.
|
||||
* Emits dataChanged() for all scale dependent layers.
|
||||
* @note added in QGIS 2.16
|
||||
*/
|
||||
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );
|
||||
|
||||
static const QIcon& iconGroup();
|
||||
|
@ -511,34 +511,42 @@ class CORE_EXPORT QgsMapLayer : public QObject
|
||||
*/
|
||||
QgsMapLayerStyleManager* styleManager() const;
|
||||
|
||||
/**
|
||||
/** Tests whether the layer should be visible at the specified scale.
|
||||
* @param scale scale denominator to test
|
||||
* @returns true if the layer is visible at the given scale.
|
||||
* @note added in QGIS 2.16
|
||||
* @see minimumScale()
|
||||
* @see maximumScale()
|
||||
* @see hasScaleBasedVisibility()
|
||||
*/
|
||||
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
|
||||
* @see setMinimumScale
|
||||
* @see maximumScale
|
||||
* @see hasScaleBasedVisibility
|
||||
* @see setMinimumScale()
|
||||
* @see maximumScale()
|
||||
* @see hasScaleBasedVisibility()
|
||||
* @see isInScaleRange()
|
||||
*/
|
||||
float 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
|
||||
* @see setMaximumScale
|
||||
* @see minimumScale
|
||||
* @see hasScaleBasedVisibility
|
||||
* @see setMaximumScale()
|
||||
* @see minimumScale()
|
||||
* @see hasScaleBasedVisibility()
|
||||
* @see isInScaleRange()
|
||||
*/
|
||||
float maximumScale() const;
|
||||
|
||||
/** Returns whether scale based visibility is enabled for the layer.
|
||||
* @returns true if scale based visibility is enabled
|
||||
* @see minimumScale
|
||||
* @see maximumScale
|
||||
* @see setScaleBasedVisibility
|
||||
* @see minimumScale()
|
||||
* @see maximumScale()
|
||||
* @see setScaleBasedVisibility()
|
||||
* @see isInScaleRange()
|
||||
*/
|
||||
bool hasScaleBasedVisibility() const;
|
||||
|
||||
|
@ -62,8 +62,10 @@ class TestQgsMapLayer : public QObject
|
||||
|
||||
void setBlendMode();
|
||||
|
||||
void isInScaleRange_data();
|
||||
void isInScaleRange();
|
||||
|
||||
|
||||
private:
|
||||
QgsMapLayer * mpLayer;
|
||||
};
|
||||
@ -119,17 +121,32 @@ void TestQgsMapLayer::setBlendMode()
|
||||
QCOMPARE( mpLayer->blendMode(), QPainter::CompositionMode_Screen );
|
||||
}
|
||||
|
||||
void TestQgsMapLayer::isInScaleRange_data()
|
||||
{
|
||||
QTest::addColumn<float>( "scale" );
|
||||
QTest::addColumn<bool>( "isInScale" );
|
||||
|
||||
QTest::newRow( "in the middle" ) << 3000.0f << true;
|
||||
QTest::newRow( "too low" ) << 1000.0f << false;
|
||||
QTest::newRow( "too high" ) << 6000.0f << false;
|
||||
QTest::newRow( "max is not inclusive" ) << 5000.0f << false;
|
||||
QTest::newRow( "min is inclusive" ) << 2500.0f << true;
|
||||
QTest::newRow( "min is inclusive even with conversion errors" ) << static_cast< float >( 1.0f / (( float )1.0 / 2500.0 ) ) << true;
|
||||
}
|
||||
|
||||
void TestQgsMapLayer::isInScaleRange()
|
||||
{
|
||||
QFETCH( float, scale );
|
||||
QFETCH( bool, isInScale );
|
||||
|
||||
mpLayer->setMinimumScale( 2500.0f );
|
||||
mpLayer->setMaximumScale( 5000.0f );
|
||||
mpLayer->setScaleBasedVisibility( true );
|
||||
QCOMPARE( mpLayer->isInScaleRange( 3000.0f ), true ); // In the middle
|
||||
QCOMPARE( mpLayer->isInScaleRange( 1000.0f ), false ); // Too low
|
||||
QCOMPARE( mpLayer->isInScaleRange( 6000.0f ), false ); // Too high
|
||||
QCOMPARE( mpLayer->isInScaleRange( 5000.0f ), false ); // Max is not inclusive
|
||||
QCOMPARE( mpLayer->isInScaleRange( 2500.0f ), true ); // Min is inclusive
|
||||
QCOMPARE( mpLayer->isInScaleRange( 1.0f / (( float )1.0 / 2500.0 ) ), true ); // Min is inclusive even with conversion errors
|
||||
QCOMPARE( mpLayer->isInScaleRange( scale ), isInScale );
|
||||
//always in scale range if scale based visibility is false
|
||||
mpLayer->setScaleBasedVisibility( false );
|
||||
QCOMPARE( mpLayer->isInScaleRange( scale ), true );
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsMapLayer )
|
||||
|
Loading…
x
Reference in New Issue
Block a user