Fix #10412 (option whether to show newly added layers)

This commit is contained in:
Martin Dobias 2014-06-04 13:31:39 +07:00
parent f3c41a07b9
commit fa3f21cdb6
4 changed files with 16 additions and 1 deletions

View File

@ -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 );

View File

@ -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
@ -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();

View File

@ -26,6 +26,7 @@ QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge( QgsLayerTreeGroup *root,
: QObject( parent )
, mRoot( root )
, mEnabled( true )
, mNewLayersVisible( true )
, mInsertionPointGroup( root )
, mInsertionPointIndex( 0 )
{
@ -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() );

View File

@ -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 );
@ -62,6 +65,7 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
QgsLayerTreeGroup* mRoot;
QStringList mLayerIdsForRemoval;
bool mEnabled;
bool mNewLayersVisible;
QgsLayerTreeGroup* mInsertionPointGroup;
int mInsertionPointIndex;