From c9210d392ca720028a4a2be427ba13100418c5b7 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 9 Mar 2016 20:55:00 +0100 Subject: [PATCH 01/62] Add argument names to the function signatures in headers Sometimes, in the .cpp, the declaration has the argument name in comments because it is not used (instead of using Q_UNUSED). The old qdoc could parse that, but once clang is used, these comments are not seen anymore. So add the argument names to the headers. This is also good for things like auto completion, which uses only the header to know what the argument name is. I grepped for " */)" and made sure all the functions that are documented have the right arguments. I also added the name to all the function around for consistency. Change-Id: I1aaa37e25a1985f7f51653f047a1ac2633242b56 Reviewed-by: Marc Mutz Reviewed-by: Martin Smith --- src/corelib/kernel/qobject.h | 16 ++++++------ src/widgets/kernel/qwidget.h | 50 ++++++++++++++++++------------------ src/widgets/styles/qstyle.h | 10 ++++---- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 64c5b58fd47..771d2f5ea04 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -113,8 +113,8 @@ public: Q_INVOKABLE explicit QObject(QObject *parent=Q_NULLPTR); virtual ~QObject(); - virtual bool event(QEvent *); - virtual bool eventFilter(QObject *, QEvent *); + virtual bool event(QEvent *event); + virtual bool eventFilter(QObject *watched, QEvent *event); #ifdef Q_QDOC static QString tr(const char *sourceText, const char *comment = Q_NULLPTR, int n = -1); @@ -189,9 +189,9 @@ public: inline const QObjectList &children() const { return d_ptr->children; } - void setParent(QObject *); - void installEventFilter(QObject *); - void removeEventFilter(QObject *); + void setParent(QObject *parent); + void installEventFilter(QObject *filterObj); + void removeEventFilter(QObject *obj); static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType = Qt::AutoConnection); @@ -430,9 +430,9 @@ protected: int receivers(const char* signal) const; bool isSignalConnected(const QMetaMethod &signal) const; - virtual void timerEvent(QTimerEvent *); - virtual void childEvent(QChildEvent *); - virtual void customEvent(QEvent *); + virtual void timerEvent(QTimerEvent *event); + virtual void childEvent(QChildEvent *event); + virtual void customEvent(QEvent *event); virtual void connectNotify(const QMetaMethod &signal); virtual void disconnectNotify(const QMetaMethod &signal); diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index a56f6e11335..2af1550ad17 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -605,43 +605,43 @@ Q_SIGNALS: protected: // Event handlers - bool event(QEvent *) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); - virtual void mouseDoubleClickEvent(QMouseEvent *); - virtual void mouseMoveEvent(QMouseEvent *); + bool event(QEvent *event) Q_DECL_OVERRIDE; + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseReleaseEvent(QMouseEvent *event); + virtual void mouseDoubleClickEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); #ifndef QT_NO_WHEELEVENT - virtual void wheelEvent(QWheelEvent *); + virtual void wheelEvent(QWheelEvent *event); #endif - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - virtual void focusInEvent(QFocusEvent *); - virtual void focusOutEvent(QFocusEvent *); - virtual void enterEvent(QEvent *); - virtual void leaveEvent(QEvent *); - virtual void paintEvent(QPaintEvent *); - virtual void moveEvent(QMoveEvent *); - virtual void resizeEvent(QResizeEvent *); - virtual void closeEvent(QCloseEvent *); + virtual void keyPressEvent(QKeyEvent *event); + virtual void keyReleaseEvent(QKeyEvent *event); + virtual void focusInEvent(QFocusEvent *event); + virtual void focusOutEvent(QFocusEvent *event); + virtual void enterEvent(QEvent *event); + virtual void leaveEvent(QEvent *event); + virtual void paintEvent(QPaintEvent *event); + virtual void moveEvent(QMoveEvent *event); + virtual void resizeEvent(QResizeEvent *event); + virtual void closeEvent(QCloseEvent *event); #ifndef QT_NO_CONTEXTMENU - virtual void contextMenuEvent(QContextMenuEvent *); + virtual void contextMenuEvent(QContextMenuEvent *event); #endif #ifndef QT_NO_TABLETEVENT - virtual void tabletEvent(QTabletEvent *); + virtual void tabletEvent(QTabletEvent *event); #endif #ifndef QT_NO_ACTION - virtual void actionEvent(QActionEvent *); + virtual void actionEvent(QActionEvent *event); #endif #ifndef QT_NO_DRAGANDDROP - virtual void dragEnterEvent(QDragEnterEvent *); - virtual void dragMoveEvent(QDragMoveEvent *); - virtual void dragLeaveEvent(QDragLeaveEvent *); - virtual void dropEvent(QDropEvent *); + virtual void dragEnterEvent(QDragEnterEvent *event); + virtual void dragMoveEvent(QDragMoveEvent *event); + virtual void dragLeaveEvent(QDragLeaveEvent *event); + virtual void dropEvent(QDropEvent *event); #endif - virtual void showEvent(QShowEvent *); - virtual void hideEvent(QHideEvent *); + virtual void showEvent(QShowEvent *event); + virtual void hideEvent(QHideEvent *event); virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result); // Misc. protected functions diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 1e9d15c9932..26d1c631955 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -66,13 +66,13 @@ public: QStyle(); virtual ~QStyle(); - virtual void polish(QWidget *); - virtual void unpolish(QWidget *); + virtual void polish(QWidget *widget); + virtual void unpolish(QWidget *widget); - virtual void polish(QApplication *); - virtual void unpolish(QApplication *); + virtual void polish(QApplication *application); + virtual void unpolish(QApplication *application); - virtual void polish(QPalette &); + virtual void polish(QPalette &palette); virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, From 6a2892bdef79e9787d8abe7c0121865f049c67f8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 8 Mar 2016 12:54:15 +0100 Subject: [PATCH 02/62] Skip spurious .toLower() on returns of QUrl::scheme() QUrl::setScheme() parses and canonicalises the scheme, so that scheme() always returns a lower-case string anyway; no need to .toLower() it. Change-Id: Ied00814b63f159386a42552dcf06346ee56f9f97 Reviewed-by: Timur Pocheptsov --- examples/network/torrent/mainwindow.cpp | 2 +- src/network/access/qhttpthreaddelegate.cpp | 2 +- src/network/access/qnetworkaccessmanager.cpp | 2 +- src/network/access/qnetworkcookiejar.cpp | 2 +- src/network/access/qnetworkreplyhttpimpl.cpp | 2 +- src/platformsupport/clipboard/qmacmime.mm | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp index 2b87f712946..bfe221c1290 100644 --- a/examples/network/torrent/mainwindow.cpp +++ b/examples/network/torrent/mainwindow.cpp @@ -702,7 +702,7 @@ void TorrentView::dragMoveEvent(QDragMoveEvent *event) { // Accept file actions with a '.torrent' extension. QUrl url(event->mimeData()->text()); - if (url.isValid() && url.scheme().toLower() == "file" + if (url.isValid() && url.scheme() == "file" && url.path().toLower().endsWith(".torrent")) event->acceptProposedAction(); } diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index b0e366d2f88..c9700e972ac 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -122,7 +122,7 @@ static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy) { QString result; QUrl copy = url; - QString scheme = copy.scheme().toLower(); + QString scheme = copy.scheme(); bool isEncrypted = scheme == QLatin1String("https"); copy.setPort(copy.port(isEncrypted ? 443 : 80)); if (scheme == QLatin1String("preconnect-http")) { diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 0e5870a2351..cf10368c52e 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1119,7 +1119,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera Q_D(QNetworkAccessManager); bool isLocalFile = req.url().isLocalFile(); - QString scheme = req.url().scheme().toLower(); + QString scheme = req.url().scheme(); // fast path for GET on file:// URLs // The QNetworkAccessFileBackend will right now only be used for PUT diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp index 39f94a451fb..97e637ff5f5 100644 --- a/src/network/access/qnetworkcookiejar.cpp +++ b/src/network/access/qnetworkcookiejar.cpp @@ -218,7 +218,7 @@ QList QNetworkCookieJar::cookiesForUrl(const QUrl &url) const Q_D(const QNetworkCookieJar); const QDateTime now = QDateTime::currentDateTimeUtc(); QList result; - bool isEncrypted = url.scheme().toLower() == QLatin1String("https"); + bool isEncrypted = url.scheme() == QLatin1String("https"); // scan our cookies for something that matches QList::ConstIterator it = d->allCookies.constBegin(), diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 6ba6928ade5..3120f29c039 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -628,7 +628,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq httpRequest.setUrl(url); httpRequest.setRedirectCount(newHttpRequest.maximumRedirectsAllowed()); - QString scheme = url.scheme().toLower(); + QString scheme = url.scheme(); bool ssl = (scheme == QLatin1String("https") || scheme == QLatin1String("preconnect-https")); q->setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, ssl); diff --git a/src/platformsupport/clipboard/qmacmime.mm b/src/platformsupport/clipboard/qmacmime.mm index ffa548bf837..dbb7e6f7542 100644 --- a/src/platformsupport/clipboard/qmacmime.mm +++ b/src/platformsupport/clipboard/qmacmime.mm @@ -634,7 +634,7 @@ QList QMacPasteboardMimeFileUri::convertFromMime(const QString &mime QUrl url = urls.at(i).toUrl(); if (url.scheme().isEmpty()) url.setScheme(QLatin1String("file")); - if (url.scheme().toLower() == QLatin1String("file")) { + if (url.scheme() == QLatin1String("file")) { if (url.host().isEmpty()) url.setHost(QLatin1String("localhost")); url.setPath(url.path().normalized(QString::NormalizationForm_D)); @@ -713,7 +713,7 @@ QList QMacPasteboardMimeUrl::convertFromMime(const QString &mime, QV QUrl url = urls.at(i).toUrl(); if (url.scheme().isEmpty()) url.setScheme(QLatin1String("file")); - if (url.scheme().toLower() == QLatin1String("file")) { + if (url.scheme() == QLatin1String("file")) { if (url.host().isEmpty()) url.setHost(QLatin1String("localhost")); url.setPath(url.path().normalized(QString::NormalizationForm_D)); From 65f88f3a5ded7fa53f50314434673cdc30977a15 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 8 Mar 2016 13:01:59 +0100 Subject: [PATCH 03/62] Deduplicate a condition to make clear that several cases ask it. QNetworkAccessManager::createRequest() had three checks relevant only to GET and HEAD requests; rather than testing for this in each of the cases, test for it once and skip all three if it fails. Tidied up the residue of conditionals in the process. Change-Id: I7baee8067a03afdc7cb0a77f1a50759dc4233843 Reviewed-by: Timur Pocheptsov --- src/network/access/qnetworkaccessmanager.cpp | 52 ++++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index cf10368c52e..28553e19e65 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1123,38 +1123,36 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera // fast path for GET on file:// URLs // The QNetworkAccessFileBackend will right now only be used for PUT - if ((op == QNetworkAccessManager::GetOperation || op == QNetworkAccessManager::HeadOperation) - && (isLocalFile || scheme == QLatin1String("qrc") -#if defined(Q_OS_ANDROID) + if (op == QNetworkAccessManager::GetOperation + || op == QNetworkAccessManager::HeadOperation) { + if (isLocalFile +#ifdef Q_OS_ANDROID || scheme == QLatin1String("assets") #endif - )) { - return new QNetworkReplyFileImpl(this, req, op); - } + || scheme == QLatin1String("qrc")) { + return new QNetworkReplyFileImpl(this, req, op); + } - if ((op == QNetworkAccessManager::GetOperation || op == QNetworkAccessManager::HeadOperation) - && scheme == QLatin1String("data")) { - return new QNetworkReplyDataImpl(this, req, op); - } + if (scheme == QLatin1String("data")) + return new QNetworkReplyDataImpl(this, req, op); - // A request with QNetworkRequest::AlwaysCache does not need any bearer management - QNetworkRequest::CacheLoadControl mode = - static_cast( - req.attribute(QNetworkRequest::CacheLoadControlAttribute, + // A request with QNetworkRequest::AlwaysCache does not need any bearer management + QNetworkRequest::CacheLoadControl mode = + static_cast( + req.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt()); - if (mode == QNetworkRequest::AlwaysCache - && (op == QNetworkAccessManager::GetOperation - || op == QNetworkAccessManager::HeadOperation)) { - // FIXME Implement a QNetworkReplyCacheImpl instead, see QTBUG-15106 - QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); - QNetworkReplyImplPrivate *priv = reply->d_func(); - priv->manager = this; - priv->backend = new QNetworkAccessCacheBackend(); - priv->backend->manager = this->d_func(); - priv->backend->setParent(reply); - priv->backend->reply = priv; - priv->setup(op, req, outgoingData); - return reply; + if (mode == QNetworkRequest::AlwaysCache) { + // FIXME Implement a QNetworkReplyCacheImpl instead, see QTBUG-15106 + QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); + QNetworkReplyImplPrivate *priv = reply->d_func(); + priv->manager = this; + priv->backend = new QNetworkAccessCacheBackend(); + priv->backend->manager = this->d_func(); + priv->backend->setParent(reply); + priv->backend->reply = priv; + priv->setup(op, req, outgoingData); + return reply; + } } #ifndef QT_NO_BEARERMANAGEMENT From 39efe3c84db554411f2e2fc5e491659c5398a059 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 9 Mar 2016 15:28:26 +0100 Subject: [PATCH 04/62] Fix glitch in tst_QLocalSocket::sendData In one code path the test checked for the emission of a readyRead() signal without waiting for it. This code path was never hit, neither on Windows nor on Unix platforms. Change-Id: Ifbe464400a2a1ba8eab49bd60315289040e6bbde Reviewed-by: Oswald Buddenhagen --- .../network/socket/qlocalsocket/tst_qlocalsocket.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 0505544a296..d12a6b53c3e 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -525,6 +525,7 @@ void tst_QLocalSocket::sendData() // test creating a connection socket.connectToServer(name); bool timedOut = true; + int expectedReadyReadSignals = 0; QCOMPARE(server.waitForNewConnection(3000, &timedOut), canListen); @@ -548,15 +549,17 @@ void tst_QLocalSocket::sendData() out << testLine << endl; bool wrote = serverSocket->waitForBytesWritten(3000); - if (!socket.canReadLine()) + if (!socket.canReadLine()) { + expectedReadyReadSignals = 1; QVERIFY(socket.waitForReadyRead()); + } QVERIFY(socket.bytesAvailable() >= 0); QCOMPARE(socket.bytesToWrite(), (qint64)0); QCOMPARE(socket.flush(), false); QCOMPARE(socket.isValid(), canListen); QCOMPARE(socket.readBufferSize(), (qint64)0); - QCOMPARE(spyReadyRead.count(), 1); + QCOMPARE(spyReadyRead.count(), expectedReadyReadSignals); QVERIFY(testLine.startsWith(in.readLine())); @@ -571,7 +574,7 @@ void tst_QLocalSocket::sendData() QCOMPARE(spyDisconnected.count(), canListen ? 1 : 0); QCOMPARE(spyError.count(), canListen ? 0 : 1); QCOMPARE(spyStateChanged.count(), canListen ? 4 : 2); - QCOMPARE(spyReadyRead.count(), canListen ? 1 : 0); + QCOMPARE(spyReadyRead.count(), canListen ? expectedReadyReadSignals : 0); server.close(); From 8589bb334f1e90630897c600c747541902434fab Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 10 Mar 2016 13:15:50 +0100 Subject: [PATCH 05/62] Enable most of tst_qstatictext on non-developer builds Only two tests inside tst_qstatictext required private symbols, so we can enable the rest on all builds. Change-Id: Id222ba01d9676c40b6447c1526ee127fcc2090d3 Reviewed-by: Oswald Buddenhagen --- tests/auto/gui/text/qstatictext/qstatictext.pro | 4 +++- tests/auto/gui/text/qstatictext/tst_qstatictext.cpp | 6 ++++++ tests/auto/gui/text/text.pro | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/auto/gui/text/qstatictext/qstatictext.pro b/tests/auto/gui/text/qstatictext/qstatictext.pro index 435b132ffd4..acffbe700b7 100644 --- a/tests/auto/gui/text/qstatictext/qstatictext.pro +++ b/tests/auto/gui/text/qstatictext/qstatictext.pro @@ -3,5 +3,7 @@ CONFIG += parallel_test linux: CONFIG += insignificant_test TARGET = tst_qstatictext QT += testlib -QT += core-private gui-private + SOURCES += tst_qstatictext.cpp + +contains(QT_CONFIG, private_tests): QT += core-private gui-private diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index 4b322efa7cf..121584b87fa 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -39,7 +39,9 @@ #include #include +#ifdef QT_BUILD_INTERNAL #include +#endif // #define DEBUG_SAVE_IMAGE @@ -90,8 +92,10 @@ private slots: void unprintableCharacter_qtbug12614(); +#ifdef QT_BUILD_INTERNAL void underlinedColor_qtbug20159(); void textDocumentColor(); +#endif private: bool supportsTransformations() const; @@ -829,6 +833,7 @@ void tst_QStaticText::unprintableCharacter_qtbug12614() QVERIFY(staticText.size().isValid()); // Force layout. Should not crash. } +#ifdef QT_BUILD_INTERNAL void tst_QStaticText::underlinedColor_qtbug20159() { QString multiScriptText; @@ -865,6 +870,7 @@ void tst_QStaticText::textDocumentColor() QCOMPARE(d->items[1].color, QColor(Qt::red)); } +#endif QTEST_MAIN(tst_QStaticText) #include "tst_qstatictext.moc" diff --git a/tests/auto/gui/text/text.pro b/tests/auto/gui/text/text.pro index 6c0def4d639..dc67794a98d 100644 --- a/tests/auto/gui/text/text.pro +++ b/tests/auto/gui/text/text.pro @@ -30,6 +30,5 @@ win32:SUBDIRS -= qtextpiecetable !contains(QT_CONFIG, private_tests): SUBDIRS -= \ qfontcache \ qcssparser \ - qstatictext \ qtextlayout \ qtextpiecetable \ From ac8dae8b5eafa07704155dd636d8da2ec21d1c6f Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 10 Mar 2016 14:07:16 +0100 Subject: [PATCH 06/62] QLocalServer/Win: Fix race condition in listen(). Suppose a client connects while the QLocalServer is still in the loop that calls addListener. The connection would SetEvent(eventHandle), but every call to ConnectNamedPipe would ResetEvent(eventHandle). Thus, the connection is never detected by the notifier on eventHandle. Callers of addListener must check the connection state of every listener to make sure that no client connected while setting up listeners. Task-number: QTBUG-49254 Change-Id: Ia961927ea76973708e6e3f73510695eb5d6a0e4c Reviewed-by: Oswald Buddenhagen --- src/network/socket/qlocalserver_win.cpp | 60 +++++++++++-------- .../network/socket/qlocalsocket/BLACKLIST | 2 - 2 files changed, 35 insertions(+), 27 deletions(-) delete mode 100644 tests/auto/network/socket/qlocalsocket/BLACKLIST diff --git a/src/network/socket/qlocalserver_win.cpp b/src/network/socket/qlocalserver_win.cpp index 265f8949725..06ad62f5481 100644 --- a/src/network/socket/qlocalserver_win.cpp +++ b/src/network/socket/qlocalserver_win.cpp @@ -192,6 +192,9 @@ bool QLocalServerPrivate::addListener() memset(&listener.overlapped, 0, sizeof(listener.overlapped)); listener.overlapped.hEvent = eventHandle; + + // Beware! ConnectNamedPipe will reset the eventHandle to non-signaled. + // Callers of addListener must check all listeners for connections. if (!ConnectNamedPipe(listener.handle, &listener.overlapped)) { switch (GetLastError()) { case ERROR_IO_PENDING: @@ -199,7 +202,6 @@ bool QLocalServerPrivate::addListener() break; case ERROR_PIPE_CONNECTED: listener.connected = true; - SetEvent(eventHandle); break; default: CloseHandle(listener.handle); @@ -251,6 +253,8 @@ bool QLocalServerPrivate::listen(const QString &name) for (int i = 0; i < SYSTEM_MAX_PENDING_SOCKETS; ++i) if (!addListener()) return false; + + _q_onNewConnection(); return true; } @@ -264,37 +268,43 @@ void QLocalServerPrivate::_q_onNewConnection() { Q_Q(QLocalServer); DWORD dummy; + bool tryAgain; + do { + tryAgain = false; - // Reset first, otherwise we could reset an event which was asserted - // immediately after we checked the conn status. - ResetEvent(eventHandle); + // Reset first, otherwise we could reset an event which was asserted + // immediately after we checked the conn status. + ResetEvent(eventHandle); - // Testing shows that there is indeed absolutely no guarantee which listener gets - // a client connection first, so there is no way around polling all of them. - for (int i = 0; i < listeners.size(); ) { - HANDLE handle = listeners[i].handle; - if (listeners[i].connected - || GetOverlappedResult(handle, &listeners[i].overlapped, &dummy, FALSE)) - { - listeners.removeAt(i); + // Testing shows that there is indeed absolutely no guarantee which listener gets + // a client connection first, so there is no way around polling all of them. + for (int i = 0; i < listeners.size(); ) { + HANDLE handle = listeners[i].handle; + if (listeners[i].connected + || GetOverlappedResult(handle, &listeners[i].overlapped, &dummy, FALSE)) + { + listeners.removeAt(i); - addListener(); + addListener(); - if (pendingConnections.size() > maxPendingConnections) - connectionEventNotifier->setEnabled(false); + if (pendingConnections.size() > maxPendingConnections) + connectionEventNotifier->setEnabled(false); + else + tryAgain = true; - // Make this the last thing so connected slots can wreak the least havoc - q->incomingConnection((quintptr)handle); - } else { - if (GetLastError() != ERROR_IO_INCOMPLETE) { - q->close(); - setError(QLatin1String("QLocalServerPrivate::_q_onNewConnection")); - return; + // Make this the last thing so connected slots can wreak the least havoc + q->incomingConnection((quintptr)handle); + } else { + if (GetLastError() != ERROR_IO_INCOMPLETE) { + q->close(); + setError(QLatin1String("QLocalServerPrivate::_q_onNewConnection")); + return; + } + + ++i; } - - ++i; } - } + } while (tryAgain); } void QLocalServerPrivate::closeServer() diff --git a/tests/auto/network/socket/qlocalsocket/BLACKLIST b/tests/auto/network/socket/qlocalsocket/BLACKLIST deleted file mode 100644 index 11ddef30a58..00000000000 --- a/tests/auto/network/socket/qlocalsocket/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[processConnection:1 client] -windows From cf827f2167d7ca122541cc17307e2b8133ec3af4 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Wed, 9 Mar 2016 23:16:29 +0100 Subject: [PATCH 07/62] Ported Qt 4 fix when getting an invalid native key on Windows Task-number: QTBUG-36061 Change-Id: Ibde65735d861af4e1ef768e9e4314d30fed534a1 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowskeymapper.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index 5790341dbfe..403ac6ecfbc 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -1247,7 +1247,12 @@ QList QWindowsKeyMapper::possibleKeys(const QKeyEvent *e) const { QList result; - const KeyboardLayoutItem &kbItem = keyLayout[e->nativeVirtualKey()]; + + const quint32 nativeVirtualKey = e->nativeVirtualKey(); + if (nativeVirtualKey > 255) + return result; + + const KeyboardLayoutItem &kbItem = keyLayout[nativeVirtualKey]; if (!kbItem.exists) return result; From 71a36d0b6576b2174b708a714f92bbbe1b309d05 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Thu, 10 Mar 2016 14:34:45 +0100 Subject: [PATCH 08/62] Disable tests requiring shared build when compiling statically Change-Id: I06ec53e46d2f61f1685899b0f8a4d385051095d6 Reviewed-by: Oliver Wolff --- tests/auto/corelib/plugin/plugin.pro | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/auto/corelib/plugin/plugin.pro b/tests/auto/corelib/plugin/plugin.pro index 506f6abaebb..e132d9da1ab 100644 --- a/tests/auto/corelib/plugin/plugin.pro +++ b/tests/auto/corelib/plugin/plugin.pro @@ -5,3 +5,9 @@ SUBDIRS=\ qplugin \ qpluginloader \ quuid + +contains(CONFIG, static) { + message(Disabling tests requiring shared build of Qt) + SUBDIRS -= qfactoryloader \ + qpluginloader +} From 0c51277bb84d816963cae1a3274722753acbf167 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 8 Mar 2016 15:36:09 +0100 Subject: [PATCH 09/62] winrt: add logging to QWinRTScreen Task-number: QTBUG-38114 Change-Id: Id653487a03ca2920c46cf16e45f28677a69fa570 Reviewed-by: Oliver Wolff --- src/plugins/platforms/winrt/qwinrtscreen.cpp | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 4c4d553b2d7..831586538f6 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -39,8 +39,10 @@ #include "qwinrtbackingstore.h" #include "qwinrtinputcontext.h" #include "qwinrtcursor.h" +#include "qwinrtwindow.h" #include +#include #include #include #include @@ -469,6 +471,7 @@ QWinRTScreen::QWinRTScreen() : d_ptr(new QWinRTScreenPrivate) { Q_D(QWinRTScreen); + qCDebug(lcQpaWindows) << __FUNCTION__; d->orientation = Qt::PrimaryOrientation; d->touchDevice = Q_NULLPTR; @@ -553,6 +556,7 @@ QWinRTScreen::QWinRTScreen() QWinRTScreen::~QWinRTScreen() { Q_D(QWinRTScreen); + qCDebug(lcQpaWindows) << __FUNCTION__ << this; // Unregister callbacks HRESULT hr; @@ -697,6 +701,8 @@ Xaml::IDependencyObject *QWinRTScreen::canvas() const void QWinRTScreen::setStatusBarVisibility(bool visible, QWindow *window) { Q_D(QWinRTScreen); + qCDebug(lcQpaWindows) << __FUNCTION__ << window << visible; + const Qt::WindowFlags windowType = window->flags() & Qt::WindowType_Mask; if (!window || (windowType != Qt::Window && windowType != Qt::Dialog)) return; @@ -768,6 +774,7 @@ QWindow *QWinRTScreen::topWindow() const void QWinRTScreen::addWindow(QWindow *window) { Q_D(QWinRTScreen); + qCDebug(lcQpaWindows) << __FUNCTION__ << window; if (window == topWindow()) return; @@ -785,6 +792,7 @@ void QWinRTScreen::addWindow(QWindow *window) void QWinRTScreen::removeWindow(QWindow *window) { Q_D(QWinRTScreen); + qCDebug(lcQpaWindows) << __FUNCTION__ << window; #ifdef Q_OS_WINPHONE if (window->visibility() == QWindow::Minimized) @@ -1131,6 +1139,7 @@ HRESULT QWinRTScreen::onSizeChanged(ICoreWindow *, IWindowSizeChangedEventArgs * hr = d->coreWindow->get_Bounds(&size); RETURN_OK_IF_FAILED("Failed to get window bounds"); d->logicalSize = QSizeF(size.Width, size.Height); + qCDebug(lcQpaWindows) << __FUNCTION__ << d->logicalSize; QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), availableGeometry()); QPlatformScreen::resizeMaximizedWindows(); handleExpose(); @@ -1140,6 +1149,7 @@ HRESULT QWinRTScreen::onSizeChanged(ICoreWindow *, IWindowSizeChangedEventArgs * HRESULT QWinRTScreen::onActivated(ICoreWindow *, IWindowActivatedEventArgs *args) { Q_D(QWinRTScreen); + qCDebug(lcQpaWindows) << __FUNCTION__; CoreWindowActivationState activationState; args->get_WindowActivationState(&activationState); @@ -1159,6 +1169,8 @@ HRESULT QWinRTScreen::onActivated(ICoreWindow *, IWindowActivatedEventArgs *args HRESULT QWinRTScreen::onClosed(ICoreWindow *, ICoreWindowEventArgs *) { + qCDebug(lcQpaWindows) << __FUNCTION__; + foreach (QWindow *w, QGuiApplication::topLevelWindows()) QWindowSystemInterface::handleCloseEvent(w); return S_OK; @@ -1170,6 +1182,7 @@ HRESULT QWinRTScreen::onVisibilityChanged(ICoreWindow *, IVisibilityChangedEvent boolean visible; HRESULT hr = args ? args->get_Visible(&visible) : d->coreWindow->get_Visible(&visible); RETURN_OK_IF_FAILED("Failed to get visibility."); + qCDebug(lcQpaWindows) << __FUNCTION__ << visible; QWindowSystemInterface::handleApplicationStateChanged(visible ? Qt::ApplicationActive : Qt::ApplicationHidden); if (visible) handleExpose(); @@ -1179,7 +1192,7 @@ HRESULT QWinRTScreen::onVisibilityChanged(ICoreWindow *, IVisibilityChangedEvent HRESULT QWinRTScreen::onOrientationChanged(IDisplayInformation *, IInspectable *) { Q_D(QWinRTScreen); - + qCDebug(lcQpaWindows) << __FUNCTION__; DisplayOrientations displayOrientation; HRESULT hr = d->displayInformation->get_CurrentOrientation(&displayOrientation); RETURN_OK_IF_FAILED("Failed to get current orientations."); @@ -1187,6 +1200,7 @@ HRESULT QWinRTScreen::onOrientationChanged(IDisplayInformation *, IInspectable * Qt::ScreenOrientation newOrientation = static_cast(static_cast(qtOrientationsFromNative(displayOrientation))); if (d->orientation != newOrientation) { d->orientation = newOrientation; + qCDebug(lcQpaWindows) << " New orientation:" << newOrientation; #ifdef Q_OS_WINPHONE onSizeChanged(nullptr, nullptr); #endif @@ -1211,6 +1225,8 @@ HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *) hr = d->displayInformation->get_ResolutionScale(&resolutionScale); d->scaleFactor = qreal(resolutionScale) / 100; #endif + qCDebug(lcQpaWindows) << __FUNCTION__ << "Scale Factor:" << d->scaleFactor; + RETURN_OK_IF_FAILED("Failed to get scale factor"); FLOAT dpi; @@ -1225,6 +1241,8 @@ HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *) hr = d->displayInformation->get_RawDpiY(&dpi); RETURN_OK_IF_FAILED("Failed to get y raw DPI."); d->physicalDpi.second = dpi ? dpi : 96.0; + qCDebug(lcQpaWindows) << __FUNCTION__ << "Logical DPI:" << d->logicalDpi + << "Physical DPI:" << d->physicalDpi; return S_OK; } @@ -1232,12 +1250,14 @@ HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *) #ifdef Q_OS_WINPHONE HRESULT QWinRTScreen::onStatusBarShowing(IStatusBar *, IInspectable *) { + qCDebug(lcQpaWindows) << __FUNCTION__; onSizeChanged(nullptr, nullptr); return S_OK; } HRESULT QWinRTScreen::onStatusBarHiding(IStatusBar *, IInspectable *) { + qCDebug(lcQpaWindows) << __FUNCTION__; onSizeChanged(nullptr, nullptr); return S_OK; } From 1929e48bba631465c256265a2ed31128e7217aca Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 8 Mar 2016 15:39:36 +0100 Subject: [PATCH 10/62] winrt: Fix painting glitches when orientation changes In addition to handling the pure rotation enforce a size change as well. This way content is redrawn for the correct orientation. It was done for Windows Phone 8.1 already, we only need to extent this to Windows 10. Task-number: QTBUG-50336 Change-Id: I6b3b964f44b631757ea856331c50f53c39ed9ec3 Reviewed-by: Oliver Wolff --- src/plugins/platforms/winrt/qwinrtscreen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 831586538f6..2410848cdee 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -1201,7 +1201,7 @@ HRESULT QWinRTScreen::onOrientationChanged(IDisplayInformation *, IInspectable * if (d->orientation != newOrientation) { d->orientation = newOrientation; qCDebug(lcQpaWindows) << " New orientation:" << newOrientation; -#ifdef Q_OS_WINPHONE +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) onSizeChanged(nullptr, nullptr); #endif QWindowSystemInterface::handleScreenOrientationChange(screen(), d->orientation); From a2d58025b63d43a843bf14138221086f25c280f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 10 Mar 2016 12:50:52 +0100 Subject: [PATCH 11/62] Cocoa: Improve native view lifetime accuracy. Ideally all native NSWindows and NSViews owned by QCocoaWindow should be deallocated during the QCocoaWindow destructor. In reality this does not always happen since Cocoa is free to hold references to the views after Qt releases its reference. We can help Cocoa clean up: - Clear the first responder for the NSWindow under the ~QCocoaWndow() autoreleasepool. - Use an autoreleasepool to clean up temp objects from [NSWindow orderFront:] immediately. Together this makes the QNSView lifetime be contained by the QCocoaWindow lifetime, at least for simple QWindow usage. It also fixes the observed memory leak reported in QTBUG-51766 Change-Id: Idd224f54ebd6f61f274461a204ff30c666b22768 Task-number: QTBUG-51766 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoawindow.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 00cb43c9405..e4cd57a115d 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -409,6 +409,7 @@ QCocoaWindow::~QCocoaWindow() #endif QMacAutoReleasePool pool; + [m_nsWindow makeFirstResponder:nil]; [m_nsWindow setContentView:nil]; [m_nsWindow.helper detachFromPlatformWindow]; if (m_isNSWindowChild) { @@ -990,7 +991,15 @@ void QCocoaWindow::raise() [parentNSWindow removeChildWindow:m_nsWindow]; [parentNSWindow addChildWindow:m_nsWindow ordered:NSWindowAbove]; } else { - [m_nsWindow orderFront: m_nsWindow]; + { + // Clean up autoreleased temp objects from orderFront immediately. + // Failure to do so has been observed to cause leaks also beyond any outer + // autorelease pool (for example around a complete QWindow + // construct-show-raise-hide-delete cyle), counter to expected autoreleasepool + // behavior. + QMacAutoReleasePool pool; + [m_nsWindow orderFront: m_nsWindow]; + } static bool raiseProcess = qt_mac_resolveOption(true, "QT_MAC_SET_RAISE_PROCESS"); if (raiseProcess) { ProcessSerialNumber psn; From a8c72b7671637d18b1915d7e46fc601e8ffde2d7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 10 Mar 2016 16:35:53 +0100 Subject: [PATCH 12/62] tst_QTextStream::textModeOnEmptyRead(): Create file in temporary directory. A test should not write to its directory. Amends change d0b54cede8d8ea0b8431c64abb51d0cd1a71327b. Task-number: QTBUG-47176 Change-Id: If15258b4aed199792fab422b7ac1d74e22a9e322 Reviewed-by: Maurice Kalinowski --- tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index a0348f3c54f..24dd05223f4 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -3049,12 +3049,10 @@ void tst_QTextStream::int_write_with_locale() void tst_QTextStream::textModeOnEmptyRead() { - const QString filename("textmodetest.txt"); - QFile::remove(filename); // Remove file if exists - + const QString filename(tempDir.path() + QLatin1String("/textmodetest.txt")); QFile file(filename); - QVERIFY(file.open(QIODevice::ReadWrite | QIODevice::Text)); + QVERIFY2(file.open(QIODevice::ReadWrite | QIODevice::Text), qPrintable(file.errorString())); QTextStream stream(&file); QVERIFY(file.isTextModeEnabled()); QString emptyLine = stream.readLine(); // Text mode flag cleared here From 514c202da95bbe876c9759961a8032eae4b96bdd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 8 Jan 2016 10:04:02 +0100 Subject: [PATCH 13/62] Add a manual test for foreign windows. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a command line tool that can either take a list of window ids and output information on them using a verbose debug stream or embed foreign windows using QWidget::createWindowContainer(). Task-number: QTBUG-41186 Change-Id: I14e436b5d08828f5b78b29e0701daeffe11367d3 Reviewed-by: Morten Johan Sørvig --- .../manual/foreignwindows/foreignwindows.pro | 6 + tests/manual/foreignwindows/main.cpp | 329 ++++++++++++++++++ tests/manual/manual.pro | 4 +- 3 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 tests/manual/foreignwindows/foreignwindows.pro create mode 100644 tests/manual/foreignwindows/main.cpp diff --git a/tests/manual/foreignwindows/foreignwindows.pro b/tests/manual/foreignwindows/foreignwindows.pro new file mode 100644 index 00000000000..6a370a68131 --- /dev/null +++ b/tests/manual/foreignwindows/foreignwindows.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +QT += widgets +CONFIG += console c++11 +CONFIG -= app_bundle +SOURCES += main.cpp +include(../diaglib/diaglib.pri) diff --git a/tests/manual/foreignwindows/main.cpp b/tests/manual/foreignwindows/main.cpp new file mode 100644 index 00000000000..6c722a3f6fc --- /dev/null +++ b/tests/manual/foreignwindows/main.cpp @@ -0,0 +1,329 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_OS_WIN +# include +#endif + +#include // diaglib +#include +#include +#include + +#include +#include + +QT_USE_NAMESPACE + +typedef QSharedPointer WidgetPtr; +typedef QList WidgetPtrList; +typedef QList WIdList; + +// Create some pre-defined Windows controls by class name +static WId createInternalWindow(const QString &name) +{ + WId result = 0; +#ifdef Q_OS_WIN + if (name == QLatin1String("BUTTON") || name == QLatin1String("COMBOBOX") + || name == QLatin1String("EDIT") || name.startsWith(QLatin1String("RICHEDIT"))) { + const HWND hwnd = + CreateWindowEx(0, reinterpret_cast(name.utf16()), + L"NativeCtrl", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + 0, 0, GetModuleHandle(NULL), NULL); + if (hwnd) { + SetWindowText(hwnd, L"Demo"); + result = WId(hwnd); + } else { + qErrnoWarning("Cannot create window \"%s\"", qPrintable(name)); + } + } +#else // Q_OS_WIN + Q_UNUSED(name) +#endif + return result; +} + +// Embed a foreign window using createWindowContainer() providing +// menu actions to dump information. +class EmbeddingWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit EmbeddingWindow(QWindow *window); + +public slots: + void releaseForeignWindow(); + +private: + QWindow *m_window; + QAction *m_releaseAction; +}; + +EmbeddingWindow::EmbeddingWindow(QWindow *window) : m_window(window) +{ + const QString title = QLatin1String("Qt ") + QLatin1String(QT_VERSION_STR) + + QLatin1String(" 0x") + QString::number(window->winId(), 16); + setWindowTitle(title); + setObjectName("MainWindow"); + QWidget *container = QWidget::createWindowContainer(window, Q_NULLPTR, Qt::Widget); + container->setObjectName("Container"); + setCentralWidget(container); + + QMenu *fileMenu = menuBar()->addMenu("File"); + fileMenu->setObjectName("FileMenu"); + QToolBar *toolbar = new QToolBar; + addToolBar(Qt::TopToolBarArea, toolbar); + + // Manipulation + QAction *action = fileMenu->addAction("Visible"); + action->setCheckable(true); + action->setChecked(true); + connect(action, &QAction::toggled, m_window, &QWindow::setVisible); + toolbar->addAction(action); + + m_releaseAction = fileMenu->addAction("Release", this, &EmbeddingWindow::releaseForeignWindow); + toolbar->addAction(m_releaseAction); + + fileMenu->addSeparator(); // Diaglib actions + action = fileMenu->addAction("Dump Widgets", + this, [] () { QtDiag::dumpAllWidgets(); }); + toolbar->addAction(action); + action = fileMenu->addAction("Dump Windows", + this, [] () { QtDiag::dumpAllWindows(); }); + toolbar->addAction(action); + action = fileMenu->addAction("Dump Native Windows", + this, [this] () { QtDiag::dumpNativeWindows(winId()); }); + toolbar->addAction(action); + + fileMenu->addSeparator(); + action = fileMenu->addAction("Quit", qApp, &QCoreApplication::quit); + toolbar->addAction(action); + action->setShortcut(Qt::CTRL + Qt::Key_Q); +} + +void EmbeddingWindow::releaseForeignWindow() +{ + if (m_window) { + m_window->setParent(Q_NULLPTR); + m_window = Q_NULLPTR; + m_releaseAction->setEnabled(false); + } +} + +// Dump information about foreign windows. +class WindowDumper : public QObject { + Q_OBJECT +public: + explicit WindowDumper(const QWindowList &watchedWindows) + : m_watchedWindows(watchedWindows) {} + +public slots: + void dump() const; + +private: + const QWindowList m_watchedWindows; +}; + +void WindowDumper::dump() const +{ + static int n = 0; + QString s; + QDebug debug(&s); + debug.nospace(); + debug.setVerbosity(3); + debug << '#' << n++; + if (m_watchedWindows.size() > 1) + debug << '\n'; + foreach (const QWindow *w, m_watchedWindows) { + const QPoint globalPos = w->mapToGlobal(QPoint()); + debug << " " << w << " pos=" << globalPos.x() << ',' << globalPos.y() << '\n'; + } + + std::cout << qPrintable(s); +} + +static QString description(const QString &appName) +{ + QString result; + QTextStream(&result) + << "\nDumps information about foreign windows passed on the command line or\n" + "tests embedding foreign windows into Qt.\n\nUse cases:\n\n" + << appName << " -a Dump a list of all native window ids.\n" + << appName << " Dump information on the window.\n" + << appName << " -c Dump information on the window continuously.\n" + << appName << " -e Embed window into a Qt widget.\n" + << "\nOn Windows, class names of well known controls (EDIT, BUTTON...) can be\n" + "passed as along with -e, which will create the control.\n"; + return result; +} + +struct EventFilterOption +{ + const char *name; + const char *description; + QtDiag::EventFilter::EventCategories categories; +}; + +EventFilterOption eventFilterOptions[] = { +{"mouse-events", "Dump mouse events.", QtDiag::EventFilter::MouseEvents}, +{"keyboard-events", "Dump keyboard events.", QtDiag::EventFilter::KeyEvents}, +{"state-events", "Dump state/focus change events.", QtDiag::EventFilter::StateChangeEvents | QtDiag::EventFilter::FocusEvents} +}; + +static inline bool isOptionSet(int argc, char *argv[], const char *option) +{ + return (argv + argc) != + std::find_if(argv + 1, argv + argc, + [option] (const char *arg) { return !qstrcmp(arg, option); }); +} + +int main(int argc, char *argv[]) +{ + // Check for no scaling before QApplication is instantiated. + if (isOptionSet(argc, argv, "-s")) + QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); + QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); + QGuiApplication::setApplicationDisplayName("Foreign window tester"); + + QApplication app(argc, argv); + + QCommandLineParser parser; + parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); + parser.setApplicationDescription(description(QCoreApplication::applicationName())); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption noScalingDummy(QStringLiteral("s"), + QStringLiteral("Disable High DPI scaling.")); + parser.addOption(noScalingDummy); + QCommandLineOption outputAllOption(QStringList() << QStringLiteral("a") << QStringLiteral("all"), + QStringLiteral("Output all native window ids (requires diaglib).")); + parser.addOption(outputAllOption); + QCommandLineOption continuousOption(QStringList() << QStringLiteral("c") << QStringLiteral("continuous"), + QStringLiteral("Output continuously.")); + parser.addOption(continuousOption); + QCommandLineOption embedOption(QStringList() << QStringLiteral("e") << QStringLiteral("embed"), + QStringLiteral("Embed a foreign window into a Qt widget.")); + parser.addOption(embedOption); + const int eventFilterOptionCount = int(sizeof(eventFilterOptions) / sizeof(eventFilterOptions[0])); + for (int i = 0; i < eventFilterOptionCount; ++i) { + parser.addOption(QCommandLineOption(QLatin1String(eventFilterOptions[i].name), + QLatin1String(eventFilterOptions[i].description))); + } + parser.addPositionalArgument(QStringLiteral("[windows]"), QStringLiteral("Window IDs.")); + + parser.process(QCoreApplication::arguments()); + + if (parser.isSet(outputAllOption)) { + QtDiag::dumpNativeWindows(); + return 0; + } + + QWindowList windows; + foreach (const QString &argument, parser.positionalArguments()) { + bool ok = true; + WId wid = createInternalWindow(argument); + if (!wid) + wid = argument.toULongLong(&ok, 0); + if (!wid || !ok) { + std::cerr << "Invalid window id: \"" << qPrintable(argument) << "\"\n"; + return -1; + } + QWindow *foreignWindow = QWindow::fromWinId(wid); + foreignWindow->setObjectName("ForeignWindow" + QString::number(wid, 16)); + windows.append(foreignWindow); + } + + if (windows.isEmpty()) + parser.showHelp(0); + + int exitCode = 0; + + if (parser.isSet(embedOption)) { + QtDiag::EventFilter::EventCategories eventCategories = 0; + for (int i = 0; i < eventFilterOptionCount; ++i) { + if (parser.isSet(QLatin1String(eventFilterOptions[i].name))) + eventCategories |= eventFilterOptions[i].categories; + } + if (eventCategories) + app.installEventFilter(new QtDiag::EventFilter(eventCategories, &app)); + + const QRect availableGeometry = QApplication::desktop()->availableGeometry(0); + QPoint pos = availableGeometry.topLeft() + QPoint(availableGeometry.width(), availableGeometry.height()) / 3; + + WidgetPtrList mainWindows; + foreach (QWindow *window, windows) { + WidgetPtr mainWindow(new EmbeddingWindow(window)); + mainWindow->move(pos); + mainWindow->resize(availableGeometry.size() / 4); + mainWindow->show(); + pos += QPoint(40, 40); + mainWindows.append(mainWindow); + } + exitCode = app.exec(); + + } else if (parser.isSet(continuousOption)) { + WindowDumper dumper(windows); + dumper.dump(); + QTimer *timer = new QTimer(&dumper); + QObject::connect(timer, &QTimer::timeout, &dumper, &WindowDumper::dump); + timer->start(1000); + exitCode = app.exec(); + + } else { + WindowDumper(windows).dump(); + } + + return exitCode; +} + +#include "main.moc" diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index cffe76b2b41..8777cc6e116 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -2,6 +2,7 @@ TEMPLATE=subdirs SUBDIRS = bearerex \ filetest \ +foreignwindows \ gestures \ inputmethodhints \ keypadnavigation \ @@ -62,4 +63,5 @@ win32 { } lessThan(QT_MAJOR_VERSION, 5): SUBDIRS -= bearerex lance qnetworkaccessmanager/qget qmimedatabase qnetworkreply \ -qpainfo qscreen socketengine xembed-raster xembed-widgets windowtransparency +qpainfo qscreen socketengine xembed-raster xembed-widgets windowtransparency \ +foreignwindows From 978804d2c229e1b15b497cb8de18032d1e220529 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 11 Mar 2016 14:59:19 +0100 Subject: [PATCH 14/62] QNetworkHeaders: fix UB (invalid enum value) in Private::parseAndSetHeader() Found by UBSan: qnetworkrequest.cpp:1016:19: runtime error: load of value 4294967295, which is not a valid value for type 'KnownHeaders' KnownHeaders does not contain a failure state, and no negative values. -1 is therefore not a valid value for an object of type KnownHeaders, so loading one is considered UB. Fix by returning the result of parseHeaderName() as an int, only casting to KnownHeaders after checking for the failure case. Change-Id: I6b165fe2b15c747344a9b2750bb753582c5bcbeb Reviewed-by: Richard J. Moore --- src/network/access/qnetworkrequest.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 558e015ae4c..f5010198f30 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -798,10 +798,10 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria return QByteArray(); } -static QNetworkRequest::KnownHeaders parseHeaderName(const QByteArray &headerName) +static int parseHeaderName(const QByteArray &headerName) { if (headerName.isEmpty()) - return QNetworkRequest::KnownHeaders(-1); + return -1; switch (tolower(headerName.at(0))) { case 'c': @@ -833,7 +833,7 @@ static QNetworkRequest::KnownHeaders parseHeaderName(const QByteArray &headerNam break; } - return QNetworkRequest::KnownHeaders(-1); // nothing found + return -1; // nothing found } static QVariant parseHttpDate(const QByteArray &raw) @@ -1005,8 +1005,10 @@ void QNetworkHeadersPrivate::setRawHeaderInternal(const QByteArray &key, const Q void QNetworkHeadersPrivate::parseAndSetHeader(const QByteArray &key, const QByteArray &value) { // is it a known header? - QNetworkRequest::KnownHeaders parsedKey = parseHeaderName(key); - if (parsedKey != QNetworkRequest::KnownHeaders(-1)) { + const int parsedKeyAsInt = parseHeaderName(key); + if (parsedKeyAsInt != -1) { + const QNetworkRequest::KnownHeaders parsedKey + = static_cast(parsedKeyAsInt); if (value.isNull()) { cookedHeaders.remove(parsedKey); } else if (parsedKey == QNetworkRequest::ContentLengthHeader From 5fe0e41e79030d14d8e32bda7fb5412d8c335c52 Mon Sep 17 00:00:00 2001 From: "Richard J. Moore" Date: Sat, 12 Mar 2016 16:47:14 +0000 Subject: [PATCH 15/62] Do not send the trailing dot of a hostname as part of the SNI The SNI extension must not include the trailing dot, even though this is legitimate for the host header. Task-number: QTBUG-51821 Change-Id: Ib7a7d8b1f8f98bc99ae745b03d2b97e507adefaf Reviewed-by: Daniel Molkentin (ownCloud) --- src/network/ssl/qsslsocket_openssl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index dd47dfc45f6..244d4bbebfa 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -390,6 +390,10 @@ bool QSslSocketBackendPrivate::initSslContext() if (!ace.isEmpty() && !QHostAddress().setAddress(tlsHostName) && !(configuration.sslOptions & QSsl::SslOptionDisableServerNameIndication)) { + // We don't send the trailing dot from the host header if present see + // https://tools.ietf.org/html/rfc6066#section-3 + if (ace.endsWith('.')) + ace.chop(1); if (!q_SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, ace.data())) qCWarning(lcSsl, "could not set SSL_CTRL_SET_TLSEXT_HOSTNAME, Server Name Indication disabled"); } From 063ad1c8b629318288223792c0ca7ab3f991f3e6 Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Wed, 10 Feb 2016 17:20:35 +0100 Subject: [PATCH 16/62] Don't include by default ciphers that are not supported There could be cases (mostly when compiled on old systems, since modern openssl versions don't include such insecure ciphers) in which defaultCiphers included a cipher that wasn't in the supported ciphers list. With this patch we make sure that defaultCiphers is a subset of supportedCiphers Change-Id: I545ea21f5fd3a6ed13b366cdd56a1393233f9fc9 Reviewed-by: Richard J. Moore --- src/network/ssl/qsslsocket_openssl.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index 244d4bbebfa..8caa56ee5b5 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -643,10 +643,12 @@ void QSslSocketPrivate::resetDefaultCiphers() // Unconditionally exclude ADH and AECDH ciphers since they offer no MITM protection if (!ciph.name().toLower().startsWith(QLatin1String("adh")) && !ciph.name().toLower().startsWith(QLatin1String("exp-adh")) && - !ciph.name().toLower().startsWith(QLatin1String("aecdh"))) + !ciph.name().toLower().startsWith(QLatin1String("aecdh"))) { ciphers << ciph; - if (ciph.usedBits() >= 128) - defaultCiphers << ciph; + + if (ciph.usedBits() >= 128) + defaultCiphers << ciph; + } } } } From c4886ca42732feb51648985b741a8113382a6fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 14 Mar 2016 09:52:09 +0100 Subject: [PATCH 17/62] Cocoa: Fix crash on screen disconnect. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Maintain virtual siblings list on screen deletion. QCocoaIntegration::updateScreens() has a loop which will delete all non-current QScreen objects using QPlatformIntegration::destroyScreen(). destroyScreen() vill eventually call QWindowPrivate:: setTopLevelScreen() which accesses the virtual siblings list for the deleted screen. This can cause a stale pointer access if the virtual screen list is not up to date, especially when disconnecting two screens at the same time. Change-Id: Ia6b9d01edf8e5eea25b64604a2b3b28b173125f7 Task-number: QTBUG-48275 Reviewed-by: Timur Pocheptsov Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaintegration.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 6bec6b191d5..91d4b2706bc 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -422,14 +422,18 @@ void QCocoaIntegration::updateScreens() } siblings << screen; } + + // Set virtual siblings list. All screens in mScreens are siblings, because we ignored the + // mirrors. Note that some of the screens we update the siblings list for here may be deleted + // below, but update anyway to keep the to-be-deleted screens out of the siblings list. + foreach (QCocoaScreen* screen, mScreens) + screen->setVirtualSiblings(siblings); + // Now the leftovers in remainingScreens are no longer current, so we can delete them. foreach (QCocoaScreen* screen, remainingScreens) { mScreens.removeOne(screen); destroyScreen(screen); } - // All screens in mScreens are siblings, because we ignored the mirrors. - foreach (QCocoaScreen* screen, mScreens) - screen->setVirtualSiblings(siblings); } QCocoaScreen *QCocoaIntegration::screenAtIndex(int index) From 11836be1274196bca5883973b3c8f31dc07c34f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20Szczygie=C5=82?= Date: Thu, 10 Mar 2016 23:18:43 +0100 Subject: [PATCH 18/62] Remove Qt::WA_OutsideWSRange flag even if the widget is not yet visible. Show the widget when its initial size is 0 and the layout changes the size during showing. Task-number: QTBUG-51788 Change-Id: I3251ac27328f9715ff13d96e1b82fbf824d9e79d Reviewed-by: Dmitry Shachnev Reviewed-by: Shawn Rutledge --- src/widgets/kernel/qwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7bd4920ff15..7529f5b3444 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7216,7 +7216,7 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) if (q->isVisible()) hide_sys(); data.crect = QRect(x, y, w, h); - } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) { + } else if (q->testAttribute(Qt::WA_OutsideWSRange)) { q->setAttribute(Qt::WA_OutsideWSRange, false); needsShow = true; } From 1a9e1fbbfc96b84bf96927b3573a6528bffc98a5 Mon Sep 17 00:00:00 2001 From: Milla Pohjanheimo Date: Thu, 10 Mar 2016 12:28:57 +0200 Subject: [PATCH 19/62] Remove restoreDockWidget from BLACKLIST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested on the Ubuntu 14.04 VM. The test didn't fail anymore with 2000 test rounds Change-Id: Ic12c60e5ebf9c234358a6983bf87fa0a88d7886e Reviewed-by: Tony Sarajärvi --- tests/auto/widgets/widgets/qdockwidget/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 tests/auto/widgets/widgets/qdockwidget/BLACKLIST diff --git a/tests/auto/widgets/widgets/qdockwidget/BLACKLIST b/tests/auto/widgets/widgets/qdockwidget/BLACKLIST deleted file mode 100644 index 60adfb9f4bb..00000000000 --- a/tests/auto/widgets/widgets/qdockwidget/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[restoreDockWidget] -ubuntu-14.04 From 52a599bb56e5e5e625909c25edee8487b0a3754d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 12 Mar 2016 11:34:48 +0100 Subject: [PATCH 20/62] QCosmeticStroker: fix several UBs involving << with a negative LHS Left-shifts of negative values are undefined in C++. In particular, they don't behave arithmetically. Reported by UBSan: qcosmeticstroker.cpp: 72:15: runtime error: left shift of negative value -14/-19/-32/-33/-34/-37/-38/-63/-64/-192/-384/-1280 qcosmeticstroker.cpp:444:20: runtime error: left shift of negative value -64 qcosmeticstroker.cpp:451:26: runtime error: left shift of negative value -1 qcosmeticstroker.cpp:483:26: runtime error: left shift of negative value -1 qcosmeticstroker.cpp:762:20: runtime error: left shift of negative value -64 qcosmeticstroker.cpp:774:26: runtime error: left shift of negative value -1 qcosmeticstroker.cpp:813:47: runtime error: left shift of negative value -1 qcosmeticstroker.cpp:839:20: runtime error: left shift of negative value -64 qcosmeticstroker.cpp:851:26: runtime error: left shift of negative value -1 qcosmeticstroker.cpp:889:47: runtime error: left shift of negative value -1 qcosmeticstroker.cpp:932:27: runtime error: left shift of negative value -64 qcosmeticstroker.cpp:995:27: runtime error: left shift of negative value -3/-64 Fix by using ordinary multiplication instead, because negative left-hand-side values don't look like they are an error. Change-Id: Icbebd41f6ddd3dca4abd385585fc0f82064fe8b6 Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qcosmeticstroker.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/painting/qcosmeticstroker.cpp b/src/gui/painting/qcosmeticstroker.cpp index b310336b9bb..64da03f13af 100644 --- a/src/gui/painting/qcosmeticstroker.cpp +++ b/src/gui/painting/qcosmeticstroker.cpp @@ -62,8 +62,8 @@ static inline uint sourceOver(uint d, uint color) inline static int F16Dot16FixedDiv(int x, int y) { if (qAbs(x) > 0x7fff) - return (((qlonglong)x) << 16) / y; - return (x << 16) / y; + return qlonglong(x) * (1<<16) / y; + return x * (1<<16) / y; } typedef void (*DrawPixel)(QCosmeticStroker *stroker, int x, int y, int coverage); @@ -435,14 +435,14 @@ void QCosmeticStroker::calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal qSwap(x1, x2); } int xinc = F16Dot16FixedDiv(x2 - x1, y2 - y1); - int x = x1 << 10; + int x = x1 * (1<<10); int y = (y1 + 32) >> 6; int ys = (y2 + 32) >> 6; int round = (xinc > 0) ? 32 : 0; if (y != ys) { - x += ( ((((y << 6) + round - y1))) * xinc ) >> 6; + x += ((y * (1<<6)) + round - y1) * xinc >> 6; if (swapped) { lastPixel.x = x >> 16; @@ -474,7 +474,7 @@ void QCosmeticStroker::calculateLastPoint(qreal rx1, qreal ry1, qreal rx2, qreal int round = (yinc > 0) ? 32 : 0; if (x != xs) { - y += ( ((((x << 6) + round - x1))) * yinc ) >> 6; + y += ((x * (1<<6)) + round - x1) * yinc >> 6; if (swapped) { lastPixel.x = x; @@ -753,7 +753,7 @@ static bool drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2, dir = QCosmeticStroker::BottomToTop; } int xinc = F16Dot16FixedDiv(x2 - x1, y2 - y1); - int x = x1 << 10; + int x = x1 * (1<<10); if ((stroker->lastDir ^ QCosmeticStroker::VerticalMask) == dir) caps |= swapped ? QCosmeticStroker::CapEnd : QCosmeticStroker::CapBegin; @@ -765,7 +765,7 @@ static bool drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2, int round = (xinc > 0) ? 32 : 0; if (y != ys) { - x += ( ((((y << 6) + round - y1))) * xinc ) >> 6; + x += ((y * (1<<6)) + round - y1) * xinc >> 6; // calculate first and last pixel and perform dropout control QCosmeticStroker::Point first; @@ -804,7 +804,7 @@ static bool drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2, stroker->lastDir = dir; stroker->lastAxisAligned = axisAligned; - Dasher dasher(stroker, swapped, y << 6, ys << 6); + Dasher dasher(stroker, swapped, y * (1<<6), ys * (1<<6)); do { if (dasher.on()) @@ -830,7 +830,7 @@ static bool drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2, dir = QCosmeticStroker::RightToLeft; } int yinc = F16Dot16FixedDiv(y2 - y1, x2 - x1); - int y = y1 << 10; + int y = y1 * (1<<10); if ((stroker->lastDir ^ QCosmeticStroker::HorizontalMask) == dir) caps |= swapped ? QCosmeticStroker::CapEnd : QCosmeticStroker::CapBegin; @@ -842,7 +842,7 @@ static bool drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2, int round = (yinc > 0) ? 32 : 0; if (x != xs) { - y += ( ((((x << 6) + round - x1))) * yinc ) >> 6; + y += ((x * (1<<6)) + round - x1) * yinc >> 6; // calculate first and last pixel to perform dropout control QCosmeticStroker::Point first; @@ -880,7 +880,7 @@ static bool drawLine(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx2, stroker->lastDir = dir; stroker->lastAxisAligned = axisAligned; - Dasher dasher(stroker, swapped, x << 6, xs << 6); + Dasher dasher(stroker, swapped, x * (1<<6), xs * (1<<6)); do { if (dasher.on()) @@ -923,7 +923,7 @@ static bool drawLineAA(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx caps = swapCaps(caps); } - int x = (x1 - 32) << 10; + int x = (x1 - 32) * (1<<10); x -= ( ((y1 & 63) - 32) * xinc ) >> 6; capAdjust(caps, y1, y2, x, xinc); @@ -986,7 +986,7 @@ static bool drawLineAA(QCosmeticStroker *stroker, qreal rx1, qreal ry1, qreal rx caps = swapCaps(caps); } - int y = (y1 - 32) << 10; + int y = (y1 - 32) * (1<<10); y -= ( ((x1 & 63) - 32) * yinc ) >> 6; capAdjust(caps, x1, x2, y, yinc); From add95c55108dcda46286846dae5ad12d6ee9057b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 12 Mar 2016 15:03:16 +0100 Subject: [PATCH 21/62] tst_QSqlQuery: fix UBs (invalid downcasts, member calls) The existing code derived a helper class from QSqlResult and overloaded two protected functions as public ones so the test could call them after casting QSqlResults to that helper class. Both the cast (which is a C-style cast, but with combined static_cast and const_cast semanics) and the following member function call are undefined behavior. Fix by making the test class a friend of QSqlResult, and dropping the casts. Change-Id: I09de2e2b46976d01cfce25892aec6ad36881d3eb Reviewed-by: Mark Brand --- src/sql/kernel/qsqlresult.h | 5 ++ .../sql/kernel/qsqlquery/tst_qsqlquery.cpp | 82 ++++++++----------- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/sql/kernel/qsqlresult.h b/src/sql/kernel/qsqlresult.h index c86a8f858fc..eeef68d2b86 100644 --- a/src/sql/kernel/qsqlresult.h +++ b/src/sql/kernel/qsqlresult.h @@ -38,6 +38,9 @@ #include #include +// for testing: +class tst_QSqlQuery; + QT_BEGIN_NAMESPACE @@ -54,6 +57,8 @@ class Q_SQL_EXPORT QSqlResult Q_DECLARE_PRIVATE(QSqlResult) friend class QSqlQuery; friend class QSqlTableModelPrivate; + // for testing: + friend class ::tst_QSqlQuery; public: virtual ~QSqlResult(); diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index b98ab68ae9f..bd553d5ffd6 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -1753,24 +1753,6 @@ void tst_QSqlQuery::synonyms() QCOMPARE( rec.field( 2 ).name().toLower(), QString( "t_varchar" ) ); } -// This class is used to test protected QSqlResult methods -class ResultHelper: public QSqlResult -{ - -public: - ResultHelper(): QSqlResult( 0 ) {} // don't call, it's only for stupid compilers - - bool execBatch( bool bindArray = false ) - { - return QSqlResult::execBatch( bindArray ); - } - - QString boundValueName( int pos ) const - { - return QSqlResult::boundValueName( pos ); - } -}; - // It doesn't make sense to split this into several tests void tst_QSqlQuery::prepare_bind_exec() { @@ -1895,81 +1877,81 @@ void tst_QSqlQuery::prepare_bind_exec() q.bindValue( 0, 0 ); q.bindValue( 1, values[ 0 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 0 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[0] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 0); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[0]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 0 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[0] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 0); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[0]); q.addBindValue( 1 ); q.addBindValue( values[ 1 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 1 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[1] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 1); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[1]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 1 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[1] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 1); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[1]); q.addBindValue( 2 ); q.addBindValue( values[ 2 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[2] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 2); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[2]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[2] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 2); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[2]); q.addBindValue( 3 ); q.addBindValue( values[ 3 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 3 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[3] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 3); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[3]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 3 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[3] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 3); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[3]); q.addBindValue( 4 ); q.addBindValue( values[ 4 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 4 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[4] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 4); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[4]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 4 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[4] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 4); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[4]); q.bindValue( 1, values[ 5 ] ); q.bindValue( 0, 5 ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 5 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[5] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 5); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[5]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 5 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[5] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 5); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[5]); q.bindValue( 0, 6 ); q.bindValue( 1, QString() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 6 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), QString() ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 6); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), QString()); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 6 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), QString() ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 6); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), QString()); if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) { q.bindValue( 0, 7 ); q.bindValue( 1, utf8str ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 7 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), utf8str ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 7); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), utf8str); QVERIFY_SQL( q, exec() ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 7 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), utf8str ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 7); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), utf8str); } QVERIFY_SQL( q, exec( "SELECT * FROM " + qtest_prepare + " order by id" ) ); From 9739cae4c84218e1a805bbd82b2f40fe20d57b74 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 10 Mar 2016 09:53:36 +0100 Subject: [PATCH 22/62] QRawFont: fix UB (misaligned load) in fontTable() Found by UBSan: qrawfont.cpp:618:60: runtime error: load of misaligned address 0x2acee92a5569 for type 'const quint32', which requires 4 byte alignment Fix by using MAKE_TAG(), like everywhere else, instead of a load through a type-punned and misaligned pointer. Change-Id: I52b88ca05a57f7d8c5e5bce953384de49514079b Reviewed-by: Konstantin Ritt Reviewed-by: Lars Knoll --- src/gui/text/qrawfont.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/text/qrawfont.cpp b/src/gui/text/qrawfont.cpp index 0fd5f510c76..59f13581dd8 100644 --- a/src/gui/text/qrawfont.cpp +++ b/src/gui/text/qrawfont.cpp @@ -607,8 +607,7 @@ QByteArray QRawFont::fontTable(const char *tagName) const if (!d->isValid()) return QByteArray(); - const quint32 *tagId = reinterpret_cast(tagName); - return d->fontEngine->getSfntTable(qToBigEndian(*tagId)); + return d->fontEngine->getSfntTable(MAKE_TAG(tagName[0], tagName[1], tagName[2], tagName[3])); } /*! From b4fa18a996bc29bbb04e7358ef57b287076b0aae Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 12 Mar 2016 00:58:52 +0100 Subject: [PATCH 23/62] Revert "Handle the QWidgetPrivate::mapper structure" This reverts commit 90de48493be283b9afb249f6a0fd8dbd8958517d. The call isn't necessary, but invokes undefined behavior. It invokes undefined behavior because deleteTLSysExtra() is called from deleteExtra(), which is called from ~QWidgetPrivate(), which is called from ~QObject(). Thus, by the time we call q->windowType() within setWinId(), q is no longer a QWidget, but only a QObject, and calling a QWidget member function then is UB. UBSan confirms: qwidget_p.h:300:5: runtime error: downcast of address 0x2afdd4053620 which does not point to an object of type 'QWidget' (the Q_Q macro) 0x2afdd4053620: note: object is of type 'QObject' qwidget.cpp:1712:93: runtime error: member call on address 0x2afdd4053620 which does not point to an object of type 'QWidget' 0x2afdd4053620: note: object is of type 'QObject' It is also unnecessary: deleteTLSysExtra() is called from two places: QWidget::destroy() and deleteExtra(). deleteExtra() is only called from ~QWidgetPrivate() which is only called from ~QObject() called by ~QWidget(), which, however, already calls QWidget::destroy(). QWidget::destroy(), in turn, unconditionally (for non-desktop widgets, at least) calls setWinId(0) itself. So fix the UB by removing the call without replacement. Conflicts: src/gui/kernel/qwidget_qpa.cpp Change-Id: Ib3a8cc9d28a096183f1d3dfd1941ea5fdc6a4aac Reviewed-by: Friedemann Kleint --- src/widgets/kernel/qwidget.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7529f5b3444..6fdd5d3d0e4 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1880,7 +1880,6 @@ void QWidgetPrivate::deleteTLSysExtra() if (extra->topextra->window) { extra->topextra->window->destroy(); } - setWinId(0); delete extra->topextra->window; extra->topextra->window = 0; From 5784c064a9c89ceb1e6dc9857e2c1ed6edf9a7b8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 14 Mar 2016 14:51:45 +0100 Subject: [PATCH 24/62] tst_QRect: drop a test that depends on int overflow The compiler can statically check that this is undefined behavior: tst_qrect.cpp:3173:52: warning: integer overflow in expression [-Woverflow] << QRect(QPoint(0,0), QPoint(INT_MAX+(0-INT_MIN),INT_MAX+(0-INT_MIN))); ~^~ tst_qrect.cpp:3173:72: warning: integer overflow in expression [-Woverflow] << QRect(QPoint(0,0), QPoint(INT_MAX+(0-INT_MIN),INT_MAX+(0-INT_MIN))); ~^~ Fix by skipping the test (like most of the others are in the block). Change-Id: I359a5e16db6c660c9f11d7dd8fbb40730bd63887 Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qrect/tst_qrect.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index 585cf5d4d0f..c6907dcac27 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -3171,8 +3171,7 @@ void tst_QRect::newMoveTopLeft_data() } { - QTest::newRow("LargestCoordQRect_NullQPoint") << getQRectCase(LargestCoordQRect) << getQPointCase(NullQPoint) - << QRect(QPoint(0,0), QPoint(INT_MAX+(0-INT_MIN),INT_MAX+(0-INT_MIN))); + // QTest::newRow("LargestCoordQRect_NullQPoint") -- Not tested as it would cause an overflow QTest::newRow("LargestCoordQRect_SmallestCoordQPoint") << getQRectCase(LargestCoordQRect) << getQPointCase(SmallestCoordQPoint) << QRect(QPoint(INT_MIN,INT_MIN), QPoint(INT_MAX,INT_MAX)); // QTest::newRow("LargestCoordQRect_MiddleNegCoordQPoint") -- Not tested as it would cause an overflow From 1dcc53f6faf53a2994c6b9fe329d35fdaf61c06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 11 Mar 2016 12:48:11 +0100 Subject: [PATCH 25/62] Compile with -no-opengl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QCocoaBackingstore::toImage() can only be Q_DECL_OVERRIDE if QPlatformBackingStore::toImage() is present, which it isn’t for NO_OPENGL builds. Change-Id: Ib116f40fd26defb29a8d520d3e3fb104d8da8d57 Task-number: QTBUG-51694 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoabackingstore.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.h b/src/plugins/platforms/cocoa/qcocoabackingstore.h index 5a199de4a5c..934f68ad184 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.h +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.h @@ -51,7 +51,11 @@ public: QPaintDevice *paintDevice() Q_DECL_OVERRIDE; void flush(QWindow *widget, const QRegion ®ion, const QPoint &offset) Q_DECL_OVERRIDE; +#ifndef QT_NO_OPENGL QImage toImage() const Q_DECL_OVERRIDE; +#else + QImage toImage() const; // No QPlatformBackingStore::toImage() for NO_OPENGL builds. +#endif void resize (const QSize &size, const QRegion &) Q_DECL_OVERRIDE; bool scroll(const QRegion &area, int dx, int dy) Q_DECL_OVERRIDE; void beginPaint(const QRegion ®ion) Q_DECL_OVERRIDE; From e4c6d73f925671a9c96558293472ed213861239c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 14 Mar 2016 15:18:11 +0100 Subject: [PATCH 26/62] QRect: fix UB (int overflow) in center() QRect::center() should be defined for any QRect(x1,y1,x2,x2), INT_MIN <= x1, x2, y1, y2 <= INT_MAX because the average of two signed integers is always representable as a signed integer. But not when it's calculated as (x1+x2)/2, since that expression overflows when x1 > INT_MAX - x2. Instead of playing games with Hacker's Delight-style expressions, or use Google's patented algorithm, which requires two divisions, take advantage of the fact that int is not intmax_t and perform the calculation in the qint64 domain. The cast back to int is always well- defined since, as mentioned, the result is always representable in an int. Fix a test-case that expected a nonsensical result due to overflow. [ChangeLog][QtCore][QRect] Fixed integer overflow in center(). This fixes the result for some corner-cases like a 1x1 rectangle at (INT_MIN, INT_MIN), for which the previous implementation could return anything (due to invoking undefined behavior), but commonly returned (0, 0). Change-Id: I1a885ca6dff770327dd31655c3eb473fcfeb8878 Reviewed-by: Lars Knoll --- src/corelib/tools/qrect.h | 2 +- tests/auto/corelib/tools/qrect/tst_qrect.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qrect.h b/src/corelib/tools/qrect.h index 59cecf9a01e..a0449ae134e 100644 --- a/src/corelib/tools/qrect.h +++ b/src/corelib/tools/qrect.h @@ -245,7 +245,7 @@ Q_DECL_CONSTEXPR inline QPoint QRect::bottomLeft() const Q_DECL_NOTHROW { return QPoint(x1, y2); } Q_DECL_CONSTEXPR inline QPoint QRect::center() const Q_DECL_NOTHROW -{ return QPoint((x1+x2)/2, (y1+y2)/2); } +{ return QPoint(int((qint64(x1)+x2)/2), int((qint64(y1)+y2)/2)); } // cast avoids overflow on addition Q_DECL_CONSTEXPR inline int QRect::width() const Q_DECL_NOTHROW { return x2 - x1 + 1; } diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index c6907dcac27..1377e801a72 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -2349,7 +2349,7 @@ void tst_QRect::center_data() QTest::newRow( "SmallestQRect" ) << getQRectCase( SmallestQRect ) << QPoint(1,1); QTest::newRow( "MiddleQRect" ) << getQRectCase( MiddleQRect ) << QPoint(0,0); QTest::newRow( "LargestQRect" ) << getQRectCase( LargestQRect ) << QPoint(INT_MAX/2,INT_MAX/2); - QTest::newRow( "SmallestCoordQRect" ) << getQRectCase( SmallestCoordQRect ) << QPoint(0,0); + QTest::newRow( "SmallestCoordQRect" ) << getQRectCase( SmallestCoordQRect ) << QPoint(INT_MIN, INT_MIN); QTest::newRow( "LargestCoordQRect" ) << getQRectCase( LargestCoordQRect ) << QPoint(0,0); QTest::newRow( "RandomQRect" ) << getQRectCase( RandomQRect ) << QPoint(105,207); QTest::newRow( "NegativeSizeQRect" ) << getQRectCase( NegativeSizeQRect ) << QPoint(-4,-4); From 6c53f2528c86fb72f19951a799f0afaa02ad4490 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 14 Mar 2016 10:07:20 +0100 Subject: [PATCH 27/62] xcb: Initialize all xcb_client_message_event_t members before use Change-Id: I01e4b69b138fd19fc7e67751d93adebc1326b2f9 Reviewed-by: Orgad Shaneh --- src/plugins/platforms/xcb/qxcbdrag.cpp | 6 ++++++ src/plugins/platforms/xcb/qxcbscreen.cpp | 1 + src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp | 2 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/xcb/qxcbdrag.cpp b/src/plugins/platforms/xcb/qxcbdrag.cpp index aa6445d2da5..f5cc87394b9 100644 --- a/src/plugins/platforms/xcb/qxcbdrag.cpp +++ b/src/plugins/platforms/xcb/qxcbdrag.cpp @@ -423,6 +423,7 @@ void QXcbDrag::move(const QPoint &globalPos) xcb_client_message_event_t enter; enter.response_type = XCB_CLIENT_MESSAGE; + enter.sequence = 0; enter.window = target; enter.format = 32; enter.type = atom(QXcbAtom::XdndEnter); @@ -451,6 +452,7 @@ void QXcbDrag::move(const QPoint &globalPos) xcb_client_message_event_t move; move.response_type = XCB_CLIENT_MESSAGE; + move.sequence = 0; move.window = target; move.format = 32; move.type = atom(QXcbAtom::XdndPosition); @@ -479,6 +481,7 @@ void QXcbDrag::drop(const QPoint &globalPos) xcb_client_message_event_t drop; drop.response_type = XCB_CLIENT_MESSAGE; + drop.sequence = 0; drop.window = current_target; drop.format = 32; drop.type = atom(QXcbAtom::XdndDrop); @@ -740,6 +743,7 @@ void QXcbDrag::handle_xdnd_position(QPlatformWindow *w, const xcb_client_message xcb_client_message_event_t response; response.response_type = XCB_CLIENT_MESSAGE; + response.sequence = 0; response.window = xdnd_dragsource; response.format = 32; response.type = atom(QXcbAtom::XdndStatus); @@ -886,6 +890,7 @@ void QXcbDrag::send_leave() xcb_client_message_event_t leave; leave.response_type = XCB_CLIENT_MESSAGE; + leave.sequence = 0; leave.window = current_target; leave.format = 32; leave.type = atom(QXcbAtom::XdndLeave); @@ -956,6 +961,7 @@ void QXcbDrag::handleDrop(QPlatformWindow *, const xcb_client_message_event_t *e xcb_client_message_event_t finished; finished.response_type = XCB_CLIENT_MESSAGE; + finished.sequence = 0; finished.window = xdnd_dragsource; finished.format = 32; finished.type = atom(QXcbAtom::XdndFinished); diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 1a90f824fc4..f74244e13c8 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -361,6 +361,7 @@ void QXcbScreen::sendStartupMessage(const QByteArray &message) const ev.response_type = XCB_CLIENT_MESSAGE; ev.format = 8; ev.type = connection()->atom(QXcbAtom::_NET_STARTUP_INFO_BEGIN); + ev.sequence = 0; ev.window = rootWindow; int sent = 0; int length = message.length() + 1; // include NUL byte diff --git a/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp b/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp index 1f217e8de79..49c0440a3c4 100644 --- a/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp +++ b/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp @@ -94,9 +94,9 @@ xcb_window_t QXcbSystemTrayTracker::locateTrayWindow(const QXcbConnection *conne void QXcbSystemTrayTracker::requestSystemTrayWindowDock(xcb_window_t window) const { xcb_client_message_event_t trayRequest; - memset(&trayRequest, 0, sizeof(trayRequest)); trayRequest.response_type = XCB_CLIENT_MESSAGE; trayRequest.format = 32; + trayRequest.sequence = 0; trayRequest.window = m_trayWindow; trayRequest.type = m_trayAtom; trayRequest.data.data32[0] = XCB_CURRENT_TIME; diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index cd1774fed7f..a0b1ddb4340 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -1224,6 +1224,7 @@ void QXcbWindow::changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two) event.response_type = XCB_CLIENT_MESSAGE; event.format = 32; + event.sequence = 0; event.window = m_window; event.type = atom(QXcbAtom::_NET_WM_STATE); event.data.data32[0] = set ? 1 : 0; @@ -1265,6 +1266,7 @@ void QXcbWindow::setWindowState(Qt::WindowState state) event.response_type = XCB_CLIENT_MESSAGE; event.format = 32; + event.sequence = 0; event.window = m_window; event.type = atom(QXcbAtom::WM_CHANGE_STATE); event.data.data32[0] = XCB_WM_STATE_ICONIC; @@ -1660,6 +1662,7 @@ void QXcbWindow::requestActivateWindow() event.response_type = XCB_CLIENT_MESSAGE; event.format = 32; + event.sequence = 0; event.window = m_window; event.type = atom(QXcbAtom::_NET_ACTIVE_WINDOW); event.data.data32[0] = 1; @@ -2608,6 +2611,7 @@ bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) xcb_client_message_event_t xev; xev.response_type = XCB_CLIENT_MESSAGE; xev.type = moveResize; + xev.sequence = 0; xev.window = xcb_window(); xev.format = 32; const QPoint globalPos = window()->mapToGlobal(pos); @@ -2636,6 +2640,7 @@ void QXcbWindow::sendXEmbedMessage(xcb_window_t window, quint32 message, event.response_type = XCB_CLIENT_MESSAGE; event.format = 32; + event.sequence = 0; event.window = window; event.type = atom(QXcbAtom::_XEMBED); event.data.data32[0] = connection()->time(); From 5393ba970b0d25280a048ef31c3ffd2e5efe0320 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 10 Jun 2015 16:45:02 +0200 Subject: [PATCH 28/62] Remove handle duplication code from QWindowsPipeWriter There is no apparent reason why the handle should be duplicated. Change-Id: I8ff2cde2f050934ed0dd9ab2d39a1b1efa327a17 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qwindowspipewriter.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index 21df5d06434..5b11ba6112a 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -39,12 +39,10 @@ QT_BEGIN_NAMESPACE QWindowsPipeWriter::QWindowsPipeWriter(HANDLE pipe, QObject * parent) : QThread(parent), - writePipe(INVALID_HANDLE_VALUE), + writePipe(pipe), quitNow(false), hasWritten(false) { - DuplicateHandle(GetCurrentProcess(), pipe, GetCurrentProcess(), - &writePipe, 0, FALSE, DUPLICATE_SAME_ACCESS); } QWindowsPipeWriter::~QWindowsPipeWriter() @@ -55,7 +53,6 @@ QWindowsPipeWriter::~QWindowsPipeWriter() lock.unlock(); if (!wait(30000)) terminate(); - CloseHandle(writePipe); } bool QWindowsPipeWriter::waitForWrite(int msecs) From e3638174983849c355f9d336759439f78497a3ee Mon Sep 17 00:00:00 2001 From: Milla Pohjanheimo Date: Tue, 15 Mar 2016 07:44:09 +0200 Subject: [PATCH 29/62] tst_qtabbar sizeHints fix tst_qtabbar uses fixed values to check the minimumSizeHint and it fails with screens that have a higher resolution. The test still uses the default values, but now in the beginning it creates enough tabs so that it goes over the default. Change-Id: I3f891d2661288d7fad50ad522d73f634b3e91958 Reviewed-by: Andy Shaw --- .../widgets/widgets/qtabbar/tst_qtabbar.cpp | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index ced2253a742..3f1badeda1f 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -279,36 +279,30 @@ void tst_QTabBar::sizeHints() { QTabBar tabBar; tabBar.setFont(QFont("Arial", 10)); - tabBar.addTab("tab 01"); - tabBar.addTab("tab 02"); - tabBar.addTab("tab 03"); - tabBar.addTab("tab 04"); - tabBar.addTab("tab 05"); - tabBar.addTab("tab 06"); - tabBar.addTab("This is tab7"); - tabBar.addTab("This is tab8"); - tabBar.addTab("This is tab9 with a very long title"); // No eliding and no scrolling -> tabbar becomes very wide tabBar.setUsesScrollButtons(false); tabBar.setElideMode(Qt::ElideNone); -// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-27230", Abort); -#endif + tabBar.addTab("tab 01"); + + // Fetch the minimum size hint width and make sure that we create enough + // tabs. + int minimumSizeHintWidth = tabBar.minimumSizeHint().width(); + for (int i = 0; i <= 700 / minimumSizeHintWidth; ++i) + tabBar.addTab(QString("tab 0%1").arg(i+2)); + + //qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); QVERIFY(tabBar.minimumSizeHint().width() > 700); QVERIFY(tabBar.sizeHint().width() > 700); // Scrolling enabled -> no reason to become very wide tabBar.setUsesScrollButtons(true); - // qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); QVERIFY(tabBar.minimumSizeHint().width() < 200); QVERIFY(tabBar.sizeHint().width() > 700); // unchanged // Eliding enabled -> no reason to become very wide tabBar.setUsesScrollButtons(false); tabBar.setElideMode(Qt::ElideRight); -// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); // The sizeHint is very much dependent on the screen DPI value // so we can not really predict it. @@ -317,7 +311,7 @@ void tst_QTabBar::sizeHints() QVERIFY(tabBarMinSizeHintWidth < tabBarSizeHintWidth); QVERIFY(tabBarSizeHintWidth > 700); // unchanged - tabBar.addTab("This is tab10 with a very long title"); + tabBar.addTab("This is tab with a very long title"); QVERIFY(tabBar.minimumSizeHint().width() > tabBarMinSizeHintWidth); QVERIFY(tabBar.sizeHint().width() > tabBarSizeHintWidth); } From eef3afaa978a25743af7efdda169052b67cc744a Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Fri, 11 Mar 2016 11:14:49 +0100 Subject: [PATCH 30/62] QTextStream test: Change current directory For platforms with builtin testdata/sandboxed platforms we need to change the current directory to be able to create files. Change-Id: I440205c95dd6df1308c6bf24b1b0f67fd697feab Reviewed-by: Oliver Wolff --- tests/auto/corelib/io/qtextstream/test/test.pro | 4 ++++ .../corelib/io/qtextstream/tst_qtextstream.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/auto/corelib/io/qtextstream/test/test.pro b/tests/auto/corelib/io/qtextstream/test/test.pro index 39d181344f6..073aecdfba6 100644 --- a/tests/auto/corelib/io/qtextstream/test/test.pro +++ b/tests/auto/corelib/io/qtextstream/test/test.pro @@ -21,3 +21,7 @@ TESTDATA += \ ../tst_qtextstream.cpp \ ../resources DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +builtin_testdata { + DEFINES += BUILTIN_TESTDATA +} diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 24dd05223f4..13be58a1f19 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -65,6 +65,7 @@ public: public slots: void initTestCase(); void cleanup(); + void cleanupTestCase(); private slots: void getSetCheck(); @@ -241,6 +242,9 @@ private: QTemporaryDir tempDir; QString testFileName; +#ifdef BUILTIN_TESTDATA + QSharedPointer m_dataDir; +#endif const QString m_rfc3261FilePath; const QString m_shiftJisFilePath; }; @@ -267,9 +271,14 @@ void tst_QTextStream::initTestCase() testFileName = tempDir.path() + "/testfile"; +#ifdef BUILTIN_TESTDATA + m_dataDir = QEXTRACTTESTDATA("/"); + QVERIFY2(QDir::setCurrent(m_dataDir->path()), qPrintable("Could not chdir to " + m_dataDir->path())); +#else // chdir into the testdata dir and refer to our helper apps with relative paths QString testdata_dir = QFileInfo(QFINDTESTDATA("stdinProcess")).absolutePath(); QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir)); +#endif } // Testing get/set functions @@ -392,6 +401,13 @@ void tst_QTextStream::cleanup() QCoreApplication::instance()->processEvents(); } +void tst_QTextStream::cleanupTestCase() +{ +#ifdef BUILTIN_TESTDATA + QDir::setCurrent(QCoreApplication::applicationDirPath()); +#endif +} + // ------------------------------------------------------------------------------ void tst_QTextStream::construction() { From e830fa8fc251f697ffee2c215c0121028eeef8ca Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Fri, 11 Mar 2016 11:12:40 +0100 Subject: [PATCH 31/62] tst_QXmlStream::writerHangs(): Create file in temporary directory A test should not write to its directory. Change-Id: I34dfc36387cf5a637b325be29c8a19ff51d9b9c3 Reviewed-by: Oliver Wolff --- tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp index 341b169113d..1da29ac3bd5 100644 --- a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp @@ -905,7 +905,8 @@ void tst_QXmlStream::testFalsePrematureError() const // Regression test for crash due to using empty QStack. void tst_QXmlStream::writerHangs() const { - QFile file("test.xml"); + QTemporaryDir dir(QDir::tempPath() + QLatin1String("/tst_qxmlstream.XXXXXX")); + QFile file(dir.path() + "/test.xml"); QVERIFY(file.open(QIODevice::WriteOnly)); From 9c3c350627c1fc9d7f6e063f9360b096f159a6d7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 9 Feb 2016 13:40:42 +0100 Subject: [PATCH 32/62] Manual High DPI test: Add test for window masks. Add a toggle for setting a triangular mask on the main window. Task-number: QTBUG-50938 Change-Id: Id4a3ee0b80e170f4ee1d195e60ce7bfa8e524359 Reviewed-by: Shawn Rutledge --- tests/manual/highdpi/main.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp index 692a60d5112..83aefdb88a0 100644 --- a/tests/manual/highdpi/main.cpp +++ b/tests/manual/highdpi/main.cpp @@ -380,16 +380,22 @@ Labels::Labels() class MainWindow : public QMainWindow { + Q_OBJECT public: MainWindow(); QMenu *addNewMenu(const QString &title, int itemCount = 5); +private slots: + void maskActionToggled(bool t); + +private: QIcon qtIcon; QIcon qtIcon1x; QIcon qtIcon2x; QToolBar *fileToolBar; int menuCount; + QAction *m_maskAction; }; MainWindow::MainWindow() @@ -408,7 +414,12 @@ MainWindow::MainWindow() addNewMenu("&Edit"); addNewMenu("&Build"); addNewMenu("&Debug", 4); - addNewMenu("&Transmogrify", 7); + QMenu *menu = addNewMenu("&Transmogrify", 7); + menu->addSeparator(); + m_maskAction = menu->addAction("Mask"); + m_maskAction->setCheckable(true); + connect(m_maskAction, &QAction::toggled, this, &MainWindow::maskActionToggled); + fileToolBar->addAction(m_maskAction); addNewMenu("T&ools"); addNewMenu("&Help", 2); } @@ -431,6 +442,16 @@ QMenu *MainWindow::addNewMenu(const QString &title, int itemCount) return menu; } +void MainWindow::maskActionToggled(bool t) +{ + if (t) { + QVector upperLeftTriangle; + upperLeftTriangle << QPoint(0, 0) << QPoint(width(), 0) << QPoint(0, height()); + setMask(QRegion(QPolygon(upperLeftTriangle))); + } else { + clearMask(); + } +} class StandardIcons : public QWidget { From 7e72a5e11e92ed1df28ed34b13b711df6ca6fde2 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Wed, 16 Mar 2016 10:32:44 +0100 Subject: [PATCH 33/62] winrt: process all triggered timers in processEvents If only one timer is processed in there it is possible that a reoccuring timer which has a very low timeout blocks all the other timers from being triggered. This high frequency timer might be the only one to be triggered in every processEvents call. Task-number: QTBUG-51888 Change-Id: I8a0026d1e8519171ab60d1b47c494a15d30328b3 Reviewed-by: Maurice Kalinowski --- src/corelib/kernel/qeventdispatcher_winrt.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index df070dd1aed..ca4ba72b666 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -210,8 +210,10 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags) const QVector timerHandles = d->timerIdToHandle.values().toVector(); if (waitTime) emit aboutToBlock(); + bool timerEventsSent = false; DWORD waitResult = WaitForMultipleObjectsEx(timerHandles.count(), timerHandles.constData(), FALSE, waitTime, TRUE); - if (waitResult >= WAIT_OBJECT_0 && waitResult < WAIT_OBJECT_0 + timerHandles.count()) { + while (waitResult >= WAIT_OBJECT_0 && waitResult < WAIT_OBJECT_0 + timerHandles.count()) { + timerEventsSent = true; const HANDLE handle = timerHandles.value(waitResult - WAIT_OBJECT_0); ResetEvent(handle); const int timerId = d->timerHandleToId.value(handle); @@ -226,12 +228,10 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags) // Update timer's targetTime const quint64 targetTime = qt_msectime() + info.interval; info.targetTime = targetTime; - emit awake(); - return true; + waitResult = WaitForMultipleObjectsEx(timerHandles.count(), timerHandles.constData(), FALSE, 0, TRUE); } emit awake(); - - if (userEventsSent) + if (timerEventsSent || userEventsSent) return true; // We cannot wait infinitely like on other platforms, as From e7cd32274e144144c1630d65d09d24a1ae0af2d7 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 15 Mar 2016 13:04:50 +0100 Subject: [PATCH 34/62] WinRT: Fix QTimeZone transitions by switching backend Previously WinRT was using the UTC backend which fails on all platforms for some QDateTime autotests related to timezone items. Hence switch to the Windows implementation for WinRT as well. However, the windows backend does query the registry heavily, which is not supported on WinRT. Instead use the API version provided by the SDK. Long-term we might want to switch to this version on desktop windows as well, as direct registry access would not be required and we could harmonize the codepaths for both platforms. Change-Id: I620b614e9994aa77b531e5c34c9be1da7e272a30 Reviewed-by: Oliver Wolff --- src/corelib/tools/qtimezone.cpp | 4 +- src/corelib/tools/qtimezoneprivate_win.cpp | 100 +++++++++++++++++- src/corelib/tools/tools.pri | 6 +- .../corelib/tools/qtimezone/tst_qtimezone.cpp | 2 +- 4 files changed, 106 insertions(+), 6 deletions(-) diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index 333a5c3471f..bf34a8b16f9 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -61,7 +61,7 @@ static QTimeZonePrivate *newBackendTimeZone() #elif defined Q_OS_UNIX return new QTzTimeZonePrivate(); // Registry based timezone backend not available on WinRT -#elif defined Q_OS_WIN && !defined Q_OS_WINRT +#elif defined Q_OS_WIN return new QWinTimeZonePrivate(); #elif defined QT_USE_ICU return new QIcuTimeZonePrivate(); @@ -88,7 +88,7 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) #elif defined Q_OS_UNIX return new QTzTimeZonePrivate(ianaId); // Registry based timezone backend not available on WinRT -#elif defined Q_OS_WIN && !defined Q_OS_WINRT +#elif defined Q_OS_WIN return new QWinTimeZonePrivate(ianaId); #elif defined QT_USE_ICU return new QIcuTimeZonePrivate(ianaId); diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp index a9bb3aa3b52..0cb26c2e5b2 100644 --- a/src/corelib/tools/qtimezoneprivate_win.cpp +++ b/src/corelib/tools/qtimezoneprivate_win.cpp @@ -42,6 +42,10 @@ QT_BEGIN_NAMESPACE +#ifndef Q_OS_WINRT +#define QT_USE_REGISTRY_TIMEZONE 1 +#endif + /* Private @@ -59,9 +63,10 @@ QT_BEGIN_NAMESPACE // Vista introduced support for historic data, see MSDN docs on DYNAMIC_TIME_ZONE_INFORMATION // http://msdn.microsoft.com/en-gb/library/windows/desktop/ms724253%28v=vs.85%29.aspx - +#ifdef QT_USE_REGISTRY_TIMEZONE static const char tzRegPath[] = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"; static const char currTzRegPath[] = "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"; +#endif enum { MIN_YEAR = -292275056, @@ -123,6 +128,7 @@ static bool equalTzi(const TIME_ZONE_INFORMATION &tzi1, const TIME_ZONE_INFORMAT && wcscmp(tzi1.DaylightName, tzi2.DaylightName) == 0); } +#ifdef QT_USE_REGISTRY_TIMEZONE static bool openRegistryKey(const QString &keyPath, HKEY *key) { return (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (const wchar_t*)keyPath.utf16(), 0, KEY_READ, key) @@ -197,9 +203,61 @@ static TIME_ZONE_INFORMATION getRegistryTzi(const QByteArray &windowsId, bool *o return tzi; } +#else // QT_USE_REGISTRY_TIMEZONE +struct QWinDynamicTimeZone +{ + QString standardName; + QString daylightName; + QString timezoneName; + qint32 bias; + bool daylightTime; +}; + +typedef QHash QWinRTTimeZoneHash; + +Q_GLOBAL_STATIC(QWinRTTimeZoneHash, gTimeZones) + +static void enumerateTimeZones() +{ + DYNAMIC_TIME_ZONE_INFORMATION dtzInfo; + quint32 index = 0; + QString prevTimeZoneKeyName; + while (SUCCEEDED(EnumDynamicTimeZoneInformation(index++, &dtzInfo))) { + QWinDynamicTimeZone item; + item.timezoneName = QString::fromWCharArray(dtzInfo.TimeZoneKeyName); + // As soon as key name repeats, break. Some systems continue to always + // return the last item independent of index being out of range + if (item.timezoneName == prevTimeZoneKeyName) + break; + item.standardName = QString::fromWCharArray(dtzInfo.StandardName); + item.daylightName = QString::fromWCharArray(dtzInfo.DaylightName); + item.daylightTime = !dtzInfo.DynamicDaylightTimeDisabled; + item.bias = dtzInfo.Bias; + gTimeZones->insert(item.timezoneName.toUtf8(), item); + prevTimeZoneKeyName = item.timezoneName; + } +} + +static DYNAMIC_TIME_ZONE_INFORMATION dynamicInfoForId(const QByteArray &windowsId) +{ + DYNAMIC_TIME_ZONE_INFORMATION dtzInfo; + quint32 index = 0; + QString prevTimeZoneKeyName; + while (SUCCEEDED(EnumDynamicTimeZoneInformation(index++, &dtzInfo))) { + const QString timeZoneName = QString::fromWCharArray(dtzInfo.TimeZoneKeyName); + if (timeZoneName == QLatin1String(windowsId)) + break; + if (timeZoneName == prevTimeZoneKeyName) + break; + prevTimeZoneKeyName = timeZoneName; + } + return dtzInfo; +} +#endif // QT_USE_REGISTRY_TIMEZONE static QList availableWindowsIds() { +#ifdef QT_USE_REGISTRY_TIMEZONE // TODO Consider caching results in a global static, very unlikely to change. QList list; HKEY key = NULL; @@ -217,10 +275,16 @@ static QList availableWindowsIds() RegCloseKey(key); } return list; +#else // QT_USE_REGISTRY_TIMEZONE + if (gTimeZones->isEmpty()) + enumerateTimeZones(); + return gTimeZones->keys(); +#endif // QT_USE_REGISTRY_TIMEZONE } static QByteArray windowsSystemZoneId() { +#ifdef QT_USE_REGISTRY_TIMEZONE // On Vista and later is held in the value TimeZoneKeyName in key currTzRegPath QString id; HKEY key = NULL; @@ -241,6 +305,11 @@ static QByteArray windowsSystemZoneId() if (equalTzi(getRegistryTzi(winId, &ok), sysTzi)) return winId; } +#else // QT_USE_REGISTRY_TIMEZONE + DYNAMIC_TIME_ZONE_INFORMATION dtzi; + if (SUCCEEDED(GetDynamicTimeZoneInformation(&dtzi))) + return QString::fromWCharArray(dtzi.TimeZoneKeyName).toLocal8Bit(); +#endif // QT_USE_REGISTRY_TIMEZONE // If we can't determine the current ID use UTC return QTimeZonePrivate::utcQByteArray(); @@ -361,6 +430,7 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) } if (!m_windowsId.isEmpty()) { +#ifdef QT_USE_REGISTRY_TIMEZONE // Open the base TZI for the time zone HKEY baseKey = NULL; const QString baseKeyPath = QString::fromUtf8(tzRegPath) + QLatin1Char('\\') @@ -397,6 +467,34 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) } RegCloseKey(baseKey); } +#else // QT_USE_REGISTRY_TIMEZONE + if (gTimeZones->isEmpty()) + enumerateTimeZones(); + QWinRTTimeZoneHash::const_iterator it = gTimeZones->find(m_windowsId); + if (it != gTimeZones->constEnd()) { + m_displayName = it->timezoneName; + m_standardName = it->standardName; + m_daylightName = it->daylightName; + DWORD firstYear = 0; + DWORD lastYear = 0; + DYNAMIC_TIME_ZONE_INFORMATION dtzi = dynamicInfoForId(m_windowsId); + GetDynamicTimeZoneInformationEffectiveYears(&dtzi, &firstYear, &lastYear); + // If there is no dynamic information, you can still query for + // year 0, which helps simplifying following part + for (DWORD year = firstYear; year <= lastYear; ++year) { + TIME_ZONE_INFORMATION tzi; + if (!GetTimeZoneInformationForYear(year, &dtzi, &tzi)) + continue; + QWinTransitionRule rule; + rule.standardTimeBias = tzi.Bias + tzi.StandardBias; + rule.daylightTimeBias = tzi.Bias + tzi.DaylightBias - rule.standardTimeBias; + rule.standardTimeRule = tzi.StandardDate; + rule.daylightTimeRule = tzi.DaylightDate; + rule.startYear = year; + m_tranRules.append(rule); + } + } +#endif // QT_USE_REGISTRY_TIMEZONE } // If there are no rules then we failed to find a windowsId or any tzi info diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index ed07f70e870..ed6afe70ce9 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -147,9 +147,11 @@ else:unix { SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp tools/qtimezoneprivate_tz.cpp } else:win32 { - SOURCES += tools/qelapsedtimer_win.cpp tools/qlocale_win.cpp - !winrt: SOURCES += tools/qtimezoneprivate_win.cpp + SOURCES += tools/qelapsedtimer_win.cpp \ + tools/qlocale_win.cpp \ + tools/qtimezoneprivate_win.cpp winphone: LIBS_PRIVATE += -lWindowsPhoneGlobalizationUtil + winrt-*-msvc2013: LIBS += advapi32.lib } else:integrity:SOURCES += tools/qelapsedtimer_unix.cpp tools/qlocale_unix.cpp else:SOURCES += tools/qelapsedtimer_generic.cpp diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index b511abf6704..32bb2aa3941 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -898,7 +898,7 @@ void tst_QTimeZone::macTest() void tst_QTimeZone::winTest() { -#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) // Known datetimes qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); From f8f3f0fbd468feaf14adcedbccbf6b434f2e2e49 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 15 Mar 2016 16:07:11 +0100 Subject: [PATCH 35/62] Correct qt_defaultDpi X/Y with just a QCoreApplication Makes the 96DPI attribute check avoid undefined behavior by using QCoreApplication::instance() directly, instead of calling through qApp, which performs an invalid cast to QGuiApplication. Change-Id: Ib86e7d2461b462a2d623f1364414f7d4d2293f22 Reviewed-by: Marc Mutz --- src/gui/text/qfont.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 2c5a0c74fc0..fe681493461 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -131,7 +131,7 @@ extern bool qt_is_gui_used; Q_GUI_EXPORT int qt_defaultDpiX() { - if (qApp->testAttribute(Qt::AA_Use96Dpi)) + if (QCoreApplication::instance()->testAttribute(Qt::AA_Use96Dpi)) return 96; if (!qt_is_gui_used) @@ -146,7 +146,7 @@ Q_GUI_EXPORT int qt_defaultDpiX() Q_GUI_EXPORT int qt_defaultDpiY() { - if (qApp->testAttribute(Qt::AA_Use96Dpi)) + if (QCoreApplication::instance()->testAttribute(Qt::AA_Use96Dpi)) return 96; if (!qt_is_gui_used) From 10a4151e83da4662eb51a8c67760f2e38d84759e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 16 Mar 2016 10:46:40 +0100 Subject: [PATCH 36/62] Fix link to sched_setscheduler in QThread documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I38412a119d2a91685b3fd2e4a459d33a60b154b0 Reviewed-by: Topi Reiniö --- src/corelib/thread/qthread.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index 590479d68c3..a0a2e76bda8 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -303,8 +303,9 @@ QThreadPrivate::~QThreadPrivate() The effect of the \a priority parameter is dependent on the operating system's scheduling policy. In particular, the \a priority will be ignored on systems that do not support thread priorities - (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler - for more details). + (such as on Linux, see the + \l {http://linux.die.net/man/2/sched_setscheduler}{sched_setscheduler} + documentation for more details). \sa run(), terminate() */ From 714cb4020e12e078e8ba8c2c5493d138d515f46d Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 10 Feb 2016 13:57:10 +0100 Subject: [PATCH 37/62] Update bundled libpng to version 1.6.20 Merged in the upstream version. The remaining diff to clean 1.6.20 is archived in the qtpatches.diff file. Change-Id: I56f557bfe04ac1aa0e2c090826bbb144ae93cbb7 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/3rdparty/libpng/ANNOUNCE | 119 ++++++-------------------- src/3rdparty/libpng/CHANGES | 34 +++++++- src/3rdparty/libpng/LICENSE | 4 +- src/3rdparty/libpng/README | 2 +- src/3rdparty/libpng/libpng-manual.txt | 9 +- src/3rdparty/libpng/png.c | 8 +- src/3rdparty/libpng/png.h | 23 ++--- src/3rdparty/libpng/pngconf.h | 2 +- src/3rdparty/libpng/pngerror.c | 2 +- src/3rdparty/libpng/pnginfo.h | 2 +- src/3rdparty/libpng/pnglibconf.h | 2 +- src/3rdparty/libpng/pngpread.c | 4 +- src/3rdparty/libpng/pngpriv.h | 8 ++ src/3rdparty/libpng/pngread.c | 1 - src/3rdparty/libpng/pngrutil.c | 43 ++++++++-- src/3rdparty/libpng/pngset.c | 6 +- src/3rdparty/libpng/pngstruct.h | 3 + src/3rdparty/libpng/pngwutil.c | 6 +- 18 files changed, 145 insertions(+), 133 deletions(-) diff --git a/src/3rdparty/libpng/ANNOUNCE b/src/3rdparty/libpng/ANNOUNCE index 9f1b6658342..4dae783b559 100644 --- a/src/3rdparty/libpng/ANNOUNCE +++ b/src/3rdparty/libpng/ANNOUNCE @@ -1,4 +1,4 @@ -Libpng 1.6.19 - November 12, 2015 +Libpng 1.6.20 - December 3, 2015 This is a public release of libpng, intended for use in production codes. @@ -7,104 +7,41 @@ Files available for download: Source files with LF line endings (for Unix/Linux) and with a "configure" script - libpng-1.6.19.tar.xz (LZMA-compressed, recommended) - libpng-1.6.19.tar.gz + libpng-1.6.20.tar.xz (LZMA-compressed, recommended) + libpng-1.6.20.tar.gz Source files with CRLF line endings (for Windows), without the "configure" script - lpng1619.7z (LZMA-compressed, recommended) - lpng1619.zip + /scratch/glennrp/Libpng16/lpng1620.7z (LZMA-compressed, recommended) + /scratch/glennrp/Libpng16/lpng1620.zip Other information: - libpng-1.6.19-README.txt - libpng-1.6.19-LICENSE.txt - libpng-1.6.19-*.asc (armored detached GPG signatures) + libpng-1.6.20-README.txt + libpng-1.6.20-LICENSE.txt + libpng-1.6.20-*.asc (armored detached GPG signatures) -Changes since the last public release (1.6.18): - - Updated obsolete information about the simplified API macros in the - manual pages (Bug report by Arc Riley). - Avoid potentially dereferencing NULL info_ptr in png_info_init_3(). - Rearranged png.h to put the major sections in the same order as - in libpng17. - Eliminated unused PNG_COST_SHIFT, PNG_WEIGHT_SHIFT, PNG_COST_FACTOR, and - PNG_WEIGHT_FACTOR macros. - Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler - (Bug report by Viktor Szakats). Several warnings remain and are - unavoidable, where we test for overflow. - Fixed potential leak of png_pixels in contrib/pngminus/pnm2png.c - Fixed uninitialized variable in contrib/gregbook/rpng2-x.c - Moved config.h.in~ from the "libpng_autotools_files" list to the - "libpng_autotools_extra" list in autogen.sh because it was causing a - false positive for missing files (bug report by Robert C. Seacord). - Removed unreachable "break" statements in png.c, pngread.c, and pngrtran.c - to suppress clang warnings (Bug report by Viktor Szakats). - Fixed some bad links in the man page. - Changed "n bit" to "n-bit" in comments. - Added signed/unsigned 16-bit safety net. This removes the dubious - 0x8000 flag definitions on 16-bit systems. They aren't supported - yet the defs *probably* work, however it seems much safer to do this - and be advised if anyone, contrary to advice, is building libpng 1.6 - on a 16-bit system. It also adds back various switch default clauses - for GCC; GCC errors out if they are not present (with an appropriately - high level of warnings). - Safely convert num_bytes to a png_byte in png_set_sig_bytes() (Robert - Seacord). - Fixed the recently reported 1's complement security issue by replacing - the value that is illegal in the PNG spec, in both signed and unsigned - values, with 0. Illegal unsigned values (anything greater than or equal - to 0x80000000) can still pass through, but since these are not illegal - in ANSI-C (unlike 0x80000000 in the signed case) the checking that - occurs later can catch them (John Bowler). - Fixed png_save_int_32 when int is not 2's complement (John Bowler). - Updated libpng16 with all the recent test changes from libpng17, - including changes to pngvalid.c to ensure that the original, - distributed, version of contrib/visupng/cexcept.h can be used - (John Bowler). - pngvalid contains the correction to the use of SAVE/STORE_ - UNKNOWN_CHUNKS; a bug revealed by changes in libpng 1.7. More - tests contain the --strict option to detect warnings and the - pngvalid-standard test has been corrected so that it does not - turn on progressive-read. There is a separate test which does - that. (John Bowler) - Also made some signed/unsigned fixes. - Make pngstest error limits version specific. Splitting the machine - generated error structs out to a file allows the values to be updated - without changing pngstest.c itself. Since libpng 1.6 and 1.7 have - slightly different error limits this simplifies maintenance. The - makepngs.sh script has also been updated to more accurately reflect - current problems in libpng 1.7 (John Bowler). - Incorporated new test PNG files into make check. tests/pngstest-* - are changed so that the new test files are divided into 8 groups by - gamma and alpha channel. These tests have considerably better code - and pixel-value coverage than contrib/pngsuite; however,coverage is - still incomplete (John Bowler). - Removed the '--strict' in 1.6 because of the double-gamma-correction - warning, updated pngstest-errors.h for the errors detected with the - new contrib/testspngs PNG test files (John Bowler). - Worked around rgb-to-gray issues in libpng 1.6. The previous - attempts to ignore the errors in the code aren't quite enough to - deal with the 'channel selection' encoding added to libpng 1.7; abort. - Fixed 'pow' macros in pngvalid.c. It is legal for 'pow' to be a - macro, therefore the argument list cannot contain preprocessing - directives. Make sure pow is a function where this happens. This is - a minimal safe fix, the issue only arises in non-performance-critical - code (bug report by Curtis Leach, fix by John Bowler). - Added sPLT support to pngtest.c - Prevent setting or writing over-length PLTE chunk (Cosmin Truta). - Silently truncate over-length PLTE chunk while reading. - Libpng incorrectly calculated the output rowbytes when the application - decreased either the number of channels or the bit depth (or both) in - a user transform. This was safe; libpng overallocated buffer space - (potentially by quite a lot; up to 4 times the amount required) but, - from 1.5.4 on, resulted in a png_error (John Bowler). - Fixed some inconsequential cut-and-paste typos in png_set_cHRM_XYZ_fixed(). - Clarified COPYRIGHT information to state explicitly that versions - are derived from previous versions. - Removed much of the long list of previous versions from png.h and - libpng.3. +Changes since the last public release (1.6.19): + Avoid potential pointer overflow/underflow in png_handle_sPLT() and + png_handle_pCAL() (Bug report by John Regehr). + Fixed incorrect implementation of png_set_PLTE() that uses png_ptr + not info_ptr, that left png_set_PLTE() open to the CVE-2015-8126 + vulnerability. + Backported tests from libpng-1.7.0beta69. + Fixed an error in handling of bad zlib CMINFO field in pngfix, found by + American Fuzzy Lop, reported by Brian Carpenter. inflate() doesn't + immediately fault a bad CMINFO field; instead a 'too far back' error + happens later (at least some times). pngfix failed to limit CMINFO to + the allowed values but then assumed that window_bits was in range, + triggering an assert. The bug is mostly harmless; the PNG file cannot + be fixed. + In libpng 1.6 zlib initialization was changed to use the window size + in the zlib stream, not a fixed value. This causes some invalid images, + where CINFO is too large, to display 'correctly' if the rest of the + data is valid. This provides a workaround for zlib versions where the + error arises (ones that support the API change to use the window size + in the stream). Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/src/3rdparty/libpng/CHANGES b/src/3rdparty/libpng/CHANGES index 2e4d2bb292c..28094fd26cb 100644 --- a/src/3rdparty/libpng/CHANGES +++ b/src/3rdparty/libpng/CHANGES @@ -5409,11 +5409,43 @@ Version 1.6.19rc03 [November 3, 2015] Version 1.6.19rc04 [November 5, 2015] Fixed new bug with CRC error after reading an over-length palette - (bug report by Cosmin Truta). + (bug report by Cosmin Truta) (CVE-2015-8126). Version 1.6.19 [November 12, 2015] Cleaned up coding style in png_handle_PLTE(). +Version 1.6.20beta01 [November 20, 2015] + Avoid potential pointer overflow/underflow in png_handle_sPLT() and + png_handle_pCAL() (Bug report by John Regehr). + +Version 1.6.20beta02 [November 23, 2015] + Fixed incorrect implementation of png_set_PLTE() that uses png_ptr + not info_ptr, that left png_set_PLTE() open to the CVE-2015-8126 + vulnerability. + +Version 1.6.20beta03 [November 24, 2015] + Backported tests from libpng-1.7.0beta69. + +Version 1.6.20rc01 [November 26, 2015] + Fixed an error in handling of bad zlib CMINFO field in pngfix, found by + American Fuzzy Lop, reported by Brian Carpenter. inflate() doesn't + immediately fault a bad CMINFO field; instead a 'too far back' error + happens later (at least some times). pngfix failed to limit CMINFO to + the allowed values but then assumed that window_bits was in range, + triggering an assert. The bug is mostly harmless; the PNG file cannot + be fixed. + +Version 1.6.20rc02 [November 29, 2015] + In libpng 1.6 zlib initialization was changed to use the window size + in the zlib stream, not a fixed value. This causes some invalid images, + where CINFO is too large, to display 'correctly' if the rest of the + data is valid. This provides a workaround for zlib versions where the + error arises (ones that support the API change to use the window size + in the stream). + +Version 1.6.20 [December 3, 2015] + No changes. + Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit https://lists.sourceforge.net/lists/listinfo/png-mng-implement diff --git a/src/3rdparty/libpng/LICENSE b/src/3rdparty/libpng/LICENSE index 11f6ffe5db4..82dbe117f6d 100644 --- a/src/3rdparty/libpng/LICENSE +++ b/src/3rdparty/libpng/LICENSE @@ -10,7 +10,7 @@ this sentence. This code is released under the libpng license. -libpng versions 1.0.7, July 1, 2000, through 1.6.19, November 12, 2015, are +libpng versions 1.0.7, July 1, 2000, through 1.6.20, December 3, 2015, are Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, are derived from libpng-1.0.6, and are distributed according to the same disclaimer and license as libpng-1.0.6 with the following individuals @@ -109,4 +109,4 @@ the additional disclaimers inserted at version 1.0.7. Glenn Randers-Pehrson glennrp at users.sourceforge.net -November 12, 2015 +December 3, 2015 diff --git a/src/3rdparty/libpng/README b/src/3rdparty/libpng/README index 17484e0fd78..59f1f918ae2 100644 --- a/src/3rdparty/libpng/README +++ b/src/3rdparty/libpng/README @@ -1,4 +1,4 @@ -README for libpng version 1.6.19 - November 12, 2015 (shared library 16.0) +README for libpng version 1.6.20 - December 3, 2015 (shared library 16.0) See the note about version numbers near the top of png.h See INSTALL for instructions on how to install libpng. diff --git a/src/3rdparty/libpng/libpng-manual.txt b/src/3rdparty/libpng/libpng-manual.txt index bc7a441cf28..87eeb2b5837 100644 --- a/src/3rdparty/libpng/libpng-manual.txt +++ b/src/3rdparty/libpng/libpng-manual.txt @@ -1,6 +1,6 @@ libpng-manual.txt - A description on how to use and modify libpng - libpng version 1.6.19 - November 12, 2015 + libpng version 1.6.20 - December 3, 2015 Updated and distributed by Glenn Randers-Pehrson Copyright (c) 1998-2015 Glenn Randers-Pehrson @@ -11,7 +11,7 @@ libpng-manual.txt - A description on how to use and modify libpng Based on: - libpng versions 0.97, January 1998, through 1.6.19 - November 12, 2015 + libpng versions 0.97, January 1998, through 1.6.20 - December 3, 2015 Updated and distributed by Glenn Randers-Pehrson Copyright (c) 1998-2015 Glenn Randers-Pehrson @@ -2960,6 +2960,7 @@ width, height, bit_depth, and color_type must be the same in each call. (array of png_color) num_palette - number of entries in the palette + png_set_gAMA(png_ptr, info_ptr, file_gamma); png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); @@ -4897,7 +4898,7 @@ a set of "safe" limits is applied in pngpriv.h. These can be overridden by application calls to png_set_user_limits(), png_set_user_chunk_cache_max(), and/or png_set_user_malloc_max() that increase or decrease the limits. Also, in libpng-1.5.10 the default width and height limits were increased -from 1,000,000 to 0x7ffffff (i.e., made unlimited). Therefore, the +from 1,000,000 to 0x7fffffff (i.e., made unlimited). Therefore, the limits are now default safe png_user_width_max 0x7fffffff 1,000,000 @@ -5323,7 +5324,7 @@ Since the PNG Development group is an ad-hoc body, we can't make an official declaration. This is your unofficial assurance that libpng from version 0.71 and -upward through 1.6.19 are Y2K compliant. It is my belief that earlier +upward through 1.6.20 are Y2K compliant. It is my belief that earlier versions were also Y2K compliant. Libpng only has two year fields. One is a 2-byte unsigned integer diff --git a/src/3rdparty/libpng/png.c b/src/3rdparty/libpng/png.c index 6fcfad72ec1..c183e3f8faf 100644 --- a/src/3rdparty/libpng/png.c +++ b/src/3rdparty/libpng/png.c @@ -14,7 +14,7 @@ #include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef png_libpng_version_1_6_19 Your_png_h_is_not_version_1_6_19; +typedef png_libpng_version_1_6_20 Your_png_h_is_not_version_1_6_20; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another @@ -775,13 +775,13 @@ png_get_copyright(png_const_structrp png_ptr) #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ - "libpng version 1.6.19 - November 12, 2015" PNG_STRING_NEWLINE \ + "libpng version 1.6.20 - December 3, 2015" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2015 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE; # else - return "libpng version 1.6.19 - November 12, 2015\ + return "libpng version 1.6.20 - December 3, 2015\ Copyright (c) 1998-2015 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; @@ -2343,7 +2343,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, * Fall through to "no match". */ png_chunk_report(png_ptr, - "Not recognizing known sRGB profile that has been edited", + "Not recognizing known sRGB profile that has been edited", PNG_CHUNK_WARNING); break; # endif diff --git a/src/3rdparty/libpng/png.h b/src/3rdparty/libpng/png.h index c83051b1ca7..4d03dfc136c 100644 --- a/src/3rdparty/libpng/png.h +++ b/src/3rdparty/libpng/png.h @@ -1,7 +1,7 @@ /* png.h - header file for PNG reference library * - * libpng version 1.6.19, November 12, 2015 + * libpng version 1.6.20, December 3, 2015 * * Copyright (c) 1998-2015 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -12,7 +12,8 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.6.19, November 12, 2015: Glenn + * libpng versions 0.97, January 1998, through 1.6.20, December 3, 2015: + * Glenn Randers-Pehrson. * See also "Contributing Authors", below. */ @@ -24,7 +25,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.0.7, July 1, 2000, through 1.6.19, November 12, 2015, are + * libpng versions 1.0.7, July 1, 2000, through 1.6.20, December 3, 2015, are * Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, are * derived from libpng-1.0.6, and are distributed according to the same * disclaimer and license as libpng-1.0.6 with the following individuals @@ -185,7 +186,7 @@ * ... * 1.5.23 15 10523 15.so.15.23[.0] * ... - * 1.6.19 16 10619 16.so.16.19[.0] + * 1.6.20 16 10620 16.so.16.20[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -213,13 +214,13 @@ * Y2K compliance in libpng: * ========================= * - * November 12, 2015 + * December 3, 2015 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.6.19 are Y2K compliant. It is my belief that + * upward through 1.6.20 are Y2K compliant. It is my belief that * earlier versions were also Y2K compliant. * * Libpng only has two year fields. One is a 2-byte unsigned integer @@ -281,9 +282,9 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.6.19" +#define PNG_LIBPNG_VER_STRING "1.6.20" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.6.19 - November 12, 2015\n" + " libpng version 1.6.20 - December 3, 2015\n" #define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_DLLNUM 16 @@ -291,7 +292,7 @@ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MINOR 6 -#define PNG_LIBPNG_VER_RELEASE 19 +#define PNG_LIBPNG_VER_RELEASE 20 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: @@ -322,7 +323,7 @@ * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10619 /* 1.6.19 */ +#define PNG_LIBPNG_VER 10620 /* 1.6.20 */ /* Library configuration: these options cannot be changed after * the library has been built. @@ -432,7 +433,7 @@ extern "C" { /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef char* png_libpng_version_1_6_19; +typedef char* png_libpng_version_1_6_20; /* Basic control structions. Read libpng-manual.txt or libpng.3 for more info. * diff --git a/src/3rdparty/libpng/pngconf.h b/src/3rdparty/libpng/pngconf.h index f1b795b4784..92f250000ce 100644 --- a/src/3rdparty/libpng/pngconf.h +++ b/src/3rdparty/libpng/pngconf.h @@ -1,7 +1,7 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.6.19, July 23, 2015 + * libpng version 1.6.20, December 3, 2015 * * Copyright (c) 1998-2015 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) diff --git a/src/3rdparty/libpng/pngerror.c b/src/3rdparty/libpng/pngerror.c index 0781866a893..bdb959ee517 100644 --- a/src/3rdparty/libpng/pngerror.c +++ b/src/3rdparty/libpng/pngerror.c @@ -768,7 +768,7 @@ png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN) /* If control reaches this point, png_longjmp() must not return. The only * choice is to terminate the whole process (or maybe the thread); to do - * this the ANSI-C abort() function is used unless a different method is + * this the ANSI-C abort() function is used unless a different method is * implemented by overriding the default configuration setting for * PNG_ABORT(). */ diff --git a/src/3rdparty/libpng/pnginfo.h b/src/3rdparty/libpng/pnginfo.h index c8c874dd1ea..4bd264b8690 100644 --- a/src/3rdparty/libpng/pnginfo.h +++ b/src/3rdparty/libpng/pnginfo.h @@ -223,7 +223,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) /* Storage for unknown chunks that the library doesn't recognize. */ png_unknown_chunkp unknown_chunks; - /* The type of this field is limited by the type of + /* The type of this field is limited by the type of * png_struct::user_chunk_cache_max, else overflow can occur. */ int unknown_chunks_num; diff --git a/src/3rdparty/libpng/pnglibconf.h b/src/3rdparty/libpng/pnglibconf.h index 8b6da9eb2c7..0dba5055f7f 100644 --- a/src/3rdparty/libpng/pnglibconf.h +++ b/src/3rdparty/libpng/pnglibconf.h @@ -1,6 +1,6 @@ /* pnglibconf.h - library build configuration */ -/* libpng version 1.6.19, July 23, 2015 */ +/* libpng version 1.6.20 - December 3, 2015 */ /* Copyright (c) 1998-2014 Glenn Randers-Pehrson */ diff --git a/src/3rdparty/libpng/pngpread.c b/src/3rdparty/libpng/pngpread.c index 9f68f990232..89ffc4018f6 100644 --- a/src/3rdparty/libpng/pngpread.c +++ b/src/3rdparty/libpng/pngpread.c @@ -133,7 +133,7 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) void /* PRIVATE */ png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) { - png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ + png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ num_to_check = 8 - num_checked; if (png_ptr->buffer_size < num_to_check) @@ -662,7 +662,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, * change the current behavior (see comments in inflate.c * for why this doesn't happen at present with zlib 1.2.5). */ - ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); + ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH); /* Check for any failure before proceeding. */ if (ret != Z_OK && ret != Z_STREAM_END) diff --git a/src/3rdparty/libpng/pngpriv.h b/src/3rdparty/libpng/pngpriv.h index f7a45477a4c..c06deee68d7 100644 --- a/src/3rdparty/libpng/pngpriv.h +++ b/src/3rdparty/libpng/pngpriv.h @@ -1229,6 +1229,14 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr), /* Initialize the row buffers, etc. */ PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY); +#if PNG_ZLIB_VERNUM >= 0x1240 +PNG_INTERNAL_FUNCTION(int,png_zlib_inflate,(png_structrp png_ptr, int flush), + PNG_EMPTY); +# define PNG_INFLATE(pp, flush) png_zlib_inflate(pp, flush) +#else /* Zlib < 1.2.4 */ +# define PNG_INFLATE(pp, flush) inflate(&(pp)->zstream, flush) +#endif /* Zlib < 1.2.4 */ + #ifdef PNG_READ_TRANSFORMS_SUPPORTED /* Optional call to update the users info structure */ PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr, diff --git a/src/3rdparty/libpng/pngread.c b/src/3rdparty/libpng/pngread.c index 48aae84881d..9cb4d2e41d2 100644 --- a/src/3rdparty/libpng/pngread.c +++ b/src/3rdparty/libpng/pngread.c @@ -2838,7 +2838,6 @@ png_image_read_colormap(png_voidp argument) default: png_error(png_ptr, "invalid PNG color type"); /*NOT REACHED*/ - break; } /* Now deal with the output processing */ diff --git a/src/3rdparty/libpng/pngrutil.c b/src/3rdparty/libpng/pngrutil.c index ee584a8c406..61892513521 100644 --- a/src/3rdparty/libpng/pngrutil.c +++ b/src/3rdparty/libpng/pngrutil.c @@ -1,7 +1,7 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.6.19 [November 12, 2015] + * Last changed in libpng 1.6.20 [December 3, 2015] * Copyright (c) 1998-2015 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) @@ -377,10 +377,16 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) == PNG_OPTION_ON) + { window_bits = 15; + png_ptr->zstream_start = 0; /* fixed window size */ + } else + { window_bits = 0; + png_ptr->zstream_start = 1; + } # else # define window_bits 0 # endif @@ -429,6 +435,31 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) #endif } +#if PNG_ZLIB_VERNUM >= 0x1240 +/* Handle the start of the inflate stream if we called inflateInit2(strm,0); + * in this case some zlib versions skip validation of the CINFO field and, in + * certain circumstances, libpng may end up displaying an invalid image, in + * contrast to implementations that call zlib in the normal way (e.g. libpng + * 1.5). + */ +int /* PRIVATE */ +png_zlib_inflate(png_structrp png_ptr, int flush) +{ + if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0) + { + if ((*png_ptr->zstream.next_in >> 4) > 7) + { + png_ptr->zstream.msg = "invalid window size (libpng)"; + return Z_DATA_ERROR; + } + + png_ptr->zstream_start = 0; + } + + return inflate(&png_ptr->zstream, flush); +} +#endif /* Zlib >= 1.2.4 */ + #ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED /* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to * allow the caller to do multiple calls if required. If the 'finish' flag is @@ -522,7 +553,7 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish, * the previous chunk of input data. Tell zlib if we have reached the * end of the output buffer. */ - ret = inflate(&png_ptr->zstream, avail_out > 0 ? Z_NO_FLUSH : + ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH)); } while (ret == Z_OK); @@ -771,7 +802,7 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size, * the available output is produced; this allows reading of truncated * streams. */ - ret = inflate(&png_ptr->zstream, + ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH)); } while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0)); @@ -1670,7 +1701,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ++entry_start; /* A sample depth should follow the separator, and we should be on it */ - if (entry_start > buffer + length - 2) + if (length < 2U || entry_start > buffer + (length - 2U)) { png_warning(png_ptr, "malformed sPLT chunk"); return; @@ -2174,7 +2205,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) /* We need to have at least 12 bytes after the purpose string * in order to get the parameter information. */ - if (endptr <= buf + 12) + if (endptr - buf <= 12) { png_chunk_benign_error(png_ptr, "invalid"); return; @@ -4039,7 +4070,7 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output, * * TODO: deal more elegantly with truncated IDAT lists. */ - ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); + ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH); /* Take the unconsumed output back. */ if (output != NULL) diff --git a/src/3rdparty/libpng/pngset.c b/src/3rdparty/libpng/pngset.c index 05a2134dbba..8fd7965fca5 100644 --- a/src/3rdparty/libpng/pngset.c +++ b/src/3rdparty/libpng/pngset.c @@ -520,8 +520,8 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, if (png_ptr == NULL || info_ptr == NULL) return; - max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? - (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; if (num_palette < 0 || num_palette > (int) max_palette_length) { @@ -1573,7 +1573,7 @@ png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, { /* Images with dimensions larger than these limits will be * rejected by png_set_IHDR(). To accept any PNG datastream - * regardless of dimensions, set both limits to 0x7ffffff. + * regardless of dimensions, set both limits to 0x7fffffff. */ if (png_ptr == NULL) return; diff --git a/src/3rdparty/libpng/pngstruct.h b/src/3rdparty/libpng/pngstruct.h index c8c0e46e8b0..d0bcc7914a5 100644 --- a/src/3rdparty/libpng/pngstruct.h +++ b/src/3rdparty/libpng/pngstruct.h @@ -263,6 +263,9 @@ struct png_struct_def /* pixel depth used for the row buffers */ png_byte transformed_pixel_depth; /* pixel depth after read/write transforms */ +#if PNG_ZLIB_VERNUM >= 0x1240 + png_byte zstream_start; /* at start of an input zlib stream */ +#endif /* Zlib >= 1.2.4 */ #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) png_uint_16 filler; /* filler bytes for pixel expansion */ #endif diff --git a/src/3rdparty/libpng/pngwutil.c b/src/3rdparty/libpng/pngwutil.c index adc4729c241..0ee102b5fba 100644 --- a/src/3rdparty/libpng/pngwutil.c +++ b/src/3rdparty/libpng/pngwutil.c @@ -2563,7 +2563,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) if (filter_to_do == PNG_FILTER_SUB) /* It's the only filter so no testing is needed */ { - (void) png_setup_sub_row(png_ptr, bpp, row_bytes, mins); + (void) png_setup_sub_row(png_ptr, bpp, row_bytes, mins); best_row = png_ptr->try_row; } @@ -2572,7 +2572,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) png_size_t sum; png_size_t lmins = mins; - sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins); + sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins); if (sum < mins) { @@ -2598,7 +2598,7 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) png_size_t sum; png_size_t lmins = mins; - sum = png_setup_up_row(png_ptr, row_bytes, lmins); + sum = png_setup_up_row(png_ptr, row_bytes, lmins); if (sum < mins) { From ca4c33a886fb4cec50f1a4140fc29ec731240ecb Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 9 Feb 2016 14:15:58 +0100 Subject: [PATCH 38/62] Manual High DPI test: Create Dnd pixmap with device pixel ratio. Apply the device pixel ratio from the widget unless Shift is pressed. Task-number: QTBUG-46068 Task-number: QTBUG-50938 Change-Id: Ib806b7e545fa228043566800d22d1002728732bf Reviewed-by: Shawn Rutledge --- tests/manual/highdpi/dragwidget.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/manual/highdpi/dragwidget.cpp b/tests/manual/highdpi/dragwidget.cpp index b2035666965..193a90cd185 100644 --- a/tests/manual/highdpi/dragwidget.cpp +++ b/tests/manual/highdpi/dragwidget.cpp @@ -168,7 +168,11 @@ void DragWidget::mousePressEvent(QMouseEvent *event) mimeData->setData("application/x-hotspot", QByteArray::number(hotSpot.x()) + " " + QByteArray::number(hotSpot.y())); - QPixmap pixmap(child->size()); + const qreal dpr = devicePixelRatioF() > 1 && !(QGuiApplication::keyboardModifiers() & Qt::ShiftModifier) + ? devicePixelRatioF() : 1; + + QPixmap pixmap(child->size() * dpr); + pixmap.setDevicePixelRatio(dpr); child->render(&pixmap); QDrag *drag = new QDrag(this); From b8e8c6ad5caf06c5865ed8ce163515f8e538ca7b Mon Sep 17 00:00:00 2001 From: Jochen Seemann Date: Wed, 25 Nov 2015 18:47:37 +0100 Subject: [PATCH 39/62] winrt: enable cross-platform high DPI scaling Task-number: QTBUG-46615 Change-Id: I7f75bc7da35b9330753130338a06feb49533061c Reviewed-by: Andrew Knight Reviewed-by: Maurice Kalinowski --- src/plugins/platforms/winrt/qwinrtscreen.cpp | 6 ++++++ src/plugins/platforms/winrt/qwinrtscreen.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp index 2410848cdee..47e68ae0afa 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp @@ -635,6 +635,12 @@ QDpi QWinRTScreen::logicalDpi() const return QDpi(d->logicalDpi, d->logicalDpi); } +qreal QWinRTScreen::pixelDensity() const +{ + Q_D(const QWinRTScreen); + return qRound(d->logicalDpi / 96); +} + qreal QWinRTScreen::scaleFactor() const { Q_D(const QWinRTScreen); diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h index 0043b2cfa3f..ac9db9bfef8 100644 --- a/src/plugins/platforms/winrt/qwinrtscreen.h +++ b/src/plugins/platforms/winrt/qwinrtscreen.h @@ -93,6 +93,7 @@ public: QImage::Format format() const Q_DECL_OVERRIDE; QSizeF physicalSize() const Q_DECL_OVERRIDE; QDpi logicalDpi() const Q_DECL_OVERRIDE; + qreal pixelDensity() const Q_DECL_OVERRIDE; qreal scaleFactor() const; QPlatformCursor *cursor() const Q_DECL_OVERRIDE; Qt::KeyboardModifiers keyboardModifiers() const; From 523c7e3fd55c853dd424d57f28e225d57439cf89 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 3 Mar 2016 14:12:16 +0100 Subject: [PATCH 40/62] build with explicitlib after all unlike speculated in 2fe363514, this is not a workaround at all: it causes that libraries' public link interfaces (LIBS) are exported in the first place. unlike with staticlib, this does not export LIBS_PRIVATE, so it wouldn't even be a particularly effective workaround for rpath brokenness anyway. the problem was pretty well hidden by the qt module system, which at the level of libraries is pretty redundant with the .prl file handling, which shows just how stupid the whole "design" is. unlike before, we now enable explicitlib for all libraries, not just qt modules - we enable create_prl for all of them as well, after all. an immediate effect of this change is that it fixes linking on RaspPI: the qtcore headers make the user code require linking libatomic, so we must add it to our public link interface. Task-number: QTBUG-51621 Change-Id: I5742c88694db8e8a9b79d17222dc6df2b38e5ab2 Reviewed-by: Joerg Bornemann Reviewed-by: Allan Sandfeld Jensen --- mkspecs/features/qt_build_config.prf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkspecs/features/qt_build_config.prf b/mkspecs/features/qt_build_config.prf index 518fd93f045..b3081b960ec 100644 --- a/mkspecs/features/qt_build_config.prf +++ b/mkspecs/features/qt_build_config.prf @@ -72,6 +72,10 @@ CONFIG += \ # However, testcases should be still built with exceptions. exceptions_off testcase_exceptions +# Under Windows, this is neither necessary (transitive deps are automatically +# resolved), nor functional (.res files end up in .prl files and break things). +unix: CONFIG += explicitlib + defineTest(qtBuildPart) { bp = $$eval($$upper($$section(_QMAKE_CONF_, /, -2, -2))_BUILD_PARTS) From c27d4eeac6dcd48b89c3deff1110da6bd0ab6476 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 3 Mar 2016 20:59:18 +0100 Subject: [PATCH 41/62] don't force our runpath upon user projects anymore now that we rely on consistently sane runpath semantics everywhere (--enable-new-dtags on linux; the default elsewhere), there is no use in forcing our runpath downstream: our libraries will find their dependencies due to their embedded runpath. this does not affect qt.prf adding qt's own library path to the user projects' runpath. this effectively reverts 42a7eb8df6, and some more. Change-Id: If7af7be7b7a894bebb9b146ccb0035452223c7ac Reviewed-by: Joerg Bornemann --- configure | 3 --- 1 file changed, 3 deletions(-) diff --git a/configure b/configure index f247401c533..7feed4c9e83 100755 --- a/configure +++ b/configure @@ -7048,9 +7048,6 @@ if [ -n "$CFG_SYSROOT" ] && [ "$CFG_GCC_SYSROOT" = "yes" ]; then echo "}" echo fi -if [ -n "$RPATH_FLAGS" ]; then - echo "QMAKE_RPATHDIR += $RPATH_FLAGS" -fi echo "QT_COMPILER_STDCXX = $CFG_STDCXX_DEFAULT" if [ -n "$QT_GCC_MAJOR_VERSION" ]; then echo "QT_GCC_MAJOR_VERSION = $QT_GCC_MAJOR_VERSION" From 867357235ecfe12edd9940d5c8ef08f4e6ac559d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 8 Mar 2016 19:38:59 +0100 Subject: [PATCH 42/62] delay application of configure -D/-I/-L/-l/-R flags it is important that the flags coming from the current qt build appear first, as otherwise a pre-existing qt installation may interfere with the build. the windows configure does not have any of this magic to start with. Task-number: QTBUG-6351 Change-Id: Iacc1d9b5aa9eed9a5f0513baef9f6c6ffcef0735 Reviewed-by: Joerg Bornemann --- configure | 8 ++++---- mkspecs/features/qt_build_config.prf | 3 +++ mkspecs/features/qt_build_extra.prf | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 mkspecs/features/qt_build_extra.prf diff --git a/configure b/configure index 7feed4c9e83..203155c819c 100755 --- a/configure +++ b/configure @@ -6439,9 +6439,9 @@ fi [ "$CFG_SYSTEM_PROXIES" = "yes" ] && QT_CONFIG="$QT_CONFIG system-proxies" [ "$CFG_DIRECTWRITE" = "yes" ] && QT_CONFIG="$QT_CONFIG directwrite" -[ '!' -z "$DEFINES" ] && QMakeVar add DEFINES "$DEFINES" -[ '!' -z "$INCLUDES" ] && QMakeVar add INCLUDEPATH "$INCLUDES" -[ '!' -z "$L_FLAGS" ] && QMakeVar add LIBS "$L_FLAGS" +[ '!' -z "$DEFINES" ] && QMakeVar add EXTRA_DEFINES "$DEFINES" +[ '!' -z "$INCLUDES" ] && QMakeVar add EXTRA_INCLUDEPATH "$INCLUDES" +[ '!' -z "$L_FLAGS" ] && QMakeVar add EXTRA_LIBS "$L_FLAGS" if [ -z "`getXQMakeConf 'QMAKE_(LFLAGS_)?RPATH'`" ]; then if [ -n "$RPATH_FLAGS" ]; then @@ -6457,7 +6457,7 @@ if [ -z "`getXQMakeConf 'QMAKE_(LFLAGS_)?RPATH'`" ]; then else if [ -n "$RPATH_FLAGS" ]; then # add the user defined rpaths - QMakeVar add QMAKE_RPATHDIR "$RPATH_FLAGS" + QMakeVar add EXTRA_RPATHS "$RPATH_FLAGS" fi fi if [ "$CFG_RPATH" = "yes" ]; then diff --git a/mkspecs/features/qt_build_config.prf b/mkspecs/features/qt_build_config.prf index b3081b960ec..2d437e7f910 100644 --- a/mkspecs/features/qt_build_config.prf +++ b/mkspecs/features/qt_build_config.prf @@ -52,6 +52,9 @@ QMAKE_DIR_REPLACE_SANE = PRECOMPILED_DIR OBJECTS_DIR MOC_DIR RCC_DIR UI_DIR unset(modpath) } +# Apply extra compiler flags passed via configure last. +CONFIG = qt_build_extra $$CONFIG + # Don't actually try to install anything in non-prefix builds. # This is much easier and safer than making every single INSTALLS # assignment conditional. diff --git a/mkspecs/features/qt_build_extra.prf b/mkspecs/features/qt_build_extra.prf new file mode 100644 index 00000000000..4b01c7b285f --- /dev/null +++ b/mkspecs/features/qt_build_extra.prf @@ -0,0 +1,27 @@ +# +# W A R N I N G +# ------------- +# +# This file is not part of the Qt API. It exists purely as an +# implementation detail. It may change from version to version +# without notice, or even be removed. +# +# We mean it. +# + +equals(TEMPLATE, subdirs): return() + +# The headersclean check needs defines and includes even for +# header-only modules. +DEFINES += $$EXTRA_DEFINES +INCLUDEPATH += $$EXTRA_INCLUDEPATH + +# The other flags are relevant only for actual libraries. +equals(TEMPLATE, aux): return() + +LIBS += $$EXTRA_LIBS + +# Static libs need no rpaths +static: return() + +QMAKE_RPATHDIR += $$EXTRA_RPATHS From d8be8110a484460504b977dade5f163ee37b8225 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 9 Mar 2016 18:12:08 +0100 Subject: [PATCH 43/62] make -D/-I/-L/-l/-R not affect bootstrapped tools it's likely that these will be wrong, and the bootstrapped tools usually don't need them anyway. should they turn out necessary after all, we need to add -H* variants of the flags. Change-Id: I15c54c5e25d20ebd474073a530f00254842f515d Reviewed-by: Joerg Bornemann --- mkspecs/features/qt_build_extra.prf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkspecs/features/qt_build_extra.prf b/mkspecs/features/qt_build_extra.prf index 4b01c7b285f..a346525e660 100644 --- a/mkspecs/features/qt_build_extra.prf +++ b/mkspecs/features/qt_build_extra.prf @@ -11,6 +11,10 @@ equals(TEMPLATE, subdirs): return() +# It's likely that these extra flags will be wrong for host builds, +# and the bootstrapped tools usually don't need them anyway. +host_build:force_bootstrap: return() + # The headersclean check needs defines and includes even for # header-only modules. DEFINES += $$EXTRA_DEFINES From adc5c93ddc85d5348ee88c330bd3ca7244781311 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 9 Mar 2016 17:42:29 +0100 Subject: [PATCH 44/62] support relative paths in configure -R [ChangeLog][configure][Unix] configure -R now supports paths relative to -libdir. Change-Id: Ie56264a6dedcbaf5577c7ef44b056c8a7870ef48 Reviewed-by: Joerg Bornemann Reviewed-by: Oswald Buddenhagen --- mkspecs/features/qt.prf | 15 +-------------- mkspecs/features/qt_build_extra.prf | 11 ++++++++++- mkspecs/features/qt_functions.prf | 13 +++++++++++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/mkspecs/features/qt.prf b/mkspecs/features/qt.prf index f62b6bb1399..5cc176c2ae1 100644 --- a/mkspecs/features/qt.prf +++ b/mkspecs/features/qt.prf @@ -160,21 +160,8 @@ qt_module_deps = $$resolve_depends(qt_module_deps, "QT.") contains(qt_module_deps, core) { relative_qt_rpath:!isEmpty(QMAKE_REL_RPATH_BASE):contains(INSTALLS, target):\ isEmpty(target.files):isEmpty(target.commands):isEmpty(target.extra) { - mac { - if(equals(TEMPLATE, app):app_bundle)|\ - if(equals(TEMPLATE, lib):plugin:plugin_bundle) { - ios: binpath = $$target.path/$${TARGET}.app - else: binpath = $$target.path/$${TARGET}.app/Contents/MacOS - } else: equals(TEMPLATE, lib):!plugin:lib_bundle { - binpath = $$target.path/$${TARGET}.framework/Versions/Current - } else { - binpath = $$target.path - } - } else { - binpath = $$target.path - } # NOT the /dev property, as INSTALLS use host paths - QMAKE_RPATHDIR += $$relative_path($$[QT_INSTALL_LIBS], $$binpath) + QMAKE_RPATHDIR += $$relative_path($$[QT_INSTALL_LIBS], $$qtRelativeRPathBase()) } else { QMAKE_RPATHDIR += $$[QT_INSTALL_LIBS/dev] } diff --git a/mkspecs/features/qt_build_extra.prf b/mkspecs/features/qt_build_extra.prf index a346525e660..378f5bbd7c4 100644 --- a/mkspecs/features/qt_build_extra.prf +++ b/mkspecs/features/qt_build_extra.prf @@ -28,4 +28,13 @@ LIBS += $$EXTRA_LIBS # Static libs need no rpaths static: return() -QMAKE_RPATHDIR += $$EXTRA_RPATHS +for (rp, EXTRA_RPATHS) { + absrp = $$absolute_path($$rp, $$[QT_INSTALL_LIBS]) + !isEqual(absrp, $$rp) { + isEmpty(QMAKE_REL_RPATH_BASE)|!contains(INSTALLS, target): \ + rp = $$absrp + else: \ + rp = $$relative_path($$absrp, $$qtRelativeRPathBase()) + } + QMAKE_RPATHDIR += $$rp +} diff --git a/mkspecs/features/qt_functions.prf b/mkspecs/features/qt_functions.prf index b2c25078071..86396958f16 100644 --- a/mkspecs/features/qt_functions.prf +++ b/mkspecs/features/qt_functions.prf @@ -32,6 +32,19 @@ defineReplace(qt5LibraryTarget) { return($$LIBRARY_NAME) } +defineReplace(qtRelativeRPathBase) { + darwin { + if(equals(TEMPLATE, app):app_bundle)|\ + if(equals(TEMPLATE, lib):plugin:plugin_bundle) { + ios: return($$target.path/$${TARGET}.app) + return($$target.path/$${TARGET}.app/Contents/MacOS) + } + equals(TEMPLATE, lib):!plugin:lib_bundle: \ + return($$target.path/$${TARGET}.framework/Versions/Current) + } + return($$target.path) +} + defineTest(qtAddLibrary) { warning("qtAddLibrary() is deprecated. Use QT+= instead.") From d3744eff8600a8d1bcc97db6737c7f4f46316312 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 11 Mar 2016 17:48:53 +0100 Subject: [PATCH 45/62] de-duplicate condition for default install target we can rely on the super class to get it right. as a "side effect", we won't try to install .pdb files for aux projects anymore - the duplicated conditional was incomplete. Change-Id: I9b66f32ab50ed2a1d4e6e03a9d205686a4b4a981 Reviewed-by: Joerg Bornemann --- qmake/generators/win32/msvc_nmake.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/qmake/generators/win32/msvc_nmake.cpp b/qmake/generators/win32/msvc_nmake.cpp index ca8e8f26158..f7a5019f8b5 100644 --- a/qmake/generators/win32/msvc_nmake.cpp +++ b/qmake/generators/win32/msvc_nmake.cpp @@ -261,12 +261,9 @@ void NmakeMakefileGenerator::writeSubMakeCall(QTextStream &t, const QString &cal QString NmakeMakefileGenerator::defaultInstall(const QString &t) { - if((t != "target" && t != "dlltarget") || - (t == "dlltarget" && (project->first("TEMPLATE") != "lib" || !project->isActiveConfig("shared"))) || - project->first("TEMPLATE") == "subdirs") - return QString(); - QString ret = Win32MakefileGenerator::defaultInstall(t); + if (ret.isEmpty()) + return ret; const QString root = installRoot(); ProStringList &uninst = project->values(ProKey(t + ".uninstall")); From abe3217bac18fe8a99cbb2f494a5e4cf6c6d70ce Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 29 Jan 2016 14:03:41 +0100 Subject: [PATCH 46/62] Reimplement QShapedPixmapWindow using QRasterWindow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation makes the window too big when a QPixmap with a DPR != 1 is set. Circumvent the problem by using a QRasterWindow. Task-number: QTBUG-46068 Task-number: QTBUG-50938 Change-Id: I0fca91f571937250c740f1400bd60286330fb595 Reviewed-by: Błażej Szczygieł Reviewed-by: Alexander Volkov Reviewed-by: Shawn Rutledge --- src/gui/kernel/qshapedpixmapdndwindow.cpp | 72 ++++++++++------------- src/gui/kernel/qshapedpixmapdndwindow_p.h | 10 +--- 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/src/gui/kernel/qshapedpixmapdndwindow.cpp b/src/gui/kernel/qshapedpixmapdndwindow.cpp index d77b6dc2622..850987ac1d3 100644 --- a/src/gui/kernel/qshapedpixmapdndwindow.cpp +++ b/src/gui/kernel/qshapedpixmapdndwindow.cpp @@ -42,52 +42,31 @@ QT_BEGIN_NAMESPACE QShapedPixmapWindow::QShapedPixmapWindow(QScreen *screen) - : QWindow(screen), - m_backingStore(0), - m_useCompositing(true) + : m_useCompositing(true) { + setScreen(screen); QSurfaceFormat format; format.setAlphaBufferSize(8); setFormat(format); - setSurfaceType(RasterSurface); - setFlags(Qt::ToolTip | Qt::FramelessWindowHint | - Qt::X11BypassWindowManagerHint | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus); - create(); - m_backingStore = new QBackingStore(this); + setFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint + | Qt::WindowTransparentForInput | Qt::WindowDoesNotAcceptFocus); } QShapedPixmapWindow::~QShapedPixmapWindow() { - delete m_backingStore; - m_backingStore = 0; -} - -void QShapedPixmapWindow::render() -{ - QRect rect(QPoint(), geometry().size()); - - m_backingStore->beginPaint(rect); - - QPaintDevice *device = m_backingStore->paintDevice(); - - { - QPainter p(device); - if (m_useCompositing) - p.setCompositionMode(QPainter::CompositionMode_Source); - else - p.fillRect(rect, QGuiApplication::palette().base()); - p.drawPixmap(0, 0, m_pixmap); - } - - m_backingStore->endPaint(); - m_backingStore->flush(rect); } void QShapedPixmapWindow::setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; - if (!m_useCompositing) - setMask(m_pixmap.mask()); + if (!m_useCompositing) { + const QBitmap mask = m_pixmap.mask(); + if (!mask.isNull()) { + if (!handle()) + create(); + setMask(mask); + } + } } void QShapedPixmapWindow::setHotspot(const QPoint &hotspot) @@ -95,19 +74,28 @@ void QShapedPixmapWindow::setHotspot(const QPoint &hotspot) m_hotSpot = hotspot; } -void QShapedPixmapWindow::updateGeometry(const QPoint &pos) +void QShapedPixmapWindow::paintEvent(QPaintEvent *) { - if (m_pixmap.isNull()) - m_backingStore->resize(QSize(1,1)); - else if (m_backingStore->size() != m_pixmap.size()) - m_backingStore->resize(m_pixmap.size()); - - setGeometry(QRect(pos - m_hotSpot, m_backingStore->size())); + if (!m_pixmap.isNull()) { + const QRect rect(QPoint(0, 0), size()); + QPainter painter(this); + if (m_useCompositing) + painter.setCompositionMode(QPainter::CompositionMode_Source); + else + painter.fillRect(rect, QGuiApplication::palette().base()); + painter.drawPixmap(rect, m_pixmap); + } } -void QShapedPixmapWindow::exposeEvent(QExposeEvent *) +void QShapedPixmapWindow::updateGeometry(const QPoint &pos) { - render(); + QSize size(1, 1); + if (!m_pixmap.isNull()) { + size = qFuzzyCompare(m_pixmap.devicePixelRatio(), 1.0) + ? m_pixmap.size() + : (QSizeF(m_pixmap.size()) / m_pixmap.devicePixelRatio()).toSize(); + } + setGeometry(QRect(pos - m_hotSpot, size)); } QT_END_NAMESPACE diff --git a/src/gui/kernel/qshapedpixmapdndwindow_p.h b/src/gui/kernel/qshapedpixmapdndwindow_p.h index 3d7974fa827..f2d678c1b47 100644 --- a/src/gui/kernel/qshapedpixmapdndwindow_p.h +++ b/src/gui/kernel/qshapedpixmapdndwindow_p.h @@ -45,21 +45,18 @@ // We mean it. // -#include +#include #include -#include QT_BEGIN_NAMESPACE -class QShapedPixmapWindow : public QWindow +class QShapedPixmapWindow : public QRasterWindow { Q_OBJECT public: explicit QShapedPixmapWindow(QScreen *screen = 0); ~QShapedPixmapWindow(); - void render(); - void setUseCompositing(bool on) { m_useCompositing = on; } void setPixmap(const QPixmap &pixmap); void setHotspot(const QPoint &hotspot); @@ -67,10 +64,9 @@ public: void updateGeometry(const QPoint &pos); protected: - void exposeEvent(QExposeEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; private: - QBackingStore *m_backingStore; QPixmap m_pixmap; QPoint m_hotSpot; bool m_useCompositing; From 09acf326dbc6b7b67f21a360be8c91605ce47f1e Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 17 Feb 2016 16:33:22 -0800 Subject: [PATCH 47/62] QCocoaMenu: Decouple NSMenuItem from NSMenu While Cocoa requires an NSMenu to be coupled to an NSMenuItem (just as Qt requires a QMenu to be coupled to a QAction), making that a hard coupling comes with some limitations. This is because Cocoa won't allow the NSMenu object to be simultaneously coupled to more than one NSMenuItem and, similarly, an NSMenuItem can only be added to a single parent NSMenu. Therefore, it becomes difficult to share one QMenu between two different QMenuBars in different windows, or to use a QMenu as context menu while being accessible from the menu bar. Previous solutions to circumvent those limitations were less than ideal (see 119882714f87ffeb6945fdb2d02997ae125ff50c for the QMenuBar shared QMenu issue). Other workarounds that relied on that hard coupling, like 996054f5e65bc676aaea0743c2eacec51918e4aa, also added gratuitous complexity. In this patch, we break that hard NSMenuItem-NSMenu coupling, and we replace it with a temporary, looser coupling. As a consequence, * QCocoaMenu only contains and manages a NSMenu instance, removing the previously used NSMenuItem. It gets a temporarily attached NSMenuItem instead. * QCocoaMenuItem gains a safe pointer to its QCocoaMenu property removing the necessity containingMenuItem() in QCocoaMenu. * QCocoaMenuBar manages its own NSMenuItems. With this setup, we bind the NSMenu to its parent NSMenuItem at the last moment. In QCocoaMenuBar, when we call updateMenuBarImmediately(). In QCocoaMenu, we use the delegate's -[QCocoaMenuDelegate menu: updateItem:atIndex:shouldCancel:] method which is called when Cocoa is about to display the NSMenu. Note: There's still one use case we don't support, which is sharing a toplevel QMenuBar menu. This is because Cocoa's menu bar requires each of its menu items to have a submenu assigned, and therefore we can't rely on that last moment assignment. Task-number: QTBUG-34160 Task-number: QTBUG-31342 Task-number: QTBUG-41587 Change-Id: I92bdb444c680789c78e43fe0b585dc6661770281 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoamenu.h | 13 +- src/plugins/platforms/cocoa/qcocoamenu.mm | 82 +++++++------ src/plugins/platforms/cocoa/qcocoamenubar.h | 6 +- src/plugins/platforms/cocoa/qcocoamenubar.mm | 115 ++++++++++-------- src/plugins/platforms/cocoa/qcocoamenuitem.h | 3 +- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 17 --- 6 files changed, 113 insertions(+), 123 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoamenu.h b/src/plugins/platforms/cocoa/qcocoamenu.h index eccc5230b5d..5064d89585f 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.h +++ b/src/plugins/platforms/cocoa/qcocoamenu.h @@ -75,8 +75,6 @@ public: inline NSMenu *nsMenu() const { return m_nativeMenu; } - inline NSMenuItem *nsMenuItem() const - { return m_nativeItem; } inline bool isVisible() const { return m_visible; } @@ -85,11 +83,9 @@ public: QList items() const; QList merged() const; - void setMenuBar(QCocoaMenuBar *menuBar); - QCocoaMenuBar *menuBar() const; - void setContainingMenuItem(QCocoaMenuItem *menuItem); - QCocoaMenuItem *containingMenuItem() const; + void setAttachedItem(NSMenuItem *item); + NSMenuItem *attachedItem() const; private: QCocoaMenuItem *itemOrNull(int index) const; @@ -97,13 +93,10 @@ private: QList m_menuItems; NSMenu *m_nativeMenu; - NSMenuItem *m_nativeItem; - NSObject *m_delegate; + NSMenuItem *m_attachedItem; bool m_enabled; bool m_visible; quintptr m_tag; - QCocoaMenuBar *m_menuBar; - QCocoaMenuItem *m_containingMenuItem; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index ad491855ff4..21a37998595 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -96,6 +96,28 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuDelegate); return self; } +- (NSInteger)numberOfItemsInMenu:(NSMenu *)menu +{ + Q_ASSERT(m_menu->nsMenu() == menu); + return m_menu->items().count(); +} + +- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(NSInteger)index shouldCancel:(BOOL)shouldCancel +{ + Q_UNUSED(index); + Q_ASSERT(m_menu->nsMenu() == menu); + if (shouldCancel) { + // TODO detach all submenus + return NO; + } + + QCocoaMenuItem *menuItem = reinterpret_cast(item.tag); + if (m_menu->items().contains(menuItem)) { + if (QCocoaMenu *itemSubmenu = menuItem->menu()) + itemSubmenu->setAttachedItem(item); + } + return YES; +} - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item { @@ -228,20 +250,16 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuDelegate); QT_BEGIN_NAMESPACE QCocoaMenu::QCocoaMenu() : + m_attachedItem(0), m_enabled(true), m_visible(true), - m_tag(0), - m_menuBar(0), - m_containingMenuItem(0) + m_tag(0) { QMacAutoReleasePool pool; - m_delegate = [[QCocoaMenuDelegate alloc] initWithMenu:this]; - m_nativeItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; m_nativeMenu = [[NSMenu alloc] initWithTitle:@"Untitled"]; [m_nativeMenu setAutoenablesItems:YES]; - m_nativeMenu.delegate = (QCocoaMenuDelegate *) m_delegate; - [m_nativeItem setSubmenu:m_nativeMenu]; + m_nativeMenu.delegate = [[QCocoaMenuDelegate alloc] initWithMenu:this]; } QCocoaMenu::~QCocoaMenu() @@ -251,14 +269,11 @@ QCocoaMenu::~QCocoaMenu() SET_COCOA_MENU_ANCESTOR(item, 0); } - if (m_containingMenuItem) - m_containingMenuItem->clearMenu(this); - QMacAutoReleasePool pool; - [m_nativeItem setSubmenu:nil]; + NSObject *delegate = m_nativeMenu.delegate; + m_nativeMenu.delegate = nil; + [delegate release]; [m_nativeMenu release]; - [m_delegate release]; - [m_nativeItem release]; } void QCocoaMenu::setText(const QString &text) @@ -266,7 +281,6 @@ void QCocoaMenu::setText(const QString &text) QMacAutoReleasePool pool; QString stripped = qt_mac_removeAmpersandEscapes(text); [m_nativeMenu setTitle:QCFString::toNSString(stripped)]; - [m_nativeItem setTitle:QCFString::toNSString(stripped)]; } void QCocoaMenu::setMinimumWidth(int width) @@ -307,17 +321,13 @@ void QCocoaMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem * void QCocoaMenu::insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem) { - [item->nsItem() setTarget:m_delegate]; + item->nsItem().target = m_nativeMenu.delegate; if (!item->menu()) [item->nsItem() setAction:@selector(itemFired:)]; if (item->isMerged()) return; - if ([item->nsItem() menu]) { - qWarning("Menu item is already in a menu, remove it from the other menu first before inserting"); - return; - } // if the item we're inserting before is merged, skip along until // we find a non-merged real item to insert ahead of. while (beforeItem && beforeItem->isMerged()) { @@ -445,12 +455,11 @@ void QCocoaMenu::setEnabled(bool enabled) bool QCocoaMenu::isEnabled() const { - return [m_nativeItem isEnabled]; + return m_attachedItem ? [m_attachedItem isEnabled] : m_enabled; } void QCocoaMenu::setVisible(bool visible) { - [m_nativeItem setSubmenu:(visible ? m_nativeMenu : nil)]; m_visible = visible; } @@ -587,8 +596,6 @@ void QCocoaMenu::syncModalState(bool modal) if (!m_enabled) modal = true; - [m_nativeItem setEnabled:!modal]; - foreach (QCocoaMenuItem *item, m_menuItems) { if (item->menu()) { // recurse into submenus item->menu()->syncModalState(modal); @@ -599,25 +606,24 @@ void QCocoaMenu::syncModalState(bool modal) } } -void QCocoaMenu::setMenuBar(QCocoaMenuBar *menuBar) +void QCocoaMenu::setAttachedItem(NSMenuItem *item) { - m_menuBar = menuBar; - SET_COCOA_MENU_ANCESTOR(this, menuBar); + if (item == m_attachedItem) + return; + + if (m_attachedItem) + m_attachedItem.submenu = nil; + + m_attachedItem = item; + + if (m_attachedItem) + m_attachedItem.submenu = m_nativeMenu; + } -QCocoaMenuBar *QCocoaMenu::menuBar() const +NSMenuItem *QCocoaMenu::attachedItem() const { - return m_menuBar; -} - -void QCocoaMenu::setContainingMenuItem(QCocoaMenuItem *menuItem) -{ - m_containingMenuItem = menuItem; -} - -QCocoaMenuItem *QCocoaMenu::containingMenuItem() const -{ - return m_containingMenuItem; + return m_attachedItem; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h index d5f75abf349..e84da7aeb0a 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.h +++ b/src/plugins/platforms/cocoa/qcocoamenubar.h @@ -71,10 +71,10 @@ private: static QCocoaMenuBar *findGlobalMenubar(); bool shouldDisable(QCocoaWindow *active) const; - void insertNativeMenu(QCocoaMenu *menu, QCocoaMenu *beforeMenu); - void removeNativeMenu(QCocoaMenu *menu); - QList m_menus; + NSMenuItem *nativeItemForMenu(QCocoaMenu *menu) const; + + QList > m_menus; NSMenu *m_nativeMenu; QCocoaWindow *m_window; }; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 1a516f874b2..ac4d29fc52f 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -51,7 +51,6 @@ static inline QCocoaMenuLoader *getMenuLoader() return [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)]; } - QCocoaMenuBar::QCocoaMenuBar() : m_window(0) { @@ -68,11 +67,20 @@ QCocoaMenuBar::~QCocoaMenuBar() #ifdef QT_COCOA_ENABLE_MENU_DEBUG qDebug() << "~QCocoaMenuBar" << this; #endif + foreach (QCocoaMenu *menu, m_menus) { + if (!menu) + continue; + NSMenuItem *item = nativeItemForMenu(menu); + if (menu->attachedItem() == item) + menu->setAttachedItem(nil); + } + [m_nativeMenu release]; static_menubars.removeOne(this); if (m_window && m_window->menubar() == this) { m_window->setMenubar(0); + // Delete the children first so they do not cause // the native menu items to be hidden after // the menu bar was updated @@ -81,24 +89,6 @@ QCocoaMenuBar::~QCocoaMenuBar() } } -void QCocoaMenuBar::insertNativeMenu(QCocoaMenu *menu, QCocoaMenu *beforeMenu) -{ - QMacAutoReleasePool pool; - - if (beforeMenu) { - NSUInteger nativeIndex = [m_nativeMenu indexOfItem:beforeMenu->nsMenuItem()]; - [m_nativeMenu insertItem: menu->nsMenuItem() atIndex: nativeIndex]; - } else { - [m_nativeMenu addItem: menu->nsMenuItem()]; - } - - menu->setMenuBar(this); - syncMenu(static_cast(menu)); - if (menu->isVisible()) { - [m_nativeMenu setSubmenu: menu->nsMenu() forItem: menu->nsMenuItem()]; - } -} - void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *before) { QCocoaMenu *menu = static_cast(platformMenu); @@ -107,33 +97,42 @@ void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *befor qDebug() << "QCocoaMenuBar" << this << "insertMenu" << menu << "before" << before; #endif - if (m_menus.contains(menu)) { + if (m_menus.contains(QPointer(menu))) { qWarning("This menu already belongs to the menubar, remove it first"); return; } - if (beforeMenu && !m_menus.contains(beforeMenu)) { + if (beforeMenu && !m_menus.contains(QPointer(beforeMenu))) { qWarning("The before menu does not belong to the menubar"); return; } - m_menus.insert(beforeMenu ? m_menus.indexOf(beforeMenu) : m_menus.size(), menu); - if (!menu->menuBar()) - insertNativeMenu(menu, beforeMenu); + int insertionIndex = beforeMenu ? m_menus.indexOf(beforeMenu) : m_menus.size(); + m_menus.insert(insertionIndex, menu); + + { + QMacAutoReleasePool pool; + NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; + item.tag = reinterpret_cast(menu); + + if (beforeMenu) { + // QMenuBar::toNSMenu() exposes the native menubar and + // the user could have inserted its own items in there. + // Same remark applies to removeMenu(). + NSMenuItem *beforeItem = nativeItemForMenu(beforeMenu); + NSInteger nativeIndex = [m_nativeMenu indexOfItem:beforeItem]; + [m_nativeMenu insertItem:item atIndex:nativeIndex]; + } else { + [m_nativeMenu addItem:item]; + } + } + + syncMenu(menu); + if (m_window && m_window->window()->isActive()) updateMenuBarImmediately(); } -void QCocoaMenuBar::removeNativeMenu(QCocoaMenu *menu) -{ - QMacAutoReleasePool pool; - - if (menu->menuBar() == this) - menu->setMenuBar(0); - NSUInteger realIndex = [m_nativeMenu indexOfItem:menu->nsMenuItem()]; - [m_nativeMenu removeItemAtIndex: realIndex]; -} - void QCocoaMenuBar::removeMenu(QPlatformMenu *platformMenu) { QCocoaMenu *menu = static_cast(platformMenu); @@ -141,8 +140,17 @@ void QCocoaMenuBar::removeMenu(QPlatformMenu *platformMenu) qWarning("Trying to remove a menu that does not belong to the menubar"); return; } + + NSMenuItem *item = nativeItemForMenu(menu); + if (menu->attachedItem() == item) + menu->setAttachedItem(nil); m_menus.removeOne(menu); - removeNativeMenu(menu); + + QMacAutoReleasePool pool; + + // See remark in insertMenu(). + NSInteger nativeIndex = [m_nativeMenu indexOfItem:item]; + [m_nativeMenu removeItemAtIndex:nativeIndex]; } void QCocoaMenuBar::syncMenu(QPlatformMenu *menu) @@ -164,7 +172,16 @@ void QCocoaMenuBar::syncMenu(QPlatformMenu *menu) break; } } - [cocoaMenu->nsMenuItem() setHidden:shouldHide]; + + nativeItemForMenu(cocoaMenu).hidden = shouldHide; +} + +NSMenuItem *QCocoaMenuBar::nativeItemForMenu(QCocoaMenu *menu) const +{ + if (!menu) + return nil; + + return [m_nativeMenu itemWithTag:reinterpret_cast(menu)]; } void QCocoaMenuBar::handleReparent(QWindow *newParentWindow) @@ -291,24 +308,16 @@ void QCocoaMenuBar::updateMenuBarImmediately() qDebug() << "QCocoaMenuBar" << "updateMenuBarImmediately" << cw; #endif bool disableForModal = mb->shouldDisable(cw); - // force a sync? - foreach (QCocoaMenu *m, mb->m_menus) { - mb->syncMenu(m); - m->syncModalState(disableForModal); - } - // reparent shared menu items if necessary. - // We browse the list in reverse order to be sure that the next items are redrawn before the current ones, - // in this way we are sure that "beforeMenu" (see below) is part of the native menu before "m" is redraw - for (int i = mb->m_menus.size() - 1; i >= 0; i--) { - QCocoaMenu *m = mb->m_menus.at(i); - QCocoaMenuBar *menuBar = m->menuBar(); - if (menuBar != mb) { - QCocoaMenu *beforeMenu = i < (mb->m_menus.size() - 1) ? mb->m_menus.at(i + 1) : 0; - if (menuBar) - menuBar->removeNativeMenu(m); - mb->insertNativeMenu(m, beforeMenu); - } + foreach (QCocoaMenu *menu, mb->m_menus) { + if (!menu) + continue; + NSMenuItem *item = mb->nativeItemForMenu(menu); + menu->setAttachedItem(item); + SET_COCOA_MENU_ANCESTOR(menu, mb); + // force a sync? + mb->syncMenu(menu); + menu->syncModalState(disableForModal); } QCocoaMenuLoader *loader = getMenuLoader(); diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.h b/src/plugins/platforms/cocoa/qcocoamenuitem.h index 1cd15e686c6..ada4b13df1b 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.h +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.h @@ -87,7 +87,6 @@ public: inline bool isSeparator() const { return m_isSeparator; } QCocoaMenu *menu() const { return m_menu; } - void clearMenu(QCocoaMenu *menu); MenuRole effectiveRole() const; private: @@ -99,7 +98,7 @@ private: QString m_text; bool m_textSynced; QIcon m_icon; - QCocoaMenu *m_menu; + QPointer m_menu; bool m_isVisible; bool m_enabled; bool m_isSeparator; diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 0f551bcd7db..e274448620d 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -134,15 +134,12 @@ void QCocoaMenuItem::setMenu(QPlatformMenu *menu) if (m_menu) { if (COCOA_MENU_ANCESTOR(m_menu) == this) SET_COCOA_MENU_ANCESTOR(m_menu, 0); - if (m_menu->containingMenuItem() == this) - m_menu->setContainingMenuItem(0); } QMacAutoReleasePool pool; m_menu = static_cast(menu); if (m_menu) { SET_COCOA_MENU_ANCESTOR(m_menu, this); - m_menu->setContainingMenuItem(this); } else { // we previously had a menu, but no longer // clear out our item so the nexy sync() call builds a new one @@ -151,12 +148,6 @@ void QCocoaMenuItem::setMenu(QPlatformMenu *menu) } } -void QCocoaMenuItem::clearMenu(QCocoaMenu *menu) -{ - if (menu == m_menu) - m_menu = 0; -} - void QCocoaMenuItem::setVisible(bool isVisible) { m_isVisible = isVisible; @@ -218,14 +209,6 @@ NSMenuItem *QCocoaMenuItem::sync() m_native = nil; } - if (m_menu) { - if (m_native != m_menu->nsMenuItem()) { - [m_native release]; - m_native = [m_menu->nsMenuItem() retain]; - [m_native setTag:reinterpret_cast(this)]; - } - } - if ((m_role != NoRole && !m_textSynced) || m_merged) { NSMenuItem *mergeItem = nil; QCocoaMenuLoader *loader = getMenuLoader(); From aa3008dfa1e3dfa0f6a35999ae62e4c012ad8089 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 17 Mar 2016 09:48:08 +0100 Subject: [PATCH 48/62] Introduce separate mapping of QStandardPaths's CLSIDs for Windows CE. CSIDL_APPDATA should be used instead of CSIDL_LOCAL_APPDATA on Windows CE. Amends 910f719bd111813f37278b67d07f9d12cb03a4ff . Task-number: QTBUG-50570 Change-Id: I0cc310ef5fe3fbaefae9c84dd9db8cf48ff48499 Reviewed-by: Tobias Koenig Reviewed-by: Andreas Holzammer --- src/corelib/io/qstandardpaths_win.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 73d49cbc258..c1b34d1341b 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -111,6 +111,7 @@ static inline void appendTestMode(QString &path) // Map QStandardPaths::StandardLocation to CLSID of SHGetSpecialFolderPath() static int writableSpecialFolderClsid(QStandardPaths::StandardLocation type) { +#ifndef Q_OS_WINCE static const int clsids[] = { CSIDL_DESKTOPDIRECTORY, // DesktopLocation CSIDL_PERSONAL, // DocumentsLocation @@ -130,6 +131,27 @@ static int writableSpecialFolderClsid(QStandardPaths::StandardLocation type) CSIDL_APPDATA, // AppDataLocation ("Roaming" path) CSIDL_LOCAL_APPDATA, // AppConfigLocation ("Local" path) }; +#else // !Q_OS_WINCE + static const int clsids[] = { + CSIDL_DESKTOPDIRECTORY, // DesktopLocation + CSIDL_PERSONAL, // DocumentsLocation + CSIDL_FONTS, // FontsLocation + CSIDL_PROGRAMS, // ApplicationsLocation + CSIDL_MYMUSIC, // MusicLocation + CSIDL_MYVIDEO, // MoviesLocation + CSIDL_MYPICTURES, // PicturesLocation + -1, -1, // TempLocation/HomeLocation + CSIDL_APPDATA, // AppLocalDataLocation, AppLocalDataLocation = DataLocation + -1, // CacheLocation + CSIDL_APPDATA, // GenericDataLocation + -1, // RuntimeLocation + CSIDL_APPDATA, // ConfigLocation + -1, -1, // DownloadLocation/GenericCacheLocation + CSIDL_APPDATA, // GenericConfigLocation + CSIDL_APPDATA, // AppDataLocation + CSIDL_APPDATA, // AppConfigLocation + }; +#endif // Q_OS_WINCE Q_STATIC_ASSERT(sizeof(clsids) / sizeof(clsids[0]) == size_t(QStandardPaths::AppConfigLocation + 1)); return size_t(type) < sizeof(clsids) / sizeof(clsids[0]) ? clsids[type] : -1; From 35dce99b5664e47b2210c2dfe36300376e837f1d Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 27 Jan 2016 13:45:55 +0100 Subject: [PATCH 49/62] Fix QAbstractItemView dragged item pixmaps to be HighDPI aware. When an item is rendered into a QPixmap sent to the QDrag implementation, make sure it's size is scaled with the current window's devicePixelRatio, so it does not appear blurry on high-dpi screens. Change-Id: Idf38c0993e8529aff7107ff1ac412de9cf10f311 Task-number: QTBUG-46068 Reviewed-by: Shawn Rutledge --- src/widgets/itemviews/qabstractitemview.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index ad7be840d0c..a126fef65e9 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -4353,7 +4353,20 @@ QPixmap QAbstractItemViewPrivate::renderToPixmap(const QModelIndexList &indexes, QItemViewPaintPairs paintPairs = draggablePaintPairs(indexes, r); if (paintPairs.isEmpty()) return QPixmap(); - QPixmap pixmap(r->size()); + + qreal scale = 1.0f; + + Q_Q(const QAbstractItemView); + QWidget *window = q->window(); + if (window) { + QWindow *windowHandle = window->windowHandle(); + if (windowHandle) + scale = windowHandle->devicePixelRatio(); + } + + QPixmap pixmap(r->size() * scale); + pixmap.setDevicePixelRatio(scale); + pixmap.fill(Qt::transparent); QPainter painter(&pixmap); QStyleOptionViewItem option = viewOptionsV1(); From 461ebedb98c986c047a68e98cb9cc3c212d5d315 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 17 Mar 2016 15:22:03 +0200 Subject: [PATCH 50/62] Android: Fix compilation with NDK r11 Task-number: QTBUG-51859 Change-Id: Id8bbcc9f0503ab2742e8da7f3b5de03fd46714b2 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/global/qlogging.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index ca38d672c38..e341b3ecfdf 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -96,6 +96,11 @@ extern char *__progname; #if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include()) # include + +# if defined(Q_OS_ANDROID) && !defined(SYS_gettid) +# define SYS_gettid __NR_gettid +# endif + static long qt_gettid() { // no error handling From 5c89e2eeeed3c58e8068ddfca0cddcc801c2e30a Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 15 Mar 2016 10:59:59 +0100 Subject: [PATCH 51/62] Rework QWindowsPipeReader The use of QWinOverlappedIoNotifier in QWindowsPipeReader restricts us in the following ways: - The handle that gets assigned to QWinOverlappedIoNotifier is forever tied to an I/O completion port. - Other notification mechanisms like I/O completion routines of WriteFileEx do not work with such a handle. - No other QWinOverlappedIoNotifier can be registered for this handle. To achieve the ultimate goal of making QWindowsPipeWriter thread-free (to fix QTBUG-23378 and QTBUG-38185) we remove the usage of QWinOverlappedIoNotifier from QWindowsPipeReader and use the ReadFileEx API instead. This has the additional advantage of removing the need for any thread synchronization, as the I/O completion routine runs in the thread that ReadFileEx was called on, leading to simpler and faster code. Change-Id: I05c983e1f1e49d7dd27e3b77a47f87cae9c3f4c6 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qwindowspipereader.cpp | 152 ++++++++++++++++---------- src/corelib/io/qwindowspipereader_p.h | 32 ++++-- 2 files changed, 117 insertions(+), 67 deletions(-) diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index f0d64174832..ee7af8a08b0 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -32,25 +32,37 @@ ****************************************************************************/ #include "qwindowspipereader_p.h" -#include "qwinoverlappedionotifier_p.h" -#include +#include "qiodevice_p.h" #include -#include QT_BEGIN_NAMESPACE +QWindowsPipeReader::Overlapped::Overlapped(QWindowsPipeReader *reader) + : pipeReader(reader) +{ +} + +void QWindowsPipeReader::Overlapped::clear() +{ + ZeroMemory(this, sizeof(OVERLAPPED)); +} + + QWindowsPipeReader::QWindowsPipeReader(QObject *parent) : QObject(parent), handle(INVALID_HANDLE_VALUE), + overlapped(this), readBufferMaxSize(0), actualReadBufferSize(0), stopped(true), readSequenceStarted(false), + notifiedCalled(false), pipeBroken(false), - readyReadEmitted(false) + readyReadPending(false), + inReadyRead(false) { - dataReadNotifier = new QWinOverlappedIoNotifier(this); - connect(dataReadNotifier, &QWinOverlappedIoNotifier::notified, this, &QWindowsPipeReader::notified); + connect(this, &QWindowsPipeReader::_q_queueReadyRead, + this, &QWindowsPipeReader::emitPendingReadyRead, Qt::QueuedConnection); } static bool qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) @@ -82,12 +94,6 @@ void QWindowsPipeReader::setHandle(HANDLE hPipeReadEnd) actualReadBufferSize = 0; handle = hPipeReadEnd; pipeBroken = false; - readyReadEmitted = false; - stopped = false; - if (hPipeReadEnd != INVALID_HANDLE_VALUE) { - dataReadNotifier->setHandle(hPipeReadEnd); - dataReadNotifier->setEnabled(true); - } } /*! @@ -98,19 +104,15 @@ void QWindowsPipeReader::stop() { stopped = true; if (readSequenceStarted) { - if (qt_cancelIo(handle, &overlapped)) { - dataReadNotifier->waitForNotified(-1, &overlapped); - } else { + if (!qt_cancelIo(handle, &overlapped)) { const DWORD dwError = GetLastError(); if (dwError != ERROR_NOT_FOUND) { qErrnoWarning(dwError, "QWindowsPipeReader: qt_cancelIo on handle %x failed.", handle); } } + waitForNotification(-1); } - readSequenceStarted = false; - dataReadNotifier->setEnabled(false); - handle = INVALID_HANDLE_VALUE; } /*! @@ -168,11 +170,10 @@ bool QWindowsPipeReader::canReadLine() const \internal Will be called whenever the read operation completes. */ -void QWindowsPipeReader::notified(quint32 numberOfBytesRead, quint32 errorCode, - OVERLAPPED *notifiedOverlapped) +void QWindowsPipeReader::notified(DWORD errorCode, DWORD numberOfBytesRead) { - if (&overlapped != notifiedOverlapped) - return; + notifiedCalled = true; + readSequenceStarted = false; switch (errorCode) { case ERROR_SUCCESS: @@ -196,8 +197,6 @@ void QWindowsPipeReader::notified(quint32 numberOfBytesRead, quint32 errorCode, break; } - readSequenceStarted = false; - // After the reader was stopped, the only reason why this function can be called is the // completion of a cancellation. No signals should be emitted, and no new read sequence should // be started in this case. @@ -212,13 +211,15 @@ void QWindowsPipeReader::notified(quint32 numberOfBytesRead, quint32 errorCode, actualReadBufferSize += numberOfBytesRead; readBuffer.truncate(actualReadBufferSize); startAsyncRead(); - readyReadEmitted = true; - emit readyRead(); + if (!readyReadPending) { + readyReadPending = true; + emit _q_queueReadyRead(QWindowsPipeReader::QPrivateSignal()); + } } /*! \internal - Reads data from the socket into the readbuffer + Reads data from the pipe into the readbuffer. */ void QWindowsPipeReader::startAsyncRead() { @@ -238,41 +239,39 @@ void QWindowsPipeReader::startAsyncRead() char *ptr = readBuffer.reserve(bytesToRead); + stopped = false; readSequenceStarted = true; - ZeroMemory(&overlapped, sizeof(overlapped)); - if (ReadFile(handle, ptr, bytesToRead, NULL, &overlapped)) { - // We get notified by the QWinOverlappedIoNotifier - even in the synchronous case. - return; - } else { + overlapped.clear(); + if (!ReadFileEx(handle, ptr, bytesToRead, &overlapped, &readFileCompleted)) { + readSequenceStarted = false; + const DWORD dwError = GetLastError(); switch (dwError) { - case ERROR_IO_PENDING: - // This is not an error. We're getting notified, when data arrives. - return; - case ERROR_MORE_DATA: - // This is not an error. The synchronous read succeeded. - // We're connected to a message mode pipe and the message - // didn't fit into the pipe's system buffer. - // We're getting notified by the QWinOverlappedIoNotifier. - break; case ERROR_BROKEN_PIPE: case ERROR_PIPE_NOT_CONNECTED: - { - // It may happen, that the other side closes the connection directly - // after writing data. Then we must set the appropriate socket state. - readSequenceStarted = false; - pipeBroken = true; - emit pipeClosed(); - return; - } + // It may happen, that the other side closes the connection directly + // after writing data. Then we must set the appropriate socket state. + pipeBroken = true; + emit pipeClosed(); + break; default: - readSequenceStarted = false; emit winError(dwError, QLatin1String("QWindowsPipeReader::startAsyncRead")); - return; + break; } } } +/*! + \internal + Called when ReadFileEx finished the read operation. + */ +void QWindowsPipeReader::readFileCompleted(DWORD errorCode, DWORD numberOfBytesTransfered, + OVERLAPPED *overlappedBase) +{ + Overlapped *overlapped = static_cast(overlappedBase); + overlapped->pipeReader->notified(errorCode, numberOfBytesTransfered); +} + /*! \internal Returns the number of available bytes in the pipe. @@ -292,17 +291,60 @@ DWORD QWindowsPipeReader::checkPipeState() return 0; } +bool QWindowsPipeReader::waitForNotification(int timeout) +{ + QElapsedTimer t; + t.start(); + notifiedCalled = false; + int msecs = timeout; + while (SleepEx(msecs == -1 ? INFINITE : msecs, TRUE) == WAIT_IO_COMPLETION) { + if (notifiedCalled) + return true; + + // Some other I/O completion routine was called. Wait some more. + msecs = qt_subtract_from_timeout(timeout, t.elapsed()); + if (!msecs) + break; + } + return notifiedCalled; +} + +void QWindowsPipeReader::emitPendingReadyRead() +{ + if (readyReadPending) { + readyReadPending = false; + inReadyRead = true; + emit readyRead(); + inReadyRead = false; + } +} + /*! Waits for the completion of the asynchronous read operation. - Returns \c true, if we've emitted the readyRead signal. + Returns \c true, if we've emitted the readyRead signal (non-recursive case) + or readyRead will be emitted by the event loop (recursive case). */ bool QWindowsPipeReader::waitForReadyRead(int msecs) { if (!readSequenceStarted) return false; - readyReadEmitted = false; - dataReadNotifier->waitForNotified(msecs, &overlapped); - return readyReadEmitted; + + if (readyReadPending) { + if (!inReadyRead) + emitPendingReadyRead(); + return true; + } + + if (!waitForNotification(msecs)) + return false; + + if (readyReadPending) { + if (!inReadyRead) + emitPendingReadyRead(); + return true; + } + + return false; } /*! diff --git a/src/corelib/io/qwindowspipereader_p.h b/src/corelib/io/qwindowspipereader_p.h index c8a66d95119..44009877f2d 100644 --- a/src/corelib/io/qwindowspipereader_p.h +++ b/src/corelib/io/qwindowspipereader_p.h @@ -45,7 +45,6 @@ // We mean it. // -#include #include #include @@ -53,9 +52,6 @@ QT_BEGIN_NAMESPACE - -class QWinOverlappedIoNotifier; - class Q_CORE_EXPORT QWindowsPipeReader : public QObject { Q_OBJECT @@ -64,6 +60,7 @@ public: ~QWindowsPipeReader(); void setHandle(HANDLE hPipeReadEnd); + void startAsyncRead(); void stop(); void setMaxReadBufferSize(qint64 size) { readBufferMaxSize = size; } @@ -76,31 +73,42 @@ public: bool waitForReadyRead(int msecs); bool waitForPipeClosed(int msecs); - void startAsyncRead(); bool isReadOperationActive() const { return readSequenceStarted; } Q_SIGNALS: void winError(ulong, const QString &); void readyRead(); void pipeClosed(); - -private Q_SLOTS: - void notified(quint32 numberOfBytesRead, quint32 errorCode, OVERLAPPED *notifiedOverlapped); + void _q_queueReadyRead(QPrivateSignal); private: + static void CALLBACK readFileCompleted(DWORD errorCode, DWORD numberOfBytesTransfered, + OVERLAPPED *overlappedBase); + void notified(DWORD errorCode, DWORD numberOfBytesRead); DWORD checkPipeState(); + bool waitForNotification(int timeout); + void emitPendingReadyRead(); + + class Overlapped : public OVERLAPPED + { + Q_DISABLE_COPY(Overlapped) + public: + explicit Overlapped(QWindowsPipeReader *reader); + void clear(); + QWindowsPipeReader *pipeReader; + }; -private: HANDLE handle; - OVERLAPPED overlapped; - QWinOverlappedIoNotifier *dataReadNotifier; + Overlapped overlapped; qint64 readBufferMaxSize; QRingBuffer readBuffer; qint64 actualReadBufferSize; bool stopped; bool readSequenceStarted; + bool notifiedCalled; bool pipeBroken; - bool readyReadEmitted; + bool readyReadPending; + bool inReadyRead; }; QT_END_NAMESPACE From 0307c008bf71e1272385d0e7f7c8d2c5a1ba6526 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 7 Mar 2016 15:57:45 +0100 Subject: [PATCH 52/62] Make QWindowsPipeWriter thread-free. Re-work QWindowsPipeWriter to not use a thread anymore but the WriteFileEx API, similar to QWindowsPipeReader. This saves us a lot of thread synchronization code and enables us to directly write data without yet another buffering layer. Also, this fixes the dreaded deadlocks in the QWindowsPipeWriter destructor that could occur when the reading end was closed before the write was finished. Task-number: QTBUG-23378 Task-number: QTBUG-38185 Change-Id: If0ae96dcd756f716ddf6fa38016080095bf3bd4e Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess_win.cpp | 6 +- src/corelib/io/qwindowspipereader.cpp | 2 +- src/corelib/io/qwindowspipewriter.cpp | 258 ++++++++++++++---------- src/corelib/io/qwindowspipewriter_p.h | 72 +++---- src/network/socket/qlocalsocket_win.cpp | 1 - 5 files changed, 185 insertions(+), 154 deletions(-) diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 98ada82446c..e7cd9d9a174 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -666,10 +666,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) QIncrementalSleepTimer timer(msecs); forever { - // Check if we have any data pending: the pipe writer has - // bytes waiting to written, or it has written data since the - // last time we called stdinChannel.writer->waitForWrite(). - bool pendingDataInPipe = stdinChannel.writer && (stdinChannel.writer->bytesToWrite() || stdinChannel.writer->hadWritten()); + bool pendingDataInPipe = stdinChannel.writer && stdinChannel.writer->bytesToWrite(); // If we don't have pending data, and our write buffer is // empty, we fail. @@ -797,7 +794,6 @@ qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) stdinChannel.writer = new QWindowsPipeWriter(stdinChannel.pipe[1], q); QObjectPrivate::connect(stdinChannel.writer, &QWindowsPipeWriter::canWrite, this, &QProcessPrivate::_q_canWrite); - stdinChannel.writer->start(); } return stdinChannel.writer->write(data, maxlen); diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index ee7af8a08b0..735386ce160 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -65,7 +65,7 @@ QWindowsPipeReader::QWindowsPipeReader(QObject *parent) this, &QWindowsPipeReader::emitPendingReadyRead, Qt::QueuedConnection); } -static bool qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) +bool qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped) { typedef BOOL (WINAPI *PtrCancelIoEx)(HANDLE, LPOVERLAPPED); static PtrCancelIoEx ptrCancelIoEx = 0; diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index 5b11ba6112a..ff92ca763e7 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -32,141 +32,177 @@ ****************************************************************************/ #include "qwindowspipewriter_p.h" +#include "qiodevice_p.h" QT_BEGIN_NAMESPACE -#ifndef QT_NO_THREAD +extern bool qt_cancelIo(HANDLE handle, OVERLAPPED *overlapped); // from qwindowspipereader.cpp -QWindowsPipeWriter::QWindowsPipeWriter(HANDLE pipe, QObject * parent) - : QThread(parent), - writePipe(pipe), - quitNow(false), - hasWritten(false) + +QWindowsPipeWriter::Overlapped::Overlapped(QWindowsPipeWriter *pipeWriter) + : pipeWriter(pipeWriter) { } +void QWindowsPipeWriter::Overlapped::clear() +{ + ZeroMemory(this, sizeof(OVERLAPPED)); +} + + +QWindowsPipeWriter::QWindowsPipeWriter(HANDLE pipeWriteEnd, QObject *parent) + : QObject(parent), + handle(pipeWriteEnd), + overlapped(this), + numberOfBytesToWrite(0), + pendingBytesWrittenValue(0), + stopped(true), + writeSequenceStarted(false), + notifiedCalled(false), + bytesWrittenPending(false), + inBytesWritten(false) +{ + connect(this, &QWindowsPipeWriter::_q_queueBytesWritten, + this, &QWindowsPipeWriter::emitPendingBytesWrittenValue, Qt::QueuedConnection); +} + QWindowsPipeWriter::~QWindowsPipeWriter() { - lock.lock(); - quitNow = true; - waitCondition.wakeOne(); - lock.unlock(); - if (!wait(30000)) - terminate(); + stop(); } bool QWindowsPipeWriter::waitForWrite(int msecs) { - QMutexLocker locker(&lock); - bool hadWritten = hasWritten; - hasWritten = false; - if (hadWritten) - return true; - if (!waitCondition.wait(&lock, msecs)) + if (!writeSequenceStarted) return false; - hadWritten = hasWritten; - hasWritten = false; - return hadWritten; + + if (bytesWrittenPending) { + if (!inBytesWritten) + emitPendingBytesWrittenValue(); + return true; + } + + if (!waitForNotification(msecs)) + return false; + + if (bytesWrittenPending) { + if (!inBytesWritten) + emitPendingBytesWrittenValue(); + return true; + } + + return false; } -qint64 QWindowsPipeWriter::write(const char *ptr, qint64 maxlen) +qint64 QWindowsPipeWriter::bytesToWrite() const { - if (!isRunning()) - return -1; - - QMutexLocker locker(&lock); - data.append(ptr, maxlen); - waitCondition.wakeOne(); - return maxlen; + return numberOfBytesToWrite; } -class QPipeWriterOverlapped +void QWindowsPipeWriter::emitPendingBytesWrittenValue() { -public: - QPipeWriterOverlapped() - { - overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - } + if (bytesWrittenPending) { + bytesWrittenPending = false; + const qint64 bytes = pendingBytesWrittenValue; + pendingBytesWrittenValue = 0; - ~QPipeWriterOverlapped() - { - CloseHandle(overlapped.hEvent); - } - - void prepare() - { - const HANDLE hEvent = overlapped.hEvent; - ZeroMemory(&overlapped, sizeof overlapped); - overlapped.hEvent = hEvent; - } - - OVERLAPPED *operator&() - { - return &overlapped; - } - -private: - OVERLAPPED overlapped; -}; - -void QWindowsPipeWriter::run() -{ - QPipeWriterOverlapped overl; - forever { - lock.lock(); - while(data.isEmpty() && (!quitNow)) { - waitCondition.wakeOne(); - waitCondition.wait(&lock); - } - - if (quitNow) { - lock.unlock(); - quitNow = false; - break; - } - - QByteArray copy = data; - - lock.unlock(); - - const char *ptrData = copy.data(); - qint64 maxlen = copy.size(); - qint64 totalWritten = 0; - overl.prepare(); - while ((!quitNow) && totalWritten < maxlen) { - DWORD written = 0; - if (!WriteFile(writePipe, ptrData + totalWritten, - maxlen - totalWritten, &written, &overl)) { - const DWORD writeError = GetLastError(); - if (writeError == 0xE8/*NT_STATUS_INVALID_USER_BUFFER*/) { - // give the os a rest - msleep(100); - continue; - } - if (writeError != ERROR_IO_PENDING) { - qErrnoWarning(writeError, "QWindowsPipeWriter: async WriteFile failed."); - return; - } - if (!GetOverlappedResult(writePipe, &overl, &written, TRUE)) { - qErrnoWarning(GetLastError(), "QWindowsPipeWriter: GetOverlappedResult failed."); - return; - } - } - totalWritten += written; -#if defined QPIPEWRITER_DEBUG - qDebug("QWindowsPipeWriter::run() wrote %d %d/%d bytes", - written, int(totalWritten), int(maxlen)); -#endif - lock.lock(); - data.remove(0, written); - hasWritten = true; - lock.unlock(); - } - emit bytesWritten(totalWritten); + inBytesWritten = true; + emit bytesWritten(bytes); + inBytesWritten = false; emit canWrite(); } } -#endif //QT_NO_THREAD +void QWindowsPipeWriter::writeFileCompleted(DWORD errorCode, DWORD numberOfBytesTransfered, + OVERLAPPED *overlappedBase) +{ + Overlapped *overlapped = static_cast(overlappedBase); + overlapped->pipeWriter->notified(errorCode, numberOfBytesTransfered); +} + +/*! + \internal + Will be called whenever the write operation completes. + */ +void QWindowsPipeWriter::notified(DWORD errorCode, DWORD numberOfBytesWritten) +{ + notifiedCalled = true; + writeSequenceStarted = false; + numberOfBytesToWrite = 0; + + switch (errorCode) { + case ERROR_SUCCESS: + break; + case ERROR_OPERATION_ABORTED: + if (stopped) + break; + // fall through + default: + qErrnoWarning(errorCode, "QWindowsPipeWriter: asynchronous write failed."); + break; + } + + // After the writer was stopped, the only reason why this function can be called is the + // completion of a cancellation. No signals should be emitted, and no new write sequence should + // be started in this case. + if (stopped) + return; + + pendingBytesWrittenValue += qint64(numberOfBytesWritten); + if (!bytesWrittenPending) { + bytesWrittenPending = true; + emit _q_queueBytesWritten(QWindowsPipeWriter::QPrivateSignal()); + } +} + +bool QWindowsPipeWriter::waitForNotification(int timeout) +{ + QElapsedTimer t; + t.start(); + notifiedCalled = false; + int msecs = timeout; + while (SleepEx(msecs == -1 ? INFINITE : msecs, TRUE) == WAIT_IO_COMPLETION) { + if (notifiedCalled) + return true; + + // Some other I/O completion routine was called. Wait some more. + msecs = qt_subtract_from_timeout(timeout, t.elapsed()); + if (!msecs) + break; + } + return notifiedCalled; +} + +qint64 QWindowsPipeWriter::write(const char *ptr, qint64 maxlen) +{ + if (writeSequenceStarted) + return 0; + + overlapped.clear(); + numberOfBytesToWrite = maxlen; + stopped = false; + writeSequenceStarted = true; + if (!WriteFileEx(handle, ptr, maxlen, &overlapped, &writeFileCompleted)) { + writeSequenceStarted = false; + qErrnoWarning("QWindowsPipeWriter::write failed."); + } + + return maxlen; +} + +void QWindowsPipeWriter::stop() +{ + stopped = true; + if (writeSequenceStarted) { + if (!qt_cancelIo(handle, &overlapped)) { + const DWORD dwError = GetLastError(); + if (dwError != ERROR_NOT_FOUND) { + qErrnoWarning(dwError, "QWindowsPipeWriter: qt_cancelIo on handle %x failed.", + handle); + } + } + waitForNotification(-1); + } +} QT_END_NAMESPACE diff --git a/src/corelib/io/qwindowspipewriter_p.h b/src/corelib/io/qwindowspipewriter_p.h index 78d43e6efef..808d303262e 100644 --- a/src/corelib/io/qwindowspipewriter_p.h +++ b/src/corelib/io/qwindowspipewriter_p.h @@ -46,16 +46,11 @@ // #include -#include -#include -#include +#include #include QT_BEGIN_NAMESPACE - -#ifndef QT_NO_THREAD - #define SLEEPMIN 10 #define SLEEPMAX 500 @@ -104,45 +99,50 @@ private: int nextSleep; }; -class Q_CORE_EXPORT QWindowsPipeWriter : public QThread +class Q_CORE_EXPORT QWindowsPipeWriter : public QObject { Q_OBJECT +public: + explicit QWindowsPipeWriter(HANDLE pipeWriteEnd, QObject *parent = 0); + ~QWindowsPipeWriter(); + + qint64 write(const char *data, qint64 maxlen); + void stop(); + bool waitForWrite(int msecs); + qint64 bytesToWrite() const; Q_SIGNALS: void canWrite(); void bytesWritten(qint64 bytes); - -public: - explicit QWindowsPipeWriter(HANDLE writePipe, QObject * parent = 0); - ~QWindowsPipeWriter(); - - bool waitForWrite(int msecs); - qint64 write(const char *data, qint64 maxlen); - - qint64 bytesToWrite() const - { - QMutexLocker locker(&lock); - return data.size(); - } - - bool hadWritten() const - { - return hasWritten; - } - -protected: - void run(); + void _q_queueBytesWritten(QPrivateSignal); private: - QByteArray data; - QWaitCondition waitCondition; - mutable QMutex lock; - HANDLE writePipe; - volatile bool quitNow; - bool hasWritten; -}; + static void CALLBACK writeFileCompleted(DWORD errorCode, DWORD numberOfBytesTransfered, + OVERLAPPED *overlappedBase); + void notified(DWORD errorCode, DWORD numberOfBytesWritten); + bool waitForNotification(int timeout); + void emitPendingBytesWrittenValue(); -#endif //QT_NO_THREAD + class Overlapped : public OVERLAPPED + { + Q_DISABLE_COPY(Overlapped) + public: + explicit Overlapped(QWindowsPipeWriter *pipeWriter); + void clear(); + + QWindowsPipeWriter *pipeWriter; + }; + + HANDLE handle; + Overlapped overlapped; + qint64 numberOfBytesToWrite; + qint64 pendingBytesWrittenValue; + bool stopped; + bool writeSequenceStarted; + bool notifiedCalled; + bool bytesWrittenPending; + bool inBytesWritten; +}; QT_END_NAMESPACE diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index ae39f78fe8e..03ad2b6654b 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -214,7 +214,6 @@ qint64 QLocalSocket::writeData(const char *data, qint64 maxSize) d->pipeWriter = new QWindowsPipeWriter(d->handle, this); connect(d->pipeWriter, SIGNAL(canWrite()), this, SLOT(_q_canWrite())); connect(d->pipeWriter, SIGNAL(bytesWritten(qint64)), this, SIGNAL(bytesWritten(qint64))); - d->pipeWriter->start(); } return d->pipeWriter->write(data, maxSize); } From c6bf48dcbfd6b1048cddfd127b95dce27815709f Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 16 Mar 2016 18:06:11 -0700 Subject: [PATCH 53/62] QTypeInfoQuery: Add public inheritance specifiers Their absence offends PySide's shiboken. Change-Id: I137d17e280276f7ffadba6d16b7c230a6880cf05 Reviewed-by: Louai Al-Khanji Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Alex Blasche --- src/corelib/global/qtypeinfo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h index b42e5998fcd..f5fc311a229 100644 --- a/src/corelib/global/qtypeinfo.h +++ b/src/corelib/global/qtypeinfo.h @@ -111,14 +111,14 @@ public: */ // apply defaults for a generic QTypeInfo that didn't provide the new values template -struct QTypeInfoQuery : QTypeInfo +struct QTypeInfoQuery : public QTypeInfo { enum { isRelocatable = !QTypeInfo::isStatic }; }; // if QTypeInfo::isRelocatable exists, use it template -struct QTypeInfoQuery::isRelocatable || true>::Type> : QTypeInfo +struct QTypeInfoQuery::isRelocatable || true>::Type> : public QTypeInfo {}; /*! From 7c7ece94429d6e12e0543c275d26fd90501193ff Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 24 Feb 2016 17:19:37 -0800 Subject: [PATCH 54/62] QMacStyle: Ensure proper focus ring clipping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By rendering the focus ring directly on the backing NSView, we would ignore the painter's clipping information. It would also require creating a custom CGContext and attached NSGraphicsContext every time. The first step is to render the focus ring on a pixmap and then use the painter to render that pixamp. This ensures the clipping is done properly. The second step is to cache said pixmap and render it as a nine-patch image. Change-Id: I1df1baf7dc490023319f025a16306d4f04e5264c Task-number: QTBUG-50645 Reviewed-by: Morten Johan Sørvig --- src/widgets/styles/qmacstyle_mac.mm | 90 +++++++++++++++++++------- src/widgets/styles/qmacstyle_mac_p_p.h | 2 + 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 4f688f6f284..092cf4d5438 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1097,17 +1097,67 @@ static QAquaWidgetSize qt_aqua_guess_size(const QWidget *widg, QSize large, QSiz } #endif -static void qt_drawFocusRingOnPath(CGContextRef cg, NSBezierPath *focusRingPath) +void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius) const { - CGContextSaveGState(cg); - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:(CGContextRef)cg flipped:NO]]; - NSSetFocusRingStyle(NSFocusRingOnly); - [focusRingPath setClip]; // Clear clip path to avoid artifacts when rendering the cursor at zero pos - [focusRingPath fill]; - [NSGraphicsContext restoreGraphicsState]; - CGContextRestoreGState(cg); + qreal pixelRatio = p->device()->devicePixelRatioF(); + static const QString keyFormat = QLatin1String("$qt_focusring%1-%2-%3-%4"); + const QString &key = keyFormat.arg(hMargin).arg(vMargin).arg(radius).arg(pixelRatio); + QPixmap focusRingPixmap; + const qreal size = radius * 2 + 5; + + if (!QPixmapCache::find(key, focusRingPixmap)) { + focusRingPixmap = QPixmap((QSize(size, size) + 2 * QSize(hMargin, vMargin)) * pixelRatio); + focusRingPixmap.fill(Qt::transparent); + focusRingPixmap.setDevicePixelRatio(pixelRatio); + { + QMacAutoReleasePool pool; + NSBezierPath *focusRingPath; + if (radius > 0) + focusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(hMargin, vMargin, size, size) + xRadius:radius + yRadius:radius]; + else + focusRingPath = [NSBezierPath bezierPathWithRect:NSMakeRect(hMargin, vMargin, size, size)]; + [NSGraphicsContext saveGraphicsState]; + QMacCGContext gc(&focusRingPixmap); + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:(CGContextRef)gc + flipped:NO]]; + NSSetFocusRingStyle(NSFocusRingOnly); + [focusRingPath fill]; + [NSGraphicsContext restoreGraphicsState]; + } + QPixmapCache::insert(key, focusRingPixmap); + } + + // Add 2 for the actual ring tickness going inwards + const qreal hCornerSize = 2 + hMargin + radius; + const qreal vCornerSize = 2 + vMargin + radius; + const qreal shCornerSize = hCornerSize * pixelRatio; + const qreal svCornerSize = vCornerSize * pixelRatio; + // top-left corner + p->drawPixmap(QPointF(targetRect.left(), targetRect.top()), focusRingPixmap, + QRectF(0, 0, shCornerSize, svCornerSize)); + // top-right corner + p->drawPixmap(QPointF(targetRect.right() - hCornerSize + 1, targetRect.top()), focusRingPixmap, + QRectF(focusRingPixmap.width() - shCornerSize, 0, shCornerSize, svCornerSize)); + // bottom-left corner + p->drawPixmap(QPointF(targetRect.left(), targetRect.bottom() - vCornerSize + 1), focusRingPixmap, + QRectF(0, focusRingPixmap.height() - svCornerSize, shCornerSize, svCornerSize)); + // bottom-right corner + p->drawPixmap(QPointF(targetRect.right() - hCornerSize + 1, targetRect.bottom() - vCornerSize + 1), focusRingPixmap, + QRect(focusRingPixmap.width() - shCornerSize, focusRingPixmap.height() - svCornerSize, shCornerSize, svCornerSize)); + // top edge + p->drawPixmap(QRectF(targetRect.left() + hCornerSize, targetRect.top(), targetRect.width() - 2 * hCornerSize, vCornerSize), focusRingPixmap, + QRect(shCornerSize, 0, focusRingPixmap.width() - 2 * shCornerSize, svCornerSize)); + // bottom edge + p->drawPixmap(QRectF(targetRect.left() + hCornerSize, targetRect.bottom() - vCornerSize + 1, targetRect.width() - 2 * hCornerSize, vCornerSize), focusRingPixmap, + QRect(shCornerSize, focusRingPixmap.height() - svCornerSize, focusRingPixmap.width() - 2 * shCornerSize, svCornerSize)); + // left edge + p->drawPixmap(QRectF(targetRect.left(), targetRect.top() + vCornerSize, hCornerSize, targetRect.height() - 2 * vCornerSize), focusRingPixmap, + QRect(0, svCornerSize, shCornerSize, focusRingPixmap.width() - 2 * svCornerSize)); + // right edge + p->drawPixmap(QRectF(targetRect.right() - hCornerSize + 1, targetRect.top() + vCornerSize, hCornerSize, targetRect.height() - 2 * vCornerSize), focusRingPixmap, + QRect(focusRingPixmap.width() - shCornerSize, svCornerSize, shCornerSize, focusRingPixmap.width() - 2 * svCornerSize)); } QAquaWidgetSize QMacStylePrivate::aquaSizeConstrain(const QStyleOption *option, const QWidget *widg, @@ -3947,12 +3997,11 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } } - NSBezierPath *pushButtonFocusRingPath; - if (bdi.kind == kThemeBevelButton) - pushButtonFocusRingPath = [NSBezierPath bezierPathWithRect:NSRectFromCGRect(focusRect)]; - else - pushButtonFocusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSRectFromCGRect(focusRect) xRadius:4 yRadius:4]; - qt_drawFocusRingOnPath(cg, pushButtonFocusRingPath); + const qreal radius = bdi.kind == kThemeBevelButton ? 0 : 4; + const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, btn, w); + const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, btn, w); + const QRect focusTargetRect(focusRect.origin.x, focusRect.origin.y, focusRect.size.width, focusRect.size.height); + d->drawFocusRing(p, focusTargetRect.adjusted(-hMargin, -vMargin, hMargin, vMargin), hMargin, vMargin, radius); } if (hasMenu && (!usingYosemiteOrLater || bdi.kind == kThemeBevelButton)) { @@ -4391,12 +4440,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } break; case CE_FocusFrame: { - int xOff = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, w); - int yOff = proxy()->pixelMetric(PM_FocusFrameVMargin, opt, w); - NSRect rect = NSMakeRect(xOff+opt->rect.x(), yOff+opt->rect.y(), opt->rect.width() - 2 * xOff, - opt->rect.height() - 2 * yOff); - NSBezierPath *focusFramePath = [NSBezierPath bezierPathWithRect:rect]; - qt_drawFocusRingOnPath(cg, focusFramePath); + const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w); + const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w); + d->drawFocusRing(p, opt->rect, hMargin, vMargin); break; } case CE_MenuItem: case CE_MenuEmptyArea: diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index 33818568ec7..b2c76c2d760 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -209,6 +209,8 @@ public: void drawNSViewInRect(QCocoaWidget widget, NSView *view, const QRect &rect, QPainter *p, bool isQWidget = true, QCocoaDrawRectBlock drawRectBlock = nil) const; void resolveCurrentNSView(QWindow *window); + void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; + public: mutable QPointer pressedButton; mutable QPointer defaultButton; From 5655f3413151beb0abaeb847942f7bf29a114d7d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 18 Mar 2016 10:25:08 +0100 Subject: [PATCH 55/62] QWindows(XP)Style: fix build with Clang after includemocs run Clang doesn't like the unused member variable: qwindowsstyle_p.h:100:11: error: private field 'reserved' is not used [-Werror,-Wunused-private-field] Remove. It's private API. Triggered by Clang seeing all methods of the classes in one TU by the following includemocs commit. Change-Id: I84e92d63af573c090ef89c1d8ee19af30f90b171 Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/styles/qwindowsstyle_p.h | 1 - src/widgets/styles/qwindowsxpstyle_p.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/widgets/styles/qwindowsstyle_p.h b/src/widgets/styles/qwindowsstyle_p.h index da36d2af1ba..27242226523 100644 --- a/src/widgets/styles/qwindowsstyle_p.h +++ b/src/widgets/styles/qwindowsstyle_p.h @@ -97,7 +97,6 @@ protected: private: Q_DISABLE_COPY(QWindowsStyle) Q_DECLARE_PRIVATE(QWindowsStyle) - void *reserved; }; #endif // QT_NO_STYLE_WINDOWS diff --git a/src/widgets/styles/qwindowsxpstyle_p.h b/src/widgets/styles/qwindowsxpstyle_p.h index 1706a1abe64..4dcb75716e6 100644 --- a/src/widgets/styles/qwindowsxpstyle_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p.h @@ -93,7 +93,6 @@ private: Q_DISABLE_COPY(QWindowsXPStyle) Q_DECLARE_PRIVATE(QWindowsXPStyle) friend class QStyleFactory; - void *reserved; }; #endif // QT_NO_STYLE_WINDOWSXP From 55878865db64bd2fa1d7fa158c56fe460ef939eb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 18 Mar 2016 10:34:19 +0100 Subject: [PATCH 56/62] QToolBarExtension: remove unused member 'orientation' The orientation is implicitly stored by which icon is used. Found by Clang: qtoolbarextension_p.h:57:21: error: private field 'orientation' is not used [-Werror,-Wunused-private-field] Change-Id: I82f8b8009b48d41fd2beb95d6107e505f9d4e835 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qtoolbarextension_p.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/widgets/widgets/qtoolbarextension_p.h b/src/widgets/widgets/qtoolbarextension_p.h index f72dfbd5970..cbb4eb5c988 100644 --- a/src/widgets/widgets/qtoolbarextension_p.h +++ b/src/widgets/widgets/qtoolbarextension_p.h @@ -54,7 +54,6 @@ QT_BEGIN_NAMESPACE class Q_AUTOTEST_EXPORT QToolBarExtension : public QToolButton { Q_OBJECT - Qt::Orientation orientation; public: explicit QToolBarExtension(QWidget *parent); From e4cea305ed2ba3c9f580bf9d16c59a1048af0e8a Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 16 Mar 2016 08:35:22 +0100 Subject: [PATCH 57/62] xcb: Merge _NET_WM_STATE hints instead of overwriting This makes possible to set custom _NET_WM_STATE hints before showing the window. Change-Id: I86ad3863f7a8b3bb610a31b9af4b02c9d38eb111 Task-number: QTBUG-26978 Reviewed-by: Ilya Kotov Reviewed-by: Shawn Rutledge Reviewed-by: Uli Schlachter --- src/plugins/platforms/xcb/qxcbwindow.cpp | 32 ++++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index a0b1ddb4340..f4c455f2782 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -1091,21 +1091,37 @@ QXcbWindow::NetWmStates QXcbWindow::netWmStates() void QXcbWindow::setNetWmStates(NetWmStates states) { QVector atoms; - if (states & NetWmStateAbove) + + xcb_get_property_cookie_t get_cookie = + xcb_get_property_unchecked(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE), + XCB_ATOM_ATOM, 0, 1024); + + xcb_get_property_reply_t *reply = + xcb_get_property_reply(xcb_connection(), get_cookie, NULL); + + if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM && reply->value_len > 0) { + const xcb_atom_t *data = static_cast(xcb_get_property_value(reply)); + atoms.resize(reply->value_len); + memcpy((void *)&atoms.first(), (void *)data, reply->value_len * sizeof(xcb_atom_t)); + } + + free(reply); + + if (states & NetWmStateAbove && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_ABOVE))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_ABOVE)); - if (states & NetWmStateBelow) + if (states & NetWmStateBelow && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_BELOW))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_BELOW)); - if (states & NetWmStateFullScreen) + if (states & NetWmStateFullScreen && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_FULLSCREEN)); - if (states & NetWmStateMaximizedHorz) + if (states & NetWmStateMaximizedHorz && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_HORZ)); - if (states & NetWmStateMaximizedVert) + if (states & NetWmStateMaximizedVert && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_MAXIMIZED_VERT)); - if (states & NetWmStateModal) + if (states & NetWmStateModal && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_MODAL))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_MODAL)); - if (states & NetWmStateStaysOnTop) + if (states & NetWmStateStaysOnTop && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_STAYS_ON_TOP))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_STAYS_ON_TOP)); - if (states & NetWmStateDemandsAttention) + if (states & NetWmStateDemandsAttention && !atoms.contains(atom(QXcbAtom::_NET_WM_STATE_DEMANDS_ATTENTION))) atoms.push_back(atom(QXcbAtom::_NET_WM_STATE_DEMANDS_ATTENTION)); if (atoms.isEmpty()) { From 0e6ad275498dc8cc60a7d163bac9ed0add8e48d5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 16 Mar 2016 00:47:08 +0100 Subject: [PATCH 58/62] QtWidgets: includemocs A very simple way to save ~3KiB in test size and 440b in data size on GCC 5.3 Linux AMD64 release builds. Change-Id: I6619148cc497116b9772a00e1bc30d573a2b2534 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/dialogs/qerrormessage.cpp | 2 ++ src/widgets/dialogs/qfileinfogatherer.cpp | 2 ++ src/widgets/dialogs/qsidebar.cpp | 2 ++ src/widgets/effects/qgraphicseffect.cpp | 3 +++ src/widgets/effects/qpixmapfilter.cpp | 2 ++ src/widgets/graphicsview/qgraphicsanchorlayout.cpp | 3 +++ src/widgets/graphicsview/qgraphicsitemanimation.cpp | 2 ++ src/widgets/graphicsview/qgraphicsscenelinearindex.cpp | 1 + src/widgets/graphicsview/qgraphicswidget.cpp | 2 ++ src/widgets/itemviews/qcolumnviewgrip.cpp | 2 ++ src/widgets/itemviews/qitemeditorfactory.cpp | 2 ++ src/widgets/itemviews/qlistview.cpp | 2 ++ src/widgets/itemviews/qlistwidget.cpp | 1 + src/widgets/itemviews/qtablewidget.cpp | 1 + src/widgets/itemviews/qtreewidget.cpp | 1 + src/widgets/kernel/qboxlayout.cpp | 2 ++ src/widgets/kernel/qdesktopwidget.cpp | 1 + src/widgets/kernel/qformlayout.cpp | 2 ++ src/widgets/kernel/qgridlayout.cpp | 2 ++ src/widgets/kernel/qlayout.cpp | 2 ++ src/widgets/kernel/qopenglwidget.cpp | 2 ++ src/widgets/kernel/qshortcut.cpp | 2 ++ src/widgets/kernel/qsizepolicy.cpp | 2 ++ src/widgets/kernel/qstackedlayout.cpp | 2 ++ src/widgets/kernel/qwidgetbackingstore.cpp | 2 ++ src/widgets/kernel/qwidgetwindow.cpp | 2 ++ src/widgets/kernel/qwindowcontainer.cpp | 2 ++ src/widgets/statemachine/qbasickeyeventtransition.cpp | 2 ++ src/widgets/statemachine/qbasicmouseeventtransition.cpp | 2 ++ src/widgets/statemachine/qkeyeventtransition.cpp | 2 ++ src/widgets/statemachine/qmouseeventtransition.cpp | 2 ++ src/widgets/styles/qfusionstyle.cpp | 2 ++ src/widgets/styles/qgtkstyle_p.cpp | 3 +++ src/widgets/styles/qproxystyle.cpp | 2 ++ src/widgets/styles/qstyle.cpp | 2 ++ src/widgets/styles/qstyleanimation.cpp | 2 ++ src/widgets/styles/qstyleplugin.cpp | 2 ++ src/widgets/styles/qwindowsstyle.cpp | 2 ++ src/widgets/util/qcompleter.cpp | 2 ++ src/widgets/util/qflickgesture.cpp | 2 ++ src/widgets/util/qscroller.cpp | 3 +++ src/widgets/util/qsystemtrayicon.cpp | 1 + src/widgets/util/qundogroup.cpp | 2 ++ src/widgets/util/qundostack.cpp | 3 +++ src/widgets/util/qundoview.cpp | 1 + src/widgets/widgets/qabstractbutton.cpp | 2 ++ src/widgets/widgets/qabstractslider.cpp | 2 ++ src/widgets/widgets/qbuttongroup.cpp | 1 + src/widgets/widgets/qcheckbox.cpp | 2 ++ src/widgets/widgets/qcombobox.cpp | 1 + src/widgets/widgets/qcommandlinkbutton.cpp | 1 + src/widgets/widgets/qdatetimeedit.cpp | 1 + src/widgets/widgets/qdial.cpp | 2 ++ src/widgets/widgets/qdockwidget.cpp | 1 + src/widgets/widgets/qfocusframe.cpp | 2 ++ src/widgets/widgets/qframe.cpp | 2 ++ src/widgets/widgets/qkeysequenceedit.cpp | 2 ++ src/widgets/widgets/qlcdnumber.cpp | 2 ++ src/widgets/widgets/qlineedit_p.cpp | 2 ++ src/widgets/widgets/qmainwindow.cpp | 2 ++ src/widgets/widgets/qmainwindowlayout.cpp | 2 ++ src/widgets/widgets/qprogressbar.cpp | 2 ++ src/widgets/widgets/qradiobutton.cpp | 2 ++ src/widgets/widgets/qrubberband.cpp | 2 ++ src/widgets/widgets/qscrollarea.cpp | 2 ++ src/widgets/widgets/qscrollbar.cpp | 2 ++ src/widgets/widgets/qslider.cpp | 2 ++ src/widgets/widgets/qspinbox.cpp | 2 ++ src/widgets/widgets/qsplashscreen.cpp | 2 ++ src/widgets/widgets/qsplitter.cpp | 2 ++ src/widgets/widgets/qstackedwidget.cpp | 2 ++ src/widgets/widgets/qstatusbar.cpp | 2 ++ src/widgets/widgets/qtabbar.cpp | 2 +- src/widgets/widgets/qtoolbarextension.cpp | 2 ++ src/widgets/widgets/qtoolbarlayout.cpp | 2 ++ src/widgets/widgets/qtoolbarseparator.cpp | 2 ++ src/widgets/widgets/qwidgetanimator.cpp | 2 ++ src/widgets/widgets/qwidgetlinecontrol.cpp | 2 ++ src/widgets/widgets/qwidgetresizehandler.cpp | 2 ++ src/widgets/widgets/widgets.pri | 1 + 80 files changed, 151 insertions(+), 1 deletion(-) diff --git a/src/widgets/dialogs/qerrormessage.cpp b/src/widgets/dialogs/qerrormessage.cpp index 855bae3c9fd..efa344d04c9 100644 --- a/src/widgets/dialogs/qerrormessage.cpp +++ b/src/widgets/dialogs/qerrormessage.cpp @@ -396,4 +396,6 @@ void QErrorMessagePrivate::retranslateStrings() QT_END_NAMESPACE +#include "moc_qerrormessage.cpp" + #endif // QT_NO_ERRORMESSAGE diff --git a/src/widgets/dialogs/qfileinfogatherer.cpp b/src/widgets/dialogs/qfileinfogatherer.cpp index 92d6b8f3bed..be96b4ce685 100644 --- a/src/widgets/dialogs/qfileinfogatherer.cpp +++ b/src/widgets/dialogs/qfileinfogatherer.cpp @@ -339,3 +339,5 @@ void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bo #endif // QT_NO_FILESYSTEMMODEL QT_END_NAMESPACE + +#include "moc_qfileinfogatherer_p.cpp" diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 645f418c4e5..bb61135cbc6 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -509,4 +509,6 @@ bool QSidebar::event(QEvent * event) QT_END_NAMESPACE +#include "moc_qsidebar_p.cpp" + #endif diff --git a/src/widgets/effects/qgraphicseffect.cpp b/src/widgets/effects/qgraphicseffect.cpp index 5a97be3d964..e845a33e0bf 100644 --- a/src/widgets/effects/qgraphicseffect.cpp +++ b/src/widgets/effects/qgraphicseffect.cpp @@ -1229,4 +1229,7 @@ void QGraphicsOpacityEffect::draw(QPainter *painter) QT_END_NAMESPACE +#include "moc_qgraphicseffect.cpp" +#include "moc_qgraphicseffect_p.cpp" + #endif //QT_NO_GRAPHICSEFFECT diff --git a/src/widgets/effects/qpixmapfilter.cpp b/src/widgets/effects/qpixmapfilter.cpp index b21726400f8..d091502b5d8 100644 --- a/src/widgets/effects/qpixmapfilter.cpp +++ b/src/widgets/effects/qpixmapfilter.cpp @@ -1330,4 +1330,6 @@ void QPixmapDropShadowFilter::draw(QPainter *p, QT_END_NAMESPACE +#include "moc_qpixmapfilter_p.cpp" + #endif //QT_NO_GRAPHICSEFFECT diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp index 3e29d29c14c..c11aa92053e 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout.cpp @@ -523,4 +523,7 @@ QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, const QSizeF &constra } QT_END_NAMESPACE + +#include "moc_qgraphicsanchorlayout.cpp" + #endif //QT_NO_GRAPHICSVIEW diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index 585539de94f..ec48beec6cf 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -588,4 +588,6 @@ void QGraphicsItemAnimation::afterAnimationStep(qreal step) QT_END_NAMESPACE +#include "moc_qgraphicsitemanimation.cpp" + #endif // QT_NO_GRAPHICSVIEW diff --git a/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp b/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp index b0cb2fe3747..32bb8d17ace 100644 --- a/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp +++ b/src/widgets/graphicsview/qgraphicsscenelinearindex.cpp @@ -85,3 +85,4 @@ Add the \a item from the index. */ +#include "moc_qgraphicsscenelinearindex_p.cpp" diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp index cd651e28970..2700605a712 100644 --- a/src/widgets/graphicsview/qgraphicswidget.cpp +++ b/src/widgets/graphicsview/qgraphicswidget.cpp @@ -2421,4 +2421,6 @@ void QGraphicsWidget::dumpFocusChain() QT_END_NAMESPACE +#include "moc_qgraphicswidget.cpp" + #endif //QT_NO_GRAPHICSVIEW diff --git a/src/widgets/itemviews/qcolumnviewgrip.cpp b/src/widgets/itemviews/qcolumnviewgrip.cpp index a1630a14a22..7810e707e8f 100644 --- a/src/widgets/itemviews/qcolumnviewgrip.cpp +++ b/src/widgets/itemviews/qcolumnviewgrip.cpp @@ -183,4 +183,6 @@ originalXLocation(-1) QT_END_NAMESPACE +#include "moc_qcolumnviewgrip_p.cpp" + #endif // QT_NO_QCOLUMNVIEW diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index e966c83fe7b..70295d56f5b 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -606,4 +606,6 @@ QT_END_NAMESPACE #include "qitemeditorfactory.moc" #endif +#include "moc_qitemeditorfactory_p.cpp" + #endif // QT_NO_ITEMVIEWS diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 18ea19c8b9d..7cba60cd813 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -3291,4 +3291,6 @@ QSize QListView::viewportSizeHint() const QT_END_NAMESPACE +#include "moc_qlistview.cpp" + #endif // QT_NO_LISTVIEW diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index d4d22c8befd..eeb50c57413 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -1948,5 +1948,6 @@ bool QListWidget::event(QEvent *e) QT_END_NAMESPACE #include "moc_qlistwidget.cpp" +#include "moc_qlistwidget_p.cpp" #endif // QT_NO_LISTWIDGET diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index cd38f4b282b..3ec6923b7f2 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -2716,5 +2716,6 @@ void QTableWidget::dropEvent(QDropEvent *event) { QT_END_NAMESPACE #include "moc_qtablewidget.cpp" +#include "moc_qtablewidget_p.cpp" #endif // QT_NO_TABLEWIDGET diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 676893ebf01..f33dd6af17c 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -3449,5 +3449,6 @@ bool QTreeWidget::event(QEvent *e) QT_END_NAMESPACE #include "moc_qtreewidget.cpp" +#include "moc_qtreewidget_p.cpp" #endif // QT_NO_TREEWIDGET diff --git a/src/widgets/kernel/qboxlayout.cpp b/src/widgets/kernel/qboxlayout.cpp index 17eb8d98c43..7bde1e4eb27 100644 --- a/src/widgets/kernel/qboxlayout.cpp +++ b/src/widgets/kernel/qboxlayout.cpp @@ -1348,3 +1348,5 @@ QVBoxLayout::~QVBoxLayout() } QT_END_NAMESPACE + +#include "moc_qboxlayout.cpp" diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index 2ddd025239c..d1b37bc03aa 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -268,3 +268,4 @@ void QDesktopWidget::resizeEvent(QResizeEvent *) QT_END_NAMESPACE #include "moc_qdesktopwidget.cpp" +#include "moc_qdesktopwidget_p.cpp" diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp index a7f9021c427..124f6b301c3 100644 --- a/src/widgets/kernel/qformlayout.cpp +++ b/src/widgets/kernel/qformlayout.cpp @@ -2108,3 +2108,5 @@ void QFormLayout::dump() const #endif QT_END_NAMESPACE + +#include "moc_qformlayout.cpp" diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp index 85898ae86c7..eca865ce171 100644 --- a/src/widgets/kernel/qgridlayout.cpp +++ b/src/widgets/kernel/qgridlayout.cpp @@ -1686,3 +1686,5 @@ void QGridLayout::invalidate() } QT_END_NAMESPACE + +#include "moc_qgridlayout.cpp" diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index e74f17b6f7a..8631149f3df 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -1471,3 +1471,5 @@ QSize QLayout::closestAcceptableSize(const QWidget *widget, const QSize &size) } QT_END_NAMESPACE + +#include "moc_qlayout.cpp" diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index a80db3f60b3..e5c5b1dbfd7 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -1343,3 +1343,5 @@ bool QOpenGLWidget::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qopenglwidget.cpp" diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index ce728e03301..2e7bc27536c 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -652,3 +652,5 @@ bool QShortcut::event(QEvent *e) #endif // QT_NO_SHORTCUT QT_END_NAMESPACE + +#include "moc_qshortcut.cpp" diff --git a/src/widgets/kernel/qsizepolicy.cpp b/src/widgets/kernel/qsizepolicy.cpp index 3c28f5ccf73..26d1733d26f 100644 --- a/src/widgets/kernel/qsizepolicy.cpp +++ b/src/widgets/kernel/qsizepolicy.cpp @@ -506,3 +506,5 @@ QDebug operator<<(QDebug dbg, const QSizePolicy &p) #endif QT_END_NAMESPACE + +#include "moc_qsizepolicy.cpp" diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp index 957b6f09b56..029c2bcec25 100644 --- a/src/widgets/kernel/qstackedlayout.cpp +++ b/src/widgets/kernel/qstackedlayout.cpp @@ -590,3 +590,5 @@ void QStackedLayout::setStackingMode(StackingMode stackingMode) } QT_END_NAMESPACE + +#include "moc_qstackedlayout.cpp" diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index bfa1d69fa82..8269bd13f6c 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -1625,3 +1625,5 @@ void QWidgetPrivate::repaint_sys(const QRegion &rgn) QT_END_NAMESPACE + +#include "moc_qwidgetbackingstore_p.cpp" diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 15c28d09130..01832a4f2b1 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -997,3 +997,5 @@ void QWidgetWindow::updateObjectName() } QT_END_NAMESPACE + +#include "moc_qwidgetwindow_p.cpp" diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp index e8c4a763ee7..ea73bcd2a6d 100644 --- a/src/widgets/kernel/qwindowcontainer.cpp +++ b/src/widgets/kernel/qwindowcontainer.cpp @@ -397,3 +397,5 @@ void QWindowContainer::parentWasLowered(QWidget *parent) } QT_END_NAMESPACE + +#include "moc_qwindowcontainer_p.cpp" diff --git a/src/widgets/statemachine/qbasickeyeventtransition.cpp b/src/widgets/statemachine/qbasickeyeventtransition.cpp index b83d4bf7e97..ef094172abb 100644 --- a/src/widgets/statemachine/qbasickeyeventtransition.cpp +++ b/src/widgets/statemachine/qbasickeyeventtransition.cpp @@ -197,4 +197,6 @@ void QBasicKeyEventTransition::onTransition(QEvent *) QT_END_NAMESPACE +#include "moc_qbasickeyeventtransition_p.cpp" + #endif //QT_NO_STATEMACHINE diff --git a/src/widgets/statemachine/qbasicmouseeventtransition.cpp b/src/widgets/statemachine/qbasicmouseeventtransition.cpp index 2a9b0a198c2..12faf47b7fa 100644 --- a/src/widgets/statemachine/qbasicmouseeventtransition.cpp +++ b/src/widgets/statemachine/qbasicmouseeventtransition.cpp @@ -202,4 +202,6 @@ void QBasicMouseEventTransition::onTransition(QEvent *) QT_END_NAMESPACE +#include "moc_qbasicmouseeventtransition_p.cpp" + #endif //QT_NO_STATEMACHINE diff --git a/src/widgets/statemachine/qkeyeventtransition.cpp b/src/widgets/statemachine/qkeyeventtransition.cpp index 67af85dd27a..5b7a60981c9 100644 --- a/src/widgets/statemachine/qkeyeventtransition.cpp +++ b/src/widgets/statemachine/qkeyeventtransition.cpp @@ -168,4 +168,6 @@ void QKeyEventTransition::onTransition(QEvent *event) QT_END_NAMESPACE +#include "moc_qkeyeventtransition.cpp" + #endif //QT_NO_STATEMACHINE diff --git a/src/widgets/statemachine/qmouseeventtransition.cpp b/src/widgets/statemachine/qmouseeventtransition.cpp index bf46e4b279b..e587bfea2f6 100644 --- a/src/widgets/statemachine/qmouseeventtransition.cpp +++ b/src/widgets/statemachine/qmouseeventtransition.cpp @@ -196,4 +196,6 @@ void QMouseEventTransition::onTransition(QEvent *event) QT_END_NAMESPACE +#include "moc_qmouseeventtransition.cpp" + #endif //QT_NO_STATEMACHINE diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 2fc52e9a324..e4302247f53 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3739,4 +3739,6 @@ QPixmap QFusionStyle::standardPixmap(StandardPixmap standardPixmap, const QStyle QT_END_NAMESPACE +#include "moc_qfusionstyle_p.cpp" + #endif // QT_NO_STYLE_FUSION || QT_PLUGIN diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp index 00682c1c0f5..a0fd8bf7db0 100644 --- a/src/widgets/styles/qgtkstyle_p.cpp +++ b/src/widgets/styles/qgtkstyle_p.cpp @@ -888,4 +888,7 @@ uint qHash(const QHashableLatin1Literal &key) QT_END_NAMESPACE +#include "moc_qgtkstyle_p.cpp" +#include "moc_qgtkstyle_p_p.cpp" + #endif // !defined(QT_NO_STYLE_GTK) diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index 61f836b23c4..2829d2db799 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -423,4 +423,6 @@ int QProxyStyle::layoutSpacing(QSizePolicy::ControlType control1, QT_END_NAMESPACE +#include "moc_qproxystyle.cpp" + #endif // QT_NO_STYLE_PROXY diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 02c420e55c6..4a601ba8718 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -2407,3 +2407,5 @@ void QStyle::setProxy(QStyle *style) } QT_END_NAMESPACE + +#include "moc_qstyle.cpp" diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 78d0297be2e..922a1e5ffbd 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -359,4 +359,6 @@ void QScrollbarStyleAnimation::updateCurrentTime(int time) QT_END_NAMESPACE +#include "moc_qstyleanimation_p.cpp" + #endif //QT_NO_ANIMATION diff --git a/src/widgets/styles/qstyleplugin.cpp b/src/widgets/styles/qstyleplugin.cpp index 2be37bd65aa..e1b28c14910 100644 --- a/src/widgets/styles/qstyleplugin.cpp +++ b/src/widgets/styles/qstyleplugin.cpp @@ -99,3 +99,5 @@ QStylePlugin::~QStylePlugin() } QT_END_NAMESPACE + +#include "moc_qstyleplugin.cpp" diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 01b82424c81..5d02bc17aec 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -2397,4 +2397,6 @@ QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOptio QT_END_NAMESPACE +#include "moc_qwindowsstyle_p.cpp" + #endif // QT_NO_STYLE_WINDOWS diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 4382abaf50a..55bb51d0a3c 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -1880,4 +1880,6 @@ QT_END_NAMESPACE #include "moc_qcompleter.cpp" +#include "moc_qcompleter_p.cpp" + #endif // QT_NO_COMPLETER diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp index c7e0861a0f2..64009ca4b46 100644 --- a/src/widgets/util/qflickgesture.cpp +++ b/src/widgets/util/qflickgesture.cpp @@ -704,4 +704,6 @@ void QFlickGestureRecognizer::reset(QGesture *state) QT_END_NAMESPACE +#include "moc_qflickgesture_p.cpp" + #endif // QT_NO_GESTURES diff --git a/src/widgets/util/qscroller.cpp b/src/widgets/util/qscroller.cpp index 38b104f9e99..92a9dd72020 100644 --- a/src/widgets/util/qscroller.cpp +++ b/src/widgets/util/qscroller.cpp @@ -2048,3 +2048,6 @@ qreal QScrollerPrivate::nextSnapPos(qreal p, int dir, Qt::Orientation orientatio */ QT_END_NAMESPACE + +#include "moc_qscroller.cpp" +#include "moc_qscroller_p.cpp" diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index ebb29211a4c..5589cda50ab 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -766,3 +766,4 @@ QT_END_NAMESPACE #endif // QT_NO_SYSTEMTRAYICON #include "moc_qsystemtrayicon.cpp" +#include "moc_qsystemtrayicon_p.cpp" diff --git a/src/widgets/util/qundogroup.cpp b/src/widgets/util/qundogroup.cpp index f4801b74707..91baec10402 100644 --- a/src/widgets/util/qundogroup.cpp +++ b/src/widgets/util/qundogroup.cpp @@ -495,4 +495,6 @@ QAction *QUndoGroup::createRedoAction(QObject *parent, const QString &prefix) co QT_END_NAMESPACE +#include "moc_qundogroup.cpp" + #endif // QT_NO_UNDOGROUP diff --git a/src/widgets/util/qundostack.cpp b/src/widgets/util/qundostack.cpp index 0272870537b..5163783b0ba 100644 --- a/src/widgets/util/qundostack.cpp +++ b/src/widgets/util/qundostack.cpp @@ -1168,4 +1168,7 @@ bool QUndoStack::isActive() const QT_END_NAMESPACE +#include "moc_qundostack.cpp" +#include "moc_qundostack_p.cpp" + #endif // QT_NO_UNDOSTACK diff --git a/src/widgets/util/qundoview.cpp b/src/widgets/util/qundoview.cpp index cd29b46dc4f..1f74ba8204a 100644 --- a/src/widgets/util/qundoview.cpp +++ b/src/widgets/util/qundoview.cpp @@ -466,5 +466,6 @@ QIcon QUndoView::cleanIcon() const QT_END_NAMESPACE #include "qundoview.moc" +#include "moc_qundoview.cpp" #endif // QT_NO_UNDOVIEW diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index a1707b9cab1..fe09b0087c9 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -1413,3 +1413,5 @@ void QAbstractButton::setIconSize(const QSize &size) QT_END_NAMESPACE + +#include "moc_qabstractbutton.cpp" diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp index 8d8c3aa4bca..283cac80daa 100644 --- a/src/widgets/widgets/qabstractslider.cpp +++ b/src/widgets/widgets/qabstractslider.cpp @@ -937,3 +937,5 @@ bool QAbstractSlider::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qabstractslider.cpp" diff --git a/src/widgets/widgets/qbuttongroup.cpp b/src/widgets/widgets/qbuttongroup.cpp index 73f0b199527..5a8dc5f3efd 100644 --- a/src/widgets/widgets/qbuttongroup.cpp +++ b/src/widgets/widgets/qbuttongroup.cpp @@ -261,3 +261,4 @@ \sa setId() */ +#include "moc_qbuttongroup.cpp" diff --git a/src/widgets/widgets/qcheckbox.cpp b/src/widgets/widgets/qcheckbox.cpp index ef2405c72d5..9775f46bd10 100644 --- a/src/widgets/widgets/qcheckbox.cpp +++ b/src/widgets/widgets/qcheckbox.cpp @@ -387,3 +387,5 @@ bool QCheckBox::event(QEvent *e) QT_END_NAMESPACE + +#include "moc_qcheckbox.cpp" diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index ce30ca18c33..2abcd4d3c26 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -3429,5 +3429,6 @@ void QComboBox::setModelColumn(int visibleColumn) QT_END_NAMESPACE #include "moc_qcombobox.cpp" +#include "moc_qcombobox_p.cpp" #endif // QT_NO_COMBOBOX diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp index 91a4118c3cc..619172d3793 100644 --- a/src/widgets/widgets/qcommandlinkbutton.cpp +++ b/src/widgets/widgets/qcommandlinkbutton.cpp @@ -407,3 +407,4 @@ QString QCommandLinkButton::description() const QT_END_NAMESPACE +#include "moc_qcommandlinkbutton.cpp" diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 7ed4564654b..8ee32a2a8be 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -2686,5 +2686,6 @@ void QCalendarPopup::hideEvent(QHideEvent *) QT_END_NAMESPACE #include "moc_qdatetimeedit.cpp" +#include "moc_qdatetimeedit_p.cpp" #endif // QT_NO_DATETIMEEDIT diff --git a/src/widgets/widgets/qdial.cpp b/src/widgets/widgets/qdial.cpp index 3f081e3a83a..f6a3d1d96b9 100644 --- a/src/widgets/widgets/qdial.cpp +++ b/src/widgets/widgets/qdial.cpp @@ -481,4 +481,6 @@ bool QDial::event(QEvent *e) QT_END_NAMESPACE +#include "moc_qdial.cpp" + #endif // QT_NO_DIAL diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index da6c3431ff4..6e6812aa1e9 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1676,5 +1676,6 @@ QT_END_NAMESPACE #include "qdockwidget.moc" #include "moc_qdockwidget.cpp" +#include "moc_qdockwidget_p.cpp" #endif // QT_NO_DOCKWIDGET diff --git a/src/widgets/widgets/qfocusframe.cpp b/src/widgets/widgets/qfocusframe.cpp index bf8cb30ef77..99322821f49 100644 --- a/src/widgets/widgets/qfocusframe.cpp +++ b/src/widgets/widgets/qfocusframe.cpp @@ -333,3 +333,5 @@ bool QFocusFrame::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qfocusframe.cpp" diff --git a/src/widgets/widgets/qframe.cpp b/src/widgets/widgets/qframe.cpp index 755b03a4ca8..a2fdfc0c86a 100644 --- a/src/widgets/widgets/qframe.cpp +++ b/src/widgets/widgets/qframe.cpp @@ -549,3 +549,5 @@ bool QFrame::event(QEvent *e) } QT_END_NAMESPACE + +#include "moc_qframe.cpp" diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp index 35c7c187b7d..2e418d0ea43 100644 --- a/src/widgets/widgets/qkeysequenceedit.cpp +++ b/src/widgets/widgets/qkeysequenceedit.cpp @@ -318,3 +318,5 @@ void QKeySequenceEdit::timerEvent(QTimerEvent *e) #endif // QT_NO_KEYSEQUENCEEDIT QT_END_NAMESPACE + +#include "moc_qkeysequenceedit.cpp" diff --git a/src/widgets/widgets/qlcdnumber.cpp b/src/widgets/widgets/qlcdnumber.cpp index d17e3e24703..17a6b2c9415 100644 --- a/src/widgets/widgets/qlcdnumber.cpp +++ b/src/widgets/widgets/qlcdnumber.cpp @@ -1216,4 +1216,6 @@ bool QLCDNumber::event(QEvent *e) QT_END_NAMESPACE +#include "moc_qlcdnumber.cpp" + #endif // QT_NO_LCDNUMBER diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 599ebce0ab3..ff4d0fec47c 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -520,4 +520,6 @@ void QLineEditPrivate::removeAction(QAction *action) QT_END_NAMESPACE +#include "moc_qlineedit_p.cpp" + #endif diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index ff4bb3cc98c..1698ca15195 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -1746,4 +1746,6 @@ QMenu *QMainWindow::createPopupMenu() QT_END_NAMESPACE +#include "moc_qmainwindow.cpp" + #endif // QT_NO_MAINWINDOW diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 1bb8496505f..8dc12d853e8 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2590,4 +2590,6 @@ void QMainWindowLayout::timerEvent(QTimerEvent *e) QT_END_NAMESPACE +#include "moc_qmainwindowlayout_p.cpp" + #endif // QT_NO_MAINWINDOW diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index 5b06e75abee..adb4d0369b3 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -623,4 +623,6 @@ QString QProgressBar::format() const QT_END_NAMESPACE +#include "moc_qprogressbar.cpp" + #endif // QT_NO_PROGRESSBAR diff --git a/src/widgets/widgets/qradiobutton.cpp b/src/widgets/widgets/qradiobutton.cpp index 150813da10f..a71644bc2cf 100644 --- a/src/widgets/widgets/qradiobutton.cpp +++ b/src/widgets/widgets/qradiobutton.cpp @@ -266,3 +266,5 @@ bool QRadioButton::event(QEvent *e) QT_END_NAMESPACE + +#include "moc_qradiobutton.cpp" diff --git a/src/widgets/widgets/qrubberband.cpp b/src/widgets/widgets/qrubberband.cpp index 3315e2703ab..60082a89309 100644 --- a/src/widgets/widgets/qrubberband.cpp +++ b/src/widgets/widgets/qrubberband.cpp @@ -327,4 +327,6 @@ bool QRubberBand::event(QEvent *e) QT_END_NAMESPACE +#include "moc_qrubberband.cpp" + #endif // QT_NO_RUBBERBAND diff --git a/src/widgets/widgets/qscrollarea.cpp b/src/widgets/widgets/qscrollarea.cpp index 90605358ee7..c1b0db1d889 100644 --- a/src/widgets/widgets/qscrollarea.cpp +++ b/src/widgets/widgets/qscrollarea.cpp @@ -532,4 +532,6 @@ Qt::Alignment QScrollArea::alignment() const QT_END_NAMESPACE +#include "moc_qscrollarea.cpp" + #endif // QT_NO_SCROLLAREA diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp index 46f903fa1e6..8ae299cdf48 100644 --- a/src/widgets/widgets/qscrollbar.cpp +++ b/src/widgets/widgets/qscrollbar.cpp @@ -738,4 +738,6 @@ Q_WIDGETS_EXPORT QStyleOptionSlider qt_qscrollbarStyleOption(QScrollBar *scrollb QT_END_NAMESPACE +#include "moc_qscrollbar.cpp" + #endif // QT_NO_SCROLLBAR diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp index dc5ec006506..7f34f8f9e05 100644 --- a/src/widgets/widgets/qslider.cpp +++ b/src/widgets/widgets/qslider.cpp @@ -553,3 +553,5 @@ Q_WIDGETS_EXPORT QStyleOptionSlider qt_qsliderStyleOption(QSlider *slider) #endif QT_END_NAMESPACE + +#include "moc_qslider.cpp" diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 457e2e1e4cc..262efc62e26 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -1322,4 +1322,6 @@ bool QSpinBox::event(QEvent *event) QT_END_NAMESPACE +#include "moc_qspinbox.cpp" + #endif // QT_NO_SPINBOX diff --git a/src/widgets/widgets/qsplashscreen.cpp b/src/widgets/widgets/qsplashscreen.cpp index b8c70f2f0f2..9b6671ef6bd 100644 --- a/src/widgets/widgets/qsplashscreen.cpp +++ b/src/widgets/widgets/qsplashscreen.cpp @@ -352,4 +352,6 @@ bool QSplashScreen::event(QEvent *e) QT_END_NAMESPACE +#include "moc_qsplashscreen.cpp" + #endif //QT_NO_SPLASHSCREEN diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index c2081c15f84..20b6a029cd6 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1733,4 +1733,6 @@ QTextStream& operator>>(QTextStream& ts, QSplitter& splitter) QT_END_NAMESPACE +#include "moc_qsplitter.cpp" + #endif // QT_NO_SPLITTER diff --git a/src/widgets/widgets/qstackedwidget.cpp b/src/widgets/widgets/qstackedwidget.cpp index 19a2edf0f27..dd9a95c5562 100644 --- a/src/widgets/widgets/qstackedwidget.cpp +++ b/src/widgets/widgets/qstackedwidget.cpp @@ -287,4 +287,6 @@ bool QStackedWidget::event(QEvent *e) QT_END_NAMESPACE +#include "moc_qstackedwidget.cpp" + #endif // QT_NO_STACKEDWIDGET diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp index 19361fc7931..1adaa6e8050 100644 --- a/src/widgets/widgets/qstatusbar.cpp +++ b/src/widgets/widgets/qstatusbar.cpp @@ -783,4 +783,6 @@ bool QStatusBar::event(QEvent *e) QT_END_NAMESPACE +#include "moc_qstatusbar.cpp" + #endif diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 7ea5455bf72..41019a1de60 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -2497,4 +2497,4 @@ QT_END_NAMESPACE #endif // QT_NO_TABBAR - +#include "moc_qtabbar_p.cpp" diff --git a/src/widgets/widgets/qtoolbarextension.cpp b/src/widgets/widgets/qtoolbarextension.cpp index 687871294a6..30306542a65 100644 --- a/src/widgets/widgets/qtoolbarextension.cpp +++ b/src/widgets/widgets/qtoolbarextension.cpp @@ -81,4 +81,6 @@ QSize QToolBarExtension::sizeHint() const QT_END_NAMESPACE +#include "moc_qtoolbarextension_p.cpp" + #endif // QT_NO_TOOLBUTTON diff --git a/src/widgets/widgets/qtoolbarlayout.cpp b/src/widgets/widgets/qtoolbarlayout.cpp index 42fd93fda25..a66bad15a7b 100644 --- a/src/widgets/widgets/qtoolbarlayout.cpp +++ b/src/widgets/widgets/qtoolbarlayout.cpp @@ -742,4 +742,6 @@ QToolBarItem *QToolBarLayout::createItem(QAction *action) QT_END_NAMESPACE +#include "moc_qtoolbarlayout_p.cpp" + #endif // QT_NO_TOOLBAR diff --git a/src/widgets/widgets/qtoolbarseparator.cpp b/src/widgets/widgets/qtoolbarseparator.cpp index 48b56dd6bea..d9d0d8986af 100644 --- a/src/widgets/widgets/qtoolbarseparator.cpp +++ b/src/widgets/widgets/qtoolbarseparator.cpp @@ -80,4 +80,6 @@ void QToolBarSeparator::paintEvent(QPaintEvent *) QT_END_NAMESPACE +#include "moc_qtoolbarseparator_p.cpp" + #endif // QT_NO_TOOLBAR diff --git a/src/widgets/widgets/qwidgetanimator.cpp b/src/widgets/widgets/qwidgetanimator.cpp index 2bed11289ff..a6aadddb981 100644 --- a/src/widgets/widgets/qwidgetanimator.cpp +++ b/src/widgets/widgets/qwidgetanimator.cpp @@ -114,3 +114,5 @@ bool QWidgetAnimator::animating() const } QT_END_NAMESPACE + +#include "moc_qwidgetanimator_p.cpp" diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 436937be72f..0ff55f7c375 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -1919,4 +1919,6 @@ bool QWidgetLineControl::isRedoAvailable() const QT_END_NAMESPACE +#include "moc_qwidgetlinecontrol_p.cpp" + #endif diff --git a/src/widgets/widgets/qwidgetresizehandler.cpp b/src/widgets/widgets/qwidgetresizehandler.cpp index 0fee399745b..78d3a16bf3f 100644 --- a/src/widgets/widgets/qwidgetresizehandler.cpp +++ b/src/widgets/widgets/qwidgetresizehandler.cpp @@ -535,4 +535,6 @@ void QWidgetResizeHandler::doMove() QT_END_NAMESPACE +#include "moc_qwidgetresizehandler_p.cpp" + #endif //QT_NO_RESIZEHANDLER diff --git a/src/widgets/widgets/widgets.pri b/src/widgets/widgets/widgets.pri index c31a7f76824..9a3fae09a22 100644 --- a/src/widgets/widgets/widgets.pri +++ b/src/widgets/widgets/widgets.pri @@ -84,6 +84,7 @@ HEADERS += \ widgets/qplaintextedit_p.h SOURCES += \ + widgets/qbuttongroup.cpp \ widgets/qabstractbutton.cpp \ widgets/qabstractslider.cpp \ widgets/qabstractspinbox.cpp \ From 69335920f724d2d4a49924f373c4fef57c942831 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 17 Mar 2016 16:24:26 +0100 Subject: [PATCH 59/62] Move QButtonGroup implementation from qabstractbutton.cpp to qbuttongroup.cpp Because it's the right thing to do. Needed to introduce qbuttongroup_p.h because QAbstractButton likes to poke around in QButtonGroup's private parts. Fixed includes of qabstractbutton_p.h so it compiles on it's own. Change-Id: Ic7725277d2419754de273b2abd4790476edd0eb4 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qabstractbutton.cpp | 135 +----------------------- src/widgets/widgets/qabstractbutton_p.h | 2 + src/widgets/widgets/qbuttongroup.cpp | 128 +++++++++++++++++++--- src/widgets/widgets/qbuttongroup_p.h | 80 ++++++++++++++ src/widgets/widgets/widgets.pri | 1 + 5 files changed, 198 insertions(+), 148 deletions(-) create mode 100644 src/widgets/widgets/qbuttongroup_p.h diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index fe09b0087c9..2a546ac0cda 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -31,7 +31,9 @@ ** ****************************************************************************/ -#include "qabstractbutton.h" +#include "private/qabstractbutton_p.h" + +#include "private/qbuttongroup_p.h" #include "qabstractitemview.h" #include "qbuttongroup.h" #include "qabstractbutton_p.h" @@ -171,137 +173,6 @@ QAbstractButtonPrivate::QAbstractButtonPrivate(QSizePolicy::ControlType type) controlType(type) {} -#ifndef QT_NO_BUTTONGROUP - -class QButtonGroupPrivate: public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QButtonGroup) - -public: - QButtonGroupPrivate():exclusive(true){} - QList buttonList; - QPointer checkedButton; - void detectCheckedButton(); - void notifyChecked(QAbstractButton *button); - bool exclusive; - QHash mapping; -}; - -QButtonGroup::QButtonGroup(QObject *parent) - : QObject(*new QButtonGroupPrivate, parent) -{ -} - -QButtonGroup::~QButtonGroup() -{ - Q_D(QButtonGroup); - for (int i = 0; i < d->buttonList.count(); ++i) - d->buttonList.at(i)->d_func()->group = 0; -} - - -bool QButtonGroup::exclusive() const -{ - Q_D(const QButtonGroup); - return d->exclusive; -} - -void QButtonGroup::setExclusive(bool exclusive) -{ - Q_D(QButtonGroup); - d->exclusive = exclusive; -} - - -void QButtonGroup::addButton(QAbstractButton *button, int id) -{ - Q_D(QButtonGroup); - if (QButtonGroup *previous = button->d_func()->group) - previous->removeButton(button); - button->d_func()->group = this; - d->buttonList.append(button); - if (id == -1) { - const QHash::const_iterator it - = std::min_element(d->mapping.cbegin(), d->mapping.cend()); - if (it == d->mapping.cend()) - d->mapping[button] = -2; - else - d->mapping[button] = *it - 1; - } else { - d->mapping[button] = id; - } - - if (d->exclusive && button->isChecked()) - button->d_func()->notifyChecked(); -} - -void QButtonGroup::removeButton(QAbstractButton *button) -{ - Q_D(QButtonGroup); - if (d->checkedButton == button) { - d->detectCheckedButton(); - } - if (button->d_func()->group == this) { - button->d_func()->group = 0; - d->buttonList.removeAll(button); - d->mapping.remove(button); - } -} - -QList QButtonGroup::buttons() const -{ - Q_D(const QButtonGroup); - return d->buttonList; -} - -QAbstractButton *QButtonGroup::checkedButton() const -{ - Q_D(const QButtonGroup); - return d->checkedButton; -} - -QAbstractButton *QButtonGroup::button(int id) const -{ - Q_D(const QButtonGroup); - return d->mapping.key(id); -} - -void QButtonGroup::setId(QAbstractButton *button, int id) -{ - Q_D(QButtonGroup); - if (button && id != -1) - d->mapping[button] = id; -} - -int QButtonGroup::id(QAbstractButton *button) const -{ - Q_D(const QButtonGroup); - return d->mapping.value(button, -1); -} - -int QButtonGroup::checkedId() const -{ - Q_D(const QButtonGroup); - return d->mapping.value(d->checkedButton, -1); -} - -// detect a checked button other than the current one -void QButtonGroupPrivate::detectCheckedButton() -{ - QAbstractButton *previous = checkedButton; - checkedButton = 0; - if (exclusive) - return; - for (int i = 0; i < buttonList.count(); i++) { - if (buttonList.at(i) != previous && buttonList.at(i)->isChecked()) { - checkedButton = buttonList.at(i); - return; - } - } -} - -#endif // QT_NO_BUTTONGROUP - QListQAbstractButtonPrivate::queryButtonList() const { #ifndef QT_NO_BUTTONGROUP diff --git a/src/widgets/widgets/qabstractbutton_p.h b/src/widgets/widgets/qabstractbutton_p.h index 0975012843b..5a35b1b9cd9 100644 --- a/src/widgets/widgets/qabstractbutton_p.h +++ b/src/widgets/widgets/qabstractbutton_p.h @@ -45,6 +45,8 @@ // We mean it. // +#include "qabstractbutton.h" + #include "QtCore/qbasictimer.h" #include "private/qwidget_p.h" diff --git a/src/widgets/widgets/qbuttongroup.cpp b/src/widgets/widgets/qbuttongroup.cpp index 5a8dc5f3efd..e33f19297c8 100644 --- a/src/widgets/widgets/qbuttongroup.cpp +++ b/src/widgets/widgets/qbuttongroup.cpp @@ -31,7 +31,28 @@ ** ****************************************************************************/ +#include "private/qbuttongroup_p.h" +#ifndef QT_NO_BUTTONGROUP + +#include "private/qabstractbutton_p.h" + +QT_BEGIN_NAMESPACE + +// detect a checked button other than the current one +void QButtonGroupPrivate::detectCheckedButton() +{ + QAbstractButton *previous = checkedButton; + checkedButton = 0; + if (exclusive) + return; + for (int i = 0; i < buttonList.count(); i++) { + if (buttonList.at(i) != previous && buttonList.at(i)->isChecked()) { + checkedButton = buttonList.at(i); + return; + } + } +} /*! \class QButtonGroup @@ -78,18 +99,24 @@ */ /*! - \fn QButtonGroup::QButtonGroup(QObject *parent) - Constructs a new, empty button group with the given \a parent. \sa addButton(), setExclusive() */ +QButtonGroup::QButtonGroup(QObject *parent) + : QObject(*new QButtonGroupPrivate, parent) +{ +} /*! - \fn QButtonGroup::~QButtonGroup() - Destroys the button group. */ +QButtonGroup::~QButtonGroup() +{ + Q_D(QButtonGroup); + for (int i = 0; i < d->buttonList.count(); ++i) + d->buttonList.at(i)->d_func()->group = 0; +} /*! \property QButtonGroup::exclusive @@ -105,6 +132,19 @@ By default, this property is \c true. */ +bool QButtonGroup::exclusive() const +{ + Q_D(const QButtonGroup); + return d->exclusive; +} + +void QButtonGroup::setExclusive(bool exclusive) +{ + Q_D(QButtonGroup); + d->exclusive = exclusive; +} + + /*! \fn void QButtonGroup::buttonClicked(QAbstractButton *button) @@ -187,8 +227,6 @@ /*! - \fn void QButtonGroup::addButton(QAbstractButton *button, int id = -1); - Adds the given \a button to the button group. If \a id is -1, an id will be assigned to the button. Automatically assigned ids are guaranteed to be negative, @@ -197,42 +235,82 @@ \sa removeButton(), buttons() */ +void QButtonGroup::addButton(QAbstractButton *button, int id) +{ + Q_D(QButtonGroup); + if (QButtonGroup *previous = button->d_func()->group) + previous->removeButton(button); + button->d_func()->group = this; + d->buttonList.append(button); + if (id == -1) { + const QHash::const_iterator it + = std::min_element(d->mapping.cbegin(), d->mapping.cend()); + if (it == d->mapping.cend()) + d->mapping[button] = -2; + else + d->mapping[button] = *it - 1; + } else { + d->mapping[button] = id; + } + + if (d->exclusive && button->isChecked()) + button->d_func()->notifyChecked(); +} /*! - \fn void QButtonGroup::removeButton(QAbstractButton *button); - Removes the given \a button from the button group. \sa addButton(), buttons() */ +void QButtonGroup::removeButton(QAbstractButton *button) +{ + Q_D(QButtonGroup); + if (d->checkedButton == button) { + d->detectCheckedButton(); + } + if (button->d_func()->group == this) { + button->d_func()->group = 0; + d->buttonList.removeAll(button); + d->mapping.remove(button); + } +} /*! - \fn QList QButtonGroup::buttons() const - Returns the button group's list of buttons. This may be empty. \sa addButton(), removeButton() */ +QList QButtonGroup::buttons() const +{ + Q_D(const QButtonGroup); + return d->buttonList; +} /*! - \fn QAbstractButton *QButtonGroup::checkedButton() const; - Returns the button group's checked button, or 0 if no buttons are checked. \sa buttonClicked() */ +QAbstractButton *QButtonGroup::checkedButton() const +{ + Q_D(const QButtonGroup); + return d->checkedButton; +} /*! - \fn QAbstractButton *QButtonGroup::button(int id) const; \since 4.1 Returns the button with the specified \a id, or 0 if no such button exists. */ +QAbstractButton *QButtonGroup::button(int id) const +{ + Q_D(const QButtonGroup); + return d->mapping.key(id); +} /*! - \fn void QButtonGroup::setId(QAbstractButton *button, int id) \since 4.1 Sets the \a id for the specified \a button. Note that \a id cannot @@ -240,9 +318,14 @@ \sa id() */ +void QButtonGroup::setId(QAbstractButton *button, int id) +{ + Q_D(QButtonGroup); + if (button && id != -1) + d->mapping[button] = id; +} /*! - \fn int QButtonGroup::id(QAbstractButton *button) const; \since 4.1 Returns the id for the specified \a button, or -1 if no such button @@ -251,14 +334,27 @@ \sa setId() */ +int QButtonGroup::id(QAbstractButton *button) const +{ + Q_D(const QButtonGroup); + return d->mapping.value(button, -1); +} /*! - \fn int QButtonGroup::checkedId() const; \since 4.1 Returns the id of the checkedButton(), or -1 if no button is checked. \sa setId() */ +int QButtonGroup::checkedId() const +{ + Q_D(const QButtonGroup); + return d->mapping.value(d->checkedButton, -1); +} + +QT_END_NAMESPACE #include "moc_qbuttongroup.cpp" + +#endif // QT_NO_BUTTONGROUP diff --git a/src/widgets/widgets/qbuttongroup_p.h b/src/widgets/widgets/qbuttongroup_p.h new file mode 100644 index 00000000000..01c03678767 --- /dev/null +++ b/src/widgets/widgets/qbuttongroup_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBUTTONGROUP_P_H +#define QBUTTONGROUP_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#ifndef QT_NO_BUTTONGROUP + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QButtonGroupPrivate: public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QButtonGroup) + +public: + QButtonGroupPrivate() : exclusive(true) {} + + QList buttonList; + QPointer checkedButton; + void detectCheckedButton(); + void notifyChecked(QAbstractButton *button); + + bool exclusive; + QHash mapping; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_BUTTONGROUP + +#endif // QBUTTONGROUP_P_H diff --git a/src/widgets/widgets/widgets.pri b/src/widgets/widgets/widgets.pri index 9a3fae09a22..784055ed62e 100644 --- a/src/widgets/widgets/widgets.pri +++ b/src/widgets/widgets/widgets.pri @@ -2,6 +2,7 @@ HEADERS += \ widgets/qbuttongroup.h \ + widgets/qbuttongroup_p.h \ widgets/qabstractbutton.h \ widgets/qabstractbutton_p.h \ widgets/qabstractslider.h \ From a1d4e4c97efaa14d58cc2c01ceceb396ebd6d18c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 16 Mar 2016 08:39:12 +0100 Subject: [PATCH 60/62] QtWidgets: Change QTLWExtra::window from QWidgetWindow to QWindow. None of QWidgetWindow's API is used in the code. Task-number: QTBUG-33079 Change-Id: Iecb1e174645eff687ee0d8b29417c30a2c508311 Reviewed-by: Marc Mutz --- src/widgets/kernel/qwidget_p.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 7eb8d048b3d..a5c7aa5815d 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -68,7 +68,6 @@ QT_BEGIN_NAMESPACE // Extra QWidget data // - to minimize memory usage for members that are seldom used. // - top-level widgets have extra extra data to reduce cost further -class QWidgetWindow; class QPaintEngine; class QPixmap; class QWidgetBackingStore; @@ -154,7 +153,7 @@ struct QTLWExtra { QWidgetBackingStoreTracker backingStoreTracker; QBackingStore *backingStore; QPainter *sharedPainter; - QWidgetWindow *window; + QWindow *window; QOpenGLContext *shareContext; // Implicit pointers (shared_null). From 6ec89bec0a2f06365dc18bda6e95b6c253c19227 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 23 Feb 2016 01:13:47 +0100 Subject: [PATCH 61/62] Fix QFINDTESTDATA when using cmake ninja generator The Qt CI does not have ninja, but the autotest can be used for manual regression finding. cd qtbase/tests/auto/cmake qmake make check cd build cmake . -DHAVE_NINJA=ON ctest -R FINDTESTDATA Change-Id: Ic3f3748f6ab04e37fa5287c59486e5cd46dcabb4 Reviewed-by: Stephen Kelly --- src/testlib/Qt5TestConfigExtras.cmake.in | 5 ++ tests/auto/cmake/CMakeLists.txt | 18 ++++++ .../cmake/test_QFINDTESTDATA/CMakeLists.txt | 11 ++++ .../test_QFINDTESTDATA/tests/CMakeLists.txt | 4 ++ .../cmake/test_QFINDTESTDATA/tests/main.cpp | 55 +++++++++++++++++++ .../test_QFINDTESTDATA/tests/testdata.txt | 1 + 6 files changed, 94 insertions(+) create mode 100644 src/testlib/Qt5TestConfigExtras.cmake.in create mode 100644 tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt create mode 100644 tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt create mode 100644 tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp create mode 100644 tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt diff --git a/src/testlib/Qt5TestConfigExtras.cmake.in b/src/testlib/Qt5TestConfigExtras.cmake.in new file mode 100644 index 00000000000..2a575958ae4 --- /dev/null +++ b/src/testlib/Qt5TestConfigExtras.cmake.in @@ -0,0 +1,5 @@ + +set_property(TARGET Qt5::Test + APPEND PROPERTY + INTERFACE_COMPILE_DEFINITIONS QT_TESTCASE_BUILDDIR=\\\"\${CMAKE_BINARY_DIR}\\\" +) diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 5248f75a84a..1abbef0d68d 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -68,6 +68,24 @@ expect_fail(test_wrap_cpp_options) expect_pass(test_platform_defs_include) expect_pass(test_qtmainwin_library) +if (HAVE_NINJA) + make_directory("${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build") + add_test(test_QFINDTESTDATA ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA" + # Build in a subdir of the source dir. + # This causes Ninja to use relative paths. + "${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build" + --build-generator Ninja + --build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) + add_test(NAME run_test_QFINDTESTDATA COMMAND sh -c "cd \"${CMAKE_SOURCE_DIR}/test_QFINDTESTDATA/build/tests\" && ./test_QFINDTESTDATA -v2") + + set_property(TEST run_test_QFINDTESTDATA + PROPERTY DEPENDS test_QFINDTESTDATA + ) +endif() + if (NOT NO_DBUS) expect_pass(test_dbus_module) endif() diff --git a/tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt b/tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt new file mode 100644 index 00000000000..e56c3c5eb9d --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt @@ -0,0 +1,11 @@ + +cmake_minimum_required(VERSION 2.8.11) + +project(test_QFINDTESTDATA) + +find_package(Qt5Test REQUIRED) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_subdirectory(tests) diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt new file mode 100644 index 00000000000..dfe321982a9 --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_executable(test_QFINDTESTDATA WIN32 main.cpp) + +target_link_libraries(test_QFINDTESTDATA Qt5::Test) diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp b/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp new file mode 100644 index 00000000000..0a5b6acd323 --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Stephen Kelly +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class TestClass : public QObject +{ + Q_OBJECT +public: + TestClass(QObject* parent = 0) {} + +private slots: + void doTest(); +}; + +void TestClass::doTest() +{ + QFile f(QFINDTESTDATA("testdata.txt")); + QVERIFY(f.open(QFile::ReadOnly)); + QCOMPARE(f.readAll().trimmed(), QByteArrayLiteral("This is a test.")); +} + +QTEST_MAIN(TestClass) +#include "main.moc" diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt b/tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt new file mode 100644 index 00000000000..484ba93ef5b --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt @@ -0,0 +1 @@ +This is a test. From 2e02de165115c9d67ac343ff0960ed80f9c09bc8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 15 Mar 2016 11:00:20 -0700 Subject: [PATCH 62/62] Fix QtDBus deadlock inside kded/kiod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whenever a message spy was installed, we failed to actually process looped-back messages by queueing them for processing by the spy. That had as a consequence that the caller got an error reply. Worse, since the message had been queued, QtDBus would attempt to deliver it later. Since that message had isLocal==true, bad things happened inside the manager thread. The correct solution is not to queue the message for the filter. If the message is local, then simply deliver directly, as we're still in the user's thread. This used to be the behavior in Qt 5.5. Task-number: QTBUG-51676 Change-Id: I1dc112894cde7121e8ce302ae51b438ade1ff612 Reviewed-by: David Faure Reviewed-by: Dmitry Shachnev Reviewed-by: Jan Kundrát --- src/dbus/qdbusintegrator.cpp | 42 +++++++++++++++++++++++++++--------- src/dbus/qdbusintegrator_p.h | 1 + 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index cd448613d65..478a2c4a05f 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -480,6 +480,11 @@ QDBusSpyCallEvent::~QDBusSpyCallEvent() } void QDBusSpyCallEvent::placeMetaCall(QObject *) +{ + invokeSpyHooks(msg, hooks, hookCount); +} + +inline void QDBusSpyCallEvent::invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount) { // call the spy hook list for (int i = 0; i < hookCount; ++i) @@ -509,7 +514,12 @@ bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) { if (!ref.load()) return false; - if (!dispatchEnabled && !QDBusMessagePrivate::isLocal(amsg)) { + + // local message are always delivered, regardless of filtering + // or whether the dispatcher is enabled + bool isLocal = QDBusMessagePrivate::isLocal(amsg); + + if (!dispatchEnabled && !isLocal) { // queue messages only, we'll handle them later qDBusDebug() << this << "delivery is suspended"; pendingMessages << amsg; @@ -523,13 +533,23 @@ bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) // let them see the signal too return false; case QDBusMessage::MethodCallMessage: - // run it through the spy filters (if any) before the regular processing + // run it through the spy filters (if any) before the regular processing: + // a) if it's a local message, we're in the caller's thread, so invoke the filter directly + // b) if it's an external message, post to the main thread if (Q_UNLIKELY(qDBusSpyHookList.exists()) && qApp) { const QDBusSpyHookList &list = *qDBusSpyHookList; - qDBusDebug() << this << "invoking message spies"; - QCoreApplication::postEvent(qApp, new QDBusSpyCallEvent(this, QDBusConnection(this), - amsg, list.constData(), list.size())); - return true; + if (isLocal) { + Q_ASSERT(QThread::currentThread() != thread()); + qDBusDebug() << this << "invoking message spies directly"; + QDBusSpyCallEvent::invokeSpyHooks(amsg, list.constData(), list.size()); + } else { + qDBusDebug() << this << "invoking message spies via event"; + QCoreApplication::postEvent(qApp, new QDBusSpyCallEvent(this, QDBusConnection(this), + amsg, list.constData(), list.size())); + + // we'll be called back, so return + return true; + } } handleObjectCall(amsg); @@ -1451,9 +1471,9 @@ void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg) // that means the dispatchLock mutex is locked // must not call out to user code in that case // - // however, if the message is internal, handleMessage was called - // directly and no lock is in place. We can therefore call out to - // user code, if necessary + // however, if the message is internal, handleMessage was called directly + // (user's thread) and no lock is in place. We can therefore call out to + // user code, if necessary. ObjectTreeNode result; int usedLength; QThread *objThread = 0; @@ -1492,12 +1512,14 @@ void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg) usedLength, msg)); return; } else if (objThread != QThread::currentThread()) { - // synchronize with other thread + // looped-back message, targeting another thread: + // synchronize with it postEventToThread(HandleObjectCallPostEventAction, result.obj, new QDBusActivateObjectEvent(QDBusConnection(this), this, result, usedLength, msg, &sem)); semWait = true; } else { + // looped-back message, targeting current thread semWait = false; } } // release the lock diff --git a/src/dbus/qdbusintegrator_p.h b/src/dbus/qdbusintegrator_p.h index 2bbebdf7083..c0d9c22af05 100644 --- a/src/dbus/qdbusintegrator_p.h +++ b/src/dbus/qdbusintegrator_p.h @@ -145,6 +145,7 @@ public: {} ~QDBusSpyCallEvent(); void placeMetaCall(QObject *) Q_DECL_OVERRIDE; + static inline void invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount); QDBusConnection conn; // keeps the refcount in QDBusConnectionPrivate up QDBusMessage msg;