Use enums for attribute form container types instead of bools

Gives flexibility for adding additional container types in future
This commit is contained in:
Nyall Dawson 2023-04-27 08:25:08 +10:00
parent 9d5af2a78d
commit a434d0e7c0
15 changed files with 353 additions and 198 deletions

View File

@ -3516,6 +3516,12 @@ 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
# monkey patching scoped based enum
Qgis.AttributeEditorContainerType.GroupBox.__doc__ = "A group box"
Qgis.AttributeEditorContainerType.Tab.__doc__ = "A tab widget"
Qgis.AttributeEditorContainerType.__doc__ = 'Attribute editor container types.\n\n.. versionadded:: 3.32\n\n' + '* ``GroupBox``: ' + Qgis.AttributeEditorContainerType.GroupBox.__doc__ + '\n' + '* ``Tab``: ' + Qgis.AttributeEditorContainerType.Tab.__doc__
# --
Qgis.AttributeEditorContainerType.baseClass = Qgis
QgsEditFormConfig.EditorLayout = Qgis.AttributeFormLayout
# monkey patching scoped based enum
QgsEditFormConfig.GeneratedLayout = Qgis.AttributeFormLayout.AutoGenerated

View File

@ -28,7 +28,6 @@ Creates a new attribute editor container
:param backgroundColor: The optional background color of the container.
%End
~QgsAttributeEditorContainer();
virtual void addChildElement( QgsAttributeEditorElement *element /Transfer/ );
@ -38,23 +37,47 @@ Add a child element to this container. This may be another container, a field or
:param element: The element to add as child
%End
virtual void setIsGroupBox( bool isGroupBox );
void setType( Qgis::AttributeEditorContainerType type );
%Docstring
Sets the container type.
.. seealso:: :py:func:`type`
.. versionadded:: 3.32
%End
Qgis::AttributeEditorContainerType type() const;
%Docstring
Returns the container type.
.. seealso:: :py:func:`setType`
.. versionadded:: 3.32
%End
virtual void setIsGroupBox( bool isGroupBox ) /Deprecated/;
%Docstring
Determines if this container is rendered as collapsible group box or tab in a tabwidget
:param isGroupBox: If ``True``, this will be a group box
.. deprecated::
use :py:func:`~QgsAttributeEditorContainer.setType` instead.
%End
virtual bool isGroupBox() const;
virtual bool isGroupBox() const /Deprecated/;
%Docstring
Returns if this container is going to be a group box
:return: ``True`` if it will be a group box, ``False`` if it will be a tab
.. deprecated::
Use :py:func:`~QgsAttributeEditorContainer.type` instead.
%End
bool collapsed() const;
%Docstring
For group box containers returns if this group box is collapsed.
For group box containers returns ``True`` if this group box is collapsed.
:return: ``True`` if the group box is collapsed, ``False`` otherwise.
@ -66,7 +89,7 @@ For group box containers returns if this group box is collapsed.
%End
void setCollapsed( bool collapsed );
%Docstring
For group box containers sets if this group box is ``collapsed``.
For group box containers sets if this group box is ``collapsed``.
.. seealso:: :py:func:`collapsed`
@ -97,17 +120,21 @@ Clear all children from this container.
void setName( const QString &name );
%Docstring
Change the name of this container
Change the name of this container.
%End
int columnCount() const;
%Docstring
Gets the number of columns in this group
Gets the number of columns in this group.
.. seealso:: :py:func:`setColumnCount`
%End
void setColumnCount( int columnCount );
%Docstring
Set the number of columns in this group
Set the number of columns in this group.
.. seealso:: :py:func:`columnCount`
%End
virtual QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const /Factory/;
@ -140,16 +167,18 @@ the field value controlled by editor widgets.
QColor backgroundColor() const;
%Docstring
backgroundColor
Returns the background color of the container.
:return: background color of the container
.. seealso:: :py:func:`setBackgroundColor`
.. versionadded:: 3.8
%End
void setBackgroundColor( const QColor &backgroundColor );
%Docstring
Sets the background color to ``backgroundColor``
Sets the background color to ``backgroundColor``.
.. seealso:: :py:func:`backgroundColor`
%End
};

View File

