summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-12-17 16:19:27 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-01-28 07:46:27 +0000
commit8b9b27bced5227fae0f44a92a24183f38c944c02 (patch)
tree22ae2dfdb993ed237ffab8dedce7bb348896e4eb /tests/auto
parentce3402b5efc929b99d6ecb27f47e671cdcfae393 (diff)
QSizePolicy: add a transposed() method
In some situations, this allows for nicer code. It's also possible to make this constexpr in C++11, whereas the mutable transpose() would require C++14-style constexpr. The new function should also be faster, since it just swaps the member variables. Because of constexpr-function limitations, the way the return value is constructed needs to depend on the level of the compiler's C++11 support. This is not the only class that requires uniform init to provide a fully constexpr interface (QUuid and QBasicAtomic come to mind), so this should probably be generalized across Qt at some point. Added tests. [ChangeLog][QtWidgets][QSizePolicy] Added transposed() method. Change-Id: Ic1077a0d5a861e7c63bd1daeeb42b97c3a2f71ef Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
index 15bd0a8c1c..98b765a6c6 100644
--- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
+++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
@@ -45,6 +45,8 @@ private Q_SLOTS:
void defaultValues();
void getSetCheck_data() { data(); }
void getSetCheck();
+ void transposed_data() { data(); }
+ void transposed();
void dataStream();
void horizontalStretch();
void verticalStretch();
@@ -161,6 +163,26 @@ void tst_QSizePolicy::getSetCheck()
QCOMPARE(sp.expandingDirections(), ed);
}
+void tst_QSizePolicy::transposed()
+{
+ FETCH_TEST_DATA;
+
+ const QSizePolicy tr = sp.transposed();
+
+ QCOMPARE(tr.horizontalPolicy(), vp); // swapped
+ QCOMPARE(tr.verticalPolicy(), hp); // swapped
+ QCOMPARE(tr.horizontalStretch(), vst); // swapped
+ QCOMPARE(tr.verticalStretch(), hst); // swapped
+ QCOMPARE(tr.controlType(), ct); // not swapped
+ QCOMPARE(tr.hasHeightForWidth(), hfw); // not swapped (historic behavior)
+ QCOMPARE(tr.hasWidthForHeight(), wfh); // not swapped (historic behavior)
+ QCOMPARE(tr.expandingDirections(), ed); // swapped
+
+ // destructive test - keep last:
+ sp.transpose();
+ QCOMPARE(sp, tr);
+}
+
static void makeRow(QSizePolicy sp, QSizePolicy::Policy hp, QSizePolicy::Policy vp,
int hst, int vst, QSizePolicy::ControlType ct, bool hfw, bool wfh,
Qt::Orientations orients)