Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move to top-level action
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent e1a0c21 commit 4162c21
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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) );
}
Expand Down
24 changes: 24 additions & 0 deletions src/gui/layertree/qgslayertreeviewdefaultactions.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions src/gui/layertree/qgslayertreeviewdefaultactions.h
Expand Up @@ -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();
Expand All @@ -33,6 +35,7 @@ protected slots:
void showFeatureCount();
void zoomToLayer();
void zoomToGroup();
void makeTopLevel();

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

0 comments on commit 4162c21

Please sign in to comment.