Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36421 from 3nids/basemap_path
Registry for localized data paths
- Loading branch information
Showing
14 changed files
with
596 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
python/core/auto_generated/qgslocalizeddatapathregistry.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgslocalizeddatapathregistry.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
class QgsLocalizedDataPathRegistry | ||
{ | ||
%Docstring | ||
A registry class to hold localized data paths which can be used for basemaps, logos, etc. | ||
Paths are meant to be absolute paths and are stored by order of preference. | ||
|
||
If a layer from one of the paths is loaded, it will be saved as localized in the project file. | ||
For instance, if you have C:\my_maps in your localized paths, | ||
C:\my_maps\my_country\ortho.tif will be save in your project as localized:my_country\ortho.tif | ||
|
||
The resolving of the file paths happens in QgsPathResolver. | ||
|
||
.. versionadded:: 3.14 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslocalizeddatapathregistry.h" | ||
%End | ||
public: | ||
QgsLocalizedDataPathRegistry(); | ||
|
||
QString globalPath( const QString &localizedPath ) const; | ||
%Docstring | ||
Returns the global path if the file has been found in one of the paths, an empty string otherwise | ||
%End | ||
|
||
QString localizedPath( const QString &globalPath ) const; | ||
%Docstring | ||
Returns the localized path if the file has been found in one of the path, an empty string otherwise | ||
%End | ||
|
||
QStringList paths() const; | ||
%Docstring | ||
Returns a list of registered localized paths | ||
%End | ||
|
||
|
||
void registerPath( const QString &path, int position = -1 ); | ||
%Docstring | ||
Registers a localized path | ||
If ``position`` is given, the path is inserted at the given position in the list | ||
Since the paths are stored by order of preference, lower positions in the list take precedence. | ||
%End | ||
|
||
void unregisterPath( const QString &path ); | ||
%Docstring | ||
Unregisters a localized path | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/qgslocalizeddatapathregistry.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/*************************************************************************** | ||
qgslocalizeddatapathregistry.cpp | ||
-------------------------------------- | ||
Date : May 2020 | ||
Copyright : (C) 2020 by Denis Rouzaud | ||
Email : denis.rouzaud | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QDir> | ||
|
||
#include "qgslocalizeddatapathregistry.h" | ||
#include "qgssettings.h" | ||
#include "qgis.h" | ||
#include "qgsreadwritelocker.h" | ||
|
||
|
||
QgsLocalizedDataPathRegistry::QgsLocalizedDataPathRegistry() | ||
{ | ||
readFromSettings(); | ||
} | ||
|
||
QString QgsLocalizedDataPathRegistry::globalPath( const QString &relativePath ) const | ||
{ | ||
for ( const QDir &basePath : qgis::as_const( mPaths ) ) | ||
if ( basePath.exists( relativePath ) ) | ||
return basePath.absoluteFilePath( relativePath ); | ||
|
||
return QString(); | ||
} | ||
|
||
QString QgsLocalizedDataPathRegistry::localizedPath( const QString &fullPath ) const | ||
{ | ||
for ( const QDir &basePath : qgis::as_const( mPaths ) ) | ||
if ( fullPath.startsWith( basePath.absolutePath() ) ) | ||
return basePath.relativeFilePath( fullPath ); | ||
|
||
return QString(); | ||
|
||
} | ||
|
||
QStringList QgsLocalizedDataPathRegistry::paths() const | ||
{ | ||
QStringList paths; | ||
for ( const QDir &dir : mPaths ) | ||
paths << dir.absolutePath(); | ||
return paths; | ||
} | ||
|
||
void QgsLocalizedDataPathRegistry::setPaths( const QStringList &paths ) | ||
{ | ||
mPaths.clear(); | ||
for ( const QString &path : paths ) | ||
{ | ||
QDir dir( path ); | ||
if ( !mPaths.contains( dir ) ) | ||
mPaths << dir; | ||
} | ||
|
||
writeToSettings(); | ||
} | ||
|
||
void QgsLocalizedDataPathRegistry::registerPath( const QString &path, int position ) | ||
{ | ||
QDir dir( path ); | ||
if ( mPaths.contains( dir ) ) | ||
return; | ||
|
||
if ( position >= 0 && position < mPaths.count() ) | ||
mPaths.insert( position, dir ); | ||
else | ||
mPaths.append( dir ); | ||
|
||
writeToSettings(); | ||
} | ||
|
||
void QgsLocalizedDataPathRegistry::unregisterPath( const QString &path ) | ||
{ | ||
mPaths.removeAll( QDir( path ) ); | ||
writeToSettings(); | ||
} | ||
|
||
void QgsLocalizedDataPathRegistry::readFromSettings() | ||
{ | ||
setPaths( QgsSettings().value( QStringLiteral( "/qgis/localized_data_paths" ) ).toStringList() ); | ||
} | ||
|
||
void QgsLocalizedDataPathRegistry::writeToSettings() | ||
{ | ||
QgsSettings().setValue( QStringLiteral( "/qgis/localized_data_paths" ), paths() ); | ||
} |
Oops, something went wrong.