uic: Refactor CustomWidgetsInfo::extends() to use QAnyStringView
Task-number: PYSIDE-1720 Pick-to: 6.2 Change-Id: I2db4ee9586a87c70db08298e311d692e20a93af0 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
271ea6cd3e
commit
fac5b084a9
@ -143,7 +143,7 @@ namespace {
|
|||||||
// ### fixme Qt 7 remove this: Exclude deprecated properties of Qt 5.
|
// ### fixme Qt 7 remove this: Exclude deprecated properties of Qt 5.
|
||||||
case DomProperty::Set:
|
case DomProperty::Set:
|
||||||
if (p->attributeName() == u"features"
|
if (p->attributeName() == u"features"
|
||||||
&& customWidgetsInfo->extends(className, QLatin1String("QDockWidget"))
|
&& customWidgetsInfo->extends(className, "QDockWidget")
|
||||||
&& p->elementSet() == u"QDockWidget::AllDockWidgetFeatures") {
|
&& p->elementSet() == u"QDockWidget::AllDockWidgetFeatures") {
|
||||||
const QString msg = fileName + QLatin1String(": Warning: Deprecated enum value QDockWidget::AllDockWidgetFeatures was encountered.");
|
const QString msg = fileName + QLatin1String(": Warning: Deprecated enum value QDockWidget::AllDockWidgetFeatures was encountered.");
|
||||||
qWarning("%s", qPrintable(msg));
|
qWarning("%s", qPrintable(msg));
|
||||||
@ -152,7 +152,7 @@ namespace {
|
|||||||
break;
|
break;
|
||||||
case DomProperty::Enum:
|
case DomProperty::Enum:
|
||||||
if (p->attributeName() == u"sizeAdjustPolicy"
|
if (p->attributeName() == u"sizeAdjustPolicy"
|
||||||
&& customWidgetsInfo->extends(className, QLatin1String("QComboBox"))
|
&& customWidgetsInfo->extends(className, "QComboBox")
|
||||||
&& p->elementEnum() == u"QComboBox::AdjustToMinimumContentsLength") {
|
&& p->elementEnum() == u"QComboBox::AdjustToMinimumContentsLength") {
|
||||||
const QString msg = fileName + QLatin1String(": Warning: Deprecated enum value QComboBox::AdjustToMinimumContentsLength was encountered.");
|
const QString msg = fileName + QLatin1String(": Warning: Deprecated enum value QComboBox::AdjustToMinimumContentsLength was encountered.");
|
||||||
qWarning("%s", qPrintable(msg));
|
qWarning("%s", qPrintable(msg));
|
||||||
@ -649,13 +649,13 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||||||
parentWidget = savedParentWidget;
|
parentWidget = savedParentWidget;
|
||||||
|
|
||||||
|
|
||||||
if (cwi->extends(className, QLatin1String("QComboBox"))) {
|
if (cwi->extends(className, "QComboBox")) {
|
||||||
initializeComboBox(node);
|
initializeComboBox(node);
|
||||||
} else if (cwi->extends(className, QLatin1String("QListWidget"))) {
|
} else if (cwi->extends(className, "QListWidget")) {
|
||||||
initializeListWidget(node);
|
initializeListWidget(node);
|
||||||
} else if (cwi->extends(className, QLatin1String("QTreeWidget"))) {
|
} else if (cwi->extends(className, "QTreeWidget")) {
|
||||||
initializeTreeWidget(node);
|
initializeTreeWidget(node);
|
||||||
} else if (cwi->extends(className, QLatin1String("QTableWidget"))) {
|
} else if (cwi->extends(className, "QTableWidget")) {
|
||||||
initializeTableWidget(node);
|
initializeTableWidget(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,7 +665,7 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||||||
writeProperties(varName, className, node->elementProperty());
|
writeProperties(varName, className, node->elementProperty());
|
||||||
|
|
||||||
if (!parentWidget.isEmpty()
|
if (!parentWidget.isEmpty()
|
||||||
&& cwi->extends(className, QLatin1String("QMenu"))) {
|
&& cwi->extends(className, "QMenu")) {
|
||||||
initializeMenu(node, parentWidget);
|
initializeMenu(node, parentWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,11 +693,11 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||||||
|
|
||||||
const QString pageDefaultString = QLatin1String("Page");
|
const QString pageDefaultString = QLatin1String("Page");
|
||||||
|
|
||||||
if (cwi->extends(parentClass, QLatin1String("QMainWindow"))) {
|
if (cwi->extends(parentClass, "QMainWindow")) {
|
||||||
if (cwi->extends(className, QLatin1String("QMenuBar"))) {
|
if (cwi->extends(className, "QMenuBar")) {
|
||||||
m_output << m_indent << parentWidget << language::derefPointer
|
m_output << m_indent << parentWidget << language::derefPointer
|
||||||
<< "setMenuBar(" << varName << ')' << language::eol;
|
<< "setMenuBar(" << varName << ')' << language::eol;
|
||||||
} else if (cwi->extends(className, QLatin1String("QToolBar"))) {
|
} else if (cwi->extends(className, "QToolBar")) {
|
||||||
m_output << m_indent << parentWidget << language::derefPointer << "addToolBar("
|
m_output << m_indent << parentWidget << language::derefPointer << "addToolBar("
|
||||||
<< language::enumValue(toolBarAreaStringFromDOMAttributes(attributes)) << varName
|
<< language::enumValue(toolBarAreaStringFromDOMAttributes(attributes)) << varName
|
||||||
<< ')' << language::eol;
|
<< ')' << language::eol;
|
||||||
@ -709,14 +709,14 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (cwi->extends(className, QLatin1String("QDockWidget"))) {
|
} else if (cwi->extends(className, "QDockWidget")) {
|
||||||
m_output << m_indent << parentWidget << language::derefPointer << "addDockWidget(";
|
m_output << m_indent << parentWidget << language::derefPointer << "addDockWidget(";
|
||||||
if (DomProperty *pstyle = attributes.value(QLatin1String("dockWidgetArea"))) {
|
if (DomProperty *pstyle = attributes.value(QLatin1String("dockWidgetArea"))) {
|
||||||
m_output << "Qt" << language::qualifier
|
m_output << "Qt" << language::qualifier
|
||||||
<< language::dockWidgetArea(pstyle->elementNumber()) << ", ";
|
<< language::dockWidgetArea(pstyle->elementNumber()) << ", ";
|
||||||
}
|
}
|
||||||
m_output << varName << ")" << language::eol;
|
m_output << varName << ")" << language::eol;
|
||||||
} else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QStatusBar"))) {
|
} else if (m_uic->customWidgetsInfo()->extends(className, "QStatusBar")) {
|
||||||
m_output << m_indent << parentWidget << language::derefPointer
|
m_output << m_indent << parentWidget << language::derefPointer
|
||||||
<< "setStatusBar(" << varName << ')' << language::eol;
|
<< "setStatusBar(" << varName << ')' << language::eol;
|
||||||
} else {
|
} else {
|
||||||
@ -732,9 +732,9 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||||||
if (!addPageMethod.isEmpty()) {
|
if (!addPageMethod.isEmpty()) {
|
||||||
m_output << m_indent << parentWidget << language::derefPointer
|
m_output << m_indent << parentWidget << language::derefPointer
|
||||||
<< addPageMethod << '(' << varName << ')' << language::eol;
|
<< addPageMethod << '(' << varName << ')' << language::eol;
|
||||||
} else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QWizard"))) {
|
} else if (m_uic->customWidgetsInfo()->extends(parentClass, "QWizard")) {
|
||||||
addWizardPage(varName, node, parentWidget);
|
addWizardPage(varName, node, parentWidget);
|
||||||
} else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QToolBox"))) {
|
} else if (m_uic->customWidgetsInfo()->extends(parentClass, "QToolBox")) {
|
||||||
const DomProperty *plabel = attributes.value(QLatin1String("label"));
|
const DomProperty *plabel = attributes.value(QLatin1String("label"));
|
||||||
DomString *plabelString = plabel ? plabel->elementString() : nullptr;
|
DomString *plabelString = plabel ? plabel->elementString() : nullptr;
|
||||||
QString icon;
|
QString icon;
|
||||||
@ -757,7 +757,7 @@ void WriteInitialization::acceptWidget(DomWidget *node)
|
|||||||
<< autoTrCall(ptoolTip->elementString()) << ')' << language::eol
|
<< autoTrCall(ptoolTip->elementString()) << ')' << language::eol
|
||||||
<< language::closeQtConfig(toolTipConfigKey());
|
<< language::closeQtConfig(toolTipConfigKey());
|
||||||
}
|
}
|
||||||
} else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QTabWidget"))) {
|
} else if (m_uic->customWidgetsInfo()->extends(parentClass, "QTabWidget")) {
|
||||||
const DomProperty *ptitle = attributes.value(QLatin1String("title"));
|
const DomProperty *ptitle = attributes.value(QLatin1String("title"));
|
||||||
DomString *ptitleString = ptitle ? ptitle->elementString() : nullptr;
|
DomString *ptitleString = ptitle ? ptitle->elementString() : nullptr;
|
||||||
QString icon;
|
QString icon;
|
||||||
@ -1190,7 +1190,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||||||
{
|
{
|
||||||
const bool isTopLevel = m_widgetChain.count() == 1;
|
const bool isTopLevel = m_widgetChain.count() == 1;
|
||||||
|
|
||||||
if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) {
|
if (m_uic->customWidgetsInfo()->extends(className, "QAxWidget")) {
|
||||||
DomPropertyMap properties = propertyMap(lst);
|
DomPropertyMap properties = propertyMap(lst);
|
||||||
if (DomProperty *p = properties.value(QLatin1String("control"))) {
|
if (DomProperty *p = properties.value(QLatin1String("control"))) {
|
||||||
m_output << m_indent << varName << language::derefPointer << "setControl("
|
m_output << m_indent << varName << language::derefPointer << "setControl("
|
||||||
@ -1239,7 +1239,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (propertyName == QLatin1String("currentRow") // QListWidget::currentRow
|
if (propertyName == QLatin1String("currentRow") // QListWidget::currentRow
|
||||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QListWidget"))) {
|
&& m_uic->customWidgetsInfo()->extends(className, "QListWidget")) {
|
||||||
m_delayedOut << m_indent << varName << language::derefPointer
|
m_delayedOut << m_indent << varName << language::derefPointer
|
||||||
<< "setCurrentRow(" << p->elementNumber() << ')' << language::eol;
|
<< "setCurrentRow(" << p->elementNumber() << ')' << language::eol;
|
||||||
continue;
|
continue;
|
||||||
@ -1255,19 +1255,19 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (propertyName == QLatin1String("tabSpacing")
|
if (propertyName == QLatin1String("tabSpacing")
|
||||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox"))) {
|
&& m_uic->customWidgetsInfo()->extends(className, "QToolBox")) {
|
||||||
m_delayedOut << m_indent << varName << language::derefPointer
|
m_delayedOut << m_indent << varName << language::derefPointer
|
||||||
<< "layout()" << language::derefPointer << "setSpacing("
|
<< "layout()" << language::derefPointer << "setSpacing("
|
||||||
<< p->elementNumber() << ')' << language::eol;
|
<< p->elementNumber() << ')' << language::eol;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (propertyName == QLatin1String("control") // ActiveQt support
|
if (propertyName == QLatin1String("control") // ActiveQt support
|
||||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) {
|
&& m_uic->customWidgetsInfo()->extends(className, "QAxWidget")) {
|
||||||
// already done ;)
|
// already done ;)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (propertyName == QLatin1String("default")
|
if (propertyName == QLatin1String("default")
|
||||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QPushButton"))) {
|
&& m_uic->customWidgetsInfo()->extends(className, "QPushButton")) {
|
||||||
// QTBUG-44406: Setting of QPushButton::default needs to be delayed until the parent is set
|
// QTBUG-44406: Setting of QPushButton::default needs to be delayed until the parent is set
|
||||||
delayProperty = true;
|
delayProperty = true;
|
||||||
} else if (propertyName == QLatin1String("database")
|
} else if (propertyName == QLatin1String("database")
|
||||||
@ -1279,7 +1279,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||||||
// Sql support
|
// Sql support
|
||||||
continue;
|
continue;
|
||||||
} else if (propertyName == QLatin1String("orientation")
|
} else if (propertyName == QLatin1String("orientation")
|
||||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("Line"))) {
|
&& m_uic->customWidgetsInfo()->extends(className, "Line")) {
|
||||||
// Line support
|
// Line support
|
||||||
QString shape = QLatin1String("QFrame::HLine");
|
QString shape = QLatin1String("QFrame::HLine");
|
||||||
if (p->elementEnum() == QLatin1String("Qt::Vertical"))
|
if (p->elementEnum() == QLatin1String("Qt::Vertical"))
|
||||||
@ -1312,7 +1312,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||||||
bottomMargin = p->elementNumber();
|
bottomMargin = p->elementNumber();
|
||||||
continue;
|
continue;
|
||||||
} else if (propertyName == QLatin1String("numDigits") // Deprecated in Qt 4, removed in Qt 5.
|
} else if (propertyName == QLatin1String("numDigits") // Deprecated in Qt 4, removed in Qt 5.
|
||||||
&& m_uic->customWidgetsInfo()->extends(className, QLatin1String("QLCDNumber"))) {
|
&& m_uic->customWidgetsInfo()->extends(className, "QLCDNumber")) {
|
||||||
qWarning("Widget '%s': Deprecated property QLCDNumber::numDigits encountered. It has been replaced by QLCDNumber::digitCount.",
|
qWarning("Widget '%s': Deprecated property QLCDNumber::numDigits encountered. It has been replaced by QLCDNumber::digitCount.",
|
||||||
qPrintable(varName));
|
qPrintable(varName));
|
||||||
propertyName = QLatin1String("digitCount");
|
propertyName = QLatin1String("digitCount");
|
||||||
@ -1354,7 +1354,7 @@ void WriteInitialization::writeProperties(const QString &varName,
|
|||||||
propertyValue = domColor2QString(p->elementColor());
|
propertyValue = domColor2QString(p->elementColor());
|
||||||
break;
|
break;
|
||||||
case DomProperty::Cstring:
|
case DomProperty::Cstring:
|
||||||
if (propertyName == QLatin1String("buddy") && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QLabel"))) {
|
if (propertyName == QLatin1String("buddy") && m_uic->customWidgetsInfo()->extends(className, "QLabel")) {
|
||||||
Buddy buddy = { varName, p->elementCstring() };
|
Buddy buddy = { varName, p->elementCstring() };
|
||||||
m_buddies.append(std::move(buddy));
|
m_buddies.append(std::move(buddy));
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,7 +58,7 @@ void CustomWidgetsInfo::acceptCustomWidget(DomCustomWidget *node)
|
|||||||
m_customWidgets.insert(node->elementClass(), node);
|
m_customWidgets.insert(node->elementClass(), node);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomWidgetsInfo::extends(const QString &classNameIn, QLatin1String baseClassName) const
|
bool CustomWidgetsInfo::extends(const QString &classNameIn, QAnyStringView baseClassName) const
|
||||||
{
|
{
|
||||||
if (classNameIn == baseClassName)
|
if (classNameIn == baseClassName)
|
||||||
return true;
|
return true;
|
||||||
@ -119,19 +119,19 @@ QString CustomWidgetsInfo::customWidgetAddPageMethod(const QString &name) const
|
|||||||
// add page methods for simple containers taking only the widget parameter
|
// add page methods for simple containers taking only the widget parameter
|
||||||
QString CustomWidgetsInfo::simpleContainerAddPageMethod(const QString &name) const
|
QString CustomWidgetsInfo::simpleContainerAddPageMethod(const QString &name) const
|
||||||
{
|
{
|
||||||
using AddPageMethod = std::pair<const char *, const char *>;
|
using AddPageMethod = std::pair<QString, QString>;
|
||||||
|
|
||||||
static AddPageMethod addPageMethods[] = {
|
static const AddPageMethod addPageMethods[] = {
|
||||||
{"QStackedWidget", "addWidget"},
|
{u"QStackedWidget"_qs, u"addWidget"_qs},
|
||||||
{"QToolBar", "addWidget"},
|
{u"QToolBar"_qs, u"addWidget"_qs},
|
||||||
{"QDockWidget", "setWidget"},
|
{u"QDockWidget"_qs, u"setWidget"_qs},
|
||||||
{"QScrollArea", "setWidget"},
|
{u"QScrollArea"_qs, u"setWidget"_qs},
|
||||||
{"QSplitter", "addWidget"},
|
{u"QSplitter"_qs, u"addWidget"_qs},
|
||||||
{"QMdiArea", "addSubWindow"}
|
{u"QMdiArea"_qs, u"addSubWindow"_qs}
|
||||||
};
|
};
|
||||||
for (const auto &m : addPageMethods) {
|
for (const auto &m : addPageMethods) {
|
||||||
if (extends(name, QLatin1String(m.first)))
|
if (extends(name, m.first))
|
||||||
return QLatin1String(m.second);
|
return m.second;
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
QString realClassName(const QString &className) const;
|
QString realClassName(const QString &className) const;
|
||||||
|
|
||||||
bool extends(const QString &className, QLatin1String baseClassName) const;
|
bool extends(const QString &className, QAnyStringView baseClassName) const;
|
||||||
bool extendsOneOf(const QString &className, const QStringList &baseClassNames) const;
|
bool extendsOneOf(const QString &className, const QStringList &baseClassNames) const;
|
||||||
|
|
||||||
bool isCustomWidgetContainer(const QString &className) const;
|
bool isCustomWidgetContainer(const QString &className) const;
|
||||||
|
@ -179,11 +179,11 @@ void WriteImports::writeImport(const QString &module)
|
|||||||
void WriteImports::doAdd(const QString &className, const DomCustomWidget *dcw)
|
void WriteImports::doAdd(const QString &className, const DomCustomWidget *dcw)
|
||||||
{
|
{
|
||||||
const CustomWidgetsInfo *cwi = uic()->customWidgetsInfo();
|
const CustomWidgetsInfo *cwi = uic()->customWidgetsInfo();
|
||||||
if (cwi->extends(className, QLatin1String("QListWidget")))
|
if (cwi->extends(className, "QListWidget"))
|
||||||
add(QStringLiteral("QListWidgetItem"));
|
add(QStringLiteral("QListWidgetItem"));
|
||||||
else if (cwi->extends(className, QLatin1String("QTreeWidget")))
|
else if (cwi->extends(className, "QTreeWidget"))
|
||||||
add(QStringLiteral("QTreeWidgetItem"));
|
add(QStringLiteral("QTreeWidgetItem"));
|
||||||
else if (cwi->extends(className, QLatin1String("QTableWidget")))
|
else if (cwi->extends(className, "QTableWidget"))
|
||||||
add(QStringLiteral("QTableWidgetItem"));
|
add(QStringLiteral("QTableWidgetItem"));
|
||||||
|
|
||||||
if (dcw != nullptr) {
|
if (dcw != nullptr) {
|
||||||
|
@ -118,7 +118,7 @@ void WriteIncludesBase::add(const QString &className, const DomCustomWidget *dcw
|
|||||||
if (cwi->extendsOneOf(className, treeViewsWithHeaders))
|
if (cwi->extendsOneOf(className, treeViewsWithHeaders))
|
||||||
add(QStringLiteral("QHeaderView"));
|
add(QStringLiteral("QHeaderView"));
|
||||||
|
|
||||||
if (!m_laidOut && cwi->extends(className, QLatin1String("QToolBox")))
|
if (!m_laidOut && cwi->extends(className, "QToolBox"))
|
||||||
add(QStringLiteral("QLayout")); // spacing property of QToolBox)
|
add(QStringLiteral("QLayout")); // spacing property of QToolBox)
|
||||||
|
|
||||||
if (className == QStringLiteral("Line")) { // ### hmm, deprecate me!
|
if (className == QStringLiteral("Line")) { // ### hmm, deprecate me!
|
||||||
@ -126,7 +126,7 @@ void WriteIncludesBase::add(const QString &className, const DomCustomWidget *dcw
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cwi->extends(className, QLatin1String("QDialogButtonBox")))
|
if (cwi->extends(className, "QDialogButtonBox"))
|
||||||
add(QStringLiteral("QAbstractButton")); // for signal "clicked(QAbstractButton*)"
|
add(QStringLiteral("QAbstractButton")); // for signal "clicked(QAbstractButton*)"
|
||||||
|
|
||||||
doAdd(className, dcw);
|
doAdd(className, dcw);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user