2

I'm using QGis 2.14.12 Essen on Windows 7 Professional.

I want to set up a project that includes a feature class which has a non-editable° creation_date field and a non-editable UUID field. I have found a way to do it but it doesn't work the way I expect it to. I was able to recreate the problem on a colleague's computer.

Here's the problem:

I created a new .shp. In the layer settings, I've created a field "creation_date" (field type "date") which has the element setting° "date/time" and a UUID field (field type "Text/string", length 50) which is "UUID Generator"°. If I tick the box "editable"° in each dialogue, everything works just fine when creating new features.

If I untick the box "editable", the pop-up upon creation of a feature displays the correct date and it's not editable. Same for the UUID. Upon saving, neither of the entries show up in the attribute table. I can see them via the identify tool, though.

Can you reproduce this problem, is this a bug or am I making some mistake?

(I'm using the German version, so I'm not sure if I translated the words (marked with °) correctly. I hope you know which buttons/settings I'm talking about. Please help me out here to make the question more understandable.)

EDIT
If I open the .dbf in Excel, the editable columns has data, but not the non-editable.
Removing layer from Project and adding it again, does not Show the Information in the Attribute table and it stops the Information from being available in the identify tool.

  • 1
    Using QGIS 2.14.15 I can't reproduce your error. Having the 2 fields with edit widget "Date/Time" and "Uuid Generator". I tried having them editable and noneditable and both saved the current date and the uuid when creating a new feature Suggestion: Save the changes and than try to remove the layer after your edits and add him again and see if they still don't appear in the attribute table – LaughU Jun 28 '17 at 7:28
  • Thanks. It doesn't help if I remove it and add it again. For a test layer, I have created an editable and a noneditable field each for both UUID and date. Only the editable Information is saved in the Attribute table, the non-editable fields remain empty. Also, if I open the .dbf in Excel, the editable columns has data, but not the non-editable. – Iris.D Jun 28 '17 at 9:55
  • but do the changes appear in the identify tool when you reload the layer? – LaughU Jun 28 '17 at 9:58
  • The identify tool showed the correct Information only before I removed the layer from the Project. After adding it again, also the identify tool doesn't Show the non-editable Information. After adding the layer to the Project again, all Settings in the layer Settings > fields are removed. All Fields are type "text Editor" again. It must have resetted. – Iris.D Jun 28 '17 at 9:59
  • I just learned I have to Import a saved style to retrieve these Settings. Odd. – Iris.D Jun 28 '17 at 10:08
1

What you can try is the Autofield Plugin:

  • Create your shapefile with the fields and the field type date and string
  • In the fields dialog set the editor widget to hidden (this way, the user don't see field in attribute table but they are there.
  • in The plugin choose the field "creation_date" and tick "Timestamp" and say "save Autofields"
  • Do the same with uuid field but use a "custom expression" with $uuid as value
  • The saves will be committed after you save your edits
  • When "unhiding" the fields the timestamp and uuid should be there

EDIT:

To prevent, that a feature is updated after you created it uncheck the "Calculate expression on existing features" checkbox when creating the auto field

enter image description here

  • For the UUID this is a really great solution, because my user actually doesn't Need to see the UUID at all, as long as it's stored in the table. I've used the AutoField Plugin for the "edit_date" already. Won't the "creation_date" be updated when I edit the Feature? I don't want that to happen. Oh, will the UUID changed = recalculated when I edit the Feature? That wouldn't be good. – Iris.D Jun 28 '17 at 13:52
  • @Iris.D you could remove this field from the "List of Autofields" when you are editing it later or remove the checkmark on "Calculate expression on existing features" – LaughU Jun 28 '17 at 13:55
  • That's not really an Option as the users should be able to as well add new Features and edit existing Features and they can't Change the Settings of the layer (because they're first-time gis-users). I Need to make it fool-proof. The way I described in my question is implemented in QGis functionality, I just don't see why it's not working, because that's exactly what I want. I personally understand the Workaround, but I can't teach my users how to use AutoFields Plugin. – Iris.D Jun 28 '17 at 14:04
  • @Iris.D adding new features won't be a problem but editing existing ones will be :/ my bad if this isn't the desired solution. An alternative would be using postgres+postgis with an update trigger but this is definitely a totally different approach – LaughU Jun 28 '17 at 14:13
  • As you said, it works fine for creating new features. But the UUID and the creation date are getting updated / newly calculated when editing. Shouldn't "not calculating Expression on existing Features" prevent updating the date / UUID of existing Features theoretically? – Iris.D Jun 28 '17 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.