Skip to content

Commit

Permalink
fix #7503
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Apr 4, 2013
1 parent db1d6ab commit 052dab8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -333,6 +333,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(
ogrType = OFTReal; ogrType = OFTReal;
break; break;


case QVariant::Date:
ogrType = OFTDate;
break;

case QVariant::DateTime:
ogrType = OFTDateTime;
break;

default: default:
//assert(0 && "invalid variant type!"); //assert(0 && "invalid variant type!");
mErrorMessage = QObject::tr( "unsupported type for field %1" ) mErrorMessage = QObject::tr( "unsupported type for field %1" )
Expand Down Expand Up @@ -543,6 +551,23 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
case QVariant::String: case QVariant::String:
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() ); OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
break; break;
case QVariant::Date:
OGR_F_SetFieldDateTime( poFeature, ogrField,
attrValue.toDate().year(),
attrValue.toDate().month(),
attrValue.toDate().day(),
0, 0, 0, 0 );
break;
case QVariant::DateTime:
OGR_F_SetFieldDateTime( poFeature, ogrField,
attrValue.toDateTime().date().year(),
attrValue.toDateTime().date().month(),
attrValue.toDateTime().date().day(),
attrValue.toDateTime().time().hour(),
attrValue.toDateTime().time().minute(),
attrValue.toDateTime().time().second(),
0 );
break;
case QVariant::Invalid: case QVariant::Invalid:
break; break;
default: default:
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgshuesaturationfilter.cpp
Expand Up @@ -155,7 +155,7 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
QColor myColor; QColor myColor;
int h, s, l; int h, s, l;
int r, g, b, alpha; int r, g, b, alpha;
double alphaFactor; double alphaFactor = 1.0;


for ( size_t i = 0; i < ( size_t )width*height; i++ ) for ( size_t i = 0; i < ( size_t )width*height; i++ )
{ {
Expand Down
68 changes: 64 additions & 4 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -107,6 +107,14 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
ogrType = OFTReal; ogrType = OFTReal;
break; break;


case QVariant::Date:
ogrType = OFTDate;
break;

case QVariant::DateTime:
ogrType = OFTDateTime;
break;

default: default:
return false; return false;
} }
Expand Down Expand Up @@ -336,11 +344,12 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
QgsMessageLog::logMessage( tr( "Data source is invalid (%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), tr( "OGR" ) ); QgsMessageLog::logMessage( tr( "Data source is invalid (%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), tr( "OGR" ) );
} }


// FIXME: sync with app/qgsnewvectorlayerdialog.cpp
mNativeTypes mNativeTypes
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 1, 10 ) << QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 1, 10 )
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 1, 20, 0, 15 ) << QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 1, 20, 0, 15 )
<< QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 1, 255 ) << QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 1, 255 )
<< QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date )
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime )
; ;
} }


Expand Down Expand Up @@ -557,10 +566,10 @@ void QgsOgrProvider::loadFields()
{ {
case OFTInteger: varType = QVariant::Int; break; case OFTInteger: varType = QVariant::Int; break;
case OFTReal: varType = QVariant::Double; break; case OFTReal: varType = QVariant::Double; break;
// unsupported in OGR 1.3
//case OFTDateTime: varType = QVariant::DateTime; break;
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1400 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1400
case OFTString: varType = QVariant::String; break; case OFTDate: varType = QVariant::Date; break;
case OFTDateTime: varType = QVariant::DateTime; break;
case OFTString:
#endif #endif
default: varType = QVariant::String; // other unsupported, leave it as a string default: varType = QVariant::String; // other unsupported, leave it as a string
} }
Expand Down Expand Up @@ -800,6 +809,25 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
OGR_F_SetFieldDouble( feature, targetAttributeId, attrVal.toDouble() ); OGR_F_SetFieldDouble( feature, targetAttributeId, attrVal.toDouble() );
break; break;


case OFTDate:
OGR_F_SetFieldDateTime( feature, targetAttributeId,
attrVal.toDate().year(),
attrVal.toDate().month(),
attrVal.toDate().day(),
0, 0, 0,
0 );
break;
case OFTDateTime:
OGR_F_SetFieldDateTime( feature, targetAttributeId,
attrVal.toDateTime().date().year(),
attrVal.toDateTime().date().month(),
attrVal.toDateTime().date().day(),
attrVal.toDateTime().time().hour(),
attrVal.toDateTime().time().minute(),
attrVal.toDateTime().time().second(),
0 );
break;

case OFTString: case OFTString:
QgsDebugMsg( QString( "Writing string attribute %1 with %2, encoding %3" ) QgsDebugMsg( QString( "Writing string attribute %1 with %2, encoding %3" )
.arg( targetAttributeId ) .arg( targetAttributeId )
Expand Down Expand Up @@ -870,6 +898,12 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
case QVariant::Double: case QVariant::Double:
type = OFTReal; type = OFTReal;
break; break;
case QVariant::Date:
type = OFTDate;
break;
case QVariant::DateTime:
type = OFTDateTime;
break;
case QVariant::String: case QVariant::String:
type = OFTString; type = OFTString;
break; break;
Expand Down Expand Up @@ -976,6 +1010,24 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
case OFTReal: case OFTReal:
OGR_F_SetFieldDouble( of, f, it2->toDouble() ); OGR_F_SetFieldDouble( of, f, it2->toDouble() );
break; break;
case OFTDate:
OGR_F_SetFieldDateTime( of, f,
it2->toDate().year(),
it2->toDate().month(),
it2->toDate().day(),
0, 0, 0,
0 );
break;
case OFTDateTime:
OGR_F_SetFieldDateTime( of, f,
it2->toDateTime().date().year(),
it2->toDateTime().date().month(),
it2->toDateTime().date().day(),
it2->toDateTime().time().hour(),
it2->toDateTime().time().minute(),
it2->toDateTime().time().second(),
0 );
break;
case OFTString: case OFTString:
OGR_F_SetFieldString( of, f, mEncoding->fromUnicode( it2->toString() ).constData() ); OGR_F_SetFieldString( of, f, mEncoding->fromUnicode( it2->toString() ).constData() );
break; break;
Expand Down Expand Up @@ -1843,6 +1895,14 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
field = OGR_Fld_Create( TO8( it->first ), OFTString ); field = OGR_Fld_Create( TO8( it->first ), OFTString );
OGR_Fld_SetWidth( field, width ); OGR_Fld_SetWidth( field, width );
} }
else if ( fields[0] == "Date" )
{
field = OGR_Fld_Create( TO8( it->first ), OFTDate );
}
else if ( fields[0] == "DateTime" )
{
field = OGR_Fld_Create( TO8( it->first ), OFTDateTime );
}
else else
{ {
continue; continue;
Expand Down

0 comments on commit 052dab8

Please sign in to comment.