Skip to content

Commit 7697d79

Browse files
authored
Merge pull request #3227 from m-kuhn/FixToplevelGroupBoxes
Fix groupboxes on toplevel in drag and drop designer
2 parents 3c06341 + eaff966 commit 7697d79

6 files changed

+59
-19
lines changed

src/app/qgsfieldsproperties.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
177177
break;
178178

179179
itemData.setColumnCount( container->columnCount() );
180+
itemData.setShowAsGroupBox( container->isGroupBox() );
180181
newWidget = mDesignerTree->addItem( parent, itemData );
181182

182183
Q_FOREACH ( QgsAttributeEditorElement* wdg, container->children() )
@@ -862,7 +863,7 @@ void QgsFieldsProperties::updateFieldRenamingStatus()
862863
}
863864
}
864865

865-
QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent )
866+
QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent , bool forceGroup )
866867
{
867868
QgsAttributeEditorElement *widgetDef = nullptr;
868869

@@ -887,6 +888,7 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
887888
{
888889
QgsAttributeEditorContainer* container = new QgsAttributeEditorContainer( item->text( 0 ), parent );
889890
container->setColumnCount( itemData.columnCount() );
891+
container->setIsGroupBox( forceGroup ? true : itemData.showAsGroupBox() );
890892

891893
for ( int t = 0; t < item->childCount(); t++ )
892894
{
@@ -985,7 +987,7 @@ void QgsFieldsProperties::apply()
985987
{
986988
QTreeWidgetItem* tabItem = mDesignerTree->invisibleRootItem()->child( t );
987989

988-
mLayer->editFormConfig()->addTab( createAttributeEditorWidget( tabItem, mLayer ) );
990+
mLayer->editFormConfig()->addTab( createAttributeEditorWidget( tabItem, mLayer, false ) );
989991
}
990992

991993
mLayer->editFormConfig()->setLayout(( QgsEditFormConfig::EditorLayout ) mEditorLayoutComboBox->currentIndex() );
@@ -1273,6 +1275,7 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
12731275
QFormLayout* layout = new QFormLayout() ;
12741276
dlg.setLayout( layout );
12751277

1278+
QCheckBox* showAsGroupBox = nullptr;
12761279
QLineEdit* title = new QLineEdit( itemData.name() );
12771280
QSpinBox* columnCount = new QSpinBox();
12781281
columnCount->setRange( 1, 5 );
@@ -1281,6 +1284,13 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
12811284
layout->addRow( tr( "Title" ), title );
12821285
layout->addRow( tr( "Column count" ), columnCount );
12831286

1287+
if ( !item->parent() )
1288+
{
1289+
showAsGroupBox = new QCheckBox( tr( "Show as group box" ) );
1290+
showAsGroupBox->setChecked( itemData.showAsGroupBox() );
1291+
layout->addRow( tr( "Show as group box" ), showAsGroupBox );
1292+
}
1293+
12841294
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok
12851295
| QDialogButtonBox::Cancel );
12861296

@@ -1292,6 +1302,7 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
12921302
if ( dlg.exec() )
12931303
{
12941304
itemData.setColumnCount( columnCount->value() );
1305+
itemData.setShowAsGroupBox( showAsGroupBox ? showAsGroupBox->isChecked() : true );
12951306
itemData.setName( title->text() );
12961307
item->setData( 0, QgsFieldsProperties::DesignerTreeRole, itemData.asQVariant() );
12971308
item->setText( 0, title->text() );
@@ -1321,3 +1332,13 @@ QDataStream& operator>>( QDataStream& stream, QgsFieldsProperties::DesignerTreeI
13211332

13221333
return stream;
13231334
}
1335+
1336+
bool QgsFieldsProperties::DesignerTreeItemData::showAsGroupBox() const
1337+
{
1338+
return mShowAsGroupBox;
1339+
}
1340+
1341+
void QgsFieldsProperties::DesignerTreeItemData::setShowAsGroupBox( bool showAsGroupBox )
1342+
{
1343+
mShowAsGroupBox = showAsGroupBox;
1344+
}

src/app/qgsfieldsproperties.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
7474
int columnCount() const { return mColumnCount; }
7575
void setColumnCount( int count ) { mColumnCount = count; }
7676

77+
bool showAsGroupBox() const;
78+
void setShowAsGroupBox( bool showAsGroupBox );
79+
7780
private:
7881
Type mType;
7982
QString mName;
8083
int mColumnCount;
84+
bool mShowAsGroupBox;
8185
};
8286

8387
/**
@@ -111,10 +115,9 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
111115
bool addAttribute( const QgsField &field );
112116

113117
/** Creates the a proper item to save from the tree
114-
* @param item The tree widget item to process
115118
* @return A widget definition. Containing another container or the final field
116119
*/
117-
QgsAttributeEditorElement* createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent );
120+
QgsAttributeEditorElement* createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent, bool forceGroup = true );
118121

