Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add base class and implementation of wrappers for settings editor wid…
…gets
- Loading branch information
Showing
4 changed files
with
735 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*************************************************************************** | ||
qgssettingseditorwidgetwrapper.cpp | ||
-------------------------------------- | ||
Date : February 2023 | ||
Copyright : (C) 2023 by Denis Rouzaud | ||
Email : denis@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "qgssettingseditorwidgetwrapper.h" | ||
|
||
#include "qgslogger.h" | ||
#include "qgssettingsentry.h" | ||
|
||
#include <QWidget> | ||
|
||
|
||
QgsSettingsEditorWidgetWrapper *QgsSettingsEditorWidgetWrapper::fromWidget( const QWidget *widget ) | ||
{ | ||
QVariant editorDataVariant = widget->property( "SETTING-EDITOR-WIDGET-WRAPPER" ); | ||
if ( editorDataVariant.isValid() ) | ||
{ | ||
return editorDataVariant.value<QgsSettingsEditorWidgetWrapper *>(); | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
QgsSettingsEditorWidgetWrapper::QgsSettingsEditorWidgetWrapper( QObject *parent ) | ||
: QObject( parent ) | ||
{ | ||
} | ||
|
||
QWidget *QgsSettingsEditorWidgetWrapper::createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent ) | ||
{ | ||
QWidget *editor = createEditorPrivate( parent ); | ||
if ( configureEditor( editor, setting, dynamicKeyPartList ) ) | ||
return editor; | ||
else | ||
QgsDebugMsg( QStringLiteral( "editor could not be confiugured" ) ); | ||
return nullptr; | ||
} | ||
|
||
bool QgsSettingsEditorWidgetWrapper::configureEditor( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList ) | ||
{ | ||
mDynamicKeyPartList = dynamicKeyPartList; | ||
|
||
bool ok = configureEditorPrivate( editor, setting ); | ||
|
||
if ( ok ) | ||
editor->setProperty( "SETTING-EDITOR-WIDGET-WRAPPER", QVariant::fromValue( this ) ); | ||
|
||
return ok; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*************************************************************************** | ||
qgssettingseditorwidgetwrapper.h | ||
-------------------------------------- | ||
Date : February 2023 | ||
Copyright : (C) 2023 by Denis Rouzaud | ||
Email : denis@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSETTINGSEDITORWIDGETWRAPPER_H | ||
#define QGSSETTINGSEDITORWIDGETWRAPPER_H | ||
|
||
#include <QVariant> | ||
|
||
#include "qgis_sip.h" | ||
#include "qgis_gui.h" | ||
|
||
class QgsSettingsEntryBase; | ||
|
||
/** | ||
* \ingroup gui | ||
* \brief Base class for settings editor wrappers | ||
* | ||
* \since QGIS 3.32 | ||
*/ | ||
class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
//! Creates a wrapper from the definition stored in a widget created by createEditor() | ||
static QgsSettingsEditorWidgetWrapper *fromWidget( const QWidget *widget ) SIP_FACTORY; | ||
|
||
//! Constructor | ||
QgsSettingsEditorWidgetWrapper( QObject *parent = nullptr ); | ||
|
||
virtual ~QgsSettingsEditorWidgetWrapper() = default; | ||
|
||
/** | ||
* This id of the type of settings it handles | ||
* \note This mostly correspond to the content of Qgis::SettingsType but it's a string since custom Python implementation are possible. | ||
*/ | ||
virtual QString id() const = 0; | ||
|
||
//! Creates a new instance of the editor wrapper so it can be configured for a widget and a setting | ||
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const = 0; | ||
|
||
//! Creates the editor for the given widget | ||
QWidget *createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList(), QWidget *parent = nullptr ); | ||
|
||
//! Configures the \a editor according the setting | ||
bool configureEditor( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() ); | ||
|
||
/** | ||
* Sets the widget value from the setting value | ||
* The wrapper must be configured before calling this medthod | ||
*/ | ||
virtual bool setWidgetFromSetting() const = 0; | ||
|
||
/** | ||
* SDets the setting value from the widget value | ||
* The wrapper must be configured before calling this medthod | ||
*/ | ||
virtual bool setSettingFromWidget() const = 0; | ||
|
||
/** | ||
* Returns the value from the widget as a variant | ||
* The wrapper must be configured before calling this medthod | ||
*/ | ||
virtual QVariant variantValueFromWidget() const = 0; | ||
|
||
/** | ||
* Sets the value of the widget | ||
* The wrapper must be configured before calling this medthod | ||
*/ | ||
virtual void setWidgetFromVariant( const QVariant &value ) const = 0; | ||
|
||
|
||
protected: | ||
virtual QWidget *createEditorPrivate( QWidget *parent = nullptr ) const = 0; | ||
|
||
virtual bool configureEditorPrivate( QWidget *editor, const QgsSettingsEntryBase *setting ) = 0; | ||
|
||
QStringList mDynamicKeyPartList; | ||
}; | ||
|
||
|
||
|
||
#endif // QGSSETTINGSEDITORWIDGETWRAPPER_H |
Oops, something went wrong.