From a84181407f51cc855a6ddb2033a7aa6738354602 Mon Sep 17 00:00:00 2001 From: aavit Date: Wed, 3 Nov 2010 16:18:02 +0100 Subject: Hide nonfunctional links, and improve html --- tests/arthur/baselineserver/src/htmlpage.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/arthur/baselineserver/src/htmlpage.cpp b/tests/arthur/baselineserver/src/htmlpage.cpp index 6b965b4..00d07f1 100644 --- a/tests/arthur/baselineserver/src/htmlpage.cpp +++ b/tests/arthur/baselineserver/src/htmlpage.cpp @@ -92,10 +92,12 @@ void HTMLPage::writeHeader(const ImageItem &item) out << "

Host: " << plat.hostName << " [" << address << "] OS: " << plat.osName << " [enum: " << plat.osVersion << "]

\n"; out << "

Qt version: " << plat.qtVersion << " [commit: " << plat.gitCommit << "] Build key: \"" << plat.buildKey << "\"

\n"; out << "

Engine: " << item.engineAsString() << " Format: " << item.formatAsString() << "

\n\n"; +#if 0 out << "

Update all baselines
"; +#endif out << "\n" "\n" "\n" @@ -129,11 +131,14 @@ void HTMLPage::addItem(const QString &baseline, const QString &rendered, const I out << "\n"; out << "\n"; - out << "\n\n"; + << "&url=" << pageUrl << "\">Blacklist test" +#endif + << "\n"; + out << "\n\n"; QMutableVectorIterator it(imageItems); while (it.hasNext()) { @@ -164,7 +169,7 @@ void HTMLPage::end() } else { out << "Test passed"; } - out << ""; + out << "\n"; } writeFooter(); -- cgit v0.12 From 111270e240320831038a47f7f0848a4f429d25d7 Mon Sep 17 00:00:00 2001 From: aavit Date: Fri, 5 Nov 2010 15:33:41 +0100 Subject: Add even more platform info, and make it expandable. --- tests/arthur/baselineserver/src/baselineserver.cpp | 29 +++++--- tests/arthur/baselineserver/src/baselineserver.h | 2 +- tests/arthur/baselineserver/src/htmlpage.cpp | 11 ++- tests/arthur/baselineserver/src/main.cpp | 3 +- tests/arthur/common/baselineprotocol.cpp | 86 ++++++++++++---------- tests/arthur/common/baselineprotocol.h | 26 ++++--- tests/auto/lancelot/lancelot.pro | 1 + 7 files changed, 89 insertions(+), 69 deletions(-) diff --git a/tests/arthur/baselineserver/src/baselineserver.cpp b/tests/arthur/baselineserver/src/baselineserver.cpp index dd26a85..03d6499 100644 --- a/tests/arthur/baselineserver/src/baselineserver.cpp +++ b/tests/arthur/baselineserver/src/baselineserver.cpp @@ -133,24 +133,29 @@ BaselineHandler::BaselineHandler(int socketDescriptor) proto.socket.setSocketDescriptor(socketDescriptor); } -QString BaselineHandler::logtime() +const char *BaselineHandler::logtime() { - return QTime::currentTime().toString(QLS("mm:ss.zzz")); + return 0; + //return QTime::currentTime().toString(QLS("mm:ss.zzz")); } void BaselineHandler::receiveRequest() { if (!connectionEstablished) { if (!proto.acceptConnection(&plat)) { - qWarning() << runId << logtime() << "Accepting new connection failed. " << proto.errorMessage(); - QThread::currentThread()->exit(1); + qWarning() << runId << logtime() << "Accepting new connection from" << proto.socket.peerAddress().toString() << "failed." << proto.errorMessage(); + proto.socket.disconnectFromHost(); return; } connectionEstablished = true; - qDebug() << runId << logtime() << "Connection established with" << plat.hostName << "[" << proto.socket.peerAddress().toString() << "]" - << "OS:" << plat.osName << "[" << plat.osVersion << "]" << "Qt version:" << plat.qtVersion << "[" << plat.buildKey << "]" - << "git commit:" << plat.gitCommit; - return; + QString logMsg; + foreach (QString key, plat.keys()) { + if (key != PI_HostName && key != PI_HostAddress) + logMsg += key + QLS(": '") + plat.value(key) + QLS("', "); + } + qDebug() << runId << logtime() << "Connection established with" << plat.value(PI_HostName) + << "[" << qPrintable(plat.value(PI_HostAddress)) << "]" << logMsg; + return; } QByteArray block; @@ -284,7 +289,7 @@ QString BaselineHandler::itemSubPath(const QString &engine, const QString &forma QString BaselineHandler::pathForItem(const ImageItem &item, bool isBaseline, bool absolute) { if (pathForRun.isNull()) { - QString host = plat.hostName.section(QLC('.'), 0, 0); // Filter away domain, if any + QString host = plat.value(PI_HostName).section(QLC('.'), 0, 0); // Filter away domain, if any if (host.isEmpty() || host == QLS("localhost")) { host = proto.socket.peerAddress().toString(); if (host.isEmpty()) @@ -438,11 +443,11 @@ void BaselineHandler::testPathMapping() item.imageChecksums << 0x0123456789abcdefULL; item.scriptChecksum = 0x0123; - plat.qtVersion = QLS("4.8.0"); - plat.buildKey = QLS("(nobuildkey)"); + plat.insert(PI_QtVersion, QLS("4.8.0")); + plat.insert(PI_BuildKey, QLS("(nobuildkey)")); foreach(const QString& host, hosts) { pathForRun = QString(); - plat.hostName = host; + plat.insert(PI_HostName, host); qDebug() << "Baseline from" << host << "->" << pathForItem(item, true).remove(BaselineServer::storagePath()); qDebug() << "Mismatch from" << host << "->" << pathForItem(item, false).remove(BaselineServer::storagePath()); } diff --git a/tests/arthur/baselineserver/src/baselineserver.h b/tests/arthur/baselineserver/src/baselineserver.h index bbebabb..e311527 100644 --- a/tests/arthur/baselineserver/src/baselineserver.h +++ b/tests/arthur/baselineserver/src/baselineserver.h @@ -116,7 +116,7 @@ private: void provideBaselineChecksums(const QByteArray &itemListBlock); void storeImage(const QByteArray &itemBlock, bool isBaseline); QString pathForItem(const ImageItem &item, bool isBaseline = true, bool absolute = true); - QString logtime(); + const char *logtime(); QString computeMismatchScore(const QImage& baseline, const QImage& rendered); QString engineForItem(const ImageItem &item); diff --git a/tests/arthur/baselineserver/src/htmlpage.cpp b/tests/arthur/baselineserver/src/htmlpage.cpp index 00d07f1..ad7f8b7 100644 --- a/tests/arthur/baselineserver/src/htmlpage.cpp +++ b/tests/arthur/baselineserver/src/htmlpage.cpp @@ -89,9 +89,12 @@ void HTMLPage::writeHeader(const ImageItem &item) out.setDevice(&file); out << "

