Bug report #12257
Cannot create virtual field with delimited text layer
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Field calculator | ||
Affected QGIS version: | 2.8.0 | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 20442 |
Description
When trying to add a field to a delimited text layer the Field Calculator UI does not enable the Output field type, width, and precision fields. This makes it impossible to define a valid field. So when OK is clicked, it is blocked with a message "Could not add the new field to the provider".
Steps to reproduce:
- Open a valid CSV file in QGIS
(eg
id,lon,lat
1,170.0,-45.0
) - open the attribute table on the new layer
- open the field calculator dialog
- enter output field name "answer"
- enter expression "42"
- click OK.
Notes 1: It is possible to add a virtual field via python, ie
from PyQt4.QtCore import *
iface.mapCanvas().currentLayer().addExpressionField('42',QgsField("answer",QVariant.Int))
Notes 2: The UI should not enable the OK button if a valid field type is not selected
History
#1 Updated by Chris Crook over 9 years ago
Note: The issue comes from the logic used to identify when the calculator should create a virtual field. In this case despite the fact that the virtual field check box is checked (and not enabled), there is a second condition, on the new field checkbox, which is not met. Instead the calculator tries to create a provider field and fails.
The issue with no field data type being selectable is separate and relates to the delimited text provider. This is addressed in pull request #1931, which I have merged into master. If the other issue with the field calculator gets fixed I'd appreciate if it and #1931 could be backported to 2.8.1.
#2 Updated by Chris Crook over 9 years ago
I've submitted a fix (PR 1932) which addresses this
#3 Updated by Nathan Woodrow over 9 years ago
- Status changed from Open to Closed
Fixed in changeset 5f1ed3582d9b549822b7110336de5c745790c189.