<commit_before>import QtQuick 2.0

Canvas {
    id:canvas
    property int paintX
    property int paintY
    property int count: 0
    property int lineWidth: 2
    property string drawColor: "black"
    property var ctx: getContext('2d')
    property variant elements: []
    property bool canvasValid: true

    property real lastX
    property real lastY

    property BasicModellerObject currenElement

    Timer {
        interval: 30;
        running: true;
        repeat: true
        onTriggered: canvas.draw()
    }

    function addType(elem) {
        currenElement = elem
    }

    function invalidate() {
        validCanvas = false;
    }

    function draw(){
        if (canvasValid == false) {
            clear(ctx);
            canvasValid = true
            var l = elements.length
            for (var i = 0; i < l; i++) {
                elements[i].draw(ctx);
            }
            canvas.requestPaint();

        }
    }

    function clear() {
        ctx.reset();
        ctx.clearRect(0, 0, width, height);
        ctx.stroke();
        canvas.requestPaint();
    }

    function clearModeller() {
        currenElement = null;
        elements = [];
        clear();
        canvasValid = false;
    }

    MouseArea {
        id: area
        anchors.fill: parent
        onPressed: {
            canvas.lastX = mouseX
            canvas.lastY = mouseY
        }
//        onPositionChanged: {
//            canvas.requestPaint()
//        }
        onClicked: {
            if (currenElement !== null) {
               currenElement.setCoordinates(mouseX, mouseY)
               var t = elements
               t.push(currenElement)
               elements = t
               currenElement = null;
               canvasValid = false
            } else {

            }
        }
    }

    //    MouseArea {
    //        id:mousearea
    //        hoverEnabled:true
    //        anchors.fill: parent
    //////        onClicked: drawPoint();
    //////        onPressed: drawPoint();
    //        onPositionChanged: {
    //            if (mousearea.pressed)
    //                drawLineSegment(paintX, paintY, mouseX, mouseY);
    //            paintX = mouseX;
    //            paintY = mouseY;
    //        }
    //////        onReleased: drawPoint();
    //    }
    //    function drawLineSegment(startX, startY, endX, endY) {
    //        ctx.beginPath();
    //        ctx.strokeStyle = drawColor
    //        ctx.lineWidth = lineWidth
    //        ctx.moveTo(startX, startY);
    //        ctx.lineTo(endX, endY);
    //        ctx.stroke();
    //        ctx.closePath();
    //    }
    //    function drawPoint() {
    //        ctx.lineWidth = lineWidth
    //        ctx.fillStyle = drawColor
    //        ctx.fillRect(mousearea.mouseX-10, mousearea.mouseY-10, 20, 20);
    //    }

    //    function zoomIn() {
    //        console.log("zoomInFunc");
    //        ctx.scale(1.5, 1.5);
    //    }

    //    function zoomOut() {
    //        console.log("zoomOutFunc");
    //        ctx.scale(0.5, 0.5);
    //    }

}
<commit_msg>Add loop that checks for selected objects if the mouse button is pressed on the canvas<commit_after>import QtQuick 2.0

Canvas {
    id:canvas
    property int paintX
    property int paintY
    property int count: 0
    property int lineWidth: 2
    property string drawColor: "black"
    property var ctx: getContext('2d')
    property variant elements: []
    property bool canvasValid: true

    property real lastX
    property real lastY

    property BasicModellerObject currenElement

    Timer {
        interval: 30;
        running: true;
        repeat: true
        onTriggered: canvas.draw()
    }

    function addType(elem) {
        currenElement = elem
    }

    function invalidate() {
        validCanvas = false;
    }

    function draw(){
        if (canvasValid == false) {
            clear(ctx);
            canvasValid = true
            var l = elements.length
            for (var i = 0; i < l; i++) {
                elements[i].draw(ctx);
            }
            canvas.requestPaint();

        }
    }

    function clear() {
        ctx.reset();
        ctx.clearRect(0, 0, width, height);
        ctx.stroke();
        canvas.requestPaint();
    }

    function clearModeller() {
        currenElement = null;
        elements = [];
        clear();
        canvasValid = false;
    }

    MouseArea {
        id: area
        anchors.fill: parent
        onPressed: {
            canvas.lastX = mouseX
            canvas.lastY = mouseY
        }
//        onPositionChanged: {
//            canvas.requestPaint()
//        }
        onClicked: {
            if (currenElement !== null) {
               currenElement.setCoordinates(mouseX, mouseY)
               var t = elements
               t.push(currenElement)
               elements = t
               currenElement = null;
               canvasValid = false
            } else {
                var l = elements.length;
                for (var i = l-1; i >= 0; i--) {
                   if (elements[i].isSelected(mouseX, mouseY)) {
                       canvasValid = false;
                   }
                }
            }
        }
    }

    //    MouseArea {
    //        id:mousearea
    //        hoverEnabled:true
    //        anchors.fill: parent
    //////        onClicked: drawPoint();
    //////        onPressed: drawPoint();
    //        onPositionChanged: {
    //            if (mousearea.pressed)
    //                drawLineSegment(paintX, paintY, mouseX, mouseY);
    //            paintX = mouseX;
    //            paintY = mouseY;
    //        }
    //////        onReleased: drawPoint();
    //    }
    //    function drawLineSegment(startX, startY, endX, endY) {
    //        ctx.beginPath();
    //        ctx.strokeStyle = drawColor
    //        ctx.lineWidth = lineWidth
    //        ctx.moveTo(startX, startY);
    //        ctx.lineTo(endX, endY);
    //        ctx.stroke();
    //        ctx.closePath();
    //    }
    //    function drawPoint() {
    //        ctx.lineWidth = lineWidth
    //        ctx.fillStyle = drawColor
    //        ctx.fillRect(mousearea.mouseX-10, mousearea.mouseY-10, 20, 20);
    //    }

    //    function zoomIn() {
    //        console.log("zoomInFunc");
    //        ctx.scale(1.5, 1.5);
    //    }

    //    function zoomOut() {
    //        console.log("zoomOutFunc");
    //        ctx.scale(0.5, 0.5);
    //    }

}

{'fraction_non_alphanumeric': 0.11758376882877344, 'fraction_numerical': 0.008300030740854596, 'mean_word_length': 1.2767669699090274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741689', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1842, 'n_words': 398}