Skip to content

Commit

Permalink
adds option to specify encoding for input tables. addresses #2628
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14670 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed Nov 14, 2010
1 parent 7c4b7e8 commit 8e5a782
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 17 additions & 2 deletions python/plugins/fTools/tools/doJoinAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ def __init__(self, iface):
QObject.connect(self.toolTable, SIGNAL("clicked()"), self.inFile)
QObject.connect(self.rdoTable, SIGNAL("clicked()"), self.updateTableFields)
QObject.connect(self.rdoVector, SIGNAL("clicked()"), self.jupdate)
QObject.connect(self.cmbEncoding, SIGNAL("currentIndexChanged(QString)"),
self.updateTableFields)
self.setWindowTitle( self.tr("Join attributes") )
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
# populate layer list
self.progressBar.setValue(0)
mapCanvas = self.iface.mapCanvas()
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
encodings = QgsVectorDataProvider.availableEncodings()
self.cmbEncoding.addItems(encodings)
id = encodings.indexOf(QSettings().value( "/UI/encoding", "System").toString())
if id < 0:
id = len(encodings)-1
self.cmbEncoding.setCurrentIndex(id)
self.inShape.addItems(layers)
self.joinShape.addItems(layers)

Expand Down Expand Up @@ -103,7 +111,10 @@ def accept(self):
useTable = True
joinField = self.joinField.currentText()
outPath = self.outShape.text()
res = self.compute(inName, inField, joinName, joinField, outPath, keep, useTable, self.progressBar)
encoding = self.cmbEncoding.currentText()
QSettings().setValue( "/UI/encoding", encoding)
res = self.compute(inName, inField, joinName, joinField,
outPath, keep, useTable, encoding, self.progressBar)
self.outShape.clear()
if res:
addToTOC = QMessageBox.question(self, self.tr("Join Attributes"),
Expand Down Expand Up @@ -146,6 +157,8 @@ def updateTableFields(self):
joinName = joinInfo.completeBaseName()
self.joinField.clear()
changedLayer = QgsVectorLayer(joinPath, joinName, 'ogr')
encoding = self.cmbEncoding.currentText()
changedLayer.setProviderEncoding(encoding)
try:
changedField = ftools_utils.getFieldList(changedLayer)
except:
Expand All @@ -154,7 +167,8 @@ def updateTableFields(self):
for i in changedField:
self.joinField.addItem(unicode(changedField[i].name()))

def compute(self, inName, inField, joinName, joinField, outName, keep, useTable, progressBar):
def compute(self, inName, inField, joinName, joinField, outName,
keep, useTable, encoding, progressBar):
layer1 = ftools_utils.getVectorLayerByName(inName)
provider1 = layer1.dataProvider()
allAttrs = provider1.attributeIndexes()
Expand All @@ -166,6 +180,7 @@ def compute(self, inName, inField, joinName, joinField, outName, keep, useTable,
joinPath = joinInfo.absoluteFilePath()
joinName = joinInfo.completeBaseName()
layer2 = QgsVectorLayer(joinPath, joinName, 'ogr')
layer2.setProviderEncoding(encoding)
useTable = False
else:
layer2 = ftools_utils.getVectorLayerByName(joinName)
Expand Down
18 changes: 16 additions & 2 deletions python/plugins/fTools/tools/frmJoinAttributes.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>417</width>
<width>431</width>
<height>562</height>
</rect>
</property>
Expand Down Expand Up @@ -53,7 +53,7 @@
<property name="title">
<string>Join data</string>
</property>
<layout class="QGridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout">
<item>
Expand Down Expand Up @@ -120,6 +120,20 @@
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="labEncoding">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbEncoding"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 8e5a782

Please sign in to comment.