Skip to content

Commit 54219c5

Browse files
committedMar 29, 2016
Centralize handling of non-identifiable layers in QgsProject
1 parent fbc2a4e commit 54219c5

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed
 

‎python/core/qgsproject.sip

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ class QgsProject : QObject
281281
*/
282282
QgsVisibilityPresetCollection* visibilityPresetCollection();
283283

284+
/**
285+
* Set a list of layers which should not be taken into account on map identification
286+
*/
287+
void setNonIdentifiableLayers( QList<QgsMapLayer*> layers );
288+
289+
/**
290+
* Set a list of layers which should not be taken into account on map identification
291+
*/
292+
void setNonIdentifiableLayers( const QStringList& layerIds );
293+
294+
/**
295+
* Get the list of layers which currently should not be taken into account on map identification
296+
*/
297+
QStringList nonIdentifiableLayers() const;
298+
284299
protected:
285300

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

346361
void snapSettingsChanged();
347362

363+
//! Emitted when the list of layer which are excluded from map identification changes
364+
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
365+
348366
private:
349367

350368
QgsProject(); // private 'cause it's a singleton

‎src/app/qgsprojectproperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
228228

229229
QgsMapLayer* currentLayer = nullptr;
230230

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

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

@@ -888,7 +888,7 @@ void QgsProjectProperties::apply()
888888
}
889889
}
890890

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

893893
QgsProject::instance()->writeEntry( "WMSServiceCapabilities", "/", grpOWSServiceCapabilities->isChecked() );
894894
QgsProject::instance()->writeEntry( "WMSServiceTitle", "/", mWMSTitle->text() );

‎src/core/qgsproject.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ bool QgsProject::read()
948948
if ( clean )
949949
dirty( false );
950950

951+
emit nonIdentifiableLayersChanged( nonIdentifiableLayers() );
952+
951953
return true;
952954

953955
} // QgsProject::read
@@ -995,7 +997,6 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
995997
}
996998
}
997999

998-
9991000
bool QgsProject::read( QDomNode &layerNode )
10001001
{
10011002
QList<QDomNode> brokenNodes;
@@ -1885,14 +1886,14 @@ QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, co
18851886
initializeEmbeddedSubtree( projectFilePath, newGroup );
18861887
mLayerTreeRegistryBridge->setEnabled( true );
18871888

1889+
QStringList thisProjectIdentifyDisabledLayers = nonIdentifiableLayers();
1890+
18881891
// consider the layers might be identify disabled in its project
18891892
Q_FOREACH ( const QString& layerId, newGroup->findLayerIds() )
18901893
{
18911894
if ( embeddedIdentifyDisabledLayers.contains( layerId ) )
18921895
{
1893-
QStringList thisProjectIdentifyDisabledLayers = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
18941896
thisProjectIdentifyDisabledLayers.append( layerId );
1895-
QgsProject::instance()->writeEntry( "Identify", "/disabledLayers", thisProjectIdentifyDisabledLayers );
18961897
}
18971898

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

1906+
setNonIdentifiableLayers( thisProjectIdentifyDisabledLayers );
1907+
19051908
return newGroup;
19061909
}
19071910

@@ -2119,3 +2122,38 @@ QgsVisibilityPresetCollection* QgsProject::visibilityPresetCollection()
21192122
{
21202123
return mVisibilityPresetCollection.data();
21212124
}
2125+
2126+
void QgsProject::setNonIdentifiableLayers( QList<QgsMapLayer*> layers )
2127+
{
2128+
QStringList currentLayers = nonIdentifiableLayers();
2129+
2130+
QStringList newLayers;
2131+
Q_FOREACH ( QgsMapLayer* l, layers )
2132+
{
2133+
newLayers << l->id();
2134+
}
2135+
2136+
if ( newLayers == currentLayers )
2137+
return;
2138+
2139+
QStringList disabledLayerIds;
2140+
2141+
Q_FOREACH ( QgsMapLayer* l, layers )
2142+
{
2143+
disabledLayerIds << l->id();
2144+
}
2145+
2146+
setNonIdentifiableLayers( disabledLayerIds );
2147+
}
2148+
2149+
void QgsProject::setNonIdentifiableLayers( const QStringList& layerIds )
2150+
{
2151+
writeEntry( "Identify", "/disabledLayers", layerIds );
2152+
2153+
emit nonIdentifiableLayersChanged( layerIds );
2154+
}
2155+
2156+
QStringList QgsProject::nonIdentifiableLayers() const
2157+
{
2158+
return QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
2159+
}

‎src/core/qgsproject.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class QgsVisibilityPresetCollection;
7070
class CORE_EXPORT QgsProject : public QObject
7171
{
7272
Q_OBJECT
73+
Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
7374

7475
public:
7576

@@ -327,8 +328,22 @@ class CORE_EXPORT QgsProject : public QObject
327328
*/
328329
QgsVisibilityPresetCollection* visibilityPresetCollection();
329330

330-
protected:
331+
/**
332+
* Set a list of layers which should not be taken into account on map identification
333+
*/
334+
void setNonIdentifiableLayers( QList<QgsMapLayer*> layers );
335+
336+
/**
337+
* Set a list of layers which should not be taken into account on map identification
338+
*/
339+
void setNonIdentifiableLayers( const QStringList& layerIds );
331340

341+
/**
342+
* Get the list of layers which currently should not be taken into account on map identification
343+
*/
344+
QStringList nonIdentifiableLayers() const;
345+
346+
protected:
332347
/** Set error message from read/write operation
333348
* @note not available in Python bindings
334349
*/
@@ -391,6 +406,9 @@ class CORE_EXPORT QgsProject : public QObject
391406

392407
void snapSettingsChanged();
393408

409+
//! Emitted when the list of layer which are excluded from map identification changes
410+
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
411+
394412
private:
395413

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

428446
QScopedPointer<QgsVisibilityPresetCollection> mVisibilityPresetCollection;
429-
430447
}; // QgsProject
431448

432449

0 commit comments

Comments
 (0)
Please sign in to comment.