-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add registry of settings editors wrappers
- Loading branch information
Showing
4 changed files
with
153 additions
and
1 deletion.
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
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
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,72 @@ | ||
/*************************************************************************** | ||
qgssettingsfactoryfactoryregistry.cpp | ||
--------------------- | ||
begin : April 2023 | ||
copyright : (C) 2023 by Denis Rouzaud | ||
email : [email protected] | ||
*************************************************************************** | ||
* * | ||
* 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 "qgssettingseditorwidgetregistry.h" | ||
|
||
#include "qgslogger.h" | ||
#include "qgssettingseditorwidgetwrapper.h" | ||
#include "qgssettingseditorwidgetwrapperimpl.h" | ||
#include "qgssettingsentry.h" | ||
|
||
QgsSettingsEditorWidgetRegistry::QgsSettingsEditorWidgetRegistry() | ||
{ | ||
addWrapper( new QgsSettingsStringEditorWidgetWrapper() ); | ||
addWrapper( new QgsSettingsBoolEditorWidgetWrapper() ); | ||
addWrapper( new QgsSettingsIntegerEditorWidgetWrapper() ); | ||
addWrapper( new QgsSettingsDoubleEditorWidgetWrapper() ); | ||
addWrapper( new QgsSettingsColorEditorWidgetWrapper() ); | ||
|
||
} | ||
|
||
QgsSettingsEditorWidgetRegistry::~QgsSettingsEditorWidgetRegistry() | ||
{ | ||
qDeleteAll( mWrappers ); | ||
} | ||
|
||
bool QgsSettingsEditorWidgetRegistry::addWrapper( QgsSettingsEditorWidgetWrapper *wrapper ) | ||
{ | ||
if ( mWrappers.contains( wrapper->id() ) ) | ||
return false; | ||
|
||
mWrappers.insert( wrapper->id(), wrapper ); | ||
return true; | ||
} | ||
|
||
QgsSettingsEditorWidgetWrapper *QgsSettingsEditorWidgetRegistry::createWrapper( const QString &id, QObject *parent ) const | ||
{ | ||
QgsSettingsEditorWidgetWrapper *wrapper = mWrappers.value( id ); | ||
if ( wrapper ) | ||
{ | ||
return wrapper->createWrapper( parent ); | ||
} | ||
else | ||
{ | ||
QgsDebugMsg( QStringLiteral( "Setting factory was not found for '%1', returning the default string factory" ).arg( id ) ); | ||
return nullptr; | ||
} | ||
} | ||
|
||
QWidget *QgsSettingsEditorWidgetRegistry::createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent ) const | ||
{ | ||
QgsSettingsEditorWidgetWrapper *eww = createWrapper( setting->typeId(), parent ); | ||
if ( eww ) | ||
return eww->createEditor( setting, dynamicKeyPartList, parent ); | ||
else | ||
return nullptr; | ||
} | ||
|
||
|
||
|
||
|
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,62 @@ | ||
/*************************************************************************** | ||
qgssettingseditorwidgetregistry.h | ||
--------------------- | ||
begin : April 2023 | ||
copyright : (C) 2023 by Denis Rouzaud | ||
email : [email protected] | ||
*************************************************************************** | ||
* * | ||
* 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 QGSSETTINGSEDITORREGISTRY_H | ||
#define QGSSETTINGSEDITORREGISTRY_H | ||
|
||
#include <QObject> | ||
#include <QMap> | ||
|
||
#include "qgis_gui.h" | ||
#include "qgis_sip.h" | ||
|
||
class QWidget; | ||
class QgsSettingsEntryBase; | ||
class QgsSettingsEditorWidgetWrapper; | ||
|
||
/** | ||
* \ingroup gui | ||
* \brief This class manages editors for settings | ||
* | ||
* \since QGIS 3.32 | ||
*/ | ||
class GUI_EXPORT QgsSettingsEditorWidgetRegistry | ||
{ | ||
public: | ||
//! Constructor | ||
QgsSettingsEditorWidgetRegistry(); | ||
~QgsSettingsEditorWidgetRegistry(); | ||
|
||
/** | ||
* Adds a editor to the registry | ||
* Returns FALSE if a editor with same id already exists. | ||
*/ | ||
bool addWrapper( QgsSettingsEditorWidgetWrapper *wrapper SIP_TRANSFER ); | ||
|
||
//! Returns a new instance of the editor for the given id | ||
QgsSettingsEditorWidgetWrapper *createWrapper( const QString &id, QObject *parent ) const; | ||
|
||
//! Creates the editor for the given settings using the corresponding registered wrapper | ||
QWidget *createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent = nullptr ) const SIP_FACTORY; | ||
|
||
//! Returns a map <name, id> of all registered editors. | ||
QMap<QString, QString> editorNames() const; | ||
|
||
|
||
private: | ||
QMap<QString, QgsSettingsEditorWidgetWrapper *> mWrappers; | ||
}; | ||
|
||
#endif // QGSSETTINGSEDITORREGISTRY_H |