Android: use _L1 for for creating Latin-1 string literals

Task-number: QTBUG-98434
Change-Id: I5ee5fe079c9a4530f636e59f6171abfa523591f4
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Sona Kurazyan 2022-04-13 16:44:37 +02:00
parent d0a08d1f11
commit b28ed7fdc2
11 changed files with 395 additions and 382 deletions

View File

@ -47,6 +47,7 @@
#include <QDebug>
using namespace QNativeInterface;
using namespace Qt::StringLiterals;
AndroidContentFileEngine::AndroidContentFileEngine(const QString &f)
: m_file(f)
@ -175,9 +176,8 @@ AndroidContentFileEngineHandler::~AndroidContentFileEngineHandler() = default;
QAbstractFileEngine* AndroidContentFileEngineHandler::create(const QString &fileName) const
{
if (!fileName.startsWith(QLatin1String("content"))) {
if (!fileName.startsWith("content"_L1))
return nullptr;
}
return new AndroidContentFileEngine(fileName);
}

View File

@ -43,6 +43,8 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
class QAndroidIntegrationPlugin : public QPlatformIntegrationPlugin
{
Q_OBJECT
@ -54,7 +56,7 @@ public:
QPlatformIntegration *QAndroidIntegrationPlugin::create(const QString& system, const QStringList& paramList)
{
if (!system.compare(QLatin1String("android"), Qt::CaseInsensitive))
if (!system.compare("android"_L1, Qt::CaseInsensitive))
return new QAndroidPlatformIntegration(paramList);
return nullptr;

View File

@ -49,14 +49,16 @@
QT_BEGIN_NAMESPACE
static const QLatin1String assetsPrefix("assets:");
using namespace Qt::StringLiterals;
static const auto assetsPrefix = "assets:"_L1;
const static int prefixSize = 7;
static inline QString cleanedAssetPath(QString file)
{
if (file.startsWith(assetsPrefix))
file.remove(0, prefixSize);
file.replace(QLatin1String("//"), QLatin1String("/"));
file.replace("//"_L1, "/"_L1);
if (file.startsWith(u'/'))
file.remove(0, 1);
if (file.endsWith(u'/'))
@ -67,7 +69,7 @@ static inline QString cleanedAssetPath(QString file)
static inline QString prefixedPath(QString path)
{
path = assetsPrefix + u'/' + path;
path.replace(QLatin1String("//"), QLatin1String("/"));
path.replace("//"_L1, "/"_L1);
return path;
}
@ -157,7 +159,7 @@ public:
}
}
m_path = assetsPrefix + u'/' + m_path + u'/';
m_path.replace(QLatin1String("//"), QLatin1String("/"));
m_path.replace("//"_L1, "/"_L1);
}
QString currentFileName() const
@ -381,7 +383,7 @@ private:
AAsset *m_assetFile = nullptr;
AAssetManager *m_assetManager = nullptr;
// initialize with a name that can't be used as a file name
QString m_fileName = QLatin1String(".");
QString m_fileName = "."_L1;
bool m_isFolder = false;
};
@ -400,7 +402,7 @@ QAbstractFileEngine * AndroidAssetsFileEngineHandler::create(const QString &file
return nullptr;
QString path = fileName.mid(prefixSize);
path.replace(QLatin1String("//"), QLatin1String("/"));
path.replace("//"_L1, "/"_L1);
if (path.startsWith(u'/'))
path.remove(0, 1);
if (path.endsWith(u'/'))

View File

@ -48,6 +48,8 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace QtAndroidDialogHelpers {
static jclass g_messageDialogHelperClass = nullptr;
@ -74,7 +76,7 @@ static QString htmlText(QString text)
if (Qt::mightBeRichText(text))
return text;
text.remove(u'\r');
return text.toHtmlEscaped().replace(u'\n', QLatin1String("<br />"));
return text.toHtmlEscaped().replace(u'\n', "<br />"_L1);
}
bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags,

View File

@ -50,6 +50,8 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace QtAndroidFileDialogHelper {
#define RESULT_OK -1
@ -172,7 +174,7 @@ void QAndroidPlatformFileDialogHelper::setMimeTypes()
mimeTypes.append(db.mimeTypeForFile(filter, QMimeDatabase::MatchExtension).name());
}
const QString initialType = mimeTypes.size() == 1 ? mimeTypes.at(0) : QLatin1String("*/*");
const QString initialType = mimeTypes.size() == 1 ? mimeTypes.at(0) : "*/*"_L1;
m_intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;",
QJniObject::fromString(initialType).object());

