Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #38331 from signedav/relation-config
Browse files Browse the repository at this point in the history
Multiple widgets of same relation
  • Loading branch information
signedav committed Sep 3, 2020
2 parents 78ca2a4 + b5af453 commit 4b8797d
Show file tree
Hide file tree
Showing 22 changed files with 645 additions and 479 deletions.
30 changes: 30 additions & 0 deletions python/core/auto_generated/qgsattributeeditorelement.sip.in
Expand Up @@ -425,6 +425,36 @@ Returns the buttons which are shown
.. versionadded:: 3.16
%End

bool forceSuppressFormPopup() const;
%Docstring
Determines the force suppress form popup status.

.. versionadded:: 3.16
%End

void setForceSuppressFormPopup( bool forceSuppressFormPopup );
%Docstring
Sets force suppress form popup status to ``forceSuppressFormPopup``.
This flag is to override the layer and general settings regarding the automatic
opening of the attribute form dialog when digitizing is completed.

.. versionadded:: 3.16
%End

QVariant nmRelationId() const;
%Docstring
Determines the relation id of the second relation involved in an N:M relation.

.. versionadded:: 3.16
%End

void setNmRelationId( const QVariant &nmRelationId = QVariant() );
%Docstring
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

};

Expand Down
Expand Up @@ -113,6 +113,39 @@ Returns the buttons which are shown
.. versionadded:: 3.16
%End

bool forceSuppressFormPopup() const;
%Docstring
Determines the force suppress form popup status that is configured for this widget

.. versionadded:: 3.16
%End

void setForceSuppressFormPopup( bool forceSuppressFormPopup );
%Docstring
Sets force suppress form popup status to ``forceSuppressFormPopup`` for this widget
and for the vectorLayerTools (if true).
This flag will override the layer and general settings regarding the automatic
opening of the attribute form dialog when digitizing is completed.

.. versionadded:: 3.16
%End

QVariant nmRelationId() const;
%Docstring
Determines the relation id of the second relation involved in an N:M relation.

.. versionadded:: 3.16
%End

void setNmRelationId( const QVariant &nmRelationId = QVariant() );
%Docstring
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


QgsRelation relation() const;
%Docstring
The relation for which this wrapper is created.
Expand Down
30 changes: 30 additions & 0 deletions python/gui/auto_generated/qgsrelationeditorwidget.sip.in
Expand Up @@ -180,6 +180,36 @@ Defines the buttons which are shown
%Docstring
Returns the buttons which are shown

.. versionadded:: 3.16
%End

bool forceSuppressFormPopup() const;
%Docstring
Determines the force suppress form popup status that is configured for this widget

.. versionadded:: 3.16
%End

void setForceSuppressFormPopup( bool forceSuppressFormPopup );
%Docstring
Sets force suppress form popup status with ``forceSuppressFormPopup``
configured for this widget

.. versionadded:: 3.16
%End

QVariant nmRelationId() const;
%Docstring
Determines the relation id of the second relation involved in an N:M relation.

.. versionadded:: 3.16
%End

void setNmRelationId( const QVariant &nmRelationId = QVariant() );
%Docstring
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

Expand Down
24 changes: 24 additions & 0 deletions src/core/qgsattributeeditorelement.cpp
Expand Up @@ -97,6 +97,8 @@ QgsAttributeEditorElement *QgsAttributeEditorRelation::clone( QgsAttributeEditor
QgsAttributeEditorRelation *element = new QgsAttributeEditorRelation( mRelationId, parent );
element->mRelation = mRelation;
element->mButtons = mButtons;
element->mForceSuppressFormPopup = mForceSuppressFormPopup;
element->mNmRelationId = mNmRelationId;

return element;
}
Expand Down Expand Up @@ -133,6 +135,8 @@ void QgsAttributeEditorRelation::saveConfiguration( QDomElement &elem ) const
{
elem.setAttribute( QStringLiteral( "relation" ), mRelation.id() );
elem.setAttribute( QStringLiteral( "buttons" ), qgsFlagValueToKeys( mButtons ) );
elem.setAttribute( QStringLiteral( "forceSuppressFormPopup" ), mForceSuppressFormPopup );
elem.setAttribute( QStringLiteral( "nmRelationId" ), mNmRelationId.toString() );
}

