From 5b22cd2660486a0cb314a9d93edce1d43b17b314 Mon Sep 17 00:00:00 2001 From: mashiros <490328928@qq.com> Date: Fri, 20 May 2022 12:55:38 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E5=B5=8C=E5=A5=97Object?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- qml/BottomUI.qml | 6 +----- qml/TopUI.qml | 6 +----- qml/WeatherWidget.qml | 6 +----- qml/WidgetTemplate.qml | 17 +++++++++++++++++ 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index a49e9e5..efb0dc7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "top.mashiros.widget.ordinalscale", - "version": "1.1.1", + "version": "1.1.2", "title": { "en": "Ordinal Scale Widget Collections", diff --git a/qml/BottomUI.qml b/qml/BottomUI.qml index 5931e40..4c69ca1 100644 --- a/qml/BottomUI.qml +++ b/qml/BottomUI.qml @@ -40,10 +40,6 @@ WidgetTemplate { readonly property real w: widget.width readonly property real r: (w**2+4*h**2)/2/h - onUpdated: { - widget.settings.styles = Object.assign(defaultValues, widget.settings.styles); - } - onConfigsChanged: { line.requestPaint(); triangle.requestPaint(); @@ -127,7 +123,7 @@ WidgetTemplate { anchors.fill: parent header: TitleBar { - text: qsTr("UI Settings") + text: qsTr("Ordinal Scale Bottom UI widget") standardButtons: Dialog.Save | Dialog.Reset diff --git a/qml/TopUI.qml b/qml/TopUI.qml index 2e68046..7053ead 100644 --- a/qml/TopUI.qml +++ b/qml/TopUI.qml @@ -30,10 +30,6 @@ WidgetTemplate { "Text Vertical Offset": 16 } - onUpdated: { - widget.settings.styles = Object.assign(defaultValues, widget.settings.styles); - } - onConfigsChanged: { line.requestPaint(); c0.requestPaint(); @@ -373,7 +369,7 @@ WidgetTemplate { anchors.fill: parent header: TitleBar { - text: qsTr("UI Settings") + text: qsTr("Ordinal Scale Top UI widget") standardButtons: Dialog.Save | Dialog.Reset diff --git a/qml/WeatherWidget.qml b/qml/WeatherWidget.qml index 901674b..5a81e75 100644 --- a/qml/WeatherWidget.qml +++ b/qml/WeatherWidget.qml @@ -52,10 +52,6 @@ WidgetTemplate { } } - onUpdated: { - widget.settings.styles = Object.assign(defaultValues, widget.settings.styles); - } - readonly property var configs: widget.settings.styles readonly property real w: widget.width readonly property real h: 0.46*widget.width @@ -245,7 +241,7 @@ WidgetTemplate { anchors.fill: parent header: TitleBar { - text: qsTr("Settings") + text: qsTr("Ordinal Scale Weather Widget") standardButtons: Dialog.Save | Dialog.Reset diff --git a/qml/WidgetTemplate.qml b/qml/WidgetTemplate.qml index 290b286..8fb82a0 100644 --- a/qml/WidgetTemplate.qml +++ b/qml/WidgetTemplate.qml @@ -14,6 +14,23 @@ T.Widget { signal completed() signal updated() + function updateObject(targetObj, sourceObj) { + for (let prop in sourceObj) { + if (sourceObj.hasOwnProperty(prop) && sourceObj[prop] !== undefined) { + if (typeof sourceObj[prop] === 'object') { + Object.assign(targetObj[prop], sourceObj[prop]); + } else { + targetObj[prop] = sourceObj[prop]; + } + } + } + return targetObj; + } + + onUpdated: { + widget.settings.styles = updateObject(JSON.parse(JSON.stringify(defaultValues)), widget.settings.styles); + } + Component.onCompleted: { if (!widget.settings.styles) { widget.settings.styles = defaultValues;