Skip to content
Permalink
Browse files

Merge pull request #3227 from m-kuhn/FixToplevelGroupBoxes

Fix groupboxes on toplevel in drag and drop designer
  • Loading branch information
3nids committed Jun 21, 2016
2 parents 3c06341 + eaff966 commit 7697d79a212b3160a15f0680613ec05b64c81006
@@ -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() )
@@ -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;

@@ -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++ )
{
@@ -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() );
@@ -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 );
@@ -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 );

@@ -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() );
@@ -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;
}
@@ -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;
};

/**
@@ -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();
@@ -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++ )
@@ -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 ); }

@@ -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 )
{
@@ -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
{

0 comments on commit 7697d79

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