mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -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
|
//! emit dataChanged() for layer tree node items
|
||||||
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
|
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() );
|
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );
|
||||||
|
|
||||||
static const QIcon& iconGroup();
|
static const QIcon& iconGroup();
|
||||||
|
@ -492,34 +492,42 @@ class QgsMapLayer : QObject
|
|||||||
*/
|
*/
|
||||||
QgsMapLayerStyleManager* styleManager() const;
|
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.
|
* @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;
|
bool isInScaleRange( double scale ) const;
|
||||||
|
|
||||||
/** Returns the minimum scale denominator at which the layer is visible.
|
/** Returns the minimum scale denominator at which the layer is visible.
|
||||||
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||||
* @returns minimum scale denominator at which the layer will render
|
* @returns minimum scale denominator at which the layer will render
|
||||||
* @see setMinimumScale
|
* @see setMinimumScale()
|
||||||
* @see maximumScale
|
* @see maximumScale()
|
||||||
* @see hasScaleBasedVisibility
|
* @see hasScaleBasedVisibility()
|
||||||
|
* @see isInScaleRange()
|
||||||
*/
|
*/
|
||||||
float minimumScale() const;
|
float minimumScale() const;
|
||||||
|
|
||||||
/** Returns the maximum scale denominator at which the layer is visible.
|
/** Returns the maximum scale denominator at which the layer is visible.
|
||||||
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||||
* @returns minimum scale denominator at which the layer will render
|
* @returns minimum scale denominator at which the layer will render
|
||||||
* @see setMaximumScale
|
* @see setMaximumScale()
|
||||||
* @see minimumScale
|
* @see minimumScale()
|
||||||
* @see hasScaleBasedVisibility
|
* @see hasScaleBasedVisibility()
|
||||||
|
* @see isInScaleRange()
|
||||||
*/
|
*/
|
||||||
float maximumScale() const;
|
float maximumScale() const;
|
||||||
|
|
||||||
/** Returns whether scale based visibility is enabled for the layer.
|
/** Returns whether scale based visibility is enabled for the layer.
|
||||||
* @returns true if scale based visibility is enabled
|
* @returns true if scale based visibility is enabled
|
||||||
* @see minimumScale
|
* @see minimumScale()
|
||||||
* @see maximumScale
|
* @see maximumScale()
|
||||||
* @see setScaleBasedVisibility
|
* @see setScaleBasedVisibility()
|
||||||
|
* @see isInScaleRange()
|
||||||
*/
|
*/
|
||||||
bool hasScaleBasedVisibility() const;
|
bool hasScaleBasedVisibility() const;
|
||||||
|
|
||||||
|
@ -742,8 +742,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
|||||||
void removeLayer();
|
void removeLayer();
|
||||||
//! Duplicate map layer(s) in legend
|
//! Duplicate map layer(s) in legend
|
||||||
void duplicateLayers( const QList<QgsMapLayer *>& lyrList = QList<QgsMapLayer *>() );
|
void duplicateLayers( const QList<QgsMapLayer *>& lyrList = QList<QgsMapLayer *>() );
|
||||||
//! Set Scale visibility of selected layers
|
//! Set scale visibility of selected layers
|
||||||
void setLayerScaleVisibility();
|
void setLayerScaleVisibility();
|
||||||
|
//! Zoom to nearest scale such that current layer is visible
|
||||||
void zoomToLayerScale();
|
void zoomToLayerScale();
|
||||||
//! Set CRS of a layer
|
//! Set CRS of a layer
|
||||||
void setLayerCRS();
|
void setLayerCRS();
|
||||||
|
@ -107,10 +107,10 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
|||||||
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
|
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
|
||||||
|
|
||||||
if ( !vlayer->isInScaleRange( mCanvas->scale() ) )
|
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
|
// 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
|
// assign layer crs to project
|
||||||
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
|
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
|
//! emit dataChanged() for layer tree node items
|
||||||
void recursivelyEmitDataChanged( const QModelIndex& index = QModelIndex() );
|
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() );
|
void refreshScaleBasedLayers( const QModelIndex& index = QModelIndex() );
|
||||||
|
|
||||||
static const QIcon& iconGroup();
|
static const QIcon& iconGroup();
|
||||||
|
@ -511,34 +511,42 @@ class CORE_EXPORT QgsMapLayer : public QObject
|
|||||||
*/
|
*/
|
||||||
QgsMapLayerStyleManager* styleManager() const;
|
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.
|
* @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;
|
bool isInScaleRange( double scale ) const;
|
||||||
|
|
||||||
/** Returns the minimum scale denominator at which the layer is visible.
|
/** Returns the minimum scale denominator at which the layer is visible.
|
||||||
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||||
* @returns minimum scale denominator at which the layer will render
|
* @returns minimum scale denominator at which the layer will render
|
||||||
* @see setMinimumScale
|
* @see setMinimumScale()
|
||||||
* @see maximumScale
|
* @see maximumScale()
|
||||||
* @see hasScaleBasedVisibility
|
* @see hasScaleBasedVisibility()
|
||||||
|
* @see isInScaleRange()
|
||||||
*/
|
*/
|
||||||
float minimumScale() const;
|
float minimumScale() const;
|
||||||
|
|
||||||
/** Returns the maximum scale denominator at which the layer is visible.
|
/** Returns the maximum scale denominator at which the layer is visible.
|
||||||
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
* Scale based visibility is only used if hasScaleBasedVisibility is true.
|
||||||
* @returns minimum scale denominator at which the layer will render
|
* @returns minimum scale denominator at which the layer will render
|
||||||
* @see setMaximumScale
|
* @see setMaximumScale()
|
||||||
* @see minimumScale
|
* @see minimumScale()
|
||||||
* @see hasScaleBasedVisibility
|
* @see hasScaleBasedVisibility()
|
||||||
|
* @see isInScaleRange()
|
||||||
*/
|
*/
|
||||||
float maximumScale() const;
|
float maximumScale() const;
|
||||||
|
|
||||||
/** Returns whether scale based visibility is enabled for the layer.
|
/** Returns whether scale based visibility is enabled for the layer.
|
||||||
* @returns true if scale based visibility is enabled
|
* @returns true if scale based visibility is enabled
|
||||||
* @see minimumScale
|
* @see minimumScale()
|
||||||
* @see maximumScale
|
* @see maximumScale()
|
||||||
* @see setScaleBasedVisibility
|
* @see setScaleBasedVisibility()
|
||||||
|
* @see isInScaleRange()
|
||||||
*/
|
*/
|
||||||
bool hasScaleBasedVisibility() const;
|
bool hasScaleBasedVisibility() const;
|
||||||
|
|
||||||
|
@ -62,8 +62,10 @@ class TestQgsMapLayer : public QObject
|
|||||||
|
|
||||||
void setBlendMode();
|
void setBlendMode();
|
||||||
|
|
||||||
|
void isInScaleRange_data();
|
||||||
void isInScaleRange();
|
void isInScaleRange();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QgsMapLayer * mpLayer;
|
QgsMapLayer * mpLayer;
|
||||||
};
|
};
|
||||||
@ -119,17 +121,32 @@ void TestQgsMapLayer::setBlendMode()
|
|||||||
QCOMPARE( mpLayer->blendMode(), QPainter::CompositionMode_Screen );
|
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()
|
void TestQgsMapLayer::isInScaleRange()
|
||||||
{
|
{
|
||||||
|
QFETCH( float, scale );
|
||||||
|
QFETCH( bool, isInScale );
|
||||||
|
|
||||||
mpLayer->setMinimumScale( 2500.0f );
|
mpLayer->setMinimumScale( 2500.0f );
|
||||||
mpLayer->setMaximumScale( 5000.0f );
|
mpLayer->setMaximumScale( 5000.0f );
|
||||||
mpLayer->setScaleBasedVisibility( true );
|
mpLayer->setScaleBasedVisibility( true );
|
||||||
QCOMPARE( mpLayer->isInScaleRange( 3000.0f ), true ); // In the middle
|
QCOMPARE( mpLayer->isInScaleRange( scale ), isInScale );
|
||||||
QCOMPARE( mpLayer->isInScaleRange( 1000.0f ), false ); // Too low
|
//always in scale range if scale based visibility is false
|
||||||
QCOMPARE( mpLayer->isInScaleRange( 6000.0f ), false ); // Too high
|
mpLayer->setScaleBasedVisibility( false );
|
||||||
QCOMPARE( mpLayer->isInScaleRange( 5000.0f ), false ); // Max is not inclusive
|
QCOMPARE( mpLayer->isInScaleRange( scale ), true );
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN( TestQgsMapLayer )
|
QTEST_MAIN( TestQgsMapLayer )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user