Skip to content
Permalink
Browse files

[feature] Allow controlling labels for individual edit widgets

In the drag and drop designer, a double click on an item will allow
controlling if the label should be shown for each item individually.

Fix #15450
  • Loading branch information
m-kuhn committed Aug 19, 2016
1 parent e30ff62 commit 1bd26f75a5cf5772ad6421d9eec0abd3d2c649e5
@@ -24,7 +24,7 @@
* layer.
*/

class QgsAttributeEditorElement
class QgsAttributeEditorElement /Abstract/
{
%TypeHeaderCode
#include <qgsattributeeditorelement.h>
@@ -87,20 +87,35 @@ switch( sipCpp->type() )
QgsAttributeEditorElement* parent() const;

/**
* Is reimplemented in classes inheriting from this to serialize it.
* Get the XML Dom element to save this element.
*
* @param doc The QDomDocument which is used to create new XML elements
*
* @return An DOM element which represents this element
* @return A DOM element to serialize this element
*/
virtual QDomElement toDomElement( QDomDocument& doc ) const = 0;
QDomElement toDomElement( QDomDocument& doc ) const;

/**
* Returns a clone of this element. To be implemented by subclasses.
*
* @note Added in QGIS 3.0
*/
virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const = 0 /Factory/;

/**
* Controls if this element should be labeled with a title (field, relation or groupname).
*
* @note Added in QGIS 2.18
*/
bool showLabel() const;

/**
* Controls if this element should be labeled with a title (field, relation or groupname).
*
* @note Added in QGIS 2.18
*/
void setShowLabel( bool showLabel );

};


@@ -160,16 +160,26 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
switch ( widgetDef->type() )
{
case QgsAttributeEditorElement::AeTypeField:
newWidget = mDesignerTree->addItem( parent, DesignerTreeItemData( DesignerTreeItemData::Field, widgetDef->name() ) );
{
DesignerTreeItemData itemData = DesignerTreeItemData( DesignerTreeItemData::Field, widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );
newWidget = mDesignerTree->addItem( parent, itemData );
break;
}

case QgsAttributeEditorElement::AeTypeRelation:
newWidget = mDesignerTree->addItem( parent, DesignerTreeItemData( DesignerTreeItemData::Relation, widgetDef->name() ) );
{
DesignerTreeItemData itemData = DesignerTreeItemData( DesignerTreeItemData::Relation, widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );

newWidget = mDesignerTree->addItem( parent, itemData );
break;
}

case QgsAttributeEditorElement::AeTypeContainer:
{
DesignerTreeItemData itemData( DesignerTreeItemData::Container, widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );

const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef );
if ( !container )
@@ -864,6 +874,8 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
}
}

widgetDef->setShowLabel( itemData.showLabel() );

return widgetDef;
}

@@ -1234,12 +1246,23 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
Q_UNUSED( column )
QgsFieldsProperties::DesignerTreeItemData itemData = item->data( 0, QgsFieldsProperties::DesignerTreeRole ).value<QgsFieldsProperties::DesignerTreeItemData>();

QGroupBox* baseData = new QGroupBox( tr( "Base configuration" ) );

QFormLayout* baseLayout = new QFormLayout();
baseData->setLayout( baseLayout );
QCheckBox* showLabelCheckbox = new QCheckBox( "Show label" );
showLabelCheckbox->setChecked( itemData.showLabel() );
baseLayout->addWidget( showLabelCheckbox );
QWidget* baseWidget = new QWidget();
baseWidget->setLayout( baseLayout );

if ( itemData.type() == QgsFieldsProperties::DesignerTreeItemData::Container )
{
QDialog dlg;
dlg.setWindowTitle( tr( "Configure container" ) );
QFormLayout* layout = new QFormLayout() ;
dlg.setLayout( layout );
layout->addWidget( baseWidget );

QCheckBox* showAsGroupBox = nullptr;
QLineEdit* title = new QLineEdit( itemData.name() );
@@ -1270,10 +1293,34 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
itemData.setColumnCount( columnCount->value() );
itemData.setShowAsGroupBox( showAsGroupBox ? showAsGroupBox->isChecked() : true );
itemData.setName( title->text() );
itemData.setShowLabel( showLabelCheckbox->isChecked() );

item->setData( 0, QgsFieldsProperties::DesignerTreeRole, itemData.asQVariant() );
item->setText( 0, title->text() );
}
}
else
{
QDialog dlg;
dlg.setWindowTitle( tr( "Configure container" ) );
dlg.setLayout( new QGridLayout() );
dlg.layout()->addWidget( baseWidget );

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

connect( buttonBox, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
connect( buttonBox, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );

dlg.layout()->addWidget( buttonBox );

if ( dlg.exec() )
{
itemData.setShowLabel( showLabelCheckbox->isChecked() );

item->setData( 0, QgsFieldsProperties::DesignerTreeRole, itemData.asQVariant() );
}
}
}

