4
votes

I have a model on C++ side which is based on AbstractListModel. The model have a set of locations through a role that is being shown in a MapView. Following is the minimal version of my code. markerModel: MarkerModel is defined on C++ side.

Map{
    MapItemView {
        model: markerModel
        delegate: markerDelegate
    }

    Component {
        id: markerDelegate

        MapQuickItem{
            anchorPoint: Qt.point(2.5, 2.5)
            coordinate: QtPositioning.coordinate(position.y, position.x)
            zoomLevel: 0
            sourceItem: Rectangle{
                ...
            }
        }
    }
}

The delegate actually draws points for each positions in the model. Now I want to have multiple such models.

  1. I can have an AbstractTableModel on C++ instead of AbstractListModel view will loop through its columns and call markerDelegate on each column. Or do the same with row.
  2. Have multiple models dynamically exposed to QML rendered on a single view with a single delegate markerDelegate

Which one of these is standard practice ? or feasible ? How to achieve any one of these ?

1
The models belong to the same class?eyllanesc
Yes all models are instances of the same class.Neel Basu
Wouldn't it may sense to put all the data in one model, and filter in this model? If you really need to use several models you could do it the other way around, with a proxy model that accepts multiple source-models, and exposes the data in one model that contains all data from the sources.Florian Schmidt
If nothing works then may be that's what I need to do. But it makes life too difficult. Actually each model corresponds to a path. It's a simulator and I need do lot of visualizations on each path. Things will be easy if I can just repeat things in QML.Neel Basu
a MapItemView can only have one model, why do you want to have several models? What differentiates one model from the other?eyllanesc

1 Answers

-2
votes

You can store data for each model in container and load appropriate data to the model object