Skip to content

Commit 5b2f944

Browse files
committedOct 21, 2011
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)
1 parent 5b53d93 commit 5b2f944

File tree

4 files changed

+96
-48
lines changed

4 files changed

+96
-48
lines changed
 

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
126126
{
127127
pbnIndex->setEnabled( false );
128128
}
129+
130+
if ( capabilities & QgsVectorDataProvider::SetEncoding )
131+
{
132+
cboProviderEncoding->addItems( QgsVectorDataProvider::availableEncodings() );
133+
QString enc = layer->dataProvider()->encoding();
134+
int encindex = cboProviderEncoding->findText( enc );
135+
if ( encindex < 0 )
136+
{
137+
cboProviderEncoding->insertItem( 0, enc );
138+
encindex = 0;
139+
}
140+
cboProviderEncoding->setCurrentIndex( encindex );
141+
}
142+
else
143+
{
144+
// currently only encoding can be set in this group, so hide it completely
145+
grpProviderOptions->hide();
146+
}
129147
}
130148

131149
updateButtons();
@@ -589,6 +607,15 @@ void QgsVectorLayerProperties::apply()
589607
layer->setMinimumScale( leMinimumScale->text().toFloat() );
590608
layer->setMaximumScale( leMaximumScale->text().toFloat() );
591609

610+
// provider-specific options
611+
if ( layer->dataProvider() )
612+
{
613+
if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SetEncoding )
614+
{
615+
layer->dataProvider()->setEncoding( cboProviderEncoding->currentText() );
616+
}
617+
}
618+
592619
// update the display field
593620
layer->setDisplayField( displayFieldComboBox->currentText() );
594621

‎src/core/qgsvectordataprovider.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
7777
RandomSelectGeometryAtId = 1 << 10,
7878
/** DEPRECATED - do not use */
7979
SequentialSelectGeometryAtId = 1 << 11,
80-
CreateAttributeIndex = 1 << 12
80+
CreateAttributeIndex = 1 << 12,
81+
/** Uses mEncoding for conversion of 8-bit strings to unicode */
82+
SetEncoding = 1 << 13,
8183
};
8284

8385
/** bitmask of all provider's editing capabilities */

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ bool QgsOgrProvider::deleteFeature( QgsFeatureId id )
12811281

12821282
int QgsOgrProvider::capabilities() const
12831283
{
1284-
int ability = NoCapabilities;
1284+
int ability = SetEncoding;
12851285

12861286
// collect abilities reported by OGR
12871287
if ( ogrLayer )

‎src/ui/qgsvectorlayerpropertiesbase.ui

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@
372372
<rect>
373373
<x>0</x>
374374
<y>0</y>
375-
<width>755</width>
376-
<height>526</height>
375+
<width>761</width>
376+
<height>539</height>
377377
</rect>
378378
</property>
379379
<layout class="QGridLayout" name="gridLayout_3">
@@ -509,7 +509,7 @@
509509
</layout>
510510
</widget>
511511
</item>
512-
<item row="2" column="0">
512+
<item row="3" column="0">
513513
<widget class="QGroupBox" name="grpSubset">
514514
<property name="title">
515515
<string>Subset</string>
@@ -557,6 +557,25 @@
557557
</layout>
558558
</widget>
559559
</item>
560+
<item row="2" column="0">
561+
<widget class="QGroupBox" name="grpProviderOptions">
562+
<property name="title">
563+
<string>Provider-specific options</string>
564+
</property>
565+
<layout class="QFormLayout" name="formLayout">
566+
<item row="0" column="0">
567+
<widget class="QLabel" name="label_2">
568+
<property name="text">
569+
<string>Encoding</string>
570+
</property>
571+
</widget>
572+
</item>
573+
<item row="0" column="1">
574+
<widget class="QComboBox" name="cboProviderEncoding"/>
575+
</item>
576+
</layout>
577+
</widget>
578+
</item>
560579
</layout>
561580
</widget>
562581
</widget>
@@ -768,6 +787,36 @@
768787
<string>Appearance</string>
769788
</property>
770789
<layout class="QGridLayout" name="gridLayout_13">
790+
<item row="1" column="1">
791+
<layout class="QHBoxLayout" name="horizontalLayout_11">
792+
<item>
793+
<widget class="QLabel" name="mPenColorLabel">
794+
<property name="text">
795+
<string>Pen color</string>
796+
</property>
797+
</widget>
798+
</item>
799+
<item>
800+
<widget class="QgsColorButton" name="mDiagramPenColorButton">
801+
<property name="sizePolicy">
802+
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
803+
<horstretch>0</horstretch>
804+
<verstretch>0</verstretch>
805+
</sizepolicy>
806+
</property>
807+
<property name="minimumSize">
808+
<size>
809+
<width>25</width>
810+
<height>0</height>
811+
</size>
812+
</property>
813+
<property name="text">
814+
<string/>
815+
</property>
816+
</widget>
817+
</item>
818+
</layout>
819+
</item>
771820
<item row="1" column="2">
772821
<layout class="QHBoxLayout" name="horizontalLayout_16">
773822
<item>
@@ -817,6 +866,19 @@
817866
</item>
818867
</layout>
819868
</item>
869+
<item row="1" column="3">
870+
<widget class="QPushButton" name="mDiagramFontButton">
871+
<property name="sizePolicy">
872+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
873+
<horstretch>0</horstretch>
874+
<verstretch>0</verstretch>
875+
</sizepolicy>
876+
</property>
877+
<property name="text">
878+
<string>Font...</string>
879+
</property>
880+
</widget>
881+
</item>
820882
<item row="1" column="0">
821883
<layout class="QHBoxLayout" name="horizontalLayout_8">
822884
<item>
@@ -851,49 +913,6 @@
851913
</item>
852914
</layout>
853915
</item>
854-
<item row="1" column="3">
855-
<widget class="QPushButton" name="mDiagramFontButton">
856-
<property name="sizePolicy">
857-
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
858-
<horstretch>0</horstretch>
859-
<verstretch>0</verstretch>
860-
</sizepolicy>
861-
</property>
862-
<property name="text">
863-
<string>Font...</string>
864-
</property>
865-
</widget>
866-
</item>
867-
<item row="1" column="1">
868-
<layout class="QHBoxLayout" name="horizontalLayout_11">
869-
<item>
870-
<widget class="QLabel" name="mPenColorLabel">
871-
<property name="text">
872-
<string>Pen color</string>
873-
</property>
874-
</widget>
875-
</item>
876-
<item>
877-
<widget class="QgsColorButton" name="mDiagramPenColorButton">
878-
<property name="sizePolicy">
879-
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
880-
<horstretch>0</horstretch>
881-
<verstretch>0</verstretch>
882-
</sizepolicy>
883-
</property>
884-
<property name="minimumSize">
885-
<size>
886-
<width>25</width>
887-
<height>0</height>
888-
</size>
889-
</property>
890-
<property name="text">
891-
<string/>
892-
</property>
893-
</widget>
894-
</item>
895-
</layout>
896-
</item>
897916
</layout>
898917
<zorder></zorder>
899918
<zorder></zorder>

0 commit comments

Comments
 (0)
Please sign in to comment.