summaryrefslogtreecommitdiffstats
path: root/src/tools/uic
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2023-01-18 17:26:08 +0100
committerhjk <hjk@qt.io>2023-02-20 18:06:33 +0100
commit7b1ba955a6da3d4414fa206ec1c06c1fc6e16161 (patch)
tree1b9602f27e8ef3fa6effd858c1d145e36f4165b4 /src/tools/uic
parentb74db90be055904c43953695e51b216100de71bb (diff)
uic: Add a -no-qt-namespace option
To suppress the generation of the Ui class within QT_BEGIN_NAMESPACE and QT_END_NAMESPACE. Change-Id: I6552b41d8e9eccb0475618d7ed7f7cea7f826625 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/tools/uic')
-rw-r--r--src/tools/uic/cpp/cppwritedeclaration.cpp4
-rw-r--r--src/tools/uic/main.cpp6
-rw-r--r--src/tools/uic/option.h2
3 files changed, 10 insertions, 2 deletions
diff --git a/src/tools/uic/cpp/cppwritedeclaration.cpp b/src/tools/uic/cpp/cppwritedeclaration.cpp
index 910c4e2ee2..8261963cfa 100644
--- a/src/tools/uic/cpp/cppwritedeclaration.cpp
+++ b/src/tools/uic/cpp/cppwritedeclaration.cpp
@@ -65,8 +65,8 @@ void WriteDeclaration::acceptUI(DomUI *node)
// is a User using Qt-in-namespace having his own classes not in a namespace.
// In this case the generated Ui helper classes will also end up in
// the Qt namespace (which is harmless, but not "pretty")
- const bool needsMacro = namespaceList.size() == 0
- || namespaceList[0] == "qdesigner_internal"_L1;
+ const bool needsMacro = m_option.qtNamespace &&
+ (namespaceList.size() == 0 || namespaceList[0] == "qdesigner_internal"_L1);
if (needsMacro)
m_output << "QT_BEGIN_NAMESPACE\n\n";
diff --git a/src/tools/uic/main.cpp b/src/tools/uic/main.cpp
index 8728212f35..d46b788419 100644
--- a/src/tools/uic/main.cpp
+++ b/src/tools/uic/main.cpp
@@ -93,6 +93,11 @@ int runUic(int argc, char *argv[])
postfixOption.setValueName(u"postfix"_s);
parser.addOption(postfixOption);
+ QCommandLineOption noQtNamespaceOption(u"no-qt-namespace"_s);
+ noQtNamespaceOption.setDescription(
+ u"Disable wrapping the definition of the generated class in QT_{BEGIN,END}_NAMESPACE."_s);
+ parser.addOption(noQtNamespaceOption);
+
QCommandLineOption translateOption(QStringList{u"tr"_s, u"translate"_s});
translateOption.setDescription(u"Use <function> for i18n."_s);
translateOption.setValueName(u"function"_s);
@@ -149,6 +154,7 @@ int runUic(int argc, char *argv[])
driver.option().autoConnection = !parser.isSet(noAutoConnectionOption);
driver.option().headerProtection = !parser.isSet(noProtOption);
driver.option().implicitIncludes = !parser.isSet(noImplicitIncludesOption);
+ driver.option().qtNamespace = !parser.isSet(noQtNamespaceOption);
driver.option().idBased = parser.isSet(idBasedOption);
driver.option().postfix = parser.value(postfixOption);
driver.option().translateFunction = parser.value(translateOption);
diff --git a/src/tools/uic/option.h b/src/tools/uic/option.h
index 78b3ff1490..cfdd90fda3 100644
--- a/src/tools/uic/option.h
+++ b/src/tools/uic/option.h
@@ -30,6 +30,7 @@ struct Option
unsigned int forceStringConnectionSyntax: 1;
unsigned int useStarImports: 1;
unsigned int rcPrefix: 1; // Python: Generate "rc_file" instead of "file_rc" import
+ unsigned int qtNamespace: 1;
QString inputFile;
QString outputFile;
@@ -57,6 +58,7 @@ struct Option
forceStringConnectionSyntax(0),
useStarImports(0),
rcPrefix(0),
+ qtNamespace(1),
prefix(QLatin1StringView("Ui_"))
{ indent.fill(u' ', 4); }