QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
qgsapplicationthemeregistry.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsapplicationthemeregistry.cpp
3
-------------------
4
begin : January 2026
5
copyright : (C) 2026 by Mathieu Pellerin
6
email : mathieu at opengis dot ch
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsapplicationthemeregistry.h
"
19
20
#include "
qgsapplication.h
"
21
22
#include <QDir>
23
#include <QString>
24
25
using namespace
Qt::StringLiterals;
26
27
QgsApplicationThemeRegistry::QgsApplicationThemeRegistry
()
28
{
29
addApplicationThemes();
30
}
31
32
void
QgsApplicationThemeRegistry::addApplicationThemes()
33
{
34
mThemes.insert(
"default"
_L1, QString() );
35
36
const
QStringList paths = QStringList() <<
QgsApplication::instance
()->
userThemesFolder
() <<
QgsApplication::instance
()->
defaultThemesFolder
();
37
for
(
const
QString &path : paths )
38
{
39
QDir folder( path );
40
const
QFileInfoList folderInfos = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
41
for
(
const
QFileInfo &folderInfo : folderInfos )
42
{
43
const
QString name = folderInfo.baseName();
44
const
QString folder = folderInfo.absoluteFilePath();
45
addTheme
( name, folder );
46
}
47
}
48
}
49
50
bool
QgsApplicationThemeRegistry::addTheme
(
const
QString &name,
const
QString &folder )
51
{
52
if
( mThemes.contains( name ) )
53
{
54
return
false
;
55
}
56
57
const
QFileInfo folderInfo( folder );
58
if
( !folderInfo.exists() )
59
{
60
return
false
;
61
}
62
63
const
QFileInfo styleInfo( folderInfo.absoluteFilePath() +
"/style.qss"
);
64
if
( !styleInfo.exists() )
65
{
66
return
false
;
67
}
68
69
mThemes.insert( name, folder );
70
return
true
;
71
}
72
73
bool
QgsApplicationThemeRegistry::removeTheme
(
const
QString &name )
74
{
75
if
( !mThemes.contains( name ) )
76
{
77
return
false
;
78
}
79
80
mThemes.remove( name );
81
return
true
;
82
}
83
84
QStringList
QgsApplicationThemeRegistry::themes
()
const
85
{
86
return
mThemes.keys();
87
}
88
89
QString
QgsApplicationThemeRegistry::themeFolder
(
const
QString &name )
const
90
{
91
return
mThemes.value( name );
92
}
93
94
QHash<QString, QString>
QgsApplicationThemeRegistry::themeFolders
()
const
95
{
96
return
mThemes;
97
}
QgsApplicationThemeRegistry::themeFolders
QHash< QString, QString > themeFolders() const
Returns a map of user interface theme names and folders.
Definition
qgsapplicationthemeregistry.cpp:94
QgsApplicationThemeRegistry::QgsApplicationThemeRegistry
QgsApplicationThemeRegistry()
Constructor for an empty user interface theme registry.
Definition
qgsapplicationthemeregistry.cpp:27
QgsApplicationThemeRegistry::themes
QStringList themes() const
Returns the list of available user interface themes.
Definition
qgsapplicationthemeregistry.cpp:84
QgsApplicationThemeRegistry::themeFolder
QString themeFolder(const QString &name) const
Returns the user interface theme folder for a matching name.
Definition
qgsapplicationthemeregistry.cpp:89
QgsApplicationThemeRegistry::addTheme
bool addTheme(const QString &name, const QString &folder)
Adds a user interface theme into the registry.
Definition
qgsapplicationthemeregistry.cpp:50
QgsApplicationThemeRegistry::removeTheme
bool removeTheme(const QString &name)
Removes a user interface theme with a matching name from the registry.
Definition
qgsapplicationthemeregistry.cpp:73
QgsApplication::instance
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
Definition
qgsapplication.cpp:689
QgsApplication::defaultThemesFolder
static QString defaultThemesFolder()
Returns the path to default themes folder from install (works as a starting point).
Definition
qgsapplication.cpp:1596
QgsApplication::userThemesFolder
static QString userThemesFolder()
Returns the path to user's themes folder.
Definition
qgsapplication.cpp:1586
qgsapplication.h
qgsapplicationthemeregistry.h
Generated on
for QGIS API Documentation by
1.17.0