Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Centralize multiple delegate for different graphical objects in MapItemView
QtWS25 Last Chance

Centralize multiple delegate for different graphical objects in MapItemView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 247 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Coubz
    wrote on last edited by
    #1

    Re: Delegate for different graphical objects in MapItemView

    Hi
    i'm reopening this old subject as i struggling with the exact same issue.

    To sum it up i'd like to have a qml file to centralise the delegates that will be used to print items in my MapItemView.

    Here's where i'm at :

    In my main map view :

    MapItemView
    {
        id: mapMarkers
        model: MapMarkerModels{}
        delegate: MapMarkerMultiDelegate{}
    }
    

    MapMarkerModels.qml

    ListModel
    {
        id: someModels
        ListElement {type: "cursor"; lat: 43.778958; lon:3.812109}
        ListElement {type: "circle"; lat: 43.788958; lon:3.812109}
        ListElement {type: "circle"; lat: 43.798958; lon:3.812109}
    }
    

    and MapMarkerMultiDelegate.qml

    Loader
    {
        id: mapMarkerMultiDelegate
        sourceComponent: getDelegate(type)
    
        function getDelegate(t) {
            switch(t)
            {
                case "cursor": return cursorDelegate;
                case "circle": return circleDelegate;
                default: return circleDelegate;
            }
        }
    
        Component
        {
            id: cursorDelegate
            MapQuickItem
            {
                id: cursor
                anchorPoint.x: rect.width / 2
                anchorPoint.y:  rect.height / 2
                coordinate
                {
                    latitude: lat
                    longitude: lon
                }
    
                sourceItem:
                    Rectangle
                    {
                        id: rect
                        width: 25
                        height: 25
                        color: "blue"
                    }
            }
        }
    
        Component
        {
            id: circleDelegate
            MapCircle
            {
                center
                {
                    latitude: lat
                    longitude: lon
                }
                radius: 500.0
                color: 'green'
                border.width: 3
            }
        }
    }
    

    It doesn't show anything on the map.
    If y break in "getDelegate(type)" it seems to be returning the good component.
    But I get a message in the output :
    "addDelegateToMap called with a MapMarkerMultiDelegate_QMLTYPE_1"

    If i remove the Loader and simply put one of the Component in the MapMarkerMultiDelegate.qml file it works fine and print what i want.

    I've only be playing with Qt for a few days so i might be doing everything wrong. Still this is tickeling me so if any of you have an idea =)

    GrecKoG 1 Reply Last reply
    0
    • C Coubz

      Re: Delegate for different graphical objects in MapItemView

      Hi
      i'm reopening this old subject as i struggling with the exact same issue.

      To sum it up i'd like to have a qml file to centralise the delegates that will be used to print items in my MapItemView.

      Here's where i'm at :

      In my main map view :

      MapItemView
      {
          id: mapMarkers
          model: MapMarkerModels{}
          delegate: MapMarkerMultiDelegate{}
      }
      

      MapMarkerModels.qml

      ListModel
      {
          id: someModels
          ListElement {type: "cursor"; lat: 43.778958; lon:3.812109}
          ListElement {type: "circle"; lat: 43.788958; lon:3.812109}
          ListElement {type: "circle"; lat: 43.798958; lon:3.812109}
      }
      

      and MapMarkerMultiDelegate.qml

      Loader
      {
          id: mapMarkerMultiDelegate
          sourceComponent: getDelegate(type)
      
          function getDelegate(t) {
              switch(t)
              {
                  case "cursor": return cursorDelegate;
                  case "circle": return circleDelegate;
                  default: return circleDelegate;
              }
          }
      
          Component
          {
              id: cursorDelegate
              MapQuickItem
              {
                  id: cursor
                  anchorPoint.x: rect.width / 2
                  anchorPoint.y:  rect.height / 2
                  coordinate
                  {
                      latitude: lat
                      longitude: lon
                  }
      
                  sourceItem:
                      Rectangle
                      {
                          id: rect
                          width: 25
                          height: 25
                          color: "blue"
                      }
              }
          }
      
          Component
          {
              id: circleDelegate
              MapCircle
              {
                  center
                  {
                      latitude: lat
                      longitude: lon
                  }
                  radius: 500.0
                  color: 'green'
                  border.width: 3
              }
          }
      }
      

      It doesn't show anything on the map.
      If y break in "getDelegate(type)" it seems to be returning the good component.
      But I get a message in the output :
      "addDelegateToMap called with a MapMarkerMultiDelegate_QMLTYPE_1"

      If i remove the Loader and simply put one of the Component in the MapMarkerMultiDelegate.qml file it works fine and print what i want.

      I've only be playing with Qt for a few days so i might be doing everything wrong. Still this is tickeling me so if any of you have an idea =)

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @Coubz Use DelegateChooser instead of Loader.
      A Loader is an Item but MapItemView needs a MapItem.

      C 1 Reply Last reply
      1
      • GrecKoG GrecKo

        @Coubz Use DelegateChooser instead of Loader.
        A Loader is an Item but MapItemView needs a MapItem.

        C Offline
        C Offline
        Coubz
        wrote on last edited by Coubz
        #3

        @GrecKo said in Centralize multiple delegate for different graphical objects in MapItemView:

        DelegateChooser

        Well it works like a charm, thank you =)

        Here the updated QML just for the next one that will have the same problem.

        MapMarkerMultiDelegate.qml

        DelegateChooser
        {
            id: mapMarkerDelegateChooser
            role: "type"
        
            DelegateChoice
            {
                id: cursorDelegate
                roleValue: "cursor"
                MapQuickItem
                {
                    id: cursor
                    anchorPoint.x: rect.width / 2
                    anchorPoint.y:  rect.height / 2
                    coordinate
                    {
                           latitude: lat
                           longitude: lon
                    }
                     sourceItem:
                        Rectangle
                        {
                            id: rect
                            width: 25
                            height: 25
                            color: "blue"
                        }
                }
            }
        
            DelegateChoice
            {
                id: circleDelegate
                roleValue: "circle"
                MapCircle
                {
                    center: markerCoordinate
                    radius: 500.0
                    color: 'green'
                    border.width: 3
                }
            }
        }
        

        And thx again !

        1 Reply Last reply
        0
        • C Coubz has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved