Skip to content
Permalink
Browse files

Don't use auto generated widgets for fields with provider default

value clause

Using auto widgets may cause the default value clause to be mangled,
eg by converting it to a number
  • Loading branch information
nyalldawson authored and m-kuhn committed Nov 16, 2016
1 parent 60bbd09 commit af016cfb94af9dae12c19b3a29716a350be32807
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/gui/editorwidgets/core/qgseditorwidgetautoconf.cpp
@@ -14,6 +14,7 @@
***************************************************************************/
#include "qgseditorwidgetautoconf.h"
#include "qgseditorwidgetregistry.h"
#include "qgsvectordataprovider.h"

/** \ingroup gui
* Widget auto conf plugin that guesses what widget type to use in function of what the widgets support.
@@ -87,8 +88,21 @@ QgsEditorWidgetSetup QgsEditorWidgetAutoConf::editorWidgetSetup( const QgsVector
{
QgsEditorWidgetSetup result( QStringLiteral( "TextEdit" ), QgsEditorWidgetConfig() );

if ( vl->fields().indexFromName( fieldName ) >= 0 )
int fieldIndex = vl->fields().indexFromName( fieldName );
if ( fieldIndex >= 0 )
{

if ( vl->fields().fieldOrigin( fieldIndex ) == QgsFields::OriginProvider )
{
// important check - for provider fields, we CANNOT use auto configured widgets if the field
// uses a default value clause - otherwise the widget will obliterate the default value clause
// (eg by trying to convert it to a number/date/etc). Instead we have to use a text edit
// widget so that the clause remains intact
int providerOrigin = vl->fields().fieldOriginIndex( fieldIndex );
if ( !vl->dataProvider()->defaultValueClause( providerOrigin ).isEmpty() )
return result;
}

int bestScore = 0;
Q_FOREACH ( QSharedPointer<QgsEditorWidgetAutoConfPlugin> cur, plugins )
{

0 comments on commit af016cf

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