mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Centralize handling of non-identifiable layers in QgsProject
This commit is contained in:
parent
fbc2a4ee7a
commit
54219c571f
@ -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
|
||||
@ -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
|
||||
|
@ -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();
|
||||
|
||||
@ -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() );
|
||||
|
@ -948,6 +948,8 @@ bool QgsProject::read()
|
||||
if ( clean )
|
||||
dirty( false );
|
||||
|
||||
emit nonIdentifiableLayersChanged( nonIdentifiableLayers() );
|
||||
|
||||
return true;
|
||||
|
||||
} // QgsProject::read
|
||||
@ -995,7 +997,6 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool QgsProject::read( QDomNode &layerNode )
|
||||
{
|
||||
QList<QDomNode> brokenNodes;
|
||||
@ -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 );
|
||||
@ -1902,6 +1903,8 @@ QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, co
|
||||
}
|
||||
}
|
||||
|
||||
setNonIdentifiableLayers( thisProjectIdentifyDisabledLayers );
|
||||
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
@ -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" );
|
||||
}
|
||||
|
@ -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:
|
||||
|
||||
@ -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
|
||||
*/
|
||||
@ -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
|
||||
@ -426,7 +444,6 @@ class CORE_EXPORT QgsProject : public QObject
|
||||
QgsLayerTreeRegistryBridge* mLayerTreeRegistryBridge;
|
||||
|
||||
QScopedPointer<QgsVisibilityPresetCollection> mVisibilityPresetCollection;
|
||||
|
||||
}; // QgsProject
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user