Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #51323 from elpaso/text-widget
Text widget
  • Loading branch information
elpaso committed Jan 15, 2023
2 parents eb168a5 + 96afc54 commit bed001f
Show file tree
Hide file tree
Showing 17 changed files with 644 additions and 4 deletions.
Expand Up @@ -69,7 +69,8 @@ layer.
AeTypeInvalid,
AeTypeQmlElement,
AeTypeHtmlElement,
AeTypeAction
AeTypeAction,
AeTypeTextElement,
};

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




class QgsAttributeEditorTextElement : QgsAttributeEditorElement
{
%Docstring(signature="appended")
An attribute editor widget that will represent arbitrary text code.

.. versionadded:: 3.30
%End

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

QgsAttributeEditorTextElement( const QString &name, QgsAttributeEditorElement *parent );
%Docstring
Creates a new element which can display text

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

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


QString text() const;
%Docstring
The Text that will be represented within this widget.
%End

void setText( const QString &text );
%Docstring
Sets the text that will be represented within this widget to ``text``
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/editform/qgsattributeeditortextelement.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 @@ -279,6 +279,7 @@
%Include auto_generated/editform/qgsattributeeditorfield.sip
%Include auto_generated/editform/qgsattributeeditorrelation.sip
%Include auto_generated/editform/qgsattributeeditorhtmlelement.sip
%Include auto_generated/editform/qgsattributeeditortextelement.sip
%Include auto_generated/editform/qgsattributeeditorqmlelement.sip
%Include auto_generated/elevation/qgsabstractprofilegenerator.sip
%Include auto_generated/elevation/qgsabstractprofilesource.sip
Expand Down
@@ -0,0 +1,69 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgstextwidgetwrapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/


class QgsTextWidgetWrapper : QgsWidgetWrapper
{
%Docstring(signature="appended")
Wraps a label widget to display text

.. versionadded:: 3.30
%End

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

QgsTextWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
%Docstring
Create a text 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

virtual bool valid() const;


virtual QWidget *createWidget( QWidget *parent );


virtual void initWidget( QWidget *editor );


void reinitWidget();
%Docstring
Clears the content and makes new initialization
%End

void setText( const QString &text );
%Docstring
Sets the text code to ``htmlCode``
%End

bool needsGeometry() const;
%Docstring
Returns true if the widget needs feature geometry
%End

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


};


/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/editorwidgets/qgstextwidgetwrapper.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 @@ -326,6 +326,7 @@
%Include auto_generated/editorwidgets/qgsrelationwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgssearchwidgettoolbutton.sip
%Include auto_generated/editorwidgets/qgsspinbox.sip
%Include auto_generated/editorwidgets/qgstextwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsvaluemapsearchwidgetwrapper.sip
%Include auto_generated/editorwidgets/qgsvaluerelationsearchwidgetwrapper.sip
%Include auto_generated/effects/qgseffectdrawmodecombobox.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -139,6 +139,7 @@ set(QGIS_CORE_SRCS
editform/qgsattributeeditorfield.cpp
editform/qgsattributeeditorrelation.cpp
editform/qgsattributeeditorhtmlelement.cpp
editform/qgsattributeeditortextelement.cpp
editform/qgsattributeeditorqmlelement.cpp

effects/qgsblureffect.cpp
Expand Down Expand Up @@ -1316,6 +1317,7 @@ set(QGIS_CORE_HDRS
editform/qgsattributeeditorfield.h
editform/qgsattributeeditorrelation.h
editform/qgsattributeeditorhtmlelement.h
editform/qgsattributeeditortextelement.h
editform/qgsattributeeditorqmlelement.h

elevation/qgsabstractprofilegenerator.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 "qgsattributeeditortextelement.h"
#include "qgssymbollayerutils.h"
#include "qgsfontutils.h"

Expand Down Expand Up @@ -85,6 +86,10 @@ QgsAttributeEditorElement *QgsAttributeEditorElement::create( const QDomElement
{
newElement = new QgsAttributeEditorHtmlElement( element.attribute( QStringLiteral( "name" ) ), parent );
}
else if ( element.tagName() == QLatin1String( "attributeEditorTextElement" ) )
{
newElement = new QgsAttributeEditorTextElement( element.attribute( QStringLiteral( "name" ) ), parent );
}
else if ( element.tagName() == QLatin1String( "attributeEditorAction" ) )
{
newElement = new QgsAttributeEditorAction( QUuid( element.attribute( QStringLiteral( "name" ) ) ), parent );
Expand Down
3 changes: 2 additions & 1 deletion src/core/editform/qgsattributeeditorelement.h
Expand Up @@ -108,7 +108,8 @@ class CORE_EXPORT QgsAttributeEditorElement SIP_ABSTRACT
AeTypeInvalid, //!< Invalid
AeTypeQmlElement, //!< A QML element
AeTypeHtmlElement, //!< A HTML element
AeTypeAction //!< A layer action element (since QGIS 3.22)
AeTypeAction, //!< A layer action element (since QGIS 3.22)
AeTypeTextElement, //!< A text element (since QGIS 3.30)
};

/**
Expand Down
55 changes: 55 additions & 0 deletions src/core/editform/qgsattributeeditortextelement.cpp
@@ -0,0 +1,55 @@
/***************************************************************************
qgsattributeeditortextelement.cpp - QgsAttributeEditorTextelement
---------------------
begin : 28.12.2022
copyright : (C) 2022 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 "qgsattributeeditortextelement.h"


QgsAttributeEditorElement *QgsAttributeEditorTextElement::clone( QgsAttributeEditorElement *parent ) const
{
QgsAttributeEditorTextElement *element = new QgsAttributeEditorTextElement( name(), parent );
element->setText( mText );

return element;
}

QString QgsAttributeEditorTextElement::text() const
{
return mText;
}

void QgsAttributeEditorTextElement::setText( const QString &text )
{
mText = text;
}

void QgsAttributeEditorTextElement::saveConfiguration( QDomElement &elem, QDomDocument &doc ) const
{
const QDomText textElem = doc.createTextNode( mText );
elem.appendChild( textElem );
}

void QgsAttributeEditorTextElement::loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields )
{
Q_UNUSED( layerId )
Q_UNUSED( context )
Q_UNUSED( fields )
setText( element.text() );
}

QString QgsAttributeEditorTextElement::typeIdentifier() const
{
return QStringLiteral( "attributeEditorTextElement" );
}

64 changes: 64 additions & 0 deletions src/core/editform/qgsattributeeditortextelement.h
@@ -0,0 +1,64 @@
/***************************************************************************
qgsattributeeditortextelement.h - QgsAttributeEditorTextElement
---------------------
begin : 28.12.2022
copyright : (C) 2022 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 QGSATTRIBUTEEDITORTEXTELEMENT_H
#define QGSATTRIBUTEEDITORTEXTELEMENT_H

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



/**
* \ingroup core
* \brief An attribute editor widget that will represent arbitrary text code.
*
* \since QGIS 3.30
*/
class CORE_EXPORT QgsAttributeEditorTextElement : public QgsAttributeEditorElement
{
public:

/**
* Creates a new element which can display text
*
* \param name The name of the widget
* \param parent The parent (used as container)
*/
QgsAttributeEditorTextElement( const QString &name, QgsAttributeEditorElement *parent )
: QgsAttributeEditorElement( AeTypeTextElement, name, parent )
{}

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

/**
* The Text that will be represented within this widget.
*/
QString text() const;

/**
* Sets the text that will be represented within this widget to \a text
*/
void setText( const QString &text );

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;
QString mText;
};


#endif // QGSATTRIBUTEEDITORTEXTELEMENT_H
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -214,6 +214,7 @@ set(QGIS_GUI_SRCS
editorwidgets/qgstexteditsearchwidgetwrapper.cpp
editorwidgets/qgstexteditwrapper.cpp
editorwidgets/qgstexteditwidgetfactory.cpp
editorwidgets/qgstextwidgetwrapper.cpp
editorwidgets/qgsuniquevaluesconfigdlg.cpp
editorwidgets/qgsuniquevaluewidgetwrapper.cpp
editorwidgets/qgsuniquevaluewidgetfactory.cpp
Expand Down Expand Up @@ -1086,6 +1087,7 @@ set(QGIS_GUI_HDRS
editorwidgets/qgstexteditsearchwidgetwrapper.h
editorwidgets/qgstexteditwidgetfactory.h
editorwidgets/qgstexteditwrapper.h
editorwidgets/qgstextwidgetwrapper.h
editorwidgets/qgsuniquevaluesconfigdlg.h
editorwidgets/qgsuniquevaluewidgetfactory.h
editorwidgets/qgsuniquevaluewidgetwrapper.h
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributeformconfig/qgsattributewidgetedit.cpp
Expand Up @@ -52,6 +52,7 @@ QgsAttributeWidgetEdit::QgsAttributeWidgetEdit( QTreeWidgetItem *item, QWidget *
case QgsAttributesFormProperties::DnDTreeItemData::Container:
case QgsAttributesFormProperties::DnDTreeItemData::QmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::HtmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::TextWidget:
case QgsAttributesFormProperties::DnDTreeItemData::WidgetType:
mWidgetSpecificConfigGroupBox->hide();
break;
Expand Down Expand Up @@ -85,6 +86,7 @@ void QgsAttributeWidgetEdit::updateItemData()
case QgsAttributesFormProperties::DnDTreeItemData::Container:
case QgsAttributesFormProperties::DnDTreeItemData::QmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::HtmlWidget:
case QgsAttributesFormProperties::DnDTreeItemData::TextWidget:
case QgsAttributesFormProperties::DnDTreeItemData::WidgetType:
break;
}
Expand Down

0 comments on commit bed001f

Please sign in to comment.