Skip to content

How to pass variable list of coordinates from Nim to QML? #40

Open
@arkanoid87

Description

@arkanoid87

I've a list of polygons described like

type
  Point = seq[float]
  Polygon = seq[Point]
  Model = seq[Polygon]

let data = @[
  @[
    @[9.183454513549805,45.464374726885],
    @[9.188776016235352,45.46058215193312],
    @[9.190363883972166,45.469039846107734],
    @[9.183454513549805,45.464374726885]
  ]
]

I'm trying to write QAbstractListModel for MapItemView to display those polygons, but the delegate requires path to be an array of javascript objects

Map {
    MapPolygon {
        color: 'green'
        path: [
            { latitude: -27, longitude: 153.0 },
            { latitude: -27, longitude: 154.1 },
            { latitude: -28, longitude: 153.5 }
        ]
    }
}

I'm trying to understand how to pass a seq of coordinates from my data proc considering that each polygon may have a variable number of vertices

method data(self: MapModel, index: QModelIndex, role: int): QVariant = ...

I see that nimqml lacks QVariantList and QVariantMap but I am not aware if a workaround solution is possible.

I'm considering turning Polygon type into a QObject and make seq[Point] one of its properties, but I don't know if it's possible to pass sequences from/to nimqml, that would mean declaring a list property using QQmlListProperty but it seems unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions