Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Centralize handling of non-identifiable layers in QgsProject
  • Loading branch information
m-kuhn committed Mar 29, 2016
1 parent fbc2a4e commit 54219c5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
18 changes: 18 additions & 0 deletions python/core/qgsproject.sip
Expand Up @@ -281,6 +281,21 @@ class QgsProject : QObject
*/
QgsVisibilityPresetCollection* visibilityPresetCollection();

/**
* Set a list of layers which should not be taken into account on map identification
*/
void setNonIdentifiableLayers( QList<QgsMapLayer*> layers );

/**
* Set a list of layers which should not be taken into account on map identification
*/
void setNonIdentifiableLayers( const QStringList& layerIds );

/**
* Get the list of layers which currently should not be taken into account on map identification
*/
QStringList nonIdentifiableLayers() const;

protected:

/** Set error message from read/write operation
Expand Down Expand Up @@ -345,6 +360,9 @@ class QgsProject : QObject

void snapSettingsChanged();

//! Emitted when the list of layer which are excluded from map identification changes
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );

private:

QgsProject(); // private 'cause it's a singleton
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -228,7 +228,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

QgsMapLayer* currentLayer = nullptr;

QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
QStringList noIdentifyLayerIdList = QgsProject::instance()->nonIdentifiableLayers();

const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance()->mapLayers();

Expand Down Expand Up @@ -888,7 +888,7 @@ void QgsProjectProperties::apply()
}
}

QgsProject::instance()->writeEntry( "Identify", "/disabledLayers", noIdentifyLayerList );
QgsProject::instance()->setNonIdentifiableLayers( noIdentifyLayerList );

QgsProject::instance()->writeEntry( "WMSServiceCapabilities", "/", grpOWSServiceCapabilities->isChecked() );
QgsProject::instance()->writeEntry( "WMSServiceTitle", "/", mWMSTitle->text() );
Expand Down
44 changes: 41 additions & 3 deletions src/core/qgsproject.cpp
Expand Up @@ -948,6 +948,8 @@ bool QgsProject::read()
if ( clean )
dirty( false );

emit nonIdentifiableLayersChanged( nonIdentifiableLayers() );

return true;

} // QgsProject::read
Expand Down Expand Up @@ -995,7 +997,6 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
}
}


bool QgsProject::read( QDomNode &layerNode )
{
QList<QDomNode> brokenNodes;
Expand Down Expand Up @@ -1885,14 +1886,14 @@ QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, co
initializeEmbeddedSubtree( projectFilePath, newGroup );
mLayerTreeRegistryBridge->setEnabled( true );

QStringList thisProjectIdentifyDisabledLayers = nonIdentifiableLayers();

// consider the layers might be identify disabled in its project
Q_FOREACH ( const QString& layerId, newGroup->findLayerIds() )
{
if ( embeddedIdentifyDisabledLayers.contains( layerId ) )
{
QStringList thisProjectIdentifyDisabledLayers = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
thisProjectIdentifyDisabledLayers.append( layerId );
QgsProject::instance()->writeEntry( "Identify", "/disabledLayers", thisProjectIdentifyDisabledLayers );
}

QgsLayerTreeLayer *layer = newGroup->findLayer( layerId );
Expand All @@ -1902,6 +1903,8 @@ QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, co
}
}

setNonIdentifiableLayers( thisProjectIdentifyDisabledLayers );

return newGroup;
}

Expand Down Expand Up @@ -2119,3 +2122,38 @@ QgsVisibilityPresetCollection* QgsProject::visibilityPresetCollection()
{
return mVisibilityPresetCollection.data();
}

void QgsProject::setNonIdentifiableLayers( QList<QgsMapLayer*> layers )
{
QStringList currentLayers = nonIdentifiableLayers();

QStringList newLayers;
Q_FOREACH ( QgsMapLayer* l, layers )
{
newLayers << l->id();
}

if ( newLayers == currentLayers )
return;

QStringList disabledLayerIds;

Q_FOREACH ( QgsMapLayer* l, layers )
{
disabledLayerIds << l->id();
}

setNonIdentifiableLayers( disabledLayerIds );
}

void QgsProject::setNonIdentifiableLayers( const QStringList& layerIds )
{
writeEntry( "Identify", "/disabledLayers", layerIds );

emit nonIdentifiableLayersChanged( layerIds );
}

QStringList QgsProject::nonIdentifiableLayers() const
{
return QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
}
21 changes: 19 additions & 2 deletions src/core/qgsproject.h
Expand Up @@ -70,6 +70,7 @@ class QgsVisibilityPresetCollection;
class CORE_EXPORT QgsProject : public QObject
{
Q_OBJECT
Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )

public:

Expand Down Expand Up @@ -327,8 +328,22 @@ class CORE_EXPORT QgsProject : public QObject
*/
QgsVisibilityPresetCollection* visibilityPresetCollection();

protected:
/**
* Set a list of layers which should not be taken into account on map identification
*/
void setNonIdentifiableLayers( QList<QgsMapLayer*> layers );

/**
* Set a list of layers which should not be taken into account on map identification
*/
void setNonIdentifiableLayers( const QStringList& layerIds );

/**
* Get the list of layers which currently should not be taken into account on map identification
*/
QStringList nonIdentifiableLayers() const;

protected:
/** Set error message from read/write operation
* @note not available in Python bindings
*/
Expand Down Expand Up @@ -391,6 +406,9 @@ class CORE_EXPORT QgsProject : public QObject

void snapSettingsChanged();

//! Emitted when the list of layer which are excluded from map identification changes
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );

private:

QgsProject(); // private 'cause it's a singleton
Expand Down Expand Up @@ -426,7 +444,6 @@ class CORE_EXPORT QgsProject : public QObject
QgsLayerTreeRegistryBridge* mLayerTreeRegistryBridge;

QScopedPointer<QgsVisibilityPresetCollection> mVisibilityPresetCollection;

}; // QgsProject


Expand Down

0 comments on commit 54219c5

Please sign in to comment.