QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
7  email : [email protected]
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  ***************************************************************************/
16 #include "qgsactionscoperegistry.h"
17 
18 #include "qgsexpressioncontext.h"
19 
21  : QObject( parent )
22 {
23  // Register some default action scopes:
24 
25  QgsExpressionContextScope canvasScope;
26  canvasScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "click_x" ), 25, true ) );
27  canvasScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "click_y" ), 30, true ) );
28  mActionScopes.insert( QgsActionScope( QStringLiteral( "Canvas" ), tr( "Canvas" ), tr( "Available for the action map tool on the canvas." ), canvasScope ) );
29 
30  QgsExpressionContextScope fieldScope;
31  fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_index" ), 0, true ) );
32  fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_name" ), "[field_name]", true ) );
33  fieldScope.addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "field_value" ), "[field_value]", true ) );
34 
35  mActionScopes.insert( QgsActionScope( QStringLiteral( "Field" ), tr( "Field" ), tr( "Available for individual fields. For example in the attribute table." ), fieldScope ) );
36  mActionScopes.insert( QgsActionScope( QStringLiteral( "Feature" ), tr( "Feature" ), tr( "Available for individual features. For example on feature forms or per row in the attribute table." ) ) );
37  mActionScopes.insert( QgsActionScope( QStringLiteral( "Layer" ), tr( "Layer" ), tr( "Available as layer global action. For example on top of the attribute table." ) ) );
38  mActionScopes.insert( QgsActionScope( QStringLiteral( "Form" ), tr( "Form" ), tr( "Available only when connected to a form action button in a drag and drop attribute form." ) ) );
39 }
40 
41 QSet<QgsActionScope> QgsActionScopeRegistry::actionScopes() const
42 {
43  return mActionScopes;
44 }
45 
47 {
48  mActionScopes.insert( actionScope );
49 
50  emit actionScopesChanged();
51 }
52 
54 {
55  mActionScopes.remove( actionScope );
56 
57  emit actionScopesChanged();
58 }
59 
61 {
62  const auto constMActionScopes = mActionScopes;
63  for ( const QgsActionScope &actionScope : constMActionScopes )
64  {
65  if ( actionScope.id() == id )
66  {
67  return actionScope;
68  }
69  }
70 
71  return QgsActionScope();
72 }
QgsExpressionContextScope::addVariable
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Definition: qgsexpressioncontext.cpp:97
QgsActionScopeRegistry::registerActionScope
void registerActionScope(const QgsActionScope &actionScope)
Register an additional action scope.
Definition: qgsactionscoperegistry.cpp:46
qgsactionscoperegistry.h
QgsActionScope::id
QString id() const
A unique identifier for this action scope.
Definition: qgsactionscope.cpp:47
QgsActionScopeRegistry::actionScope
QgsActionScope actionScope(const QString &id)
Gets an action scope by its id.
Definition: qgsactionscoperegistry.cpp:60
QgsActionScopeRegistry::actionScopesChanged
void actionScopesChanged()
Emitted whenever a new action scope is registered or an action scope is unregistered.
qgsexpressioncontext.h
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsActionScope
An action scope defines a "place" for an action to be shown and may add additional expression variabl...
Definition: qgsactionscope.h:47
QgsActionScopeRegistry::unregisterActionScope
void unregisterActionScope(const QgsActionScope &actionScope)
Unregister an additional action scope.
Definition: qgsactionscoperegistry.cpp:53
QgsExpressionContextScope::StaticVariable
Single variable definition for use within a QgsExpressionContextScope.
Definition: qgsexpressioncontext.h:120
QgsActionScopeRegistry::QgsActionScopeRegistry
QgsActionScopeRegistry(QObject *parent=nullptr)
Create a new QgsActionScopeRegistry.
Definition: qgsactionscoperegistry.cpp:20
QgsActionScopeRegistry::actionScopes
QSet< QgsActionScope > actionScopes
Definition: qgsactionscoperegistry.h:61