uic: replace QLatin1String uses with _L1 or _s

Task-number: QTBUG-98434
Change-Id: I5a9b01d1dd2a2a727cfb71e829dbf631bf25e2db
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Sona Kurazyan 2022-04-14 10:21:11 +02:00
parent 07071e3c0c
commit cd9cbc34db
11 changed files with 264 additions and 248 deletions

View File

@ -39,6 +39,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace { namespace {
void openNameSpaces(const QStringList &namespaceList, QTextStream &output) void openNameSpaces(const QStringList &namespaceList, QTextStream &output)
{ {
@ -77,7 +79,7 @@ void WriteDeclaration::acceptUI(DomUI *node)
if (!exportMacro.isEmpty()) if (!exportMacro.isEmpty())
exportMacro.append(u' '); exportMacro.append(u' ');
QStringList namespaceList = qualifiedClassName.split(QLatin1String("::")); QStringList namespaceList = qualifiedClassName.split("::"_L1);
if (namespaceList.count()) { if (namespaceList.count()) {
className = namespaceList.last(); className = namespaceList.last();
namespaceList.removeLast(); namespaceList.removeLast();
@ -89,7 +91,7 @@ void WriteDeclaration::acceptUI(DomUI *node)
// In this case the generated Ui helper classes will also end up in // In this case the generated Ui helper classes will also end up in
// the Qt namespace (which is harmless, but not "pretty") // the Qt namespace (which is harmless, but not "pretty")
const bool needsMacro = namespaceList.count() == 0 const bool needsMacro = namespaceList.count() == 0
|| namespaceList[0] == QLatin1String("qdesigner_internal"); || namespaceList[0] == "qdesigner_internal"_L1;
if (needsMacro) if (needsMacro)
m_output << "QT_BEGIN_NAMESPACE\n\n"; m_output << "QT_BEGIN_NAMESPACE\n\n";
@ -105,7 +107,7 @@ void WriteDeclaration::acceptUI(DomUI *node)
const QStringList connections = m_uic->databaseInfo()->connections(); const QStringList connections = m_uic->databaseInfo()->connections();
for (const QString &connection : connections) { for (const QString &connection : connections) {
if (connection != QLatin1String("(default)")) if (connection != "(default)"_L1)
m_output << m_option.indent << "QSqlDatabase " << connection << "Connection;\n"; m_output << m_option.indent << "QSqlDatabase " << connection << "Connection;\n";
} }
@ -125,7 +127,7 @@ void WriteDeclaration::acceptUI(DomUI *node)
m_output << "\n"; m_output << "\n";
if (m_option.generateNamespace && !m_option.prefix.isEmpty()) { if (m_option.generateNamespace && !m_option.prefix.isEmpty()) {
namespaceList.append(QLatin1String("Ui")); namespaceList.append("Ui"_L1);
openNameSpaces(namespaceList, m_output); openNameSpaces(namespaceList, m_output);
@ -143,7 +145,7 @@ void WriteDeclaration::acceptUI(DomUI *node)
void WriteDeclaration::acceptWidget(DomWidget *node) void WriteDeclaration::acceptWidget(DomWidget *node)
{ {
QString className = QLatin1String("QWidget"); QString className = "QWidget"_L1;
if (node->hasAttributeClass()) if (node->hasAttributeClass())
className = node->attributeClass(); className = node->attributeClass();
@ -160,7 +162,7 @@ void WriteDeclaration::acceptSpacer(DomSpacer *node)
void WriteDeclaration::acceptLayout(DomLayout *node) void WriteDeclaration::acceptLayout(DomLayout *node)
{ {
QString className = QLatin1String("QLayout"); QString className = "QLayout"_L1;
if (node->hasAttributeClass()) if (node->hasAttributeClass())
className = node->attributeClass(); className = node->attributeClass();

View File

@ -40,6 +40,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
enum { debugWriteIncludes = 0 }; enum { debugWriteIncludes = 0 };
enum { warnHeaderGeneration = 0 }; enum { warnHeaderGeneration = 0 };
@ -60,7 +62,7 @@ WriteIncludes::WriteIncludes(Uic *uic) : WriteIncludesBase(uic),
// When possible (no namespace) use the "QtModule/QClass" convention // When possible (no namespace) use the "QtModule/QClass" convention
// and create a re-mapping of the old header "qclass.h" to it. Do not do this // and create a re-mapping of the old header "qclass.h" to it. Do not do this
// for the "Phonon::Someclass" classes, however. // for the "Phonon::Someclass" classes, however.
const QString namespaceDelimiter = QLatin1String("::"); const QString namespaceDelimiter = "::"_L1;
for (const auto &e : classInfoEntries()) { for (const auto &e : classInfoEntries()) {
const QString klass = QLatin1String(e.klass); const QString klass = QLatin1String(e.klass);
const QString module = QLatin1String(e.module); const QString module = QLatin1String(e.module);
@ -113,7 +115,7 @@ void WriteIncludes::insertIncludeForClass(const QString &className, QString head
// Quick check by class name to detect includehints provided for custom widgets. // Quick check by class name to detect includehints provided for custom widgets.
// Remove namespaces // Remove namespaces
QString lowerClassName = className.toLower(); QString lowerClassName = className.toLower();
static const QString namespaceSeparator = QLatin1String("::"); static const QString namespaceSeparator = "::"_L1;
const int namespaceIndex = lowerClassName.lastIndexOf(namespaceSeparator); const int namespaceIndex = lowerClassName.lastIndexOf(namespaceSeparator);
if (namespaceIndex != -1) if (namespaceIndex != -1)
lowerClassName.remove(0, namespaceIndex + namespaceSeparator.size()); lowerClassName.remove(0, namespaceIndex + namespaceSeparator.size());
@ -126,7 +128,7 @@ void WriteIncludes::insertIncludeForClass(const QString &className, QString head
if (!uic()->option().implicitIncludes) if (!uic()->option().implicitIncludes)
break; break;
header = lowerClassName; header = lowerClassName;
header += QLatin1String(".h"); header += ".h"_L1;
if (warnHeaderGeneration) { if (warnHeaderGeneration) {
qWarning("%s: Warning: generated header '%s' for class '%s'.", qWarning("%s: Warning: generated header '%s' for class '%s'.",
qPrintable(uic()->option().messagePrefix()), qPrintable(uic()->option().messagePrefix()),
@ -157,7 +159,7 @@ void WriteIncludes::addCppCustomWidget(const QString &className, const DomCustom
QString header; QString header;
bool global = false; bool global = false;
if (!m_classToHeader.contains(className)) { if (!m_classToHeader.contains(className)) {
global = domHeader->attributeLocation().toLower() == QLatin1String("global"); global = domHeader->attributeLocation().toLower() == "global"_L1;
header = domHeader->text(); header = domHeader->text();
} }
insertIncludeForClass(className, header, global); insertIncludeForClass(className, header, global);
@ -169,7 +171,7 @@ void WriteIncludes::acceptInclude(DomInclude *node)
{ {
bool global = true; bool global = true;
if (node->hasAttributeLocation()) if (node->hasAttributeLocation())
global = node->attributeLocation() == QLatin1String("global"); global = node->attributeLocation() == "global"_L1;
insertInclude(node->text(), global); insertInclude(node->text(), global);
} }

File diff suppressed because it is too large Load Diff

View File

@ -120,8 +120,8 @@ bool CustomWidgetsInfo::isAmbiguousSignal(const QString &className,
QString CustomWidgetsInfo::realClassName(const QString &className) const QString CustomWidgetsInfo::realClassName(const QString &className) const
{ {
if (className == QLatin1String("Line")) if (className == "Line"_L1)
return QLatin1String("QFrame"); return "QFrame"_L1;
return className; return className;
} }

View File

@ -33,6 +33,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
DatabaseInfo::DatabaseInfo() = default; DatabaseInfo::DatabaseInfo() = default;
void DatabaseInfo::acceptUI(DomUI *node) void DatabaseInfo::acceptUI(DomUI *node)
@ -50,11 +52,11 @@ void DatabaseInfo::acceptWidget(DomWidget *node)
{ {
QHash<QString, DomProperty*> properties = propertyMap(node->elementProperty()); QHash<QString, DomProperty*> properties = propertyMap(node->elementProperty());
DomProperty *frameworkCode = properties.value(QLatin1String("frameworkCode")); DomProperty *frameworkCode = properties.value("frameworkCode"_L1);
if (frameworkCode && toBool(frameworkCode->elementBool()) == false) if (frameworkCode && toBool(frameworkCode->elementBool()) == false)
return; return;
DomProperty *db = properties.value(QLatin1String("database")); DomProperty *db = properties.value("database"_L1);
if (db && db->elementStringList()) { if (db && db->elementStringList()) {
QStringList info = db->elementStringList()->elementString(); QStringList info = db->elementStringList()->elementString();
if (info.isEmpty() || info.constFirst().isEmpty()) if (info.isEmpty() || info.constFirst().isEmpty())

View File

@ -39,6 +39,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
Driver::Driver() Driver::Driver()
: m_stdout(stdout, QFile::WriteOnly | QFile::Text) : m_stdout(stdout, QFile::WriteOnly | QFile::Text)
{ {
@ -172,7 +174,7 @@ QString Driver::unique(const QString &instanceName, const QString &className)
} else if (!className.isEmpty()) { } else if (!className.isEmpty()) {
name = unique(qtify(className)); name = unique(qtify(className));
} else { } else {
name = unique(QLatin1String("var")); name = unique("var"_L1);
} }
if (alreadyUsed && !className.isEmpty()) { if (alreadyUsed && !className.isEmpty()) {
@ -209,7 +211,7 @@ QString Driver::headerFileName() const
QString name = m_option.outputFile; QString name = m_option.outputFile;
if (name.isEmpty()) { if (name.isEmpty()) {
name = QLatin1String("ui_"); // ### use ui_ as prefix. name = "ui_"_L1; // ### use ui_ as prefix.
name.append(m_option.inputFile); name.append(m_option.inputFile);
} }
@ -219,7 +221,7 @@ QString Driver::headerFileName() const
QString Driver::headerFileName(const QString &fileName) QString Driver::headerFileName(const QString &fileName)
{ {
if (fileName.isEmpty()) if (fileName.isEmpty())
return headerFileName(QLatin1String("noname")); return headerFileName("noname"_L1);
QFileInfo info(fileName); QFileInfo info(fileName);
QString baseName = info.baseName(); QString baseName = info.baseName();
@ -235,7 +237,7 @@ QString Driver::headerFileName(const QString &fileName)
i += hex.size() + 1; i += hex.size() + 1;
} }
} }
return baseName.toUpper() + QLatin1String("_H"); return baseName.toUpper() + "_H"_L1;
} }
bool Driver::printDependencies(const QString &fileName) bool Driver::printDependencies(const QString &fileName)

View File

@ -41,6 +41,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
int runUic(int argc, char *argv[]) int runUic(int argc, char *argv[])
{ {
qSetGlobalQHashSeed(0); // set the hash seed to 0 qSetGlobalQHashSeed(0); // set the hash seed to 0
@ -134,15 +136,15 @@ int runUic(int argc, char *argv[])
driver.option().includeFile = parser.value(includeOption); driver.option().includeFile = parser.value(includeOption);
if (parser.isSet(connectionsOption)) { if (parser.isSet(connectionsOption)) {
const auto value = parser.value(connectionsOption); const auto value = parser.value(connectionsOption);
if (value == QLatin1String("pmf")) if (value == "pmf"_L1)
driver.option().forceMemberFnPtrConnectionSyntax = 1; driver.option().forceMemberFnPtrConnectionSyntax = 1;
else if (value == QLatin1String("string")) else if (value == "string"_L1)
driver.option().forceStringConnectionSyntax = 1; driver.option().forceStringConnectionSyntax = 1;
} }
Language language = Language::Cpp; Language language = Language::Cpp;
if (parser.isSet(generatorOption)) { if (parser.isSet(generatorOption)) {
if (parser.value(generatorOption).compare(QLatin1String("python")) == 0) if (parser.value(generatorOption).compare("python"_L1) == 0)
language = Language::Python; language = Language::Python;
} }
language::setLanguage(language); language::setLanguage(language);

View File

@ -38,6 +38,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace Python { namespace Python {
WriteDeclaration::WriteDeclaration(Uic *uic) : WriteDeclaration::WriteDeclaration(Uic *uic) :
@ -51,7 +53,7 @@ WriteDeclaration::WriteDeclaration(Uic *uic) :
void WriteDeclaration::acceptUI(DomUI *node) void WriteDeclaration::acceptUI(DomUI *node)
{ {
// remove any left-over C++ namespaces // remove any left-over C++ namespaces
const QString qualifiedClassName = QLatin1String("Ui_") + node->elementClass() const QString qualifiedClassName = "Ui_"_L1 + node->elementClass()
+ m_option.postfix; + m_option.postfix;
m_output << "class " << language::fixClassName(qualifiedClassName) << "(object):\n"; m_output << "class " << language::fixClassName(qualifiedClassName) << "(object):\n";

View File

@ -41,6 +41,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
// Generate imports for Python. Note some things differ from C++: // Generate imports for Python. Note some things differ from C++:
// - qItemView->header()->setFoo() does not require QHeaderView to be imported // - qItemView->header()->setFoo() does not require QHeaderView to be imported
// - qLabel->setFrameShape(QFrame::Box) however requires QFrame to be imported // - qLabel->setFrameShape(QFrame::Box) however requires QFrame to be imported
@ -84,9 +86,9 @@ static QString pythonResource(QString resource)
const qsizetype lastSlash = resource.lastIndexOf(u'/'); const qsizetype lastSlash = resource.lastIndexOf(u'/');
if (lastSlash != -1) if (lastSlash != -1)
resource.remove(0, lastSlash + 1); resource.remove(0, lastSlash + 1);
if (resource.endsWith(QLatin1String(".qrc"))) { if (resource.endsWith(".qrc"_L1)) {
resource.chop(4); resource.chop(4);
resource.append(QLatin1String("_rc")); resource.append("_rc"_L1);
} }
return resource; return resource;
} }
@ -210,7 +212,7 @@ bool WriteImports::addQtClass(const QString &className)
void WriteImports::addPythonCustomWidget(const QString &className, const DomCustomWidget *node) void WriteImports::addPythonCustomWidget(const QString &className, const DomCustomWidget *node)
{ {
if (className.contains(QLatin1String("::"))) if (className.contains("::"_L1))
return; // Exclude namespaced names (just to make tests pass). return; // Exclude namespaced names (just to make tests pass).
if (addQtClass(className)) // Qt custom widgets like QQuickWidget, QAxWidget, etc if (addQtClass(className)) // Qt custom widgets like QQuickWidget, QAxWidget, etc
@ -225,7 +227,7 @@ void WriteImports::addPythonCustomWidget(const QString &className, const DomCust
// Replace the '/' by '.' // Replace the '/' by '.'
modulePath.replace(u'/', u'.'); modulePath.replace(u'/', u'.');
// '.h' is added by default on headers for <customwidget> // '.h' is added by default on headers for <customwidget>
if (modulePath.endsWith(QLatin1String(".h"))) if (modulePath.endsWith(".h"_L1))
modulePath.chop(2); modulePath.chop(2);
insertClass(modulePath, className, &m_customWidgets); insertClass(modulePath, className, &m_customWidgets);
} }

View File

@ -32,6 +32,8 @@
namespace language { namespace language {
using namespace Qt::StringLiterals;
static Encoding encoding = Encoding::Utf8; static Encoding encoding = Encoding::Utf8;
static Language _language = Language::Cpp; static Language _language = Language::Cpp;
@ -42,29 +44,29 @@ void setLanguage(Language l)
_language = l; _language = l;
switch (_language) { switch (_language) {
case Language::Cpp: case Language::Cpp:
derefPointer = QLatin1String("->"); derefPointer = u"->"_s;
listStart = '{'; listStart = '{';
listEnd = '}'; listEnd = '}';
nullPtr = QLatin1String("nullptr"); nullPtr = u"nullptr"_s;
operatorNew = QLatin1String("new "); operatorNew = u"new "_s;
qtQualifier = QLatin1String("Qt::"); qtQualifier = u"Qt::"_s;
qualifier = QLatin1String("::"); qualifier = u"::"_s;
self = QLatin1String(""); // for testing: change to "this->"; self = u""_s; // for testing: change to "this->";
eol = QLatin1String(";\n"); eol = u";\n"_s;
emptyString = QLatin1String("QString()"); emptyString = u"QString()"_s;
encoding = Encoding::Utf8; encoding = Encoding::Utf8;
break; break;
case Language::Python: case Language::Python:
derefPointer = QLatin1String("."); derefPointer = u"."_s;
listStart = '['; listStart = '[';
listEnd = ']'; listEnd = ']';
nullPtr = QLatin1String("None"); nullPtr = u"None"_s;
operatorNew = QLatin1String(""); operatorNew = u""_s;
qtQualifier = QLatin1String("Qt."); qtQualifier = u"Qt."_s;
qualifier = QLatin1String("."); qualifier = u"."_s;
self = QLatin1String("self."); self = u"self."_s;
eol = QLatin1String("\n"); eol = u"\n"_s;
emptyString = QLatin1String("\"\""); emptyString = u"\"\""_s;
encoding = Encoding::Unicode; encoding = Encoding::Unicode;
break; break;
} }
@ -81,9 +83,9 @@ QString self;
QString eol; QString eol;
QString emptyString; QString emptyString;
QString cppQualifier = QLatin1String("::"); QString cppQualifier = "::"_L1;
QString cppTrue = QLatin1String("true"); QString cppTrue = "true"_L1;
QString cppFalse = QLatin1String("false"); QString cppFalse = "false"_L1;
QTextStream &operator<<(QTextStream &str, const qtConfig &c) QTextStream &operator<<(QTextStream &str, const qtConfig &c)
{ {
@ -125,7 +127,7 @@ const char *lookupEnum(const EnumLookup(&array)[N], int value, int defaultIndex
QString fixClassName(QString className) QString fixClassName(QString className)
{ {
if (language() == Language::Python) if (language() == Language::Python)
className.replace(cppQualifier, QLatin1String("_")); className.replace(cppQualifier, "_"_L1);
return className; return className;
} }

View File

@ -47,6 +47,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
Uic::Uic(Driver *d) Uic::Uic(Driver *d)
: drv(d), : drv(d),
out(d->output()), out(d->output()),
@ -169,7 +171,7 @@ void Uic::writeCopyrightHeaderPython(const DomUI *ui) const
static double versionFromUiAttribute(QXmlStreamReader &reader) static double versionFromUiAttribute(QXmlStreamReader &reader)
{ {
const QXmlStreamAttributes attributes = reader.attributes(); const QXmlStreamAttributes attributes = reader.attributes();
const QString versionAttribute = QLatin1String("version"); const QString versionAttribute = "version"_L1;
if (!attributes.hasAttribute(versionAttribute)) if (!attributes.hasAttribute(versionAttribute))
return 4.0; return 4.0;
const QStringView version = attributes.value(versionAttribute); const QStringView version = attributes.value(versionAttribute);
@ -180,7 +182,7 @@ DomUI *Uic::parseUiFile(QXmlStreamReader &reader)
{ {
DomUI *ui = nullptr; DomUI *ui = nullptr;
const QString uiElement = QLatin1String("ui"); const QString uiElement = "ui"_L1;
while (!reader.atEnd()) { while (!reader.atEnd()) {
if (reader.readNext() == QXmlStreamReader::StartElement) { if (reader.readNext() == QXmlStreamReader::StartElement) {
if (reader.name().compare(uiElement, Qt::CaseInsensitive) == 0 if (reader.name().compare(uiElement, Qt::CaseInsensitive) == 0
@ -195,7 +197,7 @@ DomUI *Uic::parseUiFile(QXmlStreamReader &reader)
ui = new DomUI(); ui = new DomUI();
ui->read(reader); ui->read(reader);
} else { } else {
reader.raiseError(QLatin1String("Unexpected element ") + reader.name().toString()); reader.raiseError("Unexpected element "_L1 + reader.name().toString());
} }
} }
} }
@ -231,7 +233,7 @@ bool Uic::write(QIODevice *in)
const QString &language = ui->attributeLanguage(); const QString &language = ui->attributeLanguage();
driver()->setUseIdBasedTranslations(ui->attributeIdbasedtr()); driver()->setUseIdBasedTranslations(ui->attributeIdbasedtr());
if (!language.isEmpty() && language.compare(QLatin1String("c++"), Qt::CaseInsensitive) != 0) { if (!language.isEmpty() && language.compare("c++"_L1, Qt::CaseInsensitive) != 0) {
fprintf(stderr, "uic: File is not a \"c++\" ui file, language=%s\n", qPrintable(language)); fprintf(stderr, "uic: File is not a \"c++\" ui file, language=%s\n", qPrintable(language));
return false; return false;
} }
@ -266,8 +268,7 @@ bool Uic::write(DomUI *ui)
} }
pixFunction = ui->elementPixmapFunction(); pixFunction = ui->elementPixmapFunction();
if (pixFunction == QLatin1String("QPixmap::fromMimeSource") if (pixFunction == "QPixmap::fromMimeSource"_L1 || pixFunction == "qPixmapFromMimeSource"_L1) {
|| pixFunction == QLatin1String("qPixmapFromMimeSource")) {
fprintf(stderr, "%s: Warning: Obsolete pixmap function '%s' specified in the UI file.\n", fprintf(stderr, "%s: Warning: Obsolete pixmap function '%s' specified in the UI file.\n",
qPrintable(opt.messagePrefix()), qPrintable(pixFunction)); qPrintable(opt.messagePrefix()), qPrintable(pixFunction));
pixFunction.clear(); pixFunction.clear();
@ -315,9 +316,9 @@ void Uic::writeHeaderProtectionEnd()
bool Uic::isButton(const QString &className) const bool Uic::isButton(const QString &className) const
{ {
static const QStringList buttons = { static const QStringList buttons = {
QLatin1String("QRadioButton"), QLatin1String("QToolButton"), "QRadioButton"_L1, "QToolButton"_L1,
QLatin1String("QCheckBox"), QLatin1String("QPushButton"), "QCheckBox"_L1, "QPushButton"_L1,
QLatin1String("QCommandLinkButton") "QCommandLinkButton"_L1
}; };
return customWidgetsInfo()->extendsOneOf(className, buttons); return customWidgetsInfo()->extendsOneOf(className, buttons);
} }
@ -325,10 +326,10 @@ bool Uic::isButton(const QString &className) const
bool Uic::isContainer(const QString &className) const bool Uic::isContainer(const QString &className) const
{ {
static const QStringList containers = { static const QStringList containers = {
QLatin1String("QStackedWidget"), QLatin1String("QToolBox"), "QStackedWidget"_L1, "QToolBox"_L1,
QLatin1String("QTabWidget"), QLatin1String("QScrollArea"), "QTabWidget"_L1, "QScrollArea"_L1,
QLatin1String("QMdiArea"), QLatin1String("QWizard"), "QMdiArea"_L1, "QWizard"_L1,
QLatin1String("QDockWidget") "QDockWidget"_L1
}; };
return customWidgetsInfo()->extendsOneOf(className, containers); return customWidgetsInfo()->extendsOneOf(className, containers);
@ -337,7 +338,7 @@ bool Uic::isContainer(const QString &className) const
bool Uic::isMenu(const QString &className) const bool Uic::isMenu(const QString &className) const
{ {
static const QStringList menus = { static const QStringList menus = {
QLatin1String("QMenu"), QLatin1String("QPopupMenu") "QMenu"_L1, "QPopupMenu"_L1
}; };
return customWidgetsInfo()->extendsOneOf(className, menus); return customWidgetsInfo()->extendsOneOf(className, menus);
} }