Skip to content

Commit

Permalink
uic: Prepare for encountering fully qualified enum values in new .ui …
Browse files Browse the repository at this point in the history
…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.

Pick-to: 6.6 6.5
Task-number: PYSIDE-2492
Task-number: PYSIDE-1735
Task-number: QTBUG-118473
Change-Id: Iccbb884777aa9c696fbf48f9d7329353ef945b0f
Reviewed-by: Jarek Kobus <[email protected]>
  • Loading branch information
FriedemannKleint committed Nov 15, 2023
1 parent e6febd0 commit 2e82796
Show file tree
Hide file tree
Showing 99 changed files with 306 additions and 292 deletions.
62 changes: 38 additions & 24 deletions src/tools/uic/cpp/cppwriteinitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) << ')';
}


Expand Down Expand Up @@ -1285,7 +1293,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("
Expand Down Expand Up @@ -1594,12 +1602,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;

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/tools/uic/baseline/addlinkdialog.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Ui_AddLinkDialog

verticalLayout->addLayout(formLayout);

verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);

verticalLayout->addItem(verticalSpacer);

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/tools/uic/baseline/addtorrentform.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Ui_AddTorrentFile
#endif
hboxLayout->setContentsMargins(0, 0, 0, 0);
hboxLayout->setObjectName("hboxLayout");
spacerItem = new QSpacerItem(131, 31, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem = new QSpacerItem(131, 31, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

hboxLayout->addItem(spacerItem);

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/tools/uic/baseline/authenticationdialog.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Ui_Dialog

gridLayout->addWidget(siteDescription, 1, 1, 1, 1);

spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
spacerItem = new QSpacerItem(20, 40, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);

gridLayout->addItem(spacerItem, 4, 0, 1, 1);

Expand Down
8 changes: 4 additions & 4 deletions tests/auto/tools/uic/baseline/batchtranslation.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Ui_databaseTranslationDialog
vboxLayout->setObjectName("vboxLayout");
groupBox = new QGroupBox(databaseTranslationDialog);
groupBox->setObjectName("groupBox");
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
QSizePolicy sizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Maximum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(groupBox->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -97,7 +97,7 @@ class Ui_databaseTranslationDialog

groupBox_2 = new QGroupBox(databaseTranslationDialog);
groupBox_2->setObjectName("groupBox_2");
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Minimum);
QSizePolicy sizePolicy1(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Minimum);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(groupBox_2->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -140,7 +140,7 @@ class Ui_databaseTranslationDialog

vboxLayout3->addWidget(moveDownButton);

spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
spacerItem = new QSpacerItem(20, 40, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);

vboxLayout3->addItem(spacerItem);

Expand All @@ -165,7 +165,7 @@ class Ui_databaseTranslationDialog
#endif
hboxLayout1->setContentsMargins(0, 0, 0, 0);
hboxLayout1->setObjectName("hboxLayout1");
spacerItem1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem1 = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

hboxLayout1->addItem(spacerItem1);

Expand Down
4 changes: 2 additions & 2 deletions tests/auto/tools/uic/baseline/bookmarkdialog.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Ui_BookmarkDialog
if (BookmarkDialog->objectName().isEmpty())
BookmarkDialog->setObjectName("BookmarkDialog");
BookmarkDialog->resize(450, 135);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QSizePolicy sizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(BookmarkDialog->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -114,7 +114,7 @@ class Ui_BookmarkDialog
bookmarkWidget = new BookmarkWidget(BookmarkDialog);
bookmarkWidget->setObjectName("bookmarkWidget");
bookmarkWidget->setEnabled(true);
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Ignored);
QSizePolicy sizePolicy1(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Ignored);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(bookmarkWidget->sizePolicy().hasHeightForWidth());
Expand Down
12 changes: 6 additions & 6 deletions tests/auto/tools/uic/baseline/browserwidget.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ class Ui_Browser
vboxLayout->setObjectName("vboxLayout");
splitter_2 = new QSplitter(Browser);
splitter_2->setObjectName("splitter_2");
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(splitter_2->sizePolicy().hasHeightForWidth());
splitter_2->setSizePolicy(sizePolicy);
splitter_2->setOrientation(Qt::Horizontal);
connectionWidget = new ConnectionWidget(splitter_2);
connectionWidget->setObjectName("connectionWidget");
QSizePolicy sizePolicy1(QSizePolicy::Ignored, QSizePolicy::Expanding);
QSizePolicy sizePolicy1(QSizePolicy::Policy::Ignored, QSizePolicy::Policy::Expanding);
sizePolicy1.setHorizontalStretch(1);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(connectionWidget->sizePolicy().hasHeightForWidth());
connectionWidget->setSizePolicy(sizePolicy1);
splitter_2->addWidget(connectionWidget);
table = new QTableView(splitter_2);
table->setObjectName("table");
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding);
QSizePolicy sizePolicy2(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);
sizePolicy2.setHorizontalStretch(2);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(table->sizePolicy().hasHeightForWidth());
Expand All @@ -91,7 +91,7 @@ class Ui_Browser

groupBox = new QGroupBox(Browser);
groupBox->setObjectName("groupBox");
QSizePolicy sizePolicy3(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
QSizePolicy sizePolicy3(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::MinimumExpanding);
sizePolicy3.setHorizontalStretch(0);
sizePolicy3.setVerticalStretch(0);
sizePolicy3.setHeightForWidth(groupBox->sizePolicy().hasHeightForWidth());
Expand All @@ -107,7 +107,7 @@ class Ui_Browser
vboxLayout1->setObjectName("vboxLayout1");
sqlEdit = new QTextEdit(groupBox);
sqlEdit->setObjectName("sqlEdit");
QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
QSizePolicy sizePolicy4(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::MinimumExpanding);
sizePolicy4.setHorizontalStretch(0);
sizePolicy4.setVerticalStretch(0);
sizePolicy4.setHeightForWidth(sqlEdit->sizePolicy().hasHeightForWidth());
Expand All @@ -123,7 +123,7 @@ class Ui_Browser
#endif
hboxLayout->setContentsMargins(1, 1, 1, 1);
hboxLayout->setObjectName("hboxLayout");
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

hboxLayout->addItem(spacerItem);

Expand Down
12 changes: 6 additions & 6 deletions tests/auto/tools/uic/baseline/buttongroup.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Ui_Form
gridLayout->setObjectName("gridLayout");
easingCurvePicker = new QListWidget(Form);
easingCurvePicker->setObjectName("easingCurvePicker");
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(easingCurvePicker->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -101,7 +101,7 @@ class Ui_Form

groupBox = new QGroupBox(Form);
groupBox->setObjectName("groupBox");
QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Preferred);
QSizePolicy sizePolicy1(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Preferred);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(groupBox->sizePolicy().hasHeightForWidth());
Expand All @@ -111,7 +111,7 @@ class Ui_Form
formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
label = new QLabel(groupBox);
label->setObjectName("label");
QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Preferred);
QSizePolicy sizePolicy2(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
Expand All @@ -123,7 +123,7 @@ class Ui_Form
periodSpinBox = new QDoubleSpinBox(groupBox);
periodSpinBox->setObjectName("periodSpinBox");
periodSpinBox->setEnabled(false);
QSizePolicy sizePolicy3(QSizePolicy::Minimum, QSizePolicy::Fixed);
QSizePolicy sizePolicy3(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Fixed);
sizePolicy3.setHorizontalStretch(0);
sizePolicy3.setVerticalStretch(0);
sizePolicy3.setHeightForWidth(periodSpinBox->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -170,7 +170,7 @@ class Ui_Form

verticalLayout->addWidget(groupBox);

verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);

verticalLayout->addItem(verticalSpacer);

Expand All @@ -179,7 +179,7 @@ class Ui_Form

graphicsView = new QGraphicsView(Form);
graphicsView->setObjectName("graphicsView");
QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::Expanding);
QSizePolicy sizePolicy4(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Expanding);
sizePolicy4.setHorizontalStretch(0);
sizePolicy4.setVerticalStretch(0);
sizePolicy4.setHeightForWidth(graphicsView->sizePolicy().hasHeightForWidth());
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/tools/uic/baseline/calculator.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Ui_Calculator
if (Calculator->objectName().isEmpty())
Calculator->setObjectName("Calculator");
Calculator->resize(314, 301);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(Calculator->sizePolicy().hasHeightForWidth());
Expand Down
6 changes: 3 additions & 3 deletions tests/auto/tools/uic/baseline/calculatorform.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Ui_CalculatorForm
if (CalculatorForm->objectName().isEmpty())
CalculatorForm->setObjectName("CalculatorForm");
CalculatorForm->resize(276, 98);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QSizePolicy sizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(CalculatorForm->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -154,11 +154,11 @@ class Ui_CalculatorForm

gridLayout->addLayout(hboxLayout, 0, 0, 1, 1);

spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
spacerItem = new QSpacerItem(20, 40, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);

gridLayout->addItem(spacerItem, 1, 0, 1, 1);

spacerItem1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem1 = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

gridLayout->addItem(spacerItem1, 0, 1, 1, 1);

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/tools/uic/baseline/certificateinfo.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Ui_CertificateInfo

hboxLayout2 = new QHBoxLayout();
hboxLayout2->setObjectName("hboxLayout2");
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

hboxLayout2->addItem(spacerItem);

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/tools/uic/baseline/chatmainwindow.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Ui_ChatMainWindow

sendButton = new QPushButton(centralwidget);
sendButton->setObjectName("sendButton");
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
QSizePolicy sizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(sendButton->sizePolicy().hasHeightForWidth());
Expand Down
6 changes: 3 additions & 3 deletions tests/auto/tools/uic/baseline/chatsetnickname.ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Ui_NicknameDialog
if (NicknameDialog->objectName().isEmpty())
NicknameDialog->setObjectName("NicknameDialog");
NicknameDialog->resize(396, 105);
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
QSizePolicy sizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(NicknameDialog->sizePolicy().hasHeightForWidth());
Expand Down Expand Up @@ -81,7 +81,7 @@ class Ui_NicknameDialog
#endif
hboxLayout->setContentsMargins(0, 0, 0, 0);
hboxLayout->setObjectName("hboxLayout");
spacerItem = new QSpacerItem(131, 31, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem = new QSpacerItem(131, 31, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

hboxLayout->addItem(spacerItem);

Expand All @@ -95,7 +95,7 @@ class Ui_NicknameDialog

hboxLayout->addWidget(cancelButton);

spacerItem1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
spacerItem1 = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);

hboxLayout->addItem(spacerItem1);

Expand Down
Loading

0 comments on commit 2e82796

Please sign in to comment.