QString QgsAttributeEditorRelation::typeIdentifier() const
Expand Down Expand Up @@ -175,6 +179,26 @@ void QgsAttributeEditorRelation::setVisibleButtons( const QgsAttributeEditorRela
mButtons = buttons;
}

void QgsAttributeEditorRelation::setForceSuppressFormPopup( bool forceSuppressFormPopup )
{
mForceSuppressFormPopup = forceSuppressFormPopup;
}

bool QgsAttributeEditorRelation::forceSuppressFormPopup() const
{
return mForceSuppressFormPopup;
}

void QgsAttributeEditorRelation::setNmRelationId( const QVariant &nmRelationId )
{
mNmRelationId = nmRelationId;
}

QVariant QgsAttributeEditorRelation::nmRelationId() const
{
return mNmRelationId;
}

QgsAttributeEditorElement *QgsAttributeEditorQmlElement::clone( QgsAttributeEditorElement *parent ) const
{
QgsAttributeEditorQmlElement *element = new QgsAttributeEditorQmlElement( name(), parent );
Expand Down
28 changes: 28 additions & 0 deletions src/core/qgsattributeeditorelement.h
Expand Up @@ -467,13 +467,41 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
*/
QgsAttributeEditorRelation::Buttons visibleButtons() const {return mButtons;}

/**
* Determines the force suppress form popup status.
* \since QGIS 3.16
*/
bool forceSuppressFormPopup() const;

/**
* Sets force suppress form popup status to \a forceSuppressFormPopup.
* This flag is to override the layer and general settings regarding the automatic
* opening of the attribute form dialog when digitizing is completed.
* \since QGIS 3.16
*/
void setForceSuppressFormPopup( bool forceSuppressFormPopup );

/**
* Determines the relation id of the second relation involved in an N:M relation.
* \since QGIS 3.16
*/
QVariant nmRelationId() const;

/**
* Sets \a 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.
* \since QGIS 3.16
*/
void setNmRelationId( const QVariant &nmRelationId = QVariant() );

private:
void saveConfiguration( QDomElement &elem ) const override;
QString typeIdentifier() const override;
QString mRelationId;
QgsRelation mRelation;
Buttons mButtons = Buttons( Button::AllButtons );
bool mForceSuppressFormPopup = false;
QVariant mNmRelationId;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAttributeEditorRelation::Buttons )
Expand Down
64 changes: 64 additions & 0 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgslogger.h"
#include "qgsxmlutils.h"
#include "qgsapplication.h"
#include "qgsmessagelog.h"

QgsAttributeEditorContainer::~QgsAttributeEditorContainer()
{
Expand Down Expand Up @@ -88,6 +89,43 @@ void QgsEditFormConfig::onRelationsLoaded()
}
}

bool QgsEditFormConfig::legacyUpdateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config )
{
const QList<QgsAttributeEditorElement *> children = container->children();
for ( QgsAttributeEditorElement *child : children )
{
if ( child->type() == QgsAttributeEditorElement::AeTypeContainer )
{
QgsAttributeEditorContainer *container = dynamic_cast<QgsAttributeEditorContainer *>( child );
if ( legacyUpdateRelationWidgetInTabs( container, widgetName, config ) )
{
//return when a relation has been set in a child or child child...
return true;
}
}
else if ( child->type() == QgsAttributeEditorElement::AeTypeRelation )
{
QgsAttributeEditorRelation *relation = dynamic_cast< QgsAttributeEditorRelation * >( child );
if ( relation )
{
if ( relation->relation().id() == widgetName )
{
if ( config.contains( QStringLiteral( "nm-rel" ) ) )
{
relation->setNmRelationId( config[QStringLiteral( "nm-rel" )] );
}
if ( config.contains( QStringLiteral( "force-suppress-popup" ) ) )
{
relation->setForceSuppressFormPopup( config[QStringLiteral( "force-suppress-popup" )].toBool() );
}
return true;
}
}
}
}
return false;
}

bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVariantMap &config )
{
if ( d->mFields.indexOf( widgetName ) != -1 )
Expand All @@ -96,6 +134,13 @@ bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVaria
return false;
}

//for legacy use it writes the relation editor configuration into the first instance of the widget
if ( config.contains( QStringLiteral( "force-suppress-popup" ) ) || config.contains( QStringLiteral( "nm-rel" ) ) )
{
QgsMessageLog::logMessage( QStringLiteral( "Deprecation Warning: Trying to set a relation config directly on the relation %1. Relation settings should be done for the specific widget instance instead. Use attributeEditorRelation->setNmRelationId() or attributeEditorRelation->setForceSuppressFormPopup() instead." ).arg( widgetName ) );
legacyUpdateRelationWidgetInTabs( d->mInvisibleRootContainer, widgetName, config );
}

d.detach();
d->mWidgetConfigs[widgetName] = config;
return true;
Expand Down Expand Up @@ -629,6 +674,25 @@ QgsAttributeEditorElement *QgsEditFormConfig::attributeEditorElementFromDomEleme
buttons.setFlag( QgsAttributeEditorRelation::Button::SaveChildEdits, elem.attribute( QStringLiteral( "showSaveChildEditsButton" ), QStringLiteral( "1" ) ).toInt() );
relElement->setVisibleButtons( buttons );
}
if ( elem.hasAttribute( QStringLiteral( "forceSuppressFormPopup" ) ) )
{
relElement->setForceSuppressFormPopup( elem.attribute( QStringLiteral( "forceSuppressFormPopup" ) ).toInt() );
}
else
{
// pre QGIS 3.16 compatibility - the widgets section is read before
relElement->setForceSuppressFormPopup( widgetConfig( elem.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "force-suppress-popup" ), false ).toBool() );
}

if ( elem.hasAttribute( QStringLiteral( "nmRelationId" ) ) )
{
relElement->setNmRelationId( elem.attribute( QStringLiteral( "nmRelationId" ) ) );
}
else
{
// pre QGIS 3.16 compatibility - the widgets section is read before
relElement->setNmRelationId( widgetConfig( elem.attribute( QStringLiteral( "relation" ) ) ).value( QStringLiteral( "nm-rel" ) ) );
}
newElement = relElement;
}
else if ( elem.tagName() == QLatin1String( "attributeEditorQmlElement" ) )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgseditformconfig.h
Expand Up @@ -348,6 +348,12 @@ class CORE_EXPORT QgsEditFormConfig
*/
void onRelationsLoaded();

/**
* Used for the backwards compatibility of the api, on setting nmrel or force-suppress-popup for relations.
* Returns true when a relation instance (the first one found) has been updated.
*/
bool legacyUpdateRelationWidgetInTabs( QgsAttributeEditorContainer *container, const QString &widgetName, const QVariantMap &config );

private:
QExplicitlySharedDataPointer<QgsEditFormConfigPrivate> d;

Expand Down
2 changes: 0 additions & 2 deletions src/gui/CMakeLists.txt
Expand Up @@ -74,7 +74,6 @@ SET(QGIS_GUI_SRCS
callouts/qgscalloutwidget.cpp

attributeformconfig/qgsattributeformcontaineredit.cpp
attributeformconfig/qgsattributerelationedit.cpp
attributeformconfig/qgsattributetypedialog.cpp
attributeformconfig/qgsattributewidgetedit.cpp

Expand Down Expand Up @@ -804,7 +803,6 @@ SET(QGIS_GUI_HDRS
qgswindowmanagerinterface.h

attributeformconfig/qgsattributeformcontaineredit.h
attributeformconfig/qgsattributerelationedit.h
attributeformconfig/qgsattributetypedialog.h
attributeformconfig/qgsattributewidgetedit.h

Expand Down
52 changes: 0 additions & 52 deletions src/gui/attributeformconfig/qgsattributerelationedit.cpp

This file was deleted.

0 comments on commit 4b8797d

Please sign in to comment.