QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
19#include "qgslogger.h"
20#include "qgssettingsentry.h"
21
22#include <QDialog>
23#include <QWidget>
24
25
27{
28 QVariant editorDataVariant = widget->property( "SETTING-EDITOR-WIDGET-WRAPPER" );
29 if ( editorDataVariant.isValid() )
30 {
31 return editorDataVariant.value<QgsSettingsEditorWidgetWrapper *>();
32 }
33
34 return nullptr;
35}
36
38 : QObject( parent )
39{
40}
41
42QWidget *QgsSettingsEditorWidgetWrapper::createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent )
43{
44 QWidget *editor = createEditorPrivate( parent );
45 if ( configureEditor( editor, setting, dynamicKeyPartList ) )
46 return editor;
47 else
48 QgsDebugError( QStringLiteral( "editor could not be configured" ) );
49 return nullptr;
50}
51
52bool QgsSettingsEditorWidgetWrapper::configureEditor( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList )
53{
55
56 bool ok = configureEditorPrivate( editor, setting );
57
58 if ( ok )
59 {
60 editor->setProperty( "SETTING-EDITOR-WIDGET-WRAPPER", QVariant::fromValue( this ) );
62 }
63 return ok;
64}
65
67{
69 if ( dialog )
70 {
71 QObject::connect( dialog, &QDialog::accepted, this, [ = ]()
72 {
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