diff options
author | Alejandro Exojo <alex@vikingsoftware.com> | 2018-07-11 17:33:29 +0200 |
---|---|---|
committer | Alejandro Exojo (Viking Software) <alex@vikingsoftware.com> | 2018-12-31 14:30:26 +0000 |
commit | 7f34e8b58ca51b8ce0b0d7757ae903ac9e940c80 (patch) | |
tree | 0fe8d861f337b6a02c178735254baedec662205b | |
parent | 7ef0b575b38d267bd3dc14ff46935d556562ff00 (diff) |
Fix and unit test QPalette::resolve
The function is setting the brushes correctly in the return value, but
without updating the resolve_mask, making it return wrong results in
functions like isBrushSet or the debug operator.
Added a unit test for the member function, since the class is still
mostly untested, and clarified the reference documentation of what the
function is supposed to do.
Change-Id: Iaa820dc44f095e125f9375cb00da5569986803c6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/gui/kernel/qpalette.cpp | 4 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpalette/tst_qpalette.cpp | 38 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 16b1f847bd..b4383c5bfc 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -941,7 +941,8 @@ qint64 QPalette::cacheKey() const } /*! - Returns a new QPalette that has attributes copied from \a other. + Returns a new QPalette that is a union of this instance and \a other. + Color roles set in this instance take precedence. */ QPalette QPalette::resolve(const QPalette &other) const { @@ -959,6 +960,7 @@ QPalette QPalette::resolve(const QPalette &other) const if (!(data.resolve_mask & (1<<role))) for(int grp = 0; grp < (int)NColorGroups; grp++) palette.d->br[grp][role] = other.d->br[grp][role]; + palette.data.resolve_mask |= other.data.resolve_mask; return palette; } diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index a0ac1b3631..7f29b1c24e 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -37,6 +37,7 @@ class tst_QPalette : public QObject private Q_SLOTS: void roleValues_data(); void roleValues(); + void resolve(); void copySemantics(); void moveSemantics(); void setBrush(); @@ -80,6 +81,43 @@ void tst_QPalette::roleValues() QCOMPARE(role, value); } +void tst_QPalette::resolve() +{ + QPalette p1; + p1.setBrush(QPalette::WindowText, Qt::green); + p1.setBrush(QPalette::Button, Qt::green); + + QVERIFY(p1.isBrushSet(QPalette::Active, QPalette::WindowText)); + QVERIFY(p1.isBrushSet(QPalette::Active, QPalette::Button)); + + QPalette p2; + p2.setBrush(QPalette::WindowText, Qt::red); + + QVERIFY(p2.isBrushSet(QPalette::Active, QPalette::WindowText)); + QVERIFY(!p2.isBrushSet(QPalette::Active, QPalette::Button)); + + QPalette p1ResolvedTo2 = p1.resolve(p2); + // p1ResolvedTo2 gets everything from p1 and nothing copied from p2 because + // it already has a WindowText. That is two brushes, and to the same value + // as p1. + QCOMPARE(p1ResolvedTo2, p1); + QVERIFY(p1ResolvedTo2.isBrushSet(QPalette::Active, QPalette::WindowText)); + QCOMPARE(p1.windowText(), p1ResolvedTo2.windowText()); + QVERIFY(p1ResolvedTo2.isBrushSet(QPalette::Active, QPalette::Button)); + QCOMPARE(p1.button(), p1ResolvedTo2.button()); + + QPalette p2ResolvedTo1 = p2.resolve(p1); + // p2ResolvedTo1 gets the WindowText set, and to the same value as the + // original p2, however, Button gets set from p1. + QVERIFY(p2ResolvedTo1.isBrushSet(QPalette::Active, QPalette::WindowText)); + QCOMPARE(p2.windowText(), p2ResolvedTo1.windowText()); + QVERIFY(p2ResolvedTo1.isBrushSet(QPalette::Active, QPalette::Button)); + QCOMPARE(p1.button(), p2ResolvedTo1.button()); + + QVERIFY(p2ResolvedTo1 != p1); + QVERIFY(p2ResolvedTo1 != p2); +} + void tst_QPalette::copySemantics() { QPalette src(Qt::red), dst; |