Creating a Data Model for Desktop Application - ValueTree or XML (or both)?

I am developing a desktop application with JUCE. It scans the user’s file-system for particular files and directories, and displays the information to the user using tables, detail panes and possibly other kinds of components. The TableListBox component is what I’m starting with to display and organize the data.

I’ve followed the TableListBoxTutorial project, which reads data from an XML file and populates the table. However, I’ve also watched David Rowland’s talk on using ValueTrees and have worked with his tutorial code, and this has some features that I think would be beneficial to my project later down the road, such as undo/redo.

I’ve concluded that ValueTree seems likely to be useful, but have had some trouble understanding the intricacies of their use and in particular how to populate a TableListBox with ValueTree data.

Overall, my question is whether ValueTrees are flexible enough to be used to populate various types of components with data in the form of strings, ints, doubles, dates/times, etc, for use with TableListBox and other types of GUI components? Is this their intended use?

Any information appreciated. Thanks!

Yes they are very flexible and I would say that the GUI stuff you mentioned is an intended use. They handle primitive types out of the box and can be used with user defined types as well if you provide a variant converter for them. You also get the listener capabilities so you can have views react to data changes automatically. Very useful in UI

As Dave shows in his video, you can use the value tree directly, but If you want things like data validation etc it’s best to use model classes to encapsulate the data from the value tree. The tracktion engine provides a constrained cached value I’ve used a lot for validation type purposes in my model classes

As far as using data to fill a list box, you probably have some sort of list of child nodes in your tree that correspond to the list box data. The tracktion engine provides a value tree object list that might work for you where you provide it a parent value tree and it automagically packages up the children into a list for you to use. You could then just grab that object list, iterate over the children, and populate the list box using whatever property of the child you need. He goes over this in his talk and shows the implementation but You can include the tracktion engine as a module and have it available easily.

I don’t know if it’s possible to read an xml file directly into a value tree. The value tree classes provide one that is for reading xml files created by exporting already created value trees, but it states it should not be used with regular xml. You might have to parse the xml file into a tree yourself

1 Like

Thanks for your response, a lot of great information here. I didn’t understand what Tracktion was until your explanation so many thanks.
As for reading XML, like you suggest I think I’ll just create the initial ValueTree when the user first runs the application, then persist it using the ValueTree export method as you described and go from there.
Cheers!

Thats what I have been doing. If you have any other questions feel free to ask. I started using value trees in my app last week, and have learned a lot since watching daves talk and trying different things. I started with using the tree + value tree listeners directly, then I moved to writing model classes + value tree object lists and using those in my views, now I might try implementing a model view view-model type thing since using the view + value tree models kind of tightly couples your views to the value tree, which I didnt really like. Id like to keep the fact the model is backed by a value tree hidden from the views.

1 Like