1 /*************************************************************************** 2 qgslocalizeddatapathregistry.h 3 -------------------------------------- 4 Date : May 2020 5 Copyright : (C) 2020 by Denis Rouzaud 6 Email : denis.rouzaud 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 16 17 #ifndef QGSLOCALIZEDDATAPATHREGISTRY_H 18 #define QGSLOCALIZEDDATAPATHREGISTRY_H 19 20 21 #include <QDir> 22 #include <QList> 23 #include <QReadWriteLock> 24 25 #include "qgis_core.h" 26 #include "qgis_sip.h" 27 28 /** 29 * \ingroup core 30 * \brief A registry class to hold localized data paths which can be used for basemaps, logos, etc. 31 * Paths are meant to be absolute paths and are stored by order of preference. 32 * 33 * If a layer from one of the paths is loaded, it will be saved as localized in the project file. 34 * For instance, if you have `C:/my_maps` in your localized paths, 35 * `C:/my_maps/my_country/ortho.tif` will be save in your project as `localized:my_country/ortho.tif`. 36 * 37 * The resolving of the file paths happens in QgsPathResolver. 38 * 39 * \since QGIS 3.14 40 */ 41 class CORE_EXPORT QgsLocalizedDataPathRegistry 42 { 43 public: 44 QgsLocalizedDataPathRegistry(); 45 46 //! Returns the global path if the file has been found in one of the paths, an empty string otherwise 47 QString globalPath( const QString &localizedPath ) const; 48 49 //! Returns the localized path if the file has been found in one of the path, an empty string otherwise 50 QString localizedPath( const QString &globalPath ) const; 51 52 //! Returns a list of registered localized paths 53 QStringList paths() const; 54 55 //! Sets the complete list of localized path 56 void setPaths( const QStringList &paths ) SIP_SKIP; 57 58 /** 59 * Registers a localized path 60 * If \a position is given, the path is inserted at the given position in the list 61 * Since the paths are stored by order of preference, lower positions in the list take precedence. 62 */ 63 void registerPath( const QString &path, int position = -1 ); 64 65 //! Unregisters a localized path 66 void unregisterPath( const QString &path ); 67 68 private: 69 #ifdef SIP_RUN QgsLocalizedDataPathRegistry(const QgsLocalizedDataPathRegistry & other)70 QgsLocalizedDataPathRegistry( const QgsLocalizedDataPathRegistry &other ) 71 {} 72 #endif 73 74 void readFromSettings(); 75 void writeToSettings(); 76 77 QList<QDir> mPaths; 78 mutable QReadWriteLock mLock; 79 }; 80 81 #endif // QGSLOCALIZEDDATAPATHREGISTRY_H 82