@ -1992,6 +1992,12 @@ The development version
Invalid,
};
enum class AttributeEditorContainerType
{
GroupBox,
Tab,
};
enum class AttributeFormLayout
{
AutoGenerated,

View File

@ -27,6 +27,19 @@ void QgsAttributeEditorContainer::addChildElement( QgsAttributeEditorElement *wi
mChildren.append( widget );
}
void QgsAttributeEditorContainer::setIsGroupBox( bool isGroupBox )
{
if ( isGroupBox )
setType( Qgis::AttributeEditorContainerType::GroupBox );
else
setType( Qgis::AttributeEditorContainerType::Tab );
}
bool QgsAttributeEditorContainer::isGroupBox() const
{
return mType == Qgis::AttributeEditorContainerType::GroupBox;
}
void QgsAttributeEditorContainer::setName( const QString &name )
{
mName = name;
@ -117,7 +130,7 @@ QgsAttributeEditorElement *QgsAttributeEditorContainer::clone( QgsAttributeEdito
{
element->addChildElement( child->clone( element ) );
}
element->mIsGroupBox = mIsGroupBox;
element->mType = mType;
element->mColumnCount = mColumnCount;
element->mVisibilityExpression = mVisibilityExpression;
element->mCollapsed = mCollapsed;
@ -131,7 +144,8 @@ void QgsAttributeEditorContainer::saveConfiguration( QDomElement &elem, QDomDocu
{
Q_UNUSED( doc )
elem.setAttribute( QStringLiteral( "columnCount" ), mColumnCount );
elem.setAttribute( QStringLiteral( "groupBox" ), mIsGroupBox ? 1 : 0 );
elem.setAttribute( QStringLiteral( "groupBox" ), mType == Qgis::AttributeEditorContainerType::GroupBox ? 1 : 0 );
elem.setAttribute( QStringLiteral( "type" ), qgsEnumValueToKey( mType ) );
elem.setAttribute( QStringLiteral( "collapsed" ), mCollapsed );
elem.setAttribute( QStringLiteral( "collapsedExpressionEnabled" ), mCollapsedExpression.enabled() ? 1 : 0 );
elem.setAttribute( QStringLiteral( "collapsedExpression" ), mCollapsedExpression->expression() );
@ -156,11 +170,18 @@ void QgsAttributeEditorContainer::loadConfiguration( const QDomElement &element,
cc = 0;
setColumnCount( cc );
const bool isGroupBox = element.attribute( QStringLiteral( "groupBox" ) ).toInt( &ok );
if ( ok )
setIsGroupBox( isGroupBox );
if ( element.hasAttribute( QStringLiteral( "type" ) ) )
{
mType = qgsEnumKeyToValue( element.attribute( QStringLiteral( "type" ) ), Qgis::AttributeEditorContainerType::GroupBox );
}
else
setIsGroupBox( mParent );
{
const bool isGroupBox = element.attribute( QStringLiteral( "groupBox" ) ).toInt( &ok );
if ( ok )
setType( isGroupBox ? Qgis::AttributeEditorContainerType::GroupBox : Qgis::AttributeEditorContainerType::Tab );
else
setType( mParent ? Qgis::AttributeEditorContainerType::GroupBox : Qgis::AttributeEditorContainerType::Tab );
}
const bool isCollapsed = element.attribute( QStringLiteral( "collapsed" ) ).toInt( &ok );
if ( ok )

View File

@ -38,12 +38,9 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
*/
QgsAttributeEditorContainer( const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor = QColor() )
: QgsAttributeEditorElement( Qgis::AttributeEditorType::Container, name, parent )
, mIsGroupBox( true )
, mColumnCount( 1 )
, mBackgroundColor( backgroundColor )
{}
~QgsAttributeEditorContainer() override;
/**
@ -53,22 +50,41 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
*/
virtual void addChildElement( QgsAttributeEditorElement *element SIP_TRANSFER );
/**
* Sets the container type.
*
* \see type()
* \since QGIS 3.32
*/
void setType( Qgis::AttributeEditorContainerType type ) { mType = type; }
/**
* Returns the container type.
*
* \see setType()
* \since QGIS 3.32
*/
Qgis::AttributeEditorContainerType type() const { return mType; }
/**
* Determines if this container is rendered as collapsible group box or tab in a tabwidget
*
* \param isGroupBox If TRUE, this will be a group box
* \deprecated use setType() instead.
*/
virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
Q_DECL_DEPRECATED virtual void setIsGroupBox( bool isGroupBox ) SIP_DEPRECATED;
/**
* Returns if this container is going to be a group box
*
* \returns TRUE if it will be a group box, FALSE if it will be a tab
*
* \deprecated Use type() instead.
*/
virtual bool isGroupBox() const { return mIsGroupBox; }
Q_DECL_DEPRECATED virtual bool isGroupBox() const SIP_DEPRECATED;
/**
* For group box containers returns if this group box is collapsed.
* For group box containers returns TRUE if this group box is collapsed.
*
* \returns TRUE if the group box is collapsed, FALSE otherwise.
* \see collapsed()
@ -78,7 +94,7 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
bool collapsed() const { return mCollapsed; };
/**
* For group box containers sets if this group box is \a collapsed.
* For group box containers sets if this group box is \a collapsed.
*
* \see collapsed()
* \see setCollapsed()
@ -108,17 +124,21 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
void clear();
/**
* Change the name of this container
* Change the name of this container.
*/
void setName( const QString &name );
/**
* Gets the number of columns in this group
* Gets the number of columns in this group.
*
* \see setColumnCount()
*/
int columnCount() const;
/**
* Set the number of columns in this group
* Set the number of columns in this group.
*
* \see columnCount()
*/
void setColumnCount( int columnCount );
@ -172,14 +192,17 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression ) SIP_SKIP;
/**
* \brief backgroundColor
* \return background color of the container
* Returns the background color of the container.
*
* \see setBackgroundColor()
* \since QGIS 3.8
*/
QColor backgroundColor() const;
/**
* Sets the background color to \a backgroundColor
* Sets the background color to \a backgroundColor.
*
* \see backgroundColor()
*/
void setBackgroundColor( const QColor &backgroundColor );
@ -188,9 +211,9 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
void loadConfiguration( const QDomElement &element, const QString &layerId, const QgsReadWriteContext &context, const QgsFields &fields ) override;
QString typeIdentifier() const override;
bool mIsGroupBox;
Qgis::AttributeEditorContainerType mType = Qgis::AttributeEditorContainerType::GroupBox;
QList<QgsAttributeEditorElement *> mChildren;
int mColumnCount;
int mColumnCount = 1;
QgsOptionalExpression mVisibilityExpression;
QColor mBackgroundColor;
bool mCollapsed = false;

View File

@ -3449,6 +3449,18 @@ class CORE_EXPORT Qgis
};
Q_ENUM( AttributeEditorType )
/**
* Attribute editor container types.
*
* \since QGIS 3.32
*/
enum class AttributeEditorContainerType : int
{
GroupBox, //!< A group box
Tab, //!< A tab widget
};
Q_ENUM( AttributeEditorContainerType )
/**
* Available form types for layout of the attribute form editor.
*

View File

@ -16,7 +16,7 @@
#include "qgsattributeformcontaineredit.h"
#include "ui_qgsattributeformcontaineredit.h"
#include "qgsattributesformproperties.h"
#include "qgsvectorlayer.h"
QgsAttributeFormContainerEdit::QgsAttributeFormContainerEdit( QTreeWidgetItem *item, QgsVectorLayer *layer, QWidget *parent )
: QWidget( parent )
@ -27,18 +27,25 @@ QgsAttributeFormContainerEdit::QgsAttributeFormContainerEdit( QTreeWidgetItem *i
const QgsAttributesFormProperties::DnDTreeItemData itemData = mTreeItem->data( 0, QgsAttributesFormProperties::DnDTreeRole ).value<QgsAttributesFormProperties::DnDTreeItemData>();
Q_ASSERT( itemData.type() == QgsAttributesFormProperties::DnDTreeItemData::Container );
if ( item->parent() )
if ( ! item->parent() )
{
// only top level items can be tabs
mTypeCombo->addItem( tr( "Tab" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) );
mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
}
if ( item->parent() )
{
// i.e. it's always a group box if it's a nested container
mShowAsGroupBox->hide();
mShowAsGroupBox->setEnabled( false );
mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
mTypeCombo->setEnabled( false );
}
mTitleLineEdit->setText( itemData.name() );
mShowLabelCheckBox->setChecked( itemData.showLabel() );
mShowLabelCheckBox->setEnabled( itemData.showAsGroupBox() ); // show label makes sense for group box, not for tabs
mShowAsGroupBox->setChecked( itemData.showAsGroupBox() );
mShowLabelCheckBox->setEnabled( itemData.containerType() == Qgis::AttributeEditorContainerType::GroupBox ); // show label makes sense for group box, not other container types
mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( itemData.containerType() ) ) );
if ( mTypeCombo->currentIndex() < 0 )
mTypeCombo->setCurrentIndex( 0 );
mControlVisibilityGroupBox->setChecked( itemData.visibilityExpression().enabled() );
mVisibilityExpressionWidget->setLayer( layer );
@ -47,17 +54,31 @@ QgsAttributeFormContainerEdit::QgsAttributeFormContainerEdit( QTreeWidgetItem *i
mBackgroundColorButton->setShowNull( true );
mBackgroundColorButton->setColor( itemData.backgroundColor() );
mCollapsedCheckBox->setChecked( itemData.collapsed() );
mCollapsedCheckBox->setEnabled( itemData.showAsGroupBox() );
mCollapsedCheckBox->setEnabled( itemData.containerType() == Qgis::AttributeEditorContainerType::GroupBox );
mControlCollapsedGroupBox->setChecked( itemData.collapsedExpression().enabled() );
mControlCollapsedGroupBox->setEnabled( itemData.showAsGroupBox() );
mControlCollapsedGroupBox->setEnabled( itemData.containerType() == Qgis::AttributeEditorContainerType::GroupBox );
mCollapsedExpressionWidget->setExpression( itemData.collapsedExpression()->expression() );
mFormLabelFormatWidget->setLabelStyle( itemData.labelStyle() );
// show label makes sense for group box, not for tabs
connect( mShowAsGroupBox, &QCheckBox::stateChanged, mShowLabelCheckBox, &QCheckBox::setEnabled );
connect( mShowAsGroupBox, &QCheckBox::stateChanged, mCollapsedCheckBox, &QCheckBox::setEnabled );
connect( mShowAsGroupBox, &QCheckBox::stateChanged, mControlCollapsedGroupBox, &QCheckBox::setEnabled );
connect( mTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]
{
const Qgis::AttributeEditorContainerType type = mTypeCombo->currentData().value< Qgis::AttributeEditorContainerType >();
switch ( type )
{
case Qgis::AttributeEditorContainerType::GroupBox:
mShowLabelCheckBox->setEnabled( true );
mCollapsedCheckBox->setEnabled( true );
mControlCollapsedGroupBox->setEnabled( true );
break;
case Qgis::AttributeEditorContainerType::Tab:
mShowLabelCheckBox->setEnabled( false );
mCollapsedCheckBox->setEnabled( false );
mControlCollapsedGroupBox->setEnabled( false );
break;
}
} );
}
void QgsAttributeFormContainerEdit::registerExpressionContextGenerator( QgsExpressionContextGenerator *generator )
@ -71,7 +92,7 @@ void QgsAttributeFormContainerEdit::updateItemData()
QgsAttributesFormProperties::DnDTreeItemData itemData = mTreeItem->data( 0, QgsAttributesFormProperties::DnDTreeRole ).value<QgsAttributesFormProperties::DnDTreeItemData>();
itemData.setColumnCount( mColumnCountSpinBox->value() );
itemData.setShowAsGroupBox( mShowAsGroupBox->isEnabled() ? mShowAsGroupBox->isChecked() : false );
itemData.setContainerType( mTypeCombo->currentData().value< Qgis::AttributeEditorContainerType >() );
itemData.setName( mTitleLineEdit->text() );
itemData.setShowLabel( mShowLabelCheckBox->isChecked() );
itemData.setBackgroundColor( mBackgroundColorButton->color() );

View File

@ -15,9 +15,9 @@
#include "qgsattributewidgetedit.h"
#include "qgsattributesformproperties.h"
#include "qgsgui.h"
#include "qgsrelationwidgetregistry.h"
QgsAttributeWidgetEdit::QgsAttributeWidgetEdit( QTreeWidgetItem *item, QWidget *parent )
: QgsCollapsibleGroupBox( parent )
, mTreeItem( item )

View File

@ -16,10 +16,10 @@
* *
***************************************************************************/
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgsaddtaborgroup.h"
#include "qgssettings.h"
#include "qgshelp.h"
#include <QTreeWidgetItem>
#include <QComboBox>
@ -79,9 +79,9 @@ int QgsAddTabOrGroup::columnCount() const
return mColumnCountSpinBox->value();
}
bool QgsAddTabOrGroup::tabButtonIsChecked()
Qgis::AttributeEditorContainerType QgsAddTabOrGroup::containerType() const
{
return mTabButton->isChecked();
return mTabButton->isChecked() ? Qgis::AttributeEditorContainerType::Tab : Qgis::AttributeEditorContainerType::GroupBox;
}
void QgsAddTabOrGroup::accept()

View File

@ -25,7 +25,6 @@
#include "ui_qgsaddtaborgroupbase.h"
#include "qgsguiutils.h"
#include "qgis_gui.h"
#include "qgshelp.h"
class QTreeWidgetItem;
class QgsVectorLayer;
@ -57,8 +56,12 @@ class GUI_EXPORT QgsAddTabOrGroup : public QDialog, private Ui::QgsAddTabOrGroup
//! Returns the column count
int columnCount() const;
//! Returns whether the tab button is checked
bool tabButtonIsChecked();
/**
* Returns the container type.
*
* \since QGIS 3.32
*/
Qgis::AttributeEditorContainerType containerType() const;
//! Accepts the dialog
void accept() override;

View File

@ -1707,51 +1707,57 @@ void QgsAttributeForm::init()
if ( !containerDef )
continue;
if ( containerDef->isGroupBox() )
switch ( containerDef->type() )
{
tabWidget = nullptr;
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext );
if ( widgetInfo.labelStyle.overrideColor )
case Qgis::AttributeEditorContainerType::GroupBox:
{
if ( widgetInfo.labelStyle.color.isValid() )
tabWidget = nullptr;
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext );
if ( widgetInfo.labelStyle.overrideColor )
{
widgetInfo.widget->setStyleSheet( QStringLiteral( "QGroupBox::title { color: %1; }" ).arg( widgetInfo.labelStyle.color.name( QColor::HexArgb ) ) );
if ( widgetInfo.labelStyle.color.isValid() )
{
widgetInfo.widget->setStyleSheet( QStringLiteral( "QGroupBox::title { color: %1; }" ).arg( widgetInfo.labelStyle.color.name( QColor::HexArgb ) ) );
}
}
if ( widgetInfo.labelStyle.overrideFont )
{
widgetInfo.widget->setFont( widgetInfo.labelStyle.font );
}
layout->addWidget( widgetInfo.widget, row, column, 1, 2 );
if ( containerDef->visibilityExpression().enabled() || containerDef->collapsedExpression().enabled() )
{
registerContainerInformation( new ContainerInformation( widgetInfo.widget, containerDef->visibilityExpression().enabled() ? containerDef->visibilityExpression().data() : QgsExpression(), containerDef->collapsed(), containerDef->collapsedExpression().enabled() ? containerDef->collapsedExpression().data() : QgsExpression() ) );
}
}
if ( widgetInfo.labelStyle.overrideFont )
{
widgetInfo.widget->setFont( widgetInfo.labelStyle.font );
}
layout->addWidget( widgetInfo.widget, row, column, 1, 2 );
if ( containerDef->visibilityExpression().enabled() || containerDef->collapsedExpression().enabled() )
{
registerContainerInformation( new ContainerInformation( widgetInfo.widget, containerDef->visibilityExpression().enabled() ? containerDef->visibilityExpression().data() : QgsExpression(), containerDef->collapsed(), containerDef->collapsedExpression().enabled() ? containerDef->collapsedExpression().data() : QgsExpression() ) );
}
column += 2;
}
else
{
if ( !tabWidget )
{
tabWidget = new QgsTabWidget();
layout->addWidget( tabWidget, row, column, 1, 2 );
column += 2;
break;
}
QWidget *tabPage = new QWidget( tabWidget );
tabWidget->addTab( tabPage, widgDef->name() );
tabWidget->setTabStyle( tabWidget->tabBar()->count() - 1, widgDef->labelStyle() );
if ( containerDef->visibilityExpression().enabled() )
case Qgis::AttributeEditorContainerType::Tab:
{
registerContainerInformation( new ContainerInformation( tabWidget, tabPage, containerDef->visibilityExpression().data() ) );
}
QGridLayout *tabPageLayout = new QGridLayout();
tabPage->setLayout( tabPageLayout );
if ( !tabWidget )
{
tabWidget = new QgsTabWidget();
layout->addWidget( tabWidget, row, column, 1, 2 );
column += 2;
}
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, tabPage, mLayer, mContext );
tabPageLayout->addWidget( widgetInfo.widget );
QWidget *tabPage = new QWidget( tabWidget );
tabWidget->addTab( tabPage, widgDef->name() );
tabWidget->setTabStyle( tabWidget->tabBar()->count() - 1, widgDef->labelStyle() );
if ( containerDef->visibilityExpression().enabled() )
{
registerContainerInformation( new ContainerInformation( tabWidget, tabPage, containerDef->visibilityExpression().data() ) );
}
QGridLayout *tabPageLayout = new QGridLayout();
tabPage->setLayout( tabPageLayout );
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, tabPage, mLayer, mContext );
tabPageLayout->addWidget( widgetInfo.widget );
break;
}
}
}
else if ( widgDef->type() == Qgis::AttributeEditorType::Relation )
@ -2388,41 +2394,46 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
QString widgetName;
QWidget *myContainer = nullptr;
if ( container->isGroupBox() )
switch ( container->type() )
{
QgsCollapsibleGroupBoxBasic *groupBox = new QgsCollapsibleGroupBoxBasic();
widgetName = QStringLiteral( "QGroupBox" );
if ( container->showLabel() )
case Qgis::AttributeEditorContainerType::GroupBox:
{
groupBox->setTitle( container->name() );
if ( newWidgetInfo.labelStyle.overrideColor )
QgsCollapsibleGroupBoxBasic *groupBox = new QgsCollapsibleGroupBoxBasic();
widgetName = QStringLiteral( "QGroupBox" );
if ( container->showLabel() )
{
if ( newWidgetInfo.labelStyle.color.isValid() )
groupBox->setTitle( container->name() );
if ( newWidgetInfo.labelStyle.overrideColor )
{
groupBox->setStyleSheet( QStringLiteral( "QGroupBox::title { color: %1; }" ).arg( newWidgetInfo.labelStyle.color.name( QColor::HexArgb ) ) );
if ( newWidgetInfo.labelStyle.color.isValid() )
{
groupBox->setStyleSheet( QStringLiteral( "QGroupBox::title { color: %1; }" ).arg( newWidgetInfo.labelStyle.color.name( QColor::HexArgb ) ) );
}
}
if ( newWidgetInfo.labelStyle.overrideFont )
{
groupBox->setFont( newWidgetInfo.labelStyle.font );
}
}
if ( newWidgetInfo.labelStyle.overrideFont )
{
groupBox->setFont( newWidgetInfo.labelStyle.font );
}
myContainer = groupBox;
newWidgetInfo.widget = myContainer;
groupBox->setCollapsed( container->collapsed() );
break;
}
myContainer = groupBox;
newWidgetInfo.widget = myContainer;
groupBox->setCollapsed( container->collapsed() );
}
else
{
myContainer = new QWidget();
case Qgis::AttributeEditorContainerType::Tab:
{
myContainer = new QWidget();
QgsScrollArea *scrollArea = new QgsScrollArea( parent );
QgsScrollArea *scrollArea = new QgsScrollArea( parent );
scrollArea->setWidget( myContainer );
scrollArea->setWidgetResizable( true );
scrollArea->setFrameShape( QFrame::NoFrame );
widgetName = QStringLiteral( "QScrollArea QWidget" );
scrollArea->setWidget( myContainer );
scrollArea->setWidgetResizable( true );
scrollArea->setFrameShape( QFrame::NoFrame );
widgetName = QStringLiteral( "QScrollArea QWidget" );
newWidgetInfo.widget = scrollArea;
newWidgetInfo.widget = scrollArea;
break;
}
}
if ( container->backgroundColor().isValid() )

