QGIS API Documentation 3.99.0-Master (a8882ad4560)
Loading...
Searching...
No Matches
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
19
20#include "qgsapplication.h"
21
22#include <QDir>
23
28
29void QgsApplicationThemeRegistry::addApplicationThemes()
30{
31 mThemes.insert( "default"_L1, QString() );
32
33 const QStringList paths = QStringList() << QgsApplication::instance()->userThemesFolder() << QgsApplication::instance()->defaultThemesFolder();
34 for ( const QString &path : paths )
35 {
36 QDir folder( path );
37 const QFileInfoList folderInfos = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
38 for ( const QFileInfo &folderInfo : folderInfos )
39 {
40 const QString name = folderInfo.baseName();
41 const QString folder = folderInfo.absoluteFilePath();
42 addTheme( name, folder );
43 }
44 }
45}
46
47bool QgsApplicationThemeRegistry::addTheme( const QString &name, const QString &folder )
48{
49 if ( mThemes.contains( name ) )
50 {
51 return false;
52 }
53
54 const QFileInfo folderInfo( folder );
55 if ( !folderInfo.exists() )
56 {
57 return false;
58 }
59
60 const QFileInfo styleInfo( folderInfo.absoluteFilePath() + "/style.qss" );
61 if ( !styleInfo.exists() )
62 {
63 return false;
64 }
65
66 mThemes.insert( name, folder );
67 return true;
68}
69
71{
72 if ( !mThemes.contains( name ) )
73 {
74 return false;
75 }
76
77 mThemes.remove( name );
78 return true;
79}
80
82{
83 return mThemes.keys();
84}
85
86QString QgsApplicationThemeRegistry::themeFolder( const QString &name ) const
87{
88 return mThemes.value( name );
89}
90
91QHash<QString, QString> QgsApplicationThemeRegistry::themeFolders() const
92{
93 return mThemes;
94}
QHash< QString, QString > themeFolders() const
Returns a map of user interface theme names and folders.
QgsApplicationThemeRegistry()
Constructor for an empty user interface theme registry.
QStringList themes() const
Returns the list of available user interface themes.
QString themeFolder(const QString &name) const
Returns the user interface theme folder for a matching name.
bool addTheme(const QString &name, const QString &folder)
Adds a user interface theme into the registry.
bool removeTheme(const QString &name)
Removes a user interface theme with a matching name from the registry.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
static QString defaultThemesFolder()
Returns the path to default themes folder from install (works as a starting point).
static QString userThemesFolder()
Returns the path to user's themes folder.