@@ -75,21 +75,35 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
75
75
{
76
76
menu->addAction ( actions->actionZoomToGroup ( mCanvas , menu ) );
77
77
78
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionRemoveLayer.svg" ) ), tr ( " &Remove" ), QgisApp::instance (), SLOT ( removeLayer () ) );
79
-
80
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionSetCRS.png" ) ),
81
- tr ( " &Set Group CRS" ), QgisApp::instance (), SLOT ( legendGroupSetCrs () ) );
78
+ menu->addAction ( tr ( " Copy Group" ), QgisApp::instance (), SLOT ( copyLayer () ) );
79
+ if ( QgisApp::instance ()->clipboard ()->hasFormat ( QGSCLIPBOARD_MAPLAYER_MIME ) )
80
+ {
81
+ QAction *actionPasteLayerOrGroup = new QAction ( tr ( " Paste Layer/Group" ), menu );
82
+ connect ( actionPasteLayerOrGroup, &QAction::triggered, QgisApp::instance (), &QgisApp::pasteLayer );
83
+ menu->addAction ( actionPasteLayerOrGroup );
84
+ }
82
85
83
86
menu->addAction ( actions->actionRenameGroupOrLayer ( menu ) );
84
87
85
- menu->addAction ( tr ( " &Set Group WMS data" ), QgisApp::instance (), SLOT ( legendGroupSetWmsData () ) );
88
+ menu->addSeparator ();
89
+ menu->addAction ( actions->actionAddGroup ( menu ) );
90
+ menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionRemoveLayer.svg" ) ), tr ( " &Remove…" ), QgisApp::instance (), SLOT ( removeLayer () ) );
91
+ menu->addSeparator ();
92
+
93
+ menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionSetCRS.png" ) ),
94
+ tr ( " &Set Group CRS…" ), QgisApp::instance (), SLOT ( legendGroupSetCrs () ) );
95
+ menu->addAction ( tr ( " &Set Group WMS Data…" ), QgisApp::instance (), SLOT ( legendGroupSetWmsData () ) );
96
+
97
+ menu->addSeparator ();
86
98
87
99
menu->addAction ( actions->actionMutuallyExclusiveGroup ( menu ) );
88
100
89
101
menu->addAction ( actions->actionCheckAndAllChildren ( menu ) );
90
102
91
103
menu->addAction ( actions->actionUncheckAndAllChildren ( menu ) );
92
104
105
+ menu->addSeparator ();
106
+
93
107
if ( mView ->selectedNodes ( true ).count () >= 2 )
94
108
menu->addAction ( actions->actionGroupSelected ( menu ) );
95
109
@@ -98,17 +112,13 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
98
112
menu->addAction ( tr ( " Paste Style" ), QgisApp::instance (), SLOT ( applyStyleToGroup () ) );
99
113
}
100
114
101
- menu->addAction ( tr ( " Copy Group" ), QgisApp::instance (), SLOT ( copyLayer () ) );
102
- if ( QgisApp::instance ()->clipboard ()->hasFormat ( QGSCLIPBOARD_MAPLAYER_MIME ) )
103
- {
104
- QAction *actionPasteLayerOrGroup = new QAction ( tr ( " Paste Layer/Group" ), menu );
105
- connect ( actionPasteLayerOrGroup, &QAction::triggered, QgisApp::instance (), &QgisApp::pasteLayer );
106
- menu->addAction ( actionPasteLayerOrGroup );
107
- }
108
-
109
- menu->addAction ( tr ( " Save As Layer Definition File…" ), QgisApp::instance (), SLOT ( saveAsLayerDefinition () ) );
115
+ menu->addSeparator ();
110
116
111
- menu->addAction ( actions->actionAddGroup ( menu ) );
117
+ QMenu *menuExportGroup = new QMenu ( tr ( " Export" ), menu );
118
+ QAction *actionSaveAsDefinitionGroup = new QAction ( tr ( " Save as Layer Definition File…" ), menuExportGroup );
119
+ connect ( actionSaveAsDefinitionGroup, &QAction::triggered, QgisApp::instance (), &QgisApp::saveAsLayerDefinition );
120
+ menuExportGroup->addAction ( actionSaveAsDefinitionGroup );
121
+ menu->addMenu ( menuExportGroup );
112
122
}
113
123
else if ( QgsLayerTree::isLayer ( node ) )
114
124
{
@@ -122,6 +132,15 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
122
132
menu->addAction ( actions->actionShowInOverview ( menu ) );
123
133
}
124
134
135
+ if ( vlayer )
136
+ menu->addAction ( actions->actionShowFeatureCount ( menu ) );
137
+
138
+ QAction *actionCopyLayer = new QAction ( tr ( " Copy Layer" ), menu );
139
+ connect ( actionCopyLayer, &QAction::triggered, QgisApp::instance (), &QgisApp::copyLayer );
140
+ menu->addAction ( actionCopyLayer );
141
+
142
+ menu->addAction ( actions->actionRenameGroupOrLayer ( menu ) );
143
+
125
144
if ( rlayer )
126
145
{
127
146
menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionZoomActual.svg" ) ), tr ( " &Zoom to Native Resolution (100%)" ), QgisApp::instance (), SLOT ( legendLayerZoomNative () ) );
@@ -130,100 +149,31 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
130
149
menu->addAction ( tr ( " &Stretch Using Current Extent" ), QgisApp::instance (), SLOT ( legendLayerStretchUsingCurrentExtent () ) );
131
150
}
132
151
133
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionRemoveLayer.svg" ) ), tr ( " &Remove" ), QgisApp::instance (), SLOT ( removeLayer () ) );
134
-
135
- // duplicate layer
136
- QAction *duplicateLayersAction = menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionDuplicateLayer.svg" ) ), tr ( " &Duplicate" ), QgisApp::instance (), SLOT ( duplicateLayers () ) );
137
-
138
- if ( layer && layer->isSpatial () )
152
+ addCustomLayerActions ( menu, layer );
153
+ if ( layer && layer->type () == QgsMapLayer::VectorLayer && static_cast <QgsVectorLayer *>( layer )->providerType () == QLatin1String ( " virtual" ) )
139
154
{
140
- // set layer scale visibility
141
- menu->addAction ( tr ( " &Set Layer Scale Visibility" ), QgisApp::instance (), SLOT ( setLayerScaleVisibility () ) );
142
-
143
- if ( !layer->isInScaleRange ( mCanvas ->scale () ) )
144
- menu->addAction ( tr ( " Zoom to &Visible Scale" ), QgisApp::instance (), SLOT ( zoomToLayerScale () ) );
145
-
146
- QAction *checkAll = actions->actionCheckAndAllParents ( menu );
147
- if ( checkAll )
148
- menu->addAction ( checkAll );
149
-
150
- // set layer crs
151
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionSetCRS.png" ) ), tr ( " Set Layer CRS" ), QgisApp::instance (), SLOT ( setLayerCrs () ) );
152
-
153
- // assign layer crs to project
154
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionSetProjectCRS.png" ) ), tr ( " Set &Project CRS from Layer" ), QgisApp::instance (), SLOT ( setProjectCrsFromLayer () ) );
155
+ menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionAddVirtualLayer.svg" ) ), tr ( " Edit Virtual Layer…" ), QgisApp::instance (), SLOT ( addVirtualLayer () ) );
155
156
}
156
157
157
- // style-related actions
158
- if ( layer && mView ->selectedLayerNodes ().count () == 1 )
159
- {
160
- QMenu *menuStyleManager = new QMenu ( tr ( " Styles" ), menu );
158
+ menu->addSeparator ();
161
159
162
- QgisApp *app = QgisApp::instance ();
163
- menuStyleManager->addAction ( tr ( " Copy Style" ), app, SLOT ( copyStyle () ) );
164
- if ( app->clipboard ()->hasFormat ( QGSCLIPBOARD_STYLE_MIME ) )
165
- {
166
- menuStyleManager->addAction ( tr ( " Paste Style" ), app, SLOT ( pasteStyle () ) );
167
- }
160
+ // duplicate layer
161
+ QAction *duplicateLayersAction = menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionDuplicateLayer.svg" ) ), tr ( " &Duplicate" ), QgisApp::instance (), SLOT ( duplicateLayers () ) );
162
+ menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionRemoveLayer.svg" ) ), tr ( " &Remove…" ), QgisApp::instance (), SLOT ( removeLayer () ) );
168
163
169
- menuStyleManager->addSeparator ();
170
- QgsMapLayerStyleGuiUtils::instance ()->addStyleManagerActions ( menuStyleManager, layer );
164
+ menu->addSeparator ();
171
165
172
- if ( vlayer )
173
- {
174
- const QgsSingleSymbolRenderer *singleRenderer = dynamic_cast < const QgsSingleSymbolRenderer * >( vlayer->renderer () );
175
- if ( !singleRenderer && vlayer->renderer () && vlayer->renderer ()->embeddedRenderer () )
176
- {
177
- singleRenderer = dynamic_cast < const QgsSingleSymbolRenderer * >( vlayer->renderer ()->embeddedRenderer () );
178
- }
179
- if ( singleRenderer && singleRenderer->symbol () )
180
- {
181
- // single symbol renderer, so add set color/edit symbol actions
182
- menuStyleManager->addSeparator ();
183
- QgsColorWheel *colorWheel = new QgsColorWheel ( menuStyleManager );
184
- colorWheel->setColor ( singleRenderer->symbol ()->color () );
185
- QgsColorWidgetAction *colorAction = new QgsColorWidgetAction ( colorWheel, menuStyleManager, menuStyleManager );
186
- colorAction->setDismissOnColorSelection ( false );
187
- connect ( colorAction, &QgsColorWidgetAction::colorChanged, this , &QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor );
188
- // store the layer id in action, so we can later retrieve the corresponding layer
189
- colorAction->setProperty ( " layerId" , vlayer->id () );
190
- menuStyleManager->addAction ( colorAction );
166
+ if ( node->parent () != mView ->layerTreeModel ()->rootGroup () )
167
+ menu->addAction ( actions->actionMakeTopLevel ( menu ) );
191
168
192
- // add recent colors action
193
- QList<QgsRecentColorScheme *> recentSchemes;
194
- QgsApplication::colorSchemeRegistry ()->schemes ( recentSchemes );
195
- if ( !recentSchemes.isEmpty () )
196
- {
197
- QgsColorSwatchGridAction *recentColorAction = new QgsColorSwatchGridAction ( recentSchemes.at ( 0 ), menuStyleManager, QStringLiteral ( " symbology" ), menuStyleManager );
198
- recentColorAction->setProperty ( " layerId" , vlayer->id () );
199
- recentColorAction->setDismissOnColorSelection ( false );
200
- menuStyleManager->addAction ( recentColorAction );
201
- connect ( recentColorAction, &QgsColorSwatchGridAction::colorChanged, this , &QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor );
202
- }
169
+ QAction *checkAll = actions->actionCheckAndAllParents ( menu );
170
+ if ( checkAll )
171
+ menu->addAction ( checkAll );
203
172
204
- menuStyleManager->addSeparator ();
205
- QAction *editSymbolAction = new QAction ( tr ( " Edit Symbol…" ), menuStyleManager );
206
- // store the layer id in action, so we can later retrieve the corresponding layer
207
- editSymbolAction->setProperty ( " layerId" , vlayer->id () );
208
- connect ( editSymbolAction, &QAction::triggered, this , &QgsAppLayerTreeViewMenuProvider::editVectorSymbol );
209
- menuStyleManager->addAction ( editSymbolAction );
210
- }
211
- }
212
-
213
- menu->addMenu ( menuStyleManager );
214
- }
215
- else
216
- {
217
- if ( QgisApp::instance ()->clipboard ()->hasFormat ( QGSCLIPBOARD_STYLE_MIME ) )
218
- {
219
- menu->addAction ( tr ( " Paste Style" ), QgisApp::instance (), SLOT ( applyStyleToGroup () ) );
220
- }
221
- }
173
+ if ( mView ->selectedNodes ( true ).count () >= 2 )
174
+ menu->addAction ( actions->actionGroupSelected ( menu ) );
222
175
223
176
menu->addSeparator ();
224
- QAction *actionCopyLayer = new QAction ( tr ( " Copy Layer" ), menu );
225
- connect ( actionCopyLayer, &QAction::triggered, QgisApp::instance (), &QgisApp::copyLayer );
226
- menu->addAction ( actionCopyLayer );
227
177
228
178
if ( vlayer )
229
179
{
@@ -263,11 +213,35 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
263
213
QAction *action = menu->addAction ( tr ( " &Filter…" ), QgisApp::instance (), SLOT ( layerSubsetString () ) );
264
214
action->setEnabled ( !vlayer->isEditable () );
265
215
}
216
+ }
266
217
267
- menu->addAction ( actions-> actionShowFeatureCount ( menu ) );
218
+ menu->addSeparator ( );
268
219
269
- menu->addSeparator ();
220
+ if ( layer && layer->isSpatial () )
221
+ {
222
+ // set layer scale visibility
223
+ menu->addAction ( tr ( " &Set Layer Scale Visibility" ), QgisApp::instance (), SLOT ( setLayerScaleVisibility () ) );
270
224
225
+ if ( !layer->isInScaleRange ( mCanvas ->scale () ) )
226
+ menu->addAction ( tr ( " Zoom to &Visible Scale" ), QgisApp::instance (), SLOT ( zoomToLayerScale () ) );
227
+
228
+ QMenu *menuSetCRS = new QMenu ( tr ( " Set CRS" ), menu );
229
+ // set layer crs
230
+ QAction *actionSetLayerCrs = new QAction ( tr ( " Set Layer CRS…" ), menuSetCRS );
231
+ connect ( actionSetLayerCrs, &QAction::triggered, QgisApp::instance (), &QgisApp::setLayerCrs );
232
+ menuSetCRS->addAction ( actionSetLayerCrs );
233
+ // assign layer crs to project
234
+ QAction *actionSetProjectCrs = new QAction ( tr ( " Set &Project CRS from Layer" ), menuSetCRS );
235
+ connect ( actionSetProjectCrs, &QAction::triggered, QgisApp::instance (), &QgisApp::setProjectCrsFromLayer );
236
+ menuSetCRS->addAction ( actionSetProjectCrs );
237
+
238
+ menu->addMenu ( menuSetCRS );
239
+ }
240
+
241
+ menu->addSeparator ();
242
+
243
+ if ( vlayer )
244
+ {
271
245
// save as vector file
272
246
QMenu *menuExportVector = new QMenu ( tr ( " Export" ), menu );
273
247
QAction *actionSaveAs = new QAction ( tr ( " Save as…" ), menuExportVector );
@@ -297,34 +271,85 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
297
271
connect ( actionSaveStyle, &QAction::triggered, QgisApp::instance (), [ = ] { QgisApp::instance ()->saveStyleFile (); } );
298
272
menuExportRaster->addAction ( actionSaveStyle );
299
273
menu->addMenu ( menuExportRaster );
300
-
301
- menu->addSeparator ();
302
274
}
303
275
else if ( layer && layer->type () == QgsMapLayer::PluginLayer && mView ->selectedLayerNodes ().count () == 1 )
304
276
{
305
277
// disable duplication of plugin layers
306
278
duplicateLayersAction->setEnabled ( false );
307
279
}
308
280
309
- addCustomLayerActions ( menu, layer );
281
+ menu-> addSeparator ( );
310
282
311
- if ( layer && QgsProject::instance ()->layerIsEmbedded ( layer->id () ).isEmpty () )
312
- menu->addAction ( tr ( " &Properties" ), QgisApp::instance (), SLOT ( layerProperties () ) );
283
+ // style-related actions
284
+ if ( layer && mView ->selectedLayerNodes ().count () == 1 )
285
+ {
286
+ menu->addSeparator ();
287
+ QMenu *menuStyleManager = new QMenu ( tr ( " Styles" ), menu );
313
288
314
- if ( node->parent () != mView ->layerTreeModel ()->rootGroup () )
315
- menu->addAction ( actions->actionMakeTopLevel ( menu ) );
289
+ QgisApp *app = QgisApp::instance ();
290
+ menuStyleManager->addAction ( tr ( " Copy Style" ), app, SLOT ( copyStyle () ) );
291
+ if ( app->clipboard ()->hasFormat ( QGSCLIPBOARD_STYLE_MIME ) )
292
+ {
293
+ menuStyleManager->addAction ( tr ( " Paste Style" ), app, SLOT ( pasteStyle () ) );
294
+ }
316
295
317
- menu->addAction ( actions->actionRenameGroupOrLayer ( menu ) );
296
+ menuStyleManager->addSeparator ();
297
+ QgsMapLayerStyleGuiUtils::instance ()->addStyleManagerActions ( menuStyleManager, layer );
318
298
319
- if ( mView ->selectedNodes ( true ).count () >= 2 )
320
- menu->addAction ( actions->actionGroupSelected ( menu ) );
299
+ if ( vlayer )
300
+ {
301
+ const QgsSingleSymbolRenderer *singleRenderer = dynamic_cast < const QgsSingleSymbolRenderer * >( vlayer->renderer () );
302
+ if ( !singleRenderer && vlayer->renderer () && vlayer->renderer ()->embeddedRenderer () )
303
+ {
304
+ singleRenderer = dynamic_cast < const QgsSingleSymbolRenderer * >( vlayer->renderer ()->embeddedRenderer () );
305
+ }
306
+ if ( singleRenderer && singleRenderer->symbol () )
307
+ {
308
+ // single symbol renderer, so add set color/edit symbol actions
309
+ menuStyleManager->addSeparator ();
310
+ QgsColorWheel *colorWheel = new QgsColorWheel ( menuStyleManager );
311
+ colorWheel->setColor ( singleRenderer->symbol ()->color () );
312
+ QgsColorWidgetAction *colorAction = new QgsColorWidgetAction ( colorWheel, menuStyleManager, menuStyleManager );
313
+ colorAction->setDismissOnColorSelection ( false );
314
+ connect ( colorAction, &QgsColorWidgetAction::colorChanged, this , &QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor );
315
+ // store the layer id in action, so we can later retrieve the corresponding layer
316
+ colorAction->setProperty ( " layerId" , vlayer->id () );
317
+ menuStyleManager->addAction ( colorAction );
321
318
322
- if ( layer && layer->type () == QgsMapLayer::VectorLayer && static_cast <QgsVectorLayer *>( layer )->providerType () == QLatin1String ( " virtual" ) )
319
+ // add recent colors action
320
+ QList<QgsRecentColorScheme *> recentSchemes;
321
+ QgsApplication::colorSchemeRegistry ()->schemes ( recentSchemes );
322
+ if ( !recentSchemes.isEmpty () )
323
+ {
324
+ QgsColorSwatchGridAction *recentColorAction = new QgsColorSwatchGridAction ( recentSchemes.at ( 0 ), menuStyleManager, QStringLiteral ( " symbology" ), menuStyleManager );
325
+ recentColorAction->setProperty ( " layerId" , vlayer->id () );
326
+ recentColorAction->setDismissOnColorSelection ( false );
327
+ menuStyleManager->addAction ( recentColorAction );
328
+ connect ( recentColorAction, &QgsColorSwatchGridAction::colorChanged, this , &QgsAppLayerTreeViewMenuProvider::setVectorSymbolColor );
329
+ }
330
+
331
+ menuStyleManager->addSeparator ();
332
+ QAction *editSymbolAction = new QAction ( tr ( " Edit Symbol…" ), menuStyleManager );
333
+ // store the layer id in action, so we can later retrieve the corresponding layer
334
+ editSymbolAction->setProperty ( " layerId" , vlayer->id () );
335
+ connect ( editSymbolAction, &QAction::triggered, this , &QgsAppLayerTreeViewMenuProvider::editVectorSymbol );
336
+ menuStyleManager->addAction ( editSymbolAction );
337
+ }
338
+ }
339
+
340
+ menu->addMenu ( menuStyleManager );
341
+ }
342
+ else
323
343
{
324
- menu->addAction ( tr ( " Edit Virtual Layer…" ), QgisApp::instance (), SLOT ( addVirtualLayer () ) );
344
+ if ( QgisApp::instance ()->clipboard ()->hasFormat ( QGSCLIPBOARD_STYLE_MIME ) )
345
+ {
346
+ menu->addAction ( tr ( " Paste Style" ), QgisApp::instance (), SLOT ( applyStyleToGroup () ) );
347
+ }
325
348
}
326
- }
327
349
350
+ if ( layer && QgsProject::instance ()->layerIsEmbedded ( layer->id () ).isEmpty () )
351
+ menu->addAction ( tr ( " &Properties…" ), QgisApp::instance (), SLOT ( layerProperties () ) );
352
+ }
328
353
}
329
354
else if ( QgsLayerTreeModelLegendNode *node = mView ->layerTreeModel ()->index2legendNode ( idx ) )
330
355
{
0 commit comments