QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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 <QWidget>
23
24
26{
27 QVariant editorDataVariant = widget->property( "SETTING-EDITOR-WIDGET-WRAPPER" );
28 if ( editorDataVariant.isValid() )
29 {
30 return editorDataVariant.value<QgsSettingsEditorWidgetWrapper *>();
31 }
32
33 return nullptr;
34}
35
37 : QObject( parent )
38{
39}
40
41QWidget *QgsSettingsEditorWidgetWrapper::createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent )
42{
43 QWidget *editor = createEditorPrivate( parent );
44 if ( configureEditor( editor, setting, dynamicKeyPartList ) )
45 return editor;
46 else
47 QgsDebugError( QStringLiteral( "editor could not be configured" ) );
48 return nullptr;
49}
50
51bool QgsSettingsEditorWidgetWrapper::configureEditor( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList )
52{
53 mDynamicKeyPartList = dynamicKeyPartList;
54
55 bool ok = configureEditorPrivate( editor, setting );
56
57 if ( ok )
58 editor->setProperty( "SETTING-EDITOR-WIDGET-WRAPPER", QVariant::fromValue( this ) );
59
60 return ok;
61}
Base class for settings editor wrappers.
static QgsSettingsEditorWidgetWrapper * fromWidget(const QWidget *widget)
Creates a wrapper from the definition stored in a widget created by createEditor()
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 bool configureEditorPrivate(QWidget *editor, const QgsSettingsEntryBase *setting)=0
Configures an existing editor widget.
QgsSettingsEditorWidgetWrapper(QObject *parent=nullptr)
Constructor.
Represent settings entry and provides methods for reading and writing settings values.
#define QgsDebugError(str)
Definition qgslogger.h:38