Skip to content
Permalink
Browse files

Add a default editor widget factory

for safety when working without initialized widget registry in standalone apps and tests
  • Loading branch information
m-kuhn committed May 17, 2018
1 parent 9963892 commit 2b950319ec67b5f30e17a27184e4e12ffcd62c10
@@ -40,6 +40,11 @@
#include "qgsvaluemapwidgetfactory.h"
#include "qgsvaluerelationwidgetfactory.h"

QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()
{
mFallbackWidgetFactory.reset( new QgsTextEditWidgetFactory( tr( "Text Edit" ) ) );
}

void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas *mapCanvas, QgsMessageBar *messageBar )
{
registerWidget( QStringLiteral( "TextEdit" ), new QgsTextEditWidgetFactory( tr( "Text Edit" ) ) );
@@ -163,7 +168,7 @@ QMap<QString, QgsEditorWidgetFactory *> QgsEditorWidgetRegistry::factories()

QgsEditorWidgetFactory *QgsEditorWidgetRegistry::factory( const QString &widgetId )
{
return mWidgetFactories.value( widgetId );
return mWidgetFactories.value( widgetId, mFallbackWidgetFactory.get() );
}

bool QgsEditorWidgetRegistry::registerWidget( const QString &widgetId, QgsEditorWidgetFactory *widgetFactory )
@@ -52,7 +52,7 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
* Constructor for QgsEditorWidgetRegistry. QgsEditorWidgetRegistry is not usually directly created, but rather accessed through
* QgsGui::editorWidgetRegistry().
*/
QgsEditorWidgetRegistry() = default;
QgsEditorWidgetRegistry();

/**
* Registers all the default widgets.
@@ -188,6 +188,7 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
QMap<QString, QgsEditorWidgetFactory *> mWidgetFactories;
QMap<const char *, QPair<int, QString> > mFactoriesByType;
QgsEditorWidgetAutoConf mAutoConf;
std::unique_ptr<QgsEditorWidgetFactory> mFallbackWidgetFactory = nullptr;
};

#endif // QGSEDITORWIDGETREGISTRY_H

0 comments on commit 2b95031

Please sign in to comment.
You can’t perform that action at this time.