Skip to content
Permalink
Browse files

[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.
  • Loading branch information
MieWinstrup authored and nyalldawson committed Apr 5, 2018
1 parent cae5f81 commit 924e2ec85497d5099ff53f6467275bae34d6820c
@@ -53,6 +53,7 @@ Action to check a group and all its parents
QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = 0 ) /Factory/;

QAction *actionMakeTopLevel( QObject *parent = 0 ) /Factory/;
QAction *actionMoveToTop( QObject *parent = 0 ) /Factory/;
QAction *actionGroupSelected( QObject *parent = 0 ) /Factory/;

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

void mutuallyExclusiveGroup();
@@ -118,6 +118,9 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
QAction *actionSaveAsDefinitionGroup = new QAction( tr( "Save as Layer Definition File…" ), menuExportGroup );
connect( actionSaveAsDefinitionGroup, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
menuExportGroup->addAction( actionSaveAsDefinitionGroup );

if ( !( mView->selectedNodes( true ).count() == 1 && idx.row() == 0 ) )
menu->addAction( actions->actionMoveToTop( menu ) );
menu->addMenu( menuExportGroup );
}
else if ( QgsLayerTree::isLayer( node ) )
@@ -292,6 +295,9 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()

QgisApp *app = QgisApp::instance();
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );

if ( !( mView->selectedNodes( true ).count() == 1 && idx.row() == 0 ) )
menu->addAction( actions->actionMoveToTop( menu ) );
if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
{
menuStyleManager->addAction( tr( "Paste Style" ), app, SLOT( pasteStyle() ) );
@@ -113,6 +113,13 @@ QAction *QgsLayerTreeViewDefaultActions::actionMakeTopLevel( QObject *parent )
return a;
}

QAction *QgsLayerTreeViewDefaultActions::actionMoveToTop( QObject *parent )
{
QAction *a = new QAction( tr( "Move to &Top" ), parent );
connect( a, &QAction::triggered, this, &QgsLayerTreeViewDefaultActions::moveToTop );
return a;
}

QAction *QgsLayerTreeViewDefaultActions::actionGroupSelected( QObject *parent )
{
QAction *a = new QAction( tr( "&Group Selected" ), parent );
@@ -352,6 +359,27 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
}
}

void QgsLayerTreeViewDefaultActions::moveToTop()
{
QMap <QgsLayerTreeGroup *, int> groupInsertIdx;
int insertIdx;
Q_FOREACH ( QgsLayerTreeNode *n, mView->selectedNodes() )
{
QgsLayerTreeGroup *parentGroup = qobject_cast<QgsLayerTreeGroup *>( n->parent() );
QgsLayerTreeNode *clonedNode = n->clone();
if ( groupInsertIdx.contains( parentGroup ) )
{
insertIdx = groupInsertIdx.value( parentGroup );
}
else
{
insertIdx = 0;
}
parentGroup->insertChildNode( insertIdx, clonedNode );
parentGroup->removeChildNode( n );
groupInsertIdx.insert( parentGroup, insertIdx + 1 );
}
}

void QgsLayerTreeViewDefaultActions::groupSelected()
{
@@ -62,6 +62,7 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
// TODO: zoom to selected

QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;
QAction *actionMoveToTop( QObject *parent = nullptr ) SIP_FACTORY;
QAction *actionGroupSelected( QObject *parent = nullptr ) SIP_FACTORY;

/**
@@ -84,6 +85,7 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
void zoomToLayer();
void zoomToGroup();
void makeTopLevel();
void moveToTop();
void groupSelected();

/**

0 comments on commit 924e2ec

Please sign in to comment.
You can’t perform that action at this time.