Skip to content

Commit

Permalink
QLayout: mark unsetContentsMargins as the RESET function
Browse files Browse the repository at this point in the history
contentsMargins is a Q_PROPERTY on a QLayout. Qt 6.1 introduced
QLayout::unsetContentsMargins() to reset the contents margins to the
"default" ones (that the user can't know); that's the textbook
description of a RESET function for the property.

Add some tests also for unsetContentsMargins.

[ChangeLog][QtWidgets][QLayout] The unsetContentsMargins() function now
acts as the RESET function for the contentsMargins property.

Change-Id: I463d88363c11f4a15ad3d6af71401d8698de1d41
Reviewed-by: Fabian Kosmale <[email protected]>
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
dangelog committed Apr 21, 2021
1 parent 1a65a4f commit 284d4e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/widgets/kernel/qlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Q_WIDGETS_EXPORT QLayout : public QObject, public QLayoutItem
Q_DECLARE_PRIVATE(QLayout)

Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
Q_PROPERTY(QMargins contentsMargins READ contentsMargins WRITE setContentsMargins)
Q_PROPERTY(QMargins contentsMargins READ contentsMargins WRITE setContentsMargins RESET unsetContentsMargins)
Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
public:
enum SizeConstraint {
Expand Down
17 changes: 17 additions & 0 deletions tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QTest>

#include <qcoreapplication.h>
#include <qmetaobject.h>
#include <qdebug.h>
#include <qboxlayout.h>
#include <qmenubar.h>
Expand Down Expand Up @@ -248,6 +249,22 @@ void tst_QLayout::setContentsMargins()

layout.setContentsMargins(52, 53, 54, 55);
QVERIFY(!layout.invalidated);

MyLayout otherLayout; // with default contents margins
QVERIFY(layout.contentsMargins() != otherLayout.contentsMargins());
layout.unsetContentsMargins();
QCOMPARE(layout.contentsMargins(), otherLayout.contentsMargins());

layout.setContentsMargins(10, 20, 30, 40);
QVERIFY(layout.contentsMargins() != otherLayout.contentsMargins());

int contentsMarginsPropertyIndex = QLayout::staticMetaObject.indexOfProperty("contentsMargins");
QVERIFY(contentsMarginsPropertyIndex >= 0);
QMetaProperty contentsMarginsProperty = QLayout::staticMetaObject.property(contentsMarginsPropertyIndex);
QVERIFY(contentsMarginsProperty.isValid());
QVERIFY(contentsMarginsProperty.isResettable());
QVERIFY(contentsMarginsProperty.reset(&layout));
QCOMPARE(layout.contentsMargins(), otherLayout.contentsMargins());
}

class EventReceiver : public QObject
Expand Down

0 comments on commit 284d4e7

Please sign in to comment.