QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
src
core
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
16
#include <QDir>
17
18
#include "
qgslocalizeddatapathregistry.h
"
19
#include "
qgssettings.h
"
20
#include "
qgis.h
"
21
#include "
qgsreadwritelocker.h
"
22
23
24
QgsLocalizedDataPathRegistry::QgsLocalizedDataPathRegistry
()
25
{
26
readFromSettings();
27
}
28
29
QString
QgsLocalizedDataPathRegistry::globalPath
(
const
QString &relativePath )
const
30
{
31
QgsReadWriteLocker
locker( mLock,
QgsReadWriteLocker::Read
);
32
33
for
(
const
QDir &basePath : std::as_const( mPaths ) )
34
if
( basePath.exists( relativePath ) )
35
return
basePath.absoluteFilePath( relativePath );
36
37
return
QString();
38
}
39
40
QString
QgsLocalizedDataPathRegistry::localizedPath
(
const
QString &fullPath )
const
41
{
42
QgsReadWriteLocker
locker( mLock,
QgsReadWriteLocker::Read
);
43
44
for
(
const
QDir &basePath : std::as_const( mPaths ) )
45
if
( fullPath.startsWith( basePath.absolutePath() ) )
46
return
basePath.relativeFilePath( fullPath );
47
48
return
QString();
49
50
}
51
52
QStringList
QgsLocalizedDataPathRegistry::paths
()
const
53
{
54
QgsReadWriteLocker
locker( mLock,
QgsReadWriteLocker::Read
);
55
56
QStringList
paths
;
57
for
(
const
QDir &dir : mPaths )
58
paths
<< dir.absolutePath();
59
return
paths
;
60
}
61
62
void
QgsLocalizedDataPathRegistry::setPaths
(
const
QStringList &paths )
63
{
64
QgsReadWriteLocker
locker( mLock,
QgsReadWriteLocker::Write
);
65
66
mPaths.clear();
67
for
(
const
QString &path :
paths
)
68
{
69
QDir dir( path );
70
if
( !mPaths.contains( dir ) )
71
mPaths << dir;
72
}
73
74
locker.
unlock
();
75
writeToSettings();
76
}
77
78
void
QgsLocalizedDataPathRegistry::registerPath
(
const
QString &path,
int
position )
79
{
80
QgsReadWriteLocker
locker( mLock,
QgsReadWriteLocker::Read
);
81
82
QDir dir( path );
83
if
( mPaths.contains( dir ) )
84
return
;
85
86
locker.
changeMode
(
QgsReadWriteLocker::Write
);
87
88
if
( position >= 0 && position < mPaths.count() )
89
mPaths.insert( position, dir );
90
else
91
mPaths.append( dir );
92
93
locker.
unlock
();
94
writeToSettings();
95
}
96
97
void
QgsLocalizedDataPathRegistry::unregisterPath
(
const
QString &path )
98
{
99
QgsReadWriteLocker
locker( mLock,
QgsReadWriteLocker::Write
);
100
101
mPaths.removeAll( QDir( path ) );
102
locker.
unlock
();
103
writeToSettings();
104
}
105
106
void
QgsLocalizedDataPathRegistry::readFromSettings()
107
{
108
setPaths
(
settingsLocalizedDataPaths
.
value
() );
109
}
110
111
void
QgsLocalizedDataPathRegistry::writeToSettings()
const
112
{
113
settingsLocalizedDataPaths
.
setValue
(
paths
() );
114
}
QgsReadWriteLocker::changeMode
void changeMode(Mode mode)
Change the mode of the lock to mode.
Definition:
qgsreadwritelocker.cpp:30
qgsreadwritelocker.h
QgsReadWriteLocker::Read
@ Read
Lock for read.
Definition:
qgsreadwritelocker.h:75
QgsLocalizedDataPathRegistry::settingsLocalizedDataPaths
static const QgsSettingsEntryStringList settingsLocalizedDataPaths
Settings entry localized data paths.
Definition:
qgslocalizeddatapathregistry.h:84
qgslocalizeddatapathregistry.h
QgsLocalizedDataPathRegistry::registerPath
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...
Definition:
qgslocalizeddatapathregistry.cpp:78
qgis.h
QgsLocalizedDataPathRegistry::unregisterPath
void unregisterPath(const QString &path)
Unregisters a localized path.
Definition:
qgslocalizeddatapathregistry.cpp:97
QgsLocalizedDataPathRegistry::localizedPath
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.
Definition:
qgslocalizeddatapathregistry.cpp:40
QgsReadWriteLocker::unlock
void unlock()
Unlocks the lock.
Definition:
qgsreadwritelocker.cpp:45
QgsReadWriteLocker
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
Definition:
qgsreadwritelocker.h:40
QgsLocalizedDataPathRegistry::QgsLocalizedDataPathRegistry
QgsLocalizedDataPathRegistry()
Definition:
qgslocalizeddatapathregistry.cpp:24
QgsReadWriteLocker::Write
@ Write
Lock for write.
Definition:
qgsreadwritelocker.h:76
QgsLocalizedDataPathRegistry::paths
QStringList paths() const
Returns a list of registered localized paths.
Definition:
qgslocalizeddatapathregistry.cpp:52
QgsLocalizedDataPathRegistry::globalPath
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.
Definition:
qgslocalizeddatapathregistry.cpp:29
QgsSettingsEntryByReference::value
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
Definition:
qgssettingsentry.h:379
QgsLocalizedDataPathRegistry::setPaths
void setPaths(const QStringList &paths)
Sets the complete list of localized path.
Definition:
qgslocalizeddatapathregistry.cpp:62
qgssettings.h
QgsSettingsEntryByReference::setValue
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
Definition:
qgssettingsentry.h:424
Generated on Sun Sep 11 2022 00:03:17 for QGIS API Documentation by
1.8.17