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 )
{

1 comment on commit af016cf

@stev-0

This comment has been minimized.

Copy link
Contributor

@stev-0 stev-0 commented on af016cf Dec 10, 2020

Hi @nyalldawson - realise this is an old commit, but there are at least two issues people are raising that can be traced back to this - #40032 and #39106. I'm guessing that these are impossible to work around for the reasons stated and there is no "correct" answer here?

Please sign in to comment.