#3713 closed bug (invalid)
Memory layer's fields not shown in attribute table (and layer properties) unless refreshed by entering the edit mode
Reported by: | borysiasty | Owned by: | |
---|---|---|---|
Priority: | major: does not work as expected | Milestone: | Version 1.7.0 |
Component: | Vectors | Version: | Trunk |
Keywords: | Cc: | borysiasty | |
Must Fix for Release: | Yes | Platform: | All |
Platform Version: | Awaiting user input: | no |
Description
If I add a memory layer, it contains features with geometries, but seems the layer doesn't contain any field. In the attribute table the row headers are present, but the column headers are missing, thus the records are empty. The same in Layer properties->Attributes, classification etc. Please note in the python console I can see the fields and attributes.
Now, when I enter the edit mode, something refreshes and everything starts to work properly.
Steps to reproduce:
- Add a memory layer, e.g from code below or any plugin
layer = QgsVectorLayer("Point","mylayer","memory") layer.dataProvider().addAttributes( [QgsField("foo", 2, "Int")] ) f = QgsFeature() f.setGeometry(QgsGeometry.fromPoint(QgsPoint(0,0))) f.setAttributeMap( { 0 : 2 } ) layer.dataProvider().addFeatures( [ f ] ) QgsMapLayerRegistry.instance().addMapLayer(layer)
- The attribute table is empty.
- Enter the edit mode
- Open the Attribute Table again - now everything works.
Change History (4)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Platform: | Debian → All |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Ok, it's reasonable. I'll call authors of affected plugins to encapsulate edits in editing mode.
comment:3 by , 13 years ago
Borys: even better solution (though available only from 1.7) is to specify the fields when creating the layer, see: http://www.qgis.org/pyqgis-cookbook/vector.html#memory-provider
comment:4 by , 13 years ago
Yes, but most plugins used to be compatible with older versions.
Btw. a few paragraphs later you give an example that will be affected after adding to the QgsMapLayerRegistry ("The following example code illustrates creating and populating a memory provider"). I'd suggest readers to do vl.startEditing()in advance to avoid a later confusion.
Replying to borysiasty:
You can only see the fields of the provider. The layer doesn't have any - yet.
But following works fine: