Skip to content

Commit

Permalink
Add support for toplevel widgets in drag and drop designer
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 3, 2016
1 parent 7abd691 commit a6294cf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
13 changes: 3 additions & 10 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
60 changes: 49 additions & 11 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 );

Expand Down

5 comments on commit a6294cf

@3nids
Copy link
Member

@3nids 3nids commented on a6294cf Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@m-kuhn m-kuhn commented on a6294cf Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

@3nids 3nids commented on a6294cf Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@m-kuhn m-kuhn commented on a6294cf Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks crappy indeed

@m-kuhn
Copy link
Member Author

@m-kuhn m-kuhn commented on a6294cf Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlapping issue fixed

Please sign in to comment.