Skip to content
Permalink
Browse files
Move to top-level action
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent e1a0c21 commit 4162c2101db61191fb812cd86c5eabbc7a0a4529
Showing with 32 additions and 0 deletions.
  1. +5 −0 src/app/qgisapp.cpp
  2. +24 −0 src/gui/layertree/qgslayertreeviewdefaultactions.cpp
  3. +3 −0 src/gui/layertree/qgslayertreeviewdefaultactions.h
@@ -2223,6 +2223,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
menu->addAction( actions->actionShowFeatureCount(menu) );
}

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

menu->addAction( actions->actionRemoveGroupOrLayer(menu) );
menu->addAction( actions->actionRenameGroupOrLayer(menu) );
}
@@ -81,6 +81,13 @@ QAction* QgsLayerTreeViewDefaultActions::actionZoomToGroup(QgsMapCanvas* canvas,
return a;
}

QAction* QgsLayerTreeViewDefaultActions::actionMakeTopLevel(QObject* parent)
{
QAction* a = new QAction(tr("&Move to Top-level"), parent);
connect(a, SIGNAL(triggered()), this, SLOT(makeTopLevel()));
return a;
}

void QgsLayerTreeViewDefaultActions::addGroup()
{
QgsLayerTreeGroup* group = mView->currentGroupNode();
@@ -193,3 +200,20 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers(QgsMapCanvas* canvas, const QL
canvas->setExtent( extent );
canvas->refresh();
}


void QgsLayerTreeViewDefaultActions::makeTopLevel()
{
QgsLayerTreeNode* node = mView->currentNode();
if (!node)
return;

QgsLayerTreeGroup* rootGroup = mView->layerTreeModel()->rootGroup();
QgsLayerTreeGroup* parentGroup = qobject_cast<QgsLayerTreeGroup*>(node->parent());
if (!parentGroup || parentGroup == rootGroup)
return;

QgsLayerTreeNode* clonedNode = node->clone();
rootGroup->addChildNode(clonedNode);
parentGroup->removeChildNode(node);
}
@@ -25,6 +25,8 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction* actionZoomToGroup(QgsMapCanvas* canvas, QObject* parent = 0);
// TODO: zoom to selected

QAction* actionMakeTopLevel(QObject* parent = 0);

protected slots:
void addGroup();
void removeGroupOrLayer();
@@ -33,6 +35,7 @@ protected slots:
void showFeatureCount();
void zoomToLayer();
void zoomToGroup();
void makeTopLevel();

protected:
void zoomToLayers(QgsMapCanvas* canvas, const QList<QgsMapLayer*>& layers);

0 comments on commit 4162c21

Please sign in to comment.