Skip to content
Permalink
Browse files
Merge pull request #44710 from elpaso/dd-form-actions
[feature] Drag & Drop designer form actions
  • Loading branch information
elpaso committed Aug 19, 2021
2 parents bd6ac0e + cc81788 commit a25f798d041aa9da4ba0022914695c3571986fb5
@@ -0,0 +1,61 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/editform/qgsattributeeditoraction.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsAttributeEditorAction : QgsAttributeEditorElement
{
%Docstring(signature="appended")
This element will load a layer action onto the form.

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsattributeeditoraction.h"
%End
public:

QgsAttributeEditorAction( const QgsAction &action, QgsAttributeEditorElement *parent );
%Docstring
Creates a new element which can display a layer action.

:param action: The action
:param parent: The parent (used as container)
%End

QgsAttributeEditorAction( const QUuid &uuid, QgsAttributeEditorElement *parent );
%Docstring
Creates a new element which can display a layer action, this constructor allows
to create a QgsAttributeEditorAction when actions are not yet loaded.

:param uuid: The action unique identifier (UUID).
:param parent: The parent (used as container).
%End

virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const /Factory/;


const QgsAction &action( const QgsVectorLayer *layer ) const;
%Docstring
Returns the (possibly lazy loaded) action for the given ``layer``.
%End

void setAction( const QgsAction &newAction );
%Docstring
Set the action to ``newAction``.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/editform/qgsattributeeditoraction.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -35,6 +35,9 @@ layer.
case QgsAttributeEditorElement::AeTypeRelation:
sipType = sipType_QgsAttributeEditorRelation;
break;
case QgsAttributeEditorElement::AeTypeAction:
sipType = sipType_QgsAttributeEditorAction;
break;
default:
sipType = nullptr;
break;
@@ -48,7 +51,8 @@ layer.
AeTypeRelation,
AeTypeInvalid,
AeTypeQmlElement,
AeTypeHtmlElement
AeTypeHtmlElement,
AeTypeAction
};

QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 );
@@ -34,18 +34,17 @@ Utility class that encapsulates an action based on vector attributes.
Default constructor
%End

QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false );
QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false);
%Docstring
Create a new QgsAction

:param type: The type of this action
:param description: A human readable description string
:param command: The action text. Its interpretation depends on the type
:param capture: If this is set to ``True``, the output will be captured when an action is run
:param enabledOnlyWhenEditable: if ``True`` then action is only enable in editmode. Not available in Python bindings.
%End

QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString() );
QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
%Docstring
Create a new QgsAction

@@ -57,9 +56,24 @@ Create a new QgsAction
:param shortTitle: A short string used to label user interface elements like buttons
:param actionScopes: A set of scopes in which this action will be available
:param notificationMessage: A particular message which reception will trigger the action
:param enabledOnlyWhenEditable: if ``True`` then action is only enable in editmode. Not available in Python bindings.
%End

QgsAction( const QUuid &id, ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>(), const QString &notificationMessage = QString());
%Docstring
Create a new QgsAction

:param id: The unique identifier of this action
:param type: The type of this action
:param description: A human readable description string
:param action: The action text. Its interpretation depends on the type
:param icon: Path to an icon for this action
:param capture: If this is set to ``True``, the output will be captured when an action is run
:param shortTitle: A short string used to label user interface elements like buttons
:param actionScopes: A set of scopes in which this action will be available
:param notificationMessage: A particular message which reception will trigger the action
%End


QString name() const;
%Docstring
The name of the action. This may be a longer description.
@@ -112,7 +112,7 @@ Writes the actions out in XML format
Reads the actions in in XML format
%End

QgsAction action( QUuid id );
QgsAction action( QUuid id ) const;
%Docstring
Gets an action by its id.

