QGIS API Documentation 3.99.0-Master (18a1e75d814)
Loading...
Searching...
No Matches
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
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
17
18#include "qgis.h"
19#include "qgslogger.h"
22#include "qgssettingsentry.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
29#if defined( HAVE_QTSERIALPORT )
30#include <QSerialPort>
31#endif
32
33
35{
42
43 // enum
44#if defined( HAVE_QTSERIALPORT )
49#endif
61
65
66 // flags
68}
69
74
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
89{
90 mSpecificWrappers.insert( setting, wrapper );
91}
92
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
107QWidget *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}
A factory for editors of boolean settings with a checkbox.
A factory for editors of boolean settings with a group box.
A factory for editors of color settings with a color button.
A factory for editors for double settings with a double spin box.
void addWrapperForSetting(QgsSettingsEditorWidgetWrapper *wrapper, const QgsSettingsEntryBase *setting)
Adds an editor widget wrapper for a specific setting to the registry.
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.
bool addWrapper(QgsSettingsEditorWidgetWrapper *wrapper)
Adds an editor widget wrapper to the registry If an editor widget with same id already exists,...
QgsSettingsEditorWidgetWrapper * createWrapper(const QString &id, QObject *parent) const
Returns a new instance of the editor widget for the given id.
Base class for settings editor wrappers.
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.
QWidget * createEditor(const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList(), QWidget *parent=nullptr)
Creates the editor widget for the given setting.
virtual QString id() const =0
This id of the type of settings it handles.
Represents a settings entry and provides methods for reading and writing settings values.
virtual QString typeId() const
Returns the id of the type of settings This can be re-implemented in a custom implementation of a set...
A factory for editors for integer settings with a spin box.
A factory for editors for string settings with a line edit.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
#define QgsDebugError(str)
Definition qgslogger.h:59