Currently, it’s possible to daisy-chain property setters on a value tree:
juce::ValueTree {"Tree"}
.setProperty("foo", 10, nullptr)
.setProperty("bar", 20, nullptr);
It’d be great to have the behaviour for the child-adders as well, allowing a whole tree to be constructed this way:
juce::ValueTree {"Root"}
.setProperty("foo", 10, nullptr)
.setProperty("bar", 20, nullptr)
.appendChild (juce::ValueTree {"Branch"}
.setProperty ("x", y, nullptr)
.appendChild (juce::ValueTree {"Leaf"}, nullptr),
nullptr)
.addChild (juce::ValueTree {"Branch"}, 0, nullptr);
This is useful when loading value-trees from places external to the current call site (.e.g loading state from XML) and then adding on any additional children (e.g. any state that isn’t be persisted to the file).
It also allows for better const-ness as the tree doesn’t need to be changed after initialisation:
juce::ValueTree nonConst {"Tree"};
nonConst.appendChild (juce::ValueTree {"Data"}, nullptr);
const auto isConst = juce::ValueTree {"Tree"}
.appendChild (juce::ValueTree {"Data"}, nullptr);
PR here as the changes are very simple: Allow daisy-chaining when adding children to ValueTrees by ImJimmi · Pull Request #1332 · juce-framework/JUCE · GitHub