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 Functions
FileInProjectFinder() | |
~FileInProjectFinder() | |
void | addMappedPath(const FileName &localFilePath, const QString &remoteFilePath) |
QString | findFile(const QUrl &fileUrl, bool *success = nullptr) const |
bool | findFileOrDirectory(const QString &originalPath, FileHandler fileHandler = nullptr, DirectoryHandler directoryHandler = nullptr) const |
FileName | projectDirectory() const |
FileNameList | searchDirectories() const |
void | setAdditionalSearchDirectories(const FileNameList &searchDirectories) |
void | setProjectDirectory(const FileName &absoluteProjectPath) |
void | setProjectFiles(const FileNameList &projectFiles) |
void | setSysroot(const FileName &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 Function Documentation
FileInProjectFinder::FileInProjectFinder()
Default constructs an instance of FileInProjectFinder.
FileInProjectFinder::~FileInProjectFinder()
Destroys the instance of FileInProjectFinder.
void FileInProjectFinder::addMappedPath(const FileName &localFilePath, const QString &remoteFilePath)
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.
bool FileInProjectFinder::findFileOrDirectory(const QString &originalPath, FileHandler fileHandler = nullptr, DirectoryHandler directoryHandler = nullptr) const
FileName FileInProjectFinder::projectDirectory() const
See also setProjectDirectory().
FileNameList FileInProjectFinder::searchDirectories() const
void FileInProjectFinder::setAdditionalSearchDirectories(const FileNameList &searchDirectories)
void FileInProjectFinder::setProjectDirectory(const FileName &absoluteProjectPath)
See also projectDirectory().