Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
configurable label (title) of relation editor widget instances
resolves #37675
  • Loading branch information
signedav committed Sep 9, 2020
1 parent 3f4c632 commit a209536
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 2 deletions.
15 changes: 15 additions & 0 deletions python/core/auto_generated/qgsattributeeditorelement.sip.in
Expand Up @@ -453,6 +453,21 @@ Determines the relation id of the second relation involved in an N:M relation.
Sets ``nmRelationId`` for the relation id of the second relation involved in an N:M relation.
If it's empty, then it's considered as a 1:M relationship.

.. versionadded:: 3.16
%End

QString label() const;
%Docstring
Determines the label of this element

.. versionadded:: 3.16
%End

void setLabel( const QString &label = QString() );
%Docstring
Sets ``label`` for this element
If it's empty it takes the relation id as label

.. versionadded:: 3.16
%End

Expand Down
Expand Up @@ -145,6 +145,20 @@ If it's empty, then it's considered as a 1:M relationship.
.. versionadded:: 3.16
%End

QString label() const;
%Docstring
Determines the label of this element

.. versionadded:: 3.16
%End

void setLabel( const QString &label = QString() );
%Docstring
Sets ``label`` for this element
If it's empty it takes the relation id as label

.. versionadded:: 3.16
%End

QgsRelation relation() const;
%Docstring
Expand Down
15 changes: 15 additions & 0 deletions python/gui/auto_generated/qgsrelationeditorwidget.sip.in
Expand Up @@ -210,6 +210,21 @@ Determines the relation id of the second relation involved in an N:M relation.
Sets ``nmRelationId`` for the relation id of the second relation involved in an N:M relation.
If it's empty, then it's considered as a 1:M relationship.

.. versionadded:: 3.16
%End

QString label() const;
%Docstring
Determines the label of this element

.. versionadded:: 3.16
%End

void setLabel( const QString &label = QString() );
%Docstring
Sets ``label`` for this element
If it's empty it takes the relation id as label

.. versionadded:: 3.16
%End

Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsattributeeditorelement.cpp
Expand Up @@ -99,6 +99,7 @@ QgsAttributeEditorElement *QgsAttributeEditorRelation::clone( QgsAttributeEditor
element->mButtons = mButtons;
element->mForceSuppressFormPopup = mForceSuppressFormPopup;
element->mNmRelationId = mNmRelationId;
element->mLabel = mLabel;

return element;
}
Expand Down Expand Up @@ -137,6 +138,7 @@ void QgsAttributeEditorRelation::saveConfiguration( QDomElement &elem ) const
elem.setAttribute( QStringLiteral( "buttons" ), qgsFlagValueToKeys( mButtons ) );
elem.setAttribute( QStringLiteral( "forceSuppressFormPopup" ), mForceSuppressFormPopup );
elem.setAttribute( QStringLiteral( "nmRelationId" ), mNmRelationId.toString() );
elem.setAttribute( QStringLiteral( "label" ), mLabel );
}

QString QgsAttributeEditorRelation::typeIdentifier() const
Expand Down Expand Up @@ -199,6 +201,16 @@ QVariant QgsAttributeEditorRelation::nmRelationId() const
return mNmRelationId;
}

void QgsAttributeEditorRelation::setLabel( const QString &label )
{
mLabel = label;
}

QString QgsAttributeEditorRelation::label() const
{
return mLabel;
}

QgsAttributeEditorElement *QgsAttributeEditorQmlElement::clone( QgsAttributeEditorElement *parent ) const
{
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( name(), parent );
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsattributeeditorelement.h
Expand Up @@ -494,6 +494,19 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
*/
void setNmRelationId( const QVariant &nmRelationId = QVariant() );

/**
* Determines the label of this element
* \since QGIS 3.16
*/
QString label() const;

/**
* Sets \a label for this element
* If it's empty it takes the relation id as label
* \since QGIS 3.16
*/
void setLabel( const QString &label = QString() );

private:
void saveConfiguration( QDomElement &elem ) const override;
QString typeIdentifier() const override;
Expand All @@ -502,6 +515,7 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
Buttons mButtons = Buttons( Button::AllButtons );
bool mForceSuppressFormPopup = false;
QVariant mNmRelationId;
QString mLabel;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAttributeEditorRelation::Buttons )
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -693,6 +693,11 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme
// pre QGIS 3.16 compatibility - the widgets section is read before
relElement->setNmRelationId( widgetConfig( elem.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "nm-rel" ) ) );
}
if ( elem.hasAttribute( "label" ) )
{
QString label = elem.attribute( QStringLiteral( "label" ) );
relElement->setLabel( label );
}
newElement = relElement;
}
else if ( elem.tagName() == QLatin1String( "attributeEditorQmlElement" ) )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/attributeformconfig/qgsattributewidgetedit.cpp
Expand Up @@ -118,6 +118,8 @@ void QgsAttributeWidgetRelationEditWidget::setRelationEditorConfiguration( const
mRelationCardinalityCombo->setToolTip( tr( "For a many to many (N:M) relation, the direct link has to be selected. The in-between table will be hidden." ) );
setNmRelationId( config.nmRelationId );

mRelationLabelEdit->setText( config.label );

mRelationForceSuppressFormPopupCheckBox->setChecked( config.forceSuppressFormPopup );
}

