Core::BaseFileWizard *CustomWidgetWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const { CustomWidgetWizardDialog *rc = new CustomWidgetWizardDialog(this, displayName(), icon(), parent, parameters); rc->setProjectName(CustomWidgetWizardDialog::uniqueProjectName(parameters.defaultPath())); rc->setFileNamingParameters(FileNamingParameters(headerSuffix(), sourceSuffix(), QtWizard::lowerCaseFiles())); return rc; }
QWizard *CustomWidgetWizard::createWizardDialog(QWidget *parent, const QString &defaultPath, const WizardPageList &extensionPages) const { CustomWidgetWizardDialog *rc = new CustomWidgetWizardDialog(displayName(), icon(), extensionPages, parent); rc->setPath(defaultPath); rc->setProjectName(CustomWidgetWizardDialog::uniqueProjectName(defaultPath)); rc->setFileNamingParameters(FileNamingParameters(headerSuffix(), sourceSuffix(), QtWizard::lowerCaseFiles())); return rc; }
QWizard *GuiAppWizard::createWizardDialog(QWidget *parent, const QString &defaultPath, const WizardPageList &extensionPages) const { GuiAppWizardDialog *dialog = new GuiAppWizardDialog(name(), icon(), extensionPages, parent); dialog->setPath(defaultPath.isEmpty() ? Core::Utils::PathChooser::homePath() : defaultPath); // Order! suffixes first to generate files correctly dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix()); dialog->setBaseClasses(baseClasses()); return dialog; }
QWizard *GuiAppWizard::createWizardDialog(QWidget *parent, const QString &defaultPath, const WizardPageList &extensionPages) const { GuiAppWizardDialog *dialog = new GuiAppWizardDialog(displayName(), icon(), extensionPages, showModulesPageForApplications(), m_createMobileProject, parent); dialog->setPath(defaultPath); dialog->setProjectName(GuiAppWizardDialog::uniqueProjectName(defaultPath)); // Order! suffixes first to generate files correctly dialog->setLowerCaseFiles(QtWizard::lowerCaseFiles()); dialog->setSuffixes(headerSuffix(), sourceSuffix(), formSuffix()); dialog->setBaseClasses(baseClasses()); return dialog; }
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const { const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w); const Designer::FormClassWizardParameters params = wizardDialog->parameters(); if (params.uiTemplate().isEmpty()) { *errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents"); return Core::GeneratedFiles(); } // header const QString formFileName = buildFileName(params.path(), params.uiFile(), formSuffix()); const QString headerFileName = buildFileName(params.path(), params.headerFile(), headerSuffix()); const QString sourceFileName = buildFileName(params.path(), params.sourceFile(), sourceSuffix()); Core::GeneratedFile headerFile(headerFileName); headerFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND)); // Source Core::GeneratedFile sourceFile(sourceFileName); sourceFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND)); // UI Core::GeneratedFile uiFile(formFileName); uiFile.setContents(params.uiTemplate()); uiFile.setEditorKind(QLatin1String(Constants::C_FORMEDITOR)); QString source, header; Designer::FormClassWizardGenerationParameters generationParameters; generationParameters.fromSettings(Core::ICore::instance()->settings()); params.generateCpp(generationParameters, &header, &source); sourceFile.setContents(source); headerFile.setContents(header); if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << '\n' << header << '\n' << source; return Core::GeneratedFiles() << headerFile << sourceFile << uiFile; }
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const { const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w); const Designer::FormClassWizardParameters params = wizardDialog->parameters(); if (params.uiTemplate.isEmpty()) { *errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents"); return Core::GeneratedFiles(); } // header const QString formFileName = buildFileName(params.path, params.uiFile, formSuffix()); const QString headerFileName = buildFileName(params.path, params.headerFile, headerSuffix()); const QString sourceFileName = buildFileName(params.path, params.sourceFile, sourceSuffix()); Core::GeneratedFile headerFile(headerFileName); headerFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute); // Source Core::GeneratedFile sourceFile(sourceFileName); sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute); // UI Core::GeneratedFile uiFile(formFileName); uiFile.setContents(params.uiTemplate); uiFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute); QString source, header; QtDesignerFormClassCodeGenerator::generateCpp(params, &header, &source); sourceFile.setContents(source); headerFile.setContents(header); if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << '\n' << header << '\n' << source; return Core::GeneratedFiles() << headerFile << sourceFile << uiFile; }
Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, QString *errorMessage) const { Q_UNUSED(errorMessage) const LibraryWizardDialog *dialog = qobject_cast<const LibraryWizardDialog *>(w); const QtProjectParameters projectParams = dialog->parameters(); const QString projectPath = projectParams.projectPath(); const LibraryParameters params = dialog->libraryParameters(); const QString sharedLibExportMacro = QtProjectParameters::exportMacro(projectParams.fileName); Core::GeneratedFiles rc; // Class header + source const QString sourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix()); Core::GeneratedFile source(sourceFileName); source.setAttributes(Core::GeneratedFile::OpenEditorAttribute); const QString headerFileFullName = buildFileName(projectPath, params.headerFileName, headerSuffix()); const QString headerFileName = Utils::FileName::fromString(headerFileFullName).fileName(); QString pluginJsonFileFullName; QString pluginJsonFileName; if (projectParams.type == QtProjectParameters::Qt4Plugin) { pluginJsonFileFullName = buildFileName(projectPath, projectParams.fileName, QLatin1String("json")); pluginJsonFileName = Utils::FileName::fromString(pluginJsonFileFullName).fileName(); } Core::GeneratedFile header(headerFileFullName); // Create files: global header for shared libs QString globalHeaderFileName; if (projectParams.type == QtProjectParameters::SharedLibrary) { const QString globalHeaderName = buildFileName(projectPath, projectParams.fileName.toLower() + QLatin1String(sharedHeaderPostfixC), headerSuffix()); Core::GeneratedFile globalHeader(globalHeaderName); globalHeaderFileName = Utils::FileName::fromString(globalHeader.path()).fileName(); globalHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(globalHeaderFileName) + LibraryParameters::generateSharedHeader(globalHeaderFileName, projectParams.fileName, sharedLibExportMacro)); rc.push_back(globalHeader); } // Generate code QString headerContents, sourceContents; params.generateCode(projectParams.type, projectParams.fileName, headerFileName, globalHeaderFileName, sharedLibExportMacro, pluginJsonFileName, /* indentation*/ 4, &headerContents, &sourceContents); source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName, params.className) + sourceContents); header.setContents(CppTools::AbstractEditorSupport::licenseTemplate(headerFileFullName, params.className) + headerContents); rc.push_back(source); rc.push_back(header); // Create files: profile const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix()); Core::GeneratedFile profile(profileName); profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute); QString profileContents; { QTextStream proStr(&profileContents); QtProjectParameters::writeProFileHeader(proStr); projectParams.writeProFile(proStr); proStr << "\nSOURCES += " << Utils::FileName::fromString(source.path()).fileName() << "\n\nHEADERS += " << headerFileName; if (!globalHeaderFileName.isEmpty()) proStr << "\\\n " << globalHeaderFileName << '\n'; if (!pluginJsonFileName.isEmpty()) proStr << "\nDISTFILES += " << pluginJsonFileName << '\n'; writeLinuxProFile(proStr); } profile.setContents(profileContents); rc.push_back(profile); if (!pluginJsonFileName.isEmpty()) { Core::GeneratedFile jsonFile(pluginJsonFileFullName); jsonFile.setContents(QLatin1String("{\n \"Keys\" : [ ]\n}\n")); rc.push_back(jsonFile); } return rc; }
Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w, QString *errorMessage) const { const GuiAppWizardDialog *dialog = qobject_cast<const GuiAppWizardDialog *>(w); const QtProjectParameters projectParams = dialog->projectParameters(); const QString projectPath = projectParams.projectPath(); const GuiAppParameters params = dialog->parameters(); const QString license = CppTools::AbstractEditorSupport::licenseTemplate(); // Generate file names. Note that the path for the project files is the // newly generated project directory. const QString templatePath = templateDir(); // Create files: main source QString contents; const QString mainSourceFileName = buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix()); Core::GeneratedFile mainSource(mainSourceFileName); if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage)) return Core::GeneratedFiles(); mainSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(mainSourceFileName) + contents); // Create files: form source with or without form const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix()); const QString formHeaderName = buildFileName(projectPath, params.headerFileName, headerSuffix()); Core::GeneratedFile formSource(formSourceFileName); Core::GeneratedFile formHeader(formHeaderName); formSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute); QSharedPointer<Core::GeneratedFile> form; if (params.designerForm) { // Create files: form const QString formName = buildFileName(projectPath, params.formFileName, formSuffix()); form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName)); if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage)) return Core::GeneratedFiles(); form->setContents(contents); if (!generateFormClass(params, *form, &formSource, &formHeader, errorMessage)) return Core::GeneratedFiles(); } else { const QString formSourceTemplate = QLatin1String("mywidget.cpp"); if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage)) return Core::GeneratedFiles(); formSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(formSourceFileName) + contents); // Create files: form header const QString formHeaderTemplate = QLatin1String("mywidget.h"); if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage)) return Core::GeneratedFiles(); formHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(formHeaderName) + contents); } // Create files: profile const QString profileName = buildFileName(projectPath, projectParams.fileName, profileSuffix()); Core::GeneratedFile profile(profileName); profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute); contents.clear(); { QTextStream proStr(&contents); QtProjectParameters::writeProFileHeader(proStr); projectParams.writeProFile(proStr); proStr << "\n\nSOURCES += " << QFileInfo(mainSourceFileName).fileName() << "\\\n " << QFileInfo(formSource.path()).fileName() << "\n\nHEADERS += " << QFileInfo(formHeader.path()).fileName(); if (params.designerForm) proStr << "\n\nFORMS += " << QFileInfo(form->path()).fileName(); if (params.isMobileApplication) { // Generate a development Symbian UID for the application: QString uid3String = QLatin1String("0xe") + QUuid::createUuid().toString().mid(1, 7); proStr << "\n\nCONFIG += mobility" << "\nMOBILITY = " << "\n\nsymbian {" << "\n TARGET.UID3 = " << uid3String << "\n # TARGET.CAPABILITY += " << "\n TARGET.EPOCSTACKSIZE = 0x14000" << "\n TARGET.EPOCHEAPSIZE = 0x020000 0x800000" << "\n}"; } proStr << '\n'; } profile.setContents(contents); // List Core::GeneratedFiles rc; rc << mainSource << formSource << formHeader; if (params.designerForm) rc << *form; rc << profile; return rc; }
Core::GeneratedFiles GuiAppWizard::generateFiles(const QWizard *w, QString *errorMessage) const { const GuiAppWizardDialog *dialog = qobject_cast<const GuiAppWizardDialog *>(w); const QtProjectParameters projectParams = dialog->projectParameters(); const QString projectPath = projectParams.projectPath(); const GuiAppParameters params = dialog->parameters(); // Generate file names. Note that the path for the project files is the // newly generated project directory. const QString templatePath = templateDir(); // Create files: main source QString contents; const QString mainSourceFileName = buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix()); Core::GeneratedFile mainSource(mainSourceFileName); if (!parametrizeTemplate(templatePath, QLatin1String("main.cpp"), params, &contents, errorMessage)) return Core::GeneratedFiles(); mainSource.setContents(contents); // Create files: form source const QString formSourceTemplate = params.designerForm ? QLatin1String("mywidget_form.cpp") : QLatin1String("mywidget.cpp"); const QString formSourceFileName = buildFileName(projectPath, params.sourceFileName, sourceSuffix()); Core::GeneratedFile formSource(formSourceFileName); if (!parametrizeTemplate(templatePath, formSourceTemplate, params, &contents, errorMessage)) return Core::GeneratedFiles(); formSource.setContents(contents); // Create files: form header const QString formHeaderName = buildFileName(projectPath, params.headerFileName, headerSuffix()); const QString formHeaderTemplate = params.designerForm ? QLatin1String("mywidget_form.h") : QLatin1String("mywidget.h"); Core::GeneratedFile formHeader(formHeaderName); if (!parametrizeTemplate(templatePath, formHeaderTemplate, params, &contents, errorMessage)) return Core::GeneratedFiles(); formHeader.setContents(contents); // Create files: form QSharedPointer<Core::GeneratedFile> form; if (params.designerForm) { const QString formName = buildFileName(projectPath, params.formFileName, formSuffix()); form = QSharedPointer<Core::GeneratedFile>(new Core::GeneratedFile(formName)); if (!parametrizeTemplate(templatePath, QLatin1String("widget.ui"), params, &contents, errorMessage)) return Core::GeneratedFiles(); form->setContents(contents); } // Create files: profile const QString profileName = buildFileName(projectPath, projectParams.name, profileSuffix()); Core::GeneratedFile profile(profileName); contents.clear(); { QTextStream proStr(&contents); QtProjectParameters::writeProFileHeader(proStr); projectParams.writeProFile(proStr); proStr << "\n\nSOURCES += " << QFileInfo(mainSourceFileName).fileName() << "\\\n " << QFileInfo(formSource.path()).fileName() << "\n\nHEADERS += " << QFileInfo(formHeader.path()).fileName(); if (params.designerForm) proStr << "\n\nFORMS += " << QFileInfo(form->path()).fileName(); proStr << '\n'; } profile.setContents(contents); // List Core::GeneratedFiles rc; rc << mainSource << formSource << formHeader; if (params.designerForm) rc << *form; rc << profile; return rc; }