Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New action 'Move Out of Group' that moves layer(s) out of group(s). D…
…eprecating the action 'Move to top level'
  • Loading branch information
MieWinstrup authored and nyalldawson committed May 4, 2018
1 parent 218e306 commit b9b85f9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
28 changes: 26 additions & 2 deletions python/gui/layertree/qgslayertreeviewdefaultactions.sip.in
Expand Up @@ -59,7 +59,19 @@ Action to zoom to selected features of a vector layer
%End
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;

QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
%Docstring

.. deprecated:: since QGIS 3.2, use actionMoveOutOfGroup()
%End

QAction *actionMoveOutOfGroup( QObject *parent = 0 ) /Factory/;
%Docstring

.. seealso:: :py:func:`moveOutOfGroup`

.. versionadded:: 3.2
%End

QAction *actionMoveToTop( QObject *parent = 0 ) /Factory/;
%Docstring
Expand Down Expand Up @@ -105,7 +117,19 @@ Slot to zoom to selected features of a vector layer
.. versionadded:: 3.2
%End
void zoomToGroup();
void makeTopLevel();

void makeTopLevel();
%Docstring

.. deprecated:: since QGIS 3.2, use moveOutOfGroup()
%End

void moveOutOfGroup();
%Docstring
Moves selected layer(s) out of the group(s) and places this/these above the group(s)

.. versionadded:: 3.2
%End

void moveToTop();
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -178,7 +178,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addSeparator();

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

if ( !( mView->selectedNodes( true ).count() == 1 && idx.row() == 0 ) )
{
Expand Down
32 changes: 32 additions & 0 deletions src/gui/layertree/qgslayertreeviewdefaultactions.cpp
Expand Up @@ -118,7 +118,16 @@ QAction *QgsLayerTreeViewDefaultActions::actionZoomToGroup( QgsMapCanvas *canvas
QAction *QgsLayerTreeViewDefaultActions::actionMakeTopLevel( QObject *parent )
{
QAction *a = new QAction( tr( "&Move to Top-level" ), parent );
Q_NOWARN_DEPRECATED_PUSH
connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::makeTopLevel );
Q_NOWARN_DEPRECATED_POP
return a;
}

QAction *QgsLayerTreeViewDefaultActions::actionMoveOutOfGroup( QObject *parent )
{
QAction *a = new QAction( tr( "Move Out of &Group" ), parent );
connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveOutOfGroup );
return a;
}

Expand Down Expand Up @@ -385,6 +394,29 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
}
}


void QgsLayerTreeViewDefaultActions::moveOutOfGroup()
{
const QList< QgsLayerTreeLayer * > selectedLayerNodes = mView->selectedLayerNodes();
for ( QgsLayerTreeLayer *l : selectedLayerNodes )
{
QgsLayerTreeGroup *rootGroup = mView->layerTreeModel()->rootGroup();
QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( l->parent() );
if ( !parentGroup || parentGroup == rootGroup )
continue;
QgsLayerTreeGroup *tempGroup = parentGroup;
while ( tempGroup->parent() != rootGroup )
{
tempGroup = qobject_cast<QgsLayerTreeGroup *>( tempGroup->parent() );
}
QgsLayerTreeLayer *clonedLayer = l->clone();
int insertIdx = rootGroup->children().indexOf( tempGroup );
rootGroup->insertChildNode( insertIdx, clonedLayer );
parentGroup->removeChildNode( l );
}
}


void QgsLayerTreeViewDefaultActions::moveToTop()
{
QMap <QgsLayerTreeGroup *, int> groupInsertIdx;
Expand Down
23 changes: 21 additions & 2 deletions src/gui/layertree/qgslayertreeviewdefaultactions.h
Expand Up @@ -66,7 +66,16 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction *actionZoomToSelection( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;

QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;
/**
* \deprecated since QGIS 3.2, use actionMoveOutOfGroup()
*/
Q_DECL_DEPRECATED QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;

/**
* \see moveOutOfGroup()
* \since QGIS 3.2
*/
QAction *actionMoveOutOfGroup( QObject *parent = nullptr ) SIP_FACTORY;

/**
* \see moveToTop()
Expand Down Expand Up @@ -106,7 +115,17 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
*/
void zoomToSelection();
void zoomToGroup();
void makeTopLevel();

/**
* \deprecated since QGIS 3.2, use moveOutOfGroup()
*/
Q_DECL_DEPRECATED void makeTopLevel();

/**
* Moves selected layer(s) out of the group(s) and places this/these above the group(s)
* \since QGIS 3.2
*/
void moveOutOfGroup();

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

0 comments on commit b9b85f9

Please sign in to comment.