summaryrefslogtreecommitdiffstats
path: root/src/gui/styles/qstylehelper.cpp
diff options
context:
space:
mode:
authorHarald Fernengel <harald.fernengel@nokia.com>2010-02-11 16:31:30 (GMT)
committerHarald Fernengel <harald.fernengel@nokia.com>2010-03-03 14:16:33 (GMT)
commitaee5766de0ab6c942ae3e3747162871651a4ab74 (patch)
treeb64ac2b8989844ebf7e0f0ac047b146c4dd74849 /src/gui/styles/qstylehelper.cpp
parent5d1735d6cf1820107145e7fdfe41ac502d0020f9 (diff)
downloadQt-aee5766de0ab6c942ae3e3747162871651a4ab74.zip
Qt-aee5766de0ab6c942ae3e3747162871651a4ab74.tar.gz
Qt-aee5766de0ab6c942ae3e3747162871651a4ab74.tar.bz2
Speed up creation of the pixmap cache key
As discussed with Jens and Joao Reviewed-by: Robert Griebl
Diffstat (limited to 'src/gui/styles/qstylehelper.cpp')
-rw-r--r--src/gui/styles/qstylehelper.cpp64
1 files changed, 55 insertions, 9 deletions
diff --git a/src/gui/styles/qstylehelper.cpp b/src/gui/styles/qstylehelper.cpp
index 071ec23..359e7e1 100644
--- a/src/gui/styles/qstylehelper.cpp
+++ b/src/gui/styles/qstylehelper.cpp
@@ -44,6 +44,7 @@
#include <qstyleoption.h>
#include <qpainter.h>
#include <qpixmapcache.h>
+#include <qstringbuilder.h>
#include <private/qmath_p.h>
#include <private/qstyle_p.h>
#include <qmath.h>
@@ -56,22 +57,67 @@
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 = QString::fromLatin1("%1-%2-%3-%4-%5-%6x%7").arg(key).arg(uint(option->state)).arg(option->direction)
- .arg(complexOption ? uint(complexOption->activeSubControls) : uint(0))
- .arg(option->palette.cacheKey()).arg(size.width()).arg(size.height());
+
+ 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());
+
#ifndef QT_NO_SPINBOX
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
- tmp.append(QLatin1Char('-'));
- tmp.append(QString::number(spinBox->buttonSymbols));
- tmp.append(QLatin1Char('-'));
- tmp.append(QString::number(spinBox->stepEnabled));
- tmp.append(QLatin1Char('-'));
- tmp.append(QLatin1Char(spinBox->frame ? '1' : '0'));
+ tmp = tmp
+ % QLatin1Char('-')
+ % HexString<uint>(spinBox->buttonSymbols)
+ % QLatin1Char('-')
+ % HexString<uint>(spinBox->stepEnabled)
+ % QLatin1Char('-')
+ % QLatin1Char(spinBox->frame ? '1' : '0');
}
#endif // QT_NO_SPINBOX
return tmp;