uic: No longer generate static_cast for enum values in legacy forms

Add a lookup for the affected enum values and use the names instead.

Task-number: PYSIDE-797
Change-Id: I6be166409000aff83d9465c9a3b2f37b44c5c085
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Friedemann Kleint 2018-12-04 15:48:53 +01:00
parent 4e2e7078b8
commit ac7265e950
16 changed files with 136 additions and 49 deletions

View File

@ -45,35 +45,26 @@
QT_BEGIN_NAMESPACE
namespace {
// Fixup an enumeration name from class Qt.
// They are currently stored as "BottomToolBarArea" instead of "Qt::BottomToolBarArea".
// due to MO issues. This might be fixed in the future.
QLatin1String qtEnumerationPrefix(const QString &name) {
static const QLatin1String prefix("Qt::");
if (name.indexOf(prefix) != 0)
return prefix;
return QLatin1String();
}
// 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) {
const DomProperty *pstyle = attributes.value(QLatin1String("toolBarArea"));
QString result;
if (!pstyle)
return QString();
return result;
switch (pstyle->kind()) {
case DomProperty::Number: {
return QLatin1String("static_cast<Qt::ToolBarArea>(")
+ QString::number(pstyle->elementNumber()) + QLatin1String("), ");
}
case DomProperty::Enum: {
const QString area = pstyle->elementEnum();
return qtEnumerationPrefix(area) + area + QLatin1String(", ");
}
case DomProperty::Number:
result = QLatin1String(language::toolbarArea(pstyle->elementNumber()));
break;
case DomProperty::Enum:
result = pstyle->elementEnum();
break;
default:
break;
}
return QString();
if (!result.startsWith(QLatin1String("Qt::")))
result.prepend(QLatin1String("Qt::"));
return result + QLatin1String(", ");
}
// Write a statement to create a spacer item.
@ -681,7 +672,7 @@ void WriteInitialization::acceptWidget(DomWidget *node)
} else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QDockWidget"))) {
m_output << m_indent << parentWidget << "->addDockWidget(";
if (DomProperty *pstyle = attributes.value(QLatin1String("dockWidgetArea")))
m_output << "static_cast<Qt::DockWidgetArea>(" << pstyle->elementNumber() << "), ";
m_output << "Qt::" << language::dockWidgetArea(pstyle->elementNumber()) << ", ";
m_output << varName << ");\n";
} else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QStatusBar"))) {
m_output << m_indent << parentWidget << "->setStatusBar(" << varName << ");\n";
@ -1509,8 +1500,8 @@ QString WriteInitialization::writeSizePolicy(const DomSizePolicy *sp)
m_output << m_indent << "QSizePolicy " << spName;
do {
if (sp->hasElementHSizeType() && sp->hasElementVSizeType()) {
m_output << "(static_cast<QSizePolicy::Policy>(" << sp->elementHSizeType()
<< "), static_cast<QSizePolicy::Policy>(" << sp->elementVSizeType() << "));\n";
m_output << "(QSizePolicy::" << language::sizePolicy(sp->elementHSizeType())
<< ", QSizePolicy::" << language::sizePolicy(sp->elementVSizeType()) << ");\n";
break;
}
if (sp->hasAttributeHSizeType() && sp->hasAttributeVSizeType()) {
@ -1767,7 +1758,7 @@ void WriteInitialization::writeColorGroup(DomColorGroup *colorGroup, const QStri
const DomColor *color = colors.at(i);
m_output << m_indent << paletteName << ".setColor(" << group
<< ", " << "static_cast<QPalette::ColorRole>(" << i << ')'
<< ", QPalette::" << language::paletteColorRole(i)
<< ", " << domColor2QString(color)
<< ");\n";
}

View File

@ -50,4 +50,95 @@ QTextStream &operator<<(QTextStream &str, const closeQtConfig &c)
return str;
}
struct EnumLookup
{
int value;
const char *valueString;
};
template <int N>
const char *lookupEnum(const EnumLookup(&array)[N], int value, int defaultIndex = 0)
{
for (int i = 0; i < N; ++i) {
if (value == array[i].value)
return array[i].valueString;
}
const char *defaultValue = array[defaultIndex].valueString;
qWarning("uic: Warning: Invalid enumeration value %d, defaulting to %s",
value, defaultValue);
return defaultValue;
}
const char *toolbarArea(int v)
{
static const EnumLookup toolBarAreas[] =
{
{0, "NoToolBarArea"},
{0x1, "LeftToolBarArea"},
{0x2, "RightToolBarArea"},
{0x4, "TopToolBarArea"},
{0x8, "BottomToolBarArea"},
{0xf, "AllToolBarAreas"}
};
return lookupEnum(toolBarAreas, v);
}
const char *sizePolicy(int v)
{
static const EnumLookup sizePolicies[] =
{
{0, "Fixed"},
{0x1, "Minimum"},
{0x4, "Maximum"},
{0x5, "Preferred"},
{0x3, "MinimumExpanding"},
{0x7, "Expanding"},
{0xD, "Ignored"}
};
return lookupEnum(sizePolicies, v, 3);
}
const char *dockWidgetArea(int v)
{
static const EnumLookup dockWidgetAreas[] =
{
{0, "NoDockWidgetArea"},
{0x1, "LeftDockWidgetArea"},
{0x2, "RightDockWidgetArea"},
{0x4, "TopDockWidgetArea"},
{0x8, "BottomDockWidgetArea"},
{0xf, "AllDockWidgetAreas"}
};
return lookupEnum(dockWidgetAreas, v);
}
const char *paletteColorRole(int v)
{
static const EnumLookup colorRoles[] =
{
{0, "WindowText"},
{1, "Button"},
{2, "Light"},
{3, "Midlight"},
{4, "Dark"},
{5, "Mid"},
{6, "Text"},
{7, "BrightText"},
{8, "ButtonText"},
{9, "Base"},
{10, "Window"},
{11, "Shadow"},
{12, "Highlight"},
{13, "HighlightedText"},
{14, "Link"},
{15, "LinkVisited"},
{16, "AlternateBase"},
{17, "NoRole"},
{18, "ToolTipBase"},
{19, "ToolTipText"},
{20, "PlaceholderText"},
};
return lookupEnum(colorRoles, v);
}
} // namespace language

