QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
settings
qgssettingseditorwidgetwrapper.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgssettingseditorwidgetwrapper.cpp
3
--------------------------------------
4
Date : February 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
17
#include "
qgssettingseditorwidgetwrapper.h
"
18
19
#include "
qgslogger.h
"
20
#include "
qgssettingsentry.h
"
21
22
#include <QDialog>
23
#include <QString>
24
#include <QWidget>
25
26
#include "moc_qgssettingseditorwidgetwrapper.cpp"
27
28
using namespace
Qt::StringLiterals;
29
30
QgsSettingsEditorWidgetWrapper
*
QgsSettingsEditorWidgetWrapper::fromWidget
(
const
QWidget *widget )
31
{
32
QVariant editorDataVariant = widget->property(
"SETTING-EDITOR-WIDGET-WRAPPER"
);
33
if
( editorDataVariant.isValid() )
34
{
35
return
editorDataVariant.value<
QgsSettingsEditorWidgetWrapper
*>();
36
}
37
38
return
nullptr
;
39
}
40
41
QgsSettingsEditorWidgetWrapper::QgsSettingsEditorWidgetWrapper
( QObject *parent )
42
: QObject( parent )
43
{}
44
45
QWidget *
QgsSettingsEditorWidgetWrapper::createEditor
(
const
QgsSettingsEntryBase
*setting,
const
QStringList &
dynamicKeyPartList
, QWidget *parent )
46
{
47
QWidget *editor =
createEditorPrivate
( parent );
48
if
(
configureEditor
( editor, setting,
dynamicKeyPartList
) )
49
return
editor;
50
else
51
QgsDebugError
( u
"editor could not be configured"
_s );
52
return
nullptr
;
53
}
54
55
bool
QgsSettingsEditorWidgetWrapper::configureEditor
( QWidget *editor,
const
QgsSettingsEntryBase
*setting,
const
QStringList &
dynamicKeyPartList
)
56
{
57
mDynamicKeyPartList
=
dynamicKeyPartList
;
58
59
bool
ok =
configureEditorPrivate
( editor, setting );
60
61
if
( ok )
62
{
63
editor->setProperty(
"SETTING-EDITOR-WIDGET-WRAPPER"
, QVariant::fromValue(
this
) );
64
setWidgetFromSetting
();
65
}
66
return
ok;
67
}
68
69
void
QgsSettingsEditorWidgetWrapper::configureAutomaticUpdate
( QDialog *dialog )
70
{
71
setWidgetFromSetting
();
72
if
( dialog )
73
{
74
QObject::connect( dialog, &QDialog::accepted,
this
, [
this
]() {
setSettingFromWidget
(); } );
75
}
76
else
77
{
78
enableAutomaticUpdatePrivate
();
79
}
80
}
QgsSettingsEditorWidgetWrapper::setWidgetFromSetting
virtual bool setWidgetFromSetting() const =0
Sets the widget value from the setting value The wrapper must be configured before calling this medth...
QgsSettingsEditorWidgetWrapper::dynamicKeyPartList
QStringList dynamicKeyPartList() const
Returns the dynamic key parts.
Definition
qgssettingseditorwidgetwrapper.h:101
QgsSettingsEditorWidgetWrapper::fromWidget
static QgsSettingsEditorWidgetWrapper * fromWidget(const QWidget *widget)
Creates a wrapper from the definition stored in a widget created by createEditor().
Definition
qgssettingseditorwidgetwrapper.cpp:30
QgsSettingsEditorWidgetWrapper::setSettingFromWidget
virtual bool setSettingFromWidget() const =0
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
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::mDynamicKeyPartList
QStringList mDynamicKeyPartList
Definition
qgssettingseditorwidgetwrapper.h:118
QgsSettingsEditorWidgetWrapper::createEditorPrivate
virtual QWidget * createEditorPrivate(QWidget *parent=nullptr) const =0
Creates the widgets.
QgsSettingsEditorWidgetWrapper::configureEditor
bool configureEditor(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Configures the editor according the setting.
Definition
qgssettingseditorwidgetwrapper.cpp:55
QgsSettingsEditorWidgetWrapper::enableAutomaticUpdatePrivate
virtual void enableAutomaticUpdatePrivate()=0
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
QgsSettingsEditorWidgetWrapper::configureEditorPrivate
virtual bool configureEditorPrivate(QWidget *editor, const QgsSettingsEntryBase *setting)=0
Configures an existing editor widget.
QgsSettingsEditorWidgetWrapper::configureAutomaticUpdate
void configureAutomaticUpdate(QDialog *dialog=nullptr)
Configure the settings update behavior when a widget value is changed.
Definition
qgssettingseditorwidgetwrapper.cpp:69
QgsSettingsEditorWidgetWrapper::QgsSettingsEditorWidgetWrapper
QgsSettingsEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
Definition
qgssettingseditorwidgetwrapper.cpp:41
QgsSettingsEntryBase
Represents a settings entry and provides methods for reading and writing settings values.
Definition
qgssettingsentry.h:49
qgslogger.h
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgssettingseditorwidgetwrapper.h
qgssettingsentry.h
Generated on
for QGIS API Documentation by
1.17.0