View File

@ -43,14 +43,16 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
QString QAndroidPlatformFontDatabase::fontDir() const
{
return QLatin1String("/system/fonts");
return "/system/fonts"_L1;
}
QFont QAndroidPlatformFontDatabase::defaultFont() const
{
return QFont(QLatin1String("Roboto"));
return QFont("Roboto"_L1);
}
void QAndroidPlatformFontDatabase::populateFontDatabase()
@ -64,9 +66,9 @@ void QAndroidPlatformFontDatabase::populateFontDatabase()
}
QStringList nameFilters;
nameFilters << QLatin1String("*.ttf")
<< QLatin1String("*.otf")
<< QLatin1String("*.ttc");
nameFilters << "*.ttf"_L1
<< "*.otf"_L1
<< "*.ttc"_L1;
const auto entries = dir.entryInfoList(nameFilters, QDir::Files);
for (const QFileInfo &fi : entries) {

View File

@ -80,6 +80,8 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
QSize QAndroidPlatformIntegration::m_defaultScreenSize = QSize(320, 455);
QRect QAndroidPlatformIntegration::m_defaultAvailableGeometry = QRect(0, 0, 320, 455);
QSize QAndroidPlatformIntegration::m_defaultPhysicalSize = QSize(50, 71);
@ -286,9 +288,9 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList &para
static bool needsBasicRenderloopWorkaround()
{
static bool needsWorkaround =
QtAndroid::deviceName().compare(QLatin1String("samsung SM-T211"), Qt::CaseInsensitive) == 0
|| QtAndroid::deviceName().compare(QLatin1String("samsung SM-T210"), Qt::CaseInsensitive) == 0
|| QtAndroid::deviceName().compare(QLatin1String("samsung SM-T215"), Qt::CaseInsensitive) == 0;
QtAndroid::deviceName().compare("samsung SM-T211"_L1, Qt::CaseInsensitive) == 0
|| QtAndroid::deviceName().compare("samsung SM-T210"_L1, Qt::CaseInsensitive) == 0
|| QtAndroid::deviceName().compare("samsung SM-T215"_L1, Qt::CaseInsensitive) == 0;
return needsWorkaround;
}
@ -457,7 +459,7 @@ Qt::WindowState QAndroidPlatformIntegration::defaultWindowState(Qt::WindowFlags
return QPlatformIntegration::defaultWindowState(flags);
}
static const QLatin1String androidThemeName("android");
static const auto androidThemeName = "android"_L1;
QStringList QAndroidPlatformIntegration::themeNames() const
{
return QStringList(QString(androidThemeName));

View File

@ -50,6 +50,8 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
QAndroidPlatformServices::QAndroidPlatformServices()
{
m_actionView = QJniObject::getStaticObjectField("android/content/Intent", "ACTION_VIEW",
@ -80,7 +82,7 @@ bool QAndroidPlatformServices::openUrl(const QUrl &theUrl)
// if the file is local, we need to pass the MIME type, otherwise Android
// does not start an Intent to view this file
QLatin1String fileScheme("file");
const auto fileScheme = "file"_L1;
if ((url.scheme().isEmpty() || url.scheme() == fileScheme) && QFile::exists(url.path())) {
// a real URL including the scheme is needed, else the Intent can not be started
url.setScheme(fileScheme);

View File

@ -58,6 +58,8 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace {
const int textStyle_bold = 1;
const int textStyle_italic = 2;
@ -69,44 +71,44 @@ namespace {
static int fontType(const QString &androidControl)
{
if (androidControl == QLatin1String("defaultStyle"))
if (androidControl == "defaultStyle"_L1)
return QPlatformTheme::SystemFont;
if (androidControl == QLatin1String("textViewStyle"))
if (androidControl == "textViewStyle"_L1)
return QPlatformTheme::LabelFont;
else if (androidControl == QLatin1String("buttonStyle"))
else if (androidControl == "buttonStyle"_L1)
return QPlatformTheme::PushButtonFont;
else if (androidControl == QLatin1String("checkboxStyle"))
else if (androidControl == "checkboxStyle"_L1)
return QPlatformTheme::CheckBoxFont;
else if (androidControl == QLatin1String("radioButtonStyle"))
else if (androidControl == "radioButtonStyle"_L1)
return QPlatformTheme::RadioButtonFont;
else if (androidControl == QLatin1String("simple_list_item_single_choice"))
else if (androidControl == "simple_list_item_single_choice"_L1)
return QPlatformTheme::ItemViewFont;
else if (androidControl == QLatin1String("simple_spinner_dropdown_item"))
else if (androidControl == "simple_spinner_dropdown_item"_L1)
return QPlatformTheme::ComboMenuItemFont;
else if (androidControl == QLatin1String("spinnerStyle"))
else if (androidControl == "spinnerStyle"_L1)
return QPlatformTheme::ComboLineEditFont;
else if (androidControl == QLatin1String("simple_list_item"))
else if (androidControl == "simple_list_item"_L1)
return QPlatformTheme::ListViewFont;
return -1;
}
static int paletteType(const QString &androidControl)
{
if (androidControl == QLatin1String("defaultStyle"))
if (androidControl == "defaultStyle"_L1)
return QPlatformTheme::SystemPalette;
if (androidControl == QLatin1String("textViewStyle"))
if (androidControl == "textViewStyle"_L1)
return QPlatformTheme::LabelPalette;
else if (androidControl == QLatin1String("buttonStyle"))
else if (androidControl == "buttonStyle"_L1)
return QPlatformTheme::ButtonPalette;
else if (androidControl == QLatin1String("checkboxStyle"))
else if (androidControl == "checkboxStyle"_L1)
return QPlatformTheme::CheckBoxPalette;
else if (androidControl == QLatin1String("radioButtonStyle"))
else if (androidControl == "radioButtonStyle"_L1)
return QPlatformTheme::RadioButtonPalette;
else if (androidControl == QLatin1String("simple_list_item_single_choice"))
else if (androidControl == "simple_list_item_single_choice"_L1)
return QPlatformTheme::ItemViewPalette;
else if (androidControl == QLatin1String("editTextStyle"))
else if (androidControl == "editTextStyle"_L1)
return QPlatformTheme::TextLineEditPalette;
else if (androidControl == QLatin1String("spinnerStyle"))
else if (androidControl == "spinnerStyle"_L1)
return QPlatformTheme::ComboBoxPalette;
return -1;
}
@ -118,17 +120,17 @@ static void setPaletteColor(const QVariantMap &object,
// QPalette::Active -> ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
palette.setColor(QPalette::Active,
role,
QRgb(object.value(QLatin1String("ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET")).toInt()));
QRgb(object.value("ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET"_L1).toInt()));
// QPalette::Inactive -> ENABLED_STATE_SET
palette.setColor(QPalette::Inactive,
role,
QRgb(object.value(QLatin1String("ENABLED_STATE_SET")).toInt()));
QRgb(object.value("ENABLED_STATE_SET"_L1).toInt()));
// QPalette::Disabled -> EMPTY_STATE_SET
palette.setColor(QPalette::Disabled,
role,
QRgb(object.value(QLatin1String("EMPTY_STATE_SET")).toInt()));
QRgb(object.value("EMPTY_STATE_SET"_L1).toInt()));
palette.setColor(QPalette::Current, role, palette.color(QPalette::Active, role));
@ -137,17 +139,17 @@ static void setPaletteColor(const QVariantMap &object,
// QPalette::Active -> PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
palette.setColor(QPalette::Active,
QPalette::BrightText,
QRgb(object.value(QLatin1String("PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET")).toInt()));
QRgb(object.value("PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET"_L1).toInt()));
// QPalette::Inactive -> PRESSED_ENABLED_STATE_SET
palette.setColor(QPalette::Inactive,
QPalette::BrightText,
QRgb(object.value(QLatin1String("PRESSED_ENABLED_STATE_SET")).toInt()));
QRgb(object.value("PRESSED_ENABLED_STATE_SET"_L1).toInt()));
// QPalette::Disabled -> PRESSED_STATE_SET
palette.setColor(QPalette::Disabled,
QPalette::BrightText,
QRgb(object.value(QLatin1String("PRESSED_STATE_SET")).toInt()));
QRgb(object.value("PRESSED_STATE_SET"_L1).toInt()));
palette.setColor(QPalette::Current, QPalette::BrightText, palette.color(QPalette::Active, QPalette::BrightText));
@ -155,17 +157,17 @@ static void setPaletteColor(const QVariantMap &object,
// QPalette::Active -> ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
palette.setColor(QPalette::Active,
QPalette::HighlightedText,
QRgb(object.value(QLatin1String("ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET")).toInt()));
QRgb(object.value("ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET"_L1).toInt()));
// QPalette::Inactive -> ENABLED_SELECTED_STATE_SET
palette.setColor(QPalette::Inactive,
QPalette::HighlightedText,
QRgb(object.value(QLatin1String("ENABLED_SELECTED_STATE_SET")).toInt()));
QRgb(object.value("ENABLED_SELECTED_STATE_SET"_L1).toInt()));
// QPalette::Disabled -> SELECTED_STATE_SET
palette.setColor(QPalette::Disabled,
QPalette::HighlightedText,
QRgb(object.value(QLatin1String("SELECTED_STATE_SET")).toInt()));
QRgb(object.value("SELECTED_STATE_SET"_L1).toInt()));
palette.setColor(QPalette::Current,
QPalette::HighlightedText,
@ -198,10 +200,10 @@ QJsonObject AndroidStyle::loadStyleData()
if (!androidTheme.isEmpty() && !androidTheme.endsWith(slashChar))
androidTheme += slashChar;
if (!androidTheme.isEmpty() && QFileInfo::exists(stylePath + androidTheme + QLatin1String("style.json")))
if (!androidTheme.isEmpty() && QFileInfo::exists(stylePath + androidTheme + "style.json"_L1))
stylePath += androidTheme;
QFile f(stylePath + QLatin1String("style.json"));
QFile f(stylePath + "style.json"_L1);
if (!f.open(QIODevice::ReadOnly))
return QJsonObject();
@ -228,7 +230,7 @@ static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
return std::shared_ptr<AndroidStyle>();
{
QFont font(QLatin1String("Droid Sans Mono"), 14.0 * 100 / 72);
QFont font("Droid Sans Mono"_L1, 14.0 * 100 / 72);
style->m_fonts.insert(QPlatformTheme::FixedFont, font);
}
@ -242,7 +244,7 @@ static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
continue;
}
QJsonObject item = value.toObject();
QJsonObject::const_iterator attributeIterator = item.find(QLatin1String("qtClass"));
QJsonObject::const_iterator attributeIterator = item.find("qtClass"_L1);
QByteArray qtClassName;
if (attributeIterator != item.constEnd()) {
// The item has palette and font information for a specific Qt Class (e.g. QWidget, QPushButton, etc.)
@ -254,12 +256,12 @@ static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
QFont font;
// Font size (in pixels)
attributeIterator = item.find(QLatin1String("TextAppearance_textSize"));
attributeIterator = item.find("TextAppearance_textSize"_L1);
if (attributeIterator != item.constEnd())
font.setPixelSize(int(attributeIterator.value().toDouble() / pixelDensity));
// Font style
attributeIterator = item.find(QLatin1String("TextAppearance_textStyle"));
attributeIterator = item.find("TextAppearance_textStyle"_L1);
if (attributeIterator != item.constEnd()) {
const int style = int(attributeIterator.value().toDouble());
font.setBold(style & textStyle_bold);
@ -267,7 +269,7 @@ static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
}
// Font typeface
attributeIterator = item.find(QLatin1String("TextAppearance_typeface"));
attributeIterator = item.find("TextAppearance_typeface"_L1);
if (attributeIterator != item.constEnd()) {
QFont::StyleHint styleHint = QFont::AnyStyle;
switch (int(attributeIterator.value().toDouble())) {
@ -299,23 +301,23 @@ static std::shared_ptr<AndroidStyle> loadAndroidStyle(QPalette *defaultPalette)
// Extract palette information
QPalette palette = *defaultPalette;
attributeIterator = item.find(QLatin1String("defaultTextColorPrimary"));
attributeIterator = item.find("defaultTextColorPrimary"_L1);
if (attributeIterator != item.constEnd())
palette.setColor(QPalette::WindowText, QRgb(int(attributeIterator.value().toDouble())));
attributeIterator = item.find(QLatin1String("defaultBackgroundColor"));
attributeIterator = item.find("defaultBackgroundColor"_L1);
if (attributeIterator != item.constEnd())
palette.setColor(QPalette::Window, QRgb(int(attributeIterator.value().toDouble())));
attributeIterator = item.find(QLatin1String("TextAppearance_textColor"));
attributeIterator = item.find("TextAppearance_textColor"_L1);
if (attributeIterator != item.constEnd())
setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::WindowText);
attributeIterator = item.find(QLatin1String("TextAppearance_textColorLink"));
attributeIterator = item.find("TextAppearance_textColorLink"_L1);
if (attributeIterator != item.constEnd())
setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::Link);
attributeIterator = item.find(QLatin1String("TextAppearance_textColorHighlight"));
attributeIterator = item.find("TextAppearance_textColorHighlight"_L1);
if (attributeIterator != item.constEnd())
palette.setColor(QPalette::Highlight, QRgb(int(attributeIterator.value().toDouble())));
@ -369,7 +371,7 @@ QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *an
androidPlatformNativeInterface->m_androidStyle = m_androidStyleData;
// default in case the style has not set a font
m_systemFont = QFont(QLatin1String("Roboto"), 14.0 * 100 / 72); // keep default size the same after changing from 100 dpi to 72 dpi
m_systemFont = QFont("Roboto"_L1, 14.0 * 100 / 72); // keep default size the same after changing from 100 dpi to 72 dpi
}
QPlatformMenuBar *QAndroidPlatformTheme::createPlatformMenuBar() const
@ -463,9 +465,9 @@ QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const
case StyleNames:
if (qEnvironmentVariableIntValue("QT_USE_ANDROID_NATIVE_STYLE")
&& m_androidStyleData) {
return QStringList(QLatin1String("android"));
return QStringList("android"_L1);
}
return QStringList(QLatin1String("Fusion"));
return QStringList("Fusion"_L1);
case DialogButtonBoxLayout:
return QVariant(QPlatformDialogHelper::AndroidLayout);
case MouseDoubleClickDistance:

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,8 @@
#define QT_POPEN_READ "r"
#endif
using namespace Qt::StringLiterals;
static bool checkJunit(const QByteArray &data) {
QXmlStreamReader reader{data};
while (!reader.atEnd()) {
@ -70,12 +72,12 @@ static bool checkJunit(const QByteArray &data) {
}
static bool checkTxt(const QByteArray &data) {
if (data.indexOf(QLatin1String("\nFAIL! : ")) >= 0)
if (data.indexOf("\nFAIL! : "_L1) >= 0)
return false;
if (data.indexOf(QLatin1String("\nXPASS : ")) >= 0)
if (data.indexOf("\nXPASS : "_L1) >= 0)
return false;
// Look for "********* Finished testing of tst_QTestName *********"
static const QRegularExpression testTail(QLatin1String("\\*+ +Finished testing of .+ +\\*+"));
static const QRegularExpression testTail("\\*+ +Finished testing of .+ +\\*+"_L1);
return testTail.match(QLatin1String(data)).hasMatch();
}
@ -118,7 +120,7 @@ static bool checkTeamcity(const QByteArray &data) {
const QList<QByteArray> lines = data.trimmed().split('\n');
if (lines.isEmpty())
return false;
return lines.last().startsWith(QLatin1String("##teamcity[testSuiteFinished "));
return lines.last().startsWith("##teamcity[testSuiteFinished "_L1);
}
static bool checkTap(const QByteArray &data) {
@ -127,7 +129,7 @@ static bool checkTap(const QByteArray &data) {
if (data.indexOf("\nnot ok ") >= 0)
return false;
static const QRegularExpression testTail(QLatin1String("ok [0-9]* - cleanupTestCase\\(\\)"));
static const QRegularExpression testTail("ok [0-9]* - cleanupTestCase\\(\\)"_L1);
return testTail.match(QLatin1String(data)).hasMatch();
}