Lancelot results from run " << id << "

\n\n"; - out << "

Host: " << plat.hostName << " [" << address << "] OS: " << plat.osName << " [enum: " << plat.osVersion << "]

\n"; - out << "

Qt version: " << plat.qtVersion << " [commit: " << plat.gitCommit << "] Build key: \"" << plat.buildKey << "\"

\n"; - out << "

Engine: " << item.engineAsString() << " Format: " << item.formatAsString() << "

\n\n"; + out << "

Platform Info:

\n"; + out << "
ScriptUpdate baseline
" +#if 0 "Blacklist test
\n"; + foreach (QString key, plat.keys()) + out << "\n"; + out << "
" << key << "" << plat.value(key) << "
\n"; + #if 0 out << "

Blacklisted
" "
#include #include +#include + +#ifndef QMAKESPEC +#define QMAKESPEC "Unknown" +#endif PlatformInfo::PlatformInfo(bool useLocal) + : QMap() { if (useLocal) { - buildKey = QLibraryInfo::buildKey(); - qtVersion = QLatin1String(qVersion()); - hostName = QHostInfo::localHostName(); - osVersion = -1; + insert(PI_HostName, QHostInfo::localHostName()); + insert(PI_QtVersion, QLS(qVersion())); + insert(PI_QMakeSpec, QFileInfo(QLS(QMAKESPEC)).fileName()); + insert(PI_BuildKey, QLibraryInfo::buildKey()); #if defined(Q_OS_LINUX) - osName = QLatin1String("Linux"); + insert(PI_OSName, QLS("Linux")); + QProcess uname; + uname.start(QLS("uname"), QStringList() << QLS("-r")); + if (uname.waitForFinished(3000)) + insert(PI_OSVersion, QString::fromLocal8Bit(uname.readAllStandardOutput().constData()).simplified()); #elif defined(Q_OS_WINCE) - osName = QLatin1String("WinCE"); - osVersion = QSysInfo::windowsVersion(); + insert(PI_OSName, QLS("WinCE")); + insert(PI_OSVersion, QString::number(QSysInfo::windowsVersion())); #elif defined(Q_OS_WIN) - osName = QLatin1String("Windows"); - osVersion = QSysInfo::windowsVersion(); + insert(PI_OSName, QLS("Windows")); + insert(PI_OSVersion, QString::number(QSysInfo::windowsVersion())); #elif defined(Q_OS_MAC) - osName = QLatin1String("MacOS"); - osVersion = qMacVersion(); + insert(PI_OSName, QLS("MacOS")); + insert(PI_OSVersion, QString::number(qMacVersion())); #elif defined(Q_OS_SYMBIAN) - osName = QLatin1String("Symbian"); - osVersion = QSysInfo::symbianVersion(); + insert(PI_OSName, QLS("Symbian")); + insert(PI_OSVersion, QString::number(QSysInfo::symbianVersion()); #else - osName = QLatin1String("Other"); + insert(PI_OSName, QLS("Other")); #endif QProcess git; @@ -80,27 +90,23 @@ PlatformInfo::PlatformInfo(bool useLocal) #else cmd = QLS("git"); #endif - args << QLS("log") << QLS("--max-count=1") << QLS("--pretty=%H"); + args << QLS("log") << QLS("--max-count=1") << QLS("--pretty=%H [%an] [%ad] %s"); git.start(cmd, args); git.waitForFinished(3000); if (!git.exitCode()) - gitCommit = QString::fromLocal8Bit(git.readAllStandardOutput().constData()).trimmed(); + insert(PI_GitCommit, QString::fromLocal8Bit(git.readAllStandardOutput().constData()).simplified()); else - gitCommit = QLS("Unknown"); + insert(PI_GitCommit, QLS("Unknown")); } -} -QDataStream & operator<< (QDataStream &stream, const PlatformInfo &p) -{ - stream << p.hostName << p.osName << p.osVersion << p.qtVersion << p.buildKey << p.gitCommit; - return stream; + QByteArray gb = qgetenv("PULSE_GIT_BRANCH"); + if (!gb.isEmpty()) + insert(PI_PulseGitBranch, QString::fromLatin1(gb)); + QByteArray tb = qgetenv("PULSE_TESTR_BRANCH"); + if (!tb.isEmpty()) + insert(PI_PulseTestrBranch, QString::fromLatin1(tb)); } -QDataStream & operator>> (QDataStream& stream, PlatformInfo& p) -{ - stream >> p.hostName >> p.osName >> p.osVersion >> p.qtVersion >> p.buildKey >> p.gitCommit; - return stream; -} ImageItem &ImageItem::operator=(const ImageItem &other) { @@ -151,15 +157,15 @@ QString ImageItem::engineAsString() const { switch (engine) { case Raster: - return QLatin1String("Raster"); + return QLS("Raster"); break; case OpenGL: - return QLatin1String("OpenGL"); + return QLS("OpenGL"); break; default: break; } - return QLatin1String("Unknown"); + return QLS("Unknown"); } QString ImageItem::formatAsString() const @@ -184,8 +190,8 @@ QString ImageItem::formatAsString() const "ARGB4444-Premult" }; if (renderFormat < 0 || renderFormat >= numFormats) - return QLatin1String("UnknownFormat"); - return QLatin1String(formatNames[renderFormat]); + return QLS("UnknownFormat"); + return QLS(formatNames[renderFormat]); } QDataStream & operator<< (QDataStream &stream, const ImageItem &ii) @@ -223,7 +229,7 @@ bool BaselineProtocol::connect() socket.connectToHost(serverName, ServerPort); if (!socket.waitForConnected(Timeout)) { - errMsg += QLatin1String("TCP connectToHost failed. Host:") + serverName + QLatin1String(" port:") + QString::number(ServerPort); + errMsg += QLS("TCP connectToHost failed. Host:") + serverName + QLS(" port:") + QString::number(ServerPort); return false; } @@ -232,13 +238,13 @@ bool BaselineProtocol::connect() QDataStream ds(&block, QIODevice::ReadWrite); ds << pi; if (!sendBlock(AcceptPlatformInfo, block)) { - errMsg += QLatin1String("Failed to send data to server."); + errMsg += QLS("Failed to send data to server."); return false; } Command cmd = Ack; if (!receiveBlock(&cmd, &block) || cmd != Ack) { - errMsg += QLatin1String("Failed to get response from server."); + errMsg += QLS("Failed to get response from server."); return false; } @@ -258,6 +264,7 @@ bool BaselineProtocol::acceptConnection(PlatformInfo *pi) if (pi) { QDataStream ds(block); ds >> *pi; + pi->insert(PI_HostAddress, socket.peerAddress().toString()); } if (!sendBlock(Ack, QByteArray())) @@ -307,7 +314,7 @@ bool BaselineProtocol::sendItem(Command cmd, const ImageItem &item) QDataStream ds(&buf); ds << item; if (!sendBlock(cmd, buf.data())) { - errMsg.prepend(QLatin1String("Failed to submit image to server. ")); + errMsg.prepend(QLS("Failed to submit image to server. ")); return false; } return true; @@ -334,9 +341,8 @@ bool BaselineProtocol::receiveBlock(Command *cmd, QByteArray *block) quint16 rcvProtocolVersion, rcvCmd; ds >> rcvProtocolVersion >> rcvCmd; if (rcvProtocolVersion != ProtocolVersion) { - // TBD: More resilient handling of this case; the server should accept client's version - errMsg = QLatin1String("Server protocol version mismatch, received:") + QString::number(rcvProtocolVersion); - + errMsg = QLS("Baseline protocol version mismatch, received:") + QString::number(rcvProtocolVersion) + + QLS(" expected:") + QString::number(ProtocolVersion); return false; } if (cmd) @@ -368,6 +374,6 @@ QString BaselineProtocol::errorMessage() { QString ret = errMsg; if (socket.error() >= 0) - ret += QLatin1String(" Socket state: ") + socket.errorString(); + ret += QLS(" Socket state: ") + socket.errorString(); return ret; } diff --git a/tests/arthur/common/baselineprotocol.h b/tests/arthur/common/baselineprotocol.h index a0ae028..162a19f 100644 --- a/tests/arthur/common/baselineprotocol.h +++ b/tests/arthur/common/baselineprotocol.h @@ -45,25 +45,29 @@ #include #include #include +#include #define QLS QLatin1String #define QLC QLatin1Char #define FileFormat "png" -struct PlatformInfo +const QString PI_HostName(QLS("HostName")); +const QString PI_HostAddress(QLS("HostAddress")); +const QString PI_OSName(QLS("OSName")); +const QString PI_OSVersion(QLS("OSVersion")); +const QString PI_QtVersion(QLS("QtVersion")); +const QString PI_BuildKey(QLS("BuildKey")); +const QString PI_GitCommit(QLS("GitCommit")); +const QString PI_QMakeSpec(QLS("QMakeSpec")); +const QString PI_PulseGitBranch(QLS("PulseGitBranch")); +const QString PI_PulseTestrBranch(QLS("PulseTestrBranch")); + +class PlatformInfo : public QMap { +public: PlatformInfo(bool useLocal = false); - - QString hostName; - QString osName; - int osVersion; - QString qtVersion; - QString buildKey; - QString gitCommit; }; -QDataStream & operator<< (QDataStream &stream, const PlatformInfo &p); -QDataStream & operator>> (QDataStream& stream, PlatformInfo& p); struct ImageItem { @@ -117,7 +121,7 @@ public: // Important constants here // **************************************************** enum Constant { - ProtocolVersion = 1, + ProtocolVersion = 2, ServerPort = 54129, Timeout = 10000 }; diff --git a/tests/auto/lancelot/lancelot.pro b/tests/auto/lancelot/lancelot.pro index 3859a55..6498f6c 100644 --- a/tests/auto/lancelot/lancelot.pro +++ b/tests/auto/lancelot/lancelot.pro @@ -8,5 +8,6 @@ HEADERS += $$QT_SOURCE_TREE/tests/arthur/common/paintcommands.h RESOURCES += $$QT_SOURCE_TREE/tests/arthur/common/images.qrc include($$QT_SOURCE_TREE/tests/arthur/common/baselineprotocol.pri) +DEFINES += QMAKESPEC=\\\"$$QMAKESPEC\\\" !symbian:!wince*:DEFINES += SRCDIR=\\\"$$PWD\\\" -- cgit v0.12 From 61f173852fde779ad6b3860794180eb1c9ccd8d7 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Fri, 5 Nov 2010 16:55:31 +0100 Subject: Fix QMenu rendering in the unified toolbar with the raster engine. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-12818 Reviewed-by: Samuel Rødal --- src/gui/painting/qunifiedtoolbarsurface_mac.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gui/painting/qunifiedtoolbarsurface_mac.cpp b/src/gui/painting/qunifiedtoolbarsurface_mac.cpp index 3590993..b25757b 100644 --- a/src/gui/painting/qunifiedtoolbarsurface_mac.cpp +++ b/src/gui/painting/qunifiedtoolbarsurface_mac.cpp @@ -76,9 +76,14 @@ void QUnifiedToolbarSurface::recursiveRedirect(QObject *object, const QPoint &of if (object != 0) { if (object->isWidgetType()) { QWidget *widget = qobject_cast(object); - widget->d_func()->unifiedSurface = this; - widget->d_func()->isInUnifiedToolbar = true; - widget->d_func()->toolbar_offset = offset; + + // We redirect the painting only if the widget is in the same window + // and is not a window in itself. + if (!(widget->windowType() & Qt::Window)) { + widget->d_func()->unifiedSurface = this; + widget->d_func()->isInUnifiedToolbar = true; + widget->d_func()->toolbar_offset = offset; + } } for (int i = 0; i < object->children().size(); ++i) { -- cgit v0.12 From 3223167a884103518b6c3d33fd34c4f439a10c93 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 4 Nov 2010 13:25:51 +0100 Subject: Add missing Q_ENUMS to QAbstractSocket Task-number: QT-1635 Reviewed-by: Markus Goetz --- src/network/socket/qabstractsocket.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/network/socket/qabstractsocket.h b/src/network/socket/qabstractsocket.h index f610db3..df09b92 100644 --- a/src/network/socket/qabstractsocket.h +++ b/src/network/socket/qabstractsocket.h @@ -64,6 +64,7 @@ class QAuthenticator; class Q_NETWORK_EXPORT QAbstractSocket : public QIODevice { Q_OBJECT + Q_ENUMS(SocketType NetworkLayerProtocol SocketError SocketState SocketOption) public: enum SocketType { TcpSocket, -- cgit v0.12 From 96e873d4ed59bd9feef1c5dacc28f77377e53c47 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 25 Mar 2010 16:39:19 +0100 Subject: QPointer: assert when using QPointer on destroyed QObject Uses the same assert as in QWeakPointer Reviewed-by: Thiago Task-number: QTBUG-9398 --- src/corelib/kernel/qobject.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 573bb50..ef78b0c 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -392,6 +392,7 @@ void QMetaObject::addGuard(QObject **ptr) return; } QMutexLocker locker(guardHashLock()); + Q_ASSERT_X(!QObjectPrivate::get(*ptr)->wasDeleted, "QPointer", "Detected QPointer creation on a QObject being deleted"); QObjectPrivate::get(*ptr)->hasGuards = true; hash->insert(*ptr, ptr); } @@ -434,6 +435,7 @@ void QMetaObject::changeGuard(QObject **ptr, QObject *o) } QMutexLocker locker(guardHashLock()); if (o) { + Q_ASSERT_X(!QObjectPrivate::get(o)->wasDeleted, "QPointer", "Detected QPointer creation on a QObject being deleted"); hash->insert(o, ptr); QObjectPrivate::get(o)->hasGuards = true; } -- cgit v0.12 From 1bfdedb16fdcafc0fdbcea342d68801b8404ea24 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 5 Nov 2010 10:52:30 +0100 Subject: QStyleSheetStyle: add a way to style the up arrow Patch originaly from Martin Petersson Task-number: QTBUG-13491 --- src/gui/styles/qstylesheetstyle.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 4be439d..e23c246 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -4157,6 +4157,10 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op pseudoElement = PseudoElement_DownArrow; break; + case PE_IndicatorArrowUp: + pseudoElement = PseudoElement_UpArrow; + break; + case PE_IndicatorRadioButton: pseudoElement = PseudoElement_ExclusiveIndicator; break; -- cgit v0.12 From 7b63ce043dfaec5ec83d938b1cea8ee0ead614ff Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 5 Nov 2010 12:59:18 +0100 Subject: QStyleSheetStyle: Fix crash that occurs with several instance of QStyleSheetStyle The problem is that when a widget is destroyed, it was not properly removed from the cache. We connected the destroyed signal to a slot in the QStyleSheetStyle for the first QStyleSheetStyle that handle a widget. but if this QStyleSheetStyle is destroyed, that connection is lost. Solution: Create a new QStyleSheetStyleCaches that will be responsible to clean the caches. This objects is not destroyed as long as there is a QStyleSheetStyle instance, so the connection is not lost. I took the oportunity to move all the caches to this object. Reveiwed-by: Gabriel Task-number: QTBUG-11658 --- src/gui/styles/qstylesheetstyle.cpp | 139 +++++++++------------ src/gui/styles/qstylesheetstyle_p.h | 20 ++- .../auto/qstylesheetstyle/tst_qstylesheetstyle.cpp | 32 +++++ 3 files changed, 106 insertions(+), 85 deletions(-) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index e23c246..fb6fc23 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -99,14 +99,7 @@ public: }; -static QHash > *styleRulesCache = 0; -static QHash > *hasStyleRuleCache = 0; -typedef QHash > QRenderRules; -static QHash *renderRulesCache = 0; -static QHash *customPaletteWidgets = 0; // widgets whose palette we tampered -static QHash *styleSheetCache = 0; // parsed style sheets -static QSet *autoFillDisabledWidgets = 0; - +static QStyleSheetStyleCaches *styleSheetCaches = 0; /* RECURSION_GUARD: * the QStyleSheetStyle is a proxy. If used with others proxy style, we may end up with something like: @@ -1525,8 +1518,8 @@ private: QVector QStyleSheetStyle::styleRules(const QWidget *w) const { - QHash >::const_iterator cacheIt = styleRulesCache->constFind(w); - if (cacheIt != styleRulesCache->constEnd()) + QHash >::const_iterator cacheIt = styleSheetCaches->styleRulesCache.constFind(w); + if (cacheIt != styleSheetCaches->styleRulesCache.constEnd()) return cacheIt.value(); if (!initWidget(w)) { @@ -1536,12 +1529,12 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const QStyleSheetStyleSelector styleSelector; StyleSheet defaultSs; - QHash::const_iterator defaultCacheIt = styleSheetCache->constFind(baseStyle()); - if (defaultCacheIt == styleSheetCache->constEnd()) { + QHash::const_iterator defaultCacheIt = styleSheetCaches->styleSheetCache.constFind(baseStyle()); + if (defaultCacheIt == styleSheetCaches->styleSheetCache.constEnd()) { defaultSs = getDefaultStyleSheet(); QStyle *bs = baseStyle(); - styleSheetCache->insert(bs, defaultSs); - QObject::connect(bs, SIGNAL(destroyed(QObject*)), this, SLOT(styleDestroyed(QObject*)), Qt::UniqueConnection); + styleSheetCaches->styleSheetCache.insert(bs, defaultSs); + QObject::connect(bs, SIGNAL(destroyed(QObject*)), styleSheetCaches, SLOT(styleDestroyed(QObject*)), Qt::UniqueConnection); } else { defaultSs = defaultCacheIt.value(); } @@ -1549,8 +1542,8 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const if (!qApp->styleSheet().isEmpty()) { StyleSheet appSs; - QHash::const_iterator appCacheIt = styleSheetCache->constFind(qApp); - if (appCacheIt == styleSheetCache->constEnd()) { + QHash::const_iterator appCacheIt = styleSheetCaches->styleSheetCache.constFind(qApp); + if (appCacheIt == styleSheetCaches->styleSheetCache.constEnd()) { QString ss = qApp->styleSheet(); if (ss.startsWith(QLatin1String("file:///"))) ss.remove(0, 8); @@ -1559,7 +1552,7 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const qWarning("Could not parse application stylesheet"); appSs.origin = StyleSheetOrigin_Inline; appSs.depth = 1; - styleSheetCache->insert(qApp, appSs); + styleSheetCaches->styleSheetCache.insert(qApp, appSs); } else { appSs = appCacheIt.value(); } @@ -1571,8 +1564,8 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const if (wid->styleSheet().isEmpty()) continue; StyleSheet ss; - QHash::const_iterator widCacheIt = styleSheetCache->constFind(wid); - if (widCacheIt == styleSheetCache->constEnd()) { + QHash::const_iterator widCacheIt = styleSheetCaches->styleSheetCache.constFind(wid); + if (widCacheIt == styleSheetCaches->styleSheetCache.constEnd()) { parser.init(wid->styleSheet()); if (!parser.parse(&ss)) { parser.init(QLatin1String("* {") + wid->styleSheet() + QLatin1Char('}')); @@ -1580,7 +1573,7 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const qWarning("Could not parse stylesheet of widget %p", wid); } ss.origin = StyleSheetOrigin_Inline; - styleSheetCache->insert(wid, ss); + styleSheetCaches->styleSheetCache.insert(wid, ss); } else { ss = widCacheIt.value(); } @@ -1595,7 +1588,7 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const StyleSelector::NodePtr n; n.ptr = (void *)w; QVector rules = styleSelector.styleRulesForNode(n); - styleRulesCache->insert(w, rules); + styleSheetCaches->styleRulesCache.insert(w, rules); return rules; } @@ -1724,7 +1717,7 @@ static void qt_check_if_internal_widget(const QWidget **w, int *element) QRenderRule QStyleSheetStyle::renderRule(const QWidget *w, int element, quint64 state) const { qt_check_if_internal_widget(&w, &element); - QHash &cache = (*renderRulesCache)[w][element]; + QHash &cache = styleSheetCaches->renderRulesCache[w][element]; QHash::const_iterator cacheIt = cache.constFind(state); if (cacheIt != cache.constEnd()) return cacheIt.value(); @@ -2035,7 +2028,7 @@ QRenderRule QStyleSheetStyle::renderRule(const QWidget *w, const QStyleOption *o bool QStyleSheetStyle::hasStyleRule(const QWidget *w, int part) const { - QHash &cache = (*hasStyleRuleCache)[w]; + QHash &cache = styleSheetCaches->hasStyleRuleCache[w]; QHash::const_iterator cacheIt = cache.constFind(part); if (cacheIt != cache.constEnd()) return cacheIt.value(); @@ -2565,7 +2558,7 @@ void QStyleSheetStyle::setPalette(QWidget *w) rule.configurePalette(&p, map[i].group, ew, ew != w); } - customPaletteWidgets->insert(w, w->palette()); + styleSheetCaches->customPaletteWidgets.insert(w, w->palette()); w->setPalette(p); if (ew != w) ew->setPalette(p); @@ -2573,32 +2566,32 @@ void QStyleSheetStyle::setPalette(QWidget *w) void QStyleSheetStyle::unsetPalette(QWidget *w) { - if (customPaletteWidgets->contains(w)) { - QPalette p = customPaletteWidgets->value(w); + if (styleSheetCaches->customPaletteWidgets.contains(w)) { + QPalette p = styleSheetCaches->customPaletteWidgets.value(w); w->setPalette(p); QWidget *ew = embeddedWidget(w); if (ew != w) ew->setPalette(p); - customPaletteWidgets->remove(w); + styleSheetCaches->customPaletteWidgets.remove(w); } QVariant oldFont = w->property("_q_styleSheetWidgetFont"); if (oldFont.isValid()) { w->setFont(qvariant_cast(oldFont)); } - if (autoFillDisabledWidgets->contains(w)) { + if (styleSheetCaches->autoFillDisabledWidgets.contains(w)) { embeddedWidget(w)->setAutoFillBackground(true); - autoFillDisabledWidgets->remove(w); + styleSheetCaches->autoFillDisabledWidgets.remove(w); } } static void updateWidgets(const QList& widgets) { - if (!styleRulesCache->isEmpty() || !hasStyleRuleCache->isEmpty() || !renderRulesCache->isEmpty()) { + if (!styleSheetCaches->styleRulesCache.isEmpty() || !styleSheetCaches->hasStyleRuleCache.isEmpty() || !styleSheetCaches->renderRulesCache.isEmpty()) { for (int i = 0; i < widgets.size(); ++i) { const QWidget *widget = widgets.at(i); - styleRulesCache->remove(widget); - hasStyleRuleCache->remove(widget); - renderRulesCache->remove(widget); + styleSheetCaches->styleRulesCache.remove(widget); + styleSheetCaches->hasStyleRuleCache.remove(widget); + styleSheetCaches->renderRulesCache.remove(widget); } } for (int i = 0; i < widgets.size(); ++i) { @@ -2622,12 +2615,7 @@ QStyleSheetStyle::QStyleSheetStyle(QStyle *base) { ++numinstances; if (numinstances == 1) { - styleRulesCache = new QHash >; - hasStyleRuleCache = new QHash >; - renderRulesCache = new QHash; - customPaletteWidgets = new QHash; - styleSheetCache = new QHash; - autoFillDisabledWidgets = new QSet; + styleSheetCaches = new QStyleSheetStyleCaches; } } @@ -2635,18 +2623,7 @@ QStyleSheetStyle::~QStyleSheetStyle() { --numinstances; if (numinstances == 0) { - delete styleRulesCache; - styleRulesCache = 0; - delete hasStyleRuleCache; - hasStyleRuleCache = 0; - delete renderRulesCache; - renderRulesCache = 0; - delete customPaletteWidgets; - customPaletteWidgets = 0; - delete styleSheetCache; - styleSheetCache = 0; - delete autoFillDisabledWidgets; - autoFillDisabledWidgets = 0; + delete styleSheetCaches; } } QStyle *QStyleSheetStyle::baseStyle() const @@ -2658,19 +2635,19 @@ QStyle *QStyleSheetStyle::baseStyle() const return QApplication::style(); } -void QStyleSheetStyle::widgetDestroyed(QObject *o) +void QStyleSheetStyleCaches::widgetDestroyed(QObject *o) { - styleRulesCache->remove((const QWidget *)o); - hasStyleRuleCache->remove((const QWidget *)o); - renderRulesCache->remove((const QWidget *)o); - customPaletteWidgets->remove((const QWidget *)o); - styleSheetCache->remove((const QWidget *)o); - autoFillDisabledWidgets->remove((const QWidget *)o); + styleRulesCache.remove((const QWidget *)o); + hasStyleRuleCache.remove((const QWidget *)o); + renderRulesCache.remove((const QWidget *)o); + customPaletteWidgets.remove((const QWidget *)o); + styleSheetCache.remove((const QWidget *)o); + autoFillDisabledWidgets.remove((const QWidget *)o); } -void QStyleSheetStyle::styleDestroyed(QObject *o) +void QStyleSheetStyleCaches::styleDestroyed(QObject *o) { - styleSheetCache->remove(o); + styleSheetCache.remove(o); } /*! @@ -2688,7 +2665,7 @@ bool QStyleSheetStyle::initWidget(const QWidget *w) const return false; const_cast(w)->setAttribute(Qt::WA_StyleSheet, true); - QObject::connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(widgetDestroyed(QObject*))); + QObject::connect(w, SIGNAL(destroyed(QObject*)), styleSheetCaches, SLOT(widgetDestroyed(QObject*)), Qt::UniqueConnection); return true; } @@ -2700,12 +2677,12 @@ void QStyleSheetStyle::polish(QWidget *w) if (!initWidget(w)) return; - if (styleRulesCache->contains(w)) { + if (styleSheetCaches->styleRulesCache.contains(w)) { // the widget accessed its style pointer before polish (or repolish) // (exemple: the QAbstractSpinBox constructor ask for the stylehint) - styleRulesCache->remove(w); - hasStyleRuleCache->remove(w); - renderRulesCache->remove(w); + styleSheetCaches->styleRulesCache.remove(w); + styleSheetCaches->hasStyleRuleCache.remove(w); + styleSheetCaches->renderRulesCache.remove(w); } setGeometry(w); setProperties(w); @@ -2771,7 +2748,7 @@ void QStyleSheetStyle::polish(QWidget *w) QWidget *ew = embeddedWidget(w); if (ew->autoFillBackground()) { ew->setAutoFillBackground(false); - autoFillDisabledWidgets->insert(w); + styleSheetCaches->autoFillDisabledWidgets.insert(w); if (ew != w) { //eg. viewport of a scrollarea //(in order to draw the background anyway in case we don't.) ew->setAttribute(Qt::WA_StyledBackground, true); @@ -2797,18 +2774,18 @@ void QStyleSheetStyle::repolish(QWidget *w) { QList children = w->findChildren(QString()); children.append(w); - styleSheetCache->remove(w); + styleSheetCaches->styleSheetCache.remove(w); updateWidgets(children); } void QStyleSheetStyle::repolish(QApplication *app) { Q_UNUSED(app); - const QList allWidgets = styleRulesCache->keys(); - styleSheetCache->remove(qApp); - styleRulesCache->clear(); - hasStyleRuleCache->clear(); - renderRulesCache->clear(); + const QList allWidgets = styleSheetCaches->styleRulesCache.keys(); + styleSheetCaches->styleSheetCache.remove(qApp); + styleSheetCaches->styleRulesCache.clear(); + styleSheetCaches->hasStyleRuleCache.clear(); + styleSheetCaches->renderRulesCache.clear(); updateWidgets(allWidgets); } @@ -2819,10 +2796,10 @@ void QStyleSheetStyle::unpolish(QWidget *w) return; } - styleRulesCache->remove(w); - hasStyleRuleCache->remove(w); - renderRulesCache->remove(w); - styleSheetCache->remove(w); + styleSheetCaches->styleRulesCache.remove(w); + styleSheetCaches->hasStyleRuleCache.remove(w); + styleSheetCaches->renderRulesCache.remove(w); + styleSheetCaches->styleSheetCache.remove(w); unsetPalette(w); w->setProperty("_q_stylesheet_minw", QVariant()); w->setProperty("_q_stylesheet_minh", QVariant()); @@ -2849,10 +2826,10 @@ void QStyleSheetStyle::unpolish(QApplication *app) { baseStyle()->unpolish(app); RECURSION_GUARD(return) - styleRulesCache->clear(); - hasStyleRuleCache->clear(); - renderRulesCache->clear(); - styleSheetCache->remove(qApp); + styleSheetCaches->styleRulesCache.clear(); + styleSheetCaches->hasStyleRuleCache.clear(); + styleSheetCaches->renderRulesCache.clear(); + styleSheetCaches->styleSheetCache.remove(qApp); } #ifndef QT_NO_TABBAR @@ -4261,7 +4238,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op case PE_Widget: if (!rule.hasDrawable()) { QWidget *container = containerWidget(w); - if (autoFillDisabledWidgets->contains(container) + if (styleSheetCaches->autoFillDisabledWidgets.contains(container) && (container == w || !renderRule(container, opt).hasBackground())) { //we do not have a background, but we disabled the autofillbackground anyway. so fill the background now. // (this may happen if we have rules like :focus) diff --git a/src/gui/styles/qstylesheetstyle_p.h b/src/gui/styles/qstylesheetstyle_p.h index fd81437..4564950 100644 --- a/src/gui/styles/qstylesheetstyle_p.h +++ b/src/gui/styles/qstylesheetstyle_p.h @@ -145,10 +145,6 @@ protected Q_SLOTS: protected: bool event(QEvent *e); -private Q_SLOTS: - void widgetDestroyed(QObject *); - void styleDestroyed(QObject *); - private: int refcount; @@ -186,6 +182,22 @@ private: Q_DECLARE_PRIVATE(QStyleSheetStyle) }; +class QStyleSheetStyleCaches : public QObject +{ + Q_OBJECT +public Q_SLOTS: + void widgetDestroyed(QObject *); + void styleDestroyed(QObject *); +public: + QHash > styleRulesCache; + QHash > hasStyleRuleCache; + typedef QHash > QRenderRules; + QHash renderRulesCache; + QHash customPaletteWidgets; // widgets whose palette we tampered + QHash styleSheetCache; // parsed style sheets + QSet autoFillDisabledWidgets; +}; + QT_END_NAMESPACE #endif // QT_NO_STYLE_STYLESHEET diff --git a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp index 04b1e79..9526ad8 100644 --- a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -103,6 +103,7 @@ private slots: //at the end because it mess with the style. void widgetStyle(); void appStyle(); + void QTBUG11658_cachecrash(); private: QColor COLOR(const QWidget& w) { w.ensurePolished(); @@ -1622,6 +1623,37 @@ void tst_QStyleSheetStyle::changeStyleInChangeEvent() wid.ensurePolished(); } +void tst_QStyleSheetStyle::QTBUG11658_cachecrash() +{ + //should not crash + class Widget : public QWidget + { + public: + Widget(QWidget *parent = 0) + : QWidget(parent) + { + QVBoxLayout* pLayout = new QVBoxLayout(this); + QCheckBox* pCheckBox = new QCheckBox(this); + pLayout->addWidget(pCheckBox); + setLayout(pLayout); + + QString szStyleSheet = QLatin1String("* { color: red; }"); + qApp->setStyleSheet(szStyleSheet); + qApp->setStyle(QStyleFactory::create(QLatin1String("Windows"))); + } + }; + + Widget *w = new Widget(); + delete w; + w = new Widget(); + w->show(); + + QTest::qWaitForWindowShown(w); + delete w; + qApp->setStyleSheet(QString()); +} + + QTEST_MAIN(tst_QStyleSheetStyle) #include "tst_qstylesheetstyle.moc" -- cgit v0.12 From 6134cffd3f2795d789087b037666ba8265f3b7f2 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 5 Nov 2010 17:20:16 +0100 Subject: Silence warning in qvector with MSVC Conversion from size_t to int loose precision Reviewed-by: Robin Burchell --- src/corelib/tools/qvector.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 4044a66..0f7db88 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -304,7 +304,7 @@ public: #ifndef QT_NO_STL static inline QVector fromStdVector(const std::vector &vector) - { QVector tmp; tmp.reserve(vector.size()); qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; } + { QVector tmp; tmp.reserve(int(vector.size())); qCopy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; } inline std::vector toStdVector() const { std::vector tmp; tmp.reserve(size()); qCopy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; } #endif @@ -440,9 +440,9 @@ QVector::QVector(int asize, const T &t) template QVector::QVector(std::initializer_list args) { - d = malloc(args.size()); + d = malloc(int(args.size())); d->ref = 1; - d->alloc = d->size = args.size(); + d->alloc = d->size = int(args.size()); d->sharable = true; d->capacity = false; T* i = p->array + d->size; -- cgit v0.12