From 5b2f944aa1392f9f48617eb56a0776f48f8b728c Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Fri, 21 Oct 2011 13:51:18 -0300 Subject: [PATCH] Allow setting I/O encoding for OGR layers in vector layer properties. Until now this was only possible to set when opening files with QgsEncodingFileDialog. Layers opened from browser were opened always with default encoding and no way to change it. The newly created "provider-specific" option group may be used by other providers for some custom actions ("create spatial index" should move here, too) --- src/app/qgsvectorlayerproperties.cpp | 27 ++++++ src/core/qgsvectordataprovider.h | 4 +- src/providers/ogr/qgsogrprovider.cpp | 2 +- src/ui/qgsvectorlayerpropertiesbase.ui | 111 +++++++++++++++---------- 4 files changed, 96 insertions(+), 48 deletions(-) diff --git a/src/app/qgsvectorlayerproperties.cpp b/src/app/qgsvectorlayerproperties.cpp index 9c52c837e6cc..2b8edf52bc83 100644 --- a/src/app/qgsvectorlayerproperties.cpp +++ b/src/app/qgsvectorlayerproperties.cpp @@ -126,6 +126,24 @@ QgsVectorLayerProperties::QgsVectorLayerProperties( { pbnIndex->setEnabled( false ); } + + if ( capabilities & QgsVectorDataProvider::SetEncoding ) + { + cboProviderEncoding->addItems( QgsVectorDataProvider::availableEncodings() ); + QString enc = layer->dataProvider()->encoding(); + int encindex = cboProviderEncoding->findText( enc ); + if ( encindex < 0 ) + { + cboProviderEncoding->insertItem( 0, enc ); + encindex = 0; + } + cboProviderEncoding->setCurrentIndex( encindex ); + } + else + { + // currently only encoding can be set in this group, so hide it completely + grpProviderOptions->hide(); + } } updateButtons(); @@ -589,6 +607,15 @@ void QgsVectorLayerProperties::apply() layer->setMinimumScale( leMinimumScale->text().toFloat() ); layer->setMaximumScale( leMaximumScale->text().toFloat() ); + // provider-specific options + if ( layer->dataProvider() ) + { + if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SetEncoding ) + { + layer->dataProvider()->setEncoding( cboProviderEncoding->currentText() ); + } + } + // update the display field layer->setDisplayField( displayFieldComboBox->currentText() ); diff --git a/src/core/qgsvectordataprovider.h b/src/core/qgsvectordataprovider.h index 0dc68a374f7a..a863b7228988 100644 --- a/src/core/qgsvectordataprovider.h +++ b/src/core/qgsvectordataprovider.h @@ -77,7 +77,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider RandomSelectGeometryAtId = 1 << 10, /** DEPRECATED - do not use */ SequentialSelectGeometryAtId = 1 << 11, - CreateAttributeIndex = 1 << 12 + CreateAttributeIndex = 1 << 12, + /** Uses mEncoding for conversion of 8-bit strings to unicode */ + SetEncoding = 1 << 13, }; /** bitmask of all provider's editing capabilities */ diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index 341bb1785094..efd9c072f1f5 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -1281,7 +1281,7 @@ bool QgsOgrProvider::deleteFeature( QgsFeatureId id ) int QgsOgrProvider::capabilities() const { - int ability = NoCapabilities; + int ability = SetEncoding; // collect abilities reported by OGR if ( ogrLayer ) diff --git a/src/ui/qgsvectorlayerpropertiesbase.ui b/src/ui/qgsvectorlayerpropertiesbase.ui index 5998a5704b32..f8622c7eabe2 100644 --- a/src/ui/qgsvectorlayerpropertiesbase.ui +++ b/src/ui/qgsvectorlayerpropertiesbase.ui @@ -372,8 +372,8 @@ 0 0 - 755 - 526 + 761 + 539 @@ -509,7 +509,7 @@ - + Subset @@ -557,6 +557,25 @@ + + + + Provider-specific options + + + + + + Encoding + + + + + + + + + @@ -768,6 +787,36 @@ Appearance + + + + + + Pen color + + + + + + + + 0 + 0 + + + + + 25 + 0 + + + + + + + + + @@ -817,6 +866,19 @@ + + + + + 0 + 0 + + + + Font... + + + @@ -851,49 +913,6 @@ - - - - - 0 - 0 - - - - Font... - - - - - - - - - Pen color - - - - - - - - 0 - 0 - - - - - 25 - 0 - - - - - - - - -