From 6670948fe312b656769ecdc9679f560ab9585e40 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 3 Jan 2018 14:00:24 -0800 Subject: Make QPalette::setBrush() check before detaching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting the same brush on the same group and role should not detach nor alter the result of QPalette::isCopyOf(). Task-number: QTBUG-56743 Change-Id: Ic2d0dd757d703b01e8c5d835a8c124b3317653f4 Reviewed-by: Friedemann Kleint Reviewed-by: Andy Shaw Reviewed-by: Richard Moe Gustavsen (cherry picked from commit c564779c071b35fddb76f4e50afda4305b634651) Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qpalette/tst_qpalette.cpp | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index f43e8d8ee6..ca6f677ba6 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -39,6 +39,7 @@ private Q_SLOTS: void roleValues(); void copySemantics(); void moveSemantics(); + void setBrush(); }; void tst_QPalette::roleValues_data() @@ -128,5 +129,35 @@ void tst_QPalette::moveSemantics() #endif } +void tst_QPalette::setBrush() +{ + QPalette p(Qt::red); + const QPalette q = p; + QVERIFY(q.isCopyOf(p)); + + // Setting a different brush will detach + p.setBrush(QPalette::Disabled, QPalette::Button, Qt::green); + QVERIFY(!q.isCopyOf(p)); + QVERIFY(q != p); + + // Check we only changed what we said we would + for (int i = 0; i < QPalette::NColorGroups; i++) + for (int j = 0; j < QPalette::NColorRoles; j++) { + const auto g = QPalette::ColorGroup(i); + const auto r = QPalette::ColorRole(j); + const auto b = p.brush(g, r); + if (g == QPalette::Disabled && r == QPalette::Button) + QCOMPARE(b, QBrush(Qt::green)); + else + QCOMPARE(b, q.brush(g, r)); + } + + const QPalette pp = p; + QVERIFY(pp.isCopyOf(p)); + // Setting the same brush won't detach + p.setBrush(QPalette::Disabled, QPalette::Button, Qt::green); + QVERIFY(pp.isCopyOf(p)); +} + QTEST_MAIN(tst_QPalette) #include "tst_qpalette.moc" -- cgit v1.2.3