mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[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
This commit is contained in:
parent
e30ff62419
commit
1bd26f75a5
@ -24,7 +24,7 @@
|
||||
* layer.
|
||||
*/
|
||||
|
||||
class QgsAttributeEditorElement
|
||||
class QgsAttributeEditorElement /Abstract/
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsattributeeditorelement.h>
|
||||
@ -87,13 +87,13 @@ 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.
|
||||
@ -101,6 +101,21 @@ switch( sipCpp->type() )
|
||||
* @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,6 +56,7 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
|
||||
: mType( Field )
|
||||
, mColumnCount( 1 )
|
||||
, mShowAsGroupBox( false )
|
||||
, mShowLabel( true )
|
||||
{}
|
||||
|
||||
DesignerTreeItemData( Type type, const QString& name )
|
||||
@ -63,6 +64,7 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
|
||||
, 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,14 +54,6 @@ 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 );
|
||||
@ -83,14 +61,6 @@ QgsAttributeEditorElement* QgsAttributeEditorField::clone( QgsAttributeEditorEle
|
||||
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";
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ class CORE_EXPORT QgsAttributeEditorElement
|
||||
: mType( type )
|
||||
, mName( name )
|
||||
, mParent( parent )
|
||||
, mShowLabel( true )
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
@ -79,13 +80,13 @@ class CORE_EXPORT QgsAttributeEditorElement
|
||||
QgsAttributeEditorElement* parent() const { return mParent; }
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@ -94,10 +95,41 @@ class CORE_EXPORT QgsAttributeEditorElement
|
||||
*/
|
||||
virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const = 0;
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
protected:
|
||||
AttributeEditorType mType;
|
||||
QString mName;
|
||||
QgsAttributeEditorElement* mParent;
|
||||
bool mShowLabel;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Should be implemented by subclasses to save type specific configuration.
|
||||
*
|
||||
* @note Added in QGIS 2.18
|
||||
*/
|
||||
virtual void saveConfiguration( QDomElement& elem ) const = 0;
|
||||
|
||||
/**
|
||||
* All subclasses need to overwrite this method and return a type specific identifier.
|
||||
* Needs to be XML key compatible.
|
||||
*
|
||||
* @note Added in QGIS 2.18
|
||||
*/
|
||||
virtual QString typeIdentifier() const = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -123,15 +155,6 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
|
||||
//! Destructor
|
||||
virtual ~QgsAttributeEditorContainer();
|
||||
|
||||
/**
|
||||
* Will serialize this containers information into a QDomElement for saving it in an XML file.
|
||||
*
|
||||
* @param doc The QDomDocument used to generate the QDomElement
|
||||
*
|
||||
* @return The XML element
|
||||
*/
|
||||
virtual QDomElement toDomElement( QDomDocument& doc ) const override;
|
||||
|
||||
/**
|
||||
* Add a child element to this container. This may be another container, a field or a relation.
|
||||
*
|
||||
@ -197,6 +220,9 @@ class CORE_EXPORT QgsAttributeEditorContainer : public QgsAttributeEditorElement
|
||||
virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const override;
|
||||
|
||||
private:
|
||||
void saveConfiguration( QDomElement& elem ) const override;
|
||||
QString typeIdentifier() const override;
|
||||
|
||||
bool mIsGroupBox;
|
||||
QList<QgsAttributeEditorElement*> mChildren;
|
||||
int mColumnCount;
|
||||
@ -223,15 +249,6 @@ class CORE_EXPORT QgsAttributeEditorField : public QgsAttributeEditorElement
|
||||
//! Destructor
|
||||
virtual ~QgsAttributeEditorField() {}
|
||||
|
||||
/**
|
||||
* Will serialize this elements information into a QDomElement for saving it in an XML file.
|
||||
*
|
||||
* @param doc The QDomDocument used to generate the QDomElement
|
||||
*
|
||||
* @return The XML element
|
||||
*/
|
||||
virtual QDomElement toDomElement( QDomDocument& doc ) const override;
|
||||
|
||||
/**
|
||||
* Return the index of the field
|
||||
* @return
|
||||
@ -241,6 +258,8 @@ class CORE_EXPORT QgsAttributeEditorField : public QgsAttributeEditorElement
|
||||
virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const override;
|
||||
|
||||
private:
|
||||
void saveConfiguration( QDomElement& elem ) const override;
|
||||
QString typeIdentifier() const override;
|
||||
int mIdx;
|
||||
};
|
||||
|
||||
@ -276,15 +295,6 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
|
||||
//! Destructor
|
||||
virtual ~QgsAttributeEditorRelation() {}
|
||||
|
||||
/**
|
||||
* Will serialize this elements information into a QDomElement for saving it in an XML file.
|
||||
*
|
||||
* @param doc The QDomDocument used to generate the QDomElement
|
||||
*
|
||||
* @return The XML element
|
||||
*/
|
||||
virtual QDomElement toDomElement( QDomDocument& doc ) const override;
|
||||
|
||||
/**
|
||||
* Get the id of the relation which shall be embedded
|
||||
*
|
||||
@ -303,6 +313,8 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
|
||||
virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const override;
|
||||
|
||||
private:
|
||||
void saveConfiguration( QDomElement& elem ) const override;
|
||||
QString typeIdentifier() const override;
|
||||
QString mRelationId;
|
||||
QgsRelation mRelation;
|
||||
};
|
||||
|
@ -627,6 +627,12 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
|
||||
QString name = elem.attribute( "name" );
|
||||
newElement = new QgsAttributeEditorRelation( name, elem.attribute( "relation", "[None]" ), parent );
|
||||
}
|
||||
|
||||
if ( elem.hasAttribute( "showLabel" ) )
|
||||
newElement->setShowLabel( elem.attribute( "showLabel" ).toInt() );
|
||||
else
|
||||
newElement->setShowLabel( true );
|
||||
|
||||
return newElement;
|
||||
}
|
||||
|
||||
@ -653,3 +659,20 @@ QgsAttributeEditorElement* QgsAttributeEditorContainer::clone( QgsAttributeEdito
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
void QgsAttributeEditorContainer::saveConfiguration( QDomElement& elem ) const
|
||||
{
|
||||
elem.setAttribute( "columnCount", mColumnCount );
|
||||
elem.setAttribute( "groupBox", mIsGroupBox ? 1 : 0 );
|
||||
|
||||
Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
|
||||
{
|
||||
QDomDocument doc = elem.ownerDocument();
|
||||
elem.appendChild( child->toDomElement( doc ) );
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsAttributeEditorContainer::typeIdentifier() const
|
||||
{
|
||||
return "attributeEditorContainer";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user