Skip to content

Commit 322c8f4

Browse files
committed
Preserve edits for multiline editor when length exceeds field size
Previously when using the multiline option for text edit widgets the entire contents of the field would be discarded if the entered value exceeded the maximum length for a string field. Now the entered string is truncated to the maximum field length. (cherry-picked from 7d8fba8)
1 parent d5ef91f commit 322c8f4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/gui/editorwidgets/qgstexteditwrapper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ QVariant QgsTextEditWrapper::value() const
6666

6767
QVariant res( v );
6868
if ( field().convertCompatible( res ) )
69+
{
6970
return res;
71+
}
72+
else if ( field().type() == QVariant::String && field().length() > 0 )
73+
{
74+
// for string fields convertCompatible may return false due to field length limit - in this case just truncate
75+
// input rather then discarding it entirely
76+
return QVariant( v.left( field().length() ) );
77+
}
7078
else
79+
{
7180
return QVariant( field().type() );
81+
}
7282
}
7383

7484
QWidget* QgsTextEditWrapper::createWidget( QWidget* parent )

0 commit comments

Comments
 (0)