119122
void init();
120123
void apply();

src/core/qgseditformconfig.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
421421
cc = 0;
422422
container->setColumnCount( cc );
423423

424+
bool isGroupBox = elem.attribute( "groupBox" ).toInt( &ok );
425+
if ( ok )
426+
container->setIsGroupBox( isGroupBox );
427+
else
428+
container->setIsGroupBox( qobject_cast<QgsAttributeEditorContainer*>( parent ) );
429+
424430
QDomNodeList childNodeList = elem.childNodes();
425431

426432
for ( int i = 0; i < childNodeList.size(); i++ )

src/core/qgseditformconfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class CORE_EXPORT QgsEditFormConfig : public QObject
349349
/**
350350
* This is only useful in combination with EditorLayout::TabLayout.
351351
*
352-
* Adds a new tab to the layout. Should be a QgsAttributeEditorContainer.
352+
* Adds a new element to the layout.
353353
*/
354354
void addTab( QgsAttributeEditorElement* data ) { mAttributeEditorElements.append( data ); }
355355

src/core/qgsvectorlayer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4058,6 +4058,7 @@ QDomElement QgsAttributeEditorContainer::toDomElement( QDomDocument& doc ) const
40584058
QDomElement elem = doc.createElement( "attributeEditorContainer" );
40594059
elem.setAttribute( "name", mName );
40604060
elem.setAttribute( "columnCount", mColumnCount );
4061+
elem.setAttribute( "groupBox", mIsGroupBox ? 1 : 0 );
40614062

40624063
Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
40634064
{

src/gui/qgsattributeform.cpp

+23-14
Original file line numberDiff line numberDiff line change
@@ -1100,26 +1100,35 @@ void QgsAttributeForm::init()
11001100
{
11011101
if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
11021102
{
1103-
if ( !tabWidget )
1103+
QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
1104+
if ( !containerDef )
1105+
continue;
1106+
1107+
if ( containerDef->isGroupBox() )
11041108
{
1105-
tabWidget = new QTabWidget();
1106-
layout->addWidget( tabWidget, row, column, 1, 2 );
1109+
tabWidget = nullptr;
1110+
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext );
1111+
layout->addWidget( widgetInfo.widget, row, column, 1, 2 );
11071112
column += 2;
11081113
}
1114+
else
1115+
{
1116+
if ( !tabWidget )
1117+
{
1118+
tabWidget = new QTabWidget();
1119+
layout->addWidget( tabWidget, row, column, 1, 2 );
1120+
column += 2;
1121+
}
11091122

1110-
QWidget* tabPage = new QWidget( tabWidget );
1111-
1112-
tabWidget->addTab( tabPage, widgDef->name() );
1113-
QGridLayout* tabPageLayout = new QGridLayout();
1114-
tabPage->setLayout( tabPageLayout );
1123+
QWidget* tabPage = new QWidget( tabWidget );
11151124

1116-
QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
1117-
if ( !containerDef )
1118-
continue;
1125+
tabWidget->addTab( tabPage, widgDef->name() );
1126+
QGridLayout* tabPageLayout = new QGridLayout();
1127+
tabPage->setLayout( tabPageLayout );
11191128

1120-
containerDef->setIsGroupBox( false ); // Toplevel widgets are tabs not groupboxes
1121-
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, tabPage, mLayer, mContext );
1122-
tabPageLayout->addWidget( widgetInfo.widget );
1129+
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, tabPage, mLayer, mContext );
1130+
tabPageLayout->addWidget( widgetInfo.widget );
1131+
}
11231132
}
11241133
else
11251134
{

0 commit comments

Comments
 (0)