From 9cd021f517e55abc31b3fd9e405ea94ce9eda44d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 15 Jan 2019 13:31:21 +0100 Subject: uic: Refactor reverse name lookup Add a helper routine to look up the dom classes by attribute name and change Driver::widgetByName() and Driver::actionByName() to use that as does Driver::actionGroupByName() (all these functions are called with names from the XML files). Remove the name normalization in WriteInitialization::findDeclaration() and refactor WriteInitialization::acceptActionRef() to call findOrInsert() to correctly use the unique name. Task-number: PYSIDE-797 Change-Id: I34058361964719c442182faf798f055f11b40412 Reviewed-by: Cristian Maureira-Fredes --- src/tools/uic/cpp/cppwriteinitialization.cpp | 37 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/tools/uic/cpp/cppwriteinitialization.cpp') diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp index 2fb3e502c58..881c48daea4 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.cpp +++ b/src/tools/uic/cpp/cppwriteinitialization.cpp @@ -1069,28 +1069,29 @@ void WriteInitialization::acceptActionRef(DomActionRef *node) } const QString varName = m_driver->findOrInsertWidget(m_widgetChain.top()); - const bool isSeparator = actionName == QLatin1String("separator"); - bool isMenu = false; - if (const DomWidget *w = m_driver->widgetByName(actionName)) { - isMenu = m_uic->isMenu(w->attributeClass()); - } else if (!(m_driver->actionByName(actionName) || isSeparator)) { - fprintf(stderr, "%s: Warning: action `%s' not declared\n", - qPrintable(m_option.messagePrefix()), - actionName.toLatin1().data()); + if (m_widgetChain.top() && actionName == QLatin1String("separator")) { + // separator is always reserved! + m_actionOut << m_indent << varName << "->addSeparator();\n"; return; } - if (m_widgetChain.top() && isSeparator) { - // separator is always reserved! - m_actionOut << m_indent << varName << "->addSeparator();\n"; + const DomWidget *domWidget = m_driver->widgetByName(actionName); + if (domWidget && m_uic->isMenu(domWidget->attributeClass())) { + m_actionOut << m_indent << varName << "->addAction(" + << m_driver->findOrInsertWidget(domWidget) << "->menuAction());\n"; return; } - if (isMenu) - actionName += QLatin1String("->menuAction()"); + const DomAction *domAction = m_driver->actionByName(actionName); + if (!domAction) { + fprintf(stderr, "%s: Warning: action `%s' not declared\n", + qPrintable(m_option.messagePrefix()), qPrintable(actionName)); + return; + } - m_actionOut << m_indent << varName << "->addAction(" << actionName << ");\n"; + m_actionOut << m_indent << varName << "->addAction(" + << m_driver->findOrInsertAction(domAction) << ");\n"; } QString WriteInitialization::writeStringListProperty(const DomStringList *list) const @@ -2430,13 +2431,11 @@ QTextStream &WriteInitialization::autoTrOutput(const DomString *str, const QStri QString WriteInitialization::findDeclaration(const QString &name) { - const QString normalized = Driver::normalizedName(name); - - if (const DomWidget *widget = m_driver->widgetByName(normalized)) + if (const DomWidget *widget = m_driver->widgetByName(name)) return m_driver->findOrInsertWidget(widget); - if (const DomAction *action = m_driver->actionByName(normalized)) + if (const DomAction *action = m_driver->actionByName(name)) return m_driver->findOrInsertAction(action); - if (const DomButtonGroup *group = m_driver->findButtonGroup(normalized)) + if (const DomButtonGroup *group = m_driver->findButtonGroup(name)) return m_driver->findOrInsertButtonGroup(group); return QString(); } -- cgit v1.2.3