diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-05-17 08:11:50 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-05-17 08:12:24 (GMT) |
commit | 25ae30256bd7980ed42a65ab73a4d4395040391a (patch) | |
tree | d33a13fdb8f98a99e71c6d5fa03471c6a1987378 /src/gui/styles/qstylehelper.cpp | |
parent | bdbe09ad2c01ae11d10511b51f8d7a3dfb27b17c (diff) | |
download | Qt-25ae30256bd7980ed42a65ab73a4d4395040391a.zip Qt-25ae30256bd7980ed42a65ab73a4d4395040391a.tar.gz Qt-25ae30256bd7980ed42a65ab73a4d4395040391a.tar.bz2 |
Optimized pixmapcache key generation for icons and styles
This re-apply commit c8d2e18c4b431870560f324a17f20904bb47ae68
from Jens that was reverted in b0f4dab4 because it did not compile.
Added the missing include to make it compile on mac
Task-number: QTBUG-9850
Diffstat (limited to 'src/gui/styles/qstylehelper.cpp')
-rw-r--r-- | src/gui/styles/qstylehelper.cpp | 62 |
1 files changed, 9 insertions, 53 deletions
diff --git a/src/gui/styles/qstylehelper.cpp b/src/gui/styles/qstylehelper.cpp index 296c51c..d09d7fa 100644 --- a/src/gui/styles/qstylehelper.cpp +++ b/src/gui/styles/qstylehelper.cpp @@ -58,67 +58,23 @@ QT_BEGIN_NAMESPACE -// internal helper. Converts an integer value to an unique string token -template <typename T> -struct HexString -{ - inline HexString(const T t) - : val(t) - {} - - inline void write(QChar *&dest) const - { - const ushort hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - const char *c = reinterpret_cast<const char *>(&val); - for (uint i = 0; i < sizeof(T); ++i) { - *dest++ = hexChars[*c & 0xf]; - *dest++ = hexChars[(*c & 0xf0) >> 4]; - ++c; - } - } - - const T val; -}; - -// specialization to enable fast concatenating of our string tokens to a string -template <typename T> -struct QConcatenable<HexString<T> > -{ - typedef HexString<T> type; - enum { ExactSize = true }; - static int size(const HexString<T> &str) { return sizeof(str.val) * 2; } - static inline void appendTo(const HexString<T> &str, QChar *&out) { str.write(out); } -}; - namespace QStyleHelper { QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size) { const QStyleOptionComplex *complexOption = qstyleoption_cast<const QStyleOptionComplex *>(option); - - QString tmp = key - % QLatin1Char('-') - % HexString<uint>(option->state) - % QLatin1Char('-') - % HexString<uint>(option->direction) - % QLatin1Char('-') - % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u) - % QLatin1Char('-') - % HexString<quint64>(option->palette.cacheKey()) - % QLatin1Char('-') - % HexString<uint>(size.width()) - % QLatin1Char('x') - % HexString<uint>(size.height()); + QString tmp = key % HexString<uint>(option->state) + % HexString<uint>(option->direction) + % HexString<uint>(complexOption ? uint(complexOption->activeSubControls) : 0u) + % HexString<quint64>(option->palette.cacheKey()) + % HexString<uint>(size.width()) + % HexString<uint>(size.height()); #ifndef QT_NO_SPINBOX if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { - tmp = tmp - % QLatin1Char('-') - % HexString<uint>(spinBox->buttonSymbols) - % QLatin1Char('-') - % HexString<uint>(spinBox->stepEnabled) - % QLatin1Char('-') - % QLatin1Char(spinBox->frame ? '1' : '0'); + tmp = tmp % HexString<uint>(spinBox->buttonSymbols) + % HexString<uint>(spinBox->stepEnabled) + % QLatin1Char(spinBox->frame ? '1' : '0'); ; } #endif // QT_NO_SPINBOX return tmp; |