Skip to content

Commit 052dab8

Browse files
committed
fix #7503
1 parent db1d6ab commit 052dab8

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

src/core/qgsvectorfilewriter.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(
333333
ogrType = OFTReal;
334334
break;
335335

336+
case QVariant::Date:
337+
ogrType = OFTDate;
338+
break;
339+
340+
case QVariant::DateTime:
341+
ogrType = OFTDateTime;
342+
break;
343+
336344
default:
337345
//assert(0 && "invalid variant type!");
338346
mErrorMessage = QObject::tr( "unsupported type for field %1" )
@@ -543,6 +551,23 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
543551
case QVariant::String:
544552
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
545553
break;
554+
case QVariant::Date:
555+
OGR_F_SetFieldDateTime( poFeature, ogrField,
556+
attrValue.toDate().year(),
557+
attrValue.toDate().month(),
558+
attrValue.toDate().day(),
559+
0, 0, 0, 0 );
560+
break;
561+
case QVariant::DateTime:
562+
OGR_F_SetFieldDateTime( poFeature, ogrField,
563+
attrValue.toDateTime().date().year(),
564+
attrValue.toDateTime().date().month(),
565+
attrValue.toDateTime().date().day(),
566+
attrValue.toDateTime().time().hour(),
567+
attrValue.toDateTime().time().minute(),
568+
attrValue.toDateTime().time().second(),
569+
0 );
570+
break;
546571
case QVariant::Invalid:
547572
break;
548573
default:

src/core/raster/qgshuesaturationfilter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
155155
QColor myColor;
156156
int h, s, l;
157157
int r, g, b, alpha;
158-
double alphaFactor;
158+
double alphaFactor = 1.0;
159159

160160
for ( size_t i = 0; i < ( size_t )width*height; i++ )
161161
{

src/providers/ogr/qgsogrprovider.cpp

+64-4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
107107
ogrType = OFTReal;
108108
break;
109109

110+
case QVariant::Date:
111+
ogrType = OFTDate;
112+
break;
113+
114+
case QVariant::DateTime:
115+
ogrType = OFTDateTime;
116+
break;
117+
110118
default:
111119
return false;
112120
}
@@ -336,11 +344,12 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
336344
QgsMessageLog::logMessage( tr( "Data source is invalid (%1)" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ), tr( "OGR" ) );
337345
}
338346

339-
// FIXME: sync with app/qgsnewvectorlayerdialog.cpp
340347
mNativeTypes
341348
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer)" ), "integer", QVariant::Int, 1, 10 )
342349
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 1, 20, 0, 15 )
343350
<< QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 1, 255 )
351+
<< QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date )
352+
<< QgsVectorDataProvider::NativeType( tr( "Date & Time" ), "datetime", QVariant::DateTime )
344353
;
345354
}
346355

@@ -557,10 +566,10 @@ void QgsOgrProvider::loadFields()
557566
{
558567
case OFTInteger: varType = QVariant::Int; break;
559568
case OFTReal: varType = QVariant::Double; break;
560-
// unsupported in OGR 1.3
561-
//case OFTDateTime: varType = QVariant::DateTime; break;
562569
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1400
563-
case OFTString: varType = QVariant::String; break;
570+
case OFTDate: varType = QVariant::Date; break;
571+
case OFTDateTime: varType = QVariant::DateTime; break;
572+
case OFTString:
564573
#endif
565574
default: varType = QVariant::String; // other unsupported, leave it as a string
566575
}
@@ -800,6 +809,25 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
800809
OGR_F_SetFieldDouble( feature, targetAttributeId, attrVal.toDouble() );
801810
break;
802811

812+
case OFTDate:
813+
OGR_F_SetFieldDateTime( feature, targetAttributeId,
814+
attrVal.toDate().year(),
815+
attrVal.toDate().month(),
816+
attrVal.toDate().day(),
817+
0, 0, 0,
818+
0 );
819+
break;
820+
case OFTDateTime:
821+
OGR_F_SetFieldDateTime( feature, targetAttributeId,
822+
attrVal.toDateTime().date().year(),
823+
attrVal.toDateTime().date().month(),
824+
attrVal.toDateTime().date().day(),
825+
attrVal.toDateTime().time().hour(),
826+
attrVal.toDateTime().time().minute(),
827+
attrVal.toDateTime().time().second(),
828+
0 );
829+
break;
830+
803831
case OFTString:
804832
QgsDebugMsg( QString( "Writing string attribute %1 with %2, encoding %3" )
805833
.arg( targetAttributeId )
@@ -870,6 +898,12 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
870898
case QVariant::Double:
871899
type = OFTReal;
872900
break;
901+
case QVariant::Date:
902+
type = OFTDate;
903+
break;
904+
case QVariant::DateTime:
905+
type = OFTDateTime;
906+
break;
873907
case QVariant::String:
874908
type = OFTString;
875909
break;
@@ -976,6 +1010,24 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap & attr
9761010
case OFTReal:
9771011
OGR_F_SetFieldDouble( of, f, it2->toDouble() );
9781012
break;
1013+
case OFTDate:
1014+
OGR_F_SetFieldDateTime( of, f,
1015+
it2->toDate().year(),
1016+
it2->toDate().month(),
1017+
it2->toDate().day(),
1018+
0, 0, 0,
1019+
0 );
1020+
break;
1021+
case OFTDateTime:
1022+
OGR_F_SetFieldDateTime( of, f,
1023+
it2->toDateTime().date().year(),
1024+
it2->toDateTime().date().month(),
1025+
it2->toDateTime().date().day(),
1026+
it2->toDateTime().time().hour(),
1027+
it2->toDateTime().time().minute(),
1028+
it2->toDateTime().time().second(),
1029+
0 );
1030+
break;
9791031
case OFTString:
9801032
OGR_F_SetFieldString( of, f, mEncoding->fromUnicode( it2->toString() ).constData() );
9811033
break;
@@ -1843,6 +1895,14 @@ QGISEXTERN bool createEmptyDataSource( const QString &uri,
18431895
field = OGR_Fld_Create( TO8( it->first ), OFTString );
18441896
OGR_Fld_SetWidth( field, width );
18451897
}
1898+
else if ( fields[0] == "Date" )
1899+
{
1900+
field = OGR_Fld_Create( TO8( it->first ), OFTDate );
1901+
}
1902+
else if ( fields[0] == "DateTime" )
1903+
{
1904+
field = OGR_Fld_Create( TO8( it->first ), OFTDateTime );
1905+
}
18461906
else
18471907
{
18481908
continue;

0 commit comments

Comments
 (0)