From 35ce1c4824148e435bd4cce3d7c5a10a75450612 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 24 May 2023 07:03:12 +0200 Subject: [PATCH] Adding error handling for function argument errors. --- LogarithmPlotter/i18n/lp_de.ts | 13 +++++++++++ LogarithmPlotter/i18n/lp_en.ts | 13 +++++++++++ LogarithmPlotter/i18n/lp_es.ts | 13 +++++++++++ LogarithmPlotter/i18n/lp_fr.ts | 13 +++++++++++ LogarithmPlotter/i18n/lp_hu.ts | 13 +++++++++++ LogarithmPlotter/i18n/lp_nb_NO.ts | 13 +++++++++++ LogarithmPlotter/i18n/lp_template.ts | 13 +++++++++++ .../LogarithmPlotter/LogGraphCanvas.qml | 22 +++++++++++++++++-- .../ObjectLists/Editor/CustomPropertyList.qml | 2 +- 9 files changed, 112 insertions(+), 3 deletions(-) diff --git a/LogarithmPlotter/i18n/lp_de.ts b/LogarithmPlotter/i18n/lp_de.ts index 86dccae..c762813 100644 --- a/LogarithmPlotter/i18n/lp_de.ts +++ b/LogarithmPlotter/i18n/lp_de.ts @@ -1046,6 +1046,14 @@ Evaluated expression: %3 Ausdruck analysiert: %3 + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1066,6 +1074,11 @@ Evaluated expression: %3 Ausdruck analysiert: %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/i18n/lp_en.ts b/LogarithmPlotter/i18n/lp_en.ts index 711f2cc..2a43526 100644 --- a/LogarithmPlotter/i18n/lp_en.ts +++ b/LogarithmPlotter/i18n/lp_en.ts @@ -1046,6 +1046,14 @@ Evaluated expression: %3 Evaluated expression: %3 + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1066,6 +1074,11 @@ Evaluated expression: %3 Evaluated expression: %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/i18n/lp_es.ts b/LogarithmPlotter/i18n/lp_es.ts index a6ccaec..307c1fa 100644 --- a/LogarithmPlotter/i18n/lp_es.ts +++ b/LogarithmPlotter/i18n/lp_es.ts @@ -991,6 +991,14 @@ These settings can be changed at any time from the "Settings" menu. + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1008,6 +1016,11 @@ Evaluated expression: %3 Evaluated expression: %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/i18n/lp_fr.ts b/LogarithmPlotter/i18n/lp_fr.ts index 70fd443..ef59464 100644 --- a/LogarithmPlotter/i18n/lp_fr.ts +++ b/LogarithmPlotter/i18n/lp_fr.ts @@ -1055,6 +1055,14 @@ Evaluated expression: %3 Formule analysée : %3 + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1075,6 +1083,11 @@ Evaluated expression: %3 Formule analysée : %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/i18n/lp_hu.ts b/LogarithmPlotter/i18n/lp_hu.ts index 355b65a..46fd264 100644 --- a/LogarithmPlotter/i18n/lp_hu.ts +++ b/LogarithmPlotter/i18n/lp_hu.ts @@ -1046,6 +1046,14 @@ Evaluated expression: %3 Kiértékelt kifejezés: %3 + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1066,6 +1074,11 @@ Evaluated expression: %3 Kiértékelt kifejezés: %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/i18n/lp_nb_NO.ts b/LogarithmPlotter/i18n/lp_nb_NO.ts index 1181e93..6daa1a1 100644 --- a/LogarithmPlotter/i18n/lp_nb_NO.ts +++ b/LogarithmPlotter/i18n/lp_nb_NO.ts @@ -1043,6 +1043,14 @@ Disse innstillingene kan endres når som helst fra «Innstillinger»-menyen. + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1060,6 +1068,11 @@ Evaluated expression: %3 Evaluated expression: %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/i18n/lp_template.ts b/LogarithmPlotter/i18n/lp_template.ts index ffda6b0..8390e18 100644 --- a/LogarithmPlotter/i18n/lp_template.ts +++ b/LogarithmPlotter/i18n/lp_template.ts @@ -991,6 +991,14 @@ These settings can be changed at any time from the "Settings" menu. + + + Error while attempting to draw %1 %2: +%3 + +Undoing last change. + + expression @@ -1008,6 +1016,11 @@ Evaluated expression: %3 Evaluated expression: %3 + + + LogarithmPlotter - Drawing error + + function diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml index 7ab2153..bd10c29 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml @@ -16,7 +16,8 @@ * along with this program. If not, see . */ -import QtQuick +import QtQuick +import Qt.labs.platform as Native import "js/objects.js" as Objects import "js/utils.js" as Utils import "js/mathlib.js" as MathLib @@ -170,6 +171,16 @@ Canvas { Component.onCompleted: imageLoaders = {} + Native.MessageDialog { + id: drawingErrorDialog + title: qsTranslate("expression", "LogarithmPlotter - Drawing error") + text: "" + function showDialog(objType, objName, error) { + text = qsTranslate("error", "Error while attempting to draw %1 %2:\n%3\n\nUndoing last change.").arg(objType).arg(objName).arg(error) + open() + } + } + onPaint: function(rect) { //console.log('Redrawing') if(rect.width == canvas.width) { // Redraw full canvas @@ -183,7 +194,14 @@ Canvas { for(var obj of Objects.currentObjects[objType]){ ctx.strokeStyle = obj.color ctx.fillStyle = obj.color - if(obj.visible) obj.draw(canvas, ctx) + if(obj.visible) + try { + obj.draw(canvas, ctx) + } catch(e) { + // Drawing throws an error. Generally, it's due to a new modification (or the opening of a file) + drawingErrorDialog.showDialog(objType, obj.name, e.message) + history.undo() + } } } ctx.lineWidth = 1 diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml index 0551d2e..a800c6e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/Editor/CustomPropertyList.qml @@ -91,7 +91,7 @@ Repeater { root.changed() } } - } + } }