diff options
author | Vitaly Fanaskov <vitaly.fanaskov@qt.io> | 2020-01-16 17:21:15 +0100 |
---|---|---|
committer | Vitaly Fanaskov <vitaly.fanaskov@qt.io> | 2020-01-17 02:22:22 +0100 |
commit | 63b0b857f3cc84315a10c9b6d988bd657e7ce998 (patch) | |
tree | c2e221ed7fd2ba5ef094d1172efa9a1b21a311d1 | |
parent | 983432effdae888a372d814ff9516abbcb7a3c29 (diff) |
QPalette: fix function swap and move operator
Additional data should also be taken into account when using move
operator and function swap. This is already implemented for move
constructor.
Task-number: QTBUG-78544
Change-Id: I24ba34b0957a8fba7e15a934f2d08222dc95650f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/gui/kernel/qpalette.h | 3 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpalette/tst_qpalette.cpp | 26 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h index c95640d383..fd0ef2e2d9 100644 --- a/src/gui/kernel/qpalette.h +++ b/src/gui/kernel/qpalette.h @@ -72,11 +72,12 @@ public: { other.d = nullptr; } inline QPalette &operator=(QPalette &&other) noexcept { - qSwap(d, other.d); return *this; + swap(other); return *this; } void swap(QPalette &other) noexcept { + qSwap(data, other.data); qSwap(d, other.d); } diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index a4764a47c0..04343727bb 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -124,23 +124,35 @@ void tst_QPalette::resolve() QVERIFY(p2ResolvedTo1 != p2); } + +static void compareAllPaletteData(const QPalette &firstPalette, const QPalette &secondPalette) +{ + QCOMPARE(firstPalette, secondPalette); + + // For historical reasons, operator== compares only brushes, but it's not enough for proper + // comparison after move/copy, because some additional data can also be moved/copied. + // Let's compare this data here. + QCOMPARE(firstPalette.resolve(), secondPalette.resolve()); + QCOMPARE(firstPalette.currentColorGroup(), secondPalette.currentColorGroup()); +} + void tst_QPalette::copySemantics() { QPalette src(Qt::red), dst; const QPalette control = src; // copy construction QVERIFY(src != dst); QVERIFY(!src.isCopyOf(dst)); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(src.isCopyOf(control)); dst = src; // copy assignment - QCOMPARE(dst, src); - QCOMPARE(dst, control); + compareAllPaletteData(dst, src); + compareAllPaletteData(dst, control); QVERIFY(dst.isCopyOf(src)); dst = QPalette(Qt::green); QVERIFY(dst != src); QVERIFY(dst != control); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(!dst.isCopyOf(src)); QVERIFY(src.isCopyOf(control)); } @@ -150,13 +162,13 @@ void tst_QPalette::moveSemantics() QPalette src(Qt::red), dst; const QPalette control = src; QVERIFY(src != dst); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(!dst.isCopyOf(src)); QVERIFY(!dst.isCopyOf(control)); dst = std::move(src); // move assignment QVERIFY(!dst.isCopyOf(src)); // isCopyOf() works on moved-from palettes, too QVERIFY(dst.isCopyOf(control)); - QCOMPARE(dst, control); + compareAllPaletteData(dst, control); src = control; // check moved-from 'src' can still be assigned to (doesn't crash) QVERIFY(src.isCopyOf(dst)); QVERIFY(src.isCopyOf(control)); @@ -164,7 +176,7 @@ void tst_QPalette::moveSemantics() QVERIFY(!src.isCopyOf(dst)); QVERIFY(!src.isCopyOf(dst2)); QVERIFY(!src.isCopyOf(control)); - QCOMPARE(dst2, control); + compareAllPaletteData(dst2, control); QVERIFY(dst2.isCopyOf(dst)); QVERIFY(dst2.isCopyOf(control)); // check moved-from 'src' can still be destroyed (doesn't crash) |