Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow creation of attribute form group boxes and rows which
aren't contained within tabs

This was always supported by the form, but blocked in the form
editor. It stems from a subtle twist in the original logic of
"tab containers can ONLY be top level items" which was misinterpreted
sometime as "top level items can ONLY be tabs".

Restore the original constraint that tabs can only be top
level items and allow also top level group boxes and rows
  • Loading branch information
nyalldawson committed May 2, 2023
1 parent 35f60e2 commit d404747
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
11 changes: 4 additions & 7 deletions src/gui/qgsaddtaborgroup.cpp
Expand Up @@ -38,7 +38,7 @@ QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVecto

mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) ) );

mParentCombo->setEnabled( false );
mParentCombo->addItem( QString() );
if ( !mExistingContainers.isEmpty() )
{
int i = 0;
Expand All @@ -53,12 +53,6 @@ QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVecto
++i;
}
}
else
{
// top level items must be tabs
mTypeCombo->removeItem( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) ) );
mTypeCombo->removeItem( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Row ) ) );
}

connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddAttributeFormContainerDialog::showHelp );

Expand All @@ -80,6 +74,9 @@ QTreeWidgetItem *QgsAddAttributeFormContainerDialog::parentContainerItem()
if ( containerType() == Qgis::AttributeEditorContainerType::Tab )
return nullptr;

if ( !mParentCombo->currentData().isValid() )
return nullptr;

const ContainerPair tab = mExistingContainers.at( mParentCombo->currentData().toInt() );
return tab.second;
}
Expand Down
30 changes: 13 additions & 17 deletions src/gui/vector/qgsattributesformproperties.cpp
Expand Up @@ -731,22 +731,11 @@ void QgsAttributesFormProperties::addContainer()
return;

const QString name = dialog.name();
switch ( dialog.containerType() )
{
case Qgis::AttributeEditorContainerType::Tab:
{
mFormLayoutTree->addContainer( mFormLayoutTree->invisibleRootItem(), name, dialog.columnCount(), Qgis::AttributeEditorContainerType::Tab );
break;
}

case Qgis::AttributeEditorContainerType::GroupBox:
case Qgis::AttributeEditorContainerType::Row:
{
QTreeWidgetItem *parentContainerItem = dialog.parentContainerItem();
mFormLayoutTree->addContainer( parentContainerItem, name, dialog.columnCount(), dialog.containerType() );
break;
}
}
QTreeWidgetItem *parentContainerItem = dialog.parentContainerItem();
mFormLayoutTree->addContainer( parentContainerItem ? parentContainerItem : mFormLayoutTree->invisibleRootItem(),
name,
dialog.columnCount(),
dialog.containerType() );
}

void QgsAttributesFormProperties::removeTabOrGroupButton()
Expand Down Expand Up @@ -795,7 +784,14 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
{
QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( item->text( 0 ), parent, itemData.backgroundColor() );
container->setColumnCount( itemData.columnCount() );
container->setType( isTopLevel ? Qgis::AttributeEditorContainerType::Tab : itemData.containerType() );
// only top-level containers can be tabs
Qgis::AttributeEditorContainerType type = itemData.containerType();
if ( type == Qgis::AttributeEditorContainerType::Tab && !isTopLevel )
{
// a top container found which isn't at the top level -- reset it to a group box instead
type = Qgis::AttributeEditorContainerType::GroupBox;
}
container->setType( type );
container->setCollapsed( itemData.collapsed() );
container->setCollapsedExpression( itemData.collapsedExpression() );
container->setVisibilityExpression( itemData.visibilityExpression() );
Expand Down

0 comments on commit d404747

Please sign in to comment.