QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
QgsAttributeEditorElement
This is an abstract base class for any elements of a drag and drop form.
Definition: qgsattributeeditorelement.h:37
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsActionManager::action
QgsAction action(QUuid id) const
Gets an action by its id.
Definition: qgsactionmanager.cpp:279
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsAttributeEditorAction::setAction
void setAction(const QgsAction &newAction)
Set the action to newAction.
Definition: qgsattributeeditoraction.cpp:50
QgsAttributeEditorAction::QgsAttributeEditorAction
QgsAttributeEditorAction(const QgsAction &action, QgsAttributeEditorElement *parent)
Creates a new element which can display a layer action.
Definition: qgsattributeeditoraction.cpp:21
qgsattributeeditoraction.h
QgsAction::isValid
bool isValid() const
Returns true if this action was a default constructed one.
Definition: qgsaction.h:144
qgsactionmanager.h
QgsAttributeEditorAction::clone
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Returns a clone of this element.
Definition: qgsattributeeditoraction.cpp:33
QgsAttributeEditorAction
This element will load a layer action onto the form.
Definition: qgsattributeeditoraction.h:28
QgsVectorLayer::actions
QgsActionManager * actions()
Returns all layer actions defined on this layer.
Definition: qgsvectorlayer.h:741
QgsAction
Utility class that encapsulates an action based on vector attributes.
Definition: qgsaction.h:34
qgsvectorlayer.h
QgsAction::id
QUuid id() const
Returns a unique id for this action.
Definition: qgsaction.h:137
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgsproject.h
QgsAttributeEditorElement::parent
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
Definition: qgsattributeeditorelement.h:170
QgsAttributeEditorAction::action
const QgsAction & action(const QgsVectorLayer *layer) const
Returns the (possibly lazy loaded) action for the given layer.
Definition: qgsattributeeditoraction.cpp:40