Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-111830

Let's add a QAbstractItemModel to display JSON data

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • Core: Item Models
    • None
    • 21
    • Foundation PM Prioritized

    Description

      It's kindof obvious that we should make it easy to display JSON data in a QTreeView or Qt Quick TreeView.  https://codereview.qt-project.org/c/qt/qtdoc/+/456602 is adding an example like that, but has to do it the hard way because we don't have library code for that.

      But then again, most applications need to do something more specific, not just display all the data in its original form.  For XML in Qt Quick, we have XmlListModel, supporting XPath queries.  I wonder if there's a common JSON paradigm like that.  https://stackoverflow.com/questions/8481380/is-there-a-json-equivalent-of-xquery-xpath

      There's a QML TableModel but not yet a TreeModel.  We know we should write one.  But maybe it's better to write a nice C++ class first, get it working with QTreeView, and try to make it available to QML in the QtQml.Models module at the same time, testing it with TreeView.  Alternatively, someone might want to process the JSON in QML/javascript first, and programmatically insert something into a TreeModel; so it would be nice if the same model can also be built up one-node-at-a-time, not only by parsing a JSON file to begin with.

      We have QJsonDocument, QJsonArray and QJsonObject. A tree view could start with any of those as its root, depending whether you want to show the whole document or a subtree; so that would tend to make it a bit complicated.  If the code gets too complex to support all of those cases, then I think maybe it points to an architectural improvement that we need in the QJson classes (and others): some sort of generic QTreeNode class (name TBD) that all those can inherit from.  Then we could have a QTreeModel (TBD) that can make available any subtree (with one QTreeNode root) as a QAIM, and therefore available to all the views.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              dfaure_kdab David Faure
              srutledg Shawn Rutledge
              Vladimir Minenko Vladimir Minenko
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes