Skip to content
Permalink
Browse files

Merge pull request #2713 from nirvn/fix_memory_layer_datetime

[memorylayer] fix missing datetime field type
  • Loading branch information
nyalldawson committed Jan 26, 2016
2 parents 7b01b41 + 9c0aaa9 commit e42819d4422317c6b0289b0f0b3932a81ae86e46
Showing with 13 additions and 3 deletions.
  1. +10 −2 src/providers/memory/qgsmemoryprovider.cpp
  2. +3 −1 tests/src/python/test_provider_memory.py
@@ -86,6 +86,7 @@ QgsMemoryProvider::QgsMemoryProvider( const QString& uri )

// date type
<< QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 )
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime, -1, -1, -1, -1 )

// integer types
<< QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), "int2", QVariant::Int, -1, -1, 0, 0 )
@@ -106,7 +107,7 @@ QgsMemoryProvider::QgsMemoryProvider( const QString& uri )
{
QList<QgsField> attributes;
QRegExp reFieldDef( "\\:"
"(int|integer|real|double|string|date)" // type
"(int|integer|real|double|string|date|datetime)" // type
"(?:\\((\\d+)" // length
"(?:\\,(\\d+))?" // precision
"\\))?"
@@ -142,7 +143,13 @@ QgsMemoryProvider::QgsMemoryProvider( const QString& uri )
{
type = QVariant::Date;
typeName = "date";
length = 10;
length = -1;
}
else if ( typeName == "datetime" )
{
type = QVariant::DateTime;
typeName = "datetime";
length = -1;
}

if ( reFieldDef.cap( 2 ) != "" )
@@ -350,6 +357,7 @@ bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
case QVariant::Double:
case QVariant::String:
case QVariant::Date:
case QVariant::DateTime:
case QVariant::LongLong:
break;
default:
@@ -191,7 +191,9 @@ def testSaveFields(self):
# Add some fields to the layer
myFields = [QgsField('TestInt', QVariant.Int, 'integer', 2, 0),
QgsField('TestDbl', QVariant.Double, 'double', 8, 6),
QgsField('TestString', QVariant.String, 'string', 50, 0)]
QgsField('TestString', QVariant.String, 'string', 50, 0),
QgsField('TestDate', QVariant.Date, 'date'),
QgsField('TestDateTime', QVariant.DateTime, 'datetime')]
assert myMemoryLayer.startEditing()
for f in myFields:
assert myMemoryLayer.addAttribute(f)

0 comments on commit e42819d

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