Skip to content

Commit

Permalink
Don't use auto generated widgets for fields with provider default
Browse files Browse the repository at this point in the history
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 af016cf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetautoconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 )
{
Expand Down

1 comment on commit af016cf

@stev-0
Copy link
Contributor

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.