Skip to content

Commit b9b85f9

Browse files
MieWinstrupnyalldawson
authored andcommittedMay 4, 2018
New action 'Move Out of Group' that moves layer(s) out of group(s). Deprecating the action 'Move to top level'
1 parent 218e306 commit b9b85f9

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed
 

‎python/gui/layertree/qgslayertreeviewdefaultactions.sip.in

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,19 @@ Action to zoom to selected features of a vector layer
5959
%End
6060
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;
6161

62-
QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
62+
QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
63+
%Docstring
64+
65+
.. deprecated:: since QGIS 3.2, use actionMoveOutOfGroup()
66+
%End
67+
68+
QAction *actionMoveOutOfGroup( QObject *parent = 0 ) /Factory/;
69+
%Docstring
70+
71+
.. seealso:: :py:func:`moveOutOfGroup`
72+
73+
.. versionadded:: 3.2
74+
%End
6375

6476
QAction *actionMoveToTop( QObject *parent = 0 ) /Factory/;
6577
%Docstring
@@ -105,7 +117,19 @@ Slot to zoom to selected features of a vector layer
105117
.. versionadded:: 3.2
106118
%End
107119
void zoomToGroup();
108-
void makeTopLevel();
120+
121+
void makeTopLevel();
122+
%Docstring
123+
124+
.. deprecated:: since QGIS 3.2, use moveOutOfGroup()
125+
%End
126+
127+
void moveOutOfGroup();
128+
%Docstring
129+
Moves selected layer(s) out of the group(s) and places this/these above the group(s)
130+
131+
.. versionadded:: 3.2
132+
%End
109133

110134
void moveToTop();
111135
%Docstring

‎src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
178178
menu->addSeparator();
179179

180180
if ( node->parent() != mView->layerTreeModel()->rootGroup() )
181-
menu->addAction( actions->actionMakeTopLevel( menu ) );
181+
menu->addAction( actions->actionMoveOutOfGroup( menu ) );
182182

183183
if ( !( mView->selectedNodes( true ).count() == 1 && idx.row() == 0 ) )
184184
{

‎src/gui/layertree/qgslayertreeviewdefaultactions.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,16 @@ QAction *QgsLayerTreeViewDefaultActions::actionZoomToGroup( QgsMapCanvas *canvas
118118
QAction *QgsLayerTreeViewDefaultActions::actionMakeTopLevel( QObject *parent )
119119
{
120120
QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
121+
Q_NOWARN_DEPRECATED_PUSH
121122
connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
123+
Q_NOWARN_DEPRECATED_POP
124+
return a;
125+
}
126+
127+
QAction *QgsLayerTreeViewDefaultActions::actionMoveOutOfGroup( QObject *parent )
128+
{
129+
QAction *a = new QAction( tr( "Move Out of &Group" ), parent );
130+
connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
122131
return a;
123132
}
124133

@@ -385,6 +394,29 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
385394
}
386395
}
387396

397+
398+
void QgsLayerTreeViewDefaultActions::moveOutOfGroup()
399+
{
400+
const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
401+
for ( QgsLayerTreeLayer *l : selectedLayerNodes )
402+
{
403+
QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
404+
QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
405+
if ( !parentGroup || parentGroup == rootGroup )
406+
continue;
407+
QgsLayerTreeGroup *tempGroup = parentGroup;
408+
while ( tempGroup->parent() != rootGroup )
409+
{
410+
tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
411+
}
412+
QgsLayerTreeLayer *clonedLayer = l->clone();
413+
int insertIdx = rootGroup->children().indexOf( tempGroup );
414+
rootGroup->insertChildNode( insertIdx, clonedLayer );
415+
parentGroup->removeChildNode( l );
416+
}
417+
}
418+
419+
388420
void QgsLayerTreeViewDefaultActions::moveToTop()
389421
{
390422
QMap <QgsLayerTreeGroup *, int> groupInsertIdx;

‎src/gui/layertree/qgslayertreeviewdefaultactions.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,16 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
6666
QAction *actionZoomToSelection( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
6767
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
6868

69-
QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;
69+
/**
70+
* \deprecated since QGIS 3.2, use actionMoveOutOfGroup()
71+
*/
72+
Q_DECL_DEPRECATED QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;
73+
74+
/**
75+
* \see moveOutOfGroup()
76+
* \since QGIS 3.2
77+
*/
78+
QAction *actionMoveOutOfGroup( QObject *parent = nullptr ) SIP_FACTORY;
7079

7180
/**
7281
* \see moveToTop()
@@ -106,7 +115,17 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
106115
*/
107116
void zoomToSelection();
108117
void zoomToGroup();
109-
void makeTopLevel();
118+
119+
/**
120+
* \deprecated since QGIS 3.2, use moveOutOfGroup()
121+
*/
122+
Q_DECL_DEPRECATED void makeTopLevel();
123+
124+
/**
125+
* Moves selected layer(s) out of the group(s) and places this/these above the group(s)
126+
* \since QGIS 3.2
127+
*/
128+
void moveOutOfGroup();
110129

111130
/**
112131
* Moves selected layer(s) and/or group(s) to the top of the layer panel

0 commit comments

Comments
 (0)