Skip to content
Permalink
Browse files

Disable encoding combobox in layer properties dialog for OGR provider…

… with OLCStringsAsUTF8==true (so when it doesn't work anyway). Patch from Minoru Akagi.
  • Loading branch information
borysiasty committed Apr 22, 2013
1 parent 4e4b0a9 commit 2073f87a220db5a061c794cb257f0401bed8b5d8
@@ -27,7 +27,7 @@ class QgsVectorDataProvider : QgsDataProvider
RandomSelectGeometryAtId = 1024,
SequentialSelectGeometryAtId = 2048,
CreateAttributeIndex = 4096,
SetEncoding = 8192,
SelectEncoding = 8192,
};

/** bitmask of all provider's editing capabilities */
@@ -160,7 +160,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
pbnIndex->setEnabled( false );
}

if ( capabilities & QgsVectorDataProvider::SetEncoding )
if ( capabilities & QgsVectorDataProvider::SelectEncoding )
{
cboProviderEncoding->addItems( QgsVectorDataProvider::availableEncodings() );
QString enc = layer->dataProvider()->encoding();
@@ -172,8 +172,16 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
}
cboProviderEncoding->setCurrentIndex( encindex );
}
else if ( layer->dataProvider()->name() == "ogr" )
{
// if OGR_L_TestCapability(OLCStringsAsUTF8) returns true, OGR provider encoding can be set to only UTF-8
// so make encoding box grayed out
cboProviderEncoding->addItem( layer->dataProvider()->encoding() );
cboProviderEncoding->setEnabled( false );
}
else
{
// other providers do not use mEncoding, so hide the group completely
mDataSourceEncodingFrame->hide();
}
}
@@ -391,7 +399,7 @@ void QgsVectorLayerProperties::apply()
// provider-specific options
if ( layer->dataProvider() )
{
if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SetEncoding )
if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SelectEncoding )
{
layer->setProviderEncoding( cboProviderEncoding->currentText() );
}
@@ -84,8 +84,8 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
/** DEPRECATED - do not use */
SequentialSelectGeometryAtId = 1 << 11,
CreateAttributeIndex = 1 << 12,
/** Uses mEncoding for conversion of 8-bit strings to unicode */
SetEncoding = 1 << 13,
/** allows user to select encoding */
SelectEncoding = 1 << 13,
};

/** bitmask of all provider's editing capabilities */
@@ -1198,7 +1198,7 @@ bool QgsOgrProvider::deleteFeature( QgsFeatureId id )

int QgsOgrProvider::capabilities() const
{
int ability = SetEncoding;
int ability = 0;

// collect abilities reported by OGR
if ( ogrLayer )
@@ -1289,6 +1289,15 @@ int QgsOgrProvider::capabilities() const
ability |= DeleteAttributes;
}

#if defined(OLCStringsAsUTF8)
if ( !OGR_L_TestCapability( ogrLayer, OLCStringsAsUTF8 ) )
{
ability |= SelectEncoding;
}
#else
ability |= SelectEncoding;
#endif

// OGR doesn't handle shapefiles without attributes, ie. missing DBFs well, fixes #803
if ( ogrDriverName == "ESRI Shapefile" )
{

0 comments on commit 2073f87

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