View File

@ -34,7 +34,10 @@
#include "qgsattributeeditorhtmlelement.h"
#include "qgssettingsregistrycore.h"
#include "qgstextwidgetwrapper.h"
#include "qgsattributeeditorrelation.h"
#include "qgsgui.h"
#include "qgseditorwidgetregistry.h"
#include "qgscodeeditorexpression.h"
QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent )
: QWidget( parent )
@ -493,7 +496,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
break;
itemData.setColumnCount( container->columnCount() );
itemData.setShowAsGroupBox( container->isGroupBox() );
itemData.setContainerType( container->type() );
itemData.setBackgroundColor( container->backgroundColor() );
itemData.setVisibilityExpression( container->visibilityExpression() );
itemData.setCollapsedExpression( container->collapsedExpression() );
@ -725,14 +728,20 @@ void QgsAttributesFormProperties::addTabOrGroupButton()
return;
const QString name = addTabOrGroup.name();
if ( addTabOrGroup.tabButtonIsChecked() )
switch ( addTabOrGroup.containerType() )
{
mFormLayoutTree->addContainer( mFormLayoutTree->invisibleRootItem(), name, addTabOrGroup.columnCount() );
}
else
{
QTreeWidgetItem *tabItem = addTabOrGroup.tab();
mFormLayoutTree->addContainer( tabItem, name, addTabOrGroup.columnCount() );
case Qgis::AttributeEditorContainerType::Tab:
{
mFormLayoutTree->addContainer( mFormLayoutTree->invisibleRootItem(), name, addTabOrGroup.columnCount(), Qgis::AttributeEditorContainerType::Tab );
break;
}
case Qgis::AttributeEditorContainerType::GroupBox:
{
QTreeWidgetItem *tabItem = addTabOrGroup.tab();
mFormLayoutTree->addContainer( tabItem, name, addTabOrGroup.columnCount(), addTabOrGroup.containerType() );
break;
}
}
}
@ -741,7 +750,6 @@ void QgsAttributesFormProperties::removeTabOrGroupButton()
qDeleteAll( mFormLayoutTree->selectedItems() );
}
QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWidget( QTreeWidgetItem *item, QgsAttributeEditorElement *parent, bool forceGroup )
{
QgsAttributeEditorElement *widgetDef = nullptr;
@ -783,7 +791,7 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
{
QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( item->text( 0 ), parent, itemData.backgroundColor() );
container->setColumnCount( itemData.columnCount() );
container->setIsGroupBox( forceGroup ? true : itemData.showAsGroupBox() );
container->setType( forceGroup ? Qgis::AttributeEditorContainerType::GroupBox : itemData.containerType() );
container->setCollapsed( itemData.collapsed() );
container->setCollapsedExpression( itemData.collapsedExpression() );
container->setVisibilityExpression( itemData.visibilityExpression() );
@ -1064,13 +1072,14 @@ QgsAttributesFormProperties::RelationEditorConfiguration::operator QVariant()
* DnDTree implementation
*/
QTreeWidgetItem *QgsAttributesDnDTree::addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount )
QTreeWidgetItem *QgsAttributesDnDTree::addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( QStringList() << title );
newItem->setBackground( 0, QBrush( Qt::lightGray ) );
newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled );
QgsAttributesFormProperties::DnDTreeItemData itemData( QgsAttributesFormProperties::DnDTreeItemData::Container, title, title );
itemData.setColumnCount( columnCount );
itemData.setContainerType( !parent ? Qgis::AttributeEditorContainerType::Tab : type );
newItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, itemData );
parent->addChild( newItem );
newItem->setExpanded( true );
@ -1733,14 +1742,14 @@ QDataStream &operator>>( QDataStream &stream, QgsAttributesFormProperties::DnDTr
return stream;
}
bool QgsAttributesFormProperties::DnDTreeItemData::showAsGroupBox() const
Qgis::AttributeEditorContainerType QgsAttributesFormProperties::DnDTreeItemData::containerType() const
{
return mShowAsGroupBox;
return mContainerType;
}
void QgsAttributesFormProperties::DnDTreeItemData::setShowAsGroupBox( bool showAsGroupBox )
void QgsAttributesFormProperties::DnDTreeItemData::setContainerType( Qgis::AttributeEditorContainerType type )
{
mShowAsGroupBox = showAsGroupBox;
mContainerType = type;
}
const QgsAttributeEditorElement::LabelStyle QgsAttributesFormProperties::DnDTreeItemData::labelStyle() const