/*
@@ -1308,3 +1355,13 @@ void QgsFieldsProperties::DesignerTreeItemData::setShowAsGroupBox( bool showAsGr
{
mShowAsGroupBox = showAsGroupBox;
}

bool QgsFieldsProperties::DesignerTreeItemData::showLabel() const
{
return mShowLabel;
}

void QgsFieldsProperties::DesignerTreeItemData::setShowLabel( bool showLabel )
{
mShowLabel = showLabel;
}
@@ -56,13 +56,15 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
: mType( Field )
, mColumnCount( 1 )
, mShowAsGroupBox( false )
, mShowLabel( true )
{}

DesignerTreeItemData( Type type, const QString& name )
: mType( type )
, mName( name )
, mColumnCount( 1 )
, mShowAsGroupBox( false )
, mShowLabel( true )
{}

QString name() const { return mName; }
@@ -79,11 +81,15 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
bool showAsGroupBox() const;
void setShowAsGroupBox( bool showAsGroupBox );

bool showLabel() const;
void setShowLabel( bool showLabel );

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

/**
@@ -16,20 +16,6 @@
#include "qgsattributeeditorelement.h"
#include "qgsrelationmanager.h"

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 )
{
elem.appendChild( child->toDomElement( doc ) );
}
return elem;
}

void QgsAttributeEditorContainer::addChildElement( QgsAttributeEditorElement *widget )
{
mChildren.append( widget );
@@ -68,29 +54,13 @@ void QgsAttributeEditorContainer::clear()
mChildren.clear();
}

QDomElement QgsAttributeEditorField::toDomElement( QDomDocument& doc ) const
{
QDomElement elem = doc.createElement( "attributeEditorField" );
elem.setAttribute( "name", mName );
elem.setAttribute( "index", mIdx );
return elem;
}

QgsAttributeEditorElement* QgsAttributeEditorField::clone( QgsAttributeEditorElement* parent ) const
{
QgsAttributeEditorField* element = new QgsAttributeEditorField( name(), mIdx, parent );

return element;
}

QDomElement QgsAttributeEditorRelation::toDomElement( QDomDocument& doc ) const
{
QDomElement elem = doc.createElement( "attributeEditorRelation" );
elem.setAttribute( "name", mName );
elem.setAttribute( "relation", mRelation.id() );
return elem;
}

bool QgsAttributeEditorRelation::init( QgsRelationManager* relationManager )
{
mRelation = relationManager->relation( mRelationId );
@@ -104,3 +74,42 @@ QgsAttributeEditorElement* QgsAttributeEditorRelation::clone( QgsAttributeEditor

return element;
}
void QgsAttributeEditorField::saveConfiguration( QDomElement &elem ) const
{
elem.setAttribute( "index", mIdx );
}

QString QgsAttributeEditorField::typeIdentifier() const
{
return "attributeEditorField";
}

QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument& doc ) const
{
QDomElement elem = doc.createElement( typeIdentifier() );
elem.setAttribute( "name", mName );
elem.setAttribute( "showLabel", mShowLabel );

saveConfiguration( elem );
return elem;
}

bool QgsAttributeEditorElement::showLabel() const
{
return mShowLabel;
}

void QgsAttributeEditorElement::setShowLabel( bool showLabel )
{
mShowLabel = showLabel;
}

void QgsAttributeEditorRelation::saveConfiguration( QDomElement& elem ) const
{
elem.setAttribute( "relation", mRelation.id() );
}

QString QgsAttributeEditorRelation::typeIdentifier() const
{
return "attributeEditorRelation";
}

0 comments on commit 1bd26f7

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