Skip to content
Permalink
Browse files

Clean up QgsMapLayer scale based visibility api

  • Loading branch information
nyalldawson committed Dec 5, 2014
1 parent 072c1e5 commit 8a182b7f3499f2766fa05e3d4002347bd5c8f64f
@@ -370,22 +370,68 @@ class QgsMapLayer : QObject
*/
QgsMapLayerLegend* legend() 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
*/
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
*/
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
*/
bool hasScaleBasedVisibility() const;

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
virtual void invalidTransformInput();

/** Accessor and mutator for the minimum scale denominator member */
void setMinimumScale( float theMinScale );
float minimumScale() const;
/**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 theMinScale minimum scale denominator at which the layer should render
* @see minimumScale
* @see setMaximumScale
* @see setScaleBasedVisibility
*/
void setMinimumScale( const float theMinScale );

/**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 theMaxScale maximum scale denominator at which the layer should render
* @see maximumScale
* @see setMinimumScale
* @see setScaleBasedVisibility
*/
void setMaximumScale( const float theMaxScale );

/** Accessor and mutator for the maximum scale denominator member */
void setMaximumScale( float theMaxScale );
float maximumScale() const;
/**Sets whether scale based visibility is enabled for the layer.
* @param enabled set to true to enable scale based visibility
* @see setMinimumScale
* @see setMaximumScale
* @see scaleBasedVisibility
*/
void setScaleBasedVisibility( const bool enabled );

/**Accessor for the scale based visilibility flag
* @deprecated use setScaleBasedVisibility instead
*/
void toggleScaleBasedVisibility( bool theVisibilityFlag ) /Deprecated/;

/** Accessor and mutator for the scale based visilibility flag */
void toggleScaleBasedVisibility( bool theVisibilityFlag );
bool hasScaleBasedVisibility() const;

/** Clear cached image
* @deprecated in 2.4 - use triggerRepaint() - caches automatically listen to repaintRequested() signal to invalidate the cached image */
@@ -7082,7 +7082,7 @@ void QgisApp::setLayerScaleVisibility()
mMapCanvas->freeze();
foreach ( QgsMapLayer* layer, layers )
{
layer->toggleScaleBasedVisibility( dlg->hasScaleVisibility() );
layer->setScaleBasedVisibility( dlg->hasScaleVisibility() );
layer->setMinimumScale( 1.0 / dlg->maximumScale() );
layer->setMaximumScale( 1.0 / dlg->minimumScale() );
}
@@ -847,7 +847,7 @@ void QgsRasterLayerProperties::apply()
mRasterLayer->setLayerName( mLayerOrigNameLineEd->text() );

// set up the scale based layer visibility stuff....
mRasterLayer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
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() );
@@ -495,7 +495,7 @@ void QgsVectorLayerProperties::apply()
}

// set up the scale based layer visibility stuff....
layer->toggleScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
layer->setScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
// caution: layer uses scale denoms, widget uses true scales
layer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
layer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );
@@ -342,7 +342,7 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
}

