QGIS API Documentation  3.27.0-Master (11ef3e5184)
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 "qgsproject.h"
18 #include "qgsvectorlayer.h"
19 #include "qgsactionmanager.h"
20 
22  : QgsAttributeEditorElement( AeTypeAction, action.id().toString(), parent )
23  , mAction( action )
24  , mUuid( action.id() )
25 {}
26 
28  : QgsAttributeEditorAction( QgsAction(), parent )
29 {
30  mUuid = uuid;
31 }
32 
34 {
35  QgsAttributeEditorAction *element = new QgsAttributeEditorAction( mAction, parent );
36  element->mUuid = mUuid;
37  return element;
38 }
39 
41 {
42  // Lazy loading
43  if ( ! mAction.isValid() && ! mUuid.isNull() && layer )
44  {
45  mAction = layer->actions()->action( mUuid );
46  }
47  return mAction;
48 }
49 
51 {
52  mUuid = newAction.id();
53  mAction = newAction;
54 }
55 
56 QString QgsAttributeEditorAction::typeIdentifier() const
57 {
58  return QStringLiteral( "attributeEditorAction" );
59 }
60 
61 void QgsAttributeEditorAction::saveConfiguration( QDomElement &elem, QDomDocument &doc ) const
62 {
63  Q_UNUSED( doc )
64  elem.setAttribute( QStringLiteral( "ActionUUID" ), mUuid.toString() );
65 }
66 
67 void QgsAttributeEditorAction::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
68 {
69  Q_UNUSED( layerId )
70  Q_UNUSED( context )
71  Q_UNUSED( fields )
72  mUuid = QUuid( element.attribute( QStringLiteral( "ActionUUID" ) ) );
73 }
QgsAction action(QUuid id) const
Gets an action by its id.
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:35
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:144
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:137
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.