Skip to content

Commit

Permalink
Fix groupboxes on toplevel in drag and drop designer
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 21, 2016
1 parent 5a43971 commit eaff966
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
25 changes: 23 additions & 2 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
break;

itemData.setColumnCount( container->columnCount() );
itemData.setShowAsGroupBox( container->isGroupBox() );
newWidget = mDesignerTree->addItem( parent, itemData );

Q_FOREACH ( QgsAttributeEditorElement* wdg, container->children() )
Expand Down Expand Up @@ -862,7 +863,7 @@ void QgsFieldsProperties::updateFieldRenamingStatus()
}
}

QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent )
QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTreeWidgetItem* item, QObject *parent , bool forceGroup )
{
QgsAttributeEditorElement *widgetDef = nullptr;

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

for ( int t = 0; t < item->childCount(); t++ )
{
Expand Down Expand Up @@ -985,7 +987,7 @@ void QgsFieldsProperties::apply()
{
QTreeWidgetItem* tabItem = mDesignerTree->invisibleRootItem()->child( t );

mLayer->editFormConfig()->addTab( createAttributeEditorWidget( tabItem, mLayer ) );
mLayer->editFormConfig()->addTab( createAttributeEditorWidget( tabItem, mLayer, false ) );
}

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

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

if ( !item->parent() )
{
showAsGroupBox = new QCheckBox( tr( "Show as group box" ) );
showAsGroupBox->setChecked( itemData.showAsGroupBox() );
layout->addRow( tr( "Show as group box" ), showAsGroupBox );
}

QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok
| QDialogButtonBox::Cancel );

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

return stream;
}

bool QgsFieldsProperties::DesignerTreeItemData::showAsGroupBox() const
{
return mShowAsGroupBox;
}

void QgsFieldsProperties::DesignerTreeItemData::setShowAsGroupBox( bool showAsGroupBox )
{
mShowAsGroupBox = showAsGroupBox;
}
7 changes: 5 additions & 2 deletions src/app/qgsfieldsproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
int columnCount() const { return mColumnCount; }
void setColumnCount( int count ) { mColumnCount = count; }

bool showAsGroupBox() const;
void setShowAsGroupBox( bool showAsGroupBox );

private:
Type mType;
QString mName;
int mColumnCount;
bool mShowAsGroupBox;
};

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

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

void init();
void apply();
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgseditformconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
cc = 0;
container->setColumnCount( cc );

bool isGroupBox = elem.attribute( "groupBox" ).toInt( &ok );
if ( ok )
container->setIsGroupBox( isGroupBox );
else
container->setIsGroupBox( qobject_cast<QgsAttributeEditorContainer*>( parent ) );

QDomNodeList childNodeList = elem.childNodes();

for ( int i = 0; i < childNodeList.size(); i++ )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgseditformconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class CORE_EXPORT QgsEditFormConfig : public QObject
/**
* This is only useful in combination with EditorLayout::TabLayout.
*
* Adds a new tab to the layout. Should be a QgsAttributeEditorContainer.
* Adds a new element to the layout.
*/
void addTab( QgsAttributeEditorElement* data ) { mAttributeEditorElements.append( data ); }

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4058,6 +4058,7 @@ QDomElement QgsAttributeEditorContainer::toDomElement( QDomDocument& doc ) const
QDomElement elem = doc.createElement( "attributeEditorContainer" );
elem.setAttribute( "name", mName );
elem.setAttribute( "columnCount", mColumnCount );
elem.setAttribute( "groupBox", mIsGroupBox ? 1 : 0 );

Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
{
Expand Down
37 changes: 23 additions & 14 deletions src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,26 +1100,35 @@ void QgsAttributeForm::init()
{
if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
{
if ( !tabWidget )
QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
if ( !containerDef )
continue;

if ( containerDef->isGroupBox() )
{
tabWidget = new QTabWidget();
layout->addWidget( tabWidget, row, column, 1, 2 );
tabWidget = nullptr;
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, formWidget, mLayer, mContext );
layout->addWidget( widgetInfo.widget, row, column, 1, 2 );
column += 2;
}
else
{
if ( !tabWidget )
{
tabWidget = new QTabWidget();
layout->addWidget( tabWidget, row, column, 1, 2 );
column += 2;
}

QWidget* tabPage = new QWidget( tabWidget );

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

QgsAttributeEditorContainer* containerDef = dynamic_cast<QgsAttributeEditorContainer*>( widgDef );
if ( !containerDef )
continue;
tabWidget->addTab( tabPage, widgDef->name() );
QGridLayout* tabPageLayout = new QGridLayout();
tabPage->setLayout( tabPageLayout );

containerDef->setIsGroupBox( false ); // Toplevel widgets are tabs not groupboxes
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, tabPage, mLayer, mContext );
tabPageLayout->addWidget( widgetInfo.widget );
WidgetInfo widgetInfo = createWidgetFromDef( widgDef, tabPage, mLayer, mContext );
tabPageLayout->addWidget( widgetInfo.widget );
}
}
else
{
Expand Down

0 comments on commit eaff966

Please sign in to comment.