From fa4eab1389c6379bbbda36a1fa2544de062344a2 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Thu, 27 Jan 2022 23:25:08 +0100 Subject: [PATCH] Handling dictionaries as property values in history. --- .../eu/ad5001/LogarithmPlotter/js/historylib.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js index d474b1b..4f957df 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js @@ -134,16 +134,22 @@ class EditedProperty extends Action { return [this.targetName, this.targetType, this.targetProperty, this.previousValue.toEditableString(), this.newValue.toEditableString(), true] } else if(this.previousValue instanceof Common.DrawableObject) { return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true] - } else { return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false] } } getReadableString() { - var prev = this.previousValue == null ? ""+this.previousValue : this.previousValue.toString() - var next = this.newValue == null ? ""+this.newValue : this.newValue.toString() - return qsTr('%1 of %2 %3 changed from "%4" to "%5".').arg(this.targetPropertyReadable).arg(Objects.types[this.targetType].displayType()).arg(this.targetName).arg(prev).arg(next) + var prev = this.previousValue == null ? "null" : this.previousValue.toString() + var next = this.newValue == null ? "null" : this.newValue.toString() + if(prev == "[object Object]") // Oh no! + prev = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'") + if(next == "[object Object]") // Oh no! + next = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'") + return qsTr('%1 of %2 %3 changed from "%4" to "%5".') + .arg(this.targetPropertyReadable) + .arg(Objects.types[this.targetType].displayType()) + .arg(this.targetName).arg(prev).arg(next) } }