Skip to content

Commit

Permalink
Promote attribute editor enums to enum class, move to Qgis
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 26, 2023
1 parent 26469a5 commit 9e55296
Show file tree
Hide file tree
Showing 42 changed files with 373 additions and 260 deletions.
95 changes: 95 additions & 0 deletions python/core/auto_additions/qgis.py
Expand Up @@ -3475,3 +3475,98 @@
Qgis.UserProfileSelectionPolicy.__doc__ = 'User profile selection policy.\n\n.. versionadded:: 3.32\n\n' + '* ``LastProfile``: ' + Qgis.UserProfileSelectionPolicy.LastProfile.__doc__ + '\n' + '* ``DefaultProfile``: ' + Qgis.UserProfileSelectionPolicy.DefaultProfile.__doc__ + '\n' + '* ``AskUser``: ' + Qgis.UserProfileSelectionPolicy.AskUser.__doc__
# --
Qgis.UserProfileSelectionPolicy.baseClass = Qgis
QgsAttributeEditorElement.AttributeEditorType = Qgis.AttributeEditorType
# monkey patching scoped based enum
QgsAttributeEditorElement.AeTypeContainer = Qgis.AttributeEditorType.Container
QgsAttributeEditorElement.AttributeEditorType.AeTypeContainer = Qgis.AttributeEditorType.Container
QgsAttributeEditorElement.AeTypeContainer.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeContainer.__doc__ = "A container"
QgsAttributeEditorElement.AeTypeField = Qgis.AttributeEditorType.Field
QgsAttributeEditorElement.AttributeEditorType.AeTypeField = Qgis.AttributeEditorType.Field
QgsAttributeEditorElement.AeTypeField.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeField.__doc__ = "A field"
QgsAttributeEditorElement.AeTypeRelation = Qgis.AttributeEditorType.Relation
QgsAttributeEditorElement.AttributeEditorType.AeTypeRelation = Qgis.AttributeEditorType.Relation
QgsAttributeEditorElement.AeTypeRelation.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeRelation.__doc__ = "A relation"
QgsAttributeEditorElement.AeTypeQmlElement = Qgis.AttributeEditorType.QmlElement
QgsAttributeEditorElement.AttributeEditorType.AeTypeQmlElement = Qgis.AttributeEditorType.QmlElement
QgsAttributeEditorElement.AeTypeQmlElement.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeQmlElement.__doc__ = "A QML element"
QgsAttributeEditorElement.AeTypeHtmlElement = Qgis.AttributeEditorType.HtmlElement
QgsAttributeEditorElement.AttributeEditorType.AeTypeHtmlElement = Qgis.AttributeEditorType.HtmlElement
QgsAttributeEditorElement.AeTypeHtmlElement.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeHtmlElement.__doc__ = "A HTML element"
QgsAttributeEditorElement.AeTypeAction = Qgis.AttributeEditorType.Action
QgsAttributeEditorElement.AttributeEditorType.AeTypeAction = Qgis.AttributeEditorType.Action
QgsAttributeEditorElement.AeTypeAction.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeAction.__doc__ = "A layer action element (since QGIS 3.22)"
QgsAttributeEditorElement.AeTypeTextElement = Qgis.AttributeEditorType.TextElement
QgsAttributeEditorElement.AttributeEditorType.AeTypeTextElement = Qgis.AttributeEditorType.TextElement
QgsAttributeEditorElement.AeTypeTextElement.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeTextElement.__doc__ = "A text element (since QGIS 3.30)"
QgsAttributeEditorElement.AeTypeSpacerElement = Qgis.AttributeEditorType.SpacerElement
QgsAttributeEditorElement.AttributeEditorType.AeTypeSpacerElement = Qgis.AttributeEditorType.SpacerElement
QgsAttributeEditorElement.AeTypeSpacerElement.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeSpacerElement.__doc__ = "A spacer element (since QGIS 3.30)"
QgsAttributeEditorElement.AeTypeInvalid = Qgis.AttributeEditorType.Invalid
QgsAttributeEditorElement.AttributeEditorType.AeTypeInvalid = Qgis.AttributeEditorType.Invalid
QgsAttributeEditorElement.AeTypeInvalid.is_monkey_patched = True
QgsAttributeEditorElement.AeTypeInvalid.__doc__ = "Invalid"
Qgis.AttributeEditorType.__doc__ = 'Attribute editor types.\n\n.. note::\n\n Prior to QGIS 3.32 this was available as :py:class:`QgsAttributeEditorElement`.AttributeEditorType.\n\n.. versionadded:: 3.32\n\n' + '* ``AeTypeContainer``: ' + Qgis.AttributeEditorType.Container.__doc__ + '\n' + '* ``AeTypeField``: ' + Qgis.AttributeEditorType.Field.__doc__ + '\n' + '* ``AeTypeRelation``: ' + Qgis.AttributeEditorType.Relation.__doc__ + '\n' + '* ``AeTypeQmlElement``: ' + Qgis.AttributeEditorType.QmlElement.__doc__ + '\n' + '* ``AeTypeHtmlElement``: ' + Qgis.AttributeEditorType.HtmlElement.__doc__ + '\n' + '* ``AeTypeAction``: ' + Qgis.AttributeEditorType.Action.__doc__ + '\n' + '* ``AeTypeTextElement``: ' + Qgis.AttributeEditorType.TextElement.__doc__ + '\n' + '* ``AeTypeSpacerElement``: ' + Qgis.AttributeEditorType.SpacerElement.__doc__ + '\n' + '* ``AeTypeInvalid``: ' + Qgis.AttributeEditorType.Invalid.__doc__
# --
Qgis.AttributeEditorType.baseClass = Qgis
QgsEditFormConfig.EditorLayout = Qgis.AttributeFormLayout
# monkey patching scoped based enum
QgsEditFormConfig.GeneratedLayout = Qgis.AttributeFormLayout.AutoGenerated
QgsEditFormConfig.EditorLayout.GeneratedLayout = Qgis.AttributeFormLayout.AutoGenerated
QgsEditFormConfig.GeneratedLayout.is_monkey_patched = True
QgsEditFormConfig.GeneratedLayout.__doc__ = "Autogenerate a simple tabular layout for the form"
QgsEditFormConfig.DragAndDrop = Qgis.AttributeFormLayout.DragAndDrop
QgsEditFormConfig.DragAndDrop.is_monkey_patched = True
QgsEditFormConfig.DragAndDrop.__doc__ = "\"Drag and drop\" layout. Needs to be configured."
QgsEditFormConfig.UiFileLayout = Qgis.AttributeFormLayout.UiFile
QgsEditFormConfig.EditorLayout.UiFileLayout = Qgis.AttributeFormLayout.UiFile
QgsEditFormConfig.UiFileLayout.is_monkey_patched = True
QgsEditFormConfig.UiFileLayout.__doc__ = "Load a .ui file for the layout. Needs to be configured."
Qgis.AttributeFormLayout.__doc__ = 'Available form types for layout of the attribute form editor.\n\n.. note::\n\n Prior to QGIS 3.32 this was available as :py:class:`QgsEditFormConfig`.EditorLayout.\n\n.. versionadded:: 3.32\n\n' + '* ``GeneratedLayout``: ' + Qgis.AttributeFormLayout.AutoGenerated.__doc__ + '\n' + '* ``DragAndDrop``: ' + Qgis.AttributeFormLayout.DragAndDrop.__doc__ + '\n' + '* ``UiFileLayout``: ' + Qgis.AttributeFormLayout.UiFile.__doc__
# --
Qgis.AttributeFormLayout.baseClass = Qgis
QgsEditFormConfig.FeatureFormSuppress = Qgis.AttributeFormSuppression
# monkey patching scoped based enum
QgsEditFormConfig.SuppressDefault = Qgis.AttributeFormSuppression.Default
QgsEditFormConfig.FeatureFormSuppress.SuppressDefault = Qgis.AttributeFormSuppression.Default
QgsEditFormConfig.SuppressDefault.is_monkey_patched = True
QgsEditFormConfig.SuppressDefault.__doc__ = "Use the application-wide setting."
QgsEditFormConfig.SuppressOn = Qgis.AttributeFormSuppression.On
QgsEditFormConfig.FeatureFormSuppress.SuppressOn = Qgis.AttributeFormSuppression.On
QgsEditFormConfig.SuppressOn.is_monkey_patched = True
QgsEditFormConfig.SuppressOn.__doc__ = "Always suppress feature form."
QgsEditFormConfig.SuppressOff = Qgis.AttributeFormSuppression.Off
QgsEditFormConfig.FeatureFormSuppress.SuppressOff = Qgis.AttributeFormSuppression.Off
QgsEditFormConfig.SuppressOff.is_monkey_patched = True
QgsEditFormConfig.SuppressOff.__doc__ = "Never suppress feature form."
Qgis.AttributeFormSuppression.__doc__ = 'Available form types for layout of the attribute form editor.\n\n.. note::\n\n Prior to QGIS 3.32 this was available as :py:class:`QgsEditFormConfig`.FeatureFormSuppress.\n\n.. versionadded:: 3.32\n\n' + '* ``SuppressDefault``: ' + Qgis.AttributeFormSuppression.Default.__doc__ + '\n' + '* ``SuppressOn``: ' + Qgis.AttributeFormSuppression.On.__doc__ + '\n' + '* ``SuppressOff``: ' + Qgis.AttributeFormSuppression.Off.__doc__
# --
Qgis.AttributeFormSuppression.baseClass = Qgis
QgsEditFormConfig.PythonInitCodeSource = Qgis.AttributeFormPythonInitCodeSource
# monkey patching scoped based enum
QgsEditFormConfig.CodeSourceNone = Qgis.AttributeFormPythonInitCodeSource.NoSource
QgsEditFormConfig.PythonInitCodeSource.CodeSourceNone = Qgis.AttributeFormPythonInitCodeSource.NoSource
QgsEditFormConfig.CodeSourceNone.is_monkey_patched = True
QgsEditFormConfig.CodeSourceNone.__doc__ = "Do not use Python code at all"
QgsEditFormConfig.CodeSourceFile = Qgis.AttributeFormPythonInitCodeSource.File
QgsEditFormConfig.PythonInitCodeSource.CodeSourceFile = Qgis.AttributeFormPythonInitCodeSource.File
QgsEditFormConfig.CodeSourceFile.is_monkey_patched = True
QgsEditFormConfig.CodeSourceFile.__doc__ = "Load the Python code from an external file"
QgsEditFormConfig.CodeSourceDialog = Qgis.AttributeFormPythonInitCodeSource.Dialog
QgsEditFormConfig.PythonInitCodeSource.CodeSourceDialog = Qgis.AttributeFormPythonInitCodeSource.Dialog
QgsEditFormConfig.CodeSourceDialog.is_monkey_patched = True
QgsEditFormConfig.CodeSourceDialog.__doc__ = "Use the Python code provided in the dialog"
QgsEditFormConfig.CodeSourceEnvironment = Qgis.AttributeFormPythonInitCodeSource.Environment
QgsEditFormConfig.PythonInitCodeSource.CodeSourceEnvironment = Qgis.AttributeFormPythonInitCodeSource.Environment
QgsEditFormConfig.CodeSourceEnvironment.is_monkey_patched = True
QgsEditFormConfig.CodeSourceEnvironment.__doc__ = "Use the Python code available in the Python environment"
Qgis.AttributeFormPythonInitCodeSource.__doc__ = 'The Python init code source for attribute forms.\n\n.. note::\n\n Prior to QGIS 3.32 this was available as :py:class:`QgsEditFormConfig`.PythonInitCodeSource.\n\n.. versionadded:: 3.32\n\n' + '* ``CodeSourceNone``: ' + Qgis.AttributeFormPythonInitCodeSource.NoSource.__doc__ + '\n' + '* ``CodeSourceFile``: ' + Qgis.AttributeFormPythonInitCodeSource.File.__doc__ + '\n' + '* ``CodeSourceDialog``: ' + Qgis.AttributeFormPythonInitCodeSource.Dialog.__doc__ + '\n' + '* ``CodeSourceEnvironment``: ' + Qgis.AttributeFormPythonInitCodeSource.Environment.__doc__
# --
Qgis.AttributeFormPythonInitCodeSource.baseClass = Qgis
4 changes: 0 additions & 4 deletions python/core/auto_additions/qgseditformconfig.py

