QGIS API Documentation 3.99.0-Master (8e76e220402)
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
18#include "qgsactionmanager.h"
19#include "qgsvectorlayer.h"
20
21#include <QString>
22
23using namespace Qt::StringLiterals;
24
26 : QgsAttributeEditorElement( Qgis::AttributeEditorType::Action, action.id().toString(), parent )
27 , mAction( action )
28 , mUuid( action.id() )
29{}
30
36
38{
40 element->mUuid = mUuid;
41 return element;
42}
43
45{
46 // Lazy loading
47 if ( ! mAction.isValid() && ! mUuid.isNull() && layer )
48 {
49 mAction = layer->actions()->action( mUuid );
50 }
51 return mAction;
52}
53
55{
56 mUuid = newAction.id();
57 mAction = newAction;
58}
59
60QString QgsAttributeEditorAction::typeIdentifier() const
61{
62 return u"attributeEditorAction"_s;
63}
64
65void QgsAttributeEditorAction::saveConfiguration( QDomElement &elem, QDomDocument &doc ) const
66{
67 Q_UNUSED( doc )
68 elem.setAttribute( u"ActionUUID"_s, mUuid.toString() );
69}
70
71void QgsAttributeEditorAction::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
72{
73 Q_UNUSED( layerId )
74 Q_UNUSED( context )
75 Q_UNUSED( fields )
76 mUuid = QUuid( element.attribute( u"ActionUUID"_s ) );
77}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
QgsAction action(QUuid id) const
Gets an action by its id.
Utility class that encapsulates an action based on vector attributes.
Definition qgsaction.h:38
QUuid id() const
Returns a unique id for this action.
Definition qgsaction.h:125
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.
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
QgsAttributeEditorElement(Qgis::AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent=nullptr)
Constructor.
Container of fields for a vector layer.
Definition qgsfields.h:46
A container for the context for various read/write operations on objects.
Represents a vector layer which manages a vector based dataset.
QgsActionManager * actions()
Returns all layer actions defined on this layer.