import QtQuick 2.0

import org.qgis 1.0
import org.qfield 1.0

Item {
    id: root
    anchors.fill: parent

    property variant location
    property VectorLayer currentLayer
    property var currentAttribute
    property var symbolImage
    property var currentAttributeValue
    property MapSettings settings
    


    Connections{
        target: attributeTrackingModel

        function onTrackerStarted(layer, attribute) {
            attributeTrackingModel.test("onTrackerStarted");

            attributeTrackingModel.setMapSettings(settings);

            currentLayer = layer;
            currentAttribute = attribute;

            trackingBanner.active = true;
        }

        function onTrackerStopped() {
            attributeTrackingModel.test("onTrackerStopped");
            trackingBanner.active = false;
        }

        function onLocationRecieved(attributeValue, featureId){
             attributeTrackingModel.test("onLocationRecieved");
            symbolImage = featureId;
            currentAttributeValue = attributeValue;
        }
    }
    
    Loader{
        id: trackingBanner
        sourceComponent: banner
        active: false
        onLoaded: {
            item.visible = true;            
        }
    }

    Component{
        id: banner

        Item{            
            property variant location: root.location

            parent: root
            anchors.fill: parent

            anchors.margins: 10
            anchors.bottomMargin: 55

            Image{

                anchors.bottom: parent.bottom

                //color: symbolColor
                height: mainWindow.height / 3
                width: mainWindow.width - 20

                sourceSize.height: mainWindow.height / 3
                sourceSize.width: mainWindow.width - 20


                source: "image://attributeTracking/" + symbolImage


                Rectangle{
                    color: "white"
                    anchors.centerIn: parent
                    width: attributeTrackerFieldLabel.width + 5
                    height: attributeTrackerFieldLabel.height + 5

                    Text {
                        id: attributeTrackerFieldLabel
                        text: currentAttribute +": "+ currentAttributeValue
                        anchors.centerIn: parent
                    }
                }
            }

            onLocationChanged: {
                attributeTrackingModel.test("onLocationChanged");               
                attributeTrackingModel.recieveLocation(location);
            }
        }
    }
}
