-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix relative paths to SVG files in embedded projects #4426
Conversation
Just wondering.. instead of passing the path resolver itself, wouldn't it be more future proof to pass some container class with the resolver just in case we need to pass other stuff in future? |
I thought about that - and I am half-minded about that... Such container class could be handy e.g. for reporting of errors when loading project files... |
Can I add my +1 mind to your +0.5 mind? ;) |
for what it's worth, the container idea seems clever to me ;) let me know when it's ready to test |
src/core/qgsmaplayer.cpp
Outdated
@@ -1166,7 +1167,7 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe | |||
} | |||
#endif | |||
|
|||
return readSymbology( myRoot, myErrorMessage ); | |||
return readSymbology( myRoot, myErrorMessage, QgsPathResolver() ); // TODO: support relative paths? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please! Symbols stored relative to the project file would be very handy, providing a means of encapsulating sharable ZIP archives of projects, like with QConsolidate. (same for writeSymbology
TODO below).
This probably means that a standard-named symbols folder within the project folder, e.g. symbols
is dynamically searched, if there is a project (or layer) setting to use project-relative symbol paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is more for just vector layers, e.g SVG symbols. I just focused on the TODO note and missed that this refers to the base class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wonder-sk are my comments ^ not in-line with what this work could be extended to do, i.e. should project-relative symbol paths be implemented in another way/place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dakcarto I am not sure if I understand how did you mean your comments. We already have support for relative paths to SVG symbol within project directory... (just without a special symbols
subdir - but of course users could decide to use such convention if they wanted)
That TODO (when implemented) is meant to add support for relative paths for .qml files - until now it was supposed that relative paths to SVG symbols were relative to a system SVG directory or the current project directory - which is wrong - and instead the directory of the .qml file should be used.
This is necessary in order to be able to correctly translate between absolute and relative paths deeper in the code - e.g. paths to SVG files used in marker or fill symbols. Until now, relative paths were translated to absolute paths on the fly. This is now changed - paths to files should be always absolute within QGIS objects - and paths only get turned into relative when saving projects. When loading a project, relative paths are translated to absolute paths immediately. This should lower the overall confusion about relative/absolute paths within QGIS, and also allow having different base directories for relative paths (e.g. QML or QPT files may use relative paths to their directory - rather than to the project directory)
This should make the read/write methods more flexible if we need to give them extra context.
This enables correct loading/saving of relative paths of SVG files for background of labels
207e1e9
to
5bdae75
Compare
It is decided on different level whether files are saved with relative paths and internally now QGIS always uses absolute paths to SVG files.
Loading bug: on the first project load, data-defined properties for diagram layer settings were not read as the default constructor did not populate the list of data-defined property definitions.
[work in progress - need to fix unit tests and few todos]
This PR fixes this bug - http://hub.qgis.org/issues/16355 - relative paths in embedded project were incorrectly resolved as if they were relative paths within the active project.
The solution is to propagate path resolver through renderers, annotations, diagrams etc.
This is necessary in order to be able to correctly translate between absolute and relative paths deeper in the code - e.g. paths to SVG files used in marker or fill symbols.
Until now, relative paths were translated to absolute paths on the fly. This is now changed - paths to files should be always absolute within QGIS objects - and paths only get turned into relative when saving projects. When loading a project, relative paths are translated to absolute paths immediately.
This should lower the overall confusion about relative/absolute paths within QGIS, and also allow having different base directories for relative paths (e.g. QML or QPT files may use relative paths to their directory - rather than to the project directory)
cc @3nids