diff options
Diffstat (limited to 'src/tools/uic/uic.cpp')
-rw-r--r-- | src/tools/uic/uic.cpp | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/src/tools/uic/uic.cpp b/src/tools/uic/uic.cpp index 5b2a602e5f..fb0a37d21d 100644 --- a/src/tools/uic/uic.cpp +++ b/src/tools/uic/uic.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "uic.h" #include "ui4.h" @@ -47,6 +22,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Uic::Uic(Driver *d) : drv(d), out(d->output()), @@ -61,9 +38,10 @@ bool Uic::printDependencies() QString fileName = opt.inputFile; QFile f; - if (fileName.isEmpty()) - f.open(stdin, QIODevice::ReadOnly); - else { + if (fileName.isEmpty()) { + if (!f.open(stdin, QIODevice::ReadOnly)) + return false; + } else { f.setFileName(fileName); if (!f.open(QIODevice::ReadOnly)) return false; @@ -127,7 +105,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 +120,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; } @@ -169,10 +147,10 @@ void Uic::writeCopyrightHeaderPython(const DomUI *ui) const static double versionFromUiAttribute(QXmlStreamReader &reader) { const QXmlStreamAttributes attributes = reader.attributes(); - const QString versionAttribute = QLatin1String("version"); + const auto versionAttribute = "version"_L1; if (!attributes.hasAttribute(versionAttribute)) return 4.0; - const QStringRef version = attributes.value(versionAttribute); + const QStringView version = attributes.value(versionAttribute); return version.toDouble(); } @@ -180,7 +158,7 @@ DomUI *Uic::parseUiFile(QXmlStreamReader &reader) { DomUI *ui = nullptr; - const QString uiElement = QLatin1String("ui"); + const auto uiElement = "ui"_L1; while (!reader.atEnd()) { if (reader.readNext() == QXmlStreamReader::StartElement) { if (reader.name().compare(uiElement, Qt::CaseInsensitive) == 0 @@ -195,7 +173,7 @@ DomUI *Uic::parseUiFile(QXmlStreamReader &reader) ui = new DomUI(); ui->read(reader); } else { - reader.raiseError(QLatin1String("Unexpected element ") + reader.name().toString()); + reader.raiseError("Unexpected element "_L1 + reader.name().toString()); } } } @@ -231,7 +209,7 @@ bool Uic::write(QIODevice *in) const QString &language = ui->attributeLanguage(); 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)); return false; } @@ -266,8 +244,7 @@ bool Uic::write(DomUI *ui) } pixFunction = ui->elementPixmapFunction(); - if (pixFunction == QLatin1String("QPixmap::fromMimeSource") - || pixFunction == QLatin1String("qPixmapFromMimeSource")) { + if (pixFunction == "QPixmap::fromMimeSource"_L1 || pixFunction == "qPixmapFromMimeSource"_L1) { fprintf(stderr, "%s: Warning: Obsolete pixmap function '%s' specified in the UI file.\n", qPrintable(opt.messagePrefix()), qPrintable(pixFunction)); pixFunction.clear(); @@ -315,9 +292,9 @@ void Uic::writeHeaderProtectionEnd() bool Uic::isButton(const QString &className) const { static const QStringList buttons = { - QLatin1String("QRadioButton"), QLatin1String("QToolButton"), - QLatin1String("QCheckBox"), QLatin1String("QPushButton"), - QLatin1String("QCommandLinkButton") + u"QRadioButton"_s, u"QToolButton"_s, + u"QCheckBox"_s, u"QPushButton"_s, + u"QCommandLinkButton"_s }; return customWidgetsInfo()->extendsOneOf(className, buttons); } @@ -325,10 +302,10 @@ bool Uic::isButton(const QString &className) const bool Uic::isContainer(const QString &className) const { static const QStringList containers = { - QLatin1String("QStackedWidget"), QLatin1String("QToolBox"), - QLatin1String("QTabWidget"), QLatin1String("QScrollArea"), - QLatin1String("QMdiArea"), QLatin1String("QWizard"), - QLatin1String("QDockWidget") + u"QStackedWidget"_s, u"QToolBox"_s, + u"QTabWidget"_s, u"QScrollArea"_s, + u"QMdiArea"_s, u"QWizard"_s, + u"QDockWidget"_s }; return customWidgetsInfo()->extendsOneOf(className, containers); @@ -337,7 +314,7 @@ bool Uic::isContainer(const QString &className) const bool Uic::isMenu(const QString &className) const { static const QStringList menus = { - QLatin1String("QMenu"), QLatin1String("QPopupMenu") + u"QMenu"_s, u"QPopupMenu"_s }; return customWidgetsInfo()->extendsOneOf(className, menus); } |