View File

@ -71,6 +71,11 @@ public:
QTextStream &operator<<(QTextStream &, const closeQtConfig &c);
const char *toolbarArea(int v);
const char *sizePolicy(int v);
const char *dockWidgetArea(int v);
const char *paletteColorRole(int v);
} // namespace language
#endif // LANGUAGE_H

View File

@ -90,7 +90,7 @@ public:
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
groupBox = new QGroupBox(databaseTranslationDialog);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(4));
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(groupBox->sizePolicy().hasHeightForWidth());
@ -120,7 +120,7 @@ public:
groupBox_2 = new QGroupBox(databaseTranslationDialog);
groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(1));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Minimum);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(groupBox_2->sizePolicy().hasHeightForWidth());

View File

@ -62,7 +62,7 @@ public:
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
splitter_2 = new QSplitter(Browser);
splitter_2->setObjectName(QString::fromUtf8("splitter_2"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(7));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(splitter_2->sizePolicy().hasHeightForWidth());
@ -70,7 +70,7 @@ public:
splitter_2->setOrientation(Qt::Horizontal);
connectionWidget = new ConnectionWidget(splitter_2);
connectionWidget->setObjectName(QString::fromUtf8("connectionWidget"));
QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(13), static_cast<QSizePolicy::Policy>(7));
QSizePolicy sizePolicy1(QSizePolicy::Ignored, QSizePolicy::Expanding);
sizePolicy1.setHorizontalStretch(1);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(connectionWidget->sizePolicy().hasHeightForWidth());
@ -78,7 +78,7 @@ public:
splitter_2->addWidget(connectionWidget);
table = new QTableView(splitter_2);
table->setObjectName(QString::fromUtf8("table"));
QSizePolicy sizePolicy2(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(7));
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy2.setHorizontalStretch(2);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(table->sizePolicy().hasHeightForWidth());
@ -91,7 +91,7 @@ public:
groupBox = new QGroupBox(Browser);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
QSizePolicy sizePolicy3(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(3));
QSizePolicy sizePolicy3(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
sizePolicy3.setHorizontalStretch(0);
sizePolicy3.setVerticalStretch(0);
sizePolicy3.setHeightForWidth(groupBox->sizePolicy().hasHeightForWidth());
@ -107,7 +107,7 @@ public:
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
sqlEdit = new QTextEdit(groupBox);
sqlEdit->setObjectName(QString::fromUtf8("sqlEdit"));
QSizePolicy sizePolicy4(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(3));
QSizePolicy sizePolicy4(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
sizePolicy4.setHorizontalStretch(0);
sizePolicy4.setVerticalStretch(0);
sizePolicy4.setHeightForWidth(sqlEdit->sizePolicy().hasHeightForWidth());

View File

@ -45,7 +45,7 @@ public:
if (CalculatorForm->objectName().isEmpty())
CalculatorForm->setObjectName(QString::fromUtf8("CalculatorForm"));
CalculatorForm->resize(276, 98);
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(5));
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(CalculatorForm->sizePolicy().hasHeightForWidth());

View File

@ -99,7 +99,7 @@ public:
sendButton = new QPushButton(centralwidget);
sendButton->setObjectName(QString::fromUtf8("sendButton"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(1), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(sendButton->sizePolicy().hasHeightForWidth());

View File

@ -39,7 +39,7 @@ public:
if (NicknameDialog->objectName().isEmpty())
NicknameDialog->setObjectName(QString::fromUtf8("NicknameDialog"));
NicknameDialog->resize(396, 105);
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(1), static_cast<QSizePolicy::Policy>(1));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(NicknameDialog->sizePolicy().hasHeightForWidth());

View File

@ -86,7 +86,7 @@ public:
colorDepthCombo = new QComboBox(dialog);
colorDepthCombo->setObjectName(QString::fromUtf8("colorDepthCombo"));
colorDepthCombo->setGeometry(QRect(74, 83, 227, 22));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(colorDepthCombo->sizePolicy().hasHeightForWidth());
@ -98,7 +98,7 @@ public:
nameLineEdit = new QLineEdit(dialog);
nameLineEdit->setObjectName(QString::fromUtf8("nameLineEdit"));
nameLineEdit->setGeometry(QRect(74, 83, 227, 22));
QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Fixed);
sizePolicy1.setHorizontalStretch(1);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(nameLineEdit->sizePolicy().hasHeightForWidth());

View File

@ -93,7 +93,7 @@ public:
lblPreview = new QLabel(NewForm);
lblPreview->setObjectName(QString::fromUtf8("lblPreview"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(5));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(lblPreview->sizePolicy().hasHeightForWidth());

View File

@ -81,7 +81,7 @@ public:
if (qdesigner_internal__PaletteEditor->objectName().isEmpty())
qdesigner_internal__PaletteEditor->setObjectName(QString::fromUtf8("qdesigner_internal__PaletteEditor"));
qdesigner_internal__PaletteEditor->resize(365, 409);
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(7));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(qdesigner_internal__PaletteEditor->sizePolicy().hasHeightForWidth());
@ -108,7 +108,7 @@ public:
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
buildButton = new QtColorButton(advancedBox);
buildButton->setObjectName(QString::fromUtf8("buildButton"));
QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(13));
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Ignored);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(buildButton->sizePolicy().hasHeightForWidth());
@ -143,7 +143,7 @@ public:
GroupBox126 = new QGroupBox(qdesigner_internal__PaletteEditor);
GroupBox126->setObjectName(QString::fromUtf8("GroupBox126"));
QSizePolicy sizePolicy2(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(7));
QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Expanding);
sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(GroupBox126->sizePolicy().hasHeightForWidth());

