Skip to content

Commit 9ab5f7d

Browse files
author
cfarmer
committedNov 14, 2010
adds option to specify encoding for input tables. addresses #2628
git-svn-id: http://svn.osgeo.org/qgis/trunk@14670 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6ea778d commit 9ab5f7d

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed
 

‎python/plugins/fTools/tools/doJoinAttributes.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ def __init__(self, iface):
5252
QObject.connect(self.toolTable, SIGNAL("clicked()"), self.inFile)
5353
QObject.connect(self.rdoTable, SIGNAL("clicked()"), self.updateTableFields)
5454
QObject.connect(self.rdoVector, SIGNAL("clicked()"), self.jupdate)
55+
QObject.connect(self.cmbEncoding, SIGNAL("currentIndexChanged(QString)"),
56+
self.updateTableFields)
5557
self.setWindowTitle( self.tr("Join attributes") )
5658
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
5759
# populate layer list
5860
self.progressBar.setValue(0)
5961
mapCanvas = self.iface.mapCanvas()
6062
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
63+
encodings = QgsVectorDataProvider.availableEncodings()
64+
self.cmbEncoding.addItems(encodings)
65+
id = encodings.indexOf(QSettings().value( "/UI/encoding", "System").toString())
66+
if id < 0:
67+
id = len(encodings)-1
68+
self.cmbEncoding.setCurrentIndex(id)
6169
self.inShape.addItems(layers)
6270
self.joinShape.addItems(layers)
6371

@@ -103,7 +111,10 @@ def accept(self):
103111
useTable = True
104112
joinField = self.joinField.currentText()
105113
outPath = self.outShape.text()
106-
res = self.compute(inName, inField, joinName, joinField, outPath, keep, useTable, self.progressBar)
114+
encoding = self.cmbEncoding.currentText()
115+
QSettings().setValue( "/UI/encoding", encoding)
116+
res = self.compute(inName, inField, joinName, joinField,
117+
outPath, keep, useTable, encoding, self.progressBar)
107118
self.outShape.clear()
108119
if res:
109120
addToTOC = QMessageBox.question(self, self.tr("Join Attributes"),
@@ -146,6 +157,8 @@ def updateTableFields(self):
146157
joinName = joinInfo.completeBaseName()
147158
self.joinField.clear()
148159
changedLayer = QgsVectorLayer(joinPath, joinName, 'ogr')
160+
encoding = self.cmbEncoding.currentText()
161+
changedLayer.setProviderEncoding(encoding)
149162
try:
150163
changedField = ftools_utils.getFieldList(changedLayer)
151164
except:
@@ -154,7 +167,8 @@ def updateTableFields(self):
154167
for i in changedField:
155168
self.joinField.addItem(unicode(changedField[i].name()))
156169

157-
def compute(self, inName, inField, joinName, joinField, outName, keep, useTable, progressBar):
170+
def compute(self, inName, inField, joinName, joinField, outName,
171+
keep, useTable, encoding, progressBar):
158172
layer1 = ftools_utils.getVectorLayerByName(inName)
159173
provider1 = layer1.dataProvider()
160174
allAttrs = provider1.attributeIndexes()
@@ -166,6 +180,7 @@ def compute(self, inName, inField, joinName, joinField, outName, keep, useTable,
166180
joinPath = joinInfo.absoluteFilePath()
167181
joinName = joinInfo.completeBaseName()
168182
layer2 = QgsVectorLayer(joinPath, joinName, 'ogr')
183+
layer2.setProviderEncoding(encoding)
169184
useTable = False
170185
else:
171186
layer2 = ftools_utils.getVectorLayerByName(joinName)

‎python/plugins/fTools/tools/frmJoinAttributes.ui

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<rect>
1010
<x>0</x>
1111
<y>0</y>
12-
<width>417</width>
12+
<width>431</width>
1313
<height>562</height>
1414
</rect>
1515
</property>
@@ -53,7 +53,7 @@
5353
<property name="title">
5454
<string>Join data</string>
5555
</property>
56-
<layout class="QGridLayout">
56+
<layout class="QGridLayout" name="gridLayout_2">
5757
<item row="0" column="0">
5858
<layout class="QVBoxLayout">
5959
<item>
@@ -120,6 +120,20 @@
120120
</item>
121121
</layout>
122122
</item>
123+
<item row="3" column="0">
124+
<layout class="QVBoxLayout" name="verticalLayout">
125+
<item>
126+
<widget class="QLabel" name="labEncoding">
127+
<property name="text">
128+
<string>Encoding</string>
129+
</property>
130+
</widget>
131+
</item>
132+
<item>
133+
<widget class="QComboBox" name="cmbEncoding"/>
134+
</item>
135+
</layout>
136+
</item>
123137
</layout>
124138
</widget>
125139
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.