void WriteDeclaration::acceptUI(DomUI *node) { QString qualifiedClassName = node->elementClass() + m_option.postfix; // Ruby classnames must start with an upper case letter QString className = qualifiedClassName.mid(0, 1).toUpper() + qualifiedClassName.mid(1); QString varName = m_driver->findOrInsertWidget(node->elementWidget()); QString widgetClassName = node->elementWidget()->attributeClass(); QString exportMacro = node->elementExportMacro(); if (!exportMacro.isEmpty()) exportMacro.append(QLatin1Char(' ')); QStringList namespaceList = qualifiedClassName.split(QLatin1String("::")); if (namespaceList.count()) { className = namespaceList.last().mid(0, 1).toUpper() + namespaceList.last().mid(1); namespaceList.removeLast(); } QListIterator<QString> it(namespaceList); while (it.hasNext()) { QString ns = it.next(); if (ns.isEmpty()) continue; } if (namespaceList.count()) m_output << "\n"; m_output << "class " << m_option.prefix << className << "\n"; const QStringList connections = m_uic->databaseInfo()->connections(); for (int i=0; i<connections.size(); ++i) { const QString connection = connections.at(i); if (connection == QLatin1String("(default)")) continue; m_output << m_option.indent << "@" << connection << "Connection = Qt5::QSqlDatabase.new\n"; } TreeWalker::acceptWidget(node->elementWidget()); m_output << "\n"; WriteInitialization(m_uic).acceptUI(node); if (node->elementImages()) { WriteIconDeclaration(m_uic).acceptUI(node); m_output << m_option.indent << m_option.indent << "unknown_ID = " << node->elementImages()->elementImage().size() << "\n" << m_option.indent << "\n"; WriteIconInitialization(m_uic).acceptUI(node); } m_output << "end\n\n"; it.toBack(); while (it.hasPrevious()) { QString ns = it.previous(); if (ns.isEmpty()) continue; } if (namespaceList.count()) m_output << "\n"; if (m_option.generateNamespace && !m_option.prefix.isEmpty()) { namespaceList.append(QLatin1String("Ui")); QListIterator<QString> it(namespaceList); while (it.hasNext()) { QString ns = it.next(); if (ns.isEmpty()) continue; m_output << "module " << ns.mid(0, 1).toUpper() << ns.mid(1) << "\n"; } m_output << m_option.indent << "class " << className << " < " << m_option.prefix << className << "\n"; m_output << m_option.indent << "end\n"; it.toBack(); while (it.hasPrevious()) { QString ns = it.previous(); if (ns.isEmpty()) continue; m_output << "end # module " << ns << "\n"; } if (namespaceList.count()) m_output << "\n"; } }
void WriteDeclaration::acceptUI(DomUI *node) { QString qualifiedClassName = node->elementClass() + option.postfix; QString className = qualifiedClassName; QString varName = driver->findOrInsertWidget(node->elementWidget()); QString widgetClassName = node->elementWidget()->attributeClass(); QString exportMacro = node->elementExportMacro(); if (!exportMacro.isEmpty()) exportMacro.append(QLatin1Char(' ')); QStringList nsList = qualifiedClassName.split(QLatin1String("::")); if (nsList.count()) { className = nsList.last(); nsList.removeLast(); } QListIterator<QString> it(nsList); while (it.hasNext()) { QString ns = it.next(); if (ns.isEmpty()) continue; output << "namespace " << ns << " {\n"; } if (nsList.count()) output << "\n"; output << "class " << exportMacro << option.prefix << className << "\n" << "{\n" << "public:\n"; QStringList connections = uic->databaseInfo()->connections(); for (int i=0; i<connections.size(); ++i) { QString connection = connections.at(i); if (connection == QLatin1String("(default)")) continue; output << option.indent << "QSqlDatabase " << connection << "Connection;\n"; } TreeWalker::acceptWidget(node->elementWidget()); output << "\n"; WriteInitialization(uic).acceptUI(node); if (node->elementImages()) { output << "\n" << "protected:\n" << option.indent << "enum IconID\n" << option.indent << "{\n"; WriteIconDeclaration(uic).acceptUI(node); output << option.indent << option.indent << "unknown_ID\n" << option.indent << "};\n"; WriteIconInitialization(uic).acceptUI(node); } output << "};\n\n"; it.toBack(); while (it.hasPrevious()) { QString ns = it.previous(); if (ns.isEmpty()) continue; output << "} // namespace " << ns << "\n"; } if (nsList.count()) output << "\n"; if (option.generateNamespace && !option.prefix.isEmpty()) { nsList.append(QLatin1String("Ui")); QListIterator<QString> it(nsList); while (it.hasNext()) { QString ns = it.next(); if (ns.isEmpty()) continue; output << "namespace " << ns << " {\n"; } output << option.indent << "class " << exportMacro << className << ": public " << option.prefix << className << " {};\n"; it.toBack(); while (it.hasPrevious()) { QString ns = it.previous(); if (ns.isEmpty()) continue; output << "} // namespace " << ns << "\n"; } if (nsList.count()) output << "\n"; } }
void WriteDeclaration::acceptUI(DomUI *node) { QString qualifiedClassName = node->elementClass() + m_option.postfix; QString className = qualifiedClassName; QString varName = m_driver->findOrInsertWidget(node->elementWidget()); QString widgetClassName = node->elementWidget()->attributeClass(); QString exportMacro = node->elementExportMacro(); if (!exportMacro.isEmpty()) exportMacro.append(QLatin1Char(' ')); QStringList namespaceList = qualifiedClassName.split(QLatin1String("::")); if (namespaceList.count()) { className = namespaceList.last(); namespaceList.removeLast(); } // This is a bit of the hack but covers the cases Qt in/without namespaces // and User defined classes in/without namespaces. The "strange" case // is a User using Qt-in-namespace having his own classes not in a namespace. // In this case the generated Ui helper classes will also end up in // the Qt namespace (which is harmless, but not "pretty") const bool needsMacro = namespaceList.count() == 0 || namespaceList[0] == QLatin1String("qdesigner_internal"); if (needsMacro) m_output << "QT_BEGIN_NAMESPACE\n\n"; openNameSpaces(namespaceList, m_output); if (namespaceList.count()) m_output << "\n"; m_output << "class " << exportMacro << m_option.prefix << className << "\n" << "{\n" << "public:\n"; const QStringList connections = m_uic->databaseInfo()->connections(); for (int i=0; i<connections.size(); ++i) { const QString connection = connections.at(i); if (connection == QLatin1String("(default)")) continue; m_output << m_option.indent << "QSqlDatabase " << connection << "Connection;\n"; } TreeWalker::acceptWidget(node->elementWidget()); m_output << "\n"; WriteInitialization(m_uic, m_activateScripts).acceptUI(node); if (node->elementImages()) { if (m_option.extractImages) { ExtractImages(m_uic->option()).acceptUI(node); } else { m_output << "\n" << "protected:\n" << m_option.indent << "enum IconID\n" << m_option.indent << "{\n"; WriteIconDeclaration(m_uic).acceptUI(node); m_output << m_option.indent << m_option.indent << "unknown_ID\n" << m_option.indent << "};\n"; WriteIconInitialization(m_uic).acceptUI(node); } } if (m_activateScripts) { m_output << "\nprivate:\n\n"; writeScriptContextClass(m_option.indent, m_output); } m_output << "};\n\n"; closeNameSpaces(namespaceList, m_output); if (namespaceList.count()) m_output << "\n"; if (m_option.generateNamespace && !m_option.prefix.isEmpty()) { namespaceList.append(QLatin1String("Ui")); openNameSpaces(namespaceList, m_output); m_output << m_option.indent << "class " << exportMacro << className << ": public " << m_option.prefix << className << " {};\n"; closeNameSpaces(namespaceList, m_output); if (namespaceList.count()) m_output << "\n"; } if (needsMacro) m_output << "QT_END_NAMESPACE\n\n"; }
void WriteDeclaration::acceptUI(DomUI *node) { QString qualifiedClassName = node->elementClass() + m_option.postfix; QString className = qualifiedClassName; QString varName = m_driver->findOrInsertWidget(node->elementWidget()); QString widgetClassName = node->elementWidget()->attributeClass(); QString exportMacro = node->elementExportMacro(); if (!exportMacro.isEmpty()) exportMacro.append(QLatin1Char(' ')); QStringList namespaceList = qualifiedClassName.split(QLatin1String("::")); if (namespaceList.count()) { className = namespaceList.last(); namespaceList.removeLast(); } openNameSpaces(namespaceList, m_output); if (namespaceList.count()) m_output << "\n"; m_output << "class " << exportMacro << m_option.prefix << className << "\n" << "{\n" << "public:\n"; const QStringList connections = m_uic->databaseInfo()->connections(); for (int i=0; i<connections.size(); ++i) { const QString connection = connections.at(i); if (connection == QLatin1String("(default)")) continue; m_output << m_option.indent << "QSqlDatabase " << connection << "Connection;\n"; } TreeWalker::acceptWidget(node->elementWidget()); m_output << "\n"; WriteInitialization(m_uic, m_activateScripts).acceptUI(node); if (node->elementImages()) { if (m_option.extractImages) { ExtractImages(m_uic->option()).acceptUI(node); } else { m_output << "\n" << "protected:\n" << m_option.indent << "enum IconID\n" << m_option.indent << "{\n"; WriteIconDeclaration(m_uic).acceptUI(node); m_output << m_option.indent << m_option.indent << "unknown_ID\n" << m_option.indent << "};\n"; WriteIconInitialization(m_uic).acceptUI(node); } } if (m_activateScripts) { m_output << "\nprivate:\n\n"; writeScriptContextClass(m_option.indent, m_output); } m_output << "};\n\n"; closeNameSpaces(namespaceList, m_output); if (namespaceList.count()) m_output << "\n"; if (m_option.generateNamespace && !m_option.prefix.isEmpty()) { namespaceList.append(QLatin1String("Ui")); openNameSpaces(namespaceList, m_output); m_output << m_option.indent << "class " << exportMacro << className << ": public " << m_option.prefix << className << " {};\n"; closeNameSpaces(namespaceList, m_output); if (namespaceList.count()) m_output << "\n"; } }