From 201dde1f313ab42b34fe96bd0c630beccca4960e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 29 Jan 2019 09:14:25 +0100 Subject: [PATCH 01/16] QFileDialog: Fix deprecation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix: dialogs/qfiledialog.cpp:3698:43: warning: ‘QDir& QDir::operator=(const QString&)’ is deprecated: Use QDir::setPath() instead [-Wdeprecated-declarations] dir = getEnvironmentVariable(path2); Change-Id: If8d93374cf2900974bcbd14caf2b1ef488409518 Reviewed-by: Christian Ehrlicher --- src/widgets/dialogs/qfiledialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index eb3479b3e0..edaa7854ba 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -3695,7 +3695,7 @@ void QFileDialogPrivate::_q_goToDirectory(const QString &path) } QDir dir(path2); if (!dir.exists()) - dir = getEnvironmentVariable(path2); + dir.setPath(getEnvironmentVariable(path2)); if (dir.exists() || path2.isEmpty() || path2 == model->myComputer().toString()) { _q_enterDirectory(index); From 5de981d3bc3df874f9df35a6899345f4f61fa951 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 29 Jan 2019 15:47:24 +0100 Subject: [PATCH 02/16] QtNetwork: Fix some messages in OCSP stapling Amends a8412dc020e82b45b54b0b6637b8b88b255c413a. Task-number: QTBUG-12812 Task-number: QTBUG-17158 Change-Id: Idcdf9ad39a43373097e2c3f31a62ce1b3cb46c22 Reviewed-by: Timur Pocheptsov --- src/network/ssl/qsslerror.cpp | 2 +- src/network/ssl/qsslsocket_schannel.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/network/ssl/qsslerror.cpp b/src/network/ssl/qsslerror.cpp index 74ff6987d2..02dd16a58d 100644 --- a/src/network/ssl/qsslerror.cpp +++ b/src/network/ssl/qsslerror.cpp @@ -326,7 +326,7 @@ QString QSslError::errorString() const errStr = QSslSocket::tr("The client is not authorized to request OCSP status from this server"); break; case OcspResponseCannotBeTrusted: - errStr = QSslSocket::tr("OCSP reponder's identity cannot be verified"); + errStr = QSslSocket::tr("OCSP responder's identity cannot be verified"); break; case OcspResponseCertIdUnknown: errStr = QSslSocket::tr("The identity of a certificate in an OCSP response cannot be established"); diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp index e5f31a3fcf..06bbc86469 100644 --- a/src/network/ssl/qsslsocket_schannel.cpp +++ b/src/network/ssl/qsslsocket_schannel.cpp @@ -578,10 +578,10 @@ bool QSslSocketBackendPrivate::acquireCredentialsHandle() &findParam, nullptr); if (!chainContext) { - setErrorAndEmit(QAbstractSocket::SocketError::SslInvalidUserDataError, - QSslSocket::tr("The certificate provided can not be used for a %1.") - .arg(isClient ? QSslSocket::tr("client") - : QSslSocket::tr("server"))); + const QString message = isClient + ? QSslSocket::tr("The certificate provided can not be used for a client.") + : QSslSocket::tr("The certificate provided can not be used for a server."); + setErrorAndEmit(QAbstractSocket::SocketError::SslInvalidUserDataError, message); return false; } Q_ASSERT(chainContext->cChain == 1); From 7847e6bc02552fa7fc7f518e5cb3336f667b5a6d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 29 Jan 2019 12:09:22 +0100 Subject: [PATCH 03/16] Enable deprecation warnings by default With Qt 6 in sight, people need to start moving away from their deprecated APIs, as we want to remove them all in 6.0. We are marking deprecated APIs with deprecation attributes, but by default we're disabling deprecation warnings, making them an opt-in by the user. We need to do the opposite: make deprecation warnings enabled by default, and have an opt-out define. [ChangeLog][QtCore][Important Behavior Changes] Qt now enables by default warnings when using APIs marked as deprecated. It is possible to disable such warnings by defining the QT_NO_DEPRECATED_WARNINGS macro. The old QT_DEPRECATED_WARNINGS macro which was used to enable this warning now has no effect (warnings are automatically enabled). Task-number: QTBUG-73048 Change-Id: Ie2b024fd667eb876b6ac9054cbbbc5a455cb9d5c Reviewed-by: Kai Koehne Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- qmake/generators/projectgenerator.cpp | 10 +++------- src/corelib/global/qglobal.cpp | 26 +++++++++++++++++++------- src/corelib/global/qglobal.h | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/qmake/generators/projectgenerator.cpp b/qmake/generators/projectgenerator.cpp index f45a90b851..ef34955eb1 100644 --- a/qmake/generators/projectgenerator.cpp +++ b/qmake/generators/projectgenerator.cpp @@ -345,14 +345,10 @@ ProjectGenerator::writeMakefile(QTextStream &t) << getWritableVar("CONFIG_REMOVE", false) << getWritableVar("INCLUDEPATH") << endl; - t << "# The following define makes your compiler warn you if you use any\n" - "# feature of Qt which has been marked as deprecated (the exact warnings\n" - "# depend on your compiler). Please consult the documentation of the\n" - "# deprecated API in order to know how to port your code away from it.\n" - "DEFINES += QT_DEPRECATED_WARNINGS\n" - "\n" - "# You can also make your code fail to compile if you use deprecated APIs.\n" + t << "# You can make your code fail to compile if you use deprecated APIs.\n" "# In order to do so, uncomment the following line.\n" + "# Please consult the documentation of the deprecated API in order to know\n" + "# how to port your code away from it.\n" "# You can also select to disable deprecated APIs only up to a certain version of Qt.\n" "#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0\n\n"; diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 3f0b78ec55..7879109930 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -1979,11 +1979,11 @@ bool qSharedBuild() Q_DECL_NOTHROW a specified version of Qt or any earlier version. The default version number is 5.0, meaning that functions deprecated in or before Qt 5.0 will not be included. - Examples: - When using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to - disable functions deprecated in Qt 5.1 and earlier. In any release, set - QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable any functions, including the ones - deprecated in Qt 5.0 + For instance, when using a future release of Qt 5, set + \c{QT_DISABLE_DEPRECATED_BEFORE=0x050100} to disable functions deprecated in + Qt 5.1 and earlier. In any release, set + \c{QT_DISABLE_DEPRECATED_BEFORE=0x000000} to enable all functions, including + the ones deprecated in Qt 5.0. \sa QT_DEPRECATED_WARNINGS */ @@ -1993,12 +1993,24 @@ bool qSharedBuild() Q_DECL_NOTHROW \macro QT_DEPRECATED_WARNINGS \relates - If this macro is defined, the compiler will generate warnings if API declared as + Since Qt 5.13, this macro has no effect. In Qt 5.12 and before, if this macro + is defined, the compiler will generate warnings if any API declared as deprecated by Qt is used. - \sa QT_DISABLE_DEPRECATED_BEFORE + \sa QT_DISABLE_DEPRECATED_BEFORE, QT_NO_DEPRECATED_WARNINGS */ +/*! + \macro QT_NO_DEPRECATED_WARNINGS + \relates + \since 5.13 + + This macro can be used to suppress deprecation warnings that would otherwise + be generated when using deprecated APIs. + + \sa QT_DISABLE_DEPRECATED_BEFORE +*/ + #if defined(QT_BUILD_QMAKE) // needed to bootstrap qmake static const unsigned int qt_one = 1; diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 1e4ccae65b..223ebbcabe 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -287,7 +287,7 @@ typedef double qreal; # undef QT_DEPRECATED_X # undef QT_DEPRECATED_VARIABLE # undef QT_DEPRECATED_CONSTRUCTOR -#elif defined(QT_DEPRECATED_WARNINGS) +#elif !defined(QT_NO_DEPRECATED_WARNINGS) # undef QT_DEPRECATED # define QT_DEPRECATED Q_DECL_DEPRECATED # undef QT_DEPRECATED_X From df39627fa33392a71ab79aadaa57e5c5e650e79e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 1 Jan 2019 15:18:57 +0100 Subject: [PATCH 04/16] Examples: cleanup foreach usage Replace deprecated foreach macro with range-based for loop Change-Id: If919ba1d1d4acddfc1c5460ce7aebf8c49e3ac38 Reviewed-by: Paul Wicking --- .../mimetypes/mimetypebrowser/mainwindow.cpp | 4 ++- .../corelib/serialization/savegame/game.cpp | 2 +- .../corelib/serialization/savegame/level.cpp | 2 +- .../threads/queuedcustomtype/window.cpp | 5 ++-- examples/dbus/listnames/listnames.cpp | 3 ++- examples/embedded/lightmaps/slippymap.cpp | 11 ++++---- examples/opengl/contextinfo/widget.cpp | 2 +- .../opengl/legacy/overpainting/glwidget.cpp | 2 +- examples/opengl/qopenglwidget/glwidget.cpp | 6 ++--- examples/opengl/qopenglwidget/mainwindow.cpp | 2 +- examples/qpa/windows/main.cpp | 4 +-- examples/xml/htmlinfo/main.cpp | 26 +++++++++---------- 12 files changed, 37 insertions(+), 32 deletions(-) diff --git a/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp b/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp index bc7ec17d1c..2e5c8069b8 100644 --- a/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp +++ b/examples/corelib/mimetypes/mimetypebrowser/mainwindow.cpp @@ -185,7 +185,9 @@ void MainWindow::find() m_findMatches.clear(); m_findIndex = 0; - foreach (const QStandardItem *item, m_model->findItems(value, Qt::MatchContains | Qt::MatchFixedString | Qt::MatchRecursive)) + const QList items = + m_model->findItems(value, Qt::MatchContains | Qt::MatchFixedString | Qt::MatchRecursive); + for (const QStandardItem *item : items) m_findMatches.append(m_model->indexFromItem(item)); statusBar()->showMessage(tr("%n mime types match \"%1\".", 0, m_findMatches.size()).arg(value)); updateFindActions(); diff --git a/examples/corelib/serialization/savegame/game.cpp b/examples/corelib/serialization/savegame/game.cpp index 4caec71a03..226f6fda11 100644 --- a/examples/corelib/serialization/savegame/game.cpp +++ b/examples/corelib/serialization/savegame/game.cpp @@ -185,7 +185,7 @@ void Game::write(QJsonObject &json) const json["player"] = playerObject; QJsonArray levelArray; - foreach (const Level level, mLevels) { + for (const Level level : mLevels) { QJsonObject levelObject; level.write(levelObject); levelArray.append(levelObject); diff --git a/examples/corelib/serialization/savegame/level.cpp b/examples/corelib/serialization/savegame/level.cpp index 8eda107f46..c7adc6c8ff 100644 --- a/examples/corelib/serialization/savegame/level.cpp +++ b/examples/corelib/serialization/savegame/level.cpp @@ -97,7 +97,7 @@ void Level::write(QJsonObject &json) const { json["name"] = mName; QJsonArray npcArray; - foreach (const Character npc, mNpcs) { + for (const Character npc : mNpcs) { QJsonObject npcObject; npc.write(npcObject); npcArray.append(npcObject); diff --git a/examples/corelib/threads/queuedcustomtype/window.cpp b/examples/corelib/threads/queuedcustomtype/window.cpp index 2cefba1e17..0d3f80aba4 100644 --- a/examples/corelib/threads/queuedcustomtype/window.cpp +++ b/examples/corelib/threads/queuedcustomtype/window.cpp @@ -89,9 +89,10 @@ Window::Window() void Window::loadImage() { QStringList formats; - foreach (QByteArray format, QImageReader::supportedImageFormats()) + const QList supportedFormats = QImageReader::supportedImageFormats(); + for (const QByteArray &format : supportedFormats) if (format.toLower() == format) - formats.append("*." + format); + formats.append(QLatin1String("*.") + QString::fromLatin1(format)); QString newPath = QFileDialog::getOpenFileName(this, tr("Open Image"), path, tr("Image files (%1)").arg(formats.join(' '))); diff --git a/examples/dbus/listnames/listnames.cpp b/examples/dbus/listnames/listnames.cpp index c0afec062d..50203da73d 100644 --- a/examples/dbus/listnames/listnames.cpp +++ b/examples/dbus/listnames/listnames.cpp @@ -62,7 +62,8 @@ void method1() qDebug() << "Error:" << reply.error().message(); exit(1); } - foreach (QString name, reply.value()) + const QStringList values = reply.value(); + for (const QString &name : values) qDebug() << name; } diff --git a/examples/embedded/lightmaps/slippymap.cpp b/examples/embedded/lightmaps/slippymap.cpp index ff43261700..da003981ff 100644 --- a/examples/embedded/lightmaps/slippymap.cpp +++ b/examples/embedded/lightmaps/slippymap.cpp @@ -162,7 +162,6 @@ void SlippyMap::handleNetworkData(QNetworkReply *reply) { QImage img; QPoint tp = reply->request().attribute(QNetworkRequest::User).toPoint(); - QUrl url = reply->url(); if (!reply->error()) if (!img.load(reply, 0)) img = QImage(); @@ -173,10 +172,12 @@ void SlippyMap::handleNetworkData(QNetworkReply *reply) emit updated(tileRect(tp)); // purge unused spaces - QRect bound = m_tilesRect.adjusted(-2, -2, 2, 2); - foreach(QPoint tp, m_tilePixmaps.keys()) - if (!bound.contains(tp)) - m_tilePixmaps.remove(tp); + const QRect bound = m_tilesRect.adjusted(-2, -2, 2, 2); + for (auto it = m_tilePixmaps.keyBegin(); it != m_tilePixmaps.keyEnd(); ++it) { + const QPoint &tp = *it; + if (!bound.contains(tp)) + m_tilePixmaps.remove(tp); + } download(); } diff --git a/examples/opengl/contextinfo/widget.cpp b/examples/opengl/contextinfo/widget.cpp index a5d9e98bf8..b1b7076503 100644 --- a/examples/opengl/contextinfo/widget.cpp +++ b/examples/opengl/contextinfo/widget.cpp @@ -387,7 +387,7 @@ void Widget::renderWindowReady() QList extensionList = context->extensions().toList(); std::sort(extensionList.begin(), extensionList.end()); m_extensions->append(tr("Found %1 extensions:").arg(extensionList.count())); - Q_FOREACH (const QByteArray &ext, extensionList) + for (const QByteArray &ext : qAsConst(extensionList)) m_extensions->append(QString::fromLatin1(ext)); m_output->moveCursor(QTextCursor::Start); diff --git a/examples/opengl/legacy/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp index 1ec7bd731c..f98d043c5c 100644 --- a/examples/opengl/legacy/overpainting/glwidget.cpp +++ b/examples/opengl/legacy/overpainting/glwidget.cpp @@ -201,7 +201,7 @@ void GLWidget::paintEvent(QPaintEvent *event) //! [10] QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - foreach (Bubble *bubble, bubbles) { + for (Bubble *bubble : qAsConst(bubbles)) { if (bubble->rect().intersects(event->rect())) bubble->drawBubble(&painter); } diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp index 3fe919f94b..946b2bec67 100644 --- a/examples/opengl/qopenglwidget/glwidget.cpp +++ b/examples/opengl/qopenglwidget/glwidget.cpp @@ -385,10 +385,10 @@ void GLWidget::paintGL() painter.endNativePainting(); - if (m_showBubbles) - foreach (Bubble *bubble, m_bubbles) { + if (m_showBubbles) { + for (Bubble *bubble : qAsConst(m_bubbles)) bubble->drawBubble(&painter); - } + } if (const int elapsed = m_time.elapsed()) { QString framesPerSecond; diff --git a/examples/opengl/qopenglwidget/mainwindow.cpp b/examples/opengl/qopenglwidget/mainwindow.cpp index 4bd123628f..6fab3df79e 100644 --- a/examples/opengl/qopenglwidget/mainwindow.cpp +++ b/examples/opengl/qopenglwidget/mainwindow.cpp @@ -176,7 +176,7 @@ void MainWindow::timerUsageChanged(bool enabled) m_timer->start(); } else { m_timer->stop(); - foreach (QOpenGLWidget *w, m_glWidgets) + for (QOpenGLWidget *w : qAsConst(m_glWidgets)) w->update(); } } diff --git a/examples/qpa/windows/main.cpp b/examples/qpa/windows/main.cpp index 9d22d146d8..80f44ae0dc 100644 --- a/examples/qpa/windows/main.cpp +++ b/examples/qpa/windows/main.cpp @@ -79,9 +79,9 @@ int main(int argc, char **argv) // create one window on each additional screen as well - QList screens = app.screens(); QList windows; - foreach (QScreen *screen, screens) { + const QList screens = app.screens(); + for (QScreen *screen : screens) { if (screen == app.primaryScreen()) continue; WindowPtr window(new Window(screen)); diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp index 6591c3ac91..22bf36f33c 100644 --- a/examples/xml/htmlinfo/main.cpp +++ b/examples/xml/htmlinfo/main.cpp @@ -50,7 +50,8 @@ #include -void parseHtmlFile(QTextStream &out, const QString &fileName) { +void parseHtmlFile(QTextStream &out, const QString &fileName) +{ QFile file(fileName); out << "Analysis of HTML file: " << fileName << endl; @@ -71,11 +72,11 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { while (!reader.atEnd()) { reader.readNext(); if (reader.isStartElement()) { - if (reader.name() == "title") + if (reader.name() == QLatin1String("title")) title = reader.readElementText(); - else if(reader.name() == "a") - links.append(reader.attributes().value("href").toString()); - else if(reader.name() == "p") + else if (reader.name() == QLatin1String("a")) + links.append(reader.attributes().value(QLatin1String("href")).toString()); + else if (reader.name() == QLatin1String("p")) ++paragraphCount; } } @@ -94,10 +95,10 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { << " Number of links: " << links.size() << endl << " Showing first few links:" << endl; - while(links.size() > 5) + while (links.size() > 5) links.removeLast(); - foreach(QString link, links) + for (const QString &link : qAsConst(links)) out << " " << link << endl; out << endl << endl; } @@ -108,11 +109,10 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); // get a list of all html files in the current directory - QStringList filter; - filter << "*.htm"; - filter << "*.html"; + const QStringList filter = { QStringLiteral("*.htm"), + QStringLiteral("*.html") }; - QStringList htmlFiles = QDir(":/").entryList(filter, QDir::Files); + const QStringList htmlFiles = QDir(QStringLiteral(":/")).entryList(filter, QDir::Files); QTextStream out(stdout); @@ -122,8 +122,8 @@ int main(int argc, char **argv) } // parse each html file and write the result to file/stream - foreach(QString file, htmlFiles) - parseHtmlFile(out, ":/" + file); + for (const QString &file : htmlFiles) + parseHtmlFile(out, QStringLiteral(":/") + file); return 0; } From daee9af969a04a2919a948ba1f5d314626925a9a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 25 Jan 2019 21:15:43 +0100 Subject: [PATCH 05/16] QtGui: mark obsolete QPixmapCache::find() functions as deprecated QPixmapCache::find(QString) and QPixmapCache::find(QString, QPixmap&) are deprecated since Qt4 times. Explicit mark them as deprecated so they can be removed with Qt6. Change-Id: Iaf185f69afe02203559a1c812fbb4a95c9049a1d Reviewed-by: Eirik Aavitsland --- .../widgets/painting/shared/arthurstyle.cpp | 6 ++-- src/gui/image/qicon.cpp | 6 ++-- src/gui/image/qpixmapcache.cpp | 12 ++++--- src/gui/image/qpixmapcache.h | 4 +++ src/gui/painting/qbrush.cpp | 2 +- src/gui/painting/qpainter.cpp | 2 +- .../themes/qabstractfileiconengine.cpp | 2 +- .../xcb/nativepainting/qpaintengine_x11.cpp | 2 +- src/widgets/itemviews/qitemdelegate.cpp | 31 +++++++++++++------ src/widgets/itemviews/qitemdelegate.h | 5 +++ src/widgets/styles/qcommonstyle.cpp | 2 +- src/widgets/styles/qfusionstyle.cpp | 14 ++++----- src/widgets/styles/qstyle_p.h | 2 +- 13 files changed, 57 insertions(+), 33 deletions(-) diff --git a/examples/widgets/painting/shared/arthurstyle.cpp b/examples/widgets/painting/shared/arthurstyle.cpp index f4fc76bda6..3df9d9a6dc 100644 --- a/examples/widgets/painting/shared/arthurstyle.cpp +++ b/examples/widgets/painting/shared/arthurstyle.cpp @@ -61,10 +61,10 @@ QPixmap cached(const QString &img) { - if (QPixmap *p = QPixmapCache::find(img)) - return *p; - QPixmap pm; + if (QPixmapCache::find(img, &pm)) + return pm; + pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither); if (pm.isNull()) return QPixmap(); diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 285cdf790a..c3c4b24678 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -315,9 +315,9 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St % HexString(actualSize.height()); if (mode == QIcon::Active) { - if (QPixmapCache::find(key % HexString(mode), pm)) + if (QPixmapCache::find(key % HexString(mode), &pm)) return pm; // horray - if (QPixmapCache::find(key % HexString(QIcon::Normal), pm)) { + if (QPixmapCache::find(key % HexString(QIcon::Normal), &pm)) { QPixmap active = pm; if (QGuiApplication *guiApp = qobject_cast(qApp)) active = static_cast(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm); @@ -326,7 +326,7 @@ QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::St } } - if (!QPixmapCache::find(key % HexString(mode), pm)) { + if (!QPixmapCache::find(key % HexString(mode), &pm)) { if (pm.size() != actualSize) pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); if (pe->mode != mode && mode != QIcon::Normal) { diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 3d1652f68b..66907bebd7 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -469,10 +469,13 @@ QPixmapCacheEntry::~QPixmapCacheEntry() pm_cache()->releaseKey(key); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete \overload + Use bool find(const QString &, QPixmap *) instead. + Returns the pixmap associated with the \a key in the cache, or null if there is no such pixmap. @@ -494,13 +497,14 @@ QPixmap *QPixmapCache::find(const QString &key) /*! \obsolete - Use bool find(const QString&, QPixmap*) instead. + Use bool find(const QString &, QPixmap *) instead. */ -bool QPixmapCache::find(const QString &key, QPixmap& pixmap) +bool QPixmapCache::find(const QString &key, QPixmap &pixmap) { return find(key, &pixmap); } +#endif /*! Looks for a cached pixmap associated with the given \a key in the cache. @@ -513,7 +517,7 @@ bool QPixmapCache::find(const QString &key, QPixmap& pixmap) \snippet code/src_gui_image_qpixmapcache.cpp 1 */ -bool QPixmapCache::find(const QString &key, QPixmap* pixmap) +bool QPixmapCache::find(const QString &key, QPixmap *pixmap) { QPixmap *ptr = pm_cache()->object(key); if (ptr && pixmap) @@ -530,7 +534,7 @@ bool QPixmapCache::find(const QString &key, QPixmap* pixmap) \since 4.6 */ -bool QPixmapCache::find(const Key &key, QPixmap* pixmap) +bool QPixmapCache::find(const Key &key, QPixmap *pixmap) { //The key is not valid anymore, a flush happened before probably if (!key.d || !key.d->isValid) diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h index ea10ab1b76..12d05b00f3 100644 --- a/src/gui/image/qpixmapcache.h +++ b/src/gui/image/qpixmapcache.h @@ -76,8 +76,12 @@ public: static int cacheLimit(); static void setCacheLimit(int); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use bool find(const QString &, QPixmap *) instead") static QPixmap *find(const QString &key); + QT_DEPRECATED_X("Use bool find(const QString &, QPixmap *) instead") static bool find(const QString &key, QPixmap &pixmap); +#endif static bool find(const QString &key, QPixmap *pixmap); static bool find(const Key &key, QPixmap *pixmap); static bool insert(const QString &key, const QPixmap &pixmap); diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 860653cc4c..abfa8d41bb 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -111,7 +111,7 @@ Q_GUI_EXPORT QPixmap qt_pixmapForBrush(int brushStyle, bool invert) QString key = QLatin1String("$qt-brush$") % HexString(brushStyle) % QLatin1Char(invert ? '1' : '0'); - if (!QPixmapCache::find(key, pm)) { + if (!QPixmapCache::find(key, &pm)) { pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert), QImage::Format_MonoLSB); QPixmapCache::insert(key, pm); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index df2f5e11d3..6626768d51 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -6210,7 +6210,7 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) % HexString(pen.widthF()); QPixmap pixmap; - if (QPixmapCache::find(key, pixmap)) + if (QPixmapCache::find(key, &pixmap)) return pixmap; const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio diff --git a/src/platformsupport/themes/qabstractfileiconengine.cpp b/src/platformsupport/themes/qabstractfileiconengine.cpp index 192ed00510..c5800d9119 100644 --- a/src/platformsupport/themes/qabstractfileiconengine.cpp +++ b/src/platformsupport/themes/qabstractfileiconengine.cpp @@ -76,7 +76,7 @@ QPixmap QAbstractFileIconEngine::pixmap(const QSize &size, QIcon::Mode mode, key += QLatin1Char('_') + QString::number(size.width()); QPixmap result; - if (!QPixmapCache::find(key, result)) { + if (!QPixmapCache::find(key, &result)) { result = filePixmap(size, mode, state); if (!result.isNull()) QPixmapCache::insert(key, result); diff --git a/src/plugins/platforms/xcb/nativepainting/qpaintengine_x11.cpp b/src/plugins/platforms/xcb/nativepainting/qpaintengine_x11.cpp index a3e6cedecd..2688d6e884 100644 --- a/src/plugins/platforms/xcb/nativepainting/qpaintengine_x11.cpp +++ b/src/plugins/platforms/xcb/nativepainting/qpaintengine_x11.cpp @@ -458,7 +458,7 @@ static QPixmap qt_patternForAlpha(uchar alpha, int screen) % HexString(alpha) % HexString(screen); - if (!QPixmapCache::find(key, pm)) { + if (!QPixmapCache::find(key, &pm)) { // #### why not use a mono image here???? QImage pattern(DITHER_SIZE, DITHER_SIZE, QImage::Format_ARGB32); pattern.fill(0xffffffff); diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 16d4a21f50..f85004c49c 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -724,8 +724,8 @@ void QItemDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment, pixmap.size(), rect).topLeft(); if (option.state & QStyle::State_Selected) { - QPixmap *pm = selected(pixmap, option.palette, option.state & QStyle::State_Enabled); - painter->drawPixmap(p, *pm); + const QPixmap pm = selectedPixmap(pixmap, option.palette, option.state & QStyle::State_Enabled); + painter->drawPixmap(p, pm); } else { painter->drawPixmap(p, pixmap); } @@ -1001,17 +1001,29 @@ static QString qPixmapSerial(quint64 i, bool enabled) return QString((const QChar *)ptr, int(&arr[sizeof(arr) / sizeof(ushort)] - ptr)); } +#if QT_DEPRECATED_SINCE(5, 13) +QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const +{ + const QString key = qPixmapSerial(pixmap.cacheKey(), enabled); + QPixmap *pm = QPixmapCache::find(key); + if (pm) + return pm; + selectedPixmap(pixmap, palette, enabled); + return QPixmapCache::find(key); +} +#endif + /*! \internal Returns the selected version of the given \a pixmap using the given \a palette. The \a enabled argument decides whether the normal or disabled highlight color of the palette is used. */ -QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const +QPixmap QItemDelegate::selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled) { - QString key = qPixmapSerial(pixmap.cacheKey(), enabled); - QPixmap *pm = QPixmapCache::find(key); - if (!pm) { + const QString key = qPixmapSerial(pixmap.cacheKey(), enabled); + QPixmap pm; + if (!QPixmapCache::find(key, &pm)) { QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); QColor color = palette.color(enabled ? QPalette::Normal : QPalette::Disabled, @@ -1023,13 +1035,12 @@ QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, painter.fillRect(0, 0, img.width(), img.height(), color); painter.end(); - QPixmap selected = QPixmap(QPixmap::fromImage(img)); - int n = (img.sizeInBytes() >> 10) + 1; + pm = QPixmap(QPixmap::fromImage(img)); + const int n = (img.sizeInBytes() >> 10) + 1; if (QPixmapCache::cacheLimit() < n) QPixmapCache::setCacheLimit(n); - QPixmapCache::insert(key, selected); - pm = QPixmapCache::find(key); + QPixmapCache::insert(key, pm); } return pm; } diff --git a/src/widgets/itemviews/qitemdelegate.h b/src/widgets/itemviews/qitemdelegate.h index 539dec4374..e504615fb2 100644 --- a/src/widgets/itemviews/qitemdelegate.h +++ b/src/widgets/itemviews/qitemdelegate.h @@ -113,7 +113,12 @@ protected: const QStyleOptionViewItem &option) const; QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const; + +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use selectedPixmap() instead") QPixmap *selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const; +#endif + static QPixmap selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled); QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding, const QVariant &variant) const; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 2bfc1acc26..1980dc47a9 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -751,7 +751,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-") % QLatin1String(metaObject()->className()), opt, QSize(size, size)) % HexString(pe); - if (!QPixmapCache::find(pixmapName, pixmap)) { + if (!QPixmapCache::find(pixmapName, &pixmap)) { qreal pixelRatio = p->device()->devicePixelRatioF(); int border = qRound(pixelRatio*(size/5)); int sqsize = qRound(pixelRatio*(2*(size/2))); diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 7c58adeb85..0e95d6efa4 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -261,7 +261,7 @@ static void qt_fusion_draw_arrow(Qt::ArrowType type, QPainter *painter, const QS QString cacheKey = QStyleHelper::uniqueName(QLatin1String("fusion-arrow"), option, rect.size()) % HexString(type) % HexString(color.rgba()); - if (!QPixmapCache::find(cacheKey, cachePixmap)) { + if (!QPixmapCache::find(cacheKey, &cachePixmap)) { cachePixmap = styleCachePixmap(rect.size()); cachePixmap.fill(Qt::transparent); QPainter cachePainter(&cachePixmap); @@ -1272,7 +1272,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio pixmapName += QString::number(- int(header->orientation)); QPixmap cache; - if (!QPixmapCache::find(pixmapName, cache)) { + if (!QPixmapCache::find(pixmapName, &cache)) { cache = styleCachePixmap(rect.size()); cache.fill(Qt::transparent); QRect pixmapRect(0, 0, rect.width(), rect.height()); @@ -2030,7 +2030,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast(option)) { QPixmap cache; QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size()); - if (!QPixmapCache::find(pixmapName, cache)) { + if (!QPixmapCache::find(pixmapName, &cache)) { cache = styleCachePixmap(spinBox->rect.size()); cache.fill(Qt::transparent); @@ -2745,7 +2745,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption if (!comboBox->frame) pixmapName += QLatin1String("-frameless"); - if (!QPixmapCache::find(pixmapName, cache)) { + if (!QPixmapCache::find(pixmapName, &cache)) { cache = styleCachePixmap(comboBox->rect.size()); cache.fill(Qt::transparent); QPainter cachePainter(&cache); @@ -2852,7 +2852,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption QRect pixmapRect(0, 0, groove.width(), groove.height()); // draw background groove - if (!QPixmapCache::find(groovePixmapName, cache)) { + if (!QPixmapCache::find(groovePixmapName, &cache)) { cache = styleCachePixmap(pixmapRect.size()); cache.fill(Qt::transparent); QPainter groovePainter(&cache); @@ -2880,7 +2880,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption // draw blue groove highlight QRect clipRect; groovePixmapName += QLatin1String("_blue"); - if (!QPixmapCache::find(groovePixmapName, cache)) { + if (!QPixmapCache::find(groovePixmapName, &cache)) { cache = styleCachePixmap(pixmapRect.size()); cache.fill(Qt::transparent); QPainter groovePainter(&cache); @@ -2987,7 +2987,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption // draw handle if ((option->subControls & SC_SliderHandle) ) { QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size()); - if (!QPixmapCache::find(handlePixmapName, cache)) { + if (!QPixmapCache::find(handlePixmapName, &cache)) { cache = styleCachePixmap(handle.size()); cache.fill(Qt::transparent); QRect pixmapRect(0, 0, handle.width(), handle.height()); diff --git a/src/widgets/styles/qstyle_p.h b/src/widgets/styles/qstyle_p.h index 94e4540d0b..cdea29f944 100644 --- a/src/widgets/styles/qstyle_p.h +++ b/src/widgets/styles/qstyle_p.h @@ -96,7 +96,7 @@ inline QPixmap styleCachePixmap(const QSize &size) int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \ bool doPixmapCache = (!option->rect.isEmpty()) \ && ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \ - if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { \ + if (doPixmapCache && QPixmapCache::find(unique, &internalPixmapCache)) { \ painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \ } else { \ if (doPixmapCache) { \ From e56401818b1aae9856a5334f530c4eda33788429 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 26 Jan 2019 13:02:58 +0100 Subject: [PATCH 06/16] QtGui/QPainter: mark obsolete functions as deprecated Mark some long obsolete functions as deprecated so the can be removed with Qt6: - initFrom() - setMatrix()/matrix()/deviceMatrix()/resetMatrix() - setWorldMatrix()/worldMatrix()/combinedMatrix() - setMatrixEnabled()/matrixEnabled() - drawRoundRect() - setRedirected()/redirected()/restoreRedirected() Change-Id: I0daed72c0ef06c192309f02366a7201154e75ac9 Reviewed-by: Eirik Aavitsland --- src/gui/image/qpicture.cpp | 2 +- src/gui/painting/qpainter.cpp | 22 ++++++++++++++-- src/gui/painting/qpainter.h | 47 ++++++++++++++++++++++------------ src/widgets/kernel/qwidget.cpp | 4 +-- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 7eede5ee26..51a9575fd0 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -858,7 +858,7 @@ bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords) break; case QPicturePrivate::PdcSetWXform: s >> i_8; - painter->setMatrixEnabled(i_8); + painter->setWorldMatrixEnabled(i_8); break; case QPicturePrivate::PdcSetWMatrix: if (d->formatMajor >= 8) { diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 6626768d51..36f0d1d5b9 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -1547,6 +1547,7 @@ bool QPainter::isActive() const return d->engine; } +#if QT_DEPRECATED_SINCE(5, 13) /*! Initializes the painters pen, background and font to the same as the given \a device. @@ -1574,7 +1575,7 @@ void QPainter::initFrom(const QPaintDevice *device) d->engine->setDirty(QPaintEngine::DirtyFont); } } - +#endif /*! Saves the current painter state (pushes the state onto a stack). A @@ -2885,6 +2886,7 @@ void QPainter::setClipRegion(const QRegion &r, Qt::ClipOperation op) d->updateState(d->state); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \since 4.2 \obsolete @@ -3048,7 +3050,7 @@ void QPainter::resetMatrix() { resetTransform(); } - +#endif /*! \since 4.2 @@ -3099,6 +3101,7 @@ bool QPainter::worldMatrixEnabled() const return d->state->WxF; } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -3124,6 +3127,7 @@ bool QPainter::matrixEnabled() const { return worldMatrixEnabled(); } +#endif /*! Scales the coordinate system by (\a{sx}, \a{sy}). @@ -4182,6 +4186,7 @@ void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Draws the given rectangle \a x, \a y, \a w, \a h with rounded corners. */ +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -4209,6 +4214,10 @@ void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd) Draws the rectangle \a r with rounded corners. */ +void QPainter::drawRoundRect(const QRect &rect, int xRnd, int yRnd) +{ + drawRoundRect(QRectF(rect), xRnd, yRnd); +} /*! \obsolete @@ -4219,6 +4228,11 @@ void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd) Draws the rectangle \a x, \a y, \a w, \a h with rounded corners. */ +void QPainter::drawRoundRect(int x, int y, int w, int h, int xRnd, int yRnd) +{ + drawRoundRect(QRectF(x, y, w, h), xRnd, yRnd); +} +#endif /*! \fn void QPainter::drawEllipse(const QRectF &rectangle) @@ -7378,6 +7392,7 @@ void QPainter::setViewTransformEnabled(bool enable) d->updateMatrix(); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \threadsafe @@ -7458,6 +7473,7 @@ QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) Q_UNUSED(offset) return 0; } +#endif void qt_format_text(const QFont &fnt, const QRectF &_r, int tf, const QString& str, QRectF *brect, @@ -8067,6 +8083,7 @@ QFont QPaintEngineState::font() const return static_cast(this)->font; } +#if QT_DEPRECATED_SINCE(5, 13) /*! \since 4.2 \obsolete @@ -8089,6 +8106,7 @@ QMatrix QPaintEngineState::matrix() const return st->matrix.toAffine(); } +#endif /*! \since 4.3 diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 87c4899f0b..843f24e3e1 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -132,7 +132,10 @@ public: bool end(); bool isActive() const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use begin(QPaintDevice*) instead") void initFrom(const QPaintDevice *device); +#endif enum CompositionMode { CompositionMode_SourceOver, @@ -232,28 +235,40 @@ public: void restore(); // XForm functions +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use setTransform() instead") void setMatrix(const QMatrix &matrix, bool combine = false); + QT_DEPRECATED_X("Use transform() instead") const QMatrix &matrix() const; + QT_DEPRECATED_X("Use deviceTransform() instead") const QMatrix &deviceMatrix() const; + QT_DEPRECATED_X("Use resetTransform() instead") void resetMatrix(); +#endif void setTransform(const QTransform &transform, bool combine = false); const QTransform &transform() const; const QTransform &deviceTransform() const; void resetTransform(); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use setWorldTransform() instead") void setWorldMatrix(const QMatrix &matrix, bool combine = false); + QT_DEPRECATED_X("Use worldTransform() instead") const QMatrix &worldMatrix() const; + QT_DEPRECATED_X("Use combinedTransform() instead") + QMatrix combinedMatrix() const; + QT_DEPRECATED_X("Use setWorldMatrixEnabled() instead") + void setMatrixEnabled(bool enabled); + QT_DEPRECATED_X("Use worldMatrixEnabled() instead") + bool matrixEnabled() const; +#endif void setWorldTransform(const QTransform &matrix, bool combine = false); const QTransform &worldTransform() const; - QMatrix combinedMatrix() const; QTransform combinedTransform() const; - void setMatrixEnabled(bool enabled); - bool matrixEnabled() const; - void setWorldMatrixEnabled(bool enabled); bool worldMatrixEnabled() const; @@ -355,9 +370,14 @@ public: inline void drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use drawRoundedRect(..., Qt::RelativeSize) instead") void drawRoundRect(const QRectF &r, int xround = 25, int yround = 25); - inline void drawRoundRect(int x, int y, int w, int h, int = 25, int = 25); - inline void drawRoundRect(const QRect &r, int xround = 25, int yround = 25); + QT_DEPRECATED_X("Use drawRoundedRect(..., Qt::RelativeSize) instead") + void drawRoundRect(int x, int y, int w, int h, int = 25, int = 25); + QT_DEPRECATED_X("Use drawRoundedRect(..., Qt::RelativeSize) instead") + void drawRoundRect(const QRect &r, int xround = 25, int yround = 25); +#endif void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset = QPointF()); inline void drawTiledPixmap(int x, int y, int w, int h, const QPixmap &, int sx=0, int sy=0); @@ -464,10 +484,15 @@ public: QPaintEngine *paintEngine() const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use QWidget::render() instead") static void setRedirected(const QPaintDevice *device, QPaintDevice *replacement, const QPoint& offset = QPoint()); + QT_DEPRECATED_X("Use QWidget::render() instead") static QPaintDevice *redirected(const QPaintDevice *device, QPoint *offset = nullptr); + QT_DEPRECATED_X("Use QWidget::render() instead") static void restoreRedirected(const QPaintDevice *device); +#endif void beginNativePainting(); void endNativePainting(); @@ -629,16 +654,6 @@ inline void QPainter::drawPoints(const QPolygon &points) drawPoints(points.constData(), points.size()); } -inline void QPainter::drawRoundRect(int x, int y, int w, int h, int xRnd, int yRnd) -{ - drawRoundRect(QRectF(x, y, w, h), xRnd, yRnd); -} - -inline void QPainter::drawRoundRect(const QRect &rect, int xRnd, int yRnd) -{ - drawRoundRect(QRectF(rect), xRnd, yRnd); -} - inline void QPainter::drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode) { diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index c0430bec23..3b1d82df18 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5737,12 +5737,10 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, QPoint offset = targetOffset; offset -= paintRegion.boundingRect().topLeft(); QPoint redirectionOffset; - QPaintDevice *redirected = 0; + QPaintDevice *redirected = nullptr; if (target->devType() == QInternal::Widget) redirected = static_cast(target)->d_func()->redirected(&redirectionOffset); - if (!redirected) - redirected = QPainter::redirected(target, &redirectionOffset); if (redirected) { target = redirected; From 860bfc69e44c6b8d3cd0263c5afc729292aa639d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 26 Jan 2019 13:11:41 +0100 Subject: [PATCH 07/16] QtGui/QPainterPath: mark obsolete functions as deprecated Mark some long obsolete functions as deprecated so the can be removed with Qt6: - addRoundRect() - subtractedInverted() Change-Id: I4707c07e983a4ac65ec3706d25b09ec01a9de62c Reviewed-by: Eirik Aavitsland --- src/gui/painting/qpainterpath.cpp | 25 ++++++++++++++++++ src/gui/painting/qpainterpath.h | 43 ++++++++++--------------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 3687bcf7d0..cb8bb9dfcf 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -3242,6 +3242,7 @@ void QPainterPath::addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadi Adds the given rectangle \a x, \a y, \a w, \a h with rounded corners to the path. */ +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -3308,6 +3309,17 @@ void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) \sa addRoundedRect() */ +void QPainterPath::addRoundRect(const QRectF &rect, + int roundness) +{ + int xRnd = roundness; + int yRnd = roundness; + if (rect.width() > rect.height()) + xRnd = int(roundness * rect.height()/rect.width()); + else + yRnd = int(roundness * rect.width()/rect.height()); + addRoundRect(rect, xRnd, yRnd); +} /*! \obsolete @@ -3324,6 +3336,11 @@ void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) \sa addRoundedRect() */ +void QPainterPath::addRoundRect(qreal x, qreal y, qreal w, qreal h, + int xRnd, int yRnd) +{ + addRoundRect(QRectF(x, y, w, h), xRnd, yRnd); +} /*! \obsolete @@ -3343,6 +3360,12 @@ void QPainterPath::addRoundRect(const QRectF &r, int xRnd, int yRnd) \sa addRoundedRect() */ +void QPainterPath::addRoundRect(qreal x, qreal y, qreal w, qreal h, + int roundness) +{ + addRoundRect(QRectF(x, y, w, h), roundness); +} +#endif /*! \since 4.3 @@ -3397,6 +3420,7 @@ QPainterPath QPainterPath::subtracted(const QPainterPath &p) const return clipper.clip(QPathClipper::BoolSub); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \since 4.3 \obsolete @@ -3409,6 +3433,7 @@ QPainterPath QPainterPath::subtractedInverted(const QPainterPath &p) const { return p.subtracted(*this); } +#endif /*! \since 4.4 diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 770b8f48d0..a69a192767 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -143,12 +143,18 @@ public: qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use addRoundedRect(..., Qt::RelativeSize) instead") void addRoundRect(const QRectF &rect, int xRnd, int yRnd); - inline void addRoundRect(qreal x, qreal y, qreal w, qreal h, - int xRnd, int yRnd); - inline void addRoundRect(const QRectF &rect, int roundness); - inline void addRoundRect(qreal x, qreal y, qreal w, qreal h, - int roundness); + QT_DEPRECATED_X("Use addRoundedRect(..., Qt::RelativeSize) instead") + void addRoundRect(qreal x, qreal y, qreal w, qreal h, + int xRnd, int yRnd); + QT_DEPRECATED_X("Use addRoundedRect(..., Qt::RelativeSize) instead") + void addRoundRect(const QRectF &rect, int roundness); + QT_DEPRECATED_X("Use addRoundedRect(..., Qt::RelativeSize) instead") + void addRoundRect(qreal x, qreal y, qreal w, qreal h, + int roundness); +#endif void connectPath(const QPainterPath &path); @@ -193,7 +199,10 @@ public: Q_REQUIRED_RESULT QPainterPath united(const QPainterPath &r) const; Q_REQUIRED_RESULT QPainterPath intersected(const QPainterPath &r) const; Q_REQUIRED_RESULT QPainterPath subtracted(const QPainterPath &r) const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use r.subtracted() instead") Q_REQUIRED_RESULT QPainterPath subtractedInverted(const QPainterPath &r) const; +#endif Q_REQUIRED_RESULT QPainterPath simplified() const; @@ -338,30 +347,6 @@ inline void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h, addRoundedRect(QRectF(x, y, w, h), xRadius, yRadius, mode); } -inline void QPainterPath::addRoundRect(qreal x, qreal y, qreal w, qreal h, - int xRnd, int yRnd) -{ - addRoundRect(QRectF(x, y, w, h), xRnd, yRnd); -} - -inline void QPainterPath::addRoundRect(const QRectF &rect, - int roundness) -{ - int xRnd = roundness; - int yRnd = roundness; - if (rect.width() > rect.height()) - xRnd = int(roundness * rect.height()/rect.width()); - else - yRnd = int(roundness * rect.width()/rect.height()); - addRoundRect(rect, xRnd, yRnd); -} - -inline void QPainterPath::addRoundRect(qreal x, qreal y, qreal w, qreal h, - int roundness) -{ - addRoundRect(QRectF(x, y, w, h), roundness); -} - inline void QPainterPath::addText(qreal x, qreal y, const QFont &f, const QString &text) { addText(QPointF(x, y), f, text); From 2bfb89e133b8dcb138e046700ef4fbecb9da8fa0 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 27 Jan 2019 17:48:33 +0100 Subject: [PATCH 08/16] QtWidgets: replace 0 with \nullptr in documentation Replace 0 with \nullptr in the documentation. As a drive-by also replace some 0 with nullptr in the corresponding code. Change-Id: Id8056dc2364a372e40bc04e8cb9fcc443e49fb18 Reviewed-by: Paul Wicking --- .../graphicsview/qgraphicsgridlayout.cpp | 11 +-- src/widgets/graphicsview/qgraphicsitem.cpp | 96 ++++++++++--------- .../graphicsview/qgraphicslayoutitem.cpp | 14 +-- .../graphicsview/qgraphicsproxywidget.cpp | 4 +- src/widgets/graphicsview/qgraphicsscene.cpp | 43 +++++---- .../graphicsview/qgraphicssceneevent.cpp | 4 +- src/widgets/graphicsview/qgraphicsview.cpp | 2 +- src/widgets/graphicsview/qgraphicswidget.cpp | 32 +++---- src/widgets/itemviews/qabstractitemview.cpp | 4 +- src/widgets/itemviews/qcolumnview.cpp | 2 +- src/widgets/itemviews/qtableview.cpp | 9 +- src/widgets/itemviews/qtreewidget.cpp | 16 ++-- 12 files changed, 120 insertions(+), 117 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsgridlayout.cpp b/src/widgets/graphicsview/qgraphicsgridlayout.cpp index d9005afbef..6b7052a0ab 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayout.cpp +++ b/src/widgets/graphicsview/qgraphicsgridlayout.cpp @@ -552,20 +552,19 @@ int QGraphicsGridLayout::count() const } /*! - Returns the layout item at \a index, or 0 if there is no layout item at - this index. + Returns the layout item at \a index, or \nullptr if there is no + layout item at this index. */ QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const { Q_D(const QGraphicsGridLayout); if (index < 0 || index >= d->engine.itemCount()) { qWarning("QGraphicsGridLayout::itemAt: invalid index %d", index); - return 0; + return nullptr; } - QGraphicsLayoutItem *item = 0; if (QGraphicsGridLayoutEngineItem *engineItem = static_cast(d->engine.itemAt(index))) - item = engineItem->layoutItem(); - return item; + return engineItem->layoutItem(); + return nullptr; } /*! diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 86f3d6a2f0..4476ecded3 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -661,9 +661,9 @@ \value ItemSceneChange The item is moved to a new scene. This notification is also sent when the item is added to its initial scene, and when it is removed. - The item's scene() is the old scene (or 0 if the item has not been added to a - scene yet). The value argument is the new scene (i.e., a QGraphicsScene - pointer), or a null pointer if the item is removed from a scene. Do not + The item's scene() is the old scene, or \nullptr if the item has not been added + to a scene yet. The value argument is the new scene (i.e., a QGraphicsScene + pointer), or \nullptr if the item is removed from a scene. Do not override this change by passing this item to QGraphicsScene::addItem() as this notification is delivered; instead, you can return the new scene from itemChange(). Use this feature with caution; objecting to a scene change can @@ -1542,7 +1542,7 @@ void QGraphicsItemCache::purge() Constructs a QGraphicsItem with the given \a parent item. It does not modify the parent object returned by QObject::parent(). - If \a parent is 0, you can add the item to a scene by calling + If \a parent is \nullptr, you can add the item to a scene by calling QGraphicsScene::addItem(). The item will then become a top-level item. \sa QGraphicsScene::addItem(), setParentItem() @@ -1650,8 +1650,8 @@ QGraphicsItem::~QGraphicsItem() } /*! - Returns the current scene for the item, or 0 if the item is not stored in - a scene. + Returns the current scene for the item, or \nullptr if the item is + not stored in a scene. To add or move an item to a scene, call QGraphicsScene::addItem(). */ @@ -1661,15 +1661,15 @@ QGraphicsScene *QGraphicsItem::scene() const } /*! - Returns a pointer to this item's item group, or 0 if this item is not - member of a group. + Returns a pointer to this item's item group, or \nullptr if this + item is not member of a group. \sa QGraphicsItemGroup, QGraphicsScene::createItemGroup() */ QGraphicsItemGroup *QGraphicsItem::group() const { if (!d_ptr->isMemberOfGroup) - return 0; + return nullptr; QGraphicsItem *parent = const_cast(this); while ((parent = parent->d_ptr->parent)) { if (QGraphicsItemGroup *group = qgraphicsitem_cast(parent)) @@ -1677,11 +1677,11 @@ QGraphicsItemGroup *QGraphicsItem::group() const } // Unreachable; if d_ptr->isMemberOfGroup is != 0, then one parent of this // item is a group item. - return 0; + return nullptr; } /*! - Adds this item to the item group \a group. If \a group is 0, this item is + Adds this item to the item group \a group. If \a group is \nullptr, this item is removed from any current group and added as a child of the previous group's parent. @@ -1699,7 +1699,7 @@ void QGraphicsItem::setGroup(QGraphicsItemGroup *group) /*! Returns a pointer to this item's parent item. If this item does not have a - parent, 0 is returned. + parent, \nullptr is returned. \sa setParentItem(), childItems() */ @@ -1710,8 +1710,9 @@ QGraphicsItem *QGraphicsItem::parentItem() const /*! Returns this item's top-level item. The top-level item is the item's - topmost ancestor item whose parent is 0. If an item has no parent, its own - pointer is returned (i.e., a top-level item is its own top-level item). + topmost ancestor item whose parent is \nullptr. If an item has no + parent, its own pointer is returned (i.e., a top-level item is its + own top-level item). \sa parentItem() */ @@ -1734,7 +1735,7 @@ QGraphicsItem *QGraphicsItem::topLevelItem() const QGraphicsObject *QGraphicsItem::parentObject() const { QGraphicsItem *p = d_ptr->parent; - return (p && p->d_ptr->isObject) ? static_cast(p) : 0; + return (p && p->d_ptr->isObject) ? static_cast(p) : nullptr; } /*! @@ -1757,23 +1758,24 @@ QGraphicsWidget *QGraphicsItem::parentWidget() const \since 4.4 Returns a pointer to the item's top level widget (i.e., the item's - ancestor whose parent is 0, or whose parent is not a widget), or 0 if this - item does not have a top level widget. If the item is its own top level - widget, this function returns a pointer to the item itself. + ancestor whose parent is \nullptr, or whose parent is not a widget), or + \nullptr if this item does not have a top level widget. If the item + is its own top level widget, this function returns a pointer to the + item itself. */ QGraphicsWidget *QGraphicsItem::topLevelWidget() const { if (const QGraphicsWidget *p = parentWidget()) return p->topLevelWidget(); - return isWidget() ? static_cast(const_cast(this)) : 0; + return isWidget() ? static_cast(const_cast(this)) : nullptr; } /*! \since 4.4 - Returns the item's window, or 0 if this item does not have a window. If - the item is a window, it will return itself. Otherwise it will return the - closest ancestor that is a window. + Returns the item's window, or \nullptr if this item does not have a + window. If the item is a window, it will return itself. Otherwise + it will return the closest ancestor that is a window. \sa QGraphicsWidget::isWindow() */ @@ -1782,15 +1784,15 @@ QGraphicsWidget *QGraphicsItem::window() const QGraphicsItem *p = panel(); if (p && p->isWindow()) return static_cast(p); - return 0; + return nullptr; } /*! \since 4.6 - Returns the item's panel, or 0 if this item does not have a panel. If the - item is a panel, it will return itself. Otherwise it will return the - closest ancestor that is a panel. + Returns the item's panel, or \nullptr if this item does not have a + panel. If the item is a panel, it will return itself. Otherwise it + will return the closest ancestor that is a panel. \sa isPanel(), ItemIsPanel */ @@ -1798,7 +1800,7 @@ QGraphicsItem *QGraphicsItem::panel() const { if (d_ptr->flags & ItemIsPanel) return const_cast(this); - return d_ptr->parent ? d_ptr->parent->panel() : 0; + return d_ptr->parent ? d_ptr->parent->panel() : nullptr; } /*! @@ -2397,7 +2399,7 @@ bool QGraphicsItem::isVisible() const /*! \since 4.4 Returns \c true if the item is visible to \a parent; otherwise, false is - returned. \a parent can be 0, in which case this function will return + returned. \a parent can be \nullptr, in which case this function will return whether the item is visible to the scene or not. An item may not be visible to its ancestors even if isVisible() is true. It @@ -2925,7 +2927,7 @@ void QGraphicsItem::setOpacity(qreal opacity) } /*! - Returns a pointer to this item's effect if it has one; otherwise 0. + Returns a pointer to this item's effect if it has one; otherwise \nullptr. \since 4.6 */ @@ -2939,7 +2941,7 @@ QGraphicsEffect *QGraphicsItem::graphicsEffect() const Sets \a effect as the item's effect. If there already is an effect installed on this item, QGraphicsItem will delete the existing effect before installing the new \a effect. You can delete an existing effect by calling - setGraphicsEffect(0). + setGraphicsEffect(\nullptr). If \a effect is the installed effect on a different item, setGraphicsEffect() will remove the effect from the item and install it on this item. @@ -3577,7 +3579,7 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB /*! \since 4.6 - Returns this item's focus proxy, or 0 if this item has no + Returns this item's focus proxy, or \nullptr if this item has no focus proxy. \sa setFocusProxy(), setFocus(), hasFocus() @@ -3640,7 +3642,7 @@ void QGraphicsItem::setFocusProxy(QGraphicsItem *item) If this item, a child or descendant of this item currently has input focus, this function will return a pointer to that item. If - no descendant has input focus, 0 is returned. + no descendant has input focus, \nullptr is returned. \sa hasFocus(), setFocus(), QWidget::focusWidget() */ @@ -5790,7 +5792,7 @@ void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem, QGraphicsItem /*! \internal - Sets the focusProxy pointer to 0 for all items that have this item as their + Sets the focusProxy pointer to \nullptr for all items that have this item as their focusProxy. */ void QGraphicsItemPrivate::resetFocusProxy() @@ -6001,7 +6003,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) Maps the point \a point, which is in this item's coordinate system, to \a item's coordinate system, and returns the mapped coordinate. - If \a item is 0, this function returns the same as mapToScene(). + If \a item is \nullptr, this function returns the same as mapToScene(). \sa itemTransform(), mapToParent(), mapToScene(), transform(), mapFromItem(), {The Graphics View Coordinate System} @@ -6071,7 +6073,7 @@ QPointF QGraphicsItem::mapToScene(const QPointF &point) const Maps the rectangle \a rect, which is in this item's coordinate system, to \a item's coordinate system, and returns the mapped rectangle as a polygon. - If \a item is 0, this function returns the same as mapToScene(). + If \a item is \nullptr, this function returns the same as mapToScene(). \sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System} @@ -6142,7 +6144,7 @@ QPolygonF QGraphicsItem::mapToScene(const QRectF &rect) const \a item's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon). - If \a item is 0, this function returns the same as mapRectToScene(). + If \a item is \nullptr, this function returns the same as mapRectToScene(). \sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System} @@ -6217,7 +6219,7 @@ QRectF QGraphicsItem::mapRectToScene(const QRectF &rect) const this item's coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon). - If \a item is 0, this function returns the same as mapRectFromScene(). + If \a item is \nullptr, this function returns the same as mapRectFromScene(). \sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System} @@ -6290,7 +6292,7 @@ QRectF QGraphicsItem::mapRectFromScene(const QRectF &rect) const Maps the polygon \a polygon, which is in this item's coordinate system, to \a item's coordinate system, and returns the mapped polygon. - If \a item is 0, this function returns the same as mapToScene(). + If \a item is \nullptr, this function returns the same as mapToScene(). \sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System} @@ -6337,7 +6339,7 @@ QPolygonF QGraphicsItem::mapToScene(const QPolygonF &polygon) const Maps the path \a path, which is in this item's coordinate system, to \a item's coordinate system, and returns the mapped path. - If \a item is 0, this function returns the same as mapToScene(). + If \a item is \nullptr, this function returns the same as mapToScene(). \sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The Graphics View Coordinate System} @@ -6384,7 +6386,7 @@ QPainterPath QGraphicsItem::mapToScene(const QPainterPath &path) const Maps the point \a point, which is in \a item's coordinate system, to this item's coordinate system, and returns the mapped coordinate. - If \a item is 0, this function returns the same as mapFromScene(). + If \a item is \nullptr, this function returns the same as mapFromScene(). \sa itemTransform(), mapFromParent(), mapFromScene(), transform(), mapToItem(), {The Graphics View Coordinate System} @@ -6456,7 +6458,7 @@ QPointF QGraphicsItem::mapFromScene(const QPointF &point) const this item's coordinate system, and returns the mapped rectangle as a polygon. - If \a item is 0, this function returns the same as mapFromScene() + If \a item is \nullptr, this function returns the same as mapFromScene() \sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate System} @@ -6524,7 +6526,7 @@ QPolygonF QGraphicsItem::mapFromScene(const QRectF &rect) const Maps the polygon \a polygon, which is in \a item's coordinate system, to this item's coordinate system, and returns the mapped polygon. - If \a item is 0, this function returns the same as mapFromScene(). + If \a item is \nullptr, this function returns the same as mapFromScene(). \sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate System} @@ -6569,7 +6571,7 @@ QPolygonF QGraphicsItem::mapFromScene(const QPolygonF &polygon) const Maps the path \a path, which is in \a item's coordinate system, to this item's coordinate system, and returns the mapped path. - If \a item is 0, this function returns the same as mapFromScene(). + If \a item is \nullptr, this function returns the same as mapFromScene(). \sa itemTransform(), mapFromParent(), mapFromScene(), mapToItem(), {The Graphics View Coordinate System} @@ -6633,15 +6635,15 @@ bool QGraphicsItem::isAncestorOf(const QGraphicsItem *child) const /*! \since 4.4 - Returns the closest common ancestor item of this item and \a other, or 0 - if either \a other is 0, or there is no common ancestor. + Returns the closest common ancestor item of this item and \a other, + or \nullptr if either \a other is \nullptr, or there is no common ancestor. \sa isAncestorOf() */ QGraphicsItem *QGraphicsItem::commonAncestorItem(const QGraphicsItem *other) const { if (!other) - return 0; + return nullptr; if (other == this) return const_cast(this); const QGraphicsItem *thisw = this; @@ -6726,7 +6728,7 @@ void QGraphicsItem::setData(int key, const QVariant &value) \since 4.2 Returns the given \a item cast to type T if \a item is of type T; - otherwise, 0 is returned. + otherwise, \nullptr is returned. \note To make this function work correctly with custom items, reimplement the \l{QGraphicsItem::}{type()} function for each custom QGraphicsItem diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.cpp b/src/widgets/graphicsview/qgraphicslayoutitem.cpp index aed154a95f..1192bad51e 100644 --- a/src/widgets/graphicsview/qgraphicslayoutitem.cpp +++ b/src/widgets/graphicsview/qgraphicslayoutitem.cpp @@ -193,7 +193,7 @@ QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint) /*! \internal - Returns the parent item of this layout, or 0 if this layout is + Returns the parent item of this layout, or \nullptr if this layout is not installed on any widget. If this is the item that the layout is installed on, it will return "itself". @@ -214,7 +214,7 @@ QGraphicsItem *QGraphicsLayoutItemPrivate::parentItem() const while (parent && parent->isLayout()) { parent = parent->parentLayoutItem(); } - return parent ? parent->graphicsItem() : 0; + return parent ? parent->graphicsItem() : nullptr; } /*! @@ -368,7 +368,7 @@ bool QGraphicsLayoutItemPrivate::hasWidthForHeight() const passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's protected constructor, or by calling setParentLayoutItem(). The parentLayoutItem() function returns a pointer to the item's layoutItem - parent. If the item's parent is 0 or if the parent does not inherit + parent. If the item's parent is \nullptr or if the parent does not inherit from QGraphicsItem, the parentLayoutItem() function then returns \nullptr. isLayout() returns \c true if the QGraphicsLayoutItem subclass is itself a layout, or false otherwise. @@ -737,7 +737,7 @@ QRectF QGraphicsLayoutItem::geometry() const This virtual function provides the \a left, \a top, \a right and \a bottom contents margins for this QGraphicsLayoutItem. The default implementation assumes all contents margins are 0. The parameters point to values stored - in qreals. If any of the pointers is 0, that value will not be updated. + in qreals. If any of the pointers is \nullptr, that value will not be updated. \sa QGraphicsWidget::setContentsMargins() */ @@ -826,8 +826,8 @@ void QGraphicsLayoutItem::updateGeometry() } /*! - Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, - or if the parent does not inherit from QGraphicsLayoutItem + Returns the parent of this QGraphicsLayoutItem, or \nullptr if there is + no parent, or if the parent does not inherit from QGraphicsLayoutItem (QGraphicsLayoutItem is often used through multiple inheritance with QObject-derived classes). @@ -917,7 +917,7 @@ QGraphicsItem *QGraphicsLayoutItem::graphicsItem() const * advantage of the automatic reparenting capabilities of QGraphicsLayout it * should set this value. * Note that if you delete \a item and not delete the layout item, you are - * responsible of calling setGraphicsItem(0) in order to avoid having a + * responsible of calling setGraphicsItem(\nullptr) in order to avoid having a * dangling pointer. * * \sa graphicsItem() diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index 513cf9d361..e9f092020f 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -556,7 +556,7 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget() exclusively either inside or outside of Graphics View. You cannot embed a widget as long as it is is visible elsewhere in the UI, at the same time. - \a widget must be a top-level widget whose parent is 0. + \a widget must be a top-level widget whose parent is \nullptr. When the widget is embedded, its state (e.g., visible, enabled, geometry, size hints) is copied into the proxy widget. If the embedded widget is @@ -739,7 +739,7 @@ QWidget *QGraphicsProxyWidget::widget() const Returns the rectangle for \a widget, which must be a descendant of widget(), or widget() itself, in this proxy item's local coordinates. - If no widget is embedded, \a widget is 0, or \a widget is not a + If no widget is embedded, \a widget is \nullptr, or \a widget is not a descendant of the embedded widget, this function returns an empty QRectF. \sa widget() diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index bba992144d..db7ce5251a 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -2144,8 +2144,8 @@ QList QGraphicsScene::collidingItems(const QGraphicsItem *item, \overload \obsolete - Returns the topmost visible item at the specified \a position, or 0 if - there are no items at this position. + Returns the topmost visible item at the specified \a position, or + \nullptr if there are no items at this position. This function is deprecated and returns incorrect results if the scene contains items that ignore transformations. Use the overload that takes @@ -2159,7 +2159,7 @@ QList QGraphicsScene::collidingItems(const QGraphicsItem *item, /*! \since 4.6 - Returns the topmost visible item at the specified \a position, or 0 + Returns the topmost visible item at the specified \a position, or \nullptr if there are no items at this position. \a deviceTransform is the transformation that applies to the view, and needs to @@ -2173,7 +2173,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform { const QList itemsAtPoint = items(position, Qt::IntersectsItemShape, Qt::DescendingOrder, deviceTransform); - return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first(); + return itemsAtPoint.isEmpty() ? nullptr : itemsAtPoint.first(); } /*! @@ -2182,7 +2182,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform \since 4.6 Returns the topmost visible item at the position specified by (\a x, \a - y), or 0 if there are no items at this position. + y), or \nullptr if there are no items at this position. \a deviceTransform is the transformation that applies to the view, and needs to be provided if the scene contains items that ignore transformations. @@ -2199,7 +2199,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform \obsolete Returns the topmost visible item at the position specified by (\a x, \a - y), or 0 if there are no items at this position. + y), or \nullptr if there are no items at this position. This convenience function is equivalent to calling \c {itemAt(QPointF(x, y))}. @@ -2941,9 +2941,9 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) /*! When the scene is active, this functions returns the scene's current focus - item, or 0 if no item currently has focus. When the scene is inactive, this - functions returns the item that will gain input focus when the scene becomes - active. + item, or \nullptr if no item currently has focus. When the scene is inactive, + this functions returns the item that will gain input focus when the scene + becomes active. The focus item receives keyboard input when the scene receives a key event. @@ -2961,12 +2961,12 @@ QGraphicsItem *QGraphicsScene::focusItem() const focusReason, after removing focus from any previous item that may have had focus. - If \a item is 0, or if it either does not accept focus (i.e., it does not + If \a item is \nullptr, or if it either does not accept focus (i.e., it does not have the QGraphicsItem::ItemIsFocusable flag enabled), or is not visible or not enabled, this function only removes focus from any previous focusitem. - If item is not 0, and the scene does not currently have focus (i.e., + If item is not \nullptr, and the scene does not currently have focus (i.e., hasFocus() returns \c false), this function will call setFocus() automatically. @@ -3062,9 +3062,9 @@ bool QGraphicsScene::stickyFocus() const } /*! - Returns the current mouse grabber item, or 0 if no item is currently - grabbing the mouse. The mouse grabber item is the item that receives all - mouse events sent to the scene. + Returns the current mouse grabber item, or \nullptr if no item is + currently grabbing the mouse. The mouse grabber item is the item + that receives all mouse events sent to the scene. An item becomes a mouse grabber when it receives and accepts a mouse press event, and it stays the mouse grabber until either of @@ -5547,7 +5547,7 @@ bool QGraphicsScene::focusNextPrevChild(bool next) \a oldFocusItem is a pointer to the item that previously had focus, or 0 if no item had focus before the signal was emitted. \a newFocusItem - is a pointer to the item that gained input focus, or 0 if focus was lost. + is a pointer to the item that gained input focus, or \nullptr if focus was lost. \a reason is the reason for the focus change (e.g., if the scene was deactivated while an input field had focus, \a oldFocusItem would point to the input field item, \a newFocusItem would be 0, and \a reason would be @@ -5582,7 +5582,7 @@ QStyle *QGraphicsScene::style() const the style for all widgets in the scene that do not have a style explicitly assigned to them. - If \a style is 0, QGraphicsScene will revert to QApplication::style(). + If \a style is \nullptr, QGraphicsScene will revert to QApplication::style(). \sa style() */ @@ -5703,7 +5703,8 @@ bool QGraphicsScene::isActive() const /*! \since 4.6 - Returns the current active panel, or 0 if no panel is currently active. + Returns the current active panel, or \nullptr if no panel is + currently active. \sa QGraphicsScene::setActivePanel() */ @@ -5720,7 +5721,7 @@ QGraphicsItem *QGraphicsScene::activePanel() const deactivate any currently active panel. If the scene is currently inactive, \a item remains inactive until the - scene becomes active (or, ir \a item is 0, no item will be activated). + scene becomes active (or, ir \a item is \nullptr, no item will be activated). \sa activePanel(), isActive(), QGraphicsItem::isActive() */ @@ -5733,8 +5734,8 @@ void QGraphicsScene::setActivePanel(QGraphicsItem *item) /*! \since 4.4 - Returns the current active window, or 0 if no window is currently - active. + Returns the current active window, or \nullptr if no window is + currently active. \sa QGraphicsScene::setActiveWindow() */ @@ -5743,7 +5744,7 @@ QGraphicsWidget *QGraphicsScene::activeWindow() const Q_D(const QGraphicsScene); if (d->activePanel && d->activePanel->isWindow()) return static_cast(d->activePanel); - return 0; + return nullptr; } /*! diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp index 398ef1aaf5..5077a39d67 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.cpp +++ b/src/widgets/graphicsview/qgraphicssceneevent.cpp @@ -319,8 +319,8 @@ QGraphicsSceneEvent::~QGraphicsSceneEvent() } /*! - Returns the widget where the event originated, or 0 if the event - originates from another application. + Returns the widget where the event originated, or \nullptr if the + event originates from another application. */ QWidget *QGraphicsSceneEvent::widget() const { diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 24647dd74c..5fe520132f 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -1676,7 +1676,7 @@ void QGraphicsView::setInteractive(bool allowed) /*! Returns a pointer to the scene that is currently visualized in the - view. If no scene is currently visualized, 0 is returned. + view. If no scene is currently visualized, \nullptr is returned. \sa setScene() */ diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp index a4534c73dd..c994136091 100644 --- a/src/widgets/graphicsview/qgraphicswidget.cpp +++ b/src/widgets/graphicsview/qgraphicswidget.cpp @@ -159,7 +159,7 @@ QT_BEGIN_NAMESPACE manage the relationships between parent and child items. These functions control the stacking order of items as well as their ownership. - \note The QObject::parent() should always return 0 for QGraphicsWidgets, + \note The QObject::parent() should always return \nullptr for QGraphicsWidgets, but this policy is not strictly defined. \sa QGraphicsProxyWidget, QGraphicsItem, {Widgets and Layouts} @@ -518,7 +518,7 @@ void QGraphicsWidget::setContentsMargins(qreal left, qreal top, qreal right, qre /*! Gets the widget's contents margins. The margins are stored in \a left, \a top, \a right and \a bottom, as pointers to qreals. Each argument can - be \e {omitted} by passing 0. + be \e {omitted} by passing \nullptr. \sa setContentsMargins() */ @@ -573,7 +573,7 @@ void QGraphicsWidget::setWindowFrameMargins(qreal left, qreal top, qreal right, /*! Gets the widget's window frame margins. The margins are stored in \a left, \a top, \a right and \a bottom as pointers to qreals. Each argument can - be \e {omitted} by passing 0. + be \e {omitted} by passing \nullptr. \sa setWindowFrameMargins(), windowFrameRect() */ @@ -780,7 +780,7 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c \brief The layout of the widget Any existing layout manager is deleted before the new layout is assigned. If - \a layout is 0, the widget is left without a layout. Existing subwidgets' + \a layout is \nullptr, the widget is left without a layout. Existing subwidgets' geometries will remain unaffected. QGraphicsWidget takes ownership of \a layout. @@ -792,7 +792,7 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c explicitly managed by \a layout remain unaffected by the layout after it has been assigned to this widget. - If no layout is currently managing this widget, layout() will return 0. + If no layout is currently managing this widget, layout() will return \nullptr. */ @@ -803,8 +803,8 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c */ /*! - Returns this widget's layout, or 0 if no layout is currently managing this - widget. + Returns this widget's layout, or \nullptr if no layout is currently + managing this widget. \sa setLayout() */ @@ -818,7 +818,7 @@ QGraphicsLayout *QGraphicsWidget::layout() const \fn void QGraphicsWidget::setLayout(QGraphicsLayout *layout) Sets the layout for this widget to \a layout. Any existing layout manager - is deleted before the new layout is assigned. If \a layout is 0, the + is deleted before the new layout is assigned. If \a layout is \nullptr, the widget is left without a layout. Existing subwidgets' geometries will remain unaffected. @@ -937,11 +937,11 @@ QStyle *QGraphicsWidget::style() const Sets the widget's style to \a style. QGraphicsWidget does \e not take ownership of \a style. - If no style is assigned, or \a style is 0, the widget will use + If no style is assigned, or \a style is \nullptr, the widget will use QGraphicsScene::style() (if this has been set). Otherwise the widget will use QApplication::style(). - This function sets the Qt::WA_SetStyle attribute if \a style is not 0; + This function sets the Qt::WA_SetStyle attribute if \a style is not \nullptr; otherwise it clears the attribute. \sa style() @@ -1871,7 +1871,7 @@ void QGraphicsWidget::setFocusPolicy(Qt::FocusPolicy policy) /*! If this widget, a child or descendant of this widget currently has input focus, this function will return a pointer to that widget. If - no descendant widget has input focus, 0 is returned. + no descendant widget has input focus, \nullptr is returned. \sa QGraphicsItem::focusItem(), QWidget::focusWidget() */ @@ -1880,7 +1880,7 @@ QGraphicsWidget *QGraphicsWidget::focusWidget() const Q_D(const QGraphicsWidget); if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget) return static_cast(d->subFocusItem); - return 0; + return nullptr; } #ifndef QT_NO_SHORTCUT @@ -2022,7 +2022,7 @@ void QGraphicsWidget::addActions(QList actions) \since 4.5 Inserts the action \a action to this widget's list of actions, - before the action \a before. It appends the action if \a before is 0 or + before the action \a before. It appends the action if \a before is \nullptr or \a before is not a valid action for this widget. A QGraphicsWidget should only have one of each action. @@ -2062,7 +2062,7 @@ void QGraphicsWidget::insertAction(QAction *before, QAction *action) \since 4.5 Inserts the actions \a actions to this widget's list of actions, - before the action \a before. It appends the action if \a before is 0 or + before the action \a before. It appends the action if \a before is \nullptr or \a before is not a valid action for this widget. A QGraphicsWidget can have at most one of each action. @@ -2131,9 +2131,9 @@ QList QGraphicsWidget::actions() const \snippet code/src_gui_graphicsview_qgraphicswidget.cpp 2 - If \a first is 0, this indicates that \a second should be the first widget + If \a first is \nullptr, this indicates that \a second should be the first widget to receive input focus should the scene gain Tab focus (i.e., the user - hits Tab so that focus passes into the scene). If \a second is 0, this + hits Tab so that focus passes into the scene). If \a second is \nullptr, this indicates that \a first should be the first widget to gain focus if the scene gained BackTab focus. diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 1151379e17..7441161e13 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -940,8 +940,8 @@ void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *de \since 4.2 Returns the item delegate used by this view and model for the given \a row, - or 0 if no delegate has been assigned. You can call itemDelegate() to get a - pointer to the current delegate for a given index. + or \nullptr if no delegate has been assigned. You can call itemDelegate() + to get a pointer to the current delegate for a given index. \sa setItemDelegateForRow(), itemDelegateForColumn(), setItemDelegate() */ diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp index 1fe17721ba..a4eed2d885 100644 --- a/src/widgets/itemviews/qcolumnview.cpp +++ b/src/widgets/itemviews/qcolumnview.cpp @@ -801,7 +801,7 @@ void QColumnView::initializeColumn(QAbstractItemView *column) const } /*! - Returns the preview widget, or 0 if there is none. + Returns the preview widget, or \nullptr if there is none. \sa setPreviewWidget(), updatePreviewWidget() */ diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index a7d144672c..dd43c6d3e4 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -138,20 +138,21 @@ void QSpanCollection::updateSpan(QSpanCollection::Span *span, int old_height) } /** \internal - * \return a spans that spans over cell x,y (column,row) or 0 if there is none. + * \return a spans that spans over cell x,y (column,row) + * or \nullptr if there is none. */ QSpanCollection::Span *QSpanCollection::spanAt(int x, int y) const { Index::const_iterator it_y = index.lowerBound(-y); if (it_y == index.end()) - return 0; + return nullptr; SubIndex::const_iterator it_x = (*it_y).lowerBound(-x); if (it_x == (*it_y).end()) - return 0; + return nullptr; Span *span = *it_x; if (span->right() >= x && span->bottom() >= y) return span; - return 0; + return nullptr; } diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 6050bcd616..29cc199526 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -2539,8 +2539,8 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, QStyle::SH_ItemView_ActivateItemOnSingleClick style hint) or pressing a special key (e.g., \uicontrol Enter). - The specified \a item is the item that was clicked, or 0 if no - item was clicked. The \a column is the item's column that was + The specified \a item is the item that was clicked, or \nullptr if + no item was clicked. The \a column is the item's column that was clicked, or -1 if no item was clicked. */ @@ -2550,8 +2550,8 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, This signal is emitted when the user presses a mouse button inside the widget. - The specified \a item is the item that was clicked, or 0 if no - item was clicked. The \a column is the item's column that was + The specified \a item is the item that was clicked, or \nullptr if + no item was clicked. The \a column is the item's column that was clicked, or -1 if no item was clicked. */ @@ -2571,8 +2571,8 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, This signal is emitted when the user double clicks inside the widget. - The specified \a item is the item that was clicked, or 0 if no - item was clicked. The \a column is the item's column that was + The specified \a item is the item that was clicked, or \nullptr if + no item was clicked. The \a column is the item's column that was clicked. If no item was double clicked, no signal will be emitted. */ @@ -2724,8 +2724,8 @@ QTreeWidgetItem *QTreeWidget::invisibleRootItem() const } /*! - Returns the top level item at the given \a index, or 0 if the item does - not exist. + Returns the top level item at the given \a index, or \nullptr if the + item does not exist. \sa topLevelItemCount(), insertTopLevelItem() */ From ae44da62ef30503a5380e5d1ee8b0cadd5960994 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 27 Jan 2019 17:49:29 +0100 Subject: [PATCH 09/16] QtGui: replace 0 with \nullptr in documentation Replace 0 with \nullptr in the documentation. As a drive-by also replace some 0 with nullptr in the corresponding code. Change-Id: Ieffbfffa76e3018257b667a3e8ad6e3b88486cde Reviewed-by: Paul Wicking --- src/gui/image/qimageiohandler.cpp | 2 +- src/gui/image/qimagereader.cpp | 6 +++--- src/gui/image/qimagewriter.cpp | 4 ++-- src/gui/image/qmovie.cpp | 2 +- src/gui/image/qpicture.cpp | 6 +++--- src/gui/kernel/qcursor.cpp | 8 ++++---- src/gui/kernel/qopenglcontext.cpp | 7 +++---- src/gui/kernel/qplatformwindow.cpp | 4 ++-- src/gui/painting/qpainter.cpp | 2 +- src/gui/text/qtextdocumentwriter.cpp | 4 ++-- src/gui/text/qtextobject.cpp | 12 ++++++------ 11 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp index 9fe3b863b3..0e7b541cf2 100644 --- a/src/gui/image/qimageiohandler.cpp +++ b/src/gui/image/qimageiohandler.cpp @@ -340,7 +340,7 @@ void QImageIOHandler::setDevice(QIODevice *device) /*! Returns the device currently assigned to the QImageIOHandler. If - not device has been assigned, 0 is returned. + not device has been assigned, \nullptr is returned. */ QIODevice *QImageIOHandler::device() const { diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 3f1297c81a..61f20e0c65 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -756,13 +756,13 @@ void QImageReader::setDevice(QIODevice *device) d->device = device; d->deleteDevice = false; delete d->handler; - d->handler = 0; + d->handler = nullptr; d->text.clear(); } /*! - Returns the device currently assigned to QImageReader, or 0 if no - device has been assigned. + Returns the device currently assigned to QImageReader, or \nullptr + if no device has been assigned. */ QIODevice *QImageReader::device() const { diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index 41048fa681..ec66588ddf 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -407,8 +407,8 @@ void QImageWriter::setDevice(QIODevice *device) } /*! - Returns the device currently assigned to QImageWriter, or 0 if no - device has been assigned. + Returns the device currently assigned to QImageWriter, or \nullptr + if no device has been assigned. */ QIODevice *QImageWriter::device() const { diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index 7d17b7d5ef..79203c7b98 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -659,7 +659,7 @@ void QMovie::setDevice(QIODevice *device) /*! Returns the device QMovie reads image data from. If no device has - currently been assigned, 0 is returned. + currently been assigned, \nullptr is returned. \sa setDevice(), fileName() */ diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 51a9575fd0..6e57f679d8 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -1200,8 +1200,8 @@ QT_END_INCLUDE_NAMESPACE \obsolete Returns a string that specifies the picture format of the file \a - fileName, or 0 if the file cannot be read or if the format is not - recognized. + fileName, or \nullptr if the file cannot be read or if the format + is not recognized. \sa load(), save() */ @@ -1543,7 +1543,7 @@ const QPicture &QPictureIO::picture() const { return d->pi; } int QPictureIO::status() const { return d->iostat; } /*! - Returns the picture format string or 0 if no format has been + Returns the picture format string or \nullptr if no format has been explicitly set. */ const char *QPictureIO::format() const { return d->frmt; } diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index bb81ca109a..9e4787589f 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -564,8 +564,8 @@ void QCursor::setShape(Qt::CursorShape shape) } /*! - Returns the cursor bitmap, or 0 if it is one of the standard - cursors. + Returns the cursor bitmap, or \nullptr if it is one of the + standard cursors. */ const QBitmap *QCursor::bitmap() const { @@ -575,8 +575,8 @@ const QBitmap *QCursor::bitmap() const } /*! - Returns the cursor bitmap mask, or 0 if it is one of the standard - cursors. + Returns the cursor bitmap mask, or \nullptr if it is one of the + standard cursors. */ const QBitmap *QCursor::mask() const diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index be04513de6..4847a62b0f 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -414,15 +414,14 @@ int QOpenGLContextPrivate::maxTextureSize() /*! Returns the last context which called makeCurrent in the current thread, - or 0, if no context is current. + or \nullptr, if no context is current. */ QOpenGLContext* QOpenGLContext::currentContext() { QGuiGLThreadContext *threadContext = qwindow_context_storage()->localData(); - if (threadContext) { + if (threadContext) return threadContext->context; - } - return 0; + return nullptr; } /*! diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index 50f05721f7..d6f90c9254 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -90,11 +90,11 @@ QWindow *QPlatformWindow::window() const } /*! - Returns the parent platform window (or 0 if orphan). + Returns the parent platform window (or \nullptr if orphan). */ QPlatformWindow *QPlatformWindow::parent() const { - return window()->parent() ? window()->parent()->handle() : 0; + return window()->parent() ? window()->parent()->handle() : nullptr; } /*! diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 36f0d1d5b9..c746df9dd6 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -1521,7 +1521,7 @@ QPainter::~QPainter() /*! Returns the paint device on which this painter is currently - painting, or 0 if the painter is not active. + painting, or \nullptr if the painter is not active. \sa isActive() */ diff --git a/src/gui/text/qtextdocumentwriter.cpp b/src/gui/text/qtextdocumentwriter.cpp index 5ea04fe9e9..ee72300bc7 100644 --- a/src/gui/text/qtextdocumentwriter.cpp +++ b/src/gui/text/qtextdocumentwriter.cpp @@ -206,8 +206,8 @@ void QTextDocumentWriter::setDevice (QIODevice *device) } /*! - Returns the device currently assigned, or 0 if no device has been - assigned. + Returns the device currently assigned, or \nullptr if no device + has been assigned. */ QIODevice *QTextDocumentWriter::device () const { diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp index 0ed8be8530..18c5a4f3dd 100644 --- a/src/gui/text/qtextobject.cpp +++ b/src/gui/text/qtextobject.cpp @@ -704,8 +704,8 @@ QTextFrame::iterator &QTextFrame::iterator::operator=(const iterator &other) Q_D #endif /*! - Returns the current frame pointed to by the iterator, or 0 if the - iterator currently points to a block. + Returns the current frame pointed to by the iterator, or \nullptr + if the iterator currently points to a block. \sa currentBlock() */ @@ -1291,12 +1291,12 @@ QVector QTextBlock::textFormats() const } /*! - Returns the text document this text block belongs to, or 0 if the - text block does not belong to any document. + Returns the text document this text block belongs to, or \nullptr + if the text block does not belong to any document. */ const QTextDocument *QTextBlock::document() const { - return p ? p->document() : 0; + return p ? p->document() : nullptr; } /*! @@ -1306,7 +1306,7 @@ const QTextDocument *QTextBlock::document() const QTextList *QTextBlock::textList() const { if (!isValid()) - return 0; + return nullptr; const QTextBlockFormat fmt = blockFormat(); QTextObject *obj = p->document()->objectForFormat(fmt); From b76a923a8e81f5fabe6e48ed467e5326275fae4e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 2 Feb 2019 14:50:19 +0100 Subject: [PATCH 10/16] QAnimationDriver: mark obsolete functions as deprecated Mark the two long obsolete (and empty) functions as deprecated so they can be removed with Qt6: - setStartTime()/startTime() Change-Id: I7ee1d99ff194860e41723909f81adc181a71ec7c Reviewed-by: Lars Knoll --- src/corelib/animation/qabstractanimation.cpp | 2 ++ src/corelib/animation/qabstractanimation.h | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 9dd81b2ecd..9d7a256191 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -773,6 +773,7 @@ QAnimationDriver::~QAnimationDriver() } +#if QT_DEPRECATED_SINCE(5, 13) /*! Sets the time at which an animation driver should start at. @@ -799,6 +800,7 @@ qint64 QAnimationDriver::startTime() const { return 0; } +#endif /*! diff --git a/src/corelib/animation/qabstractanimation.h b/src/corelib/animation/qabstractanimation.h index 25b5726d56..7f2577d7f7 100644 --- a/src/corelib/animation/qabstractanimation.h +++ b/src/corelib/animation/qabstractanimation.h @@ -147,9 +147,10 @@ public: virtual qint64 elapsed() const; - // ### Qt6: Remove these two functions - void setStartTime(qint64 startTime); - qint64 startTime() const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED void setStartTime(qint64 startTime); + QT_DEPRECATED qint64 startTime() const; +#endif Q_SIGNALS: void started(); From 3514aedbf36b96f6e03f88c9c7814b6ba50aac8f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 3 Feb 2019 19:55:51 +0100 Subject: [PATCH 11/16] QtWidgets documentation: cleanup Cleanup the QtWidgets documentation: - use new signal/slot syntax - use range-based for loop instead foreach Change-Id: I621b1ddac108d3df676209241d93d9b4f04a25fe Reviewed-by: Friedemann Kleint --- .../src_gui_itemviews_qdatawidgetmapper.cpp | 8 ++--- .../code/src_gui_kernel_qapplication.cpp | 12 ++++--- .../snippets/code/src_gui_widgets_qmenu.cpp | 2 +- src/widgets/doc/snippets/dialogs/dialogs.cpp | 9 +++--- .../doc/snippets/dockwidgets/mainwindow.cpp | 8 ++--- src/widgets/doc/snippets/mdiareasnippets.cpp | 4 +-- .../doc/snippets/qlistview-dnd/mainwindow.cpp | 3 +- .../doc/snippets/qlistview-dnd/model.cpp | 8 ++--- .../snippets/qlistwidget-dnd/mainwindow.cpp | 4 +-- .../snippets/qlistwidget-using/mainwindow.cpp | 17 +++++----- .../snippets/qsortfilterproxymodel/main.cpp | 7 ++--- .../doc/snippets/qstackedlayout/main.cpp | 9 +++--- .../doc/snippets/qstackedwidget/main.cpp | 7 ++--- .../qtablewidget-resizing/mainwindow.cpp | 8 ++--- .../qtablewidget-using/mainwindow.cpp | 20 ++++++------ .../snippets/qtreewidget-using/mainwindow.cpp | 31 +++++++++---------- .../mainwindow.cpp | 21 ++++++------- .../snippets/reading-selections/window.cpp | 18 +++++------ .../snippets/updating-selections/window.cpp | 17 +++++----- .../doc/src/model-view-programming.qdoc | 5 ++- 20 files changed, 104 insertions(+), 114 deletions(-) diff --git a/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp b/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp index 4dad563660..cc1568cb9d 100644 --- a/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp +++ b/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp @@ -59,7 +59,7 @@ mapper->toFirst(); //! [1] -QDataWidgetMapper *mapper = new QDataWidgetMapper(); +QDataWidgetMapper *mapper = new QDataWidgetMapper; mapper->setModel(myModel); mapper->addMapping(nameLineEdit, 0); mapper->addMapping(ageSpinBox, 1); @@ -67,7 +67,7 @@ mapper->addMapping(ageSpinBox, 1); //! [2] -QDataWidgetMapper *mapper = new QDataWidgetMapper(); -connect(myTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - mapper, SLOT(setCurrentModelIndex(QModelIndex))); +QDataWidgetMapper *mapper = new QDataWidgetMapper; +connect(myTableView->selectionModel(), &QItemSelectionModel::currentRowChanged, + mapper, &QDataWidgetMapper::setCurrentModelIndex); //! [2] diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp index a907a0421f..0a70c1d32a 100644 --- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp +++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -100,7 +100,8 @@ QSize MyWidget::sizeHint() const //! [4] void showAllHiddenTopLevelWidgets() { - foreach (QWidget *widget, QApplication::topLevelWidgets()) { + const QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); + for (QWidget *widget : topLevelWidgets) { if (widget->isHidden()) widget->show(); } @@ -111,7 +112,8 @@ void showAllHiddenTopLevelWidgets() //! [5] void updateAllWidgets() { - foreach (QWidget *widget, QApplication::allWidgets()) + const QWidgetList allWidgets = QApplication::allWidgets(); + for (QWidget *widget : allWidgets) widget->update(); } //! [5] @@ -171,13 +173,15 @@ appname -session id //! [10] -foreach (const QString &command, mySession.restartCommand()) +const QStringList commands = mySession.restartCommand(); +for (const QString &command : commands) do_something(command); //! [10] //! [11] -foreach (const QString &command, mySession.discardCommand()) +const QStringList commands = mySession.discardCommand(); +for (const QString &command : commands) do_something(command); //! [11] diff --git a/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp b/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp index 4b1c4cd645..da3fd28056 100644 --- a/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp +++ b/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp @@ -81,7 +81,7 @@ exec(e->globalPos()); //! [6] QMenu menu; QAction *at = actions[0]; // Assumes actions is not empty -foreach (QAction *a, actions) +for (QAction *a : qAsConst(actions)) menu.addAction(a); menu.exec(pos, at); //! [6] diff --git a/src/widgets/doc/snippets/dialogs/dialogs.cpp b/src/widgets/doc/snippets/dialogs/dialogs.cpp index cca3ac8d75..7fa793c70f 100644 --- a/src/widgets/doc/snippets/dialogs/dialogs.cpp +++ b/src/widgets/doc/snippets/dialogs/dialogs.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include typedef QDialog WordCountDialog; typedef QDialog FindDialog; @@ -76,7 +76,8 @@ void EditorWindow::find() { if (!findDialog) { findDialog = new FindDialog(this); - connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext())); + connect(findDialog, &FindDialog::findNext, + this, &EditorWindow::findNext); } findDialog->show(); @@ -249,9 +250,9 @@ Operation::Operation(QObject *parent) : QObject(parent), steps(0) { pd = new QProgressDialog("Operation in progress.", "Cancel", 0, 100); - connect(pd, SIGNAL(canceled()), this, SLOT(cancel())); + connect(pd, &QProgressDialog::canceled, this, &Operation::cancel); t = new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(perform())); + connect(t, &QTimer::timeout, this, &Operation::perform); t->start(0); } //! [4] //! [5] diff --git a/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp b/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp index f6959cc12b..53f91589bf 100644 --- a/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp +++ b/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -63,8 +63,8 @@ MainWindow::MainWindow(QWidget *parent) textBrowser = new QTextBrowser(this); - connect(headingList, SIGNAL(itemClicked(QListWidgetItem*)), - this, SLOT(updateText(QListWidgetItem*))); + connect(headingList, &QListWidget::itemClicked, + this, &MainWindow::updateText); updateText(headingList->item(0)); headingList->setCurrentRow(0); @@ -119,7 +119,7 @@ void MainWindow::setupMenus() QAction *exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(tr("Ctrl+Q")); exitAct->setStatusTip(tr("Exit the application")); - connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); + connect(exitAct, &QAction::triggered, qApp, &QApplication::closeAllWindows); QMenu *fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(exitAct); diff --git a/src/widgets/doc/snippets/mdiareasnippets.cpp b/src/widgets/doc/snippets/mdiareasnippets.cpp index b9d6f05daf..dec7aaa1e7 100644 --- a/src/widgets/doc/snippets/mdiareasnippets.cpp +++ b/src/widgets/doc/snippets/mdiareasnippets.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include void mainWindowExample() { @@ -95,7 +95,7 @@ int main(int argv, char **args) QAction *act = new QAction(qApp); act->setShortcut(Qt::ALT + Qt::Key_S); act->setShortcutContext( Qt::ApplicationShortcut ); - QObject::connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + QObject::connect(act, &QAction::triggered, qApp, &QApplication::aboutQt); QWidget widget5; widget5.show(); diff --git a/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp b/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp index c2af9c4cf1..45f1eb7aa3 100644 --- a/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp +++ b/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp @@ -73,7 +73,8 @@ listView->setDropIndicatorShown(true); this->listView = listView; - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(quitAction, &QAction::triggered, + this, &QWidget::close); setupListItems(); diff --git a/src/widgets/doc/snippets/qlistview-dnd/model.cpp b/src/widgets/doc/snippets/qlistview-dnd/model.cpp index 710bbb2964..6835479e7a 100644 --- a/src/widgets/doc/snippets/qlistview-dnd/model.cpp +++ b/src/widgets/doc/snippets/qlistview-dnd/model.cpp @@ -54,7 +54,7 @@ A simple model that uses a QStringList as its data source. */ -#include +#include #include "model.h" @@ -121,7 +121,7 @@ bool DragDropListModel::dropMimeData(const QMimeData *data, //! [6] insertRows(beginRow, rows, QModelIndex()); - foreach (const QString &text, newItems) { + for (const QString &text : qAsConst(newItems)) { QModelIndex idx = index(beginRow, 0, QModelIndex()); setData(idx, text); beginRow++; @@ -146,12 +146,12 @@ Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const //! [8] QMimeData *DragDropListModel::mimeData(const QModelIndexList &indexes) const { - QMimeData *mimeData = new QMimeData(); + QMimeData *mimeData = new QMimeData; QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); - foreach (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { if (index.isValid()) { QString text = data(index, Qt::DisplayRole).toString(); stream << text; diff --git a/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp b/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp index 1153250b17..70df2b112e 100644 --- a/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp +++ b/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -74,7 +74,7 @@ listWidget->setDragDropMode(QAbstractItemView::InternalMove); this->listWidget = listWidget; - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(quitAction, &QAction::triggered, this, &QWidget::close); setupListItems(); diff --git a/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp index ff69fd2efd..13b20bb856 100644 --- a/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -77,14 +77,13 @@ MainWindow::MainWindow() listWidget = new QListWidget(this); listWidget->setSelectionMode(QAbstractItemView::SingleSelection); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); - connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); - connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); - connect(listWidget, - SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(updateMenus(QListWidgetItem*))); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending); + connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending); + connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem); + connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem); + connect(listWidget, &QListWidget::currentItemChanged, + this, &MainWindow::updateMenus); setupListItems(); updateMenus(listWidget->currentItem()); diff --git a/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp b/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp index a6284bd578..2d4b1023f1 100644 --- a/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp +++ b/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include int main(int argc, char *argv[]) { @@ -74,9 +74,8 @@ int main(int argc, char *argv[]) filteredView->setWindowTitle("Filtered view onto a string list model"); QLineEdit *patternEditor = new QLineEdit; - QObject:: - connect(patternEditor, SIGNAL(textChanged(QString)), - filterModel, SLOT(setFilterRegExp(QString))); + QObject::connect(patternEditor, &QLineEdit::textChanged, + filterModel, &QSortFilterProxyModel::setFilterWildcard); QVBoxLayout *layout = new QVBoxLayout(window); layout->addWidget(filteredView); diff --git a/src/widgets/doc/snippets/qstackedlayout/main.cpp b/src/widgets/doc/snippets/qstackedlayout/main.cpp index 765608848c..9c61939dee 100644 --- a/src/widgets/doc/snippets/qstackedlayout/main.cpp +++ b/src/widgets/doc/snippets/qstackedlayout/main.cpp @@ -48,13 +48,12 @@ ** ****************************************************************************/ -#include -#include +#include class Widget : public QWidget { public: - Widget(QWidget *parent = 0); + Widget(QWidget *parent = nullptr); }; Widget::Widget(QWidget *parent) @@ -75,8 +74,8 @@ Widget::Widget(QWidget *parent) pageComboBox->addItem(tr("Page 1")); pageComboBox->addItem(tr("Page 2")); pageComboBox->addItem(tr("Page 3")); - connect(pageComboBox, SIGNAL(activated(int)), - stackedLayout, SLOT(setCurrentIndex(int))); + connect(pageComboBox, QOverload::of(&QComboBox::activated), + stackedLayout, &QStackedLayout::setCurrentIndex); //! [1] //! [2] diff --git a/src/widgets/doc/snippets/qstackedwidget/main.cpp b/src/widgets/doc/snippets/qstackedwidget/main.cpp index a6c9c7afe3..077c281830 100644 --- a/src/widgets/doc/snippets/qstackedwidget/main.cpp +++ b/src/widgets/doc/snippets/qstackedwidget/main.cpp @@ -48,8 +48,7 @@ ** ****************************************************************************/ -#include -#include +#include class Widget : public QWidget { @@ -75,8 +74,8 @@ Widget::Widget(QWidget *parent) pageComboBox->addItem(tr("Page 1")); pageComboBox->addItem(tr("Page 2")); pageComboBox->addItem(tr("Page 3")); - connect(pageComboBox, SIGNAL(activated(int)), - stackedWidget, SLOT(setCurrentIndex(int))); + connect(pageComboBox, QOverload::of(&QComboBox::activated), + stackedWidget, &QStackedWidget::setCurrentIndex); //! [1] //! [2] QVBoxLayout *layout = new QVBoxLayout; diff --git a/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp b/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp index 95113153e1..d2c50336f6 100644 --- a/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -72,9 +72,9 @@ MainWindow::MainWindow() //! [0] tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(tableWidthAction, SIGNAL(triggered()), this, SLOT(changeWidth())); - connect(tableHeightAction, SIGNAL(triggered()), this, SLOT(changeHeight())); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(tableWidthAction, &QAction::triggered, this, &MainWindow::changeWidth); + connect(tableHeightAction, &QAction::triggered, this, &MainWindow::changeHeight); setupTableItems(); diff --git a/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp index 15b9457dd5..47b63b2b3f 100644 --- a/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp @@ -48,8 +48,8 @@ ** ****************************************************************************/ -#include -#include "math.h" +#include +#include #include "mainwindow.h" @@ -89,9 +89,9 @@ MainWindow::MainWindow() tableWidget->setHorizontalHeaderItem(1, squaresHeaderItem); tableWidget->setHorizontalHeaderItem(2, cubesHeaderItem); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems())); - connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems())); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(sumItemsAction, &QAction::triggered, this, &MainWindow::sumItems); + connect(averageItemsAction, &QAction::triggered, this, &MainWindow::averageItems); setupTableItems(); @@ -119,12 +119,11 @@ void MainWindow::setupTableItems() void MainWindow::averageItems() { - QList selected = tableWidget->selectedItems(); - QTableWidgetItem *item; + const QList selected = tableWidget->selectedItems(); int number = 0; double total = 0; - foreach (item, selected) { + for (QTableWidgetItem *item : selected) { bool ok; double value = item->text().toDouble(&ok); @@ -140,12 +139,11 @@ void MainWindow::averageItems() void MainWindow::sumItems() { //! [4] - QList selected = tableWidget->selectedItems(); - QTableWidgetItem *item; + const QList selected = tableWidget->selectedItems(); int number = 0; double total = 0; - foreach (item, selected) { + for (QTableWidgetItem *item : selected) { bool ok; double value = item->text().toDouble(&ok); diff --git a/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp index 7c8d3f936e..b9e258cb03 100644 --- a/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -90,16 +90,15 @@ MainWindow::MainWindow() treeWidget->setHeaderLabels(headers); //! [2] - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); - connect(autoSortAction, SIGNAL(triggered()), this, SLOT(updateSortItems())); - connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); - connect(findItemsAction, SIGNAL(triggered()), this, SLOT(findItems())); - connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); - connect(treeWidget, - SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(updateMenus(QTreeWidgetItem*))); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending); + connect(autoSortAction, &QAction::triggered, this, &MainWindow::updateSortItems); + connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending); + connect(findItemsAction, &QAction::triggered, this, &MainWindow::findItems); + connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem); + connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem); + connect(treeWidget, &QTreeWidget::currentItemChanged, + this, &MainWindow::updateMenus); setupTreeItems(); updateMenus(treeWidget->currentItem()); @@ -150,17 +149,15 @@ void MainWindow::findItems() if (itemText.isEmpty()) return; -//! [6] - QTreeWidgetItem *item; -//! [6] - foreach (item, treeWidget->selectedItems()) + const QList items = treeWidget->selectedItems(); + for (QTreeWidgetItem *item : items) item->setSelected(false); //! [7] - QList found = treeWidget->findItems( + const QList found = treeWidget->findItems( itemText, Qt::MatchWildcard); - foreach (item, found) { + for (QTreeWidgetItem *item : found) { item->setSelected(true); // Show the item->text(0) for each item. } diff --git a/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp b/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp index 5f1f606185..bfe099bbb4 100644 --- a/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -85,16 +85,15 @@ MainWindow::MainWindow() headers << tr("Subject") << tr("Default"); treeWidget->setHeaderLabels(headers); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); - connect(autoSortAction, SIGNAL(triggered()), this, SLOT(updateSortItems())); - connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); - connect(findItemsAction, SIGNAL(triggered()), this, SLOT(findItems())); - connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); - connect(treeWidget, - SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(updateMenus(QTreeWidgetItem*))); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending); + connect(autoSortAction, &QAction::triggered, this, &MainWindow::updateSortItems); + connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending); + connect(findItemsAction, &QAction::triggered, this, &MainWindow::findItems); + connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem); + connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem); + connect(treeWidget, &QTreeWidget::currentItemChanged, + this, &MainWindow::updateMenus); setupTreeItems(); updateMenus(treeWidget->currentItem()); diff --git a/src/widgets/doc/snippets/reading-selections/window.cpp b/src/widgets/doc/snippets/reading-selections/window.cpp index 08805fe4b3..045d66a199 100644 --- a/src/widgets/doc/snippets/reading-selections/window.cpp +++ b/src/widgets/doc/snippets/reading-selections/window.cpp @@ -81,9 +81,9 @@ MainWindow::MainWindow(QWidget *parent) QAction *selectAllAction = actionMenu->addAction(tr("&Select All")); menuBar()->addMenu(actionMenu); - connect(fillAction, SIGNAL(triggered()), this, SLOT(fillSelection())); - connect(clearAction, SIGNAL(triggered()), this, SLOT(clearSelection())); - connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll())); + connect(fillAction, &QAction::triggered, this, &MainWindow::fillSelection); + connect(clearAction, &QAction::triggered, this, &MainWindow::clearSelection); + connect(selectAllAction, &QAction::triggered, this, &MainWindow::selectAll); selectionModel = table->selectionModel(); @@ -94,10 +94,9 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::fillSelection() { //! [0] - QModelIndexList indexes = selectionModel->selectedIndexes(); - QModelIndex index; + const QModelIndexList indexes = selectionModel->selectedIndexes(); - foreach(index, indexes) { + for (const QModelIndex &index : indexes) { QString text = QString("(%1,%2)").arg(index.row()).arg(index.column()); model->setData(index, text); } @@ -106,11 +105,10 @@ void MainWindow::fillSelection() void MainWindow::clearSelection() { - QModelIndexList indexes = selectionModel->selectedIndexes(); - QModelIndex index; + const QModelIndexList indexes = selectionModel->selectedIndexes(); - foreach(index, indexes) - model->setData(index, ""); + for (const QModelIndex &index : indexes) + model->setData(index, QString()); } void MainWindow::selectAll() diff --git a/src/widgets/doc/snippets/updating-selections/window.cpp b/src/widgets/doc/snippets/updating-selections/window.cpp index 0bdcf8a64d..26e9b56ae4 100644 --- a/src/widgets/doc/snippets/updating-selections/window.cpp +++ b/src/widgets/doc/snippets/updating-selections/window.cpp @@ -74,12 +74,10 @@ MainWindow::MainWindow(QWidget *parent) table->setModel(model); selectionModel = table->selectionModel(); - connect(selectionModel, - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(updateSelection(QItemSelection,QItemSelection))); - connect(selectionModel, - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(changeCurrent(QModelIndex,QModelIndex))); + connect(selectionModel, &QItemSelectionModel::selectionChanged, + this, &MainWindow::updateSelection); + connect(selectionModel, &QItemSelectionModel::currentChanged, + this, &MainWindow::changeCurrent); statusBar(); setCentralWidget(table); @@ -89,10 +87,9 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::updateSelection(const QItemSelection &selected, const QItemSelection &deselected) { - QModelIndex index; QModelIndexList items = selected.indexes(); - foreach (index, items) { + for (const QModelIndex &index : qAsConst(items)) { QString text = QString("(%1,%2)").arg(index.row()).arg(index.column()); model->setData(index, text); //! [0] //! [1] @@ -102,8 +99,8 @@ void MainWindow::updateSelection(const QItemSelection &selected, //! [2] items = deselected.indexes(); - foreach (index, items) - model->setData(index, ""); + for (const QModelIndex &index : qAsConst(items)) { + model->setData(index, QString()); } //! [2] diff --git a/src/widgets/doc/src/model-view-programming.qdoc b/src/widgets/doc/src/model-view-programming.qdoc index 83397c90b6..9335ff78c9 100644 --- a/src/widgets/doc/src/model-view-programming.qdoc +++ b/src/widgets/doc/src/model-view-programming.qdoc @@ -1003,8 +1003,8 @@ \snippet reading-selections/window.cpp 0 - The above code uses Qt's convenient \l{Container Classes}{foreach - keyword} to iterate over, and modify, the items corresponding to the + The above code uses a range-based for-loop to iterate over, + and modify, the items corresponding to the indexes returned by the selection model. The selection model emits signals to indicate changes in the @@ -1611,7 +1611,6 @@ We can obtain a list of matching items with the \c findItems() function: - \snippet qtreewidget-using/mainwindow.cpp 6 \snippet qtreewidget-using/mainwindow.cpp 7 The above code causes items in a tree widget to be selected if they From 0059de2d1b4f9a063af7e81788aaec22a3ac7739 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 3 Feb 2019 20:29:34 +0100 Subject: [PATCH 12/16] QtGui documentation: cleanup Cleanup the QtGui documentation: - use new signal/slot syntax - use range-based for loop instead foreach Change-Id: Id49ff2cbe78f28a06ca0fb63e6ca6f7dc2736f7b Reviewed-by: Frederik Gladhorn Reviewed-by: Paul Wicking --- src/gui/doc/snippets/clipboard/clipwindow.cpp | 9 +++++---- .../src_gui_itemviews_qstandarditemmodel.cpp | 4 ++-- .../code/src_gui_kernel_qguiapplication.cpp | 9 ++++++--- .../doc/snippets/draganddrop/mainwindow.cpp | 10 +++++----- src/gui/doc/snippets/picture/picture.cpp | 10 +++++----- src/gui/doc/snippets/qfontdatabase/main.cpp | 11 +++++++---- .../doc/snippets/separations/screenwidget.cpp | 4 ++-- src/gui/doc/snippets/separations/viewer.cpp | 18 +++++++++--------- .../textblock-fragments/mainwindow.cpp | 8 ++++---- .../textdocument-blocks/mainwindow.cpp | 8 ++++---- .../textdocument-frames/mainwindow.cpp | 8 ++++---- .../snippets/textdocument-lists/mainwindow.cpp | 5 +++-- .../textdocument-printing/mainwindow.cpp | 2 +- .../textdocument-selections/mainwindow.cpp | 5 +++-- .../textdocument-tables/mainwindow.cpp | 8 ++++---- 15 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/gui/doc/snippets/clipboard/clipwindow.cpp b/src/gui/doc/snippets/clipboard/clipwindow.cpp index bf1b2d904b..d1b39070fa 100644 --- a/src/gui/doc/snippets/clipboard/clipwindow.cpp +++ b/src/gui/doc/snippets/clipboard/clipwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "clipwindow.h" @@ -67,10 +67,11 @@ ClipWindow::ClipWindow(QWidget *parent) previousItems = new QListWidget(centralWidget); //! [0] - connect(clipboard, SIGNAL(dataChanged()), this, SLOT(updateClipboard())); + connect(clipboard, &QClipboard::dataChanged, + this, &ClipWindow::updateClipboard); //! [0] - connect(mimeTypeCombo, SIGNAL(activated(QString)), - this, SLOT(updateData(QString))); + connect(mimeTypeCombo, QOverload::of(&QComboBox::activated), + this, &ClipWindow::updateData); QVBoxLayout *currentLayout = new QVBoxLayout(currentItem); currentLayout->addWidget(mimeTypeLabel); diff --git a/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp b/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp index 40893fae87..4266da0a11 100644 --- a/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp +++ b/src/gui/doc/snippets/code/src_gui_itemviews_qstandarditemmodel.cpp @@ -73,8 +73,8 @@ for (int i = 0; i < 4; ++i) { //! [2] QTreeView *treeView = new QTreeView(this); treeView->setModel(myStandardItemModel); -connect(treeView, SIGNAL(clicked(QModelIndex)), - this, SLOT(clicked(QModelIndex))); +connect(treeView, &QTreeView::clicked, + this, &MyWidget::clicked); //! [2] diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp index 7c5c387a5a..a399d444e1 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qguiapplication.cpp @@ -64,7 +64,8 @@ MyMainWidget::MyMainWidget(QWidget *parent) :QWidget(parent) { QGuiApplication::setFallbackSessionManagementEnabled(false); - connect(qApp, SIGNAL(commitDataRequest(QSessionManager)), SLOT(commitData(QSessionManager))); + connect(qApp, &QGuiApplication::commitDataRequest, + this, &MyMainWidget::commitData); } void MyMainWidget::commitData(QSessionManager& manager) @@ -102,12 +103,14 @@ appname -session id //! [3] -foreach (const QString &command, mySession.restartCommand()) +const QStringList commands = mySession.restartCommand(); +for (const QString &command : commands) do_something(command); //! [3] //! [4] -foreach (const QString &command, mySession.discardCommand()) +const QStringList commands = mySession.discardCommand(); +for (const QString &command : mySession.discardCommand()) do_something(command); //! [4] diff --git a/src/gui/doc/snippets/draganddrop/mainwindow.cpp b/src/gui/doc/snippets/draganddrop/mainwindow.cpp index 551114856e..11311a0b57 100644 --- a/src/gui/doc/snippets/draganddrop/mainwindow.cpp +++ b/src/gui/doc/snippets/draganddrop/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "dragwidget.h" #include "mainwindow.h" @@ -64,10 +64,10 @@ MainWindow::MainWindow(QWidget *parent) QLabel *dataLabel = new QLabel(tr("Amount of data (bytes):"), centralWidget); dragWidget = new DragWidget(centralWidget); - connect(dragWidget, SIGNAL(mimeTypes(QStringList)), - this, SLOT(setMimeTypes(QStringList))); - connect(dragWidget, SIGNAL(dragResult(QString)), - this, SLOT(setDragResult(QString))); + connect(dragWidget, &DragWidget::mimeTypes, + this, &MainWindow::setMimeTypes); + connect(dragWidget, &DragWidget:dragResult, + this, &MainWindow::setDragResult); QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget); mainLayout->addWidget(mimeTypeLabel); diff --git a/src/gui/doc/snippets/picture/picture.cpp b/src/gui/doc/snippets/picture/picture.cpp index 3a7676f60a..863476fdbf 100644 --- a/src/gui/doc/snippets/picture/picture.cpp +++ b/src/gui/doc/snippets/picture/picture.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include void myProcessing(const QString &) { @@ -85,8 +85,8 @@ int main() { // FORMATS //! [2] - QStringList list = QPicture::inputFormatList(); - foreach (const QString &string, list) + const QStringList list = QPicture::inputFormatList(); + for (const QString &string : list) myProcessing(string); //! [2] } @@ -94,8 +94,8 @@ int main() { // OUTPUT //! [3] - QStringList list = QPicture::outputFormatList(); - foreach (const QString &string, list) + const QStringList list = QPicture::outputFormatList(); + for (const QString &string : list) myProcessing(string); //! [3] } diff --git a/src/gui/doc/snippets/qfontdatabase/main.cpp b/src/gui/doc/snippets/qfontdatabase/main.cpp index ae078f374d..5a5aa7b485 100644 --- a/src/gui/doc/snippets/qfontdatabase/main.cpp +++ b/src/gui/doc/snippets/qfontdatabase/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include int main(int argc, char **argv) { @@ -60,16 +60,19 @@ int main(int argc, char **argv) fontTree.setColumnCount(2); fontTree.setHeaderLabels(QStringList() << "Font" << "Smooth Sizes"); - foreach (const QString &family, database.families()) { + const QStringList fontFamilies = database.families(); + for (const QString &family : fontFamilies) { QTreeWidgetItem *familyItem = new QTreeWidgetItem(&fontTree); familyItem->setText(0, family); - foreach (const QString &style, database.styles(family)) { + const QStringList fontStyles = database.styles(family); + for (const QString &style : fontStyles) { QTreeWidgetItem *styleItem = new QTreeWidgetItem(familyItem); styleItem->setText(0, style); QString sizes; - foreach (int points, database.smoothSizes(family, style)) + const QList smoothSizes = database.smoothSizes(family, style) + for (int points : smoothSizes) sizes += QString::number(points) + ' '; styleItem->setText(1, sizes.trimmed()); diff --git a/src/gui/doc/snippets/separations/screenwidget.cpp b/src/gui/doc/snippets/separations/screenwidget.cpp index 6f8be49bfa..d562991d26 100644 --- a/src/gui/doc/snippets/separations/screenwidget.cpp +++ b/src/gui/doc/snippets/separations/screenwidget.cpp @@ -105,8 +105,8 @@ ScreenWidget::ScreenWidget(QWidget *parent, QColor initialColor, //invertButton->setOn(inverted); invertButton->setEnabled(false); - connect(colorButton, SIGNAL(clicked()), this, SLOT(setColor())); - connect(invertButton, SIGNAL(clicked()), this, SLOT(invertImage())); + connect(colorButton, &QPushButton::clicked, this, &ScreenWidget::setColor); + connect(invertButton, &QPushButton::clicked, this, &ScreenWidget::invertImage); QGridLayout *gridLayout = new QGridLayout; gridLayout->addWidget(imageLabel, 0, 0, 1, 2); diff --git a/src/gui/doc/snippets/separations/viewer.cpp b/src/gui/doc/snippets/separations/viewer.cpp index 641294ea35..018b397f1a 100644 --- a/src/gui/doc/snippets/separations/viewer.cpp +++ b/src/gui/doc/snippets/separations/viewer.cpp @@ -58,7 +58,7 @@ A main menu provides entries for selecting files, and adjusting the brightness of the separations. */ -#include +#include #include "finalwidget.h" #include "screenwidget.h" @@ -126,11 +126,11 @@ void Viewer::createMenus() menuBar()->addMenu(fileMenu); menuBar()->addMenu(brightnessMenu); - connect(openAction, SIGNAL(triggered()), this, SLOT(chooseFile())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveImage())); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(brightnessMenu, SIGNAL(triggered(QAction*)), this, - SLOT(setBrightness(QAction*))); + connect(openAction, &QAction::triggered, this, &Viewer::chooseFile); + connect(saveAction, &QAction::triggered, this, &Viewer::saveImage); + connect(quitAction, &QAction::triggered, qApp, QApplication::quit); + connect(brightnessMenu, &QMenu::triggered, + this, &Viewer::setBrightness); } /* @@ -160,9 +160,9 @@ QFrame* Viewer::createCentralWidget() yellowWidget = new ScreenWidget(frame, Qt::yellow, tr("Yellow"), ScreenWidget::Yellow, labelSize); - connect(cyanWidget, SIGNAL(imageChanged()), this, SLOT(createImage())); - connect(magentaWidget, SIGNAL(imageChanged()), this, SLOT(createImage())); - connect(yellowWidget, SIGNAL(imageChanged()), this, SLOT(createImage())); + connect(cyanWidget, &ScreenWidget::imageChanged, this, &Viewer::createImage); + connect(magentaWidget, &ScreenWidget::imageChanged, this, &Viewer::createImage); + connect(yellowWidget, &ScreenWidget::imageChanged, this, &Viewer::createImage); grid->addWidget(finalWidget, 0, 0, Qt::AlignTop | Qt::AlignHCenter); grid->addWidget(cyanWidget, 0, 1, Qt::AlignTop | Qt::AlignHCenter); diff --git a/src/gui/doc/snippets/textblock-fragments/mainwindow.cpp b/src/gui/doc/snippets/textblock-fragments/mainwindow.cpp index bcc5c7dc30..bf864ce48d 100644 --- a/src/gui/doc/snippets/textblock-fragments/mainwindow.cpp +++ b/src/gui/doc/snippets/textblock-fragments/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" #include "xmlwriter.h" @@ -73,9 +73,9 @@ MainWindow::MainWindow() editor = new QTextEdit(this); - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(calendarAction, SIGNAL(triggered()), this, SLOT(insertCalendar())); + connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile); + connect(quitAction, &QAction::triggered, this, &MainWindow::close); + connect(calendarAction, &QAction::triggered, this, &MainWindow::insertCalendar); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); diff --git a/src/gui/doc/snippets/textdocument-blocks/mainwindow.cpp b/src/gui/doc/snippets/textdocument-blocks/mainwindow.cpp index f512cf0dc6..a5801da67e 100644 --- a/src/gui/doc/snippets/textdocument-blocks/mainwindow.cpp +++ b/src/gui/doc/snippets/textdocument-blocks/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" #include "xmlwriter.h" @@ -75,9 +75,9 @@ MainWindow::MainWindow() editor = new QTextEdit(this); //! [0] - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(calendarAction, SIGNAL(triggered()), this, SLOT(insertCalendar())); + connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile); + connect(quitAction, &QAction::triggered, this, &MainWindow::close); + connect(calendarAction, &QAction::triggered, this, &MainWindow::insertCalendar); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); diff --git a/src/gui/doc/snippets/textdocument-frames/mainwindow.cpp b/src/gui/doc/snippets/textdocument-frames/mainwindow.cpp index f15ad45f2e..edfadb4c77 100644 --- a/src/gui/doc/snippets/textdocument-frames/mainwindow.cpp +++ b/src/gui/doc/snippets/textdocument-frames/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" #include "xmlwriter.h" @@ -64,7 +64,7 @@ MainWindow::MainWindow() quitAction->setShortcut(tr("Ctrl+Q")); menuBar()->addMenu(fileMenu); - editor = new QTextEdit(); + editor = new QTextEdit; QTextCursor cursor(editor->textCursor()); cursor.movePosition(QTextCursor::Start); @@ -130,8 +130,8 @@ MainWindow::MainWindow() plainCharFormat); - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile); + connect(quitAction, &QAction::triggered, this, &MainWindow::close); setCentralWidget(editor); setWindowTitle(tr("Text Document Frames")); diff --git a/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp b/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp index 15a2752c8b..785f7ebcc9 100644 --- a/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp +++ b/src/gui/doc/snippets/textdocument-lists/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -88,7 +88,8 @@ MainWindow::MainWindow() document = new QTextDocument(this); editor->setDocument(document); - connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + connect(editor, &QTextEdit::selectionChanged, + this, &MainWindow::updateMenus); updateMenus(); diff --git a/src/gui/doc/snippets/textdocument-printing/mainwindow.cpp b/src/gui/doc/snippets/textdocument-printing/mainwindow.cpp index 40459b49da..a7bd90a9f1 100644 --- a/src/gui/doc/snippets/textdocument-printing/mainwindow.cpp +++ b/src/gui/doc/snippets/textdocument-printing/mainwindow.cpp @@ -74,7 +74,7 @@ MainWindow::MainWindow() document = new QTextDocument(this); editor->setDocument(document); - connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + connect(editor, &QTextEdit::selectionChanged, this, &MainWindow::updateMenus); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); diff --git a/src/gui/doc/snippets/textdocument-selections/mainwindow.cpp b/src/gui/doc/snippets/textdocument-selections/mainwindow.cpp index 8ac3913f3c..9253e87670 100644 --- a/src/gui/doc/snippets/textdocument-selections/mainwindow.cpp +++ b/src/gui/doc/snippets/textdocument-selections/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" @@ -90,7 +90,8 @@ MainWindow::MainWindow() document = new QTextDocument(this); editor->setDocument(document); - connect(editor, SIGNAL(selectionChanged()), this, SLOT(updateMenus())); + connect(editor, &QTextEdit::selectionChanged, + this, &MainWindow::updateMenus); setCentralWidget(editor); setWindowTitle(tr("Text Document Writer")); diff --git a/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp b/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp index 061c191f1c..bd976a8ce4 100644 --- a/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp +++ b/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" #include "xmlwriter.h" @@ -132,9 +132,9 @@ MainWindow::MainWindow() } //! [8] - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(showTableAction, SIGNAL(triggered()), this, SLOT(showTable())); + connect(saveAction, &QAction:triggered, this, &MainWindow::saveFile); + connect(quitAction, &QAction:triggered, this, &MainWindow::close); + connect(showTableAction, &QAction:triggered, this, &MainWindow::showTable); setCentralWidget(editor); setWindowTitle(tr("Text Document Tables")); From 1b90684948df45977515ab5e9a3fb4aafb72c6fd Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 27 Jan 2019 17:49:07 +0100 Subject: [PATCH 13/16] QtWidgets: replace 0 with \nullptr in documentation Replace 0 with \nullptr in the documentation. As a drive-by also replace some 0 with nullptr in the corresponding code. Change-Id: I5e5bc1ae892f270d7c3419db1c179053561f1b26 Reviewed-by: Paul Wicking --- src/widgets/dialogs/qdialog.cpp | 4 +- src/widgets/dialogs/qmessagebox.cpp | 14 +++---- src/widgets/dialogs/qwizard.cpp | 16 ++++---- src/widgets/kernel/qactiongroup.cpp | 4 +- src/widgets/kernel/qapplication.cpp | 20 +++++----- src/widgets/kernel/qgridlayout.cpp | 6 +-- src/widgets/kernel/qlayout.cpp | 17 +++++---- src/widgets/kernel/qlayoutitem.cpp | 18 ++++----- src/widgets/kernel/qopenglwidget.cpp | 4 +- src/widgets/kernel/qstackedlayout.cpp | 12 +++--- src/widgets/kernel/qwidget.cpp | 55 ++++++++++++++------------- src/widgets/styles/qstyleoption.cpp | 8 ++-- 12 files changed, 90 insertions(+), 88 deletions(-) diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index ebbd2fa9ea..cc04110a30 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -422,7 +422,7 @@ QDialog::~QDialog() /*! \internal This function is called by the push button \a pushButton when it - becomes the default button. If \a pushButton is 0, the dialogs + becomes the default button. If \a pushButton is \nullptr, the dialogs default default button becomes the default button. This is what a push button calls when it loses focus. */ @@ -1014,7 +1014,7 @@ void QDialog::setExtension(QWidget* extension) /*! \obsolete - Returns the dialog's extension or 0 if no extension has been + Returns the dialog's extension or \nullptr if no extension has been defined. Instead of using this functionality, we recommend that you simply call diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index ac1952a642..c9818624fb 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -834,7 +834,7 @@ QMessageBox::QMessageBox(QWidget *parent) The message box is an \l{Qt::ApplicationModal} {application modal} dialog box. - On \macos, if \a parent is not 0 and you want your message box + On \macos, if \a parent is not \nullptr and you want your message box to appear as a Qt::Sheet of that parent, set the message box's \l{setWindowModality()} {window modality} to Qt::WindowModal (default). Otherwise, the message box will be a standard dialog. @@ -983,7 +983,7 @@ QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) \since 4.2 Returns a pointer corresponding to the standard button \a which, - or 0 if the standard button doesn't exist in this message box. + or \nullptr if the standard button doesn't exist in this message box. \sa standardButtons, standardButton() */ @@ -1106,7 +1106,7 @@ void QMessageBoxPrivate::detectEscapeButton() \since 4.2 Returns the button that was clicked by the user, - or 0 if the user hit the \uicontrol Esc key and + or \nullptr if the user hit the \uicontrol Esc key and no \l{setEscapeButton()}{escape button} was set. If exec() hasn't been called yet, returns nullptr. @@ -1173,7 +1173,7 @@ void QMessageBox::setDefaultButton(QMessageBox::StandardButton button) /*! \since 5.2 Sets the checkbox \a cb on the message dialog. The message box takes ownership of the checkbox. - The argument \a cb can be 0 to remove an existing checkbox from the message box. + The argument \a cb can be \nullptr to remove an existing checkbox from the message box. \sa checkBox() */ @@ -1205,7 +1205,7 @@ void QMessageBox::setCheckBox(QCheckBox *cb) /*! \since 5.2 - Returns the checkbox shown on the dialog. This is 0 if no checkbox is set. + Returns the checkbox shown on the dialog. This is \nullptr if no checkbox is set. \sa setCheckBox() */ @@ -1570,7 +1570,7 @@ QList QMessageBox::buttons() const \since 4.5 Returns the button role for the specified \a button. This function returns - \l InvalidRole if \a button is 0 or has not been added to the message box. + \l InvalidRole if \a button is \nullptr or has not been added to the message box. \sa buttons(), addButton() */ @@ -1835,7 +1835,7 @@ void QMessageBox::about(QWidget *parent, const QString &title, const QString &te /*! Displays a simple message box about Qt, with the given \a title - and centered over \a parent (if \a parent is not 0). The message + and centered over \a parent (if \a parent is not \nullptr). The message includes the version number of Qt being used by the application. This is useful for inclusion in the \uicontrol Help menu of an application, diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 59168ba14d..9345a4b583 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -2374,8 +2374,8 @@ void QWizard::removePage(int id) /*! \fn QWizardPage *QWizard::page(int id) const - Returns the page with the given \a id, or 0 if there is no such - page. + Returns the page with the given \a id, or \nullptr if there is no + such page. \sa addPage(), setPage() */ @@ -2462,8 +2462,8 @@ int QWizard::startId() const } /*! - Returns a pointer to the current page, or 0 if there is no current - page (e.g., before the wizard is shown). + Returns a pointer to the current page, or \nullptr if there is no + current page (e.g., before the wizard is shown). This is equivalent to calling page(currentId()). @@ -2954,7 +2954,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property, Passing 0 shows no side widget. - When the \a widget is not 0 the wizard reparents it. + When the \a widget is not \nullptr the wizard reparents it. Any previous side widget is hidden. @@ -2963,7 +2963,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property, All widgets set here will be deleted by the wizard when it is destroyed unless you separately reparent the widget after setting - some other side widget (or 0). + some other side widget (or \nullptr). By default, no side widget is present. */ @@ -2981,7 +2981,7 @@ void QWizard::setSideWidget(QWidget *widget) /*! \since 4.7 - Returns the widget on the left side of the wizard or 0. + Returns the widget on the left side of the wizard or \nullptr. By default, no side widget is present. */ @@ -3969,7 +3969,7 @@ void QWizardPage::registerField(const QString &name, QWidget *widget, const char } /*! - Returns the wizard associated with this page, or 0 if this page + Returns the wizard associated with this page, or \nullptr if this page hasn't been inserted into a QWizard yet. \sa QWizard::addPage(), QWizard::setPage() diff --git a/src/widgets/kernel/qactiongroup.cpp b/src/widgets/kernel/qactiongroup.cpp index 7934ae1d90..4786437d7e 100644 --- a/src/widgets/kernel/qactiongroup.cpp +++ b/src/widgets/kernel/qactiongroup.cpp @@ -316,8 +316,8 @@ bool QActionGroup::isEnabled() const } /*! - Returns the currently checked action in the group, or 0 if none - are checked. + Returns the currently checked action in the group, or \nullptr if + none are checked. */ QAction *QActionGroup::checkedAction() const { diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 53e1d13455..3594b5c902 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -784,7 +784,7 @@ QWidget *QApplication::activeModalWidget() /*! Cleans up any window system resources that were allocated by this - application. Sets the global variable \c qApp to 0. + application. Sets the global variable \c qApp to \nullptr. */ QApplication::~QApplication() @@ -893,8 +893,8 @@ void qt_cleanup() /*! \fn QWidget *QApplication::widgetAt(const QPoint &point) - Returns the widget at global screen position \a point, or 0 if there is no - Qt widget there. + Returns the widget at global screen position \a point, or \nullptr + if there is no Qt widget there. This function can be slow. @@ -904,9 +904,9 @@ QWidget *QApplication::widgetAt(const QPoint &p) { QWidget *window = QApplication::topLevelAt(p); if (!window) - return 0; + return nullptr; - QWidget *child = 0; + QWidget *child = nullptr; if (!window->testAttribute(Qt::WA_TransparentForMouseEvents)) child = window->childAt(window->mapFromGlobal(p)); @@ -942,8 +942,8 @@ QWidget *QApplication::widgetAt(const QPoint &p) \overload - Returns the widget at global screen position (\a x, \a y), or 0 if there is - no Qt widget there. + Returns the widget at global screen position (\a x, \a y), or + \nullptr if there is no Qt widget there. */ /*! @@ -1728,8 +1728,8 @@ QWidgetList QApplication::allWidgets() } /*! - Returns the application widget that has the keyboard input focus, or 0 if - no widget in this application has the focus. + Returns the application widget that has the keyboard input focus, + or \nullptr if no widget in this application has the focus. \sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged() */ @@ -1797,7 +1797,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason) /*! Returns the application top-level window that has the keyboard input focus, - or 0 if no application window has the focus. There might be an + or \nullptr if no application window has the focus. There might be an activeWindow() even if there is no focusWidget(), for example if no widget in that window accepts key events. diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp index f1c6c96a6d..4f2b505e32 100644 --- a/src/widgets/kernel/qgridlayout.cpp +++ b/src/widgets/kernel/qgridlayout.cpp @@ -1330,8 +1330,8 @@ QLayoutItem *QGridLayout::itemAt(int index) const /*! \since 4.4 - Returns the layout item that occupies cell (\a row, \a column), or 0 if - the cell is empty. + Returns the layout item that occupies cell (\a row, \a column), or + \nullptr if the cell is empty. \sa getItemPosition(), indexOf() */ @@ -1346,7 +1346,7 @@ QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const return box->item(); } } - return 0; + return nullptr; } /*! diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index eac5674161..090abc883d 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -474,8 +474,8 @@ QRect QLayout::contentsRect() const /*! - Returns the parent widget of this layout, or 0 if this layout is - not installed on any widget. + Returns the parent widget of this layout, or \nullptr if this + layout is not installed on any widget. If the layout is a sub-layout, this function returns the parent widget of the parent layout. @@ -490,11 +490,11 @@ QWidget *QLayout::parentWidget() const QLayout *parentLayout = qobject_cast(parent()); if (Q_UNLIKELY(!parentLayout)) { qWarning("QLayout::parentWidget: A layout can only have another layout as a parent."); - return 0; + return nullptr; } return parentLayout->parentWidget(); } else { - return 0; + return nullptr; } } else { Q_ASSERT(parent() && parent()->isWidgetType()); @@ -950,8 +950,8 @@ void QLayout::setMenuBar(QWidget *widget) } /*! - Returns the menu bar set for this layout, or 0 if no menu bar is - set. + Returns the menu bar set for this layout, or \nullptr if no + menu bar is set. */ QWidget *QLayout::menuBar() const @@ -1130,8 +1130,9 @@ bool QLayout::activate() Searches for widget \a from and replaces it with widget \a to if found. Returns the layout item that contains the widget \a from on success. - Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively - (the default), sub-layouts are searched for doing the replacement. + Otherwise \nullptr is returned. + If \a options contains \c Qt::FindChildrenRecursively (the default), + sub-layouts are searched for doing the replacement. Any other flag in \a options is ignored. Notice that the returned item therefore might not belong to this layout, diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp index 25890e888b..9e6d1c5eac 100644 --- a/src/widgets/kernel/qlayoutitem.cpp +++ b/src/widgets/kernel/qlayoutitem.cpp @@ -309,24 +309,24 @@ void QLayoutItem::invalidate() /*! If this item is a QLayout, it is returned as a QLayout; otherwise - 0 is returned. This function provides type-safe casting. + \nullptr is returned. This function provides type-safe casting. \sa spacerItem(), widget() */ -QLayout * QLayoutItem::layout() +QLayout *QLayoutItem::layout() { - return 0; + return nullptr; } /*! If this item is a QSpacerItem, it is returned as a QSpacerItem; - otherwise 0 is returned. This function provides type-safe casting. + otherwise \nullptr is returned. This function provides type-safe casting. \sa layout(), widget() */ -QSpacerItem * QLayoutItem::spacerItem() +QSpacerItem *QLayoutItem::spacerItem() { - return 0; + return nullptr; } /*! @@ -354,7 +354,7 @@ QSpacerItem * QSpacerItem::spacerItem() /*! If this item manages a QWidget, returns that widget. Otherwise, - \c nullptr is returned. + \nullptr is returned. \note While the functions layout() and spacerItem() perform casts, this function returns another object: QLayout and QSpacerItem inherit QLayoutItem, @@ -362,9 +362,9 @@ QSpacerItem * QSpacerItem::spacerItem() \sa layout(), spacerItem() */ -QWidget * QLayoutItem::widget() +QWidget *QLayoutItem::widget() { - return 0; + return nullptr; } /*! diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 89f860150f..cf15614680 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -1118,8 +1118,8 @@ void QOpenGLWidget::setTextureFormat(GLenum texFormat) /*! \return the active internal texture format if the widget has already initialized, the requested format if one was set but the widget has not yet - been made visible, or 0 if setTextureFormat() was not called and the widget - has not yet been made visible. + been made visible, or \nullptr if setTextureFormat() was not called and the + widget has not yet been made visible. \since 5.10 */ diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp index 7430d833db..0412dc188d 100644 --- a/src/widgets/kernel/qstackedlayout.cpp +++ b/src/widgets/kernel/qstackedlayout.cpp @@ -378,20 +378,20 @@ void QStackedLayout::setCurrentWidget(QWidget *widget) /*! - Returns the current widget, or 0 if there are no widgets in this - layout. + Returns the current widget, or \nullptr if there are no widgets + in this layout. \sa currentIndex(), setCurrentWidget() */ QWidget *QStackedLayout::currentWidget() const { Q_D(const QStackedLayout); - return d->index >= 0 ? d->list.at(d->index)->widget() : 0; + return d->index >= 0 ? d->list.at(d->index)->widget() : nullptr; } /*! - Returns the widget at the given \a index, or 0 if there is no - widget at the given position. + Returns the widget at the given \a index, or \nullptr if there is + no widget at the given position. \sa currentWidget(), indexOf() */ @@ -399,7 +399,7 @@ QWidget *QStackedLayout::widget(int index) const { Q_D(const QStackedLayout); if (index < 0 || index >= d->list.size()) - return 0; + return nullptr; return d->list.at(index)->widget(); } diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 3b1d82df18..87cc150530 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -511,10 +511,10 @@ void QWidget::setAutoFillBackground(bool enabled) Every widget's constructor accepts one or two standard arguments: \list 1 - \li \c{QWidget *parent = 0} is the parent of the new widget. If it is 0 - (the default), the new widget will be a window. If not, it will be - a child of \e parent, and be constrained by \e parent's geometry - (unless you specify Qt::Window as window flag). + \li \c{QWidget *parent = \nullptr} is the parent of the new widget. + If it is \nullptr (the default), the new widget will be a window. + If not, it will be a child of \e parent, and be constrained by + \e parent's geometry (unless you specify Qt::Window as window flag). \li \c{Qt::WindowFlags f = 0} (where available) sets the window flags; the default is suitable for almost all widgets, but to get, for example, a window without a window system frame, you must use @@ -1003,7 +1003,7 @@ struct QWidgetExceptionCleaner Constructs a widget which is a child of \a parent, with widget flags set to \a f. - If \a parent is 0, the new widget becomes a window. If + If \a parent is \nullptr, the new widget becomes a window. If \a parent is another widget, this widget becomes a child window inside \a parent. The new widget is deleted when its \a parent is deleted. @@ -2497,12 +2497,12 @@ void QWidgetPrivate::deactivateWidgetCleanup() The window identifier type depends on the underlying window system, see \c qwindowdefs.h for the actual definition. If there - is no widget with this identifier, 0 is returned. + is no widget with this identifier, \nullptr is returned. */ QWidget *QWidget::find(WId id) { - return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0; + return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : nullptr; } @@ -3279,7 +3279,7 @@ void QWidget::addActions(QList actions) /*! Inserts the action \a action to this widget's list of actions, - before the action \a before. It appends the action if \a before is 0 or + before the action \a before. It appends the action if \a before is \nullptr or \a before is not a valid action for this widget. A QWidget should only have one of each action. @@ -3313,7 +3313,7 @@ void QWidget::insertAction(QAction *before, QAction *action) /*! Inserts the actions \a actions to this widget's list of actions, - before the action \a before. It appends the action if \a before is 0 or + before the action \a before. It appends the action if \a before is \nullptr or \a before is not a valid action for this widget. A QWidget can have at most one of each action. @@ -4336,7 +4336,8 @@ QWidget *QWidget::window() const \since 4.4 Returns the native parent for this widget, i.e. the next ancestor widget - that has a system identifier, or 0 if it does not have any native parent. + that has a system identifier, or \nullptr if it does not have any native + parent. \sa effectiveWinId() */ @@ -5273,7 +5274,7 @@ QPixmap QWidget::grab(const QRect &rectangle) \brief The graphicsEffect function returns a pointer to the widget's graphics effect. - If the widget has no graphics effect, 0 is returned. + If the widget has no graphics effect, \nullptr is returned. \since 4.6 @@ -5917,10 +5918,10 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint * Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this widget and its ancestors. The search starts at \a origin (inclusive). - If successful, the function returns the proxy that embeds the widget, or 0 if no embedded - widget was found. + If successful, the function returns the proxy that embeds the widget, or \nullptr if no + embedded widget was found. */ -QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin) +QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin) { if (origin) { QWExtra *extra = origin->d_func()->extra; @@ -5928,7 +5929,7 @@ QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget return extra->proxyWidget; return nearestGraphicsProxyWidget(origin->parentWidget()); } - return 0; + return nullptr; } #endif @@ -6400,7 +6401,7 @@ void QWidget::setWindowRole(const QString &role) /*! - Sets the widget's focus proxy to widget \a w. If \a w is 0, the + Sets the widget's focus proxy to widget \a w. If \a w is \nullptr, the function resets this widget to have no focus proxy. Some widgets can "have focus", but create a child widget, such as @@ -6433,15 +6434,15 @@ void QWidget::setFocusProxy(QWidget * w) /*! - Returns the focus proxy, or 0 if there is no focus proxy. + Returns the focus proxy, or \nullptr if there is no focus proxy. \sa setFocusProxy() */ -QWidget * QWidget::focusProxy() const +QWidget *QWidget::focusProxy() const { Q_D(const QWidget); - return d->extra ? (QWidget *)d->extra->focus_proxy : 0; + return d->extra ? (QWidget *)d->extra->focus_proxy : nullptr; } @@ -8819,7 +8820,7 @@ QSize QWidget::minimumSizeHint() const /*! \fn QWidget *QWidget::parentWidget() const - Returns the parent of this widget, or 0 if it does not have any + Returns the parent of this widget, or \nullptr if it does not have any parent widget. */ @@ -10229,7 +10230,7 @@ QRegion QWidget::mask() const } /*! - Returns the layout manager that is installed on this widget, or 0 + Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is installed. The layout manager sets the geometry of the widget's children @@ -12117,14 +12118,14 @@ bool QWidgetPrivate::navigateToDirection(Direction direction) Searches for a widget that is positioned in the \a direction, starting from the current focusWidget. - Returns the pointer to a found widget or 0, if there was no widget in - that direction. + Returns the pointer to a found widget or \nullptr, if there was no widget + in that direction. */ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) { const QWidget *sourceWidget = QApplication::focusWidget(); if (!sourceWidget) - return 0; + return nullptr; const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint())); const int sourceX = (direction == DirectionNorth || direction == DirectionSouth) ? @@ -12138,7 +12139,7 @@ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) const QPoint sourceCenter = sourceRect.center(); const QWidget *sourceWindow = sourceWidget->window(); - QWidget *targetWidget = 0; + QWidget *targetWidget = nullptr; int shortestDistance = INT_MAX; const auto targetCandidates = QApplication::allWidgets(); @@ -12805,7 +12806,7 @@ void QWidget::releaseKeyboard() Returns the widget that is currently grabbing the mouse input. If no widget in this application is currently grabbing the mouse, - 0 is returned. + \nullptr is returned. \sa grabMouse(), keyboardGrabber() */ @@ -12822,7 +12823,7 @@ QWidget *QWidget::mouseGrabber() Returns the widget that is currently grabbing the keyboard input. If no widget in this application is currently grabbing the - keyboard, 0 is returned. + keyboard, \nullptr is returned. \sa grabMouse(), mouseGrabber() */ diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index 97631a5841..88031a9f1e 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -3270,7 +3270,7 @@ QStyleOptionViewItem::QStyleOptionViewItem(int version) \fn template T qstyleoption_cast(const QStyleOption *option) \relates QStyleOption - Returns a T or 0 depending on the \l{QStyleOption::type}{type} and + Returns a T or \nullptr depending on the \l{QStyleOption::type}{type} and \l{QStyleOption::version}{version} of the given \a option. Example: @@ -3285,7 +3285,7 @@ QStyleOptionViewItem::QStyleOptionViewItem(int version) \overload \relates QStyleOption - Returns a T or 0 depending on the type of the given \a option. + Returns a T or \nullptr depending on the type of the given \a option. */ #if QT_CONFIG(tabwidget) @@ -4006,7 +4006,7 @@ QStyleHintReturnVariant::~QStyleHintReturnVariant() \fn template T qstyleoption_cast(const QStyleHintReturn *hint) \relates QStyleHintReturn - Returns a T or 0 depending on the \l{QStyleHintReturn::type}{type} + Returns a T or \nullptr depending on the \l{QStyleHintReturn::type}{type} and \l{QStyleHintReturn::version}{version} of \a hint. Example: @@ -4021,7 +4021,7 @@ QStyleHintReturnVariant::~QStyleHintReturnVariant() \overload \relates QStyleHintReturn - Returns a T or 0 depending on the type of \a hint. + Returns a T or \nullptr depending on the type of \a hint. */ #if !defined(QT_NO_DEBUG_STREAM) From 93cebb3837e341718dfc0cc44cb74d963e8e2c6c Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 26 Jan 2019 20:06:14 +0100 Subject: [PATCH 14/16] QtWidgets/Graphics-/ItemViews: mark obsolete functions as deprecated Mark some long obsolete functions as deprecated so the can be removed with Qt6: - QGraphicsItem::matrix()/setMatrix()/resetMatrix()/sceneMatrix() - QGraphicsItemAnimation::reset() - QGraphicsScene::isSortCacheEnabled()/setSortCacheEnabled() - QAbstractItemDelegate::elidedText() - QAbstractItemView::setHorizontalStepsPerItem()/horizontalStepsPerItem() - QAbstractItemView::setVerticalStepsPerItem()/verticalStepsPerItem() Change-Id: I7244078552ebeac9dfbcf3291b3ae0c44cc2c1d9 Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/graphicsview/qgraphicsitem.cpp | 9 ++++++++- src/widgets/graphicsview/qgraphicsitem.h | 6 ++++++ src/widgets/graphicsview/qgraphicsitemanimation.cpp | 2 ++ src/widgets/graphicsview/qgraphicsitemanimation.h | 3 +++ src/widgets/graphicsview/qgraphicsscene.cpp | 2 ++ src/widgets/graphicsview/qgraphicsscene.h | 6 ++++-- src/widgets/itemviews/qabstractitemdelegate.cpp | 2 ++ src/widgets/itemviews/qabstractitemdelegate.h | 3 +++ src/widgets/itemviews/qabstractitemview.cpp | 2 ++ src/widgets/itemviews/qabstractitemview.h | 10 ++++++---- 10 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 4476ecded3..6e53ea94f3 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -3997,6 +3997,7 @@ void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin) ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin). */ +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -4012,6 +4013,7 @@ QMatrix QGraphicsItem::matrix() const { return transform().toAffine(); } +#endif /*! \since 4.3 @@ -4322,6 +4324,7 @@ void QGraphicsItem::setTransformOriginPoint(const QPointF &origin) */ +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -4334,7 +4337,7 @@ QMatrix QGraphicsItem::sceneMatrix() const d_ptr->ensureSceneTransform(); return d_ptr->sceneTransform.toAffine(); } - +#endif /*! \since 4.3 @@ -4546,6 +4549,7 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co return x; } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -4584,6 +4588,7 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine) // Send post-notification. itemChange(ItemTransformHasChanged, QVariant::fromValue(newTransform)); } +#endif /*! \since 4.3 @@ -4638,6 +4643,7 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine) d_ptr->sendScenePosChange(); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -4647,6 +4653,7 @@ void QGraphicsItem::resetMatrix() { resetTransform(); } +#endif /*! \since 4.3 diff --git a/src/widgets/graphicsview/qgraphicsitem.h b/src/widgets/graphicsview/qgraphicsitem.h index 729176530d..7dd4441ae9 100644 --- a/src/widgets/graphicsview/qgraphicsitem.h +++ b/src/widgets/graphicsview/qgraphicsitem.h @@ -283,10 +283,16 @@ public: inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50); // Local transformation +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use transform() instead") QMatrix matrix() const; + QT_DEPRECATED_X("Use sceneTransform() instead") QMatrix sceneMatrix() const; + QT_DEPRECATED_X("Use setTransform() instead") void setMatrix(const QMatrix &matrix, bool combine = false); + QT_DEPRECATED_X("Use resetTransform() instead") void resetMatrix(); +#endif QTransform transform() const; QTransform sceneTransform() const; QTransform deviceTransform(const QTransform &viewportTransform) const; diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index 572ec141bc..78b91d5c39 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -549,6 +549,7 @@ void QGraphicsItemAnimation::setStep(qreal step) afterAnimationStep(step); } +#if QT_DEPRECATED_SINCE(5, 13) /*! Resets the item to its starting position and transformation. @@ -563,6 +564,7 @@ void QGraphicsItemAnimation::reset() d->startPos = d->item->pos(); d->startMatrix = d->item->matrix(); } +#endif /*! \fn void QGraphicsItemAnimation::beforeAnimationStep(qreal step) diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.h b/src/widgets/graphicsview/qgraphicsitemanimation.h index 7417d7729c..f983bd8026 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.h +++ b/src/widgets/graphicsview/qgraphicsitemanimation.h @@ -96,7 +96,10 @@ public: public Q_SLOTS: void setStep(qreal x); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use setStep(0) instead") void reset(); +#endif protected: virtual void beforeAnimationStep(qreal step); diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index db7ce5251a..a60c2872ae 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -1929,6 +1929,7 @@ void QGraphicsScene::setBspTreeDepth(int depth) bspTree->setBspTreeDepth(depth); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \property QGraphicsScene::sortCacheEnabled \brief whether sort caching is enabled @@ -1949,6 +1950,7 @@ void QGraphicsScene::setSortCacheEnabled(bool enabled) return; d->sortCacheEnabled = enabled; } +#endif /*! Calculates and returns the bounding rect of all items on the scene. This diff --git a/src/widgets/graphicsview/qgraphicsscene.h b/src/widgets/graphicsview/qgraphicsscene.h index 287e551db7..71b8fc3013 100644 --- a/src/widgets/graphicsview/qgraphicsscene.h +++ b/src/widgets/graphicsview/qgraphicsscene.h @@ -141,8 +141,10 @@ public: ItemIndexMethod itemIndexMethod() const; void setItemIndexMethod(ItemIndexMethod method); - bool isSortCacheEnabled() const; - void setSortCacheEnabled(bool enabled); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED bool isSortCacheEnabled() const; + QT_DEPRECATED void setSortCacheEnabled(bool enabled); +#endif int bspTreeDepth() const; void setBspTreeDepth(int depth); diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index 4bdc318566..448e775a71 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -345,6 +345,7 @@ bool QAbstractItemDelegate::editorEvent(QEvent *, return false; } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -364,6 +365,7 @@ QString QAbstractItemDelegate::elidedText(const QFontMetrics &fontMetrics, int w { return fontMetrics.elidedText(text, mode, width); } +#endif /*! \since 4.3 diff --git a/src/widgets/itemviews/qabstractitemdelegate.h b/src/widgets/itemviews/qabstractitemdelegate.h index 575728e806..5696e55691 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.h +++ b/src/widgets/itemviews/qabstractitemdelegate.h @@ -103,8 +103,11 @@ public: const QStyleOptionViewItem &option, const QModelIndex &index); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use QFontMetrics::elidedText() instead") static QString elidedText(const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text); +#endif virtual bool helpEvent(QHelpEvent *event, QAbstractItemView *view, diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 7441161e13..63803767c8 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -2921,6 +2921,7 @@ void QAbstractItemView::editorDestroyed(QObject *editor) setState(NoState); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete Sets the horizontal scroll bar's steps per item to \a steps. @@ -2978,6 +2979,7 @@ int QAbstractItemView::verticalStepsPerItem() const { return 1; } +#endif /*! Moves to and selects the item best matching the string \a search. diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index 981582c166..be8fa07c94 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -272,10 +272,12 @@ Q_SIGNALS: protected: QAbstractItemView(QAbstractItemViewPrivate &, QWidget *parent = nullptr); - void setHorizontalStepsPerItem(int steps); - int horizontalStepsPerItem() const; - void setVerticalStepsPerItem(int steps); - int verticalStepsPerItem() const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED void setHorizontalStepsPerItem(int steps); + QT_DEPRECATED int horizontalStepsPerItem() const; + QT_DEPRECATED void setVerticalStepsPerItem(int steps); + QT_DEPRECATED int verticalStepsPerItem() const; +#endif enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight, MoveHome, MoveEnd, MovePageUp, MovePageDown, From a6aacdd5607437f13866aff7e0869a7c5f508f00 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 31 Jan 2019 11:27:04 +0100 Subject: [PATCH 15/16] Fix convertARGBToARGB32PM_avx2 and convertARGBToRGBA64PM_avx2 The tails was off since f370410097f8cb8d8fdf6174b799497fe7fe0adf Fixes: QTBUG-73440 Change-Id: If86178c6cad3f87d9b5f0f89e90354d49cd386a4 Reviewed-by: Thiago Macieira --- src/gui/painting/qdrawhelper_avx2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qdrawhelper_avx2.cpp b/src/gui/painting/qdrawhelper_avx2.cpp index 8c69e21569..4a3e24d6d5 100644 --- a/src/gui/painting/qdrawhelper_avx2.cpp +++ b/src/gui/painting/qdrawhelper_avx2.cpp @@ -1054,7 +1054,7 @@ static void convertARGBToARGB32PM_avx2(uint *buffer, const uint *src, qsizetype __m128i maskedAlphaMask = _mm256_castsi256_si128(alphaMask); __m128i mask = maskFromCount((count - i) * sizeof(*src)); maskedAlphaMask = _mm_and_si128(mask, maskedAlphaMask); - __m128i srcVector = _mm_maskload_epi32(reinterpret_cast(src), mask); + __m128i srcVector = _mm_maskload_epi32(reinterpret_cast(src + i), mask); if (!_mm_testz_si128(srcVector, maskedAlphaMask)) { // keep the two _mm_test[zc]_siXXX next to each other @@ -1166,7 +1166,7 @@ static void convertARGBToRGBA64PM_avx2(QRgba64 *buffer, const uint *src, qsizety __m128i maskedAlphaMask = _mm256_castsi256_si128(alphaMask); __m128i mask = maskFromCount((count - i) * sizeof(*src)); maskedAlphaMask = _mm_and_si128(mask, maskedAlphaMask); - __m128i srcVector = _mm_maskload_epi32(reinterpret_cast(src), mask); + __m128i srcVector = _mm_maskload_epi32(reinterpret_cast(src + i), mask); __m256i src; if (!_mm_testz_si128(srcVector, maskedAlphaMask)) { From 4c165e68342b7de32bbbb49fe103c1eb7f575696 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 5 Feb 2019 11:16:58 +0100 Subject: [PATCH 16/16] Disable Docker-based test servers on macOS temporarily The coin agent starts to crash after the docker-compose call. Need to have qt5 5.13 integrated first, then fix the real issue later. Task-number: QTQAINFRA-2717 Task-number: QTQAINFRA-2750 Change-Id: I3dcd963b1c5cea0b2197f1589398d8a9ed18f46f Reviewed-by: Aapo Keskimolo --- tests/auto/testserver.pri | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/auto/testserver.pri b/tests/auto/testserver.pri index 73008ea8b3..26e7f6ab8a 100644 --- a/tests/auto/testserver.pri +++ b/tests/auto/testserver.pri @@ -56,7 +56,18 @@ # Makefile.Debug and Makefile.Release. debug_and_release:!build_pass: return() -TESTSERVER_VERSION = $$system(docker-compose --version) +DOCKER_ENABLED = 1 + +equals(QMAKE_HOST.os, Darwin) { + DOCKER_ENABLED = 0 + message("Not using docker network test server on macOS, see QTQAINFRA-2717 and QTQAINFRA-2750") +} + +TESTSERVER_VERSION = "" + +equals(DOCKER_ENABLED, 1) { + TESTSERVER_VERSION = $$system(docker-compose --version) +} isEmpty(TESTSERVER_VERSION) { # Make check with server "qt-test-server.qt-test-net" as a fallback