// use scale dependent visibility flag
toggleScaleBasedVisibility( layerElement.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setScaleBasedVisibility( layerElement.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( layerElement.attribute( "minimumScale" ).toFloat() );
setMaximumScale( layerElement.attribute( "maximumScale" ).toFloat() );

@@ -738,15 +738,15 @@ void QgsMapLayer::connectNotify( const char * signal )

void QgsMapLayer::toggleScaleBasedVisibility( bool theVisibilityFlag )
{
mScaleBasedVisibility = theVisibilityFlag;
setScaleBasedVisibility( theVisibilityFlag );
}

bool QgsMapLayer::hasScaleBasedVisibility() const
{
return mScaleBasedVisibility;
}

void QgsMapLayer::setMinimumScale( float theMinScale )
void QgsMapLayer::setMinimumScale( const float theMinScale )
{
mMinScale = theMinScale;
}
@@ -757,17 +757,21 @@ float QgsMapLayer::minimumScale() const
}


void QgsMapLayer::setMaximumScale( float theMaxScale )
void QgsMapLayer::setMaximumScale( const float theMaxScale )
{
mMaxScale = theMaxScale;
}

void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
{
mScaleBasedVisibility = enabled;
}

float QgsMapLayer::maximumScale() const
{
return mMaxScale;
}


QStringList QgsMapLayer::subLayers() const
{
return QStringList(); // Empty
@@ -997,7 +1001,7 @@ QString QgsMapLayer::loadNamedStyle( const QString &theURI, bool &theResultFlag
}

// use scale dependent visibility flag
toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );

@@ -387,22 +387,67 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
QgsMapLayerLegend* legend() 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
*/
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
*/
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
*/
bool hasScaleBasedVisibility() const;

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
virtual void invalidTransformInput();

/** Accessor and mutator for the minimum scale denominator member */
void setMinimumScale( float theMinScale );
float minimumScale() const;
/**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 theMinScale minimum scale denominator at which the layer should render
* @see minimumScale
* @see setMaximumScale
* @see setScaleBasedVisibility
*/
void setMinimumScale( const float theMinScale );

/**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 theMaxScale maximum scale denominator at which the layer should render
* @see maximumScale
* @see setMinimumScale
* @see setScaleBasedVisibility
*/
void setMaximumScale( const float theMaxScale );

/** Accessor and mutator for the maximum scale denominator member */
void setMaximumScale( float theMaxScale );
float maximumScale() const;
/**Sets whether scale based visibility is enabled for the layer.
* @param enabled set to true to enable scale based visibility
* @see setMinimumScale
* @see setMaximumScale
* @see scaleBasedVisibility
*/
void setScaleBasedVisibility( const bool enabled );

/** Accessor and mutator for the scale based visilibility flag */
void toggleScaleBasedVisibility( bool theVisibilityFlag );
bool hasScaleBasedVisibility() const;
/**Accessor for the scale based visilibility flag
* @deprecated use setScaleBasedVisibility instead
*/
Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );

/** Clear cached image
* @deprecated in 2.4 - use triggerRepaint() - caches automatically listen to repaintRequested() signal to invalidate the cached image */
@@ -2143,7 +2143,7 @@ bool QgsVectorLayer::deleteAttributes( QList<int> attrs )

qSort( attrs.begin(), attrs.end(), qGreater<int>() );

Q_FOREACH( int attr, attrs )
Q_FOREACH ( int attr, attrs )
{
if ( deleteAttribute( attr ) )
{
@@ -2839,7 +2839,7 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
if ( mEditBuffer )
{
QSet<QString> vals;
Q_FOREACH( const QVariant& v, uniqueValues )
Q_FOREACH ( const QVariant& v, uniqueValues )
{
vals << v.toString();
}
@@ -3565,13 +3565,13 @@ void QgsVectorLayer::invalidateSymbolCountedFlag()

void QgsVectorLayer::onRelationsLoaded()
{
Q_FOREACH( QgsAttributeEditorElement* elem, mAttributeEditorElements )
Q_FOREACH ( QgsAttributeEditorElement* elem, mAttributeEditorElements )
{
if ( elem->type() == QgsAttributeEditorElement::AeTypeContainer )
{
QgsAttributeEditorContainer* cont = dynamic_cast< QgsAttributeEditorContainer* >( elem );
QList<QgsAttributeEditorElement*> relations = cont->findElements( QgsAttributeEditorElement::AeTypeRelation );
Q_FOREACH( QgsAttributeEditorElement* relElem, relations )
Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
{
QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
rel->init( QgsProject::instance()->relationManager() );
@@ -3627,7 +3627,7 @@ QDomElement QgsAttributeEditorContainer::toDomElement( QDomDocument& doc ) const
QDomElement elem = doc.createElement( "attributeEditorContainer" );
elem.setAttribute( "name", mName );

Q_FOREACH( QgsAttributeEditorElement* child, mChildren )
Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
{
elem.appendChild( child->toDomElement( doc ) );
}
@@ -3643,7 +3643,7 @@ QList<QgsAttributeEditorElement*> QgsAttributeEditorContainer::findElements( Qgs
{
QList<QgsAttributeEditorElement*> results;

Q_FOREACH( QgsAttributeEditorElement* elem, mChildren )
Q_FOREACH ( QgsAttributeEditorElement* elem, mChildren )
{
if ( elem->type() == type )
{
@@ -3796,7 +3796,7 @@ bool QgsVectorLayer::applyNamedStyle( QString namedStyle, QString errorMsg )
errorMsg = tr( "Error: qgis element could not be found" );
return false;
}
toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );

0 comments on commit 8a182b7

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