Skip to content

Commit

Permalink
Add missing NoButton enum value to avoid losing relation editor butto…
Browse files Browse the repository at this point in the history
…n configuration (#43479)

* add dox to duplicated enum in QgsAttributeEditorRelation and QgsRelationEditorWidget

also remove leftover

* add extra enum NoButton to avoid saving an empty string when using qgsFlagsValueToKeys

fixes #43123

* fix test by using non deprecated enum

* add comment

* add since
  • Loading branch information
3nids committed Jun 1, 2021
2 parents a516549 + b9277cd commit 570846a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
Expand Up @@ -165,7 +165,6 @@ Sets the relation editor configuration
QFlags<QgsAttributeEditorRelation::Button> operator|(QgsAttributeEditorRelation::Button f1, QFlags<QgsAttributeEditorRelation::Button> f2);



/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
1 change: 1 addition & 0 deletions python/gui/auto_generated/qgsrelationeditorwidget.sip.in
Expand Up @@ -36,6 +36,7 @@ The default relation widget in QGIS.

enum Button
{
NoButton,
Link,
Unlink,
SaveChildEdits,
Expand Down
8 changes: 8 additions & 0 deletions src/core/editform/qgsattributeeditorrelation.cpp
Expand Up @@ -66,16 +66,24 @@ void QgsAttributeEditorRelation::loadConfiguration( const QDomElement &element,
{
if ( element.hasAttribute( "buttons" ) )
{
Q_NOWARN_DEPRECATED_PUSH
// QgsAttributeEditorRelation::Button has been deprecated in favor of QgsRelationEditorWidget::Button
// we cannot use it here since the new flags are in gui, while the current code is in core
// TODO: remove this compatibility code in QGIS 4
// or make the enum private if we really want to keep the backward compatibility (but not worth it!)
QString buttonString = element.attribute( QStringLiteral( "buttons" ), qgsFlagValueToKeys( QgsAttributeEditorRelation::Button::AllButtons ) );
config.insert( "buttons", qgsFlagValueToKeys( qgsFlagKeysToValue( buttonString, QgsAttributeEditorRelation::Button::AllButtons ) ) );
Q_NOWARN_DEPRECATED_POP
}
else
{
// pre QGIS 3.16 compatibility
Q_NOWARN_DEPRECATED_PUSH
QgsAttributeEditorRelation::Buttons buttons = QgsAttributeEditorRelation::Button::AllButtons;
buttons.setFlag( QgsAttributeEditorRelation::Button::Link, element.attribute( QStringLiteral( "showLinkButton" ), QStringLiteral( "1" ) ).toInt() );
buttons.setFlag( QgsAttributeEditorRelation::Button::Unlink, element.attribute( QStringLiteral( "showUnlinkButton" ), QStringLiteral( "1" ) ).toInt() );
buttons.setFlag( QgsAttributeEditorRelation::Button::SaveChildEdits, element.attribute( QStringLiteral( "showSaveChildEditsButton" ), QStringLiteral( "1" ) ).toInt() );
Q_NOWARN_DEPRECATED_POP
config.insert( "buttons", qgsFlagValueToKeys( buttons ) );
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/core/editform/qgsattributeeditorrelation.h
Expand Up @@ -36,9 +36,10 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement

/**
* Possible buttons shown in the relation editor
* \deprecated since QGIS 3.18 use QgsRelationEditorWidget::Button instead
* \since QGIS 3.16
*/
enum Button
enum Q_DECL_DEPRECATED Button
{
Link = 1 << 1, //!< Link button
Unlink = 1 << 2, //!< Unlink button
Expand All @@ -49,9 +50,11 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
ZoomToChildFeature = 1 << 7, //!< Zoom to child feature
AllButtons = Link | Unlink | SaveChildEdits | AddChildFeature | DuplicateChildFeature | DeleteChildFeature | ZoomToChildFeature //!< All buttons
};
Q_NOWARN_DEPRECATED_PUSH
Q_ENUM( Button )
Q_DECLARE_FLAGS( Buttons, Button )
Q_FLAG( Buttons )
Q_NOWARN_DEPRECATED_POP

/**
* \deprecated since QGIS 3.0.2. The name parameter is not used for anything and overwritten by the relationId internally.
Expand Down Expand Up @@ -183,15 +186,18 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
QString typeIdentifier() const override;
QString mRelationId;
QgsRelation mRelation;
Q_NOWARN_DEPRECATED_PUSH
Buttons mButtons = Buttons( Button::AllButtons );
Q_NOWARN_DEPRECATED_POP
bool mForceSuppressFormPopup = false;
QVariant mNmRelationId;
QString mLabel;
QString mRelationWidgetTypeId;
QVariantMap mRelationEditorConfig;
};

Q_NOWARN_DEPRECATED_PUSH
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAttributeEditorRelation::Buttons )

Q_NOWARN_DEPRECATED_POP

#endif // QGSATTRIBUTEEDITORRELATION_H
2 changes: 2 additions & 0 deletions src/gui/qgsrelationeditorwidget.h
Expand Up @@ -95,9 +95,11 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge

/**
* Possible buttons shown in the relation editor
* \since QGIS 3.18
*/
enum Button
{
NoButton = 0, //!< No button (since QGIS 3.20)
Link = 1 << 1, //!< Link button
Unlink = 1 << 2, //!< Unlink button
SaveChildEdits = 1 << 3, //!< Save child edits button
Expand Down
1 change: 0 additions & 1 deletion src/gui/vector/qgsattributesformproperties.h
Expand Up @@ -71,7 +71,6 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
{
operator QVariant();

QgsAttributeEditorRelation::Buttons buttons = QgsAttributeEditorRelation::Button::AllButtons;
QString mRelationWidgetType;
QVariantMap mRelationWidgetConfig;
QVariant nmRelationId;
Expand Down
10 changes: 5 additions & 5 deletions tests/src/core/testqgis.cpp
Expand Up @@ -24,7 +24,7 @@
#include "qgis.h"
#include "qgsmaplayermodel.h"
#include "qgsattributeeditorelement.h"
#include "qgsattributeeditorrelation.h"
#include "qgsfieldproxymodel.h"

/**
* \ingroup UnitTests
Expand Down Expand Up @@ -451,13 +451,13 @@ void TestQgis::testQgsEnumKeyToValue()

void TestQgis::testQgsFlagValueToKeys()
{
QgsAttributeEditorRelation::Buttons buttons = QgsAttributeEditorRelation::Button::Link | QgsAttributeEditorRelation::Button::AddChildFeature;
QCOMPARE( qgsFlagValueToKeys( buttons ), QStringLiteral( "Link|AddChildFeature" ) );
QgsFieldProxyModel::Filters filters = QgsFieldProxyModel::Filter::String | QgsFieldProxyModel::Filter::Double;
QCOMPARE( qgsFlagValueToKeys( filters ), QStringLiteral( "String|Double" ) );
}
void TestQgis::testQgsFlagKeysToValue()
{
QCOMPARE( qgsFlagKeysToValue( QStringLiteral( "Link|AddChildFeature" ), QgsAttributeEditorRelation::Buttons( QgsAttributeEditorRelation::Button::AllButtons ) ), QgsAttributeEditorRelation::Button::Link | QgsAttributeEditorRelation::Button::AddChildFeature );
QCOMPARE( qgsFlagKeysToValue( QStringLiteral( "UnknownKey" ), QgsAttributeEditorRelation::Buttons( QgsAttributeEditorRelation::Button::AllButtons ) ), QgsAttributeEditorRelation::Buttons( QgsAttributeEditorRelation::Button::AllButtons ) );
QCOMPARE( qgsFlagKeysToValue( QStringLiteral( "String|Double" ), QgsFieldProxyModel::Filters( QgsFieldProxyModel::Filter::AllTypes ) ), QgsFieldProxyModel::Filter::String | QgsFieldProxyModel::Filter::Double );
QCOMPARE( qgsFlagKeysToValue( QStringLiteral( "UnknownKey" ), QgsFieldProxyModel::Filters( QgsFieldProxyModel::Filter::AllTypes ) ), QgsFieldProxyModel::Filters( QgsFieldProxyModel::Filter::AllTypes ) );
}

void TestQgis::testQMapQVariantList()
Expand Down

0 comments on commit 570846a

Please sign in to comment.