This file was deleted.

Expand Up @@ -81,7 +81,7 @@ Gets a list of the children elements of this container
:return: A list of elements
%End

virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
virtual QList<QgsAttributeEditorElement *> findElements( Qgis::AttributeEditorType type ) const;
%Docstring
Traverses the element tree to find any element of the specified type

Expand Down
Expand Up @@ -8,6 +8,7 @@




class QgsAttributeEditorElement /Abstract/
{
%Docstring(signature="appended")
Expand All @@ -26,16 +27,16 @@ layer.
%ConvertToSubClassCode
switch ( sipCpp->type() )
{
case QgsAttributeEditorElement::AeTypeContainer:
case Qgis::AttributeEditorType::Container:
sipType = sipType_QgsAttributeEditorContainer;
break;
case QgsAttributeEditorElement::AeTypeField:
case Qgis::AttributeEditorType::Field:
sipType = sipType_QgsAttributeEditorField;
break;
case QgsAttributeEditorElement::AeTypeRelation:
case Qgis::AttributeEditorType::Relation:
sipType = sipType_QgsAttributeEditorRelation;
break;
case QgsAttributeEditorElement::AeTypeAction:
case Qgis::AttributeEditorType::Action:
sipType = sipType_QgsAttributeEditorAction;
break;
default:
Expand All @@ -60,21 +61,7 @@ layer.

};


enum AttributeEditorType
{
AeTypeContainer,
AeTypeField,
AeTypeRelation,
AeTypeInvalid,
AeTypeQmlElement,
AeTypeHtmlElement,
AeTypeAction,
AeTypeTextElement,
AeTypeSpacerElement,
};

QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 );
QgsAttributeEditorElement( Qgis::AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = 0 );
%Docstring
Constructor

