mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-22 00:06:12 -05:00
Unset attribute values are always compatible with all field types
Refs #38913
This commit is contained in:
parent
db546ff142
commit
cc327f8503
@ -20,6 +20,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsreferencedgeometry.h"
|
||||
#include "qgsvariantutils.h"
|
||||
#include "qgsunsetattributevalue.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QIcon>
|
||||
@ -482,6 +483,11 @@ bool QgsField::convertCompatible( QVariant &v, QString *errorMessage ) const
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( v.userType() == qMetaTypeId< QgsUnsetAttributeValue >() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( d->type == QMetaType::Type::Int && v.toInt() != v.toLongLong() )
|
||||
{
|
||||
v = QgsVariantUtils::createNullVariant( d->type );
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgstest.h"
|
||||
#include "qgsreferencedgeometry.h"
|
||||
#include "qgsunsetattributevalue.h"
|
||||
|
||||
class TestQgsField : public QObject
|
||||
{
|
||||
@ -603,6 +604,9 @@ void TestQgsField::convertCompatible()
|
||||
QVERIFY( stringField.convertCompatible( nullDouble ) );
|
||||
QCOMPARE( static_cast<QMetaType::Type>( nullDouble.userType() ), QMetaType::Type::QString );
|
||||
QVERIFY( nullDouble.isNull() );
|
||||
QVariant unsetValue = QgsUnsetAttributeValue( QStringLiteral( "Autonumber" ) );
|
||||
QVERIFY( stringField.convertCompatible( unsetValue ) );
|
||||
QCOMPARE( static_cast<QMetaType::Type>( unsetValue.userType() ), qMetaTypeId< QgsUnsetAttributeValue >() );
|
||||
|
||||
//test double
|
||||
const QgsField doubleField( QStringLiteral( "double" ), QMetaType::Type::Double, QStringLiteral( "double" ) );
|
||||
@ -636,6 +640,9 @@ void TestQgsField::convertCompatible()
|
||||
QVERIFY( doubleField.convertCompatible( nullDouble ) );
|
||||
QCOMPARE( static_cast<QMetaType::Type>( nullDouble.userType() ), QMetaType::Type::Double );
|
||||
QVERIFY( nullDouble.isNull() );
|
||||
unsetValue = QgsUnsetAttributeValue( QStringLiteral( "Autonumber" ) );
|
||||
QVERIFY( doubleField.convertCompatible( unsetValue ) );
|
||||
QCOMPARE( static_cast<QMetaType::Type>( unsetValue.userType() ), qMetaTypeId< QgsUnsetAttributeValue >() );
|
||||
|
||||
//test special rules
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user