@@ -88,16 +88,18 @@ QAction* QgsLayerTreeViewDefaultActions::actionMakeTopLevel(QObject* parent)
88
88
return a;
89
89
}
90
90
91
+ QAction* QgsLayerTreeViewDefaultActions::actionGroupSelected (QObject* parent)
92
+ {
93
+ QAction* a = new QAction (tr (" &Group Selected" ), parent);
94
+ connect (a, SIGNAL (triggered ()), this , SLOT (groupSelected ()));
95
+ return a;
96
+ }
97
+
91
98
void QgsLayerTreeViewDefaultActions::addGroup ()
92
99
{
93
100
QgsLayerTreeGroup* group = mView ->currentGroupNode ();
94
- QString prefix = group == mView ->layerTreeModel ()->rootGroup () ? " group" : " sub-group" ;
95
-
96
- QString newName = prefix + " 1" ;
97
- for ( int i = 2 ; group->findGroup (newName); ++i)
98
- newName = prefix + QString::number (i);
99
101
100
- QgsLayerTreeGroup* newGroup = group->addGroup (newName );
102
+ QgsLayerTreeGroup* newGroup = group->addGroup (uniqueGroupName (group) );
101
103
mView ->edit ( mView ->layerTreeModel ()->node2index (newGroup) );
102
104
}
103
105
@@ -202,6 +204,16 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers(QgsMapCanvas* canvas, const QL
202
204
}
203
205
204
206
207
+ QString QgsLayerTreeViewDefaultActions::uniqueGroupName (QgsLayerTreeGroup* parentGroup)
208
+ {
209
+ QString prefix = parentGroup == mView ->layerTreeModel ()->rootGroup () ? " group" : " sub-group" ;
210
+ QString newName = prefix + " 1" ;
211
+ for ( int i = 2 ; parentGroup->findGroup (newName); ++i)
212
+ newName = prefix + QString::number (i);
213
+ return newName;
214
+ }
215
+
216
+
205
217
void QgsLayerTreeViewDefaultActions::makeTopLevel ()
206
218
{
207
219
QgsLayerTreeNode* node = mView ->currentNode ();
@@ -217,3 +229,26 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
217
229
rootGroup->addChildNode (clonedNode);
218
230
parentGroup->removeChildNode (node);
219
231
}
232
+
233
+
234
+ void QgsLayerTreeViewDefaultActions::groupSelected ()
235
+ {
236
+ QList<QgsLayerTreeNode*> nodes = mView ->selectedNodes (true );
237
+ if (nodes.count () < 2 )
238
+ return ;
239
+
240
+ QgsLayerTreeGroup* parentGroup = mView ->layerTreeModel ()->rootGroup ();
241
+
242
+ QgsLayerTreeGroup* newGroup = new QgsLayerTreeGroup (uniqueGroupName (parentGroup));
243
+ foreach (QgsLayerTreeNode* node, nodes)
244
+ newGroup->addChildNode (node->clone ());
245
+
246
+ parentGroup->addChildNode (newGroup);
247
+
248
+ foreach (QgsLayerTreeNode* node, nodes)
249
+ {
250
+ QgsLayerTreeGroup* group = qobject_cast<QgsLayerTreeGroup*>(node->parent ());
251
+ if (group)
252
+ group->removeChildNode (node);
253
+ }
254
+ }
0 commit comments