forked from qt-creator/qt-creator
FilePath: Remove ::toDir() and deprecation hints
Change-Id: Ib561c019e3fd44cd85504ad4286eb3759ce19516 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -153,7 +153,7 @@ Qt::CaseSensitivity FilePath::caseSensitivity() const
|
||||
// FIXME: This could or possibly should the target device's file name case sensitivity
|
||||
// into account by diverting to IDevice. However, as this is expensive and we are
|
||||
// in time-critical path here, we go with "good enough" for now:
|
||||
// The first approximation is "Anything unusual is not case sensitive"
|
||||
// The first approximation is "most things are case-sensitive".
|
||||
return Qt::CaseSensitive;
|
||||
}
|
||||
|
||||
@@ -387,6 +387,16 @@ FilePath FilePath::fromUrl(const QUrl &url)
|
||||
return fn;
|
||||
}
|
||||
|
||||
FilePath FilePath::currentWorkingPath()
|
||||
{
|
||||
return FilePath::fromString(QDir::currentPath());
|
||||
}
|
||||
|
||||
FilePath FilePath::rootPath()
|
||||
{
|
||||
return FilePath::fromString(QDir::rootPath());
|
||||
}
|
||||
|
||||
static QString hostEncoded(QString host)
|
||||
{
|
||||
host.replace('%', "%25");
|
||||
@@ -839,6 +849,7 @@ FilePath FilePath::parentDir() const
|
||||
if (basePath.isEmpty())
|
||||
return FilePath();
|
||||
|
||||
// TODO: Replace usage of QDir !!
|
||||
const QDir base(basePath);
|
||||
if (base.isRoot())
|
||||
return FilePath();
|
||||
@@ -854,22 +865,16 @@ FilePath FilePath::parentDir() const
|
||||
|
||||
FilePath FilePath::absolutePath() const
|
||||
{
|
||||
if (isAbsolutePath())
|
||||
return parentDir();
|
||||
QTC_ASSERT(!needsDevice(), return *this);
|
||||
FilePath result = *this;
|
||||
result.m_data = QFileInfo(m_data).absolutePath();
|
||||
return result;
|
||||
const FilePath parentPath = isAbsolutePath() ? parentDir() : FilePath::currentWorkingPath().resolvePath(*this).parentDir();
|
||||
return parentPath.isEmpty() ? *this : parentPath;
|
||||
}
|
||||
|
||||
FilePath FilePath::absoluteFilePath() const
|
||||
{
|
||||
if (isAbsolutePath())
|
||||
return *this;
|
||||
QTC_ASSERT(!needsDevice(), return *this);
|
||||
FilePath result = *this;
|
||||
result.m_data = QFileInfo(m_data).absoluteFilePath();
|
||||
return result;
|
||||
|
||||
return FilePath::currentWorkingPath().resolvePath(*this);
|
||||
}
|
||||
|
||||
QString FilePath::specialPath(SpecialPathComponent component)
|
||||
@@ -1102,11 +1107,6 @@ QVariant FilePath::toVariant() const
|
||||
return toString();
|
||||
}
|
||||
|
||||
QDir FilePath::toDir() const
|
||||
{
|
||||
return QDir(m_data);
|
||||
}
|
||||
|
||||
bool FilePath::operator==(const FilePath &other) const
|
||||
{
|
||||
return QString::compare(m_data, other.m_data, caseSensitivity()) == 0
|
||||
|
@@ -79,6 +79,10 @@ public:
|
||||
[[nodiscard]] static FilePath fromVariant(const QVariant &variant);
|
||||
[[nodiscard]] static FilePath fromUrl(const QUrl &url);
|
||||
|
||||
[[nodiscard]] static FilePath currentWorkingPath();
|
||||
[[nodiscard]] static FilePath rootPath();
|
||||
|
||||
|
||||
QString toUserOutput() const;
|
||||
QString toString() const;
|
||||
QString toFSPathString() const;
|
||||
@@ -156,6 +160,8 @@ public:
|
||||
|
||||
size_t hash(uint seed) const;
|
||||
|
||||
[[nodiscard]] FilePath absoluteFilePath() const;
|
||||
[[nodiscard]] FilePath absolutePath() const;
|
||||
[[nodiscard]] FilePath resolvePath(const FilePath &tail) const;
|
||||
[[nodiscard]] FilePath resolvePath(const QString &tail) const;
|
||||
[[nodiscard]] FilePath cleanPath() const;
|
||||
@@ -206,12 +212,8 @@ public:
|
||||
// on FilePath::osType().
|
||||
bool needsDevice() const;
|
||||
|
||||
// Deprecated.
|
||||
[[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info); // Avoid.
|
||||
[[nodiscard]] QFileInfo toFileInfo() const; // Avoid.
|
||||
[[nodiscard]] QDir toDir() const; // Avoid.
|
||||
[[nodiscard]] FilePath absolutePath() const; // Avoid. Use resolvePath(...)[.parent()] with proper base.
|
||||
[[nodiscard]] FilePath absoluteFilePath() const; // Avoid. Use resolvePath(...) with proper base.
|
||||
[[nodiscard]] QFileInfo toFileInfo() const;
|
||||
[[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info);
|
||||
|
||||
enum class SpecialPathComponent {
|
||||
RootName,
|
||||
|
@@ -632,12 +632,15 @@ void ExternalToolConfig::showInfoForItem(const QModelIndex &index)
|
||||
|
||||
static FilePath getUserFilePath(const QString &proposalFileName)
|
||||
{
|
||||
const QDir resourceDir(ICore::userResourcePath().toDir());
|
||||
if (!resourceDir.exists(QLatin1String("externaltools")))
|
||||
resourceDir.mkpath(QLatin1String("externaltools"));
|
||||
const QFileInfo fi(proposalFileName);
|
||||
const QString &suffix = QLatin1Char('.') + fi.completeSuffix();
|
||||
const FilePath newFilePath = ICore::userResourcePath("externaltools") / fi.baseName();
|
||||
const FilePath resourceDir(ICore::userResourcePath());
|
||||
const FilePath externalToolsDir = resourceDir / "externalTools";
|
||||
if (!externalToolsDir.isDir())
|
||||
externalToolsDir.createDir();
|
||||
|
||||
const FilePath proposal = FilePath::fromString(proposalFileName);
|
||||
const QString suffix = QLatin1Char('.') + proposal.suffix();
|
||||
const FilePath newFilePath = externalToolsDir / proposal.baseName();
|
||||
|
||||
int count = 0;
|
||||
FilePath tryPath = newFilePath + suffix;
|
||||
while (tryPath.exists()) {
|
||||
|
@@ -180,13 +180,14 @@ void GeneralSettingsWidget::fillLanguageBox() const
|
||||
m_languageBox->setCurrentIndex(m_languageBox->count() - 1);
|
||||
|
||||
const FilePath creatorTrPath = ICore::resourcePath("translations");
|
||||
const QStringList languageFiles = creatorTrPath.toDir().entryList(
|
||||
const FilePaths languageFiles = creatorTrPath.dirEntries(
|
||||
QStringList(QLatin1String("qtcreator*.qm")));
|
||||
|
||||
for (const QString &languageFile : languageFiles) {
|
||||
int start = languageFile.indexOf('_') + 1;
|
||||
int end = languageFile.lastIndexOf('.');
|
||||
const QString locale = languageFile.mid(start, end-start);
|
||||
for (const FilePath &languageFile : languageFiles) {
|
||||
const QString path = languageFile.path();
|
||||
int start = path.indexOf('_') + 1;
|
||||
int end = path.lastIndexOf('.');
|
||||
const QString locale = path.mid(start, end-start);
|
||||
// no need to show a language that creator will not load anyway
|
||||
if (hasQmFilesForLocale(locale, creatorTrPath.toString())) {
|
||||
QLocale tmpLocale(locale);
|
||||
|
@@ -182,12 +182,12 @@ void GeneratedFile::setEditorId(Id id)
|
||||
bool GeneratedFile::write(QString *errorMessage) const
|
||||
{
|
||||
// Ensure the directory
|
||||
const QDir dir = m_d->path.parentDir().toDir();
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkpath(dir.absolutePath())) {
|
||||
const FilePath parentDir = m_d->path.parentDir();
|
||||
if (!parentDir.isDir()) {
|
||||
if (!parentDir.createDir()) {
|
||||
*errorMessage = QCoreApplication::translate("BaseFileWizard",
|
||||
"Unable to create the directory %1.")
|
||||
.arg(QDir::toNativeSeparators(dir.absolutePath()));
|
||||
.arg(parentDir.toUserOutput());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -257,8 +257,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsComboBox()
|
||||
|
||||
static QString iconInsideResource(const QString &relativePathToIcon)
|
||||
{
|
||||
const QDir resourcePath(Core::ICore::resourcePath().toDir());
|
||||
return resourcePath.filePath(relativePathToIcon);
|
||||
return Core::ICore::resourcePath().resolvePath(relativePathToIcon).toString();
|
||||
}
|
||||
|
||||
void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsIconList()
|
||||
|
@@ -70,7 +70,7 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
|
||||
Utils::FilePath directoryWithoutPrefix;
|
||||
bool isRelative = false;
|
||||
|
||||
if (path.isEmpty() || path.toDir().isRoot()) {
|
||||
if (path.isEmpty() || path == FilePath::rootPath()) {
|
||||
directoryWithoutPrefix = directory;
|
||||
isRelative = false;
|
||||
} else {
|
||||
|
@@ -32,9 +32,11 @@
|
||||
#include <richtexteditor/richtexteditor.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <qmlprojectmanager/qmlproject.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCryptographicHash>
|
||||
|
||||
using namespace Utils;
|
||||
namespace QmlDesigner {
|
||||
|
||||
AnnotationCommentTab::AnnotationCommentTab(QWidget *parent)
|
||||
@@ -53,7 +55,8 @@ AnnotationCommentTab::AnnotationCommentTab(QWidget *parent)
|
||||
|
||||
const QmlDesigner::DesignDocument *designDocument = QmlDesigner::QmlDesignerPlugin::instance()
|
||||
->documentManager().currentDesignDocument();
|
||||
Utils::FilePath projectPath;
|
||||
|
||||
FilePath projectPath;
|
||||
|
||||
Q_ASSERT(designDocument);
|
||||
|
||||
@@ -142,7 +145,8 @@ QString AnnotationCommentTab::backupFile(const QString &filePath)
|
||||
{
|
||||
const QmlDesigner::DesignDocument *designDocument = QmlDesigner::QmlDesignerPlugin::instance()
|
||||
->documentManager().currentDesignDocument();
|
||||
Utils::FilePath projectFolderPath;
|
||||
|
||||
FilePath projectFolderPath;
|
||||
|
||||
Q_ASSERT(designDocument);
|
||||
|
||||
@@ -155,43 +159,35 @@ QString AnnotationCommentTab::backupFile(const QString &filePath)
|
||||
else
|
||||
return {};
|
||||
|
||||
const QDir projDir(projectFolderPath.toDir());
|
||||
|
||||
if (!projDir.exists())
|
||||
if (!projectFolderPath.isDir())
|
||||
return {};
|
||||
|
||||
const QString imageSubDir(".AnnotationImages");
|
||||
const QDir imgDir(projDir.absolutePath() + QDir::separator() + imageSubDir);
|
||||
const FilePath imgDir(projectFolderPath / imageSubDir);
|
||||
|
||||
ensureDir(imgDir);
|
||||
|
||||
Q_ASSERT(imgDir.exists());
|
||||
if (!imgDir.exists())
|
||||
return {};
|
||||
imgDir.createDir();
|
||||
|
||||
const QFileInfo oldFile(filePath);
|
||||
QFileInfo newFile(imgDir, oldFile.fileName());
|
||||
QTC_ASSERT(imgDir.isDir(), return {});
|
||||
|
||||
QString newName = newFile.baseName() + "_%1." + newFile.completeSuffix();
|
||||
const FilePath oldFile = FilePath::fromString(filePath);
|
||||
FilePath newFile = imgDir.resolvePath(oldFile.fileName());
|
||||
|
||||
QString newNameTemplate = newFile.baseName() + "_%1." + newFile.completeSuffix();
|
||||
|
||||
for (size_t i = 1; true; ++i) {
|
||||
if (!newFile.exists()) {
|
||||
QFile(oldFile.absoluteFilePath()).copy(newFile.absoluteFilePath());
|
||||
oldFile.copyFile(newFile);
|
||||
break;
|
||||
} else if (compareFileChecksum(oldFile.absoluteFilePath(), newFile.absoluteFilePath()) == 0)
|
||||
} else if (compareFileChecksum(oldFile.absoluteFilePath().toString(), newFile.absoluteFilePath().toString()) == 0)
|
||||
break;
|
||||
|
||||
newFile.setFile(imgDir, newName.arg(i));
|
||||
newFile = imgDir / newNameTemplate.arg(i);
|
||||
}
|
||||
|
||||
return projDir.relativeFilePath(newFile.absoluteFilePath());
|
||||
return newFile.relativeChildPath(projectFolderPath).toString();
|
||||
}
|
||||
|
||||
void AnnotationCommentTab::ensureDir(const QDir &dir)
|
||||
{
|
||||
if (!dir.exists())
|
||||
dir.mkdir(".");
|
||||
}
|
||||
|
||||
int AnnotationCommentTab::compareFileChecksum(const QString &firstFile, const QString &secondFile)
|
||||
{
|
||||
|
@@ -69,7 +69,6 @@ signals:
|
||||
|
||||
private:
|
||||
QString backupFile(const QString &filePath);
|
||||
void ensureDir(const QDir &dir);
|
||||
int compareFileChecksum(const QString &firstFile, const QString &secondFile);
|
||||
|
||||
private:
|
||||
|
@@ -494,11 +494,11 @@ public:
|
||||
minorVersion = importInfo.version().minorVersion();
|
||||
typeName.prepend(name + QLatin1Char('.'));
|
||||
} else if (importInfo.isValid() && importInfo.type() == ImportType::Directory) {
|
||||
QString path = importInfo.path();
|
||||
QDir dir = m_doc->path().toDir();
|
||||
// should probably try to make it relatve to some import path, not to the document path
|
||||
QString relativeDir = dir.relativeFilePath(path);
|
||||
QString name = relativeDir.replace(QLatin1Char('/'), QLatin1Char('.'));
|
||||
const Utils::FilePath path = Utils::FilePath::fromString(importInfo.path());
|
||||
const Utils::FilePath dir = m_doc->path();
|
||||
// should probably try to make it relative to some import path, not to the document path
|
||||
const Utils::FilePath relativePath = path.relativeChildPath(dir);
|
||||
QString name = relativePath.path().replace(QLatin1Char('/'), QLatin1Char('.'));
|
||||
if (!name.isEmpty() && name != QLatin1String("."))
|
||||
typeName.prepend(name + QLatin1Char('.'));
|
||||
} else if (importInfo.isValid() && importInfo.type() == ImportType::QrcDirectory) {
|
||||
|
@@ -124,11 +124,11 @@ static inline QString getModuleName(const ScopeChain &scopeChain, const Document
|
||||
return moduleName + QString::number(majorVersion) + QLatin1Char('.')
|
||||
+ QString::number(minorVersion) ;
|
||||
} else if (importInfo.isValid() && importInfo.type() == ImportType::Directory) {
|
||||
const QString path = importInfo.path();
|
||||
const QDir dir = qmlDocument->path().toDir();
|
||||
const Utils::FilePath path = Utils::FilePath::fromString(importInfo.path());
|
||||
const Utils::FilePath dir = qmlDocument->path();
|
||||
// should probably try to make it relatve to some import path, not to the document path
|
||||
QString relativeDir = dir.relativeFilePath(path);
|
||||
const QString name = relativeDir.replace(QLatin1Char('/'), QLatin1Char('.'));
|
||||
const Utils::FilePath relativePath = path.relativeChildPath(dir);
|
||||
const QString name = relativePath.path().replace(QLatin1Char('/'), QLatin1Char('.'));
|
||||
return name;
|
||||
} else if (importInfo.isValid() && importInfo.type() == ImportType::QrcDirectory) {
|
||||
QString path = Utils::QrcParser::normalizedQrcDirectoryPath(importInfo.path());
|
||||
|
@@ -289,9 +289,8 @@ bool QmlBuildSystem::setFileSettingInProjectFile(const QString &setting, const U
|
||||
|
||||
const QString settingQmlCode = setting + ":";
|
||||
|
||||
QDir projectDir = project()->projectFilePath().toDir();
|
||||
projectDir.cdUp();
|
||||
const QString relativePath = projectDir.relativeFilePath(mainFilePath.toString());
|
||||
const Utils::FilePath projectDir = project()->projectFilePath().parentDir();
|
||||
const QString relativePath = mainFilePath.relativeChildPath(projectDir).path();
|
||||
|
||||
if (fileContent.indexOf(settingQmlCode) < 0) {
|
||||
QString addedText = QString("\n %1 \"%2\"\n").arg(settingQmlCode).arg(relativePath);
|
||||
|
@@ -194,9 +194,9 @@ const Utils::FilePath findQmlProjectUpwards(const Utils::FilePath &folder)
|
||||
if (ret.exists())
|
||||
return ret;
|
||||
|
||||
QDir dir = folder.toDir();
|
||||
if (dir.cdUp())
|
||||
return findQmlProjectUpwards(Utils::FilePath::fromString(dir.absolutePath()));
|
||||
if (folder.parentDir().isDir())
|
||||
return findQmlProjectUpwards(folder.parentDir());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@@ -262,18 +262,18 @@ public:
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
static Utils::FilePath customStylesPath()
|
||||
static FilePath customStylesPath()
|
||||
{
|
||||
return Core::ICore::userResourcePath("styles");
|
||||
}
|
||||
|
||||
static Utils::FilePath createColorSchemeFileName(const QString &pattern)
|
||||
static FilePath createColorSchemeFileName(const QString &pattern)
|
||||
{
|
||||
const Utils::FilePath stylesPath = customStylesPath();
|
||||
const FilePath stylesPath = customStylesPath();
|
||||
|
||||
// Find an available file name
|
||||
int i = 1;
|
||||
Utils::FilePath filePath;
|
||||
FilePath filePath;
|
||||
do {
|
||||
filePath = stylesPath.pathAppended(pattern.arg((i == 1) ? QString() : QString::number(i)));
|
||||
++i;
|
||||
@@ -545,7 +545,7 @@ void FontSettingsPageWidget::copyColorScheme(const QString &name)
|
||||
|
||||
QString baseFileName = QFileInfo(entry.fileName).completeBaseName();
|
||||
baseFileName += QLatin1String("_copy%1.xml");
|
||||
Utils::FilePath fileName = createColorSchemeFileName(baseFileName);
|
||||
FilePath fileName = createColorSchemeFileName(baseFileName);
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
// Ask about saving any existing modifications
|
||||
@@ -604,7 +604,7 @@ void FontSettingsPageWidget::deleteColorScheme()
|
||||
|
||||
void FontSettingsPageWidget::importScheme()
|
||||
{
|
||||
const Utils::FilePath importedFile
|
||||
const FilePath importedFile
|
||||
= Utils::FileUtils::getOpenFilePath(this,
|
||||
tr("Import Color Scheme"),
|
||||
{},
|
||||
@@ -613,7 +613,7 @@ void FontSettingsPageWidget::importScheme()
|
||||
if (importedFile.isEmpty())
|
||||
return;
|
||||
|
||||
Utils::FilePath fileName = createColorSchemeFileName(importedFile.baseName() + "%1."
|
||||
FilePath fileName = createColorSchemeFileName(importedFile.baseName() + "%1."
|
||||
+ importedFile.suffix());
|
||||
|
||||
// Ask about saving any existing modifications
|
||||
@@ -647,10 +647,10 @@ void FontSettingsPageWidget::exportScheme()
|
||||
|
||||
const ColorSchemeEntry &entry = m_schemeListModel.colorSchemeAt(index);
|
||||
|
||||
const Utils::FilePath filePath
|
||||
const FilePath filePath
|
||||
= Utils::FileUtils::getSaveFilePath(this,
|
||||
tr("Export Color Scheme"),
|
||||
Utils::FilePath::fromString(entry.fileName),
|
||||
FilePath::fromString(entry.fileName),
|
||||
tr("Color scheme (*.xml);;All files (*)"));
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
@@ -686,34 +686,30 @@ void FontSettingsPageWidget::refreshColorSchemeList()
|
||||
{
|
||||
QList<ColorSchemeEntry> colorSchemes;
|
||||
|
||||
QDir styleDir(Core::ICore::resourcePath("styles").toDir());
|
||||
styleDir.setNameFilters(QStringList() << QLatin1String("*.xml"));
|
||||
styleDir.setFilter(QDir::Files);
|
||||
const FilePath styleDir = Core::ICore::resourcePath("styles");
|
||||
|
||||
FilePaths schemeList = styleDir.dirEntries(FileFilter({"*.xml"}, QDir::Files));
|
||||
const FilePath defaultScheme = FilePath::fromString(FontSettings::defaultSchemeFileName());
|
||||
|
||||
if (schemeList.removeAll(defaultScheme))
|
||||
schemeList.prepend(defaultScheme);
|
||||
|
||||
int selected = 0;
|
||||
|
||||
QStringList schemeList = styleDir.entryList();
|
||||
QString defaultScheme = Utils::FilePath::fromString(FontSettings::defaultSchemeFileName()).fileName();
|
||||
if (schemeList.removeAll(defaultScheme))
|
||||
schemeList.prepend(defaultScheme);
|
||||
for (const QString &file : qAsConst(schemeList)) {
|
||||
const QString fileName = styleDir.absoluteFilePath(file);
|
||||
if (m_value.colorSchemeFileName() == fileName)
|
||||
for (const FilePath &file : qAsConst(schemeList)) {
|
||||
if (FilePath::fromString(m_value.colorSchemeFileName()) == file)
|
||||
selected = colorSchemes.size();
|
||||
colorSchemes.append(ColorSchemeEntry(fileName, true));
|
||||
colorSchemes.append(ColorSchemeEntry(file.toString(), true));
|
||||
}
|
||||
|
||||
if (colorSchemes.isEmpty())
|
||||
qWarning() << "Warning: no color schemes found in path:" << styleDir.path();
|
||||
qWarning() << "Warning: no color schemes found in path:" << styleDir.toUserOutput();
|
||||
|
||||
styleDir.setPath(customStylesPath().path());
|
||||
|
||||
const QStringList files = styleDir.entryList();
|
||||
for (const QString &file : files) {
|
||||
const QString fileName = styleDir.absoluteFilePath(file);
|
||||
if (m_value.colorSchemeFileName() == fileName)
|
||||
const FilePaths files = customStylesPath().dirEntries(FileFilter({"*.xml"}, QDir::Files));
|
||||
for (const FilePath &file : files) {
|
||||
if (FilePath::fromString(m_value.colorSchemeFileName()) == file)
|
||||
selected = colorSchemes.size();
|
||||
colorSchemes.append(ColorSchemeEntry(fileName, false));
|
||||
colorSchemes.append(ColorSchemeEntry(file.toString(), false));
|
||||
}
|
||||
|
||||
m_refreshingSchemeList = true;
|
||||
|
Reference in New Issue
Block a user