FileInProjectFinder Class

(Utils::FileInProjectFinder)

The FileInProjectFinder class is a helper class to find the original file in the project directory for a given file URL. More...

Header: #include <FileInProjectFinder>

Public Types

enum FindMode { FindFile, FindDirectory, FindEither }

Public Functions

FileInProjectFinder()
QString findFile(const QUrl &fileUrl, bool *success = nullptr) const
QString findFileOrDirectory(const QString &originalPath, FindMode findMode, bool *success) const
QString projectDirectory() const
QStringList searchDirectories() const
void setAdditionalSearchDirectories(const QStringList &searchDirectories)
void setProjectDirectory(const QString &absoluteProjectPath)
void setProjectFiles(const QStringList &projectFiles)
void setSysroot(const QString &sysroot)

Detailed Description

The FileInProjectFinder class is a helper class to find the original file in the project directory for a given file URL.

Often files are copied in the build and deploy process. findFile() searches for an existing file in the project directory for a given file path.

For example, the following file paths should all be mapped to $PROJECTDIR/qml/app/main.qml:

  • C:/app-build-desktop/qml/app/main.qml (shadow build directory)
  • /Users/x/app-build-desktop/App.app/Contents/Resources/qml/App/main.qml (folder on Mac OS X)

Member Type Documentation

enum FileInProjectFinder::FindMode

Member Function Documentation

FileInProjectFinder::FileInProjectFinder()

Default constructs an instance of FileInProjectFinder.

QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success = nullptr) const

Returns the best match for the given file URL in the project directory.

The function first checks whether the file inside the project directory exists. If not, the leading directory in the path is stripped, and the - now shorter - path is checked for existence, and so on. Second, it tries to locate the file in the sysroot folder specified. Third, we walk the list of project files, and search for a file name match there. If all fails, it returns the original path from the file URL.

QString FileInProjectFinder::findFileOrDirectory(const QString &originalPath, FindMode findMode, bool *success) const

QString FileInProjectFinder::projectDirectory() const

See also setProjectDirectory().

QStringList FileInProjectFinder::searchDirectories() const

void FileInProjectFinder::setAdditionalSearchDirectories(const QStringList &searchDirectories)

void FileInProjectFinder::setProjectDirectory(const QString &absoluteProjectPath)

See also projectDirectory().

void FileInProjectFinder::setProjectFiles(const QStringList &projectFiles)

void FileInProjectFinder::setSysroot(const QString &sysroot)