Skip to content

Commit 924e2ec

Browse files
MieWinstrupnyalldawson
authored andcommittedApr 5, 2018
[FEATURE][Needs-docs] Move layer or group to top of layer panel
A feature that moves the layer(s) or group(s) to the top of the layer panel.
1 parent cae5f81 commit 924e2ec

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed
 

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Action to check a group and all its parents
5353
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;
5454

5555
QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
56+
QAction *actionMoveToTop( QObject *parent = 0 ) /Factory/;
5657
QAction *actionGroupSelected( QObject *parent = 0 ) /Factory/;
5758

5859
QAction *actionMutuallyExclusiveGroup( QObject *parent = 0 ) /Factory/;
@@ -76,6 +77,7 @@ Action to enable/disable mutually exclusive flag of a group (only one child node
7677
void zoomToLayer();
7778
void zoomToGroup();
7879
void makeTopLevel();
80+
void moveToTop();
7981
void groupSelected();
8082

8183
void mutuallyExclusiveGroup();

‎src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
118118
QAction *actionSaveAsDefinitionGroup = new QAction( tr( "Save as Layer Definition File…" ), menuExportGroup );
119119
connect( actionSaveAsDefinitionGroup, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
120120
menuExportGroup->addAction( actionSaveAsDefinitionGroup );
121+
122+
if ( !( mView->selectedNodes( true ).count() == 1 && idx.row() == 0 ) )
123+
menu->addAction( actions->actionMoveToTop( menu ) );
121124
menu->addMenu( menuExportGroup );
122125
}
123126
else if ( QgsLayerTree::isLayer( node ) )
@@ -292,6 +295,9 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
292295

293296
QgisApp *app = QgisApp::instance();
294297
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
298+
299+
if ( !( mView->selectedNodes( true ).count() == 1 && idx.row() == 0 ) )
300+
menu->addAction( actions->actionMoveToTop( menu ) );
295301
if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
296302
{
297303
menuStyleManager->addAction( tr( "Paste Style" ), app, SLOT( pasteStyle() ) );

‎src/gui/layertree/qgslayertreeviewdefaultactions.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ QAction *QgsLayerTreeViewDefaultActions::actionMakeTopLevel( QObject *parent )
113113
return a;
114114
}
115115

116+
QAction *QgsLayerTreeViewDefaultActions::actionMoveToTop( QObject *parent )
117+
{
118+
QAction *a = new QAction( tr( "Move to &Top" ), parent );
119+
connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
120+
return a;
121+
}
122+
116123
QAction *QgsLayerTreeViewDefaultActions::actionGroupSelected( QObject *parent )
117124
{
118125
QAction *a = new QAction( tr( "&Group Selected" ), parent );
@@ -352,6 +359,27 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
352359
}
353360
}
354361

362+
void QgsLayerTreeViewDefaultActions::moveToTop()
363+
{
364+
QMap <QgsLayerTreeGroup *, int> groupInsertIdx;
365+
int insertIdx;
366+
Q_FOREACH ( QgsLayerTreeNode *n, mView->selectedNodes() )
367+
{
368+
QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
369+
QgsLayerTreeNode *clonedNode = n->clone();
370+
if ( groupInsertIdx.contains( parentGroup ) )
371+
{
372+
insertIdx = groupInsertIdx.value( parentGroup );
373+
}
374+
else
375+
{
376+
insertIdx = 0;
377+
}
378+
parentGroup->insertChildNode( insertIdx, clonedNode );
379+
parentGroup->removeChildNode( n );
380+
groupInsertIdx.insert( parentGroup, insertIdx + 1 );
381+
}
382+
}
355383

356384
void QgsLayerTreeViewDefaultActions::groupSelected()
357385
{

‎src/gui/layertree/qgslayertreeviewdefaultactions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
6262
// TODO: zoom to selected
6363

6464
QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;
65+
QAction *actionMoveToTop( QObject *parent = nullptr ) SIP_FACTORY;
6566
QAction *actionGroupSelected( QObject *parent = nullptr ) SIP_FACTORY;
6667

6768
/**
@@ -84,6 +85,7 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
8485
void zoomToLayer();
8586
void zoomToGroup();
8687
void makeTopLevel();
88+
void moveToTop();
8789
void groupSelected();
8890

8991
/**

0 commit comments

Comments
 (0)
Please sign in to comment.