summaryrefslogtreecommitdiffstats
path: root/src/designer/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/designer/data')
-rw-r--r--src/designer/data/README2
-rw-r--r--src/designer/data/generate_header.xsl2
-rw-r--r--src/designer/data/generate_impl.xsl50
-rw-r--r--src/designer/data/generate_shared.xsl8
-rwxr-xr-xsrc/designer/data/generate_ui126
-rw-r--r--src/designer/data/generate_ui.py96
-rw-r--r--src/designer/data/ui4.xsd4
7 files changed, 123 insertions, 165 deletions
diff --git a/src/designer/data/README b/src/designer/data/README
index b7160b8f6..5b05ffa26 100644
--- a/src/designer/data/README
+++ b/src/designer/data/README
@@ -1,4 +1,4 @@
-You may generate ui4.h and ui4.cpp parser files by using the generate_ui script
+You may generate ui4.h and ui4.cpp parser files by using the generate_ui.py script
or manually by invoking the xsltproc command:
xsltproc generate_header.xsl ui4.xsd > ui4.h
diff --git a/src/designer/data/generate_header.xsl b/src/designer/data/generate_header.xsl
index af39044be..c2b12dfa8 100644
--- a/src/designer/data/generate_header.xsl
+++ b/src/designer/data/generate_header.xsl
@@ -407,7 +407,7 @@
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
-// of Qt Designer. This header
+// of Qt Widgets Designer. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
diff --git a/src/designer/data/generate_impl.xsl b/src/designer/data/generate_impl.xsl
index 2002c71a1..7ce02f41b 100644
--- a/src/designer/data/generate_impl.xsl
+++ b/src/designer/data/generate_impl.xsl
@@ -161,29 +161,12 @@
</xsl:template>
- <!-- Format a string constant for comparison as QLatin1String("foo") - they're all ascii-only -->
- <xsl:template name="string-constant-for-comparison">
- <xsl:param name="literal"/>
- <xsl:text>QLatin1String("</xsl:text>
- <xsl:value-of select="$literal"/>
- <xsl:text>")</xsl:text>
- </xsl:template>
-
- <!-- Format a string constant for storage as QString(QLatin1Char('X')) or QLatin1String("foo"), respectively -->
- <xsl:template name="string-constant-for-storage">
+ <!-- Format a string constant -->
+ <xsl:template name="string-constant">
<xsl:param name="literal"/>
- <xsl:choose>
- <xsl:when test="string-length($literal) &lt; 2">
- <xsl:text>QString(QLatin1Char('</xsl:text>
- <xsl:value-of select="$literal"/>
- <xsl:text>'))</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>QStringLiteral("</xsl:text>
- <xsl:value-of select="$literal"/>
- <xsl:text>")</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:text>u"</xsl:text>
+ <xsl:value-of select="$literal"/>
+ <xsl:text>"_s</xsl:text>
</xsl:template>
<!-- Implementation: read(QXmlStreamReader) -->
@@ -217,7 +200,7 @@
</xsl:variable>
<xsl:text> if (name == </xsl:text>
- <xsl:call-template name="string-constant-for-comparison">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="@name"/>
</xsl:call-template>
<xsl:text>) {&endl;</xsl:text>
@@ -230,7 +213,7 @@
<xsl:text> }&endl;</xsl:text>
</xsl:for-each>
- <xsl:text> reader.raiseError(QLatin1String("Unexpected attribute ") + name);&endl;</xsl:text>
+ <xsl:text> reader.raiseError("Unexpected attribute "_L1 + name);&endl;</xsl:text>
<xsl:text> }&endl;</xsl:text>
<xsl:text>&endl;</xsl:text>
</xsl:if>
@@ -264,7 +247,7 @@
<xsl:variable name="array" select="@maxOccurs = 'unbounded'"/>
<xsl:text> if (!tag.compare(</xsl:text>
- <xsl:call-template name="string-constant-for-comparison">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
<xsl:text>, Qt::CaseInsensitive)) {&endl;</xsl:text>
@@ -355,7 +338,7 @@
</xsl:call-template>
</xsl:for-each>
- <xsl:text> reader.raiseError(QLatin1String("Unexpected element ") + tag);&endl;</xsl:text>
+ <xsl:text> reader.raiseError("Unexpected element "_L1 + tag);&endl;</xsl:text>
<xsl:text> }&endl;</xsl:text>
<xsl:text> break;&endl;</xsl:text>
<xsl:text> case QXmlStreamReader::EndElement :&endl;</xsl:text>
@@ -402,7 +385,7 @@
<xsl:value-of select="$cap-name"/>
<xsl:text>())&endl;</xsl:text>
<xsl:text> writer.writeAttribute(</xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
@@ -458,7 +441,7 @@
</xsl:variable>
<xsl:text> writer.writeTextElement(</xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$camel-case-name"/>
</xsl:call-template>
<xsl:text>, </xsl:text>
@@ -478,7 +461,7 @@
<xsl:text> m_</xsl:text>
<xsl:value-of select="$camel-case-name"/>
<xsl:text>->write(writer, </xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
<xsl:text>);&endl;</xsl:text>
@@ -533,7 +516,7 @@
<xsl:choose>
<xsl:when test="$xs-type-cat = 'pointer'">
<xsl:text> v->write(writer, </xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
<xsl:text>);&endl;</xsl:text>
@@ -547,7 +530,7 @@
</xsl:variable>
<xsl:text> writer.writeTextElement(</xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
<xsl:text>, </xsl:text>
@@ -566,7 +549,7 @@
<xsl:text> m_</xsl:text>
<xsl:value-of select="$camel-case-name"/>
<xsl:text>->write(writer, </xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
<xsl:text>);&endl;</xsl:text>
@@ -579,7 +562,7 @@
</xsl:call-template>
</xsl:variable>
<xsl:text> writer.writeTextElement(</xsl:text>
- <xsl:call-template name="string-constant-for-storage">
+ <xsl:call-template name="string-constant">
<xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template>
<xsl:text>, </xsl:text>
@@ -838,6 +821,7 @@
<xsl:text>&endl;</xsl:text>
<xsl:text>&endl;</xsl:text>
<xsl:text>QT_BEGIN_NAMESPACE&endl;</xsl:text>
+ <xsl:text>&endl;using namespace Qt::StringLiterals;&endl;&endl;</xsl:text>
<xsl:text>#ifdef QFORMINTERNAL_NAMESPACE&endl;</xsl:text>
<xsl:text>using namespace QFormInternal;&endl;</xsl:text>
diff --git a/src/designer/data/generate_shared.xsl b/src/designer/data/generate_shared.xsl
index 38269cd61..d1ca2b94b 100644
--- a/src/designer/data/generate_shared.xsl
+++ b/src/designer/data/generate_shared.xsl
@@ -48,6 +48,8 @@
<xsl:when test="$text='pointsize'">pointSize</xsl:when>
<xsl:when test="$text='strikeout'">strikeOut</xsl:when>
<xsl:when test="$text='stylestrategy'">styleStrategy</xsl:when>
+ <xsl:when test="$text='hintingpreference'">hintingPreference</xsl:when>
+ <xsl:when test="$text='fontweight'">fontWeight</xsl:when>
<xsl:when test="$text='hsizetype'">hSizeType</xsl:when>
<xsl:when test="$text='vsizetype'">vSizeType</xsl:when>
<xsl:when test="$text='horstretch'">horStretch</xsl:when>
@@ -142,7 +144,7 @@
</xsl:when>
<xsl:when test="$xs-type='xs:boolean'">
<xsl:value-of select="$val"/>
- <xsl:text> == QLatin1String("true")</xsl:text>
+ <xsl:text> == u"true"_s</xsl:text>
</xsl:when>
<xsl:when test="$xs-type='xs:long'">
<xsl:value-of select="$val"/>
@@ -217,9 +219,7 @@
<xsl:when test="$xs-type='xs:boolean'">
<xsl:text>(</xsl:text>
<xsl:value-of select="$val"/>
- <!-- Note: Do not use QStringLiteral here as the types are not compatible:
- QConstStringData<5> vs QConstStringData<4> -->
- <xsl:text> ? QLatin1String("true") : QLatin1String("false"))</xsl:text>
+ <xsl:text> ? u"true"_s : u"false"_s)</xsl:text>
</xsl:when>
<xsl:otherwise>### BZZZZT! ###</xsl:otherwise>
</xsl:choose>
diff --git a/src/designer/data/generate_ui b/src/designer/data/generate_ui
deleted file mode 100755
index 4c723a61c..000000000
--- a/src/designer/data/generate_ui
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/perl -w
-####################################################################################################
-#
-# Helper script for Qt 5
-#
-# Copyright (C) 2015 The Qt Company Ltd.
-# Contact: http://www.qt.io/licensing/
-#
-####################################################################################################
-
-############################################################################################
-#
-# Generates the source files ui4.cpp, ui4.h used in the uic tool, the QtUiTools library and
-# Qt Designer from the XML schema used for .ui files.
-#
-############################################################################################
-
-use strict;
-
-use File::Basename;
-use File::Spec;
-use File::Copy;
-use IO::File;
-use File::Path;
-use File::Temp;
-
-my $USAGE=<<EOF;
-Usage: generate_ui
-
-Generates the source files ui4.cpp, ui4.h used in the uic tool, the QtUiTools library and
-Qt Designer from the XML schema used for .ui files.
-
-Requires the environment variable QTDIR to point to qtbase and xalan.
-EOF
-
-my $qtDir = $ENV{'QTDIR'};
-die ('QTDIR not set') unless defined $qtDir && -d $qtDir;
-
-print 'Generating ui4.cpp/ui4.h ',$qtDir,"\n";
-
-my $uicDir = File::Spec->catfile($qtDir, 'src', 'tools', 'uic');
-my $toolsDir = File::Spec->catfile($qtDir, '..', 'qttools');
-my $designerDir = File::Spec->catfile($toolsDir, 'src', 'designer');
-my $uiLibDir = File::Spec->catfile($designerDir, 'src', 'lib', 'uilib');
-my $xmlDir = File::Spec->catfile($designerDir, 'data');
-my $qtXmlPatterns = File::Spec->catfile($qtDir, 'bin', 'xmlpatterns');
-
-print 'uic at: ',$uicDir, ' Designer at: ',$designerDir, ' uilib at: ',$uiLibDir,' XML at ',$xmlDir,"\n";
-die ('Invalid folder structure') unless -d $xmlDir && -d $uicDir && -d $uiLibDir;
-
-# Read out license delimited by '/** .. **/' from a C++ source
-sub readCppLicense
-{
- my ($fileName) = @_;
- my $license = '';
- my $file = new IO::File('<' . $fileName) or die ('Unable to open ' . $fileName . ' for reading: ' . $!);
- while (my $line = <$file>) {
- $license .= $line;
- last if index($line, '*****/') >= 0;
- }
- $file->close();
- return $license;
-}
-
-# Replace special keys in XSL files and return a handle to temporary file
-sub replaceXslKeys
-{
- my ($xslSourceFileName, $license, $uiHeaderName) = @_;
-
- my $xslSourceFile = new IO::File('<' . $xslSourceFileName) or die ('Unable to open ' . $xslSourceFileName . ' for reading: ' . $!);
- my $xsl = '';
- while (my $line = <$xslSourceFile>) {
- $xsl .= $line;
- }
- $xslSourceFile->close();
- $xsl =~ s/\@LICENSE\@/$license/g;
- $xsl =~ s/\@HEADER\@/$uiHeaderName/g if defined $uiHeaderName;
-
- my $xslHandle = File::Temp->new(DIR => dirname($xslSourceFileName), SUFFIX => '.xsl');
- print $xslHandle $xsl;
- $xslHandle->close();
- return $xslHandle;
-}
-
-# Run xalan. Note: xmlpatterns currently reports a syntax error on the sheets
-sub runXSLT
-{
- my ($source, $sheet, $target) = @_;
- my $rc = system('xalan', '-in', $source, '-xsl', $sheet, '-out', $target);
-# my $rc = system($qtXmlPatterns, '-output', $target, $sheet, $source);
- die ('Xalan failed on ' . $source . ' ' . $sheet) unless $rc == 0;
-}
-
-# Generate uilib header and source.
-
-my $uiLibImpl = File::Spec->catfile($uiLibDir, 'ui4.cpp');
-my $uiLibHeader = File::Spec->catfile($uiLibDir, 'ui4_p.h');
-my $license = readCppLicense($uiLibImpl);
-
-print "Running XSLT processor for uilib header...\n";
-
-my $ui4Xsd = File::Spec->catfile($xmlDir, 'ui4.xsd');
-my $headerXslSource = File::Spec->catfile($xmlDir, 'generate_header.xsl');
-my $headerXsl = replaceXslKeys($headerXslSource, $license);
-runXSLT($ui4Xsd, $headerXsl->filename, $uiLibHeader);
-
-print "Running XSLT processor for uilib source...\n";
-my $implXslSource = File::Spec->catfile($xmlDir, 'generate_impl.xsl');
-my $implXsl = replaceXslKeys($implXslSource, $license, 'ui4_p.h');
-runXSLT($ui4Xsd, $implXsl->filename, $uiLibImpl);
-
-# uic: Header is called 'ui4.h' instead of 'ui4_p.h'
-
-my $uicImpl = File::Spec->catfile($uicDir, 'ui4.cpp');
-my $uicHeader = File::Spec->catfile($uicDir, 'ui4.h');
-$license = readCppLicense($uicImpl);
-
-print "Running XSLT processor for uic header...\n";
-$headerXsl = replaceXslKeys($headerXslSource, $license);
-runXSLT($ui4Xsd, $headerXsl->filename, $uicHeader);
-
-print "Running XSLT processor for uic source...\n";
-$implXsl = replaceXslKeys($implXslSource, $license, 'ui4.h');
-runXSLT($ui4Xsd, $implXsl->filename, $uicImpl);
-
-system('git', 'diff');
diff --git a/src/designer/data/generate_ui.py b/src/designer/data/generate_ui.py
new file mode 100644
index 000000000..05472c7f5
--- /dev/null
+++ b/src/designer/data/generate_ui.py
@@ -0,0 +1,96 @@
+#!/usr/bin/python3
+
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import subprocess
+
+from argparse import ArgumentParser, RawTextHelpFormatter
+from pathlib import Path
+from tempfile import NamedTemporaryFile
+
+
+DESCRIPTION = """
+Usage: generate_ui.py
+
+Generates the source files ui4.cpp, ui4.h used in the uic tool, the QtUiTools library and
+Qt Widgets Designer from the XML schema used for .ui files.
+
+Requires xalan.
+"""
+
+
+opt_delete_temp_files = True
+
+
+def read_cpp_license(path):
+ """Read out the license from a C++ source"""
+ result = ""
+ for line in path.read_text().splitlines():
+ result += line + "\n"
+ if 'SPDX-License-Identifier' in line:
+ break
+ return result
+
+
+def replace_xsl_keys(xsl_source_file, license, ui_header_name=None):
+ """Replace special keys in XSL files and return a handle to temporary file"""
+ xsl = xsl_source_file.read_text()
+ xsl = xsl.replace("@LICENSE@", license)
+ if ui_header_name:
+ xsl = xsl.replace("@HEADER@", ui_header_name)
+
+ result = NamedTemporaryFile(mode='w', suffix='.xsl',
+ dir=Path.cwd(),
+ delete=opt_delete_temp_files)
+ result.write(xsl)
+ return result
+
+
+def run_xslt(source, sheet, target):
+ """Run xalan."""
+ cmd = ['xalan', '-in', os.fspath(source), '-xsl', os.fspath(sheet),
+ '-out', os.fspath(target)]
+ subprocess.check_call(cmd)
+
+
+if __name__ == '__main__':
+ argument_parser = ArgumentParser(description=DESCRIPTION,
+ formatter_class=RawTextHelpFormatter)
+ argument_parser.add_argument('--keep', '-k', action='store_true',
+ help='Keep temporary files')
+ options = argument_parser.parse_args()
+ opt_delete_temp_files = not options.keep
+
+ # Generate uilib header and source.
+ xml_dir = Path(__file__).parent.resolve()
+ ui4_xsd = xml_dir / 'ui4.xsd'
+
+ designer_dir = xml_dir.parent
+ uilib_dir = designer_dir / "src" / "lib" / "uilib"
+ uilib_impl = uilib_dir / 'ui4.cpp'
+ license = read_cpp_license(uilib_impl)
+
+ print("Running XSLT processor for uilib header...\n")
+ header_xsl_source = xml_dir / 'generate_header.xsl'
+ header_xsl = replace_xsl_keys(header_xsl_source, license)
+ run_xslt(ui4_xsd, header_xsl.name, uilib_dir / 'ui4_p.h')
+
+ print("Running XSLT processor for uilib source...\n")
+ impl_xsl_source = xml_dir / 'generate_impl.xsl'
+ impl_xsl = replace_xsl_keys(impl_xsl_source, license, 'ui4_p.h')
+ run_xslt(ui4_xsd, impl_xsl.name, uilib_impl)
+
+ # uic: Header is called 'ui4.h' instead of 'ui4_p.h'
+ uic_dir = designer_dir.parents[2] / "qtbase" / "src" / "tools" / "uic"
+ uic_impl = uic_dir / 'ui4.cpp'
+ license = read_cpp_license(uic_impl)
+ print("Running XSLT processor for uic header...\n")
+ header_xsl = replace_xsl_keys(header_xsl_source, license)
+ run_xslt(ui4_xsd, header_xsl.name, uic_dir / 'ui4.h')
+ print("Running XSLT processor for uic source...\n")
+ impl_xsl = replace_xsl_keys(impl_xsl_source, license, 'ui4.h')
+ run_xslt(ui4_xsd, impl_xsl.name, uic_impl)
+
+ subprocess.call(['git', 'diff'])
diff --git a/src/designer/data/ui4.xsd b/src/designer/data/ui4.xsd
index e1dc35d49..0063f473b 100644
--- a/src/designer/data/ui4.xsd
+++ b/src/designer/data/ui4.xsd
@@ -301,6 +301,7 @@
<xs:all>
<xs:element name="family" type="xs:string" minOccurs="0" />
<xs:element name="pointsize" type="xs:integer" minOccurs="0" />
+ <!-- Qt 4 legacy (int) -->
<xs:element name="weight" type="xs:integer" minOccurs="0" />
<xs:element name="italic" type="xs:boolean" minOccurs="0" />
<xs:element name="bold" type="xs:boolean" minOccurs="0" />
@@ -309,6 +310,9 @@
<xs:element name="antialiasing" type="xs:boolean" minOccurs="0" />
<xs:element name="stylestrategy" type="xs:string" minOccurs="0" />
<xs:element name="kerning" type="xs:boolean" minOccurs="0" />
+ <xs:element name="hintingpreference" type="xs:string" minOccurs="0"/>
+ <!-- Qt 5/6 (enum) -->
+ <xs:element name="fontweight" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>