From b91dbfb31100e221553d61657a5b2b1a3835dfc4 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 11 Oct 2024 02:14:42 +0200 Subject: [PATCH] Finishing touches on putting History off QML. --- common/src/events.mjs | 1 - common/src/module/history.mjs | 10 +- common/src/module/io.mjs | 3 +- .../LogarithmPlotter/History/History.qml | 112 ------------------ .../History/HistoryBrowser.qml | 2 +- .../eu/ad5001/LogarithmPlotter/History/qmldir | 1 - .../LogarithmPlotter/LogarithmPlotter.qml | 2 +- 7 files changed, 12 insertions(+), 119 deletions(-) delete mode 100644 runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml diff --git a/common/src/events.mjs b/common/src/events.mjs index fbc8228..dbdd00f 100644 --- a/common/src/events.mjs +++ b/common/src/events.mjs @@ -58,7 +58,6 @@ export class BaseEventEmitter { for(const type of eventType.split(" ")) this.on(type, eventListener) else { - console.log("Listening to", eventType) if(!this.constructor.emits.includes(eventType)) { const className = this.constructor.name const eventTypes = this.constructor.emits.join(", ") diff --git a/common/src/module/history.mjs b/common/src/module/history.mjs index 2a38730..6e32fed 100644 --- a/common/src/module/history.mjs +++ b/common/src/module/history.mjs @@ -29,6 +29,12 @@ class ClearedEvent extends BaseEvent { } } +class LoadedEvent extends BaseEvent { + constructor() { + super("loaded") + } +} + class AddedEvent extends BaseEvent { constructor(action) { super("added") @@ -51,7 +57,7 @@ class RedoneEvent extends BaseEvent { } class HistoryAPI extends Module { - static emits = ["cleared", "added", "undone", "redone"] + static emits = ["cleared", "loaded", "added", "undone", "redone"] #helper @@ -154,7 +160,7 @@ class HistoryAPI extends Module { this.redoStack.push( new Actions[name](...args) ) - this.emit(new UpdatedEvent()) + this.emit(new LoadedEvent()) } /** diff --git a/common/src/module/io.mjs b/common/src/module/io.mjs index 360a8fc..472b061 100644 --- a/common/src/module/io.mjs +++ b/common/src/module/io.mjs @@ -59,7 +59,6 @@ class IOAPI extends Module { }) // Settings.on("changed", this.__emitModified.bind(this)) - console.log("Init IO", this) History.on("added undone redone", this.__emitModified.bind(this)) } @@ -125,6 +124,7 @@ class IOAPI extends Module { } Helper.write(filename, JSON.stringify(settings)) this.#alert.show(qsTranslate("io", "Saved plot to '%1'.").arg(filename.split("/").pop())) + this.#saved = true this.emit(new SavedEvent()) } @@ -203,6 +203,7 @@ class IOAPI extends Module { } Canvas.redraw() this.#alert.show(qsTranslate("io", "Loaded file '%1'.").arg(basename)) + this.#saved = true this.emit(new LoadedEvent()) } diff --git a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml deleted file mode 100644 index 88579e7..0000000 --- a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml +++ /dev/null @@ -1,112 +0,0 @@ -/** - * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions. - * Copyright (C) 2021-2024 Ad5001 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import QtQuick -import QtQml -import QtQuick.Window -import "../js/index.mjs" as JS - -/*! - \qmltype History - \inqmlmodule eu.ad5001.LogarithmPlotter.History - \brief QObject holding persistantly for undo & redo stacks. - - \sa HistoryBrowser, HistoryLib -*/ -Item { - // Using a QtObject is necessary in order to have proper property propagation in QML - id: historyObj - - /*! - \qmlproperty int History::undoCount - Count of undo actions. - */ - property int undoCount: 0 - /*! - \qmlproperty int History::redoCount - Count of redo actions. - */ - property int redoCount: 0 - /*! - \qmlproperty var History::undoStack - Stack of undo actions. - */ - property var undoStack: [] - /*! - \qmlproperty var History::redoStack - Stack of redo actions. - */ - property var redoStack: [] - /*! - \qmlproperty bool History::saved - true when no modification was done to the current working file, false otherwise. - */ - property bool saved: true - - - /*! - \qmlmethod void History::clear() - Clears both undo and redo stacks completly. - */ - function clear() { - Modules.History.clear() - } - - - /*! - \qmlmethod var History::serialize() - Serializes history into JSON-able content. - */ - function serialize() { - return Modules.History.serialize() - } - - /*! - \qmlmethod void History::unserialize(var undoSt, var redoSt) - Unserializes both \c undoSt stack and \c redoSt stack from serialized content. - */ - function unserialize(undoSt, redoSt) { - Modules.History.unserialize(undoSt, redoSt) - } - - /*! - \qmlmethod void History::addToHistory(var action) - Adds an instance of HistoryLib.Action to history. - */ - function addToHistory(action) { - Modules.History.addToHistory(action) - } - - /*! - \qmlmethod void History::undo(bool updateObjectList = true) - Undoes the HistoryLib.Action at the top of the undo stack and pushes it to the top of the redo stack. - By default, will update the graph and the object list. This behavior can be disabled by setting the \c updateObjectList to false. - */ - function undo(updateObjectList = true) { - Modules.History.undo() - } - - /*! - \qmlmethod void History::redo(bool updateObjectList = true) - Redoes the HistoryLib.Action at the top of the redo stack and pushes it to the top of the undo stack. - By default, will update the graph and the object list. This behavior can be disabled by setting the \c updateObjectList to false. - */ - function redo(updateObjectList = true) { - Modules.History.redo() - } -} diff --git a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml index aca7943..eb84340 100644 --- a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml +++ b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml @@ -225,7 +225,7 @@ Item { imageDepth: Screen.devicePixelRatio, fontSize: 14 }) - Modules.History.on("cleared added undone redone", () => { + Modules.History.on("cleared loaded added undone redone", () => { undoCount = Modules.History.undoStack.length redoCount = Modules.History.redoStack.length }) diff --git a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/qmldir b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/qmldir index 4f011a5..7f8a628 100644 --- a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/qmldir +++ b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/qmldir @@ -1,5 +1,4 @@ module eu.ad5001.LogarithmPlotter.History -History 1.0 History.qml HistoryBrowser 1.0 HistoryBrowser.qml HistoryItem 1.0 HistoryItem.qml diff --git a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml index 33967aa..e7cfc1a 100644 --- a/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml +++ b/runtime-pyside6/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml @@ -183,7 +183,7 @@ ApplicationWindow { } onClosing: function(close) { - if(!Modules.History.saved) { + if(!Modules.IO.saved) { close.accepted = false appMenu.openSaveUnsavedChangesDialog() }