View File

@ -70,7 +70,7 @@ public:
paperSizeCombo = new QComboBox(PreviewDialogBase);
paperSizeCombo->setObjectName(QString::fromUtf8("paperSizeCombo"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(1), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(paperSizeCombo->sizePolicy().hasHeightForWidth());
@ -115,7 +115,7 @@ public:
previewArea = new QScrollArea(PreviewDialogBase);
previewArea->setObjectName(QString::fromUtf8("previewArea"));
QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(5));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(1);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(previewArea->sizePolicy().hasHeightForWidth());
@ -135,7 +135,7 @@ public:
progressBar = new QProgressBar(PreviewDialogBase);
progressBar->setObjectName(QString::fromUtf8("progressBar"));
progressBar->setEnabled(false);
QSizePolicy sizePolicy2(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
sizePolicy2.setHorizontalStretch(1);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(progressBar->sizePolicy().hasHeightForWidth());

View File

@ -92,7 +92,7 @@ public:
if (qdesigner_internal__PreviewWidget->objectName().isEmpty())
qdesigner_internal__PreviewWidget->setObjectName(QString::fromUtf8("qdesigner_internal__PreviewWidget"));
qdesigner_internal__PreviewWidget->resize(471, 251);
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(1), static_cast<QSizePolicy::Policy>(1));
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(qdesigner_internal__PreviewWidget->sizePolicy().hasHeightForWidth());

View File

@ -73,7 +73,7 @@ public:
styleCombo = new QComboBox(StyleSheetEditor);
styleCombo->setObjectName(QString::fromUtf8("styleCombo"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(5), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(styleCombo->sizePolicy().hasHeightForWidth());
@ -83,7 +83,7 @@ public:
label_7 = new QLabel(StyleSheetEditor);
label_7->setObjectName(QString::fromUtf8("label_7"));
QSizePolicy sizePolicy1(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(5));
QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Preferred);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(label_7->sizePolicy().hasHeightForWidth());

View File

@ -117,7 +117,7 @@ public:
editFind = new QLineEdit(frameFind);
editFind->setObjectName(QString::fromUtf8("editFind"));
QSizePolicy sizePolicy(static_cast<QSizePolicy::Policy>(0), static_cast<QSizePolicy::Policy>(0));
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(editFind->sizePolicy().hasHeightForWidth());

View File

@ -117,7 +117,7 @@ public:
mainToolBar = new QToolBar(TrPreviewToolClass);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
mainToolBar->setOrientation(Qt::Horizontal);
TrPreviewToolClass->addToolBar(static_cast<Qt::ToolBarArea>(4), mainToolBar);
TrPreviewToolClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(TrPreviewToolClass);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
TrPreviewToolClass->setStatusBar(statusBar);
@ -138,7 +138,7 @@ public:
vboxLayout->addWidget(viewForms);
dwForms->setWidget(dockWidgetContents);
TrPreviewToolClass->addDockWidget(static_cast<Qt::DockWidgetArea>(1), dwForms);
TrPreviewToolClass->addDockWidget(Qt::LeftDockWidgetArea, dwForms);
menuBar->addAction(menuFile->menuAction());
menuBar->addAction(menuView->menuAction());