@@ -250,6 +250,7 @@
%Include auto_generated/diagram/qgstextdiagram.sip
%Include auto_generated/dxf/qgsdxfexport.sip
%Include auto_generated/editform/qgseditformconfig.sip
%Include auto_generated/editform/qgsattributeeditoraction.sip
%Include auto_generated/editform/qgsattributeeditorelement.sip
%Include auto_generated/editform/qgsattributeeditorcontainer.sip
%Include auto_generated/editform/qgsattributeeditorfield.sip
@@ -0,0 +1,62 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgsactionwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsActionWidgetWrapper : QgsWidgetWrapper
{
%Docstring(signature="appended")
Wraps a button widget to launch a layer action.

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsactionwidgetwrapper.h"
%End
public:

QgsActionWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
%Docstring
Create an action widget wrapper

:param layer: The layer on which the feature is.
:param editor: An editor widget. Can be ``None`` if one should be autogenerated.
:param parent: A parent widget
%End

public:

void setAction( const QgsAction &action );
%Docstring
Sets the ``action``.
%End

virtual bool valid() const;

virtual QWidget *createWidget( QWidget *parent );

virtual void initWidget( QWidget *editor );


public slots:

virtual void setFeature( const QgsFeature &feature );

virtual void setEnabled( bool enabled );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgsactionwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -290,6 +290,7 @@
%Include auto_generated/editorwidgets/core/qgseditorwidgetwrapper.sip
%Include auto_generated/editorwidgets/core/qgssearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/core/qgswidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsactionwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgscheckboxsearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsdatetimeedit.sip
%Include auto_generated/editorwidgets/qgsdatetimesearchwidgetwrapper.sip
@@ -112,6 +112,7 @@ set(QGIS_CORE_SRCS
diagram/qgstextdiagram.cpp

editform/qgseditformconfig.cpp
editform/qgsattributeeditoraction.cpp
editform/qgsattributeeditorelement.cpp
editform/qgsattributeeditorcontainer.cpp
editform/qgsattributeeditorfield.cpp
@@ -1204,6 +1205,7 @@ set(QGIS_CORE_HDRS
dxf/qgsdxfexport.h

editform/qgseditformconfig.h
editform/qgsattributeeditoraction.h
editform/qgsattributeeditorelement.h
editform/qgsattributeeditorcontainer.h
editform/qgsattributeeditorfield.h
@@ -0,0 +1,73 @@
/***************************************************************************
qgsattributeeditoraction.cpp - QgsAttributeEditorAction
---------------------
begin : 14.8.2021
copyright : (C) 2021 by Alessandro Pasotti
email : elpaso at itopen dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsattributeeditoraction.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsactionmanager.h"

QgsAttributeEditorAction::QgsAttributeEditorAction( const QgsAction &action, QgsAttributeEditorElement *parent )
: QgsAttributeEditorElement( AeTypeAction, action.id().toString(), parent )
, mAction( action )
, mUuid( action.id() )
{}

QgsAttributeEditorAction::QgsAttributeEditorAction( const QUuid &uuid, QgsAttributeEditorElement *parent )
: QgsAttributeEditorAction( QgsAction(), parent )
{
mUuid = uuid;
}

QgsAttributeEditorElement *QgsAttributeEditorAction::clone( QgsAttributeEditorElement *parent ) const
{
QgsAttributeEditorAction *element = new QgsAttributeEditorAction( mAction, parent );
element->mUuid = mUuid;
return element;
}

const QgsAction &QgsAttributeEditorAction::action( const QgsVectorLayer *layer ) const
{
// Lazy loading
if ( ! mAction.isValid() && ! mUuid.isNull() && layer )
{
mAction = layer->actions()->action( mUuid );
}
return mAction;
}

void QgsAttributeEditorAction::setAction( const QgsAction &newAction )
{
mUuid = newAction.id();
mAction = newAction;
}

QString QgsAttributeEditorAction::typeIdentifier() const
{
return QStringLiteral( "attributeEditorAction" );
}

void QgsAttributeEditorAction::saveConfiguration( QDomElement &elem, QDomDocument &doc ) const
{
Q_UNUSED( doc )
elem.setAttribute( QStringLiteral( "ActionUUID" ), mUuid.toString() );
}

void QgsAttributeEditorAction::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
Q_UNUSED( layerId )
Q_UNUSED( context )
Q_UNUSED( fields )
mUuid = QUuid( element.attribute( QStringLiteral( "ActionUUID" ) ) );
}
@@ -0,0 +1,74 @@
/***************************************************************************
qgsattributeeditoraction.h - QgsAttributeEditorAction
---------------------
begin : 14.8.2021
copyright : (C) 2021 by Alessandro Pasotti
email : elpaso at itopen dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSATTRIBUTEEDITORACTION_H
#define QGSATTRIBUTEEDITORACTION_H

#include "qgis_core.h"
#include "qgsattributeeditorelement.h"
#include "qgsaction.h"

/**
* \ingroup core
* \brief This element will load a layer action onto the form.
* \since QGIS 3.22
*/
class CORE_EXPORT QgsAttributeEditorAction : public QgsAttributeEditorElement
{
public:

/**
* Creates a new element which can display a layer action.
*
* \param action The action
* \param parent The parent (used as container)
*/
QgsAttributeEditorAction( const QgsAction &action, QgsAttributeEditorElement *parent );

/**
* Creates a new element which can display a layer action, this constructor allows
* to create a QgsAttributeEditorAction when actions are not yet loaded.
*
* \param uuid The action unique identifier (UUID).
* \param parent The parent (used as container).
*/
QgsAttributeEditorAction( const QUuid &uuid, QgsAttributeEditorElement *parent );

QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const override SIP_FACTORY;

/**
* Returns the (possibly lazy loaded) action for the given \a layer.
*/
const QgsAction &action( const QgsVectorLayer *layer ) const;

/**
* Set the action to \a newAction.
*/
void setAction( const QgsAction &newAction );

private:

// Lazy loaded
mutable QgsAction mAction;
QUuid mUuid;

// QgsAttributeEditorElement interface
void saveConfiguration( QDomElement &elem, QDomDocument &doc ) const override;
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;

};

#endif // QGSATTRIBUTEEDITORACTION_H

0 comments on commit a25f798

Please sign in to comment.