Can one easily convert between QVariantMap and ItemModel (QAbstractItemModel, say)?
-
It really doesn't seem possible directly from what I've looked at so far... but it seems strange to me that on the one hand, you have this QVariantMap kind of structure that is useful for storing data and, say, transferring it into a JSON object of some kind. And on the other hand, there are QAbstractItemModel type structures that are useful for exposing the data to a GUI and allowing it to be edited and modified.
Both of them have the capacity to be nested, tree-like structures... A data element in a QVariantMap can be a list, a list of lists (ie, an array) or another QVariantMap. Data Models are similarly nested, though they are addressed by row/column, parent/child relationships rather than named items.
So I'm starting to roll my own class, a QVariantMapModel, to do just this... But I don't want to reinvent the wheel if I'm forgetting some easier way.
The codebase for this project will be https://bitbucket.org/alex_shaver/qvariantmapmodel_project
-
Hi,
I haven't seen yet a model doing that so go ahead :)
As for the coding style and guidelines you have "this":http://qt-project.org/wiki/Qt_Coding_Style and "this":http://qt-project.org/wiki/Coding-Conventions
From your code base, the file casing should be lowercase. Only the generate includes are camel cased
Happy coding !
-
Thanks for sharing!
If you're interested, here's the work of another community member, who made a model for JSON documents: http://qt-project.org/forums/viewthread/51593/