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; }
Core::GeneratedFiles ConsoleAppWizard::generateFiles(const QWizard *w, QString * /*errorMessage*/) const { const ConsoleAppWizardDialog *wizard = qobject_cast< const ConsoleAppWizardDialog *>(w); const QtProjectParameters params = wizard->parameters(); const QString projectPath = params.projectPath(); // Create files: Source const QString sourceFileName = Core::BaseFileWizard::buildFileName(projectPath, QLatin1String(mainSourceFileC), sourceSuffix()); Core::GeneratedFile source(sourceFileName); source.setContents(CppTools::AbstractEditorSupport::licenseTemplate(sourceFileName) + QLatin1String(mainCppC)); source.setAttributes(Core::GeneratedFile::OpenEditorAttribute); // Create files: Profile const QString profileName = Core::BaseFileWizard::buildFileName(projectPath, params.fileName, profileSuffix()); Core::GeneratedFile profile(profileName); profile.setAttributes(Core::GeneratedFile::OpenProjectAttribute); QString contents; { QTextStream proStr(&contents); QtProjectParameters::writeProFileHeader(proStr); params.writeProFile(proStr); proStr << "\n\nSOURCES += " << QFileInfo(sourceFileName).fileName() << '\n'; } profile.setContents(contents); return Core::GeneratedFiles() << source << profile; }
Core::GeneratedFiles LibraryWizard::generateFiles(const QWizard *w, QString *errorMessage) const { Q_UNUSED(errorMessage) const auto *dialog = qobject_cast<const LibraryWizardDialog *>(w); const QtProjectParameters projectParams = dialog->parameters(); const QString projectPath = projectParams.projectPath(); const LibraryParameters params = dialog->libraryParameters(); const bool usePragmaOnce = CppTools::AbstractEditorSupport::usePragmaOnce(); 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::QtPlugin) { 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, usePragmaOnce)); rc.push_back(globalHeader); } // Generate code QString headerContents, sourceContents; params.generateCode(projectParams.type, headerFileName, globalHeaderFileName, sharedLibExportMacro, pluginJsonFileName, /* indentation*/ 4, usePragmaOnce, &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 +=" << " \\\n " << Utils::FileName::fromString(source.path()).fileName() << "\n\nHEADERS +=" << " \\\n " << headerFileName; if (!globalHeaderFileName.isEmpty()) proStr << " \\\n " << globalHeaderFileName << " \n"; if (!pluginJsonFileName.isEmpty()) proStr << "\nDISTFILES += " << pluginJsonFileName << " \n"; writeLinuxProFile(proStr, projectParams); } 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; }