Bug report #4636
Selecting/Deleting in attribute table does not work correctly for layers with no attributes (crashes in one situation!)
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Digitising | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | Yes | Copied to github as #: | 14537 |
Description
- Create a vector layer with no attribute columns. (This is possible with the "new memory layer" plugin - I'm not sure what other formats support layers with no attributes. I guess you could do it with csv + csvt).
- Open the attribute table
- Click the edit button
- Add or select and delete a feature using the digitising tools in the QGIS map window, and:
- The attribute table will be refreshed as it should (i.e. the features will appear or disappear).
- Select a feature by using the selection tools in the map window, and:
- The feature will not be highlighted in the attribute table as it is when you select a feature in a layer that has an attribute column (i.e. selected row number in bold, and looking like a depressed button or something).
- Select a feature by clicking on a row in the attribute table, and:
- The selected feature will neither be highlighted in the attribute table nor in the map canvas. Is it selected, or not?
- Click the button in the attribute table to delete the feature:
- You will be asked to confirm whether you really want to delete (1) feature (so it looks like the feature was selected). But: - say yes, you do want to delete the feature, and:
- The feature will not be deleted. It will still be visible in the map canvas and the attribute table (so maybe it wasn't really selected).
- Click on another row in the attribute table.
- Click the button in the attribute table to delete the feature.
- say yes, you do want to delete the feature, and:
- QGIS will freeze, using 100% of a CPU. You will need to kill it.
- Try steps 1 to 9 again, but instead of clicking the button in the attribute table in step 7, use the button in the main digitizing toolbar in the QGIS map window.
- Now at step 9 the selected feature is magically highlighted in the map window.
- Click another row in the attribute table to selected a different feature.
- The previously selected feature remains highlighted in the map window. - Click the button in the digitizing toolbar to delete the selected feature
- The highlighted feature is deleted.
- Delete some more features this way.
- If you took note of the order in which you created the features, I think you'll notice that they are not deleted in the order that you expect. But the memory layer provider does keep the features in the order that you expect if there is an attribute column.
Associated revisions
fix #4636:
- add a column containing the feature id, if no columns are there (otherwise
there are no valid model indices)
- vector layer: emit featureDeleted and featureAdded signals, when added
features change their temporary to a permanent id (e.g. makes the now defunct
rows in the attribute table disappear, instead of showing ERROR)
- memory provider: update the feature id in added features
History
#1 Updated by Alister Hood about 13 years ago
Sorry, the automatic numbering didn't work as I expected:
1. Create a vector layer with no attribute columns. (This is possible with the "new memory layer" plugin - I'm not sure what other formats support layers with no attributes. I guess you could do it with csv + csvt).
2. Open the attribute table
3. Click the edit button
4. Add or select and delete a feature using the digitising tools in the QGIS map window, and:
- The attribute table will be refreshed as it should (i.e. the features will appear or disappear).
5. Select a feature by using the selection tools in the map window, and:
- The feature will not be highlighted in the attribute table as it is when you select a feature in a layer that has an attribute column (i.e. selected row number in bold, and looking like a depressed button or something).
6. Select a feature by clicking on a row in the attribute table, and:
- The selected feature will neither be highlighted in the attribute table nor in the map canvas. Is it selected, or not?
7. Click the button in the attribute table to delete the feature:
- You will be asked to confirm whether you really want to delete (1) feature (so it looks like the feature was selected). But:
8. say yes, you do want to delete the feature, and:
- The feature will not be deleted. It will still be visible in the map canvas and the attribute table (so maybe it wasn't really selected).
9. Click on another row in the attribute table.
10. Click the button in the attribute table to delete the feature.
11. say yes, you do want to delete the feature, and:
- QGIS will freeze, using 100% of a CPU. You will need to kill it.
12. Try steps 1 to 9 again, but instead of clicking the button in the attribute table in step 7, use the button in the main digitizing toolbar in the QGIS map window.
- Now at step 9 the selected feature is magically highlighted in the map window.
13. Click another row in the attribute table to selected a different feature.
- The previously selected feature remains highlighted in the map window.
14. Click the button in the digitizing toolbar to delete the selected feature
- The highlighted feature is deleted.
#2 Updated by Giovanni Manghi about 13 years ago
- Target version set to Version 1.7.4
#3 Updated by Jürgen Fischer about 13 years ago
- Affected QGIS version set to master
- Crashes QGIS or corrupts data set to Yes
#4 Updated by Giovanni Manghi about 13 years ago
- Status changed from Open to Feedback
Hi Alister,
I made a test following the steps you describe and the memory layer plugin, and on both Windows and Linux (gnome) I found differences and I wasn't able to replicate all your steps. Please have a look here and let me know if/what I have done wrong.
steps 1-4: the table of attributes shows just the first "pseudo" column with the row id and nothing more. From the canvas with the editing tools is possible to add/remove features and this will reflect correctly in the (empty) table of attributes.
step 5: right, selecting a feature in the canvas does not selects anything in the table of attributes. Question: what should be selected in the table of attributes? is empty. I don't see anything strange here.
steps 6-8: in my tests clicking on a row id does NOT select anything, in fact if I first click on "deselect features from all layers" and then try to select a feature using the row id in the table of attributes and subsequently clicking on "delete selected features" I always get a "Delete 0 feature(s)?" that as expected does nothing.
On the other hand "delete selected features" works as expected after selecting features from the canvas.
steps 9-11: cannot replicate this behavior because as I said I'm not able to select anything from the table of attributes, as expected I would say.
steps 12-14: same as 9-11
I'm not sure I have done the test correctly, probably I have not understand well your description. Eventually can you make a screencast?
#5 Updated by Alister Hood almost 13 years ago
OK, here is a screencast.
http://dl.dropbox.com/u/24564149/%234636.avi
The behaviour does depend on what order you do things in (I can get the same result as you if I do things differently), and it seems like some aspects of this have changed slightly in current trunk. But the essence is the same:
- in some circumstances features can be selected but not appear to be selected.
- in some circumstances it freezes when you try to select these features.
Note that this computer is quad core, hence the 25% CPU use by QGIS when it freezes.
Also note the inconsistencies in how many features the attribute table title bar claims are selected (compare with the main window status bar, the map, and the actual attribute table, which always shows none selected).
#6 Updated by Alister Hood almost 13 years ago
- File attribute_table.PNG added
Giovanni Manghi wrote:
...
step 5: right, selecting a feature in the canvas does not selects anything in the table of attributes. Question: what should be selected in the table of attributes? is empty. I don't see anything strange here.
...
The table doesn't have any cells to show as selected, but the row-header (or whatever it is called) should show as selected. It should look like the attached image.
#7 Updated by Jürgen Fischer almost 13 years ago
- Status changed from Feedback to Closed
- % Done changed from 0 to 100
Fixed in changeset d43c89ae6a1cbdc9d957ea5663579ad13950e3b2.
#8 Updated by Alister Hood almost 13 years ago
Great, I think that fixed another much more common (but not dangerous) bug, too. Thanks.
I think there could be two minor improvements:
1. Try this: create a new memory layer without adding any attribute columns (or open a shapefile with no attributes), right-click on it and save-as a new shape file.
OR
Open any shape file or memory layer which does have attributes, right-click on it and save-as a new shape file, selecting the option to "Skip attribute creation".
RESULT: the new shape file will have an attribute field called "FID". In both cases I don't think it should.
2. Is there really a need to hide the Feature ID column if the layer has attribute fields?
- I can imagine some people might like to see it.
- Having it hidden sometimes and visible other times will be a little bit confusing.
#9 Updated by Jürgen Fischer almost 13 years ago
Alister Hood wrote:
Great, I think that fixed another much more common (but not dangerous) bug, too. Thanks.
No problem.
I think there could be two minor improvements:
1. Try this: create a new memory layer without adding any attribute columns (or open a shapefile with no attributes), right-click on it and save-as a new shape file.
OR
Open any shape file or memory layer which does have attributes, right-click on it and save-as a new shape file, selecting the option to "Skip attribute creation".
RESULT: the new shape file will have an attribute field called "FID". In both cases I don't think it should.
That's something OGR does internally as it doesn't fully support shapefiles without DBF (see http://www.gdal.org/ogr/drv_shapefile.html). OGR only support those readonly.
2. Is there really a need to hide the Feature ID column if the layer has attribute fields?
- I can imagine some people might like to see it.
- Having it hidden sometimes and visible other times will be a little bit confusing.
IMHO layers without any attributes are already an edge case and using the attributetable on attributeless layers even tops that ;)
#10 Updated by Alister Hood almost 13 years ago
Jürgen Fischer wrote:
Alister Hood wrote:
Great, I think that fixed another much more common (but not dangerous) bug, too. Thanks.
No problem.
I think there could be two minor improvements:
1. Try this: create a new memory layer without adding any attribute columns (or open a shapefile with no attributes), right-click on it and save-as a new shape file.
OR
Open any shape file or memory layer which does have attributes, right-click on it and save-as a new shape file, selecting the option to "Skip attribute creation".
RESULT: the new shape file will have an attribute field called "FID". In both cases I don't think it should.That's something OGR does internally as it doesn't fully support shapefiles without DBF (see http://www.gdal.org/ogr/drv_shapefile.html). OGR only support those readonly.
Oh, I see. I was wondering why I could edit features in shape files with no attributes, but not add attributes, or add or delete features :)
2. Is there really a need to hide the Feature ID column if the layer has attribute fields?
- I can imagine some people might like to see it.
- Having it hidden sometimes and visible other times will be a little bit confusing.IMHO layers without any attributes are already an edge case and using the attributetable on attributeless layers even tops that ;)
Fair enough.