QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsactionscoperegistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsactionscoperegistry.cpp - QgsActionScopeRegistry
3
4 ---------------------
5 begin : 1.11.2016
6 copyright : (C) 2016 by Matthias Kuhn
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17#include "moc_qgsactionscoperegistry.cpp"
18
20
22 : QObject( parent )
23{
24 // Register some default action scopes:
25
26 QgsExpressionContextScope canvasScope;
27 canvasScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "click_x" ), 25, true ) );
28 canvasScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "click_y" ), 30, true ) );
29 mActionScopes.insert( QgsActionScope( QStringLiteral( "Canvas" ), tr( "Canvas" ), tr( "Available for the action map tool on the canvas." ), canvasScope ) );
30
32 fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_index" ), 0, true ) );
33 fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_name" ), "[field_name]", true ) );
34 fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_value" ), "[field_value]", true ) );
35
36 mActionScopes.insert( QgsActionScope( QStringLiteral( "Field" ), tr( "Field" ), tr( "Available for individual fields. For example in the attribute table." ), fieldScope ) );
37 mActionScopes.insert( QgsActionScope( QStringLiteral( "Feature" ), tr( "Feature" ), tr( "Available for individual features. For example on feature forms or per row in the attribute table." ) ) );
38 mActionScopes.insert( QgsActionScope( QStringLiteral( "Layer" ), tr( "Layer" ), tr( "Available as layer global action. For example on top of the attribute table." ) ) );
39 mActionScopes.insert( QgsActionScope( QStringLiteral( "Form" ), tr( "Form" ), tr( "Available only when connected to a form action button in a drag and drop attribute form." ) ) );
40}
41
42QSet<QgsActionScope> QgsActionScopeRegistry::actionScopes() const
43{
44 return mActionScopes;
45}
46
48{
49 mActionScopes.insert( actionScope );
50
52}
53
55{
56 mActionScopes.remove( actionScope );
57
59}
60
62{
63 const auto constMActionScopes = mActionScopes;
64 for ( const QgsActionScope &actionScope : constMActionScopes )
65 {
66 if ( actionScope.id() == id )
67 {
68 return actionScope;
69 }
70 }
71
72 return QgsActionScope();
73}
void unregisterActionScope(const QgsActionScope &actionScope)
Unregister an additional action scope.
void registerActionScope(const QgsActionScope &actionScope)
Register an additional action scope.
QgsActionScope actionScope(const QString &id)
Gets an action scope by its id.
QgsActionScopeRegistry(QObject *parent=nullptr)
Create a new QgsActionScopeRegistry.
QSet< QgsActionScope > actionScopes
void actionScopesChanged()
Emitted whenever a new action scope is registered or an action scope is unregistered.
An action scope defines a "place" for an action to be shown and may add additional expression variabl...
QString id() const
Returns the unique identifier for this action scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Single variable definition for use within a QgsExpressionContextScope.