diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-03-21 15:17:15 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-04-11 09:43:06 +0000 |
commit | eb3e5c9c312a22b61fa951aefea81126e9026f71 (patch) | |
tree | 259969716d19cfea1ec24e44a6fb8edade6ef174 | |
parent | f8d73cf765c9c81d195ccd7e5f4f50574d82e859 (diff) | |
download | qttools-eb3e5c9c312a22b61fa951aefea81126e9026f71.tar.gz |
Qt Designer: Replace QLatin1String by modern literals
Pick-to: 6.5
Change-Id: I1a76bf2224795275a8c62cf37144936bda87cbca
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
17 files changed, 60 insertions, 74 deletions
diff --git a/src/designer/src/components/formeditor/qdesigner_resource.cpp b/src/designer/src/components/formeditor/qdesigner_resource.cpp index d63f36c3c..4f7832b79 100644 --- a/src/designer/src/components/formeditor/qdesigner_resource.cpp +++ b/src/designer/src/components/formeditor/qdesigner_resource.cpp @@ -951,8 +951,8 @@ void QDesignerResource::applyProperties(QObject *o, const QList<DomProperty*> &p if (isDeprecatedQt5Property(o, p)) // ### fixme Qt 7 remove this continue; // ### fixme Qt 7 remove this: Exclude deprecated value of Qt 5. QString propertyName = p->attributeName(); - if (propertyName == QLatin1String("numDigits") && o->inherits("QLCDNumber")) // Deprecated in Qt 4, removed in Qt 5. - propertyName = QLatin1String("digitCount"); + if (propertyName == "numDigits"_L1 && o->inherits("QLCDNumber")) // Deprecated in Qt 4, removed in Qt 5. + propertyName = u"digitCount"_s; const int index = sheet->indexOf(propertyName); QVariant v; if (!readDomEnumerationValue(p, sheet, index, v)) @@ -1342,7 +1342,7 @@ DomWidget *QDesignerResource::saveWidget(QToolBar *toolBar, DomWidget *ui_parent attr = new DomProperty(); attr->setAttributeName(u"toolBarBreak"_s); - attr->setElementBool(toolBarBreak ? QLatin1String("true") : QLatin1String("false")); + attr->setElementBool(toolBarBreak ? u"true"_s : u"false"_s); attributes << attr; ui_widget->setElementAttribute(attributes); } diff --git a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp index ca852e5ce..57152f3d2 100644 --- a/src/designer/src/components/propertyeditor/designerpropertymanager.cpp +++ b/src/designer/src/components/propertyeditor/designerpropertymanager.cpp @@ -1582,7 +1582,7 @@ QString DesignerPropertyManager::valueText(const QtProperty *property) const QVariant v = value(property); const QStringList list = v.metaType().id() == QMetaType::QStringList ? v.toStringList() : qvariant_cast<PropertySheetStringListValue>(v).value(); - return list.join(QLatin1String("; ")); + return list.join("; "_L1); } if (vType == designerKeySequenceTypeId()) { return qvariant_cast<PropertySheetKeySequenceValue>(value(property)).value().toString(QKeySequence::NativeText); diff --git a/src/designer/src/components/propertyeditor/paletteeditor.cpp b/src/designer/src/components/propertyeditor/paletteeditor.cpp index 3ff9c882c..b073bc0ba 100644 --- a/src/designer/src/components/propertyeditor/paletteeditor.cpp +++ b/src/designer/src/components/propertyeditor/paletteeditor.cpp @@ -313,7 +313,7 @@ static bool loadPalette(const QString &fileName, QPalette *pal, QString *errorMe *errorMessage = msgCannotReadPalette(fileName, reader); return false; } - if (reader.name() != QLatin1String("palette")) { + if (reader.name() != "palette"_L1) { const auto why = PaletteEditor::tr("Invalid element \"%1\", expected \"palette\".") .arg(reader.name().toString()); *errorMessage = msgCannotReadPalette(fileName, reader, why); diff --git a/src/designer/src/components/propertyeditor/propertyeditor.cpp b/src/designer/src/components/propertyeditor/propertyeditor.cpp index 751d92342..c7bfd2861 100644 --- a/src/designer/src/components/propertyeditor/propertyeditor.cpp +++ b/src/designer/src/components/propertyeditor/propertyeditor.cpp @@ -1006,8 +1006,8 @@ void PropertyEditor::setObject(QObject *object) descriptionToolTip = customData.propertyToolTip(propertyName); if (descriptionToolTip.isEmpty()) { if (const char *typeS = typeName(type)) { - descriptionToolTip = propertyName + QLatin1String(" (") - + QLatin1String(typeS) + QLatin1Char(')'); + descriptionToolTip = propertyName + " ("_L1 + + QLatin1StringView(typeS) + ')'_L1; } } if (!descriptionToolTip.isEmpty()) diff --git a/src/designer/src/designer/doc/snippets/plugins/doc_src_qtdesigner.cpp b/src/designer/src/designer/doc/snippets/plugins/doc_src_qtdesigner.cpp index 9cb08e027..6ac5db04f 100644 --- a/src/designer/src/designer/doc/snippets/plugins/doc_src_qtdesigner.cpp +++ b/src/designer/src/designer/doc/snippets/plugins/doc_src_qtdesigner.cpp @@ -228,7 +228,7 @@ QDesignerPropertySheetExtension *propertySheet = nullptr; QExtensionManager manager = formEditor->extensionManager(); propertySheet = qt_extension<QDesignerPropertySheetExtension*>(manager, widget); -int index = propertySheet->indexOf(QLatin1String("margin")); +int index = propertySheet->indexOf(u"margin"_s); propertySheet->setProperty(index, 10); propertySheet->setChanged(index, true); diff --git a/src/designer/src/designer/qdesigner.cpp b/src/designer/src/designer/qdesigner.cpp index 099e7509c..cc20413c5 100644 --- a/src/designer/src/designer/qdesigner.cpp +++ b/src/designer/src/designer/qdesigner.cpp @@ -147,9 +147,7 @@ static inline QDesigner::ParseArgumentsResult parseDesignerCommandLineArguments(QCommandLineParser &parser, Options *options, QString *errorMessage) { - parser.setApplicationDescription(u"Qt Designer "_s - + QLatin1String(QT_VERSION_STR) - + QLatin1String("\n\nUI designer for QWidget-based applications.")); + parser.setApplicationDescription(u"Qt Designer " QT_VERSION_STR "\n\nUI designer for QWidget-based applications."_s); const QCommandLineOption helpOption = parser.addHelpOption(); parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); const QCommandLineOption serverOption(u"server"_s, diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp index ac85c91a6..ba3791f3d 100644 --- a/src/designer/src/designer/qdesigner_actions.cpp +++ b/src/designer/src/designer/qdesigner_actions.cpp @@ -799,7 +799,7 @@ bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QStr if (check) { const QStringList problems = fw->checkContents(); if (!problems.isEmpty()) - QMessageBox::information(fw->window(), tr("Qt Designer"), problems.join(QLatin1String("<br>"))); + QMessageBox::information(fw->window(), tr("Qt Designer"), problems.join("<br>"_L1)); } QString contents = fw->contents(); diff --git a/src/designer/src/lib/shared/actioneditor_p.h b/src/designer/src/lib/shared/actioneditor_p.h index 38dcebfe3..471d12d04 100644 --- a/src/designer/src/lib/shared/actioneditor_p.h +++ b/src/designer/src/lib/shared/actioneditor_p.h @@ -63,7 +63,7 @@ public: static void setObjectNamingMode(ObjectNamingMode n) { m_objectNamingMode = n; } static QString actionTextToName(const QString &text, - const QString &prefix = QLatin1String("action")); + const QString &prefix = QLatin1StringView("action")); // Utility to create a configure button with menu for usage on toolbars static QToolButton *createConfigureMenuButton(const QString &t, QMenu **ptrToMenu); diff --git a/src/designer/src/lib/shared/codedialog.cpp b/src/designer/src/lib/shared/codedialog.cpp index ae91ea6dc..639cd7da8 100644 --- a/src/designer/src/lib/shared/codedialog.cpp +++ b/src/designer/src/lib/shared/codedialog.cpp @@ -180,15 +180,15 @@ bool CodeDialog::showCodeDialog(const QDesignerFormWindowInterface *fw, dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setCode(code); dialog->setFormFileName(fw->fileName()); - QString languageName; + QLatin1StringView languageName; switch (language) { case UicLanguage::Cpp: - languageName = QLatin1String("C++"); - dialog->setMimeType(QLatin1String("text/x-chdr")); + languageName = "C++"_L1; + dialog->setMimeType(u"text/x-chdr"_s); break; case UicLanguage::Python: - languageName = QLatin1String("Python"); - dialog->setMimeType(QLatin1String("text/x-python")); + languageName = "Python"_L1; + dialog->setMimeType(u"text/x-python"_s); break; } dialog->setWindowTitle(tr("%1 - [%2 Code]"). @@ -212,8 +212,8 @@ void CodeDialog::slotSaveAs() if (!uiFile.isEmpty()) { QFileInfo uiFi(uiFile); fileDialog.setDirectory(uiFi.absolutePath()); - fileDialog.selectFile(QLatin1String("ui_") + uiFi.baseName() - + QLatin1Char('.') + suffix); + fileDialog.selectFile("ui_"_L1 + uiFi.baseName() + + '.'_L1 + suffix); } while (true) { diff --git a/src/designer/src/lib/shared/htmlhighlighter.cpp b/src/designer/src/lib/shared/htmlhighlighter.cpp index 6f7bbfc24..dead3a100 100644 --- a/src/designer/src/lib/shared/htmlhighlighter.cpp +++ b/src/designer/src/lib/shared/htmlhighlighter.cpp @@ -8,6 +8,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { HtmlHighlighter::HtmlHighlighter(QTextEdit *textEdit) @@ -55,9 +57,6 @@ void HtmlHighlighter::highlightBlock(const QString &text) static const QLatin1Char apos = QLatin1Char('\''); static const QLatin1Char semicolon = QLatin1Char(';'); static const QLatin1Char equals = QLatin1Char('='); - static const QLatin1String startComment("<!--"); - static const QLatin1String endComment("-->"); - static const QLatin1String endElement("/>"); int state = previousBlockState(); qsizetype len = text.size(); @@ -71,7 +70,7 @@ void HtmlHighlighter::highlightBlock(const QString &text) while (pos < len) { QChar ch = text.at(pos); if (ch == startTag) { - if (text.mid(pos, 4) == startComment) { + if (QStringView{text}.sliced(pos).startsWith("<!--"_L1)) { state = InComment; } else { state = InTag; @@ -79,9 +78,10 @@ void HtmlHighlighter::highlightBlock(const QString &text) while (pos < len && text.at(pos) != space && text.at(pos) != endTag && text.at(pos) != tab - && text.mid(pos, 2) != endElement) + && !QStringView{text}.sliced(pos).startsWith("/>"_L1)) { ++pos; - if (text.mid(pos, 2) == endElement) + } + if (QStringView{text}.sliced(pos).startsWith("/>"_L1)) ++pos; setFormat(start, pos - start, m_formats[Tag]); @@ -104,7 +104,7 @@ void HtmlHighlighter::highlightBlock(const QString &text) case InComment: start = pos; for ( ; pos < len; ++pos) { - if (text.mid(pos, 3) == endComment) { + if (QStringView{text}.sliced(pos).startsWith("-->"_L1)) { pos += 3; state = NormalState; break; @@ -125,7 +125,7 @@ void HtmlHighlighter::highlightBlock(const QString &text) setFormat(start, pos - start, m_formats[Tag]); state = NormalState; break; - } else if (text.mid(pos, 2) == endElement) { + } else if (QStringView{text}.sliced(pos).startsWith("/>"_L1)) { pos += 2; setFormat(start, pos - start, m_formats[Tag]); state = NormalState; diff --git a/src/designer/src/lib/shared/layout.cpp b/src/designer/src/lib/shared/layout.cpp index 7ec7775e2..9c4be81a3 100644 --- a/src/designer/src/lib/shared/layout.cpp +++ b/src/designer/src/lib/shared/layout.cpp @@ -197,7 +197,7 @@ bool Layout::prepareLayout(bool &needMove, bool &needReparent) if (m_layoutBase == nullptr) { const bool useSplitter = m_layoutType == LayoutInfo::HSplitter || m_layoutType == LayoutInfo::VSplitter; - const QString baseWidgetClassName = useSplitter ? QLatin1String("QSplitter") : QLatin1String("QLayoutWidget"); + const QString baseWidgetClassName = useSplitter ? u"QSplitter"_s : u"QLayoutWidget"_s; m_layoutBase = widgetFactory->createWidget(baseWidgetClassName, widgetFactory->containerOfWidget(m_parentWidget)); if (useSplitter) { m_layoutBase->setObjectName(u"splitter"_s); diff --git a/src/designer/src/lib/shared/plugindialog.cpp b/src/designer/src/lib/shared/plugindialog.cpp index 9b954802f..c3f2093d1 100644 --- a/src/designer/src/lib/shared/plugindialog.cpp +++ b/src/designer/src/lib/shared/plugindialog.cpp @@ -108,9 +108,9 @@ void PluginDialog::populateTreeWidget() const QFont boldFont = topLevelItem->font(0); for (const QString &plugin : notLoadedPlugins) { const QString failureReason = pluginManager->failureReason(plugin); - const QString htmlFailureReason = QLatin1String("<html><head/><body><p>") + const QString htmlFailureReason = "<html><head/><body><p>"_L1 + failureReason.toHtmlEscaped() - + QLatin1String("</p></body></html>"); + + "</p></body></html>"_L1; QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, QFileInfo(plugin), boldFont); auto errorItem = setItem(pluginItem, failureReason, htmlFailureReason, QString(), QIcon()); diff --git a/src/designer/src/lib/shared/qdesigner_dockwidget.cpp b/src/designer/src/lib/shared/qdesigner_dockwidget.cpp index f2ced0dee..9b857efff 100644 --- a/src/designer/src/lib/shared/qdesigner_dockwidget.cpp +++ b/src/designer/src/lib/shared/qdesigner_dockwidget.cpp @@ -17,12 +17,14 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + bool QDockWidgetPropertySheet::isEnabled(int index) const { const QString &name = propertyName(index); - if (name == QLatin1String("dockWidgetArea")) + if (name == "dockWidgetArea"_L1) return static_cast<const QDesignerDockWidget *>(object())->docked(); - if (name == QLatin1String("docked")) + if (name == "docked"_L1) return static_cast<const QDesignerDockWidget *>(object())->inMainWindow(); return QDesignerPropertySheet::isEnabled(index); } diff --git a/src/designer/src/lib/shared/qdesigner_utils.cpp b/src/designer/src/lib/shared/qdesigner_utils.cpp index f2e2372ff..ec278645c 100644 --- a/src/designer/src/lib/shared/qdesigner_utils.cpp +++ b/src/designer/src/lib/shared/qdesigner_utils.cpp @@ -719,7 +719,7 @@ namespace qdesigner_internal case UicLanguage::Cpp: break; case UicLanguage::Python: - arguments << QLatin1String("-g") << QLatin1String("python"); + arguments << u"-g"_s << u"python"_s; break; } arguments << fileName; diff --git a/src/designer/src/lib/shared/widgetdatabase.cpp b/src/designer/src/lib/shared/widgetdatabase.cpp index c09b634ed..6f1453376 100644 --- a/src/designer/src/lib/shared/widgetdatabase.cpp +++ b/src/designer/src/lib/shared/widgetdatabase.cpp @@ -626,11 +626,11 @@ static QString generateNewFormXML(const QString &className, const QString &simil << NewFormWidth << "</width><height>" << NewFormHeight << "</height></rect></property>" << R"(<property name="windowTitle"><string>)" << name << "</string></property>\n"; - if (similarClassName == QLatin1String("QMainWindow")) { + if (similarClassName == "QMainWindow"_L1) { str << R"(<widget class="QWidget" name="centralwidget"/>)"; - } else if (similarClassName == QLatin1String("QWizard")) { + } else if (similarClassName == "QWizard"_L1) { str << R"(<widget class="QWizardPage" name="wizardPage1"/><widget class="QWizardPage" name="wizardPage2"/>)"; - } else if (similarClassName == QLatin1String("QDockWidget")) { + } else if (similarClassName == "QDockWidget"_L1) { str << R"(<widget class="QWidget" name="dockWidgetContents"/>)"; } str << "</widget></ui>\n"; diff --git a/src/designer/src/lib/uilib/abstractformbuilder.cpp b/src/designer/src/lib/uilib/abstractformbuilder.cpp index 021ea4cbe..560d8d6ce 100644 --- a/src/designer/src/lib/uilib/abstractformbuilder.cpp +++ b/src/designer/src/lib/uilib/abstractformbuilder.cpp @@ -874,8 +874,8 @@ void QAbstractFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> const QVariant v = toVariant(o->metaObject(), p); if (!v.isNull()) { QString attributeName = p->attributeName(); - if (attributeName == QLatin1String("numDigits") && o->inherits("QLCDNumber")) // Deprecated in Qt 4, removed in Qt 5. - attributeName = QLatin1String("digitCount"); + if (attributeName == "numDigits"_L1 && o->inherits("QLCDNumber")) // Deprecated in Qt 4, removed in Qt 5. + attributeName = u"digitCount"_s; if (!d->applyPropertyInternally(o, attributeName, v)) o->setProperty(attributeName.toUtf8(), v); } @@ -1889,6 +1889,18 @@ static const QLatin1StringView tableHeaderPrefixes[] = { "verticalHeader"_L1, }; +static constexpr QLatin1StringView itemViewHeaderRealPropertyNames[] = +{ + // Special handling for qtableview/qtreeview fake header attributes + "visible"_L1, + "cascadingSectionResizes"_L1, + "minimumSectionSize"_L1, // before defaultSectionSize + "defaultSectionSize"_L1, + "highlightSections"_L1, + "showSortIndicator"_L1, + "stretchLastSection"_L1 +}; + /*! \internal \since 4.5 @@ -1896,24 +1908,11 @@ static const QLatin1StringView tableHeaderPrefixes[] = { void QAbstractFormBuilder::saveItemViewExtraInfo(const QAbstractItemView *itemView, DomWidget *ui_widget, DomWidget *) { - // - // Special handling for qtableview/qtreeview fake header attributes - // - static const QLatin1String realPropertyNames[] = { - QLatin1String("visible"), - QLatin1String("cascadingSectionResizes"), - QLatin1String("minimumSectionSize"), // before defaultSectionSize - QLatin1String("defaultSectionSize"), - QLatin1String("highlightSections"), - QLatin1String("showSortIndicator"), - QLatin1String("stretchLastSection"), - }; - if (const QTreeView *treeView = qobject_cast<const QTreeView*>(itemView)) { auto viewProperties = ui_widget->elementAttribute(); const auto &headerProperties = computeProperties(treeView->header()); - for (QString realPropertyName : realPropertyNames) { - const QString upperPropertyName = realPropertyName.at(0).toUpper() + for (const QLatin1StringView realPropertyName : itemViewHeaderRealPropertyNames) { + const QString upperPropertyName = QChar(realPropertyName.at(0)).toUpper() + realPropertyName.mid(1); const QString fakePropertyName = "header"_L1 + upperPropertyName; for (DomProperty *property : headerProperties) { @@ -1930,8 +1929,8 @@ void QAbstractFormBuilder::saveItemViewExtraInfo(const QAbstractItemView *itemVi const auto &headerProperties = headerPrefix == "horizontalHeader"_L1 ? computeProperties(tableView->horizontalHeader()) : computeProperties(tableView->verticalHeader()); - for (QString realPropertyName : realPropertyNames) { - const QString upperPropertyName = realPropertyName.at(0).toUpper() + for (const QLatin1StringView realPropertyName : itemViewHeaderRealPropertyNames) { + const QString upperPropertyName = QChar(realPropertyName.at(0)).toUpper() + realPropertyName.mid(1); const QString fakePropertyName = headerPrefix + upperPropertyName; for (DomProperty *property : std::as_const(headerProperties)) { @@ -2270,24 +2269,11 @@ void QAbstractFormBuilder::loadButtonExtraInfo(const DomWidget *ui_widget, QAbst void QAbstractFormBuilder::loadItemViewExtraInfo(DomWidget *ui_widget, QAbstractItemView *itemView, QWidget *) { - // - // Special handling for qtableview/qtreeview fake header attributes - // - static const QLatin1String realPropertyNames[] = { - QLatin1String("visible"), - QLatin1String("cascadingSectionResizes"), - QLatin1String("minimumSectionSize"), // before defaultSectionSize - QLatin1String("defaultSectionSize"), - QLatin1String("highlightSections"), - QLatin1String("showSortIndicator"), - QLatin1String("stretchLastSection"), - }; - if (QTreeView *treeView = qobject_cast<QTreeView*>(itemView)) { const auto &allAttributes = ui_widget->elementAttribute(); QList<DomProperty *> headerProperties; - for (QString realPropertyName : realPropertyNames) { - const QString upperPropertyName = realPropertyName.at(0).toUpper() + for (QLatin1StringView realPropertyName : itemViewHeaderRealPropertyNames) { + const QString upperPropertyName = QChar(realPropertyName.at(0)).toUpper() + realPropertyName.mid(1); const QString fakePropertyName = "header"_L1 + upperPropertyName; for (DomProperty *attr : allAttributes) { @@ -2302,8 +2288,8 @@ void QAbstractFormBuilder::loadItemViewExtraInfo(DomWidget *ui_widget, QAbstract const auto &allAttributes = ui_widget->elementAttribute(); for (QLatin1StringView headerPrefix : tableHeaderPrefixes) { QList<DomProperty*> headerProperties; - for (QString realPropertyName : realPropertyNames) { - const QString upperPropertyName = realPropertyName.at(0).toUpper() + for (QLatin1StringView realPropertyName : itemViewHeaderRealPropertyNames) { + const QString upperPropertyName = QChar(realPropertyName.at(0)).toUpper() + realPropertyName.mid(1); const QString fakePropertyName = headerPrefix + upperPropertyName; for (DomProperty *attr : allAttributes) { diff --git a/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp b/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp index 53cbd69c4..9c75af8b0 100644 --- a/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp +++ b/src/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp @@ -50,7 +50,7 @@ bool QAxWidgetPropertySheet::isEnabled(int index) const bool QAxWidgetPropertySheet::isVisible(int index) const { // classContext is ulong, which the property editor does not support - return propertyName(index) != QLatin1String("classContext"); + return propertyName(index) != "classContext"_L1; } bool QAxWidgetPropertySheet::dynamicPropertiesAllowed() const |