diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-11-22 13:00:22 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-11-25 14:28:48 +0100 |
commit | ef379f95c7621272933b06fb3edfe502b14bd145 (patch) | |
tree | efd7e5ec1b81684183a294b5379110274a7a8562 | |
parent | 01780d753e960133ae0110c6ef4292fbd2ea306c (diff) |
QPalette: always increase serial number when modifying
After 109e088c7c5d0c9325966e88d55fd9f7a58f67ea, cache keys were unique
for palettes with different private or data instances, but the key did
not change when a palette without any shared copies was modified, as
that does not create new private data structures.
To fix this, always increase the counter for the private data structure,
also when not detaching from shared copies.
Augment test case with scenario that broke.
Pick-to: 6.4
Fixes: QTBUG-108709
Change-Id: I606abfb8b1a03e515e46b10dc840a631eb31d496
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: JiDe Zhang <zhangjide@uniontech.com>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
-rw-r--r-- | src/gui/kernel/qpalette.cpp | 4 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpalette/tst_qpalette.cpp | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 081af38074..4abbcd5e65 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -62,7 +62,7 @@ public: QAtomicInt ref; QPalette::ResolveMask resolveMask = {0}; static inline int qt_palette_private_count = 0; - const int detach_no = ++qt_palette_private_count; + int detach_no = ++qt_palette_private_count; QExplicitlySharedDataPointer<Data> data; }; @@ -864,6 +864,8 @@ void QPalette::detach() if (!d->ref.deref()) delete d; d = x; + } else { + d->detach_no = ++QPalettePrivate::qt_palette_private_count; } } diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index f9b0792960..81036bee0a 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -274,6 +274,14 @@ void tst_QPalette::cacheKey() const auto defaultSerNo = defaultCacheKey >> 32; const auto defaultDetachNo = defaultCacheKey & 0xffffffff; + QPalette changeTwicePalette(defaultPalette); + changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::red); + const auto firstChangeCacheKey = changeTwicePalette.cacheKey(); + QCOMPARE_NE(firstChangeCacheKey, defaultCacheKey); + changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::green); + const auto secondChangeCacheKey = changeTwicePalette.cacheKey(); + QCOMPARE_NE(firstChangeCacheKey, secondChangeCacheKey); + QPalette copyDifferentData(defaultPalette); QPalette copyDifferentMask(defaultPalette); QPalette copyDifferentMaskAndData(defaultPalette); |