Skip to content
Permalink
Browse files

Add support for toplevel widgets in drag and drop designer

  • Loading branch information
m-kuhn committed Jun 3, 2016
1 parent 7abd691 commit a6294cfe51224edb118f9b3a52594a26b3a6bcd0
Showing with 52 additions and 21 deletions.
  1. +3 −10 src/app/qgsfieldsproperties.cpp
  2. +49 −11 src/gui/qgsattributeform.cpp
@@ -1157,13 +1157,6 @@ void DesignerTree::dragMoveEvent( QDragMoveEvent *event )
QDataStream stream( &itemData, QIODevice::ReadOnly );
stream >> itemElement;

// Forbid dropping fields on root item
if ( itemElement.type() == QgsFieldsProperties::DesignerTreeItemData::Field && !targetItem )
{
event->ignore();
return;
}

// Inner drag and drop actions are always MoveAction
if ( event->source() == this )
{
@@ -1203,10 +1196,10 @@ bool DesignerTree::dropMimeData( QTreeWidgetItem* parent, int index, const QMime
addItem( parent, itemElement );
bDropSuccessful = true;
}
else // Should never happen as we ignore drops of fields onto the root element in dragMoveEvent, but actually does happen. Qt?
else
{
// addItem( invisibleRootItem(), itemName );
// bDropSuccessful = true;
addItem( invisibleRootItem(), itemElement );
bDropSuccessful = true;
}
}
}
@@ -1059,22 +1059,31 @@ void QgsAttributeForm::init()
}
}

QTabWidget* tabWidget = nullptr;

// Tab layout
if ( !formWidget && mLayer->editFormConfig()->layout() == QgsEditFormConfig::TabLayout )
{
QTabWidget* tabWidget = new QTabWidget();
layout->addWidget( tabWidget );
int row = 0;
int column = 0;
int columnCount = 1;

Q_FOREACH ( QgsAttributeEditorElement* widgDef, mLayer->editFormConfig()->tabs() )
{
QWidget* tabPage = new QWidget( tabWidget );

tabWidget->addTab( tabPage, widgDef->name() );
QGridLayout* tabPageLayout = new QGridLayout();
tabPage->setLayout( tabPageLayout );

if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
{
if ( !tabWidget )
{
tabWidget = new QTabWidget();
layout->addWidget( tabWidget, row, column, 1, 2 );
}

QWidget* tabPage = new QWidget( tabWidget );

tabWidget->addTab( tabPage, widgDef->name() );
QGridLayout* tabPageLayout = new QGridLayout();
tabPage->setLayout( tabPageLayout );

QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
if ( !containerDef )
continue;
@@ -1085,10 +1094,39 @@ void QgsAttributeForm::init()
}
else
{
QgsDebugMsg( "No support for fields in attribute editor on top level" );
tabWidget = nullptr;
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, container, mLayer, mContext );
QLabel* label = new QLabel( widgetInfo.labelText );
if ( columnCount > 1 && !widgetInfo.labelOnTop )
{
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
}

label->setBuddy( widgetInfo.widget );

if ( widgetInfo.labelOnTop )
{
QVBoxLayout* c = new QVBoxLayout();
label->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
c->layout()->addWidget( label );
c->layout()->addWidget( widgetInfo.widget );
layout->addLayout( c, row, column, 1, 2 );
column += 2;
}
else
{
layout->addWidget( label, row, column++ );
layout->addWidget( widgetInfo.widget, row, column++ );
}
}

if ( column >= columnCount * 2 )
{
column = 0;
row += 1;
}
}
formWidget = tabWidget;
formWidget = container;
}

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

5 comments on commit a6294cf

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Jun 21, 2016

Not sure if I have done the things properly, but top level is not removed in my case:

image

image

Also, if a field is not in a container it is not shown. Is it expected?

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied Jun 21, 2016

You can directly put fields on toplevel. Toplevel is not removed.

Also, if a field is not in a container it is not shown. Is it expected?

No

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Jun 21, 2016

ok thanks.

Actually, the not show widget was a relation with an old id. So no big deal (although, it should have been removed whenever the relation was removed no?)

Now, here is the config
image

and the result:
image

Another issue is that you can't add a group container at the top level from current UI. you can cheat by creating tab, then groups into it and drag'n'drop them to the top level, but that's not very intuitive.
Can you fix the UI for this?

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied Jun 21, 2016

That looks crappy indeed

@m-kuhn

This comment has been minimized.

Copy link
Member Author

@m-kuhn m-kuhn replied Jun 21, 2016

Overlapping issue fixed

Please sign in to comment.
You can’t perform that action at this time.