Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #10412 (option whether to show newly added layers)
  • Loading branch information
wonder-sk committed Jun 4, 2014
1 parent f3c41a0 commit fa3f21c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions python/core/layertree/qgslayertreeregistrybridge.sip
Expand Up @@ -22,6 +22,9 @@ class QgsLayerTreeRegistryBridge : QObject
void setEnabled( bool enabled );
bool isEnabled() const;

void setNewLayersVisible( bool enabled );
bool newLayersVisible() const;

//! Set where the new layers should be inserted - can be used to follow current selection.
//! By default it is root group with zero index.
void setLayerInsertionPoint( QgsLayerTreeGroup* parentGroup, int index );
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -3335,6 +3335,8 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
QgsProject* prj = QgsProject::instance();
prj->clear();

prj->layerTreeRegistryBridge()->setNewLayersVisible( settings.value( "/qgis/new_layers_visible", true ).toBool() );

mLayerTreeCanvasBridge->clear();

//set the color for selections
Expand Down Expand Up @@ -7235,6 +7237,8 @@ void QgisApp::showOptionsDialog( QWidget *parent, QString currentPage )
// set the theme if it changed
setTheme( optionsDialog->theme() );

QgsProject::instance()->layerTreeRegistryBridge()->setNewLayersVisible( mySettings.value( "/qgis/new_layers_visible", true ).toBool() );

mMapCanvas->enableAntiAliasing( mySettings.value( "/qgis/enable_anti_aliasing" ).toBool() );

int action = mySettings.value( "/qgis/wheel_action", 2 ).toInt();
Expand Down
6 changes: 5 additions & 1 deletion src/core/layertree/qgslayertreeregistrybridge.cpp
Expand Up @@ -26,6 +26,7 @@ QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge( QgsLayerTreeGroup *root,
: QObject( parent )
, mRoot( root )
, mEnabled( true )
, mNewLayersVisible( true )
, mInsertionPointGroup( root )
, mInsertionPointIndex( 0 )
{
Expand All @@ -50,8 +51,11 @@ void QgsLayerTreeRegistryBridge::layersAdded( QList<QgsMapLayer*> layers )
int i = 0;
foreach ( QgsMapLayer* layer, layers )
{
QgsLayerTreeLayer* nodeLayer = new QgsLayerTreeLayer( layer );
nodeLayer->setVisible( mNewLayersVisible ? Qt::Checked : Qt::Unchecked );

// add new layer to the top
QgsLayerTreeLayer* nodeLayer = mInsertionPointGroup->insertLayer( mInsertionPointIndex + i++, layer );
mInsertionPointGroup->insertChildNode( mInsertionPointIndex + i++, nodeLayer );

// check whether the layer is marked as embedded
QString projectFile = QgsProject::instance()->layerIsEmbedded( nodeLayer->layerId() );
Expand Down
4 changes: 4 additions & 0 deletions src/core/layertree/qgslayertreeregistrybridge.h
Expand Up @@ -45,6 +45,9 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
void setEnabled( bool enabled ) { mEnabled = enabled; }
bool isEnabled() const { return mEnabled; }

void setNewLayersVisible( bool enabled ) { mNewLayersVisible = enabled; }
bool newLayersVisible() const { return mNewLayersVisible; }

//! Set where the new layers should be inserted - can be used to follow current selection.
//! By default it is root group with zero index.
void setLayerInsertionPoint( QgsLayerTreeGroup* parentGroup, int index );
Expand All @@ -62,6 +65,7 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
QgsLayerTreeGroup* mRoot;
QStringList mLayerIdsForRemoval;
bool mEnabled;
bool mNewLayersVisible;

QgsLayerTreeGroup* mInsertionPointGroup;
int mInsertionPointIndex;
Expand Down

0 comments on commit fa3f21c

Please sign in to comment.