mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-18 00:06:00 -04:00
Fix #11474 (cannot move layers in layer tree anymore)
I have managed to break that with implementation of #11369. Obviously it is a bad idea to change selection in a slot connected to model's rowsInserted signals because the drag'n'drop does not work properly anymore. Now registry bridge will emit a signal after new layers have been added, so the selection change at that point should be safe.
This commit is contained in:
parent
88e5cde31a
commit
cc306099d9
@ -29,4 +29,9 @@ class QgsLayerTreeRegistryBridge : QObject
|
|||||||
//! By default it is root group with zero index.
|
//! By default it is root group with zero index.
|
||||||
void setLayerInsertionPoint( QgsLayerTreeGroup* parentGroup, int index );
|
void setLayerInsertionPoint( QgsLayerTreeGroup* parentGroup, int index );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
//! Tell others we have just added layers to the tree (used in QGIS to auto-select first newly added layer)
|
||||||
|
//! @note added in 2.6
|
||||||
|
void addedLayersToLayerTree( QList<QgsMapLayer*> layers );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -63,13 +63,6 @@ class QgsLayerTreeView : QTreeView
|
|||||||
//! Get list of selected layers
|
//! Get list of selected layers
|
||||||
QList<QgsMapLayer*> selectedLayers() const;
|
QList<QgsMapLayer*> selectedLayers() const;
|
||||||
|
|
||||||
//! if enabled, current selection will be automatically changed to the newly added layer node.
|
|
||||||
//! This is purely for user's convenience so they do not need to click on the layer explicitly.
|
|
||||||
//! @note added in 2.6
|
|
||||||
void setAutoSelectAddedLayers( bool enabled );
|
|
||||||
//! @note added in 2.6
|
|
||||||
bool autoSelectAddedLayers() const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
|
//! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
|
||||||
void refreshLayerSymbology( const QString& layerId );
|
void refreshLayerSymbology( const QString& layerId );
|
||||||
|
@ -2315,13 +2315,14 @@ void QgisApp::initLayerTreeView()
|
|||||||
|
|
||||||
mLayerTreeView->setModel( model );
|
mLayerTreeView->setModel( model );
|
||||||
mLayerTreeView->setMenuProvider( new QgsAppLayerTreeViewMenuProvider( mLayerTreeView, mMapCanvas ) );
|
mLayerTreeView->setMenuProvider( new QgsAppLayerTreeViewMenuProvider( mLayerTreeView, mMapCanvas ) );
|
||||||
mLayerTreeView->setAutoSelectAddedLayers( true );
|
|
||||||
|
|
||||||
setupLayerTreeViewFromSettings();
|
setupLayerTreeViewFromSettings();
|
||||||
|
|
||||||
connect( mLayerTreeView, SIGNAL( doubleClicked( QModelIndex ) ), this, SLOT( layerTreeViewDoubleClicked( QModelIndex ) ) );
|
connect( mLayerTreeView, SIGNAL( doubleClicked( QModelIndex ) ), this, SLOT( layerTreeViewDoubleClicked( QModelIndex ) ) );
|
||||||
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( activeLayerChanged( QgsMapLayer* ) ) );
|
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( activeLayerChanged( QgsMapLayer* ) ) );
|
||||||
connect( mLayerTreeView->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( updateNewLayerInsertionPoint() ) );
|
connect( mLayerTreeView->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( updateNewLayerInsertionPoint() ) );
|
||||||
|
connect( QgsProject::instance()->layerTreeRegistryBridge(), SIGNAL( addedLayersToLayerTree( QList<QgsMapLayer*> ) ),
|
||||||
|
this, SLOT( autoSelectAddedLayer( QList<QgsMapLayer*> ) ) );
|
||||||
|
|
||||||
// add group tool button
|
// add group tool button
|
||||||
QToolButton* btnAddGroup = new QToolButton;
|
QToolButton* btnAddGroup = new QToolButton;
|
||||||
@ -2447,6 +2448,15 @@ void QgisApp::updateNewLayerInsertionPoint()
|
|||||||
QgsProject::instance()->layerTreeRegistryBridge()->setLayerInsertionPoint( parentGroup, index );
|
QgsProject::instance()->layerTreeRegistryBridge()->setLayerInsertionPoint( parentGroup, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgisApp::autoSelectAddedLayer( QList<QgsMapLayer*> layers )
|
||||||
|
{
|
||||||
|
if ( layers.count() )
|
||||||
|
{
|
||||||
|
QgsLayerTreeLayer* nodeLayer = QgsProject::instance()->layerTreeRoot()->findLayer( layers[0]->id() );
|
||||||
|
QModelIndex index = mLayerTreeView->layerTreeModel()->node2index( nodeLayer );
|
||||||
|
mLayerTreeView->setCurrentIndex( index );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QgisApp::createMapTips()
|
void QgisApp::createMapTips()
|
||||||
{
|
{
|
||||||
@ -3782,7 +3792,6 @@ void QgisApp::enableProjectMacros()
|
|||||||
QgsPythonRunner::run( "qgis.utils.reloadProjectMacros()" );
|
QgsPythonRunner::run( "qgis.utils.reloadProjectMacros()" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
adds a saved project to qgis, usually called on startup by specifying a
|
adds a saved project to qgis, usually called on startup by specifying a
|
||||||
project file on the command line
|
project file on the command line
|
||||||
@ -3798,11 +3807,6 @@ bool QgisApp::addProject( QString projectFile )
|
|||||||
// close the previous opened project if any
|
// close the previous opened project if any
|
||||||
closeProject();
|
closeProject();
|
||||||
|
|
||||||
// temporarily disable auto-select for project loading
|
|
||||||
// (having it on all the time would give inconsistent results,
|
|
||||||
// e.g. we select the first node if it is a layer, but not if it is a group)
|
|
||||||
mLayerTreeView->setAutoSelectAddedLayers( false );
|
|
||||||
|
|
||||||
if ( ! QgsProject::instance()->read( projectFile ) )
|
if ( ! QgsProject::instance()->read( projectFile ) )
|
||||||
{
|
{
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
@ -3818,8 +3822,6 @@ bool QgisApp::addProject( QString projectFile )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mLayerTreeView->setAutoSelectAddedLayers( true );
|
|
||||||
|
|
||||||
setTitleBarText_( *this );
|
setTitleBarText_( *this );
|
||||||
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
|
int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
|
||||||
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
|
int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
|
||||||
|
@ -477,6 +477,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
|||||||
void layerTreeViewDoubleClicked( const QModelIndex& index );
|
void layerTreeViewDoubleClicked( const QModelIndex& index );
|
||||||
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
|
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
|
||||||
void updateNewLayerInsertionPoint();
|
void updateNewLayerInsertionPoint();
|
||||||
|
//! connected to layer tree registry bridge, selects first of the newly added map layers
|
||||||
|
void autoSelectAddedLayer( QList<QgsMapLayer*> layers );
|
||||||
void activeLayerChanged( QgsMapLayer* layer );
|
void activeLayerChanged( QgsMapLayer* layer );
|
||||||
//! Zoom to full extent
|
//! Zoom to full extent
|
||||||
void zoomFull();
|
void zoomFull();
|
||||||
|
@ -68,6 +68,9 @@ void QgsLayerTreeRegistryBridge::layersAdded( QList<QgsMapLayer*> layers )
|
|||||||
|
|
||||||
// add new layers to the right place
|
// add new layers to the right place
|
||||||
mInsertionPointGroup->insertChildNodes( mInsertionPointIndex, nodes );
|
mInsertionPointGroup->insertChildNodes( mInsertionPointIndex, nodes );
|
||||||
|
|
||||||
|
// tell other components that layers have been added - this signal is used in QGIS to auto-select the first layer
|
||||||
|
emit addedLayersToLayerTree( layers );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsLayerTreeRegistryBridge::layersWillBeRemoved( QStringList layerIds )
|
void QgsLayerTreeRegistryBridge::layersWillBeRemoved( QStringList layerIds )
|
||||||
|
@ -53,6 +53,9 @@ class CORE_EXPORT QgsLayerTreeRegistryBridge : public QObject
|
|||||||
void setLayerInsertionPoint( QgsLayerTreeGroup* parentGroup, int index );
|
void setLayerInsertionPoint( QgsLayerTreeGroup* parentGroup, int index );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
//! Tell others we have just added layers to the tree (used in QGIS to auto-select first newly added layer)
|
||||||
|
//! @note added in 2.6
|
||||||
|
void addedLayersToLayerTree( QList<QgsMapLayer*> layers );
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void layersAdded( QList<QgsMapLayer*> layers );
|
void layersAdded( QList<QgsMapLayer*> layers );
|
||||||
|
@ -28,7 +28,6 @@ QgsLayerTreeView::QgsLayerTreeView( QWidget *parent )
|
|||||||
: QTreeView( parent )
|
: QTreeView( parent )
|
||||||
, mDefaultActions( 0 )
|
, mDefaultActions( 0 )
|
||||||
, mMenuProvider( 0 )
|
, mMenuProvider( 0 )
|
||||||
, mAutoSelectAddedLayers( false )
|
|
||||||
{
|
{
|
||||||
setHeaderHidden( true );
|
setHeaderHidden( true );
|
||||||
|
|
||||||
@ -138,10 +137,6 @@ void QgsLayerTreeView::modelRowsInserted( QModelIndex index, int start, int end
|
|||||||
updateExpandedStateFromNode( children[i] );
|
updateExpandedStateFromNode( children[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// make newly added layer active (if auto-select is enabled)
|
|
||||||
if ( mAutoSelectAddedLayers && QgsLayerTree::isLayer( children[start] ) )
|
|
||||||
setCurrentIndex( layerTreeModel()->node2index( children[start] ) );
|
|
||||||
|
|
||||||
// make sure we still have correct current layer
|
// make sure we still have correct current layer
|
||||||
onCurrentChanged();
|
onCurrentChanged();
|
||||||
}
|
}
|
||||||
|
@ -81,13 +81,6 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
|
|||||||
//! Get list of selected layers
|
//! Get list of selected layers
|
||||||
QList<QgsMapLayer*> selectedLayers() const;
|
QList<QgsMapLayer*> selectedLayers() const;
|
||||||
|
|
||||||
//! if enabled, current selection will be automatically changed to the newly added layer node.
|
|
||||||
//! This is purely for user's convenience so they do not need to click on the layer explicitly.
|
|
||||||
//! @note added in 2.6
|
|
||||||
void setAutoSelectAddedLayers( bool enabled ) { mAutoSelectAddedLayers = enabled; }
|
|
||||||
//! @note added in 2.6
|
|
||||||
bool autoSelectAddedLayers() const { return mAutoSelectAddedLayers; }
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
|
//! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
|
||||||
void refreshLayerSymbology( const QString& layerId );
|
void refreshLayerSymbology( const QString& layerId );
|
||||||
@ -121,8 +114,6 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
|
|||||||
QgsLayerTreeViewMenuProvider* mMenuProvider;
|
QgsLayerTreeViewMenuProvider* mMenuProvider;
|
||||||
//! Keeps track of current layer ID (to check when to emit signal about change of current layer)
|
//! Keeps track of current layer ID (to check when to emit signal about change of current layer)
|
||||||
QString mCurrentLayerID;
|
QString mCurrentLayerID;
|
||||||
//! Indicates whether the view should select newly added layers when they are added to the model
|
|
||||||
bool mAutoSelectAddedLayers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user