|
31 | 31 | QgsRelation,
|
32 | 32 | QgsEditorWidgetSetup
|
33 | 33 | )
|
34 |
| -from qgis.PyQt.QtCore import QVariant, QTextCodec |
| 34 | +from qgis.PyQt.QtCore import QVariant, QTextCodec, QLocale |
35 | 35 |
|
36 | 36 | start_app()
|
37 | 37 | codec = QTextCodec.codecForName("System")
|
@@ -676,6 +676,56 @@ def testExportFeatures(self):
|
676 | 676 | ]}"""
|
677 | 677 | self.assertEqual(exporter.exportFeatures([feature, feature2]), expected)
|
678 | 678 |
|
| 679 | + def testExportFeaturesWithLocale_regression20053(self): |
| 680 | + """ Test exporting feature export with range widgets and locale different than C |
| 681 | + Regression: https://issues.qgis.org/issues/20053 - decimal separator in csv files |
| 682 | + """ |
| 683 | + |
| 684 | + source = QgsVectorLayer("Point?field=name:string&field=cost:double&field=population:int&field=date:date", |
| 685 | + "parent", "memory") |
| 686 | + self.assertTrue(source.isValid()) |
| 687 | + fields = source.fields() |
| 688 | + |
| 689 | + feature = QgsFeature(fields, 5) |
| 690 | + feature.setGeometry(QgsGeometry(QgsPoint(5, 6))) |
| 691 | + feature.setAttributes(['Valsier Peninsula', 6.8, 198000, '2018-09-10']) |
| 692 | + |
| 693 | + exporter = QgsJsonExporter() |
| 694 | + |
| 695 | + # single feature |
| 696 | + expected = """{ "type": "FeatureCollection", |
| 697 | + "features":[ |
| 698 | +{ |
| 699 | + "type":"Feature", |
| 700 | + "id":5, |
| 701 | + "geometry": |
| 702 | + {"type": "Point", "coordinates": [5, 6]}, |
| 703 | + "properties":{ |
| 704 | + "name":"Valsier Peninsula", |
| 705 | + "cost":6.8, |
| 706 | + "population":198000, |
| 707 | + "date":"2018-09-10" |
| 708 | + } |
| 709 | +} |
| 710 | +]}""" |
| 711 | + self.assertEqual(exporter.exportFeatures([feature]), expected) |
| 712 | + |
| 713 | + setup = QgsEditorWidgetSetup('Range', { |
| 714 | + 'AllowNull': True, |
| 715 | + 'Max': 2147483647, |
| 716 | + 'Min': -2147483648, |
| 717 | + 'Precision': 4, |
| 718 | + 'Step': 1, |
| 719 | + 'Style': 'SpinBox' |
| 720 | + } |
| 721 | + ) |
| 722 | + source.setEditorWidgetSetup(1, setup) |
| 723 | + source.setEditorWidgetSetup(2, setup) |
| 724 | + |
| 725 | + QLocale.setDefault(QLocale('it')) |
| 726 | + exporter.setVectorLayer(source) |
| 727 | + self.assertEqual(exporter.exportFeatures([feature]), expected) |
| 728 | + |
679 | 729 |
|
680 | 730 | if __name__ == "__main__":
|
681 | 731 | unittest.main()
|
0 commit comments