summaryrefslogtreecommitdiffstats
path: root/src/tools/uic/cpp/cppwriteinitialization.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2023-10-19 13:50:53 +0200
committerQt Cherry-pick Bot <[email protected]>2023-11-17 06:58:05 +0000
commitc3280b616f443ac9c295e5f9b634f2662cdaade5 (patch)
tree7f241dcd9c1afb49c5336232fd40c1bc9dd096e2 /src/tools/uic/cpp/cppwriteinitialization.cpp
parentf100430e8f26664246b8771c96295ac5c2c386c3 (diff)
uic: Prepare for encountering fully qualified enum values in new .ui files
This means checks have to be rewritten using endsWith(). It mainly affects the QSizePolicy handling whose values originate from different sources, including numbers. To address this, refactor the code to deal with unqualified enum value names and introduce a helper function that fully qualifies the enumeration when writing out. Task-number: PYSIDE-2492 Task-number: PYSIDE-1735 Task-number: QTBUG-118473 Change-Id: Iccbb884777aa9c696fbf48f9d7329353ef945b0f Reviewed-by: Jarek Kobus <[email protected]> (cherry picked from commit 2e82796022b9eaeeb3a231713603c39ae7b2099d) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 2ee11d3e019cb4deb3b2af0212f6edb9f6d77543)
Diffstat (limited to 'src/tools/uic/cpp/cppwriteinitialization.cpp')
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index 3301c6e230f..c0c20380b71 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -24,6 +24,24 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace {
+
+ // Expand "Horizontal", "Qt::Horizontal" to "Qt::Orientation::Horizontal"
+ QString expandEnum(QString value, const QString &prefix)
+ {
+ if (value.startsWith(prefix))
+ return value;
+ const auto pos = value.lastIndexOf("::"_L1);
+ if (pos == -1)
+ return prefix + "::"_L1 + value;
+ value.replace(0, pos, prefix);
+ return value;
+ }
+
+ inline QString expandSizePolicyEnum(const QString &value)
+ {
+ return expandEnum(value, "QSizePolicy::Policy"_L1);
+ }
+
// figure out the toolbar area of a DOM attrib list.
// By legacy, it is stored as an integer. As of 4.3.0, it is the enumeration value.
QString toolBarAreaStringFromDOMAttributes(const CPP::WriteInitialization::DomPropertyMap &attributes) {
@@ -62,27 +80,17 @@ namespace {
output << w << ", " << h << ", ";
// size type
- QString sizeType;
- if (const DomProperty *st = properties.value("sizeType"_L1)) {
- const QString value = st->elementEnum();
- if (value.startsWith("QSizePolicy::"_L1))
- sizeType = value;
- else
- sizeType = "QSizePolicy::"_L1 + value;
- } else {
- sizeType = QStringLiteral("QSizePolicy::Expanding");
- }
+ const DomProperty *st = properties.value("sizeType"_L1);
+ QString horizType = st != nullptr ? st->elementEnum() : "Expanding"_L1;
+ QString vertType = "Minimum"_L1;
// orientation
- bool isVspacer = false;
- if (const DomProperty *o = properties.value("orientation"_L1)) {
- const QString orientation = o->elementEnum();
- if (orientation == "Qt::Vertical"_L1 || orientation == "Vertical"_L1)
- isVspacer = true;
- }
- const QString horizType = isVspacer ? "QSizePolicy::Minimum"_L1 : sizeType;
- const QString vertType = isVspacer ? sizeType : "QSizePolicy::Minimum"_L1;
- output << language::enumValue(horizType) << ", " << language::enumValue(vertType) << ')';
+ const DomProperty *o = properties.value("orientation"_L1);
+ if (o != nullptr && o->elementEnum().endsWith("Vertical"_L1))
+ std::swap(horizType, vertType);
+
+ output << language::enumValue(expandSizePolicyEnum(horizType)) << ", "
+ << language::enumValue(expandSizePolicyEnum(vertType)) << ')';
}
@@ -1281,7 +1289,7 @@ void WriteInitialization::writeProperties(const QString &varName,
&& m_uic->customWidgetsInfo()->extends(className, "Line")) {
// Line support
QString shape = u"QFrame::HLine"_s;
- if (p->elementEnum() == "Qt::Vertical"_L1)
+ if (p->elementEnum().endsWith("::Vertical"_L1))
shape = u"QFrame::VLine"_s;
m_output << m_indent << varName << language::derefPointer << "setFrameShape("
@@ -1590,12 +1598,18 @@ QString WriteInitialization::writeSizePolicy(const DomSizePolicy *sp)
m_sizePolicyNameMap.insert(sizePolicyHandle, spName);
m_output << m_indent << language::stackVariableWithInitParameters("QSizePolicy", spName);
+ QString horizPolicy;
+ QString vertPolicy;
if (sp->hasElementHSizeType() && sp->hasElementVSizeType()) {
- m_output << "QSizePolicy" << language::qualifier << language::sizePolicy(sp->elementHSizeType())
- << ", QSizePolicy" << language::qualifier << language::sizePolicy(sp->elementVSizeType());
+ horizPolicy = language::sizePolicy(sp->elementHSizeType());
+ vertPolicy = language::sizePolicy(sp->elementVSizeType());
} else if (sp->hasAttributeHSizeType() && sp->hasAttributeVSizeType()) {
- m_output << "QSizePolicy" << language::qualifier << sp->attributeHSizeType()
- << ", QSizePolicy" << language::qualifier << sp->attributeVSizeType();
+ horizPolicy = sp->attributeHSizeType();
+ vertPolicy = sp->attributeVSizeType();
+ }
+ if (!horizPolicy.isEmpty() && !vertPolicy.isEmpty()) {
+ m_output << language::enumValue(expandSizePolicyEnum(horizPolicy))
+ << ", " << language::enumValue(expandSizePolicyEnum(vertPolicy));
}
m_output << ')' << language::eol;