Skip to content

Commit

Permalink
[memorylayer] fix missing datetime field type
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 22, 2016
1 parent ac22e9b commit 9c0aaa9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/providers/memory/qgsmemoryprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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
"\\))?"
Expand Down Expand Up @@ -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 ) != "" )
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tests/src/python/test_provider_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9c0aaa9

Please sign in to comment.