Expand All @@ -99,7 +86,7 @@ Returns the name of this element
:return: The name for this element
%End

AttributeEditorType type() const;
Qgis::AttributeEditorType type() const;
%Docstring
The type of this element

Expand Down
35 changes: 6 additions & 29 deletions python/core/auto_generated/editform/qgseditformconfig.sip.in
Expand Up @@ -25,13 +25,6 @@ Contains configuration settings for an editor form.

public:

enum EditorLayout
{
GeneratedLayout,
TabLayout,
UiFileLayout
};

struct GroupData
{
GroupData();
Expand All @@ -55,21 +48,6 @@ Constructor for TabData
QList<QgsEditFormConfig::GroupData> mGroups;
};

enum FeatureFormSuppress
{
SuppressDefault,
SuppressOn,
SuppressOff
};

enum PythonInitCodeSource
{
CodeSourceNone,
CodeSourceFile,
CodeSourceDialog,
CodeSourceEnvironment
};

enum DataDefinedProperty
{
NoProperty,
Expand Down Expand Up @@ -112,12 +90,12 @@ Gets the invisible root container for the drag and drop designer form (EditorLay
.. versionadded:: 3
%End

EditorLayout layout() const;
Qgis::AttributeFormLayout layout() const;
%Docstring
Gets the active layout style for the attribute editor for this layer
%End

void setLayout( EditorLayout editorLayout );
void setLayout( Qgis::AttributeFormLayout editorLayout );
%Docstring
Sets the active layout style for the attribute editor for this layer
%End
Expand Down Expand Up @@ -265,23 +243,23 @@ Make sure that you also set the appropriate function name in
:py:func:`~QgsEditFormConfig.setInitFunction`.
%End

PythonInitCodeSource initCodeSource() const;
Qgis::AttributeFormPythonInitCodeSource initCodeSource() const;
%Docstring
Returns Python code source for edit form initialization
(if it shall be loaded from a file, read from the
provided dialog editor or inherited from the environment)
%End

void setInitCodeSource( PythonInitCodeSource initCodeSource );
void setInitCodeSource( Qgis::AttributeFormPythonInitCodeSource initCodeSource );
%Docstring
Sets if Python code shall be used for edit form initialization and its origin
%End

FeatureFormSuppress suppress() const;
Qgis::AttributeFormSuppression suppress() const;
%Docstring
Type of feature form pop-up suppression after feature creation (overrides app setting)
%End
void setSuppress( FeatureFormSuppress s );
void setSuppress( Qgis::AttributeFormSuppression s );
%Docstring
Sets type of feature form pop-up suppression after feature creation (overrides app setting)
%End
Expand Down Expand Up @@ -326,7 +304,6 @@ Returns data defined properties for ``fieldName``
.. versionadded:: 3.14
%End


static const QgsPropertiesDefinition &propertyDefinitions();
%Docstring
Returns data defined property definitions.
Expand Down
35 changes: 35 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Expand Up @@ -1979,6 +1979,41 @@ The development version
AskUser,
};

enum class AttributeEditorType
{
Container,
Field,
Relation,
QmlElement,
HtmlElement,
Action,
TextElement,
SpacerElement,
Invalid,
};

enum class AttributeFormLayout
{
AutoGenerated,
DragAndDrop,
UiFile
};

enum class AttributeFormSuppression
{
Default,
On,
Off
};

enum class AttributeFormPythonInitCodeSource
{
NoSource,
File,
Dialog,
Environment
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -91,7 +91,7 @@ void QgsAttributeTableDialog::readXml( const QDomElement &element )

void QgsAttributeTableDialog::updateMultiEditButtonState()
{
if ( ! mLayer || ( mLayer->editFormConfig().layout() == QgsEditFormConfig::EditorLayout::UiFileLayout ) )
if ( ! mLayer || ( mLayer->editFormConfig().layout() == Qgis::AttributeFormLayout::UiFile ) )
return;

mActionToggleMultiEdit->setEnabled( mLayer->isEditable() );
Expand Down Expand Up @@ -427,7 +427,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mActionSearchForm, &QAction::toggled, mMainView, &QgsDualView::toggleSearchMode );
updateMultiEditButtonState();

if ( mLayer->editFormConfig().layout() == QgsEditFormConfig::EditorLayout::UiFileLayout )
if ( mLayer->editFormConfig().layout() == Qgis::AttributeFormLayout::UiFile )
{
//not supported with custom UI
mActionToggleMultiEdit->setEnabled( false );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -227,13 +227,13 @@ QgsFeatureAction::AddFeatureResult QgsFeatureAction::addFeature( const QgsAttrib
// override application-wide setting with any layer setting
switch ( mLayer->editFormConfig().suppress() )
{
case QgsEditFormConfig::SuppressOn:
case Qgis::AttributeFormSuppression::On:
isDisabledAttributeValuesDlg = true;
break;
case QgsEditFormConfig::SuppressOff:
case Qgis::AttributeFormSuppression::Off:
isDisabledAttributeValuesDlg = false;
break;
case QgsEditFormConfig::SuppressDefault:
case Qgis::AttributeFormSuppression::Default:
break;
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/editform/qgsattributeeditoraction.cpp
Expand Up @@ -14,12 +14,11 @@
* *
***************************************************************************/
#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 )
: QgsAttributeEditorElement( Qgis::AttributeEditorType::Action, action.id().toString(), parent )
, mAction( action )
, mUuid( action.id() )
{}
Expand Down
4 changes: 2 additions & 2 deletions src/core/editform/qgsattributeeditorcontainer.cpp
Expand Up @@ -68,7 +68,7 @@ void QgsAttributeEditorContainer::setBackgroundColor( const QColor &backgroundCo
mBackgroundColor = backgroundColor;
}

QList<QgsAttributeEditorElement *> QgsAttributeEditorContainer::findElements( QgsAttributeEditorElement::AttributeEditorType type ) const
QList<QgsAttributeEditorElement *> QgsAttributeEditorContainer::findElements( Qgis::AttributeEditorType type ) const
{
QList<QgsAttributeEditorElement *> results;

Expand All @@ -80,7 +80,7 @@ QList<QgsAttributeEditorElement *> QgsAttributeEditorContainer::findElements( Qg
results.append( elem );
}

if ( elem->type() == AeTypeContainer )
if ( elem->type() == Qgis::AttributeEditorType::Container )
{
QgsAttributeEditorContainer *cont = dynamic_cast<QgsAttributeEditorContainer *>( elem );
if ( cont )
Expand Down
5 changes: 3 additions & 2 deletions src/core/editform/qgsattributeeditorcontainer.h
Expand Up @@ -18,6 +18,7 @@

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

/**
* \ingroup core
Expand All @@ -36,7 +37,7 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
* \param backgroundColor The optional background color of the container.
*/
QgsAttributeEditorContainer( const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor = QColor() )
: QgsAttributeEditorElement( AeTypeContainer, name, parent )
: QgsAttributeEditorElement( Qgis::AttributeEditorType::Container, name, parent )
, mIsGroupBox( true )
, mColumnCount( 1 )
, mBackgroundColor( backgroundColor )
Expand Down Expand Up @@ -99,7 +100,7 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
*
* \returns A list of elements of the type which has been searched for
*/
virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
virtual QList<QgsAttributeEditorElement *> findElements( Qgis::AttributeEditorType type ) const;

/**
* Clear all children from this container.
Expand Down

0 comments on commit 9e55296

Please sign in to comment.