QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslocalizeddatapathregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslocalizeddatapathregistry.cpp
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
17
18#include "qgis.h"
19#include "qgsreadwritelocker.h"
21#include "qgssettingstree.h"
22
23#include <QDir>
24
26
31
32QString QgsLocalizedDataPathRegistry::globalPath( const QString &relativePath ) const
33{
35
36 for ( const QDir &basePath : std::as_const( mPaths ) )
37 if ( basePath.exists( relativePath ) )
38 return basePath.absoluteFilePath( relativePath );
39
40 return QString();
41}
42
43QString QgsLocalizedDataPathRegistry::localizedPath( const QString &fullPath ) const
44{
46
47 for ( const QDir &basePath : std::as_const( mPaths ) )
48 if ( fullPath.startsWith( basePath.absolutePath() ) )
49 return basePath.relativeFilePath( fullPath );
50
51 return QString();
52
53}
54
56{
58
59 QStringList paths;
60 for ( const QDir &dir : mPaths )
61 paths << dir.absolutePath();
62 return paths;
63}
64
66{
68
69 mPaths.clear();
70 for ( const QString &path : paths )
71 {
72 QDir dir( path );
73 if ( !mPaths.contains( dir ) )
74 mPaths << dir;
75 }
76
77 locker.unlock();
78 writeToSettings();
79}
80
81void QgsLocalizedDataPathRegistry::registerPath( const QString &path, int position )
82{
84
85 QDir dir( path );
86 if ( mPaths.contains( dir ) )
87 return;
88
90
91 if ( position >= 0 && position < mPaths.count() )
92 mPaths.insert( position, dir );
93 else
94 mPaths.append( dir );
95
96 locker.unlock();
97 writeToSettings();
98}
99
101{
103
104 mPaths.removeAll( QDir( path ) );
105 locker.unlock();
106 writeToSettings();
107}
108
109void QgsLocalizedDataPathRegistry::readFromSettings()
110{
112}
113
114void QgsLocalizedDataPathRegistry::writeToSettings() const
115{
116 settingsLocalizedDataPaths->setValue( paths() );
117}
QString globalPath(const QString &localizedPath) const
Returns the global path if the file has been found in one of the paths, an empty string otherwise.
void setPaths(const QStringList &paths)
Sets the complete list of localized path.
void unregisterPath(const QString &path)
Unregisters a localized path.
QString localizedPath(const QString &globalPath) const
Returns the localized path if the file has been found in one of the path, an empty string otherwise.
static const QgsSettingsEntryStringList * settingsLocalizedDataPaths
Settings entry localized data paths.
void registerPath(const QString &path, int position=-1)
Registers a localized path If position is given, the path is inserted at the given position in the li...
QStringList paths() const
Returns a list of registered localized paths.
A convenience class that simplifies locking and unlocking QReadWriteLocks.
@ Write
Lock for write.
void unlock()
Unlocks the lock.
void changeMode(Mode mode)
Change the mode of the lock to mode.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
A string list settings entry.
static QgsSettingsTreeNode * sTreeQgis