Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Spacer widget for Drag&Drop attribute forms
  • Loading branch information
elpaso committed Jan 16, 2023
1 parent 5e56917 commit 6cd867e
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 0 deletions.
Expand Up @@ -71,6 +71,7 @@ layer.
AeTypeHtmlElement,
AeTypeAction,
AeTypeTextElement,
AeTypeSpacerElement,
};

QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 );
Expand Down
@@ -0,0 +1,43 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/editform/qgsattributeeditorspacerelement.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsAttributeEditorSpacerElement : QgsAttributeEditorElement
{
%Docstring(signature="appended")
An attribute editor widget that will represent a spacer.

.. versionadded:: 3.30
%End

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

QgsAttributeEditorSpacerElement( const QString &name, QgsAttributeEditorElement *parent );
%Docstring
Creates a new element which represents a spacer

:param name: The name of the widget
:param parent: The parent (used as container)
%End

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



};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/editform/qgsattributeeditorspacerelement.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -281,6 +281,7 @@
%Include auto_generated/editform/qgsattributeeditorhtmlelement.sip
%Include auto_generated/editform/qgsattributeeditortextelement.sip
%Include auto_generated/editform/qgsattributeeditorqmlelement.sip
%Include auto_generated/editform/qgsattributeeditorspacerelement.sip
%Include auto_generated/elevation/qgsabstractprofilegenerator.sip
%Include auto_generated/elevation/qgsabstractprofilesource.sip
%Include auto_generated/elevation/qgsprofilepoint.sip
Expand Down
@@ -0,0 +1,51 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgsspacerwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsSpacerWidgetWrapper : QgsWidgetWrapper
{
%Docstring(signature="appended")
Wraps a spacer widget.

.. versionadded:: 3.30
%End

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

explicit QgsSpacerWidgetWrapper( QgsVectorLayer *layer, QWidget *editor = 0, QWidget *parent = 0 );
%Docstring
Create a new widget wrapper

:param layer: The vector layer of the form the widget belongs to.
:param editor: An editor widget. Can be ``None`` if one should be autogenerated.
:param parent: A parent widget for this widget wrapper and the created widget.
%End

public:
virtual bool valid() const;


protected:
virtual QWidget *createWidget( QWidget *parent );


public slots:
virtual void setFeature( const QgsFeature &feature );

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgsspacerwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -325,6 +325,7 @@
%Include auto_generated/editorwidgets/qgsrelationreferencewidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsrelationwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgssearchwidgettoolbutton.sip
%Include auto_generated/editorwidgets/qgsspacerwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsspinbox.sip
%Include auto_generated/editorwidgets/qgstextwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsvaluemapsearchwidgetwrapper.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -141,6 +141,7 @@ set(QGIS_CORE_SRCS
editform/qgsattributeeditorhtmlelement.cpp
editform/qgsattributeeditortextelement.cpp
editform/qgsattributeeditorqmlelement.cpp
editform/qgsattributeeditorspacerelement.cpp

effects/qgsblureffect.cpp
effects/qgscoloreffect.cpp
Expand Down Expand Up @@ -1319,6 +1320,7 @@ set(QGIS_CORE_HDRS
editform/qgsattributeeditorhtmlelement.h
editform/qgsattributeeditortextelement.h
editform/qgsattributeeditorqmlelement.h
editform/qgsattributeeditorspacerelement.h

elevation/qgsabstractprofilegenerator.h
elevation/qgsabstractprofilesurfacegenerator.h
Expand Down
5 changes: 5 additions & 0 deletions src/core/editform/qgsattributeeditorelement.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsattributeeditorhtmlelement.h"
#include "qgsattributeeditorqmlelement.h"
#include "qgsattributeeditorrelation.h"
#include "qgsattributeeditorspacerelement.h"
#include "qgsattributeeditortextelement.h"
#include "qgssymbollayerutils.h"
#include "qgsfontutils.h"
Expand Down Expand Up @@ -90,6 +91,10 @@ QgsAttributeEditorElement *QgsAttributeEditorElement::create( const QDomElement
{
newElement = new QgsAttributeEditorTextElement( element.attribute( QStringLiteral( "name" ) ), parent );
}
else if ( element.tagName() == QLatin1String( "attributeEditorSpacerElement" ) )
{
newElement = new QgsAttributeEditorSpacerElement( element.attribute( QStringLiteral( "name" ) ), parent );
}
else if ( element.tagName() == QLatin1String( "attributeEditorAction" ) )
{
newElement = new QgsAttributeEditorAction( QUuid( element.attribute( QStringLiteral( "name" ) ) ), parent );
Expand Down
1 change: 1 addition & 0 deletions src/core/editform/qgsattributeeditorelement.h
Expand Up @@ -110,6 +110,7 @@ class CORE_EXPORT QgsAttributeEditorElement SIP_ABSTRACT
AeTypeHtmlElement, //!< A HTML element
AeTypeAction, //!< A layer action element (since QGIS 3.22)
AeTypeTextElement, //!< A text element (since QGIS 3.30)
AeTypeSpacerElement, //!< A spacer element (since QGIS 3.30)
};

/**
Expand Down
43 changes: 43 additions & 0 deletions src/core/editform/qgsattributeeditorspacerelement.cpp
@@ -0,0 +1,43 @@
/***************************************************************************
qgsattributeeditorspacerelement.cpp - QgsAttributeEditorSpacerElement
---------------------
begin : 16.1.2023
copyright : (C) 2023 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 "qgsattributeeditorspacerelement.h"


QgsAttributeEditorElement *QgsAttributeEditorSpacerElement::clone( QgsAttributeEditorElement *parent ) const
{
return new QgsAttributeEditorSpacerElement( name(), parent );
}

void QgsAttributeEditorSpacerElement::saveConfiguration( QDomElement &elem, QDomDocument &doc ) const
{
// Nothing to save
Q_UNUSED( elem );
Q_UNUSED( doc );
}

void QgsAttributeEditorSpacerElement::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
// Nothing to load
Q_UNUSED( element );
Q_UNUSED( layerId );
Q_UNUSED( context );
Q_UNUSED( fields );
}

QString QgsAttributeEditorSpacerElement::typeIdentifier() const
{
return QStringLiteral( "attributeEditorSpacerElement" );
}
52 changes: 52 additions & 0 deletions src/core/editform/qgsattributeeditorspacerelement.h
@@ -0,0 +1,52 @@
/***************************************************************************
qgsattributeeditorspacerelement.h - QgsAttributeEditorSpacerElement
---------------------
begin : 16.1.2023
copyright : (C) 2023 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 QGSATTRIBUTEEDITORSPACERELEMENT_H
#define QGSATTRIBUTEEDITORSPACERELEMENT_H

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

/**
* \ingroup core
* \brief An attribute editor widget that will represent a spacer.
*
* \since QGIS 3.30
*/
class CORE_EXPORT QgsAttributeEditorSpacerElement : public QgsAttributeEditorElement
{
public:

/**
* Creates a new element which represents a spacer
*
* \param name The name of the widget
* \param parent The parent (used as container)
*/
QgsAttributeEditorSpacerElement( const QString &name, QgsAttributeEditorElement *parent )
: QgsAttributeEditorElement( AeTypeSpacerElement, name, parent )
{}

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


// QgsAttributeEditorElement interface
private:
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 // QGSATTRIBUTEEDITORSPACERELEMENT_H
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -209,6 +209,7 @@ set(QGIS_GUI_SRCS
editorwidgets/qgsrelationreferencefactory.cpp
editorwidgets/qgsrelationreferencesearchwidgetwrapper.cpp
editorwidgets/qgsrelationreferencewidget.cpp
editorwidgets/qgsspacerwidgetwrapper.cpp
editorwidgets/qgsrelationreferencewidgetwrapper.cpp
editorwidgets/qgstexteditconfigdlg.cpp
editorwidgets/qgstexteditsearchwidgetwrapper.cpp
Expand Down Expand Up @@ -1083,6 +1084,7 @@ set(QGIS_GUI_HDRS
editorwidgets/qgsrelationreferencewidgetwrapper.h
editorwidgets/qgsrelationwidgetwrapper.h
editorwidgets/qgssearchwidgettoolbutton.h
editorwidgets/qgsspacerwidgetwrapper.h
editorwidgets/qgsspinbox.h
editorwidgets/qgstexteditconfigdlg.h
editorwidgets/qgstexteditsearchwidgetwrapper.h
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributeformconfig/qgsattributewidgetedit.cpp
Expand Up @@ -53,6 +53,7 @@ QgsAttributeWidgetEdit::QgsAttributeWidgetEdit( QTreeWidgetItem *item, QWidget *
case QgsAttributesFormProperties::DnDTreeItemData::QmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::HtmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::TextWidget:
case QgsAttributesFormProperties::DnDTreeItemData::SpacerWidget:
case QgsAttributesFormProperties::DnDTreeItemData::WidgetType:
mWidgetSpecificConfigGroupBox->hide();
break;
Expand Down Expand Up @@ -87,6 +88,7 @@ void QgsAttributeWidgetEdit::updateItemData()
case QgsAttributesFormProperties::DnDTreeItemData::QmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::HtmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::TextWidget:
case QgsAttributesFormProperties::DnDTreeItemData::SpacerWidget:
case QgsAttributesFormProperties::DnDTreeItemData::WidgetType:
break;
}
Expand Down
39 changes: 39 additions & 0 deletions src/gui/editorwidgets/qgsspacerwidgetwrapper.cpp
@@ -0,0 +1,39 @@
/***************************************************************************
qgsspacerwidgetwrapper.cpp - QgsSpacerWidgetWrapper
---------------------
begin : 16.1.2023
copyright : (C) 2023 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 "qgsspacerwidgetwrapper.h"


QgsSpacerWidgetWrapper::QgsSpacerWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
: QgsWidgetWrapper( layer, editor, parent )
{

}

bool QgsSpacerWidgetWrapper::valid() const
{
return true;
}

QWidget *QgsSpacerWidgetWrapper::createWidget( QWidget *parent )
{
return new QWidget( parent );
}

void QgsSpacerWidgetWrapper::setFeature( const QgsFeature &feature )
{
Q_UNUSED( feature );
}
52 changes: 52 additions & 0 deletions src/gui/editorwidgets/qgsspacerwidgetwrapper.h
@@ -0,0 +1,52 @@
/***************************************************************************
qgsspacerwidgetwrapper.h - QgsSpacerWidgetWrapper
---------------------
begin : 16.1.2023
copyright : (C) 2023 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 QGSSPACERWIDGETWRAPPER_H
#define QGSSPACERWIDGETWRAPPER_H

#include <qgswidgetwrapper.h>
#include "qgis_gui.h"

/**
* \ingroup gui
* \brief Wraps a spacer widget.
* \since QGIS 3.30
*/
class GUI_EXPORT QgsSpacerWidgetWrapper : public QgsWidgetWrapper
{
Q_OBJECT
public:

/**
* Create a new widget wrapper
*
* \param layer The vector layer of the form the widget belongs to.
* \param editor An editor widget. Can be NULLPTR if one should be autogenerated.
* \param parent A parent widget for this widget wrapper and the created widget.
*/
explicit QgsSpacerWidgetWrapper( QgsVectorLayer *layer, QWidget *editor = nullptr, QWidget *parent = nullptr );

// QgsWidgetWrapper interface
public:
bool valid() const override;

protected:
QWidget *createWidget( QWidget *parent ) override;

public slots:
void setFeature( const QgsFeature &feature ) override;
};

#endif // QGSSPACERWIDGETWRAPPER_H

0 comments on commit 6cd867e

Please sign in to comment.