Skip to content

Commit a6294cf

Browse files
committed
Add support for toplevel widgets in drag and drop designer
1 parent 7abd691 commit a6294cf

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

src/app/qgsfieldsproperties.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -1157,13 +1157,6 @@ void DesignerTree::dragMoveEvent( QDragMoveEvent *event )
11571157
QDataStream stream( &itemData, QIODevice::ReadOnly );
11581158
stream >> itemElement;
11591159

1160-
// Forbid dropping fields on root item
1161-
if ( itemElement.type() == QgsFieldsProperties::DesignerTreeItemData::Field && !targetItem )
1162-
{
1163-
event->ignore();
1164-
return;
1165-
}
1166-
11671160
// Inner drag and drop actions are always MoveAction
11681161
if ( event->source() == this )
11691162
{
@@ -1203,10 +1196,10 @@ bool DesignerTree::dropMimeData( QTreeWidgetItem* parent, int index, const QMime
12031196
addItem( parent, itemElement );
12041197
bDropSuccessful = true;
12051198
}
1206-
else // Should never happen as we ignore drops of fields onto the root element in dragMoveEvent, but actually does happen. Qt?
1199+
else
12071200
{
1208-
// addItem( invisibleRootItem(), itemName );
1209-
// bDropSuccessful = true;
1201+
addItem( invisibleRootItem(), itemElement );
1202+
bDropSuccessful = true;
12101203
}
12111204
}
12121205
}

src/gui/qgsattributeform.cpp

+49-11
Original file line numberDiff line numberDiff line change
@@ -1059,22 +1059,31 @@ void QgsAttributeForm::init()
10591059
}
10601060
}
10611061

1062+
QTabWidget* tabWidget = nullptr;
1063+
10621064
// Tab layout
10631065
if ( !formWidget && mLayer->editFormConfig()->layout() == QgsEditFormConfig::TabLayout )
10641066
{
1065-
QTabWidget* tabWidget = new QTabWidget();
1066-
layout->addWidget( tabWidget );
1067+
int row = 0;
1068+
int column = 0;
1069+
int columnCount = 1;
10671070

10681071
Q_FOREACH ( QgsAttributeEditorElement* widgDef, mLayer->editFormConfig()->tabs() )
10691072
{
1070-
QWidget* tabPage = new QWidget( tabWidget );
1071-
1072-
tabWidget->addTab( tabPage, widgDef->name() );
1073-
QGridLayout* tabPageLayout = new QGridLayout();
1074-
tabPage->setLayout( tabPageLayout );
1075-
10761073
if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
10771074
{
1075+
if ( !tabWidget )
1076+
{
1077+
tabWidget = new QTabWidget();
1078+
layout->addWidget( tabWidget, row, column, 1, 2 );
1079+
}
1080+
1081+
QWidget* tabPage = new QWidget( tabWidget );
1082+
1083+
tabWidget->addTab( tabPage, widgDef->name() );
1084+
QGridLayout* tabPageLayout = new QGridLayout();
1085+
tabPage->setLayout( tabPageLayout );
1086+
10781087
QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
10791088
if ( !containerDef )
10801089
continue;
@@ -1085,10 +1094,39 @@ void QgsAttributeForm::init()
10851094
}
10861095
else
10871096
{
1088-
QgsDebugMsg( "No support for fields in attribute editor on top level" );
1097+
tabWidget = nullptr;
1098+
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, container, mLayer, mContext );
1099+
QLabel* label = new QLabel( widgetInfo.labelText );
1100+
if ( columnCount > 1 && !widgetInfo.labelOnTop )
1101+
{
1102+
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
1103+
}
1104+
1105+
label->setBuddy( widgetInfo.widget );
1106+
1107+
if ( widgetInfo.labelOnTop )
1108+
{
1109+
QVBoxLayout* c = new QVBoxLayout();
1110+
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
1111+
c->layout()->addWidget( label );
1112+
c->layout()->addWidget( widgetInfo.widget );
1113+
layout->addLayout( c, row, column, 1, 2 );
1114+
column += 2;
1115+
}
1116+
else
1117+
{
1118+
layout->addWidget( label, row, column++ );
1119+
layout->addWidget( widgetInfo.widget, row, column++ );
1120+
}
1121+
}
1122+
1123+
if ( column >= columnCount * 2 )
1124+
{
1125+
column = 0;
1126+
row += 1;
10891127
}
10901128
}
1091-
formWidget = tabWidget;
1129+
formWidget = container;
10921130
}
10931131

10941132
// Autogenerate Layout
@@ -1188,7 +1226,7 @@ void QgsAttributeForm::init()
11881226
{
11891227
mButtonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
11901228
mButtonBox->setObjectName( "buttonBox" );
1191-
layout->addWidget( mButtonBox );
1229+
layout->addWidget( mButtonBox, layout->rowCount(), 0, 1, layout->columnCount() );
11921230
}
11931231
mButtonBox->setVisible( buttonBoxVisible );
11941232

0 commit comments

Comments
 (0)