QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
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
18#include "moc_qgssettingseditorwidgetwrapper.cpp"
19
20#include "qgslogger.h"
21#include "qgssettingsentry.h"
22
23#include <QDialog>
24#include <QWidget>
25
26
28{
29 QVariant editorDataVariant = widget->property( "SETTING-EDITOR-WIDGET-WRAPPER" );
30 if ( editorDataVariant.isValid() )
31 {
32 return editorDataVariant.value<QgsSettingsEditorWidgetWrapper *>();
33 }
34
35 return nullptr;
36}
37
39 : QObject( parent )
40{
41}
42
43QWidget *QgsSettingsEditorWidgetWrapper::createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent )
44{
45 QWidget *editor = createEditorPrivate( parent );
46 if ( configureEditor( editor, setting, dynamicKeyPartList ) )
47 return editor;
48 else
49 QgsDebugError( QStringLiteral( "editor could not be configured" ) );
50 return nullptr;
51}
52
53bool QgsSettingsEditorWidgetWrapper::configureEditor( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList )
54{
56
57 bool ok = configureEditorPrivate( editor, setting );
58
59 if ( ok )
60 {
61 editor->setProperty( "SETTING-EDITOR-WIDGET-WRAPPER", QVariant::fromValue( this ) );
63 }
64 return ok;
65}
66
68{
70 if ( dialog )
71 {
72 QObject::connect( dialog, &QDialog::accepted, this, [=]() {
74 } );
75 }
76 else
77 {
79 }
80}
Base class for settings editor wrappers.
virtual bool setWidgetFromSetting() const =0
Sets the widget value from the setting value The wrapper must be configured before calling this medth...
QStringList dynamicKeyPartList() const
Returns the dynamic key parts.
static QgsSettingsEditorWidgetWrapper * fromWidget(const QWidget *widget)
Creates a wrapper from the definition stored in a widget created by createEditor()
virtual bool setSettingFromWidget() const =0
Sets the setting value from the widget value The wrapper must be configured before calling this medth...
QWidget * createEditor(const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList(), QWidget *parent=nullptr)
Creates the editor widget for the given setting.
virtual QWidget * createEditorPrivate(QWidget *parent=nullptr) const =0
Creates the widgets.
bool configureEditor(QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList=QStringList())
Configures the editor according the setting.
virtual void enableAutomaticUpdatePrivate()=0
Enables automatic update, which causes the setting to be updated immediately when the widget value is...
virtual bool configureEditorPrivate(QWidget *editor, const QgsSettingsEntryBase *setting)=0
Configures an existing editor widget.
void configureAutomaticUpdate(QDialog *dialog=nullptr)
Configure the settings update behavior when a widget value is changed.
QgsSettingsEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
Represent settings entry and provides methods for reading and writing settings values.
#define QgsDebugError(str)
Definition qgslogger.h:38