From 7c9c195235378c2619d140bccbb957ba1d7a7dea Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Tue, 12 Apr 2022 17:33:01 +0200 Subject: [PATCH] Plugins: stop using QLatin1Char constructor for creating char literals Required for porting away from QLatin1Char/QLatin1String in scope of QTBUG-98434. As a drive-by, fix qsizetype -> int narrowing conversion warnings for the touched lines. Change-Id: Id76add7e86b6dfb89f758a9efb0644067f0f44de Reviewed-by: Marc Mutz --- .../ibus/qibusplatforminputcontext.cpp | 2 +- .../cocoa/qcocoaaccessibilityelement.mm | 2 +- .../platforms/cocoa/qcocoafiledialoghelper.mm | 6 +++--- src/plugins/platforms/cocoa/qcocoahelpers.mm | 2 +- src/plugins/platforms/cocoa/qcocoamenubar.mm | 2 +- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 2 +- .../platforms/directfb/qdirectfbblitter.cpp | 2 +- .../platforms/minimal/qminimalbackingstore.cpp | 4 +++- src/plugins/platforms/qnx/qqnxscreen.cpp | 2 +- .../platforms/windows/qwindowsdialoghelpers.cpp | 2 +- src/plugins/platforms/xcb/qxcbintegration.cpp | 2 +- src/plugins/platforms/xcb/qxcbmime.cpp | 4 ++-- .../platforms/xcb/qxcbnativeinterface.cpp | 2 +- src/plugins/platforms/xcb/qxcbscreen.cpp | 4 ++-- src/plugins/platforms/xcb/qxcbsessionmanager.cpp | 5 ++--- .../platformthemes/gtk3/qgtk3dialoghelpers.cpp | 2 +- src/plugins/platformthemes/gtk3/qgtk3menu.cpp | 16 ++++++++-------- .../qxdgdesktopportalfiledialog.cpp | 2 +- 18 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp index 900482470d..886ebfaad8 100644 --- a/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp +++ b/src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.cpp @@ -745,7 +745,7 @@ QString QIBusPlatformInputContextPrivate::getSocketPath() return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/ibus/bus/") + QLatin1String(QDBusConnection::localMachineId()) + - QLatin1Char('-') + QString::fromLocal8Bit(host) + QLatin1Char('-') + QString::fromLocal8Bit(displayNumber); + u'-' + QString::fromLocal8Bit(host) + u'-' + QString::fromLocal8Bit(displayNumber); } QDBusConnection *QIBusPlatformInputContextPrivate::createConnection() diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index 9e26f93b9d..131f899a31 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -192,7 +192,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of + (id) lineNumberForIndex: (int)index forText:(const QString &)text { auto textBefore = QStringView(text).left(index); - int newlines = textBefore.count(QLatin1Char('\n')); + qsizetype newlines = textBefore.count(u'\n'); return @(newlines); } diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 367164d740..8801b5fb8e 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -290,7 +290,7 @@ typedef QSharedPointer SharedPointerFileDialogOptions; return NO; } if (!(filter & QDir::Hidden) - && (qtFileName.startsWith(QLatin1Char('.')) || [self isHiddenFileAtURL:url])) + && (qtFileName.startsWith(u'.') || [self isHiddenFileAtURL:url])) return NO; return YES; @@ -446,10 +446,10 @@ typedef QSharedPointer SharedPointerFileDialogOptions; if (!filter.startsWith(QLatin1String("*."))) continue; - if (filter.contains(QLatin1Char('?'))) + if (filter.contains(u'?')) continue; - if (filter.count(QLatin1Char('*')) != 1) + if (filter.count(u'*') != 1) continue; auto extensions = filter.split('.', Qt::SkipEmptyParts); diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index e4c6d415c0..4ae97ef6ad 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -225,7 +225,7 @@ QString qt_mac_applicationName() if (appName.isEmpty()) { QString arg0 = QGuiApplicationPrivate::instance()->appName(); if (arg0.contains("/")) { - QStringList parts = arg0.split(QLatin1Char('/')); + QStringList parts = arg0.split(u'/'); appName = parts.at(parts.count() - 1); } else { appName = arg0; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index aaea688b39..2dc27759d6 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -195,7 +195,7 @@ void QCocoaMenuBar::syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate) cocoaMenu->syncMenuItem_helper(item, menubarUpdate); const QString captionNoAmpersand = QString::fromNSString(cocoaMenu->nsMenu().title) - .remove(QLatin1Char('&')); + .remove(u'&'); if (captionNoAmpersand == QCoreApplication::translate("QCocoaMenu", "Edit")) { // prevent recursion from QCocoaMenu::insertMenuItem - when the menu is visible // it calls syncMenu again. QCocoaMenu::setVisible just sets the bool, which then diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 022972518a..4b4a0b9316 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -216,7 +216,7 @@ void QCocoaMenuItem::setNativeContents(WId item) static QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption) { QString captionNoAmpersand(caption); - captionNoAmpersand.remove(QLatin1Char('&')); + captionNoAmpersand.remove(u'&'); const QString aboutString = QCoreApplication::translate("QCocoaMenuItem", "About"); if (captionNoAmpersand.startsWith(aboutString, Qt::CaseInsensitive) || captionNoAmpersand.endsWith(aboutString, Qt::CaseInsensitive)) { diff --git a/src/plugins/platforms/directfb/qdirectfbblitter.cpp b/src/plugins/platforms/directfb/qdirectfbblitter.cpp index 3e21a1925d..5d85fe071e 100644 --- a/src/plugins/platforms/directfb/qdirectfbblitter.cpp +++ b/src/plugins/platforms/directfb/qdirectfbblitter.cpp @@ -403,7 +403,7 @@ bool QDirectFbBlitterPlatformPixmap::fromFile(const QString &filename, const cha return QBlittablePlatformPixmap::fromFile(filename, format, flags); // Deal with resources - if (filename.startsWith(QLatin1Char(':'))) + if (filename.startsWith(u':')) return QBlittablePlatformPixmap::fromFile(filename, format, flags); // Try to use directfb to load it. diff --git a/src/plugins/platforms/minimal/qminimalbackingstore.cpp b/src/plugins/platforms/minimal/qminimalbackingstore.cpp index 402ee7e2dd..2ea5b159c4 100644 --- a/src/plugins/platforms/minimal/qminimalbackingstore.cpp +++ b/src/plugins/platforms/minimal/qminimalbackingstore.cpp @@ -47,6 +47,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QMinimalBackingStore::QMinimalBackingStore(QWindow *window) : QPlatformBackingStore(window) , mDebug(QMinimalIntegration::instance()->options() & QMinimalIntegration::DebugBackingStore) @@ -75,7 +77,7 @@ void QMinimalBackingStore::flush(QWindow *window, const QRegion ®ion, const Q if (mDebug) { static int c = 0; - QString filename = QString("output%1.png").arg(c++, 4, 10, QLatin1Char('0')); + QString filename = QString("output%1.png").arg(c++, 4, 10, QChar(u'0')); qDebug() << "QMinimalBackingStore::flush() saving contents to" << filename.toLocal8Bit().constData(); mImage.save(filename); } diff --git a/src/plugins/platforms/qnx/qqnxscreen.cpp b/src/plugins/platforms/qnx/qqnxscreen.cpp index 7b33eed3ab..7f33816f1d 100644 --- a/src/plugins/platforms/qnx/qqnxscreen.cpp +++ b/src/plugins/platforms/qnx/qqnxscreen.cpp @@ -86,7 +86,7 @@ static QSize determineScreenSize(screen_display_t display, bool primaryScreen) { const QString envPhySizeStr = qgetenv("QQNX_PHYSICAL_SCREEN_SIZE"); if (!envPhySizeStr.isEmpty()) { - const auto envPhySizeStrList = QStringView{envPhySizeStr}.split(QLatin1Char(',')); + const auto envPhySizeStrList = QStringView{envPhySizeStr}.split(u','); const int envWidth = envPhySizeStrList.size() == 2 ? envPhySizeStrList[0].toInt() : -1; const int envHeight = envPhySizeStrList.size() == 2 ? envPhySizeStrList[1].toInt() : -1; diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index 89d55e9b48..ec0a504577 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -1053,7 +1053,7 @@ static QList filterSpecs(const QStringList &filters, #if QT_CONFIG(regularexpression) filterSpec.filter.replace(filterSeparatorRE, separator); #else - filterSpec.filter.replace(QLatin1Char(' '), QLatin1Char(';')); + filterSpec.filter.replace(u' ', u';'); #endif filterSpec.description = filterString; if (hideFilterDetails && openingParenPos != -1) { // Do not show pattern in description diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index d47ed372a6..672e6d92a8 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -501,7 +501,7 @@ static QString argv0BaseName() const QStringList arguments = QCoreApplication::arguments(); if (!arguments.isEmpty() && !arguments.front().isEmpty()) { result = arguments.front(); - const int lastSlashPos = result.lastIndexOf(QLatin1Char('/')); + const int lastSlashPos = result.lastIndexOf(u'/'); if (lastSlashPos != -1) result.remove(0, lastSlashPos + 1); } diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 62149e7f6b..f4672c3f75 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -112,7 +112,7 @@ bool QXcbMime::mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeDa // so QXcbConnection::atomName() has to be used. if (atomName == QLatin1String("text/uri-list") && connection->atomName(a) == "text/x-moz-url") { - const QString mozUri = QLatin1String(data->split('\n').constFirst()) + QLatin1Char('\n'); + const QString mozUri = QLatin1String(data->split('\n').constFirst()) + u'\n'; *data = QByteArray(reinterpret_cast(mozUri.data()), mozUri.length() * 2); } else if (atomName == QLatin1String("application/x-color")) @@ -195,7 +195,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, reinterpret_cast(data.constData()), data.size() / 2); if (!str.isNull()) { if (format == QLatin1String("text/uri-list")) { - const auto urls = QStringView{str}.split(QLatin1Char('\n')); + const auto urls = QStringView{str}.split(u'\n'); QList list; list.reserve(urls.size()); for (const QStringView &s : urls) { diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp index 55633aade7..53321ae371 100644 --- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp +++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp @@ -613,7 +613,7 @@ static void dumpNativeWindowsRecursion(const QXcbConnection *connection, xcb_win const int oldFieldWidth = str.fieldWidth(); const QChar oldPadChar =str.padChar(); str.setFieldWidth(8); - str.setPadChar(QLatin1Char('0')); + str.setPadChar(u'0'); str << Qt::hex << window; str.setFieldWidth(oldFieldWidth); str.setPadChar(oldPadChar); diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index a3390b08dc..981ffe635a 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -729,7 +729,7 @@ QString QXcbScreen::defaultName() int dotPos = displayName.lastIndexOf('.'); if (dotPos != -1) displayName.truncate(dotPos); - name = QString::fromLocal8Bit(displayName) + QLatin1Char('.') + name = QString::fromLocal8Bit(displayName) + u'.' + QString::number(m_virtualDesktop->number()); return name; } @@ -762,7 +762,7 @@ QString QXcbScreen::getName(xcb_randr_monitor_info_t *monitorInfo) int dotPos = displayName.lastIndexOf('.'); if (dotPos != -1) displayName.truncate(dotPos); - name = QString::fromLocal8Bit(displayName) + QLatin1Char('.') + name = QString::fromLocal8Bit(displayName) + u'.' + QString::number(m_virtualDesktop->number()); } return name; diff --git a/src/plugins/platforms/xcb/qxcbsessionmanager.cpp b/src/plugins/platforms/xcb/qxcbsessionmanager.cpp index acdd5b4a90..64fb29f8df 100644 --- a/src/plugins/platforms/xcb/qxcbsessionmanager.cpp +++ b/src/plugins/platforms/xcb/qxcbsessionmanager.cpp @@ -194,7 +194,7 @@ static void sm_performSaveYourself(QXcbSessionManager *sm) timeval tv; gettimeofday(&tv, nullptr); sm->setSessionKey(QString::number(qulonglong(tv.tv_sec)) + - QLatin1Char('_') + + u'_' + QString::number(qulonglong(tv.tv_usec))); QStringList arguments = QCoreApplication::arguments(); @@ -228,8 +228,7 @@ static void sm_performSaveYourself(QXcbSessionManager *sm) // generate a restart and discard command that makes sense QStringList restart; - restart << argument0 << QLatin1String("-session") - << sm->sessionId() + QLatin1Char('_') + sm->sessionKey(); + restart << argument0 << QLatin1String("-session") << sm->sessionId() + u'_' + sm->sessionKey(); QFileInfo fi(QCoreApplication::applicationFilePath()); if (qAppName().compare(fi.fileName(), Qt::CaseInsensitive) != 0) diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp index 9d22f0b701..9ffd5fd496 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp @@ -521,7 +521,7 @@ void QGtk3FileDialogHelper::setNameFilters(const QStringList &filters) foreach (const QString &filter, filters) { GtkFileFilter *gtkFilter = gtk_file_filter_new(); - const QString name = filter.left(filter.indexOf(QLatin1Char('('))); + const QString name = filter.left(filter.indexOf(u'(')); const QStringList extensions = cleanFilterList(filter); gtk_file_filter_set_name(gtkFilter, qUtf8Printable(name.isEmpty() ? extensions.join(QLatin1String(", ")) : name)); diff --git a/src/plugins/platformthemes/gtk3/qgtk3menu.cpp b/src/plugins/platformthemes/gtk3/qgtk3menu.cpp index 8726708917..50eb790340 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3menu.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3menu.cpp @@ -158,23 +158,23 @@ static QString convertMnemonics(QString text, bool *found) { *found = false; - int i = text.length() - 1; + qsizetype i = text.length() - 1; while (i >= 0) { const QChar c = text.at(i); - if (c == QLatin1Char('&')) { - if (i == 0 || text.at(i - 1) != QLatin1Char('&')) { + if (c == u'&') { + if (i == 0 || text.at(i - 1) != u'&') { // convert Qt to GTK mnemonic if (i < text.length() - 1 && !text.at(i + 1).isSpace()) { - text.replace(i, 1, QLatin1Char('_')); + text.replace(i, 1, u'_'); *found = true; } - } else if (text.at(i - 1) == QLatin1Char('&')) { + } else if (text.at(i - 1) == u'&') { // unescape ampersand - text.replace(--i, 2, QLatin1Char('&')); + text.replace(--i, 2, u'&'); } - } else if (c == QLatin1Char('_')) { + } else if (c == u'_') { // escape GTK mnemonic - text.insert(i, QLatin1Char('_')); + text.insert(i, u'_'); } --i; } diff --git a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp index 61d0059898..92ac792b9c 100644 --- a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp +++ b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp @@ -251,7 +251,7 @@ void QXdgDesktopPortalFileDialog::openPortal() QRegularExpressionMatch match = regexp.match(nameFilter); if (match.hasMatch()) { QString userVisibleName = match.captured(1); - QStringList filterStrings = match.captured(2).split(QLatin1Char(' '), Qt::SkipEmptyParts); + QStringList filterStrings = match.captured(2).split(u' ', Qt::SkipEmptyParts); if (filterStrings.isEmpty()) { qWarning() << "Filter " << userVisibleName << " is empty and will be ignored.";