mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-09 00:04:30 -05:00
D&D forms show as group box collapsible
Funded by: ARPA Piemonte
This commit is contained in:
parent
667886b3b9
commit
735f1c703e
@ -52,6 +52,28 @@ Returns if this container is going to be rendered as a group box
|
|||||||
:return: ``True`` if it will be a group box, ``False`` if it will be a tab
|
:return: ``True`` if it will be a group box, ``False`` if it will be a tab
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
bool collapsed() const;
|
||||||
|
%Docstring
|
||||||
|
For containers rendedered a group box returns if this group box is collapsed.
|
||||||
|
|
||||||
|
:return: ``True`` if the group box, ``False`` otherwise.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`collapsed`
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`setCollapsed`
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
%End
|
||||||
|
void setCollapsed( bool collapsed );
|
||||||
|
%Docstring
|
||||||
|
For containers rendedered a group box sets if this group box is ``collapsed``.
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`collapsed`
|
||||||
|
|
||||||
|
.. seealso:: :py:func:`setCollapsed`
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
%End
|
||||||
QList<QgsAttributeEditorElement *> children() const;
|
QList<QgsAttributeEditorElement *> children() const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Gets a list of the children elements of this container
|
Gets a list of the children elements of this container
|
||||||
@ -112,6 +134,26 @@ show or hide this container based on an expression incorporating
|
|||||||
the field value controlled by editor widgets.
|
the field value controlled by editor widgets.
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
.. versionadded:: 3.0
|
||||||
|
%End
|
||||||
|
|
||||||
|
QgsOptionalExpression collapsedExpression() const;
|
||||||
|
%Docstring
|
||||||
|
The collapsed expression is used in the attribute form to
|
||||||
|
set the collapsed status of the group box container container based on an expression incorporating
|
||||||
|
the field value controlled by editor widgets. This property is ignored if the container is not
|
||||||
|
rendered as a group box.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
%End
|
||||||
|
|
||||||
|
void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
|
||||||
|
%Docstring
|
||||||
|
The visibility expression is used in the attribute form to
|
||||||
|
set the collapsed status of the group box of this container based on an expression incorporating
|
||||||
|
the field value controlled by editor widgets. This property is ignored if the container is not
|
||||||
|
rendered as a group box.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QColor backgroundColor() const;
|
QColor backgroundColor() const;
|
||||||
|
|||||||
@ -45,6 +45,19 @@ void QgsAttributeEditorContainer::setVisibilityExpression( const QgsOptionalExpr
|
|||||||
mVisibilityExpression = visibilityExpression;
|
mVisibilityExpression = visibilityExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsOptionalExpression QgsAttributeEditorContainer::collapsedExpression() const
|
||||||
|
{
|
||||||
|
return mCollapsedExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsAttributeEditorContainer::setCollapsedExpression( const QgsOptionalExpression &collapsedExpression )
|
||||||
|
{
|
||||||
|
if ( collapsedExpression == mCollapsedExpression )
|
||||||
|
return;
|
||||||
|
|
||||||
|
mCollapsedExpression = collapsedExpression;
|
||||||
|
}
|
||||||
|
|
||||||
QColor QgsAttributeEditorContainer::backgroundColor() const
|
QColor QgsAttributeEditorContainer::backgroundColor() const
|
||||||
{
|
{
|
||||||
return mBackgroundColor;
|
return mBackgroundColor;
|
||||||
@ -107,6 +120,7 @@ QgsAttributeEditorElement *QgsAttributeEditorContainer::clone( QgsAttributeEdito
|
|||||||
element->mIsGroupBox = mIsGroupBox;
|
element->mIsGroupBox = mIsGroupBox;
|
||||||
element->mColumnCount = mColumnCount;
|
element->mColumnCount = mColumnCount;
|
||||||
element->mVisibilityExpression = mVisibilityExpression;
|
element->mVisibilityExpression = mVisibilityExpression;
|
||||||
|
element->mCollapsed = mCollapsed;
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
@ -116,6 +130,9 @@ void QgsAttributeEditorContainer::saveConfiguration( QDomElement &elem, QDomDocu
|
|||||||
Q_UNUSED( doc )
|
Q_UNUSED( doc )
|
||||||
elem.setAttribute( QStringLiteral( "columnCount" ), mColumnCount );
|
elem.setAttribute( QStringLiteral( "columnCount" ), mColumnCount );
|
||||||
elem.setAttribute( QStringLiteral( "groupBox" ), mIsGroupBox ? 1 : 0 );
|
elem.setAttribute( QStringLiteral( "groupBox" ), mIsGroupBox ? 1 : 0 );
|
||||||
|
elem.setAttribute( QStringLiteral( "collapsed" ), mCollapsed );
|
||||||
|
elem.setAttribute( QStringLiteral( "collapsedExpressionEnabled" ), mCollapsedExpression.enabled() ? 1 : 0 );
|
||||||
|
elem.setAttribute( QStringLiteral( "collapsedExpression" ), mCollapsedExpression->expression() );
|
||||||
elem.setAttribute( QStringLiteral( "visibilityExpressionEnabled" ), mVisibilityExpression.enabled() ? 1 : 0 );
|
elem.setAttribute( QStringLiteral( "visibilityExpressionEnabled" ), mVisibilityExpression.enabled() ? 1 : 0 );
|
||||||
elem.setAttribute( QStringLiteral( "visibilityExpression" ), mVisibilityExpression->expression() );
|
elem.setAttribute( QStringLiteral( "visibilityExpression" ), mVisibilityExpression->expression() );
|
||||||
if ( mBackgroundColor.isValid() )
|
if ( mBackgroundColor.isValid() )
|
||||||
@ -143,6 +160,22 @@ void QgsAttributeEditorContainer::loadConfiguration( const QDomElement &element,
|
|||||||
else
|
else
|
||||||
setIsGroupBox( mParent );
|
setIsGroupBox( mParent );
|
||||||
|
|
||||||
|
const bool isCollapsed = element.attribute( QStringLiteral( "collapsed" ) ).toInt( &ok );
|
||||||
|
if ( ok )
|
||||||
|
setCollapsed( isCollapsed );
|
||||||
|
else
|
||||||
|
setCollapsed( false );
|
||||||
|
|
||||||
|
const bool collapsedExpressionEnabled = element.attribute( QStringLiteral( "collapsedExpressionEnabled" ) ).toInt( &ok );
|
||||||
|
QgsOptionalExpression collapsedExpression;
|
||||||
|
if ( ok )
|
||||||
|
{
|
||||||
|
collapsedExpression.setEnabled( collapsedExpressionEnabled );
|
||||||
|
collapsedExpression.setData( QgsExpression( element.attribute( QStringLiteral( "collapsedExpression" ) ) ) );
|
||||||
|
}
|
||||||
|
setCollapsedExpression( collapsedExpression );
|
||||||
|
|
||||||
|
|
||||||
const bool visibilityExpressionEnabled = element.attribute( QStringLiteral( "visibilityExpressionEnabled" ) ).toInt( &ok );
|
const bool visibilityExpressionEnabled = element.attribute( QStringLiteral( "visibilityExpressionEnabled" ) ).toInt( &ok );
|
||||||
QgsOptionalExpression visibilityExpression;
|
QgsOptionalExpression visibilityExpression;
|
||||||
if ( ok )
|
if ( ok )
|
||||||
|
|||||||
@ -66,6 +66,25 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
|
|||||||
*/
|
*/
|
||||||
virtual bool isGroupBox() const { return mIsGroupBox; }
|
virtual bool isGroupBox() const { return mIsGroupBox; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For containers rendedered a group box returns if this group box is collapsed.
|
||||||
|
*
|
||||||
|
* \returns TRUE if the group box, FALSE otherwise.
|
||||||
|
* \see collapsed()
|
||||||
|
* \see setCollapsed()
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
bool collapsed() const { return mCollapsed; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For containers rendedered a group box sets if this group box is \a collapsed.
|
||||||
|
*
|
||||||
|
* \see collapsed()
|
||||||
|
* \see setCollapsed()
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list of the children elements of this container
|
* Gets a list of the children elements of this container
|
||||||
*
|
*
|
||||||
@ -127,6 +146,26 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
|
|||||||
*/
|
*/
|
||||||
void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
|
void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The collapsed expression is used in the attribute form to
|
||||||
|
* set the collapsed status of the group box container container based on an expression incorporating
|
||||||
|
* the field value controlled by editor widgets. This property is ignored if the container is not
|
||||||
|
* rendered as a group box.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
QgsOptionalExpression collapsedExpression() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The visibility expression is used in the attribute form to
|
||||||
|
* set the collapsed status of the group box of this container based on an expression incorporating
|
||||||
|
* the field value controlled by editor widgets. This property is ignored if the container is not
|
||||||
|
* rendered as a group box.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief backgroundColor
|
* \brief backgroundColor
|
||||||
* \return background color of the container
|
* \return background color of the container
|
||||||
@ -149,6 +188,8 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
|
|||||||
int mColumnCount;
|
int mColumnCount;
|
||||||
QgsOptionalExpression mVisibilityExpression;
|
QgsOptionalExpression mVisibilityExpression;
|
||||||
QColor mBackgroundColor;
|
QColor mBackgroundColor;
|
||||||
|
bool mCollapsed = false;
|
||||||
|
QgsOptionalExpression mCollapsedExpression;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,28 +31,36 @@ QgsAttributeFormContainerEdit::QgsAttributeFormContainerEdit( QTreeWidgetItem *i
|
|||||||
{
|
{
|
||||||
// only top level items can be tabs
|
// only top level items can be tabs
|
||||||
// i.e. it's always a group box if it's a nested container
|
// i.e. it's always a group box if it's a nested container
|
||||||
mShowAsGroupBoxCheckBox->hide();
|
mShowAsGroupBox->hide();
|
||||||
mShowAsGroupBoxCheckBox->setEnabled( false );
|
mShowAsGroupBox->setEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
mTitleLineEdit->setText( itemData.name() );
|
mTitleLineEdit->setText( itemData.name() );
|
||||||
mShowLabelCheckBox->setChecked( itemData.showLabel() );
|
mShowLabelCheckBox->setChecked( itemData.showLabel() );
|
||||||
mShowLabelCheckBox->setEnabled( itemData.showAsGroupBox() ); // show label makes sense for group box, not for tabs
|
mShowLabelCheckBox->setEnabled( itemData.showAsGroupBox() ); // show label makes sense for group box, not for tabs
|
||||||
mShowAsGroupBoxCheckBox->setChecked( itemData.showAsGroupBox() );
|
mShowAsGroupBox->setChecked( itemData.showAsGroupBox() );
|
||||||
|
|
||||||
mControlVisibilityGroupBox->setChecked( itemData.visibilityExpression().enabled() );
|
mControlVisibilityGroupBox->setChecked( itemData.visibilityExpression().enabled() );
|
||||||
mVisibilityExpressionWidget->setLayer( layer );
|
mVisibilityExpressionWidget->setLayer( layer );
|
||||||
mVisibilityExpressionWidget->setExpression( itemData.visibilityExpression()->expression() );
|
mVisibilityExpressionWidget->setExpression( itemData.visibilityExpression()->expression() );
|
||||||
mColumnCountSpinBox->setValue( itemData.columnCount() );
|
mColumnCountSpinBox->setValue( itemData.columnCount() );
|
||||||
mBackgroundColorButton->setColor( itemData.backgroundColor() );
|
mBackgroundColorButton->setColor( itemData.backgroundColor() );
|
||||||
|
mCollapsedCheckBox->setChecked( itemData.collapsed() );
|
||||||
|
mCollapsedCheckBox->setEnabled( itemData.showAsGroupBox() );
|
||||||
|
mControlCollapsedGroupBox->setChecked( itemData.collapsedExpression().enabled() );
|
||||||
|
mControlCollapsedGroupBox->setEnabled( itemData.showAsGroupBox() );
|
||||||
|
mCollapsedExpressionWidget->setExpression( itemData.collapsedExpression()->expression() );
|
||||||
|
|
||||||
// show label makes sense for group box, not for tabs
|
// show label makes sense for group box, not for tabs
|
||||||
connect( mShowAsGroupBoxCheckBox, &QCheckBox::stateChanged, mShowLabelCheckBox, &QCheckBox::setEnabled );
|
connect( mShowAsGroupBox, &QCheckBox::toggled, mShowLabelCheckBox, &QCheckBox::setEnabled );
|
||||||
|
connect( mShowAsGroupBox, &QCheckBox::toggled, mCollapsedCheckBox, &QCheckBox::setEnabled );
|
||||||
|
connect( mShowAsGroupBox, &QCheckBox::toggled, mControlCollapsedGroupBox, &QCheckBox::setEnabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsAttributeFormContainerEdit::registerExpressionContextGenerator( QgsExpressionContextGenerator *generator )
|
void QgsAttributeFormContainerEdit::registerExpressionContextGenerator( QgsExpressionContextGenerator *generator )
|
||||||
{
|
{
|
||||||
mVisibilityExpressionWidget->registerExpressionContextGenerator( generator );
|
mVisibilityExpressionWidget->registerExpressionContextGenerator( generator );
|
||||||
|
mCollapsedExpressionWidget->registerExpressionContextGenerator( generator );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsAttributeFormContainerEdit::updateItemData()
|
void QgsAttributeFormContainerEdit::updateItemData()
|
||||||
@ -60,7 +68,7 @@ void QgsAttributeFormContainerEdit::updateItemData()
|
|||||||
QgsAttributesFormProperties::DnDTreeItemData itemData = mTreeItem->data( 0, QgsAttributesFormProperties::DnDTreeRole ).value<QgsAttributesFormProperties::DnDTreeItemData>();
|
QgsAttributesFormProperties::DnDTreeItemData itemData = mTreeItem->data( 0, QgsAttributesFormProperties::DnDTreeRole ).value<QgsAttributesFormProperties::DnDTreeItemData>();
|
||||||
|
|
||||||
itemData.setColumnCount( mColumnCountSpinBox->value() );
|
itemData.setColumnCount( mColumnCountSpinBox->value() );
|
||||||
itemData.setShowAsGroupBox( mShowAsGroupBoxCheckBox->isEnabled() ? mShowAsGroupBoxCheckBox->isChecked() : false );
|
itemData.setShowAsGroupBox( mShowAsGroupBox->isEnabled() ? mShowAsGroupBox->isChecked() : false );
|
||||||
itemData.setName( mTitleLineEdit->text() );
|
itemData.setName( mTitleLineEdit->text() );
|
||||||
itemData.setShowLabel( mShowLabelCheckBox->isChecked() );
|
itemData.setShowLabel( mShowLabelCheckBox->isChecked() );
|
||||||
itemData.setBackgroundColor( mBackgroundColorButton->color() );
|
itemData.setBackgroundColor( mBackgroundColorButton->color() );
|
||||||
@ -70,6 +78,12 @@ void QgsAttributeFormContainerEdit::updateItemData()
|
|||||||
visibilityExpression.setEnabled( mControlVisibilityGroupBox->isChecked() );
|
visibilityExpression.setEnabled( mControlVisibilityGroupBox->isChecked() );
|
||||||
itemData.setVisibilityExpression( visibilityExpression );
|
itemData.setVisibilityExpression( visibilityExpression );
|
||||||
|
|
||||||
|
QgsOptionalExpression collapsedExpression;
|
||||||
|
collapsedExpression.setData( QgsExpression( mCollapsedExpressionWidget->expression() ) );
|
||||||
|
collapsedExpression.setEnabled( mControlCollapsedGroupBox->isChecked() );
|
||||||
|
itemData.setCollapsedExpression( collapsedExpression );
|
||||||
|
itemData.setCollapsed( mCollapsedCheckBox->isEnabled() ? mCollapsedCheckBox->isChecked() : false );
|
||||||
|
|
||||||
mTreeItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, itemData );
|
mTreeItem->setData( 0, QgsAttributesFormProperties::DnDTreeRole, itemData );
|
||||||
mTreeItem->setText( 0, itemData.name() );
|
mTreeItem->setText( 0, itemData.name() );
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,6 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QGroupBox>
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@ -1088,7 +1087,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
|
|||||||
|
|
||||||
QgsExpressionContext context = createExpressionContext( ft );
|
QgsExpressionContext context = createExpressionContext( ft );
|
||||||
|
|
||||||
// Recheck visibility for all containers which are controlled by this value
|
// Recheck visibility/collapsed state for all containers which are controlled by this value
|
||||||
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
|
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
|
||||||
for ( ContainerInformation *info : infos )
|
for ( ContainerInformation *info : infos )
|
||||||
{
|
{
|
||||||
@ -1101,7 +1100,7 @@ void QgsAttributeForm::updateContainersVisibility()
|
|||||||
{
|
{
|
||||||
QgsExpressionContext context = createExpressionContext( mFeature );
|
QgsExpressionContext context = createExpressionContext( mFeature );
|
||||||
|
|
||||||
const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;
|
const QVector<ContainerInformation *> infos = mContainerVisibilityCollapsedInformation;
|
||||||
|
|
||||||
for ( ContainerInformation *info : infos )
|
for ( ContainerInformation *info : infos )
|
||||||
{
|
{
|
||||||
@ -1224,9 +1223,9 @@ bool QgsAttributeForm::currentFormValuesFeature( QgsFeature &feature )
|
|||||||
|
|
||||||
void QgsAttributeForm::registerContainerInformation( QgsAttributeForm::ContainerInformation *info )
|
void QgsAttributeForm::registerContainerInformation( QgsAttributeForm::ContainerInformation *info )
|
||||||
{
|
{
|
||||||
mContainerVisibilityInformation.append( info );
|
mContainerVisibilityCollapsedInformation.append( info );
|
||||||
|
|
||||||
const QSet<QString> referencedColumns = info->expression.referencedColumns();
|
const QSet<QString> referencedColumns = info->expression.referencedColumns().unite( info->collapsedExpression.referencedColumns() );
|
||||||
|
|
||||||
for ( const QString &col : referencedColumns )
|
for ( const QString &col : referencedColumns )
|
||||||
{
|
{
|
||||||
@ -1611,9 +1610,9 @@ void QgsAttributeForm::init()
|
|||||||
tabWidget = nullptr;
|
tabWidget = nullptr;
|
||||||
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext );
|
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext );
|
||||||
layout->addWidget( widgetInfo.widget, row, column, 1, 2 );
|
layout->addWidget( widgetInfo.widget, row, column, 1, 2 );
|
||||||
if ( containerDef->visibilityExpression().enabled() )
|
if ( containerDef->visibilityExpression().enabled() || containerDef->collapsedExpression().enabled() )
|
||||||
{
|
{
|
||||||
registerContainerInformation( new ContainerInformation( widgetInfo.widget, containerDef->visibilityExpression().data() ) );
|
registerContainerInformation( new ContainerInformation( widgetInfo.widget, containerDef->visibilityExpression().enabled() ? containerDef->visibilityExpression().data() : QgsExpression(), containerDef->collapsed(), containerDef->collapsedExpression().enabled() ? containerDef->collapsedExpression().data() : QgsExpression() ) );
|
||||||
}
|
}
|
||||||
column += 2;
|
column += 2;
|
||||||
}
|
}
|
||||||
@ -2232,12 +2231,13 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
|
|||||||
QWidget *myContainer = nullptr;
|
QWidget *myContainer = nullptr;
|
||||||
if ( container->isGroupBox() )
|
if ( container->isGroupBox() )
|
||||||
{
|
{
|
||||||
QGroupBox *groupBox = new QGroupBox( parent );
|
QgsCollapsibleGroupBoxBasic *groupBox = new QgsCollapsibleGroupBoxBasic();
|
||||||
widgetName = QStringLiteral( "QGroupBox" );
|
widgetName = QStringLiteral( "QGroupBox" );
|
||||||
if ( container->showLabel() )
|
if ( container->showLabel() )
|
||||||
groupBox->setTitle( container->name() );
|
groupBox->setTitle( container->name() );
|
||||||
myContainer = groupBox;
|
myContainer = groupBox;
|
||||||
newWidgetInfo.widget = myContainer;
|
newWidgetInfo.widget = myContainer;
|
||||||
|
groupBox->setCollapsed( container->collapsed() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2274,9 +2274,9 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
|
|||||||
if ( childDef->type() == QgsAttributeEditorElement::AeTypeContainer )
|
if ( childDef->type() == QgsAttributeEditorElement::AeTypeContainer )
|
||||||
{
|
{
|
||||||
QgsAttributeEditorContainer *containerDef = static_cast<QgsAttributeEditorContainer *>( childDef );
|
QgsAttributeEditorContainer *containerDef = static_cast<QgsAttributeEditorContainer *>( childDef );
|
||||||
if ( containerDef->visibilityExpression().enabled() )
|
if ( containerDef->visibilityExpression().enabled() || containerDef->collapsedExpression().enabled() )
|
||||||
{
|
{
|
||||||
registerContainerInformation( new ContainerInformation( widgetInfo.widget, containerDef->visibilityExpression().data() ) );
|
registerContainerInformation( new ContainerInformation( widgetInfo.widget, containerDef->visibilityExpression().enabled() ? containerDef->visibilityExpression().data() : QgsExpression(), containerDef->collapsed(), containerDef->collapsedExpression().enabled() ? containerDef->collapsedExpression().data() : QgsExpression() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2679,9 +2679,10 @@ void QgsAttributeForm::setExtraContextScope( QgsExpressionContextScope *extraSco
|
|||||||
|
|
||||||
void QgsAttributeForm::ContainerInformation::apply( QgsExpressionContext *expressionContext )
|
void QgsAttributeForm::ContainerInformation::apply( QgsExpressionContext *expressionContext )
|
||||||
{
|
{
|
||||||
bool newVisibility = expression.evaluate( expressionContext ).toBool();
|
|
||||||
|
|
||||||
if ( newVisibility != isVisible )
|
const bool newVisibility = expression.evaluate( expressionContext ).toBool();
|
||||||
|
|
||||||
|
if ( expression.isValid() && ! expression.hasEvalError() && newVisibility != isVisible )
|
||||||
{
|
{
|
||||||
if ( tabWidget )
|
if ( tabWidget )
|
||||||
{
|
{
|
||||||
@ -2694,6 +2695,19 @@ void QgsAttributeForm::ContainerInformation::apply( QgsExpressionContext *expres
|
|||||||
|
|
||||||
isVisible = newVisibility;
|
isVisible = newVisibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool newCollapsedState = collapsedExpression.evaluate( expressionContext ).toBool();
|
||||||
|
|
||||||
|
if ( collapsedExpression.isValid() && ! collapsedExpression.hasEvalError() && newCollapsedState != isCollapsed )
|
||||||
|
{
|
||||||
|
|
||||||
|
QgsCollapsibleGroupBoxBasic *collapsibleGroupBox { qobject_cast<QgsCollapsibleGroupBoxBasic *>( widget ) };
|
||||||
|
if ( collapsibleGroupBox )
|
||||||
|
{
|
||||||
|
collapsibleGroupBox->setCollapsed( newCollapsedState );
|
||||||
|
isCollapsed = newCollapsedState;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
|
void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
|
||||||
|
|||||||
@ -488,10 +488,21 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
, isVisible( true )
|
, isVisible( true )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
ContainerInformation( QWidget *widget, const QgsExpression &visibilityExpression, bool collapsed, const QgsExpression &collapsedExpression )
|
||||||
|
: widget( widget )
|
||||||
|
, expression( visibilityExpression )
|
||||||
|
, isVisible( true )
|
||||||
|
, isCollapsed( collapsed )
|
||||||
|
, collapsedExpression( collapsedExpression )
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
QgsTabWidget *tabWidget = nullptr;
|
QgsTabWidget *tabWidget = nullptr;
|
||||||
QWidget *widget = nullptr;
|
QWidget *widget = nullptr;
|
||||||
QgsExpression expression;
|
QgsExpression expression;
|
||||||
bool isVisible;
|
bool isVisible;
|
||||||
|
bool isCollapsed = false;
|
||||||
|
QgsExpression collapsedExpression;
|
||||||
|
|
||||||
void apply( QgsExpressionContext *expressionContext );
|
void apply( QgsExpressionContext *expressionContext );
|
||||||
};
|
};
|
||||||
@ -502,8 +513,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
|
|
||||||
void reloadIcon( const QString &file, const QString &tooltip, QSvgWidget *sw );
|
void reloadIcon( const QString &file, const QString &tooltip, QSvgWidget *sw );
|
||||||
|
|
||||||
// Contains information about tabs and groupboxes, their visibility state visibility conditions
|
// Contains information about tabs and groupboxes, their visibility/collapsed state conditions
|
||||||
QVector<ContainerInformation *> mContainerVisibilityInformation;
|
QVector<ContainerInformation *> mContainerVisibilityCollapsedInformation;
|
||||||
QMap<QString, QVector<ContainerInformation *> > mContainerInformationDependency;
|
QMap<QString, QVector<ContainerInformation *> > mContainerInformationDependency;
|
||||||
|
|
||||||
// Variables below are used for Python
|
// Variables below are used for Python
|
||||||
|
|||||||
@ -479,6 +479,8 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
|
|||||||
itemData.setShowAsGroupBox( container->isGroupBox() );
|
itemData.setShowAsGroupBox( container->isGroupBox() );
|
||||||
itemData.setBackgroundColor( container->backgroundColor() );
|
itemData.setBackgroundColor( container->backgroundColor() );
|
||||||
itemData.setVisibilityExpression( container->visibilityExpression() );
|
itemData.setVisibilityExpression( container->visibilityExpression() );
|
||||||
|
itemData.setCollapsedExpression( container->collapsedExpression() );
|
||||||
|
itemData.setCollapsed( container->collapsed() );
|
||||||
newWidget = tree->addItem( parent, itemData );
|
newWidget = tree->addItem( parent, itemData );
|
||||||
|
|
||||||
const QList<QgsAttributeEditorElement *> children = container->children();
|
const QList<QgsAttributeEditorElement *> children = container->children();
|
||||||
@ -733,6 +735,8 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
|
|||||||
QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( item->text( 0 ), parent, itemData.backgroundColor() );
|
QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( item->text( 0 ), parent, itemData.backgroundColor() );
|
||||||
container->setColumnCount( itemData.columnCount() );
|
container->setColumnCount( itemData.columnCount() );
|
||||||
container->setIsGroupBox( forceGroup ? true : itemData.showAsGroupBox() );
|
container->setIsGroupBox( forceGroup ? true : itemData.showAsGroupBox() );
|
||||||
|
container->setCollapsed( itemData.collapsed() );
|
||||||
|
container->setCollapsedExpression( itemData.collapsedExpression() );
|
||||||
container->setVisibilityExpression( itemData.visibilityExpression() );
|
container->setVisibilityExpression( itemData.visibilityExpression() );
|
||||||
container->setBackgroundColor( itemData.backgroundColor( ) );
|
container->setBackgroundColor( itemData.backgroundColor( ) );
|
||||||
|
|
||||||
@ -1542,6 +1546,16 @@ void QgsAttributesFormProperties::DnDTreeItemData::setVisibilityExpression( cons
|
|||||||
mVisibilityExpression = visibilityExpression;
|
mVisibilityExpression = visibilityExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsOptionalExpression QgsAttributesFormProperties::DnDTreeItemData::collapsedExpression() const
|
||||||
|
{
|
||||||
|
return mCollapsedExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsAttributesFormProperties::DnDTreeItemData::setCollapsedExpression( const QgsOptionalExpression &collapsedExpression )
|
||||||
|
{
|
||||||
|
mCollapsedExpression = collapsedExpression;
|
||||||
|
}
|
||||||
|
|
||||||
QgsAttributesFormProperties::RelationEditorConfiguration QgsAttributesFormProperties::DnDTreeItemData::relationEditorConfiguration() const
|
QgsAttributesFormProperties::RelationEditorConfiguration QgsAttributesFormProperties::DnDTreeItemData::relationEditorConfiguration() const
|
||||||
{
|
{
|
||||||
return mRelationEditorConfiguration;
|
return mRelationEditorConfiguration;
|
||||||
|
|||||||
@ -137,11 +137,33 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
|
|||||||
bool showAsGroupBox() const;
|
bool showAsGroupBox() const;
|
||||||
void setShowAsGroupBox( bool showAsGroupBox );
|
void setShowAsGroupBox( bool showAsGroupBox );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For containers rendedered a group box returns if this group box is collapsed.
|
||||||
|
*
|
||||||
|
* \returns TRUE if the group box, FALSE otherwise.
|
||||||
|
* \see collapsed()
|
||||||
|
* \see setCollapsed()
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
bool collapsed() const { return mCollapsed; };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For containers rendedered a group box sets if this group box is \a collapsed.
|
||||||
|
*
|
||||||
|
* \see collapsed()
|
||||||
|
* \see setCollapsed()
|
||||||
|
* \since QGIS 3.26
|
||||||
|
*/
|
||||||
|
void setCollapsed( bool collapsed ) { mCollapsed = collapsed; };
|
||||||
|
|
||||||
bool showLabel() const;
|
bool showLabel() const;
|
||||||
void setShowLabel( bool showLabel );
|
void setShowLabel( bool showLabel );
|
||||||
|
|
||||||
QgsOptionalExpression visibilityExpression() const;
|
QgsOptionalExpression visibilityExpression() const;
|
||||||
void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
|
void setVisibilityExpression( const QgsOptionalExpression &collapsedExpression );
|
||||||
|
|
||||||
|
QgsOptionalExpression collapsedExpression() const;
|
||||||
|
void setCollapsedExpression( const QgsOptionalExpression &collapsedExpression );
|
||||||
|
|
||||||
RelationEditorConfiguration relationEditorConfiguration() const;
|
RelationEditorConfiguration relationEditorConfiguration() const;
|
||||||
void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
|
void setRelationEditorConfiguration( RelationEditorConfiguration relationEditorConfiguration );
|
||||||
@ -167,6 +189,8 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
|
|||||||
QmlElementEditorConfiguration mQmlElementEditorConfiguration;
|
QmlElementEditorConfiguration mQmlElementEditorConfiguration;
|
||||||
HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
|
HtmlElementEditorConfiguration mHtmlElementEditorConfiguration;
|
||||||
QColor mBackgroundColor;
|
QColor mBackgroundColor;
|
||||||
|
bool mCollapsed = false;
|
||||||
|
QgsOptionalExpression mCollapsedExpression;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,48 +7,14 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>401</width>
|
<width>401</width>
|
||||||
<height>303</height>
|
<height>320</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string notr="true">Form</string>
|
<string notr="true">Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="3" column="0">
|
<item row="4" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>Columns</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="mShowLabelCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Show label</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Title</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" 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="4" column="0" colspan="3">
|
|
||||||
<widget class="QgsCollapsibleGroupBox" name="mControlVisibilityGroupBox">
|
<widget class="QgsCollapsibleGroupBox" name="mControlVisibilityGroupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Control Visibility by Expression</string>
|
<string>Control Visibility by Expression</string>
|
||||||
@ -63,27 +29,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="9" column="0" colspan="2">
|
||||||
<widget class="QgsSpinBox" name="mColumnCountSpinBox">
|
|
||||||
<property name="minimum">
|
|
||||||
<number>1</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>10</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QLineEdit" name="mTitleLineEdit"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="mShowAsGroupBoxCheckBox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Show as group box</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" colspan="2">
|
|
||||||
<widget class="QgsCollapsibleGroupBox" name="mGroupBox">
|
<widget class="QgsCollapsibleGroupBox" name="mGroupBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Style</string>
|
<string>Style</string>
|
||||||
@ -102,20 +48,96 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<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="0" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="mShowLabelCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show label</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Columns</string>
|
||||||
|
</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="2" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Title</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>QgsSpinBox</class>
|
||||||
|
<extends>QSpinBox</extends>
|
||||||
|
<header>qgsspinbox.h</header>
|
||||||
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QgsCollapsibleGroupBox</class>
|
<class>QgsCollapsibleGroupBox</class>
|
||||||
<extends>QGroupBox</extends>
|
<extends>QGroupBox</extends>
|
||||||
<header>qgscollapsiblegroupbox.h</header>
|
<header>qgscollapsiblegroupbox.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
|
||||||
<class>QgsSpinBox</class>
|
|
||||||
<extends>QSpinBox</extends>
|
|
||||||
<header>qgsspinbox.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QgsFieldExpressionWidget</class>
|
<class>QgsFieldExpressionWidget</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
@ -131,10 +153,8 @@
|
|||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>mShowLabelCheckBox</tabstop>
|
<tabstop>mShowLabelCheckBox</tabstop>
|
||||||
<tabstop>mShowAsGroupBoxCheckBox</tabstop>
|
|
||||||
<tabstop>mTitleLineEdit</tabstop>
|
<tabstop>mTitleLineEdit</tabstop>
|
||||||
<tabstop>mColumnCountSpinBox</tabstop>
|
<tabstop>mColumnCountSpinBox</tabstop>
|
||||||
<tabstop>mControlVisibilityGroupBox</tabstop>
|
|
||||||
<tabstop>mBackgroundColorButton</tabstop>
|
<tabstop>mBackgroundColorButton</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user