Skip to content

Commit

Permalink
Disable encoding combobox in layer properties dialog for OGR provider…
Browse files Browse the repository at this point in the history
… 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 2073f87
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsvectordataprovider.sip
Expand Up @@ -27,7 +27,7 @@ class QgsVectorDataProvider : QgsDataProvider
RandomSelectGeometryAtId = 1024,
SequentialSelectGeometryAtId = 2048,
CreateAttributeIndex = 4096,
SetEncoding = 8192,
SelectEncoding = 8192,
};

/** bitmask of all provider's editing capabilities */
Expand Down
12 changes: 10 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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();
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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() );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -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 */
Expand Down
11 changes: 10 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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" )
{
Expand Down

0 comments on commit 2073f87

Please sign in to comment.