Extending the Plugin Component to Use the Selected Plot

This part is almost pythonically simple.

Sending the Plot ID to the Component

In demo2_selection.qml, our pointHandler sent the plot ID to the plugin component by assigning it directly to the component's plotId property.

if (shouldHandle){
    <...>
    if (it.hasNext()){
        const feature = it.next()
        iface.logMessage(feature.id)
        it.close()
        pluginLoader.active = true
        // Pass the plot ID to the plugin component
        pluginLoader.item.plotId = feature.attribute("plot_id")
        return true
    }
}

Handling the Plot ID in demo2_plugin_component

The plotId property is bound directly to the text of the MessageBox. Setting it from outside automatically updates the message. Ba Da Bing.

  Rectangle{
    id: pluginFrame

    // Plot ID Property - set by parent, propagated via bindings
    property string plotId: ""

    Rectangle{
        id: messageBoxFrame
        Text{
            id: messageBox

            text: "Plot loaded: " + pluginFrame.plotId
        }
    }
  }