QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
processing
qgsprocessingdefaultstyleregistry.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsprocessingdefaultstyleregistry.cpp
3
------------------------
4
begin : Septeber 2026
5
copyright : (C) 2026 by Nyall Dawson
6
email : nyall dot dawson at gmail dot com
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 "
qgsprocessingdefaultstyleregistry.h
"
19
20
#include "
qgsprocessingutils.h
"
21
22
#include <QDir>
23
#include <QFile>
24
#include <QString>
25
26
#include "moc_qgsprocessingdefaultstyleregistry.cpp"
27
28
using namespace
Qt::StringLiterals;
29
30
QgsProcessingDefaultStyleRegistry::QgsProcessingDefaultStyleRegistry
( QObject *parent )
31
: QObject( parent )
32
{}
33
34
void
QgsProcessingDefaultStyleRegistry::setDefaultStyleForOutput
(
const
QString &algorithmId,
const
QString &outputName,
const
QString &qmlPath )
35
{
36
if
( qmlPath.isEmpty() )
37
{
38
if
( mStyles[algorithmId].contains( outputName ) )
39
{
40
mStyles[algorithmId].remove( outputName );
41
if
( mStyles[algorithmId].isEmpty() )
42
{
43
mStyles.remove( algorithmId );
44
}
45
}
46
}
47
else
48
{
49
mStyles[algorithmId][outputName] = qmlPath;
50
}
51
}
52
53
QString
QgsProcessingDefaultStyleRegistry::defaultStyleForOutput
(
const
QString &algorithmId,
const
QString &outputName )
const
54
{
55
return
mStyles.value( algorithmId ).value( outputName );
56
}
57
58
QString QgsProcessingDefaultStyleRegistry::configFilePath()
59
{
60
const
QDir dir(
QgsProcessingUtils::userFolder
() );
61
return
dir.filePath( u
"processing_qgis_styles.conf"
_s );
62
}
63
64
void
QgsProcessingDefaultStyleRegistry::loadStyles
()
65
{
66
const
QString filePath = configFilePath();
67
if
( !QFile::exists( filePath ) )
68
return
;
69
70
QFile file( filePath );
71
if
( !file.open( QIODevice::ReadOnly ) )
72
return
;
73
74
QTextStream in( &file );
75
const
QString originalFileContent = in.readAll();
76
file.close();
77
78
const
QStringList lines = originalFileContent.split(
'\n'
);
79
for
(
const
QString &line : lines )
80
{
81
const
QStringList lineParts = line.split(
'|'
);
82
if
( lineParts.size() < 3 )
83
continue
;
84
85
const
QString algorithmId = lineParts.at( 0 );
86
const
QString outputName = lineParts.at( 1 );
87
if
( algorithmId.isEmpty() || outputName.isEmpty() )
88
continue
;
89
90
const
QString qmlFilePath = lineParts.mid( 2 ).join(
'|'
);
91
92
mStyles[algorithmId][outputName] = qmlFilePath;
93
}
94
}
95
96
void
QgsProcessingDefaultStyleRegistry::saveStyles
()
97
{
98
const
QString filePath = configFilePath();
99
100
QFile file( filePath );
101
if
( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
102
{
103
file.close();
104
return
;
105
}
106
107
QTextStream out( &file );
108
for
(
auto
algIt = mStyles.constBegin(); algIt != mStyles.constEnd(); ++algIt )
109
{
110
for
(
auto
outputIt = algIt->constBegin(); outputIt != algIt->constEnd(); ++outputIt )
111
{
112
out << algIt.key() <<
'|'
<< outputIt.key() <<
'|'
<< outputIt.value() <<
"\n"
;
113
}
114
}
115
116
file.close();
117
}
QgsProcessingDefaultStyleRegistry::loadStyles
void loadStyles()
Loads all saved styles from the configuration file.
Definition
qgsprocessingdefaultstyleregistry.cpp:64
QgsProcessingDefaultStyleRegistry::defaultStyleForOutput
QString defaultStyleForOutput(const QString &algorithmId, const QString &outputName) const
Returns the QML path to the default style to use for the specified output from an algorithm,...
Definition
qgsprocessingdefaultstyleregistry.cpp:53
QgsProcessingDefaultStyleRegistry::saveStyles
void saveStyles()
Saves registered styles to the configuration file.
Definition
qgsprocessingdefaultstyleregistry.cpp:96
QgsProcessingDefaultStyleRegistry::setDefaultStyleForOutput
void setDefaultStyleForOutput(const QString &algorithmId, const QString &outputName, const QString &qmlPath)
Sets the default style for an output from an algorithm.
Definition
qgsprocessingdefaultstyleregistry.cpp:34
QgsProcessingDefaultStyleRegistry::QgsProcessingDefaultStyleRegistry
QgsProcessingDefaultStyleRegistry(QObject *parent=nullptr)
Constructor for QgsProcessingDefaultStyleRegistry.
Definition
qgsprocessingdefaultstyleregistry.cpp:30
QgsProcessingUtils::userFolder
static QString userFolder()
Returns the location for Processing files stored within the user's current QGIS profile.
Definition
qgsprocessingutils.cpp:1852
qgsprocessingdefaultstyleregistry.h
qgsprocessingutils.h
Generated on
for QGIS API Documentation by
1.17.0