QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsattributeeditoraction.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsattributeeditoraction.cpp - QgsAttributeEditorAction
3
4 ---------------------
5 begin : 14.8.2021
6 copyright : (C) 2021 by Alessandro Pasotti
7 email : elpaso at itopen dot it
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 "qgsvectorlayer.h"
18#include "qgsactionmanager.h"
19
21 : QgsAttributeEditorElement( Qgis::AttributeEditorType::Action, action.id().toString(), parent )
22 , mAction( action )
23 , mUuid( action.id() )
24{}
25
28{
29 mUuid = uuid;
30}
31
33{
35 element->mUuid = mUuid;
36 return element;
37}
38
40{
41 // Lazy loading
42 if ( ! mAction.isValid() && ! mUuid.isNull() && layer )
43 {
44 mAction = layer->actions()->action( mUuid );
45 }
46 return mAction;
47}
48
50{
51 mUuid = newAction.id();
52 mAction = newAction;
53}
54
55QString QgsAttributeEditorAction::typeIdentifier() const
56{
57 return QStringLiteral( "attributeEditorAction" );
58}
59
60void QgsAttributeEditorAction::saveConfiguration( QDomElement &elem, QDomDocument &doc ) const
61{
62 Q_UNUSED( doc )
63 elem.setAttribute( QStringLiteral( "ActionUUID" ), mUuid.toString() );
64}
65
66void QgsAttributeEditorAction::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
67{
68 Q_UNUSED( layerId )
69 Q_UNUSED( context )
70 Q_UNUSED( fields )
71 mUuid = QUuid( element.attribute( QStringLiteral( "ActionUUID" ) ) );
72}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QgsAction action(QUuid id) const
Gets an action by its id.
Utility class that encapsulates an action based on vector attributes.
Definition qgsaction.h:37
bool isValid() const
Returns true if this action was a default constructed one.
Definition qgsaction.h:133
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:127
This element will load a layer action onto the form.
const QgsAction & action(const QgsVectorLayer *layer) const
Returns the (possibly lazy loaded) action for the given layer.
QgsAttributeEditorAction(const QgsAction &action, QgsAttributeEditorElement *parent)
Creates a new element which can display a layer action.
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
void setAction(const QgsAction &newAction)
Set the action to newAction.
This is an abstract base class for any elements of a drag and drop form.
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
Container of fields for a vector layer.
Definition qgsfields.h:45
The class is used as a container of context for various read/write operations on other objects.
Represents a vector layer which manages a vector based data sets.
QgsActionManager * actions()
Returns all layer actions defined on this layer.