mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-06 00:05:16 -04:00
check for GDAL Version and exclude by ifdef
This commit is contained in:
parent
de12239b7e
commit
40c6896fb9
@ -152,11 +152,13 @@ QgsFields QgsOgrUtils::readOgrFields( OGRFeatureH ogrFet, QTextCodec *encoding )
|
|||||||
varType = QVariant::DateTime;
|
varType = QVariant::DateTime;
|
||||||
break;
|
break;
|
||||||
case OFTString:
|
case OFTString:
|
||||||
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
|
||||||
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
|
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
|
||||||
varType = QVariant::Map;
|
varType = QVariant::Map;
|
||||||
else
|
else
|
||||||
varType = QVariant::String;
|
varType = QVariant::String;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
varType = QVariant::String; // other unsupported, leave it as a string
|
varType = QVariant::String; // other unsupported, leave it as a string
|
||||||
}
|
}
|
||||||
|
@ -155,12 +155,12 @@ bool QgsOgrProvider::convertField( QgsField &field, const QTextCodec &encoding )
|
|||||||
ogrType = OFTDateTime;
|
ogrType = OFTDateTime;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//not sure if needed, but for consistency
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
|
||||||
case QVariant::Map:
|
case QVariant::Map:
|
||||||
ogrType = OFTString;
|
ogrType = OFTString;
|
||||||
ogrSubType = OFSTJSON;
|
ogrSubType = OFSTJSON;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1049,6 +1049,7 @@ void QgsOgrProvider::loadFields()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OFTString:
|
case OFTString:
|
||||||
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
|
||||||
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
|
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
|
||||||
{
|
{
|
||||||
ogrSubType = OFSTJSON;
|
ogrSubType = OFSTJSON;
|
||||||
@ -1061,6 +1062,7 @@ void QgsOgrProvider::loadFields()
|
|||||||
varType = QVariant::String;
|
varType = QVariant::String;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
varType = QVariant::String; // other unsupported, leave it as a string
|
varType = QVariant::String; // other unsupported, leave it as a string
|
||||||
}
|
}
|
||||||
@ -1531,6 +1533,8 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
|
|||||||
case OFTString:
|
case OFTString:
|
||||||
{
|
{
|
||||||
QString stringValue;
|
QString stringValue;
|
||||||
|
|
||||||
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
|
||||||
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
|
if ( OGR_Fld_GetSubType( fldDef ) == OFSTJSON )
|
||||||
{
|
{
|
||||||
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( attrVal.toMap() ).toJson().data() );
|
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( attrVal.toMap() ).toJson().data() );
|
||||||
@ -1543,7 +1547,9 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags )
|
|||||||
{
|
{
|
||||||
stringValue = attrVal.toString();
|
stringValue = attrVal.toString();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
stringValue = attrVal.toString();
|
||||||
|
#endif
|
||||||
QgsDebugMsgLevel( QStringLiteral( "Writing string attribute %1 with %2, encoding %3" )
|
QgsDebugMsgLevel( QStringLiteral( "Writing string attribute %1 with %2, encoding %3" )
|
||||||
.arg( qgisAttId )
|
.arg( qgisAttId )
|
||||||
.arg( attrVal.toString(),
|
.arg( attrVal.toString(),
|
||||||
@ -1689,9 +1695,11 @@ bool QgsOgrProvider::addAttributeOGRLevel( const QgsField &field, bool &ignoreEr
|
|||||||
case QVariant::Bool:
|
case QVariant::Bool:
|
||||||
OGR_Fld_SetSubType( fielddefn.get(), OFSTBoolean );
|
OGR_Fld_SetSubType( fielddefn.get(), OFSTBoolean );
|
||||||
break;
|
break;
|
||||||
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
|
||||||
case QVariant::Map:
|
case QVariant::Map:
|
||||||
OGR_Fld_SetSubType( fielddefn.get(), OFSTJSON );
|
OGR_Fld_SetSubType( fielddefn.get(), OFSTJSON );
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2121,6 +2129,7 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
|
|||||||
case OFTString:
|
case OFTString:
|
||||||
{
|
{
|
||||||
QString stringValue;
|
QString stringValue;
|
||||||
|
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
|
||||||
if ( OGR_Fld_GetSubType( fd ) == OFSTJSON )
|
if ( OGR_Fld_GetSubType( fd ) == OFSTJSON )
|
||||||
{
|
{
|
||||||
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( it2->toMap() ).toJson().data() );
|
stringValue = QString::fromUtf8( QJsonDocument::fromVariant( it2->toMap() ).toJson().data() );
|
||||||
@ -2133,7 +2142,9 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
|
|||||||
{
|
{
|
||||||
stringValue = it2->toString();
|
stringValue = it2->toString();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
stringValue = it2->toString();
|
||||||
|
#endif
|
||||||
OGR_F_SetFieldString( of.get(), f, textEncoding()->fromUnicode( stringValue ).constData() );
|
OGR_F_SetFieldString( of.get(), f, textEncoding()->fromUnicode( stringValue ).constData() );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1231,6 +1231,9 @@ class TestPyQgsOGRProviderGpkg(unittest.TestCase):
|
|||||||
del vl2_external
|
del vl2_external
|
||||||
|
|
||||||
def testJson(self):
|
def testJson(self):
|
||||||
|
if int(gdal.VersionInfo('VERSION_NUM')) < GDAL_COMPUTE_VERSION(2, 4, 0):
|
||||||
|
return
|
||||||
|
|
||||||
tmpfile = os.path.join(self.basetestpath, 'test_json.gpkg')
|
tmpfile = os.path.join(self.basetestpath, 'test_json.gpkg')
|
||||||
testdata_path = unitTestDataPath('provider')
|
testdata_path = unitTestDataPath('provider')
|
||||||
shutil.copy(os.path.join(unitTestDataPath('provider'), 'test_json.gpkg'), tmpfile)
|
shutil.copy(os.path.join(unitTestDataPath('provider'), 'test_json.gpkg'), tmpfile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user