View File

@ -36,19 +36,10 @@
#include "ui_qgsattributesformproperties.h"
#include "qgis_gui.h"
#include "qgsaddattrdialog.h"
#include "qgslogger.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsfieldcalculator.h"
#include "qgsfieldexpressionwidget.h"
#include "qgsattributesforminitcode.h"
#include "qgsgui.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgsrelationmanager.h"
#include "qgsattributeeditorrelation.h"
#include "qgsoptionalexpression.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgsattributeeditorelement.h"
#include "qgspropertycollection.h"
class QgsAttributesDnDTree;
class QgsAttributeFormContainerEdit;
@ -147,8 +138,21 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
int columnCount() const { return mColumnCount; }
void setColumnCount( int count ) { mColumnCount = count; }
bool showAsGroupBox() const;
void setShowAsGroupBox( bool showAsGroupBox );
/**
* Returns the container type.
*
* \see setContainerType()
* \since QGIS 3.32
*/
Qgis::AttributeEditorContainerType containerType() const;
/**
* Sets the container type.
*
* \see containerType()
* \since QGIS 3.32
*/
void setContainerType( Qgis::AttributeEditorContainerType type );
/**
* For group box containers returns if this group box is collapsed.
@ -257,7 +261,7 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
QString mName;
QString mDisplayName;
int mColumnCount = 1;
bool mShowAsGroupBox = false;
Qgis::AttributeEditorContainerType mContainerType = Qgis::AttributeEditorContainerType::Tab;
bool mShowLabel = true;
QgsOptionalExpression mVisibilityExpression;
RelationEditorConfiguration mRelationEditorConfiguration;
@ -394,7 +398,13 @@ class GUI_EXPORT QgsAttributesDnDTree : public QTreeWidget, private QgsExpressio
* Otherwise it is inserted at the specified \a index.
*/
QTreeWidgetItem *addItem( QTreeWidgetItem *parent, QgsAttributesFormProperties::DnDTreeItemData data, int index = -1, const QIcon &icon = QIcon() );
QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount );
/**
* Adds a new container to \a parent.
*
* If no \a parent is set then the container will be forced to a tab widget.
*/
QTreeWidgetItem *addContainer( QTreeWidgetItem *parent, const QString &title, int columnCount, Qgis::AttributeEditorContainerType type );
enum Type
{

View File

@ -35,13 +35,11 @@
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmetadatawidget.h"
#include "qgsmetadataurlitemdelegate.h"
#include "qgsnative.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerjoininfo.h"
#include "qgsvectorlayerproperties.h"
#include "qgsvectordataprovider.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgssubsetstringeditorinterface.h"
#include "qgsdatasourceuri.h"
#include "qgsrenderer.h"
@ -61,12 +59,15 @@
#include "qgsexpressioncontextutils.h"
#include "qgsmaskingwidget.h"
#include "qgsvectorlayertemporalpropertieswidget.h"
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgsprovidersourcewidget.h"
#include "qgsproviderregistry.h"
#include "qgsmaplayerstylemanager.h"
#include "qgslayertreemodel.h"
#include "qgsmaptip.h"
#include "qgsgui.h"
#include "qgsnative.h"
#include "qgssubsetstringeditorproviderregistry.h"
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgswebview.h"
#include "qgswebframe.h"
#if WITH_QTWEBKIT

View File

@ -7,28 +7,38 @@
<x>0</x>
<y>0</y>
<width>401</width>
<height>360</height>
<height>385</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mControlVisibilityGroupBox">
<item row="7" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mControlCollapsedGroupBox">
<property name="title">
<string>Control Visibility by Expression</string>
<string>Control Collapsed by Expression</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QgsFieldExpressionWidget" name="mVisibilityExpressionWidget" native="true"/>
<widget class="QgsFieldExpressionWidget" name="mCollapsedExpressionWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsSpinBox" name="mColumnCountSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mGroupBox">
<property name="title">
@ -58,18 +68,12 @@
</layout>
</widget>
</item>
<item row="10" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Type</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="mShowLabelCheckBox">
@ -85,26 +89,27 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsSpinBox" name="mColumnCountSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="mShowAsGroupBox">
<property name="text">
<string>Show as Group Box</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mTitleLineEdit"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mControlVisibilityGroupBox">
<property name="title">
<string>Control Visibility by Expression</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QgsFieldExpressionWidget" name="mVisibilityExpressionWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="mTypeCombo"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -112,28 +117,26 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="10" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="mCollapsedCheckBox">
<property name="text">
<string>Collapsed</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mControlCollapsedGroupBox">
<property name="title">
<string>Control Collapsed by Expression</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QgsFieldExpressionWidget" name="mCollapsedExpressionWidget" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@ -172,7 +175,7 @@
<tabstop>mTitleLineEdit</tabstop>
<tabstop>mColumnCountSpinBox</tabstop>
<tabstop>mControlVisibilityGroupBox</tabstop>
<tabstop>mShowAsGroupBox</tabstop>
<tabstop>mTypeCombo</tabstop>
<tabstop>mCollapsedCheckBox</tabstop>
<tabstop>mControlCollapsedGroupBox</tabstop>
<tabstop>mBackgroundColorButton</tabstop>