diff --git a/src/declarativesizepolicy.cpp b/src/declarativesizepolicy.cpp new file mode 100644 index 0000000..dd20e97 --- /dev/null +++ b/src/declarativesizepolicy.cpp @@ -0,0 +1,182 @@ +#include "declarativesizepolicy_p.h" + +#include + +DeclarativeSizePolicy::DeclarativeSizePolicy(QWidget *extendedWidget, QObject *parent) + : QObject(parent) + , m_extendedWidget(extendedWidget) +{ + Q_ASSERT(m_extendedWidget); +} + +DeclarativeSizePolicy::ControlType DeclarativeSizePolicy::controlType() const +{ + Q_ASSERT(m_extendedWidget); + + return static_cast(m_extendedWidget->sizePolicy().controlType()); +} + +DeclarativeSizePolicy::Policy DeclarativeSizePolicy::horizontalPolicy() const +{ + Q_ASSERT(m_extendedWidget); + + return static_cast(m_extendedWidget->sizePolicy().horizontalPolicy()); +} + +DeclarativeSizePolicy::Policy DeclarativeSizePolicy::verticalPolicy() const +{ + Q_ASSERT(m_extendedWidget); + + return static_cast(m_extendedWidget->sizePolicy().verticalPolicy()); +} + +Qt::Orientations DeclarativeSizePolicy::expandingDirections() const +{ + Q_ASSERT(m_extendedWidget); + + return m_extendedWidget->sizePolicy().expandingDirections(); +} + +bool DeclarativeSizePolicy::hasHeightForWidth() const +{ + Q_ASSERT(m_extendedWidget); + + return m_extendedWidget->sizePolicy().hasHeightForWidth(); +} + +bool DeclarativeSizePolicy::hasWidthForHeight() const +{ + Q_ASSERT(m_extendedWidget); + + return m_extendedWidget->sizePolicy().hasWidthForHeight(); +} + +int DeclarativeSizePolicy::horizontalStretch() const +{ + Q_ASSERT(m_extendedWidget); + + return m_extendedWidget->sizePolicy().horizontalStretch(); +} + +int DeclarativeSizePolicy::verticalStretch() const +{ + + Q_ASSERT(m_extendedWidget); + + return m_extendedWidget->sizePolicy().verticalStretch(); +} + +bool DeclarativeSizePolicy::retainSizeWhenHidden() const +{ + Q_ASSERT(m_extendedWidget); + + return m_extendedWidget->sizePolicy().retainSizeWhenHidden(); +} + +void DeclarativeSizePolicy::setControlType(DeclarativeSizePolicy::ControlType controlType) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.controlType() == static_cast(controlType)) + return; + policy.setControlType(static_cast(controlType)); + m_extendedWidget->setSizePolicy(policy); + emit controlTypeChanged(controlType); +} + +void DeclarativeSizePolicy::setHorizontalPolicy(DeclarativeSizePolicy::Policy horizontalPolicy) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.horizontalPolicy() == static_cast(horizontalPolicy)) + return; + + const Qt::Orientations oldExpandingDirections = policy.expandingDirections(); + policy.setHorizontalPolicy(static_cast(horizontalPolicy)); + const Qt::Orientations newExpandingDirections = policy.expandingDirections(); + m_extendedWidget->setSizePolicy(policy); + + emit horizontalPolicyChanged(horizontalPolicy); + if (newExpandingDirections != oldExpandingDirections) + emit expandingDirectionsChanged(newExpandingDirections); +} + +void DeclarativeSizePolicy::setVerticalPolicy(DeclarativeSizePolicy::Policy verticalPolicy) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.verticalPolicy() == static_cast(verticalPolicy)) + return; + + const Qt::Orientations oldExpandingDirections = policy.expandingDirections(); + policy.setVerticalPolicy(static_cast(verticalPolicy)); + const Qt::Orientations newExpandingDirections = policy.expandingDirections(); + m_extendedWidget->setSizePolicy(policy); + + emit verticalPolicyChanged(verticalPolicy); + if (newExpandingDirections != oldExpandingDirections) + emit expandingDirectionsChanged(newExpandingDirections); +} + +void DeclarativeSizePolicy::setHeightForWidth(bool heightForWidth) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.hasHeightForWidth() == heightForWidth) + return; + policy.setHeightForWidth(heightForWidth); + m_extendedWidget->setSizePolicy(policy); + emit hasHeightForWidthChanged(heightForWidth); +} + +void DeclarativeSizePolicy::setWidthForHeight(bool widthForHeight) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.hasWidthForHeight() == widthForHeight) + return; + policy.setWidthForHeight(widthForHeight); + m_extendedWidget->setSizePolicy(policy); + emit hasWidthForHeightChanged(widthForHeight); +} + +void DeclarativeSizePolicy::setHorizontalStretch(int horizontalStretch) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.horizontalStretch() == horizontalStretch) + return; + policy.setHorizontalStretch(horizontalStretch); + m_extendedWidget->setSizePolicy(policy); + emit horizontalStretchChanged(horizontalStretch); +} + +void DeclarativeSizePolicy::setVerticalStretch(int verticalStretch) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.verticalStretch() == verticalStretch) + return; + policy.setVerticalStretch(verticalStretch); + m_extendedWidget->setSizePolicy(policy); + emit verticalStretchChanged(verticalStretch); +} + +void DeclarativeSizePolicy::setRetainSizeWhenHidden(bool retainSizeWhenHidden) +{ + Q_ASSERT(m_extendedWidget); + + QSizePolicy policy = m_extendedWidget->sizePolicy(); + if (policy.retainSizeWhenHidden() == retainSizeWhenHidden) + return; + policy.setRetainSizeWhenHidden(retainSizeWhenHidden); + m_extendedWidget->setSizePolicy(policy); + emit retainSizeWhenHiddenChanged(retainSizeWhenHidden); +} diff --git a/src/declarativesizepolicy_p.h b/src/declarativesizepolicy_p.h new file mode 100644 index 0000000..3e3573c --- /dev/null +++ b/src/declarativesizepolicy_p.h @@ -0,0 +1,102 @@ +#ifndef DECLARATIVESIZEPOLICYEXTENSION_H +#define DECLARATIVESIZEPOLICYEXTENSION_H + +#include + +class DeclarativeSizePolicy : public QObject +{ + Q_OBJECT + + Q_PROPERTY(ControlType controlType READ controlType WRITE setControlType NOTIFY controlTypeChanged) + + Q_PROPERTY(Policy horizontalPolicy READ horizontalPolicy WRITE setHorizontalPolicy NOTIFY horizontalPolicyChanged) + Q_PROPERTY(Policy verticalPolicy READ verticalPolicy WRITE setVerticalPolicy NOTIFY verticalPolicyChanged) + + Q_PROPERTY(Qt::Orientations expandingDirections READ expandingDirections STORED false NOTIFY expandingDirectionsChanged) + + Q_PROPERTY(bool hasHeightForWidth READ hasHeightForWidth WRITE setHeightForWidth NOTIFY hasHeightForWidthChanged) + Q_PROPERTY(bool hasWidthForHeight READ hasWidthForHeight WRITE setWidthForHeight NOTIFY hasWidthForHeightChanged) + + Q_PROPERTY(int horizontalStretch READ horizontalStretch WRITE setHorizontalStretch NOTIFY horizontalStretchChanged) + Q_PROPERTY(int verticalStretch READ verticalStretch WRITE setVerticalStretch NOTIFY verticalStretchChanged) + + Q_PROPERTY(bool retainSizeWhenHidden READ retainSizeWhenHidden WRITE setRetainSizeWhenHidden NOTIFY retainSizeWhenHiddenChanged) + +public: + enum PolicyFlag { + GrowFlag = 1, + ExpandFlag = 2, + ShrinkFlag = 4, + IgnoreFlag = 8 + }; + + enum Policy { + Fixed = 0, + Minimum = GrowFlag, + Maximum = ShrinkFlag, + Preferred = GrowFlag | ShrinkFlag, + MinimumExpanding = GrowFlag | ExpandFlag, + Expanding = GrowFlag | ShrinkFlag | ExpandFlag, + Ignored = ShrinkFlag | GrowFlag | IgnoreFlag + }; + Q_ENUM(Policy) + + enum ControlType { + DefaultType = 0x00000001, + ButtonBox = 0x00000002, + CheckBox = 0x00000004, + ComboBox = 0x00000008, + Frame = 0x00000010, + GroupBox = 0x00000020, + Label = 0x00000040, + Line = 0x00000080, + LineEdit = 0x00000100, + PushButton = 0x00000200, + RadioButton = 0x00000400, + Slider = 0x00000800, + SpinBox = 0x00001000, + TabWidget = 0x00002000, + ToolButton = 0x00004000 + }; + Q_ENUM(ControlType) + Q_DECLARE_FLAGS(ControlTypes, ControlType) + Q_FLAG(ControlTypes) + + explicit DeclarativeSizePolicy(QWidget* extendedWidget, QObject* parent); + + ControlType controlType() const; + Policy horizontalPolicy() const; + Policy verticalPolicy() const; + Qt::Orientations expandingDirections() const; + bool hasHeightForWidth() const; + bool hasWidthForHeight() const; + int horizontalStretch() const; + int verticalStretch() const; + bool retainSizeWhenHidden() const; + +public slots: + void setControlType(ControlType controlType); + void setHorizontalPolicy(Policy horizontalPolicy); + void setVerticalPolicy(Policy verticalPolicy); + void setHeightForWidth(bool heightForWidth); + void setWidthForHeight(bool widthForHeight); + void setHorizontalStretch(int horizontalStretch); + void setVerticalStretch(int verticalStretch); + void setRetainSizeWhenHidden(bool retainSizeWhenHidden); + +signals: + void controlTypeChanged(ControlType controlType); + void horizontalPolicyChanged(Policy horizontalPolicy); + void verticalPolicyChanged(Policy verticalPolicy); + void expandingDirectionsChanged(Qt::Orientations expandingDirections); + void hasHeightForWidthChanged(bool hasHeightForWidth); + void hasWidthForHeightChanged(bool hasWidthForHeight); + void horizontalStretchChanged(int horizontalStretch); + void verticalStretchChanged(int verticalStretch); + void retainSizeWhenHiddenChanged(bool retainSizeWhenHidden); + +private: + QWidget* m_extendedWidget; +}; + +#endif // DECLARATIVESIZEPOLICYEXTENSION_H diff --git a/src/declarativewidgetextension.cpp b/src/declarativewidgetextension.cpp index e5d46c3..00dd09c 100644 --- a/src/declarativewidgetextension.cpp +++ b/src/declarativewidgetextension.cpp @@ -28,6 +28,7 @@ #include "declarativewidgetextension.h" #include "declarativeactionitem_p.h" +#include "declarativesizepolicy_p.h" #include "defaultobjectcontainer_p.h" #include "defaultwidgetcontainer.h" #include "objectadaptors_p.h" @@ -94,6 +95,7 @@ class WidgetContainerDelegate : public DefaultObjectContainer DeclarativeWidgetExtension::DeclarativeWidgetExtension(QObject *parent) : DeclarativeObjectExtension(new WidgetContainerDelegate(new DefaultWidgetContainer(qobject_cast(parent))), parent) + , m_sizePolicy(nullptr) { parent->installEventFilter(this); } @@ -229,6 +231,15 @@ bool DeclarativeWidgetExtension::eventFilter(QObject *watched, QEvent *event) return false; } +DeclarativeSizePolicy *DeclarativeWidgetExtension::sizePolicy() +{ + if (!m_sizePolicy) { + m_sizePolicy = new DeclarativeSizePolicy(extendedWidget(), this); + } + + return m_sizePolicy; +} + DeclarativeWidgetExtension::DeclarativeWidgetExtension(WidgetContainerInterface *widgetContainer, QObject *parent) : DeclarativeObjectExtension(new WidgetContainerDelegate(widgetContainer), parent) { diff --git a/src/declarativewidgetextension.h b/src/declarativewidgetextension.h index 00bf4bf..3e16840 100644 --- a/src/declarativewidgetextension.h +++ b/src/declarativewidgetextension.h @@ -33,6 +33,7 @@ #include +class DeclarativeSizePolicy; class WidgetContainerInterface; QT_BEGIN_NAMESPACE @@ -54,6 +55,7 @@ class DeclarativeWidgetExtension : public DeclarativeObjectExtension Q_PROPERTY(int height READ height WRITE setHeight NOTIFY sizeChanged) Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(DeclarativeSizePolicy *sizePolicy READ sizePolicy CONSTANT) Q_CLASSINFO("DefaultProperty", "data") @@ -82,6 +84,8 @@ class DeclarativeWidgetExtension : public DeclarativeObjectExtension bool eventFilter(QObject *watched, QEvent *event); + DeclarativeSizePolicy *sizePolicy(); + protected: explicit DeclarativeWidgetExtension(WidgetContainerInterface *widgetContainer, QObject *parent = 0); @@ -90,6 +94,9 @@ class DeclarativeWidgetExtension : public DeclarativeObjectExtension void sizeChanged(); void geometryChanged(); void visibleChanged(bool visible); + + private: + DeclarativeSizePolicy *m_sizePolicy; }; #endif // DECLARATIVEWIDGETEXTENSION_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 02a7be2..ba62a9e 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -51,6 +51,7 @@ #include "declarativeqmlcontext_p.h" #include "declarativequickwidgetextension_p.h" #include "declarativeseparator_p.h" +#include "declarativesizepolicy_p.h" #include "declarativespaceritem_p.h" #include "declarativestackedlayout_p.h" #include "declarativestatusbar_p.h" @@ -123,6 +124,8 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterUncreatableType(uri, 1, 0, "LayoutContentMargins", "Grouped Property"); qmlRegisterUncreatableType(uri, 1, 0, "HeaderView", ""); qmlRegisterUncreatableType(uri, 1, 0, "Layout", "For access of SizeConstraint enum"); + qmlRegisterUncreatableType(uri, 1, 0, "QSizePolicy", "Cannot create QSizePolicy, it is a Q_GADGET"); + qmlRegisterUncreatableType(uri, 1, 0, "SizePolicy", "Cannot create SizePolicy, it wraps QSizePolicy"); // core qmlRegisterType(uri, 1, 0, "Timer"); diff --git a/src/src.pro b/src/src.pro index d8c0224..6d5919b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -85,7 +85,8 @@ HEADERS = \ stackedwidgetwidgetcontainer_p.h \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ - widgetcontainerinterface_p.h + widgetcontainerinterface_p.h \ + declarativesizepolicy_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -135,4 +136,5 @@ SOURCES = \ scrollareawidgetcontainer.cpp \ stackedwidgetwidgetcontainer.cpp \ staticdialogmethodattached.cpp \ - toolbarwidgetcontainer.cpp + toolbarwidgetcontainer.cpp \ + declarativesizepolicy.cpp diff --git a/tests/auto/layouts/tst_layouts.cpp b/tests/auto/layouts/tst_layouts.cpp index 5fc91e4..9e8f3f0 100644 --- a/tests/auto/layouts/tst_layouts.cpp +++ b/tests/auto/layouts/tst_layouts.cpp @@ -38,6 +38,7 @@ #include #include #include +#include typedef QSharedPointer QWidgetPtr; Q_DECLARE_METATYPE(QWidgetPtr) @@ -62,6 +63,8 @@ private slots: void stackedLayout(); void stackedWidget_data(); void stackedWidget(); + void sizePolicy_data(); + void sizePolicy(); private: QQmlEngine* m_qmlEngine; @@ -71,6 +74,7 @@ private slots: void compareLayoutItems(QLayoutItem* a, QLayoutItem* b); void compareWidgets(QWidget* a, QWidget* b); void compareGeometry(const QRect& a, const QRect& b); + void compareSizePolicy(const QSizePolicy& aPolicy, const QSizePolicy& bPolicy); }; tst_Layouts::tst_Layouts() @@ -210,6 +214,108 @@ void tst_Layouts::stackedWidget() testLayouts(uiWidget, declarativeWidget); } +void tst_Layouts::sizePolicy_data() +{ + // QSizePolicy::ControlType is not registered with the meta-type system. + QTest::addColumn("controlType"); + QTest::addColumn("horizontalPolicy"); + QTest::addColumn("verticalPolicy"); + QTest::addColumn("hasHeightForWidth"); + QTest::addColumn("hasWidthForHeight"); + QTest::addColumn("horizontalStretch"); + QTest::addColumn("verticalStretch"); + QTest::addColumn("retainSizeWhenHidden"); + + QTest::addColumn("declarativeControlType"); + QTest::addColumn("declarativeHorizontalPolicy"); + QTest::addColumn("declarativeVerticalPolicy"); + + QTest::newRow("Default") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Fixed << false << false << 0 << 0 << false + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; + QTest::newRow("Control Type") << (int) QSizePolicy::ToolButton << QSizePolicy::Fixed << QSizePolicy::Fixed << false << false << 0 << 0 << false + << "SizePolicy.ToolButton" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; + QTest::newRow("Horizontal Policy") << (int) QSizePolicy::DefaultType << QSizePolicy::Ignored << QSizePolicy::Fixed << false << false << 0 << 0 << false + << "SizePolicy.DefaultType" << "SizePolicy.Ignored" << "SizePolicy.Fixed"; + QTest::newRow("Vertical Policy") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Ignored << false << false << 0 << 0 << false + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Ignored"; + QTest::newRow("hasHeightForWidth") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Fixed << true << false << 0 << 0 << false + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; + QTest::newRow("hasWidthForHeight") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Fixed << false << true << 0 << 0 << false + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; + QTest::newRow("Horizontal Stretch") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Fixed << false << false << 255 << 0 << false + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; + QTest::newRow("Vertical Stretch") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Fixed << false << false << 0 << 255 << false + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; + QTest::newRow("retainSizeWhenHidden") << (int) QSizePolicy::DefaultType << QSizePolicy::Fixed << QSizePolicy::Fixed << false << false << 0 << 0 << true + << "SizePolicy.DefaultType" << "SizePolicy.Fixed" << "SizePolicy.Fixed"; +} + +void tst_Layouts::sizePolicy() +{ + auto printErrors = [](const QQmlComponent &component) { + if (component.isError()) { + for (auto error : component.errors()) { + QWARN(qPrintable(error.toString())); + } + } + }; + + QFETCH(int, controlType); + QFETCH(QSizePolicy::Policy, horizontalPolicy); + QFETCH(QSizePolicy::Policy, verticalPolicy); + QFETCH(bool, hasHeightForWidth); + QFETCH(bool, hasWidthForHeight); + QFETCH(int, horizontalStretch); + QFETCH(int, verticalStretch); + QFETCH(bool, retainSizeWhenHidden); + + QFETCH(QString, declarativeControlType); + QFETCH(QString, declarativeHorizontalPolicy); + QFETCH(QString, declarativeVerticalPolicy); + + QSizePolicy aPolicy(horizontalPolicy, verticalPolicy, (QSizePolicy::ControlType) controlType); + aPolicy.setHeightForWidth(hasHeightForWidth); + aPolicy.setWidthForHeight(hasWidthForHeight); + aPolicy.setHorizontalStretch(horizontalStretch); + aPolicy.setVerticalStretch(verticalStretch); + aPolicy.setRetainSizeWhenHidden(retainSizeWhenHidden); + + QString declarativePolicy = +QStringLiteral(R"( +sizePolicy { + controlType: %1 + horizontalPolicy: %2 + verticalPolicy: %3 + hasHeightForWidth: %4 + hasWidthForHeight: %5 + horizontalStretch: %6 + verticalStretch: %7 + retainSizeWhenHidden: %8 +})") + .arg(declarativeControlType) + .arg(declarativeHorizontalPolicy) + .arg(declarativeVerticalPolicy) + .arg(hasHeightForWidth ? "true" : "false") + .arg(hasWidthForHeight ? "true" : "false") + .arg(horizontalStretch) + .arg(verticalStretch) + .arg(retainSizeWhenHidden ? "true" : "false"); + + QQmlComponent component(m_qmlEngine); + component.setData( + QStringLiteral("import QtWidgets 1.0; Widget { %1 }") + .arg(declarativePolicy).toUtf8() + , QUrl()); + printErrors(component); + + QScopedPointer widget(qobject_cast(component.create())); + QVERIFY(!widget.isNull()); + + QSizePolicy bPolicy = widget->sizePolicy(); + + compareSizePolicy(aPolicy, bPolicy); +} + void tst_Layouts::testLayouts(QWidgetPtr uiWidget, QWidgetPtr declarativeWidget) { QVERIFY(uiWidget != nullptr); @@ -353,6 +459,51 @@ void tst_Layouts::compareGeometry(const QRect &a, const QRect &b) .arg(b.height()))); } +void tst_Layouts::compareSizePolicy(const QSizePolicy& aPolicy, const QSizePolicy& bPolicy) +{ + QVERIFY2(aPolicy.expandingDirections() == bPolicy.expandingDirections() + , qPrintable(QStringLiteral("Expanding directions do not match (%1 != %2") + .arg(aPolicy.expandingDirections()) + .arg(bPolicy.expandingDirections()))); + QVERIFY2(aPolicy.hasHeightForWidth() == bPolicy.hasHeightForWidth() + , qPrintable(QStringLiteral("hasHeightForWidth does not match (%1 != %2") + .arg(aPolicy.hasHeightForWidth()) + .arg(bPolicy.hasHeightForWidth()))); + QVERIFY2(aPolicy.hasWidthForHeight() == bPolicy.hasWidthForHeight() + , qPrintable(QStringLiteral("hasWidthForHeight does not match (%1 != %2") + .arg(aPolicy.hasWidthForHeight()) + .arg(bPolicy.hasWidthForHeight()))); + QVERIFY2(aPolicy.horizontalPolicy() == bPolicy.horizontalPolicy() + , qPrintable(QStringLiteral("horizontalPolicy does not match (%1 != %2") + .arg(aPolicy.horizontalPolicy()) + .arg(bPolicy.horizontalPolicy()))); + QVERIFY2(aPolicy.horizontalStretch() == bPolicy.horizontalStretch() + , qPrintable(QStringLiteral("horizontalStretch does not match (%1 != %2") + .arg(aPolicy.horizontalStretch()) + .arg(bPolicy.horizontalStretch()))); + QVERIFY2(aPolicy.horizontalStretch() == bPolicy.horizontalStretch() + , qPrintable(QStringLiteral("horizontalStretch does not match (%1 != %2") + .arg(aPolicy.horizontalStretch()) + .arg(bPolicy.horizontalStretch()))); + QVERIFY2(aPolicy.retainSizeWhenHidden() == bPolicy.retainSizeWhenHidden() + , qPrintable(QStringLiteral("retainSizeWhenHidden does not match (%1 != %2") + .arg(aPolicy.retainSizeWhenHidden()) + .arg(bPolicy.retainSizeWhenHidden()))); + QVERIFY2(aPolicy.verticalPolicy() == bPolicy.verticalPolicy() + , qPrintable(QStringLiteral("verticalPolicy does not match (%1 != %2") + .arg(aPolicy.verticalPolicy()) + .arg(bPolicy.verticalPolicy()))); + QVERIFY2(aPolicy.verticalStretch() == bPolicy.verticalStretch() + , qPrintable(QStringLiteral("verticalStretch does not match (%1 != %2") + .arg(aPolicy.verticalStretch()) + .arg(bPolicy.verticalStretch()))); + QVERIFY2(aPolicy.controlType() == bPolicy.controlType() + , qPrintable(QStringLiteral("controlType does not match (%1 != %2") + .arg(aPolicy.controlType()) + .arg(bPolicy.controlType()))); + QVERIFY2(aPolicy == bPolicy, "Expected size policy to match"); +} + QTEST_MAIN(tst_Layouts) #include "tst_layouts.moc"