uic: 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: I0d3c232a9fa95aea854445922f100b89c6d6f5a1
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
bb10
Sona Kurazyan 2022-04-13 17:21:47 +02:00
parent 3aef84d600
commit fedba8eaab
8 changed files with 26 additions and 27 deletions

View File

@ -75,7 +75,7 @@ void WriteDeclaration::acceptUI(DomUI *node)
QString exportMacro = node->elementExportMacro();
if (!exportMacro.isEmpty())
exportMacro.append(QLatin1Char(' '));
exportMacro.append(u' ');
QStringList namespaceList = qualifiedClassName.split(QLatin1String("::"));
if (namespaceList.count()) {

View File

@ -47,7 +47,7 @@ enum { warnHeaderGeneration = 0 };
static inline QString moduleHeader(const QString &module, const QString &header)
{
QString rc = module;
rc += QLatin1Char('/');
rc += u'/';
rc += header;
return rc;
}
@ -190,8 +190,8 @@ void WriteIncludes::insertInclude(const QString &header, bool global)
void WriteIncludes::writeHeaders(const OrderedSet &headers, bool global)
{
const QChar openingQuote = global ? QLatin1Char('<') : QLatin1Char('"');
const QChar closingQuote = global ? QLatin1Char('>') : QLatin1Char('"');
const QChar openingQuote = global ? u'<' : u'"';
const QChar closingQuote = global ? u'>' : u'"';
// Check for the old headers 'qslider.h' and replace by 'QtGui/QSlider'
for (const QString &header : headers) {

View File

@ -983,7 +983,7 @@ void WriteInitialization::acceptLayout(DomLayout *node)
m_layoutChain.pop();
// Stretch? (Unless we are compiling for UIC3)
const QString numberNull = QString(QLatin1Char('0'));
const QString numberNull(u'0');
writePropertyList(varName, QLatin1String("setStretch"), node->attributeStretch(), numberNull);
writePropertyList(varName, QLatin1String("setRowStretch"), node->attributeRowStretch(), numberNull);
writePropertyList(varName, QLatin1String("setColumnStretch"), node->attributeColumnStretch(), numberNull);
@ -999,7 +999,7 @@ void WriteInitialization::writePropertyList(const QString &varName,
{
if (value.isEmpty())
return;
const QStringList list = value.split(QLatin1Char(','));
const QStringList list = value.split(u',');
const int count = list.count();
for (int i = 0; i < count; i++) {
if (list.at(i) != defaultValue) {
@ -1375,7 +1375,7 @@ void WriteInitialization::writeProperties(const QString &varName,
if (p->hasAttributeStdset() && !p->attributeStdset())
varNewName += language::derefPointer + QLatin1String("viewport()");
propertyValue = QLatin1String("QCursor(Qt") + language::qualifier
+ p->elementCursorShape() + QLatin1Char(')');
+ p->elementCursorShape() + u')';
break;
case DomProperty::Enum:
propertyValue = p->elementEnum();
@ -1479,17 +1479,17 @@ void WriteInitialization::writeProperties(const QString &varName,
break;
case DomProperty::UInt:
propertyValue = QString::number(p->elementUInt());
propertyValue += QLatin1Char('u');
propertyValue += u'u';
break;
case DomProperty::LongLong:
propertyValue = QLatin1String("Q_INT64_C(");
propertyValue += QString::number(p->elementLongLong());
propertyValue += QLatin1Char(')');;
propertyValue += u')';
break;
case DomProperty::ULongLong:
propertyValue = QLatin1String("Q_UINT64_C(");
propertyValue += QString::number(p->elementULongLong());
propertyValue += QLatin1Char(')');
propertyValue += u')';
break;
case DomProperty::Float:
propertyValue = QString::number(p->elementFloat(), 'f', 8);
@ -2227,10 +2227,10 @@ void WriteInitialization::addQtFlagsInitializer(Item *item,
const DomPropertyMap &properties, const QString &name, int column) const
{
if (const DomProperty *p = properties.value(name)) {
const QString orOperator = QLatin1Char('|') + language::qtQualifier;
const QString orOperator = u'|' + language::qtQualifier;
QString v = p->elementSet();
if (!v.isEmpty()) {
v.replace(QLatin1Char('|'), orOperator);
v.replace(u'|', orOperator);
addInitializer(item, name, column, language::qtQualifier + v);
}
}

View File

@ -152,7 +152,7 @@ QString Driver::normalizedName(const QString &name)
QString result = name;
std::replace_if(result.begin(), result.end(),
[] (QChar c) { return !c.isLetterOrNumber(); },
QLatin1Char('_'));
u'_');
return result;
}
@ -190,7 +190,7 @@ QString Driver::qtify(const QString &name)
{
QString qname = name;
if (qname.at(0) == QLatin1Char('Q') || qname.at(0) == QLatin1Char('K'))
if (qname.at(0) == u'Q' || qname.at(0) == u'K')
qname.remove(0, 1);
for (int i = 0, size = qname.size(); i < size && qname.at(i).isUpper(); ++i)
@ -201,8 +201,7 @@ QString Driver::qtify(const QString &name)
static bool isAnsiCCharacter(QChar c)
{
return (c.toUpper() >= QLatin1Char('A') && c.toUpper() <= QLatin1Char('Z'))
|| c.isDigit() || c == QLatin1Char('_');
return (c.toUpper() >= u'A' && c.toUpper() <= u'Z') || c.isDigit() || c == u'_';
}
QString Driver::headerFileName() const
@ -226,13 +225,13 @@ QString Driver::headerFileName(const QString &fileName)
QString baseName = info.baseName();
// Transform into a valid C++ identifier
if (!baseName.isEmpty() && baseName.at(0).isDigit())
baseName.prepend(QLatin1Char('_'));
baseName.prepend(u'_');
for (int i = 0; i < baseName.size(); ++i) {
QChar c = baseName.at(i);
if (!isAnsiCCharacter(c)) {
// Replace character by its unicode value
QString hex = QString::number(c.unicode(), 16);
baseName.replace(i, 1, QLatin1Char('_') + hex + QLatin1Char('_'));
baseName.replace(i, 1, u'_' + hex + u'_');
i += hex.size() + 1;
}
}

View File

@ -74,7 +74,7 @@ struct Option
forceStringConnectionSyntax(0),
useStarImports(0),
prefix(QLatin1String("Ui_"))
{ indent.fill(QLatin1Char(' '), 4); }
{ indent.fill(u' ', 4); }
QString messagePrefix() const
{

View File

@ -81,7 +81,7 @@ static WriteImports::ClassesPerModule defaultClasses()
// module name "foo_rc" according to project conventions.
static QString pythonResource(QString resource)
{
const int lastSlash = resource.lastIndexOf(QLatin1Char('/'));
const qsizetype lastSlash = resource.lastIndexOf(u'/');
if (lastSlash != -1)
resource.remove(0, lastSlash + 1);
if (resource.endsWith(QLatin1String(".qrc"))) {
@ -223,7 +223,7 @@ void WriteImports::addPythonCustomWidget(const QString &className, const DomCust
} else { // When we do have elementHeader, we know it's a relative import.
QString modulePath = node->elementHeader()->text();
// Replace the '/' by '.'
modulePath.replace(QLatin1Char('/'), QLatin1Char('.'));
modulePath.replace(u'/', u'.');
// '.h' is added by default on headers for <customwidget>
if (modulePath.endsWith(QLatin1String(".h")))
modulePath.chop(2);

View File

@ -217,7 +217,7 @@ static int formatEscapedNumber(QTextStream &str, ushort value, int base, int wid
const auto oldFieldWidth = str.fieldWidth();
const auto oldFieldAlignment = str.fieldAlignment();
const auto oldIntegerBase = str.integerBase();
str.setPadChar(QLatin1Char('0'));
str.setPadChar(u'0');
str.setFieldWidth(width);
str.setFieldAlignment(QTextStream::AlignRight);
str.setIntegerBase(base);
@ -405,7 +405,7 @@ enum OverloadUse {
static void formatMemberFnPtr(QTextStream &str, const SignalSlot &s,
OverloadUse useQOverload = DontUseOverload)
{
const int parenPos = s.signature.indexOf(QLatin1Char('('));
const qsizetype parenPos = s.signature.indexOf(u'(');
Q_ASSERT(parenPos >= 0);
const auto functionName = QStringView{s.signature}.left(parenPos);
@ -469,7 +469,7 @@ void formatConnection(QTextStream &str, const SignalSlot &sender, const SignalSl
str << "[\"" << parameters << "\"]";
}
str << ".connect(" << receiver.name << '.'
<< QStringView{receiver.signature}.left(receiver.signature.indexOf(QLatin1Char('(')))
<< QStringView{receiver.signature}.left(receiver.signature.indexOf(u'('))
<< ')';
}
break;

View File

@ -127,7 +127,7 @@ void Uic::writeCopyrightHeaderCpp(const DomUI *ui) const
static inline bool isCppCommentChar(QChar c)
{
return c == QLatin1Char('/') || c == QLatin1Char('*');
return c == u'/' || c == u'*';
}
static int leadingCppCommentCharCount(QStringView s)
@ -142,13 +142,13 @@ void Uic::writeCopyrightHeaderPython(const DomUI *ui) const
{
QString comment = ui->elementComment();
if (!comment.isEmpty()) {
const auto lines = QStringView{comment}.split(QLatin1Char('\n'));
const auto lines = QStringView{comment}.split(u'\n');
for (const auto &line : lines) {
if (const int leadingCommentChars = leadingCppCommentCharCount(line)) {
out << language::repeat(leadingCommentChars, '#')
<< line.right(line.size() - leadingCommentChars);
} else {
if (!line.startsWith(QLatin1Char('#')))
if (!line.startsWith(u'#'))
out << "# ";
out << line;
}