Skip to content

Commit

Permalink
Add a default editor widget factory
Browse files Browse the repository at this point in the history
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 2b95031
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ) );
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.