Expand All @@ -135,6 +137,7 @@ QgsAttributesFormProperties::RelationEditorConfiguration QgsAttributeWidgetRelat
relEdCfg.buttons = buttons;
relEdCfg.nmRelationId = mRelationCardinalityCombo->currentData();
relEdCfg.forceSuppressFormPopup = mRelationForceSuppressFormPopupCheckBox->isChecked();
relEdCfg.label = mRelationLabelEdit->text();
return relEdCfg;
}

Expand Down
14 changes: 14 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -280,3 +280,17 @@ QVariant QgsRelationWidgetWrapper::nmRelationId() const
return mWidget->nmRelationId();
return QVariant();
}


void QgsRelationWidgetWrapper::setLabel( const QString &label )
{
if ( mWidget )
mWidget->setLabel( label );
}

QString QgsRelationWidgetWrapper::label() const
{
if ( mWidget )
return mWidget->label();
return QString();
}
12 changes: 12 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.h
Expand Up @@ -134,6 +134,18 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
*/
void setNmRelationId( const QVariant &nmRelationId = QVariant() );

/**
* Determines the label of this element
* \since QGIS 3.16
*/
QString label() const;

/**
* Sets \a label for this element
* If it's empty it takes the relation id as label
* \since QGIS 3.16
*/
void setLabel( const QString &label = QString() );

/**
* The relation for which this wrapper is created.
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -1961,6 +1961,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
rww->setShowLabel( relDef->showLabel() );
rww->setNmRelationId( relDef->nmRelationId() );
rww->setForceSuppressFormPopup( relDef->forceSuppressFormPopup() );
rww->setLabel( relDef->label() );

mWidgets.append( rww );
mFormWidgets.append( formWidget );
Expand Down
22 changes: 21 additions & 1 deletion src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -1009,6 +1009,18 @@ QVariant QgsRelationEditorWidget::nmRelationId() const
return mNmRelationId;
}

QString QgsRelationEditorWidget::label() const
{
return mLabel;
}

void QgsRelationEditorWidget::setLabel( const QString &label )
{
mLabel = label;

updateTitle();
}

void QgsRelationEditorWidget::setShowUnlinkButton( bool showUnlinkButton )
{
mUnlinkFeatureButton->setVisible( showUnlinkButton );
Expand Down Expand Up @@ -1069,10 +1081,18 @@ void QgsRelationEditorWidget::unsetMapTool()

void QgsRelationEditorWidget::updateTitle()
{
if ( mShowLabel && mRelation.isValid() )
if ( mShowLabel && !mLabel.isEmpty() )
{
setTitle( mLabel );
}
else if ( mShowLabel && mRelation.isValid() )
{
setTitle( mRelation.name() );
}
else
{
setTitle( QString() );
}
}

QgsFeature QgsRelationEditorWidget::feature() const
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -247,6 +247,19 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
*/
void setNmRelationId( const QVariant &nmRelationId = QVariant() );

/**
* Determines the label of this element
* \since QGIS 3.16
*/
QString label() const;

/**
* Sets \a label for this element
* If it's empty it takes the relation id as label
* \since QGIS 3.16
*/
void setLabel( const QString &label = QString() );

/**
* Returns the widget's current feature
*
Expand Down Expand Up @@ -321,6 +334,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox

bool mForceSuppressFormPopup = false;
QVariant mNmRelationId;
QString mLabel;

/**
* Deletes the features
Expand Down
2 changes: 2 additions & 0 deletions src/gui/vector/qgsattributesformproperties.cpp
Expand Up @@ -413,6 +413,7 @@ QTreeWidgetItem *QgsAttributesFormProperties::loadAttributeEditorTreeItem( QgsAt
relEdConfig.buttons = relationEditor->visibleButtons();
relEdConfig.nmRelationId = relationEditor->nmRelationId();
relEdConfig.forceSuppressFormPopup = relationEditor->forceSuppressFormPopup();
relEdConfig.label = relationEditor->label();
itemData.setRelationEditorConfiguration( relEdConfig );
newWidget = tree->addItem( parent, itemData );
break;
Expand Down Expand Up @@ -659,6 +660,7 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid
relDef->setVisibleButtons( itemData.relationEditorConfiguration().buttons );
relDef->setNmRelationId( itemData.relationEditorConfiguration().nmRelationId );
relDef->setForceSuppressFormPopup( itemData.relationEditorConfiguration().forceSuppressFormPopup );
relDef->setLabel( itemData.relationEditorConfiguration().label );
widgetDef = relDef;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/vector/qgsattributesformproperties.h
Expand Up @@ -70,6 +70,7 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
QgsAttributeEditorRelation::Buttons buttons = QgsAttributeEditorRelation::Button::AllButtons;
QVariant nmRelationId;
bool forceSuppressFormPopup = false;
QString label;
};

struct QmlElementEditorConfiguration
Expand Down
Expand Up @@ -7,13 +7,37 @@
<x>0</x>
<y>0</y>
<width>340</width>
<height>293</height>
<height>361</height>
</rect>
</property>
<property name="windowTitle">
<string>Attribute Widget Relation Edit Widget</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="labelLabel">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mRelationLabelEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="mRelationShowLinkCheckBox">
<property name="text">
Expand Down

0 comments on commit a209536

Please sign in to comment.