Skip to content
Permalink
Browse files

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)
  • Loading branch information
wonder-sk committed Oct 21, 2011
1 parent 5b53d93 commit 5b2f944aa1392f9f48617eb56a0776f48f8b728c
@@ -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() );

@@ -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 */
@@ -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 )
@@ -372,8 +372,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>755</width>
<height>526</height>
<width>761</width>
<height>539</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
@@ -509,7 +509,7 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QGroupBox" name="grpSubset">
<property name="title">
<string>Subset</string>
@@ -557,6 +557,25 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="grpProviderOptions">
<property name="title">
<string>Provider-specific options</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cboProviderEncoding"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
@@ -768,6 +787,36 @@
<string>Appearance</string>
</property>
<layout class="QGridLayout" name="gridLayout_13">
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="mPenColorLabel">
<property name="text">
<string>Pen color</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="mDiagramPenColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>25</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
@@ -817,6 +866,19 @@
</item>
</layout>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="mDiagramFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Font...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
@@ -851,49 +913,6 @@
</item>
</layout>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="mDiagramFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Font...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="mPenColorLabel">
<property name="text">
<string>Pen color</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="mDiagramPenColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>25</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder></zorder>
<zorder></zorder>

0 comments on commit 5b2f944

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