QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
settings
qgssettingseditorwidgetregistry.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgssettingseditorwidgetregistry.cpp
3
---------------------
4
begin : April 2023
5
copyright : (C) 2023 by Denis Rouzaud
6
email : denis@opengis.ch
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 "
qgssettingseditorwidgetregistry.h
"
17
18
#include "
qgis.h
"
19
#include "
qgslogger.h
"
20
#include "
qgssettingseditorwidgetwrapper.h
"
21
#include "
qgssettingseditorwidgetwrapperimpl.h
"
22
#include "
qgssettingsentry.h
"
23
#include "
qgssettingsenumflageditorwidgetwrapper.h
"
24
25
#include <QString>
26
27
using namespace
Qt::StringLiterals;
28
29
#if defined( HAVE_QTSERIALPORT )
30
#include <QSerialPort>
31
#endif
32
33
34
QgsSettingsEditorWidgetRegistry::QgsSettingsEditorWidgetRegistry
()
35
{
36
addWrapper
(
new
QgsSettingsStringLineEditWrapper
() );
37
addWrapper
(
new
QgsSettingsBoolCheckBoxWrapper
() );
38
addWrapper
(
new
QgsSettingsBoolGroupBoxWrapper
() );
39
addWrapper
(
new
QgsSettingsIntegerSpinBoxWrapper
() );
40
addWrapper
(
new
QgsSettingsDoubleSpinBoxWrapper
() );
41
addWrapper
(
new
QgsSettingsColorButtonWrapper
() );
42
43
// enum
44
#if defined( HAVE_QTSERIALPORT )
45
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<QSerialPort::DataBits>
() );
46
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<QSerialPort::FlowControl>
() );
47
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<QSerialPort::Parity>
() );
48
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<QSerialPort::StopBits>
() );
49
#endif
50
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::CaptureTechnique>
() );
51
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::DpiMode>
() );
52
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::EndCapStyle>
() );
53
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::GpsConnectionType>
() );
54
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::GpsInformationComponent>
() );
55
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::JoinStyle>
() );
56
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::MapRecenteringMode>
() );
57
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::MapToolUnit>
() );
58
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::SnappingMode>
() );
59
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::SnappingType>
() );
60
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::TilePixelRatio>
() );
61
62
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::VectorSimplificationAlgorithm>
() );
63
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qgis::VectorRenderingSimplificationFlags>
() );
64
addWrapper
(
new
QgsSettingsEnumEditorWidgetWrapper<Qt::TimeSpec>
() );
65
66
// flags
67
addWrapper
(
new
QgsSettingsFlagsEditorWidgetWrapper<Qgis::GpsInformationComponent, Qgis::GpsInformationComponents>
() );
68
}
69
70
QgsSettingsEditorWidgetRegistry::~QgsSettingsEditorWidgetRegistry
()
71
{
72
qDeleteAll( mWrappers );
73
}
74
75
bool
QgsSettingsEditorWidgetRegistry::addWrapper
(
QgsSettingsEditorWidgetWrapper
*wrapper )
76
{
77
if
( mWrappers.contains( wrapper->
id
() ) )
78
{
79
QgsDebugMsgLevel
( QString(
"Settings editor widget registry already contains a wrapper with id '%1'"
).arg( wrapper->
id
() ), 2 );
80
delete
wrapper;
81
return
false
;
82
}
83
84
mWrappers.insert( wrapper->
id
(), wrapper );
85
return
true
;
86
}
87
88
void
QgsSettingsEditorWidgetRegistry::addWrapperForSetting
(
QgsSettingsEditorWidgetWrapper
*wrapper,
const
QgsSettingsEntryBase
*setting )
89
{
90
mSpecificWrappers.insert( setting, wrapper );
91
}
92
93
QgsSettingsEditorWidgetWrapper
*
QgsSettingsEditorWidgetRegistry::createWrapper
(
const
QString &
id
, QObject *parent )
const
94
{
95
QgsSettingsEditorWidgetWrapper
*wrapper = mWrappers.value(
id
);
96
if
( wrapper )
97
{
98
return
wrapper->
createWrapper
( parent );
99
}
100
else
101
{
102
QgsDebugError
( u
"Setting factory was not found for '%1', returning the default string factory"
_s.arg(
id
) );
103
return
nullptr
;
104
}
105
}
106
107
QWidget *
QgsSettingsEditorWidgetRegistry::createEditor
(
const
QgsSettingsEntryBase
*setting,
const
QStringList &dynamicKeyPartList, QWidget *parent )
const
108
{
109
auto
it = mSpecificWrappers.constFind( setting );
110
if
( it != mSpecificWrappers.constEnd() )
111
{
112
return
it.value()->createEditor( setting, dynamicKeyPartList, parent );
113
}
114
QgsSettingsEditorWidgetWrapper
*eww =
createWrapper
( setting->
typeId
(), parent );
115
if
( eww )
116
return
eww->
createEditor
( setting, dynamicKeyPartList, parent );
117
else
118
return
nullptr
;
119
}
QgsSettingsBoolCheckBoxWrapper
A factory for editors of boolean settings with a checkbox.
Definition
qgssettingseditorwidgetwrapperimpl.h:200
QgsSettingsBoolGroupBoxWrapper
A factory for editors of boolean settings with a group box.
Definition
qgssettingseditorwidgetwrapperimpl.h:229
QgsSettingsColorButtonWrapper
A factory for editors of color settings with a color button.
Definition
qgssettingseditorwidgetwrapperimpl.h:321
QgsSettingsDoubleSpinBoxWrapper
A factory for editors for double settings with a double spin box.
Definition
qgssettingseditorwidgetwrapperimpl.h:291
QgsSettingsEditorWidgetRegistry::QgsSettingsEditorWidgetRegistry
QgsSettingsEditorWidgetRegistry()
Constructor.
Definition
qgssettingseditorwidgetregistry.cpp:34
QgsSettingsEditorWidgetRegistry::addWrapperForSetting
void addWrapperForSetting(QgsSettingsEditorWidgetWrapper *wrapper, const QgsSettingsEntryBase *setting)
Adds an editor widget wrapper for a specific setting to the registry.
Definition
qgssettingseditorwidgetregistry.cpp:88
QgsSettingsEditorWidgetRegistry::createEditor
QWidget * createEditor(const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent=nullptr) const
Creates an editor widget for the given setting using the corresponding registered wrapper.
Definition
qgssettingseditorwidgetregistry.cpp:107
QgsSettingsEditorWidgetRegistry::addWrapper
bool addWrapper(QgsSettingsEditorWidgetWrapper *wrapper)
Adds an editor widget wrapper to the registry If an editor widget with same id already exists,...
Definition
qgssettingseditorwidgetregistry.cpp:75
QgsSettingsEditorWidgetRegistry::createWrapper
QgsSettingsEditorWidgetWrapper * createWrapper(const QString &id, QObject *parent) const
Returns a new instance of the editor widget for the given id.
Definition
qgssettingseditorwidgetregistry.cpp:93
QgsSettingsEditorWidgetRegistry::~QgsSettingsEditorWidgetRegistry
~QgsSettingsEditorWidgetRegistry()
Definition
qgssettingseditorwidgetregistry.cpp:70
QgsSettingsEditorWidgetWrapper
Base class for settings editor wrappers.
Definition
qgssettingseditorwidgetwrapper.h:35
QgsSettingsEditorWidgetWrapper::createWrapper
virtual QgsSettingsEditorWidgetWrapper * createWrapper(QObject *parent=nullptr) const =0
Creates a new instance of the editor wrapper so it can be configured for a widget and a setting.
QgsSettingsEditorWidgetWrapper::createEditor
QWidget * createEditor(const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList(), QWidget *parent=nullptr)
Creates the editor widget for the given setting.
Definition
qgssettingseditorwidgetwrapper.cpp:45
QgsSettingsEditorWidgetWrapper::id
virtual QString id() const =0
This id of the type of settings it handles.
QgsSettingsEntryBase
Represents a settings entry and provides methods for reading and writing settings values.
Definition
qgssettingsentry.h:49
QgsSettingsEntryBase::typeId
virtual QString typeId() const
Returns the id of the type of settings This can be re-implemented in a custom implementation of a set...
Definition
qgssettingsentry.cpp:89
QgsSettingsEnumEditorWidgetWrapper
A factory for editors for enum settings.
Definition
qgssettingsenumflageditorwidgetwrapper.h:145
QgsSettingsFlagsEditorWidgetWrapper
A factory for editors of flags settings.
Definition
qgssettingsenumflageditorwidgetwrapper.h:41
QgsSettingsIntegerSpinBoxWrapper
A factory for editors for integer settings with a spin box.
Definition
qgssettingseditorwidgetwrapperimpl.h:261
QgsSettingsStringLineEditWrapper
A factory for editors for string settings with a line edit.
Definition
qgssettingseditorwidgetwrapperimpl.h:119
qgis.h
qgslogger.h
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgssettingseditorwidgetregistry.h
qgssettingseditorwidgetwrapper.h
qgssettingseditorwidgetwrapperimpl.h
qgssettingsentry.h
qgssettingsenumflageditorwidgetwrapper.h
Generated on
for QGIS API Documentation by
1.17.0