diff --git a/src/plugins/coreplugin/basefilewizardfactory.cpp b/src/plugins/coreplugin/basefilewizardfactory.cpp index 9939b769801..ce9807f6076 100644 --- a/src/plugins/coreplugin/basefilewizardfactory.cpp +++ b/src/plugins/coreplugin/basefilewizardfactory.cpp @@ -27,11 +27,11 @@ using namespace Utils; namespace Core { -static int indexOfFile(const GeneratedFiles &f, const QString &path) +static int indexOfFile(const GeneratedFiles &f, const FilePath &path) { const int size = f.size(); for (int i = 0; i < size; ++i) - if (f.at(i).path() == path) + if (f.at(i).filePath() == path) return i; return -1; } @@ -166,9 +166,10 @@ bool BaseFileWizardFactory::postGenerateOpenEditors(const GeneratedFiles &l, QSt { for (const GeneratedFile &file : qAsConst(l)) { if (file.attributes() & GeneratedFile::OpenEditorAttribute) { - if (!EditorManager::openEditor(FilePath::fromString(file.path()), file.editorId())) { + if (!EditorManager::openEditor(file.filePath(), file.editorId())) { if (errorMessage) - *errorMessage = tr("Failed to open an editor for \"%1\".").arg(QDir::toNativeSeparators(file.path())); + *errorMessage = tr("Failed to open an editor for \"%1\"."). + arg(file.filePath().toUserOutput()); return false; } } @@ -197,9 +198,9 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge static const QString symLinkMsg = tr("[symbolic link]"); for (const GeneratedFile &file : qAsConst(*files)) { - const QString path = file.path(); - if (QFileInfo::exists(path)) - existingFiles.append(path); + const FilePath path = file.filePath(); + if (path.exists()) + existingFiles.append(path.toString()); } if (existingFiles.isEmpty()) return OverwriteOk; @@ -244,7 +245,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge overwriteDialog.setFiles(existingFiles); for (const GeneratedFile &file : qAsConst(*files)) if (file.attributes() & GeneratedFile::CustomGeneratorAttribute) - overwriteDialog.setFileEnabled(file.path(), false); + overwriteDialog.setFileEnabled(file.filePath().toString(), false); if (overwriteDialog.exec() != QDialog::Accepted) return OverwriteCanceled; const QStringList existingFilesToKeep = overwriteDialog.uncheckedFiles(); @@ -252,7 +253,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge return OverwriteCanceled; // Set 'keep' attribute in files for (const QString &keepFile : qAsConst(existingFilesToKeep)) { - const int i = indexOfFile(*files, keepFile); + const int i = indexOfFile(*files, FilePath::fromString(keepFile).cleanPath()); QTC_ASSERT(i != -1, return OverwriteCanceled); GeneratedFile &file = (*files)[i]; file.setAttributes(file.attributes() | GeneratedFile::KeepExistingFileAttribute); diff --git a/src/plugins/coreplugin/dialogs/promptoverwritedialog.h b/src/plugins/coreplugin/dialogs/promptoverwritedialog.h index 2c2492ce386..eff25e770bb 100644 --- a/src/plugins/coreplugin/dialogs/promptoverwritedialog.h +++ b/src/plugins/coreplugin/dialogs/promptoverwritedialog.h @@ -16,6 +16,8 @@ QT_END_NAMESPACE namespace Core { +// TODO: Port to Utils::FilePaths + // Documentation inside. class CORE_EXPORT PromptOverwriteDialog : public QDialog { diff --git a/src/plugins/coreplugin/generatedfile.cpp b/src/plugins/coreplugin/generatedfile.cpp index 3bf3016d96a..bf8277f5def 100644 --- a/src/plugins/coreplugin/generatedfile.cpp +++ b/src/plugins/coreplugin/generatedfile.cpp @@ -96,22 +96,11 @@ GeneratedFile &GeneratedFile::operator=(const GeneratedFile &rhs) GeneratedFile::~GeneratedFile() = default; -QString GeneratedFile::path() const -{ - return m_d->path.toString(); -} - FilePath GeneratedFile::filePath() const { return m_d->path; } -void GeneratedFile::setPath(const QString &p) -{ - m_d->path = Utils::FilePath::fromString(p).cleanPath(); -} - - void GeneratedFile::setFilePath(const Utils::FilePath &p) { m_d->path = p; diff --git a/src/plugins/coreplugin/generatedfile.h b/src/plugins/coreplugin/generatedfile.h index de25bc51059..09c7590922b 100644 --- a/src/plugins/coreplugin/generatedfile.h +++ b/src/plugins/coreplugin/generatedfile.h @@ -42,8 +42,6 @@ public: ~GeneratedFile(); // Full path of the file should be created, or the suggested file name - QString path() const; - void setPath(const QString &p); void setFilePath(const Utils::FilePath &p); Utils::FilePath filePath() const; diff --git a/src/plugins/projectexplorer/baseprojectwizarddialog.cpp b/src/plugins/projectexplorer/baseprojectwizarddialog.cpp index c2e80e4f5d9..31b12a750b8 100644 --- a/src/plugins/projectexplorer/baseprojectwizarddialog.cpp +++ b/src/plugins/projectexplorer/baseprojectwizarddialog.cpp @@ -126,7 +126,7 @@ void BaseProjectWizardDialog::slotAccepted() bool BaseProjectWizardDialog::validateCurrentPage() { if (currentId() == d->introPageId) - emit projectParametersChanged(d->introPage->projectName(), d->introPage->filePath().toString()); + emit projectParametersChanged(d->introPage->projectName(), d->introPage->filePath()); return Core::BaseFileWizard::validateCurrentPage(); } diff --git a/src/plugins/projectexplorer/baseprojectwizarddialog.h b/src/plugins/projectexplorer/baseprojectwizarddialog.h index c8681032d04..2a739fdf0d7 100644 --- a/src/plugins/projectexplorer/baseprojectwizarddialog.h +++ b/src/plugins/projectexplorer/baseprojectwizarddialog.h @@ -49,7 +49,7 @@ public: void setForceSubProject(bool force); signals: - void projectParametersChanged(const QString &projectName, const QString &path); + void projectParametersChanged(const QString &projectName, const Utils::FilePath &path); protected: Utils::ProjectIntroPage *introPage() const; diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp index bae444550a7..d929ad8266b 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp @@ -183,7 +183,7 @@ static bool createFile(CustomWizardFile cwFile, return false; GeneratedFile generatedFile; - generatedFile.setPath(targetPath); + generatedFile.setFilePath(FilePath::fromString(targetPath).cleanPath()); if (cwFile.binary) { // Binary file: Set data. generatedFile.setBinary(true); @@ -279,9 +279,10 @@ bool CustomWizard::writeFiles(const GeneratedFiles &files, QString *errorMessage // Paranoia: Check on the files generated by the script: for (const GeneratedFile &generatedFile : files) { if (generatedFile.attributes() & GeneratedFile::CustomGeneratorAttribute) - if (!QFileInfo(generatedFile.path()).isFile()) { + if (!generatedFile.filePath().isFile()) { *errorMessage = QString::fromLatin1("%1 failed to generate %2"). - arg(d->m_parameters->filesGeneratorScript.back(), generatedFile.path()); + arg(d->m_parameters->filesGeneratorScript.back()). + arg(generatedFile.filePath().toString()); return false; } } @@ -511,7 +512,7 @@ void CustomProjectWizard::initProjectWizardDialog(BaseProjectWizardDialog *w, w->setProjectName(BaseProjectWizardDialog::uniqueProjectName(defaultPath)); connect(w, &BaseProjectWizardDialog::projectParametersChanged, - this, &CustomProjectWizard::projectParametersChanged); + this, &CustomProjectWizard::handleProjectParametersChanged); if (CustomWizardPrivate::verbose) qDebug() << "initProjectWizardDialog" << w << w->pageIds(); @@ -563,12 +564,13 @@ bool CustomProjectWizard::postGenerateFiles(const QWizard *, const GeneratedFile return CustomProjectWizard::postGenerateOpen(l, errorMessage); } -void CustomProjectWizard::projectParametersChanged(const QString &project, const QString & path) +void CustomProjectWizard::handleProjectParametersChanged(const QString &name, + const Utils::FilePath &path) { // Make '%ProjectName%' available in base replacements. - context()->baseReplacements.insert(QLatin1String("ProjectName"), project); + context()->baseReplacements.insert(QLatin1String("ProjectName"), name); - emit projectLocationChanged(path + QLatin1Char('/') + project); + emit projectLocationChanged(path / name); } } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/customwizard/customwizard.h b/src/plugins/projectexplorer/customwizard/customwizard.h index 8caeaa73e37..64078d92b4e 100644 --- a/src/plugins/projectexplorer/customwizard/customwizard.h +++ b/src/plugins/projectexplorer/customwizard/customwizard.h @@ -110,7 +110,7 @@ public: static bool postGenerateOpen(const Core::GeneratedFiles &l, QString *errorMessage = nullptr); signals: - void projectLocationChanged(const QString &path); + void projectLocationChanged(const Utils::FilePath &path); protected: Core::BaseFileWizard *create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const override; @@ -123,7 +123,7 @@ protected: const QList &extensionPages) const; private: - void projectParametersChanged(const QString &project, const QString &path); + void handleProjectParametersChanged(const QString &project, const Utils::FilePath &path); }; } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp index 3d2a3736a55..3e92ccd1c4c 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardscriptgenerator.cpp @@ -157,7 +157,7 @@ Core::GeneratedFiles fileInfo.isAbsolute() ? token : (targetPath + QLatin1Char('/') + token); - file.setPath(fullPath); + file.setFilePath(FilePath::fromString(fullPath).cleanPath()); } } file.setAttributes(attributes); @@ -168,7 +168,7 @@ Core::GeneratedFiles QDebug nospace = qDebug().nospace(); nospace << script << " generated:\n"; for (const Core::GeneratedFile &f : qAsConst(files)) - nospace << ' ' << f.path() << f.attributes() << '\n'; + nospace << ' ' << f.filePath() << f.attributes() << '\n'; } return files; } diff --git a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp index 7eb1ebead58..701a3df4a87 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonsummarypage.cpp @@ -223,8 +223,9 @@ Node *JsonSummaryPage::findWizardContextNode(Node *contextNode) const void JsonSummaryPage::updateFileList() { m_fileList = m_wizard->generateFileList(); - QStringList filePaths - = Utils::transform(m_fileList, [](const JsonWizard::GeneratorFile &f) { return f.file.path(); }); + const FilePaths filePaths = + Utils::transform(m_fileList, + [](const JsonWizard::GeneratorFile &f) { return f.file.filePath(); }); setFiles(filePaths); } diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index 89fa5aed0c0..7ce7802bda6 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -58,7 +58,7 @@ private: { if (column != 0 || role != Qt::DisplayRole) return QVariant(); - return QDir::toNativeSeparators(m_candidate->file.path()); + return m_candidate->file.filePath().toUserOutput(); } JsonWizard::GeneratorFile * const m_candidate; @@ -167,15 +167,18 @@ JsonWizard::GeneratorFiles JsonWizard::generateFileList() QString errorMessage; GeneratorFiles list; - QString targetPath = stringValue(QLatin1String("TargetPath")); + const Utils::FilePath targetPath = + Utils::FilePath::fromString(stringValue(QLatin1String("TargetPath"))); if (targetPath.isEmpty()) errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page."); if (m_files.isEmpty() && errorMessage.isEmpty()) { emit preGenerateFiles(); for (JsonWizardGenerator *gen : qAsConst(m_generators)) { - Core::GeneratedFiles tmp = gen->fileList(&m_expander, stringValue(QStringLiteral("WizardDir")), - targetPath, &errorMessage); + const Utils::FilePath wizardDir = + Utils::FilePath::fromString(stringValue(QLatin1String("WizardDir"))); + const Core::GeneratedFiles tmp = + gen->fileList(&m_expander, wizardDir, targetPath, &errorMessage); if (!errorMessage.isEmpty()) break; list.append(Utils::transform(tmp, [&gen](const Core::GeneratedFile &f) @@ -423,7 +426,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files) bool openedSomething = false; for (const JsonWizard::GeneratorFile &f : files) { const Core::GeneratedFile &file = f.file; - if (!QFileInfo::exists(file.path())) { + if (!file.filePath().exists()) { errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "\"%1\" does not exist in the file system.") .arg(file.filePath().toUserOutput()); @@ -445,8 +448,7 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files) openedSomething = true; } if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) { - Core::IEditor *editor = Core::EditorManager::openEditor(Utils::FilePath::fromString( - file.path()), + Core::IEditor *editor = Core::EditorManager::openEditor(file.filePath(), file.editorId()); if (!editor) { errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp index 6cb8acb2ca8..9abd8e78ce5 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.cpp @@ -41,8 +41,8 @@ bool JsonWizardFileGenerator::setup(const QVariant &data, QString *errorMessage) File f; const QVariantMap tmp = d.toMap(); - f.source = tmp.value(QLatin1String("source")).toString(); - f.target = tmp.value(QLatin1String("target")).toString(); + f.source = Utils::FilePath::fromVariant(tmp.value(QLatin1String("source"))); + f.target = Utils::FilePath::fromVariant(tmp.value(QLatin1String("target"))); f.condition = tmp.value(QLatin1String("condition"), true); f.isBinary = tmp.value(QLatin1String("isBinary"), false); f.overwrite = tmp.value(QLatin1String("overwrite"), false); @@ -77,12 +77,12 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file, QIODevice::ReadOnly : (QIODevice::ReadOnly|QIODevice::Text); Utils::FileReader reader; - if (!reader.fetch(Utils::FilePath::fromString(file.source), openMode, errorMessage)) + if (!reader.fetch(file.source, openMode, errorMessage)) return Core::GeneratedFile(); // Generate file information: Core::GeneratedFile gf; - gf.setPath(file.target); + gf.setFilePath(file.target); if (!file.keepExisting) { if (file.isBinary.toBool()) { @@ -114,7 +114,7 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file, errorMessage)); if (!errorMessage->isEmpty()) { *errorMessage = QCoreApplication::translate("ProjectExplorer::JsonWizard", "When processing \"%1\":
%2") - .arg(file.source, *errorMessage); + .arg(file.source.toUserOutput(), *errorMessage); return Core::GeneratedFile(); } } @@ -138,14 +138,11 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file, } Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *expander, - const QString &wizardDir, const QString &projectDir, + const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir, QString *errorMessage) { errorMessage->clear(); - QDir wizard(wizardDir); - QDir project(projectDir); - const QList enabledFiles = Utils::filtered(m_fileList, [&expander](const File &f) { return JsonWizard::boolFromVariant(f.condition, expander); @@ -153,14 +150,15 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp const QList concreteFiles = Utils::transform(enabledFiles, - [&expander, &wizard, &project](const File &f) -> File { + [&expander, &wizardDir, &projectDir](const File &f) -> File { // Return a new file with concrete values based on input file: File file = f; file.keepExisting = file.source.isEmpty(); - file.target = project.absoluteFilePath(expander->expand(file.target)); - file.source = file.keepExisting ? file.target : wizard.absoluteFilePath( - expander->expand(file.source)); + file.target = projectDir / expander->expand(file.target.toString()); + file.source = file.keepExisting + ? file.target + : wizardDir / expander->expand(file.source.toString()); file.isBinary = JsonWizard::boolFromVariant(file.isBinary, expander); return file; @@ -169,18 +167,18 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp QList fileList; QList dirList; std::tie(fileList, dirList) - = Utils::partition(concreteFiles, [](const File &f) { return !QFileInfo(f.source).isDir(); }); + = Utils::partition(concreteFiles, [](const File &f) { return !f.source.isDir(); }); - const QSet knownFiles = Utils::transform(fileList, &File::target); + const QSet knownFiles = Utils::transform(fileList, &File::target); for (const File &dir : qAsConst(dirList)) { - QDir sourceDir(dir.source); - QDirIterator it(dir.source, QDir::NoDotAndDotDot | QDir::Files| QDir::Hidden, - QDirIterator::Subdirectories); + Utils::FilePath sourceDir(dir.source); + const Utils::FilePaths entries = + sourceDir.dirEntries(QDir::NoDotAndDotDot | QDir::Files| QDir::Hidden); - while (it.hasNext()) { - const QString relativeFilePath = sourceDir.relativeFilePath(it.next()); - const QString targetPath = dir.target + QLatin1Char('/') + relativeFilePath; + for (const Utils::FilePath &entry : entries) { + const Utils::FilePath relativeFilePath = sourceDir.relativeChildPath(entry); + const Utils::FilePath targetPath = dir.target / relativeFilePath.toString(); if (knownFiles.contains(targetPath)) continue; @@ -188,7 +186,7 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp // initialize each new file with properties (isBinary etc) // from the current directory json entry File newFile = dir; - newFile.source = dir.source + QLatin1Char('/') + relativeFilePath; + newFile.source = dir.source / relativeFilePath.toString(); newFile.target = targetPath; fileList.append(newFile); } @@ -200,7 +198,8 @@ Core::GeneratedFiles JsonWizardFileGenerator::fileList(Utils::MacroExpander *exp return generateFile(f, expander, errorMessage); }); - if (Utils::contains(result, [](const Core::GeneratedFile &gf) { return gf.path().isEmpty(); })) + if (Utils::contains(result, + [](const Core::GeneratedFile &gf) { return gf.filePath().isEmpty(); })) return Core::GeneratedFiles(); return result; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h index cdbc4c56f48..fc843a085b8 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardfilegenerator.h @@ -17,7 +17,7 @@ public: bool setup(const QVariant &data, QString *errorMessage); Core::GeneratedFiles fileList(Utils::MacroExpander *expander, - const QString &wizardDir, const QString &projectDir, + const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir, QString *errorMessage) override; bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage) override; @@ -26,8 +26,8 @@ private: class File { public: bool keepExisting = false; - QString source; - QString target; + Utils::FilePath source; + Utils::FilePath target; QVariant condition = true; QVariant isBinary = false; QVariant overwrite = false; diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp index 7cbd2a93e97..719c5790234 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp @@ -140,11 +140,10 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso bool oddStuffFound = false; for (const JsonWizard::GeneratorFile &f : qAsConst(*files)) { - const QFileInfo fi(f.file.path()); - if (fi.exists() + if (f.file.filePath().exists() && !(f.file.attributes() & GeneratedFile::ForceOverwrite) && !(f.file.attributes() & GeneratedFile::KeepExistingFileAttribute)) - existingFiles.append(f.file.path()); + existingFiles.append(f.file.filePath().toString()); } if (existingFiles.isEmpty()) return OverwriteOk; @@ -190,7 +189,7 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso overwriteDialog.setFiles(existingFiles); for (const JsonWizard::GeneratorFile &file : qAsConst(*files)) if (!file.generator->canKeepExistingFiles()) - overwriteDialog.setFileEnabled(file.file.path(), false); + overwriteDialog.setFileEnabled(file.file.filePath().toString(), false); if (overwriteDialog.exec() != QDialog::Accepted) return OverwriteCanceled; @@ -200,7 +199,7 @@ JsonWizardGenerator::OverwriteResult JsonWizardGenerator::promptForOverwrite(Jso // Set 'keep' attribute in files for (JsonWizard::GeneratorFile &file : *files) { - if (!existingFilesToKeep.contains(file.file.path())) + if (!existingFilesToKeep.contains(file.file.filePath().toString())) continue; file.file.setAttributes(file.file.attributes() | GeneratedFile::KeepExistingFileAttribute); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h index 4f44e2bb245..e677f6bc706 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.h @@ -22,7 +22,7 @@ public: virtual ~JsonWizardGenerator() = default; virtual Core::GeneratedFiles fileList(Utils::MacroExpander *expander, - const QString &baseDir, const QString &projectDir, + const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir, QString *errorMessage) = 0; virtual bool formatFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); virtual bool writeFile(const JsonWizard *wizard, Core::GeneratedFile *file, QString *errorMessage); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp index 57fb260e0d1..ef1a8c0b8e2 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.cpp @@ -51,14 +51,13 @@ bool JsonWizardScannerGenerator::setup(const QVariant &data, QString *errorMessa } Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander *expander, - const QString &wizardDir, - const QString &projectDir, + const Utils::FilePath &wizardDir, + const Utils::FilePath &projectDir, QString *errorMessage) { Q_UNUSED(wizardDir) errorMessage->clear(); - QDir project(projectDir); Core::GeneratedFiles result; QRegularExpression binaryPattern; @@ -72,18 +71,18 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander * } } - result = scan(project.absolutePath(), project); + result = scan(projectDir, projectDir); - static const auto getDepth = [](const QString &filePath) { return int(filePath.count('/')); }; + static const auto getDepth = + [](const Utils::FilePath &filePath) { return int(filePath.path().count('/')); }; int minDepth = std::numeric_limits::max(); for (auto it = result.begin(); it != result.end(); ++it) { - const QString relPath = project.relativeFilePath(it->path()); - it->setBinary(binaryPattern.match(relPath).hasMatch()); - bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile( - Utils::FilePath::fromString(relPath))); + const Utils::FilePath relPath = projectDir.relativePath(it->filePath()); + it->setBinary(binaryPattern.match(relPath.toString()).hasMatch()); + bool found = ProjectManager::canOpenProjectForMimeType(Utils::mimeTypeForFile(relPath)); if (found) { it->setAttributes(it->attributes() | Core::GeneratedFile::OpenProjectAttribute); - minDepth = std::min(minDepth, getDepth(it->path())); + minDepth = std::min(minDepth, getDepth(it->filePath())); } } @@ -91,7 +90,7 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander * // other project files are not candidates for opening. for (Core::GeneratedFile &f : result) { if (f.attributes().testFlag(Core::GeneratedFile::OpenProjectAttribute) - && getDepth(f.path()) > minDepth) { + && getDepth(f.filePath()) > minDepth) { f.setAttributes(f.attributes().setFlag(Core::GeneratedFile::OpenProjectAttribute, false)); } @@ -100,31 +99,31 @@ Core::GeneratedFiles JsonWizardScannerGenerator::fileList(Utils::MacroExpander * return result; } -bool JsonWizardScannerGenerator::matchesSubdirectoryPattern(const QString &path) +bool JsonWizardScannerGenerator::matchesSubdirectoryPattern(const Utils::FilePath &path) { for (const QRegularExpression ®exp : qAsConst(m_subDirectoryExpressions)) { - if (regexp.match(path).hasMatch()) + if (regexp.match(path.path()).hasMatch()) return true; } return false; } -Core::GeneratedFiles JsonWizardScannerGenerator::scan(const QString &dir, const QDir &base) +Core::GeneratedFiles JsonWizardScannerGenerator::scan(const Utils::FilePath &dir, + const Utils::FilePath &base) { Core::GeneratedFiles result; - QDir directory(dir); - if (!directory.exists()) + if (!dir.exists()) return result; - const QFileInfoList entries = directory.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, - QDir::DirsLast | QDir::Name); - for (const QFileInfo &fi : entries) { - const QString relativePath = base.relativeFilePath(fi.absoluteFilePath()); + const Utils::FilePaths entries = dir.dirEntries({{}, QDir::AllEntries | QDir::NoDotAndDotDot}, + QDir::DirsLast | QDir::Name); + for (const Utils::FilePath &fi : entries) { + const Utils::FilePath relativePath = base.relativePath(fi); if (fi.isDir() && matchesSubdirectoryPattern(relativePath)) { - result += scan(fi.absoluteFilePath(), base); + result += scan(fi, base); } else { - Core::GeneratedFile f(fi.absoluteFilePath()); + Core::GeneratedFile f(fi); f.setAttributes(f.attributes() | Core::GeneratedFile::KeepExistingFileAttribute); result.append(f); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.h b/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.h index 697d63017dd..ab858bc8a52 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.h +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardscannergenerator.h @@ -19,11 +19,11 @@ public: bool setup(const QVariant &data, QString *errorMessage); Core::GeneratedFiles fileList(Utils::MacroExpander *expander, - const QString &wizardDir, const QString &projectDir, + const Utils::FilePath &wizardDir, const Utils::FilePath &projectDir, QString *errorMessage) override; private: - Core::GeneratedFiles scan(const QString &dir, const QDir &base); - bool matchesSubdirectoryPattern(const QString &path); + Core::GeneratedFiles scan(const Utils::FilePath &dir, const Utils::FilePath &base); + bool matchesSubdirectoryPattern(const Utils::FilePath &path); QString m_binaryPattern; QList m_subDirectoryExpressions; diff --git a/src/plugins/projectexplorer/projectfilewizardextension.cpp b/src/plugins/projectexplorer/projectfilewizardextension.cpp index 5307132cb28..d263bb7f9a0 100644 --- a/src/plugins/projectexplorer/projectfilewizardextension.cpp +++ b/src/plugins/projectexplorer/projectfilewizardextension.cpp @@ -97,7 +97,7 @@ void ProjectFileWizardExtension::firstExtensionPageShown( if (debugExtension) qDebug() << Q_FUNC_INFO << files.size(); - QStringList fileNames = Utils::transform(files, &GeneratedFile::path); + const FilePaths fileNames = Utils::transform(files, &GeneratedFile::filePath); m_context->page->setFiles(fileNames); FilePaths filePaths; diff --git a/src/plugins/projectexplorer/projectwizardpage.cpp b/src/plugins/projectexplorer/projectwizardpage.cpp index 4865761e707..4502400865e 100644 --- a/src/plugins/projectexplorer/projectwizardpage.cpp +++ b/src/plugins/projectexplorer/projectwizardpage.cpp @@ -123,14 +123,14 @@ Qt::ItemFlags AddNewTree::flags(int) const class BestNodeSelector { public: - BestNodeSelector(const QString &commonDirectory, const FilePaths &files); + BestNodeSelector(const FilePath &commonDirectory, const FilePaths &files); void inspect(AddNewTree *tree, bool isContextNode); AddNewTree *bestChoice() const; bool deploys(); QString deployingProjects() const; private: - QString m_commonDirectory; + FilePath m_commonDirectory; FilePaths m_files; bool m_deploys = false; QString m_deployText; @@ -139,7 +139,7 @@ private: int m_bestMatchPriority = -1; }; -BestNodeSelector::BestNodeSelector(const QString &commonDirectory, const FilePaths &files) : +BestNodeSelector::BestNodeSelector(const FilePath &commonDirectory, const FilePaths &files) : m_commonDirectory(commonDirectory), m_files(files), m_deployText(QCoreApplication::translate("ProjectWizard", "The files are implicitly added to the projects:") + QLatin1Char('\n')) @@ -154,7 +154,7 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode) { FolderNode *node = tree->node(); if (node->isProjectNodeType()) { - if (static_cast(node)->deploysFolder(m_commonDirectory)) { + if (static_cast(node)->deploysFolder(m_commonDirectory.toString())) { m_deploys = true; m_deployText += tree->displayName() + QLatin1Char('\n'); } @@ -162,10 +162,11 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode) if (m_deploys) return; - const QString projectDirectory = node->directory().toString(); - const int projectDirectorySize = projectDirectory.size(); + const FilePath projectDirectory = node->directory(); + const int projectDirectorySize = projectDirectory.toString().size(); if (m_commonDirectory != projectDirectory - && !m_commonDirectory.startsWith(projectDirectory + QLatin1Char('/')) + && !m_commonDirectory.toString().startsWith( + projectDirectory.toString() + QLatin1Char('/')) // TODO: still required? && !isContextNode) return; @@ -384,7 +385,7 @@ void ProjectWizardPage::initializeVersionControls() QStringList versionControlChoices = QStringList(tr("")); if (!m_commonDirectory.isEmpty()) { IVersionControl *managingControl = - VcsManager::findVersionControlForDirectory(FilePath::fromString(m_commonDirectory)); + VcsManager::findVersionControlForDirectory(m_commonDirectory); if (managingControl) { // Under VCS if (managingControl->supportsOperation(IVersionControl::AddOperation)) { @@ -427,8 +428,10 @@ bool ProjectWizardPage::runVersionControl(const QList &files, QSt // Create repository? if (!m_repositoryExists) { QTC_ASSERT(versionControl->supportsOperation(IVersionControl::CreateRepositoryOperation), return false); - if (!versionControl->vcsCreateRepository(FilePath::fromString(m_commonDirectory))) { - *errorMessage = tr("A version control system repository could not be created in \"%1\".").arg(m_commonDirectory); + if (!versionControl->vcsCreateRepository(m_commonDirectory)) { + *errorMessage = + tr("A version control system repository could not be created in \"%1\"."). + arg(m_commonDirectory.toUserOutput()); return false; } } @@ -436,7 +439,8 @@ bool ProjectWizardPage::runVersionControl(const QList &files, QSt if (versionControl->supportsOperation(IVersionControl::AddOperation)) { for (const GeneratedFile &generatedFile : files) { if (!versionControl->vcsAdd(generatedFile.filePath())) { - *errorMessage = tr("Failed to add \"%1\" to the version control system.").arg(generatedFile.path()); + *errorMessage = tr("Failed to add \"%1\" to the version control system."). + arg(generatedFile.filePath().toUserOutput()); return false; } } @@ -517,12 +521,9 @@ IVersionControl *ProjectWizardPage::currentVersionControl() return m_activeVersionControls.at(index); } -void ProjectWizardPage::setFiles(const QStringList &fileNames) +void ProjectWizardPage::setFiles(const FilePaths &files) { - if (fileNames.count() == 1) - m_commonDirectory = QFileInfo(fileNames.first()).absolutePath(); - else - m_commonDirectory = Utils::commonPath(fileNames); + m_commonDirectory = FileUtils::commonPath(files); QString fileMessage; { QTextStream str(&fileMessage); @@ -532,14 +533,13 @@ void ProjectWizardPage::setFiles(const QStringList &fileNames) QStringList formattedFiles; if (m_commonDirectory.isEmpty()) { - formattedFiles = fileNames; + formattedFiles = Utils::transform(files, &FilePath::toString); } else { - str << QDir::toNativeSeparators(m_commonDirectory) << ":\n\n"; - int prefixSize = m_commonDirectory.size(); - if (!m_commonDirectory.endsWith('/')) - ++prefixSize; - formattedFiles = Utils::transform(fileNames, [prefixSize](const QString &f) - { return f.mid(prefixSize); }); + str << m_commonDirectory.toUserOutput() << ":\n\n"; + int prefixSize = m_commonDirectory.toUserOutput().size(); + formattedFiles = Utils::transform(files, [prefixSize] (const FilePath &f) { + return f.toUserOutput().mid(prefixSize + 1); // +1 skips the initial dir separator + }); } // Alphabetically, and files in sub-directories first Utils::sort(formattedFiles, [](const QString &filePath1, const QString &filePath2) -> bool { @@ -549,8 +549,7 @@ void ProjectWizardPage::setFiles(const QStringList &fileNames) if (filePath1HasDir == filePath2HasDir) return FilePath::fromString(filePath1) < FilePath::fromString(filePath2); return filePath1HasDir; - } -); + }); for (const QString &f : qAsConst(formattedFiles)) str << QDir::toNativeSeparators(f) << '\n'; diff --git a/src/plugins/projectexplorer/projectwizardpage.h b/src/plugins/projectexplorer/projectwizardpage.h index 308f3498f7a..00998cae6ce 100644 --- a/src/plugins/projectexplorer/projectwizardpage.h +++ b/src/plugins/projectexplorer/projectwizardpage.h @@ -44,7 +44,7 @@ public: Core::IVersionControl *currentVersionControl(); // Returns the common path - void setFiles(const QStringList &files); + void setFiles(const Utils::FilePaths &files); bool runVersionControl(const QList &files, QString *errorMessage); @@ -75,7 +75,7 @@ private: Utils::TreeModel<> m_model; QList m_activeVersionControls; - QString m_commonDirectory; + Utils::FilePath m_commonDirectory; bool m_repositoryExists = false; QLabel *m_projectLabel; diff --git a/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp b/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp index 38a958f36d9..588da68ebc4 100644 --- a/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp +++ b/src/plugins/qmakeprojectmanager/customwidgetwizard/plugingenerator.cpp @@ -253,7 +253,7 @@ QList PluginGenerator::generatePlugin(const GenerationPara const Core::GeneratedFile iconFile = generateIconFile(Utils::FilePath::fromFileInfo(qfi), newIcon, errorMessage); - if (iconFile.path().isEmpty()) + if (iconFile.filePath().isEmpty()) return QList(); rc.push_back(iconFile); icon = qfi.fileName(); diff --git a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp index 82efae5d005..a0428f28145 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp +++ b/src/plugins/qmakeprojectmanager/wizards/qtwizard.cpp @@ -70,7 +70,7 @@ bool QtWizard::qt4ProjectPostGenerateFiles(const QWizard *w, // Generate user settings for (const Core::GeneratedFile &file : generatedFiles) if (file.attributes() & Core::GeneratedFile::OpenProjectAttribute) { - dialog->writeUserFile(file.path()); + dialog->writeUserFile(file.filePath()); break; } @@ -181,12 +181,12 @@ int BaseQmakeProjectWizardDialog::addTargetSetupPage(int id) return id; } -bool BaseQmakeProjectWizardDialog::writeUserFile(const QString &proFileName) const +bool BaseQmakeProjectWizardDialog::writeUserFile(const Utils::FilePath &proFile) const { if (!m_targetSetupPage) return false; - QmakeProject *pro = new QmakeProject(Utils::FilePath::fromString(proFileName)); + QmakeProject *pro = new QmakeProject(proFile); bool success = m_targetSetupPage->setupProject(pro); if (success) pro->saveSettings(); @@ -201,14 +201,15 @@ QList BaseQmakeProjectWizardDialog::selectedKits() const return m_targetSetupPage->selectedKits(); } -void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name, const QString &path) +void BaseQmakeProjectWizardDialog::generateProfileName(const QString &name, + const Utils::FilePath &path) { if (!m_targetSetupPage) return; - const QString proFile = QDir::cleanPath(path + '/' + name + '/' + name + ".pro"); + const Utils::FilePath proFile = path / name / name + ".pro"; - m_targetSetupPage->setProjectPath(Utils::FilePath::fromString(proFile)); + m_targetSetupPage->setProjectPath(proFile); } } // Internal diff --git a/src/plugins/qmakeprojectmanager/wizards/qtwizard.h b/src/plugins/qmakeprojectmanager/wizards/qtwizard.h index 8efe5ef0c5e..10810fe8fb5 100644 --- a/src/plugins/qmakeprojectmanager/wizards/qtwizard.h +++ b/src/plugins/qmakeprojectmanager/wizards/qtwizard.h @@ -91,11 +91,11 @@ public: int addTargetSetupPage(int id = -1); - bool writeUserFile(const QString &proFileName) const; + bool writeUserFile(const Utils::FilePath &proFile) const; QList selectedKits() const; private: - void generateProfileName(const QString &name, const QString &path); + void generateProfileName(const QString &name, const Utils::FilePath &path); ProjectExplorer::TargetSetupPage *m_targetSetupPage = nullptr; QList m_profileIds;