From 6fe9e1b3a26b29c90e3b2cb1bdec441713cf6843 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 7 Apr 2021 14:51:48 +0200 Subject: [PATCH] History browser & fixing bugs --- qml/History.qml | 44 ++++++++++++++- qml/HistoryBrowser.qml | 119 +++++++++++++++++++++++++++++++++++++++++ qml/LogGraph.qml | 9 ++++ qml/ObjectLists.qml | 2 +- qml/js/objects.js | 2 - run.py | 2 +- 6 files changed, 172 insertions(+), 6 deletions(-) diff --git a/qml/History.qml b/qml/History.qml index b1dbc39..f030365 100644 --- a/qml/History.qml +++ b/qml/History.qml @@ -17,11 +17,12 @@ */ import QtQuick 2.12 +import QtQml 2.12 import "js/objects.js" as Objects import "js/historylib.js" as HistoryLib -QtObject { +Item { // Using a QtObject is necessary in order to have proper property propagation in QML id: historyObj property int undoCount: 0 @@ -29,7 +30,7 @@ QtObject { property var undoStack: [] property var redoStack: [] - function empty() { + function clear() { undoStack = [] redoStack = [] } @@ -40,6 +41,7 @@ QtObject { undoStack.push(action) undoCount++; redoStack = [] + redoCount = 0 } } @@ -65,6 +67,44 @@ QtObject { } } + function undoMultipleDefered(toUndoCount) { + undoTimer.toUndoCount = toUndoCount; + undoTimer.start() + } + + function redoMultipleDefered(toRedoCount) { + redoTimer.toRedoCount = toRedoCount; + redoTimer.start() + } + + Timer { + id: undoTimer + interval: 5; running: false; repeat: true + property int toUndoCount: 0 + onTriggered: { + if(toUndoCount > 0) { + historyObj.undo() + toUndoCount--; + } else { + running = false; + } + } + } + + Timer { + id: redoTimer + interval: 5; running: false; repeat: true + property int toRedoCount: 0 + onTriggered: { + if(toRedoCount > 0) { + historyObj.redo() + toRedoCount--; + } else { + running = false; + } + } + } + Component.onCompleted: { Objects.history = historyObj Objects.HistoryLib = HistoryLib diff --git a/qml/HistoryBrowser.qml b/qml/HistoryBrowser.qml index 8b13789..56589a4 100644 --- a/qml/HistoryBrowser.qml +++ b/qml/HistoryBrowser.qml @@ -1 +1,120 @@ +/** + * Logarithm Graph Creator - Create graphs with logarithm scales. + * Copyright (C) 2020 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.Controls 2.12 +import QtQuick 2.12 +import "js/utils.js" as Utils + +ScrollView { + id: historyBrowser + + property int actionWidth: width-20 + + Flickable { + width: parent.width + height: parent.height + contentHeight: redoColumn.height + nowRect.height + undoColumn.height + contentWidth: parent.width + + Column { + id: redoColumn + anchors.right: parent.right + anchors.top: parent.top + width: historyBrowser.actionWidth + + Repeater { + model: history.redoCount + + Button { + id: redoButton + width: historyBrowser.actionWidth + height: 30 + flat: true + text: history.redoStack[index].getReadableString() + + + onClicked: { + history.redoMultipleDefered(history.redoCount-index) + } + } + } + } + + Text { + anchors.left: parent.left + anchors.bottom: nowRect.top + text: "Redo >" + color: sysPaletteIn.windowText + transform: Rotation { origin.x: 30; origin.y: 30; angle: 270} + height: 70 + width: 20 + visible: history.redoCount > 0 + } + + Rectangle { + id: nowRect + anchors.right: parent.right + anchors.top: redoColumn.bottom + width: historyBrowser.actionWidth + height: 30 + color: sysPalette.highlight + Text { + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 5 + text: "> Now" + color: sysPalette.windowText + } + } + + Column { + id: undoColumn + anchors.right: parent.right + anchors.top: nowRect.bottom + width: historyBrowser.actionWidth + + Repeater { + model: history.undoCount + + Button { + id: undoButton + width: historyBrowser.actionWidth + height: 30 + flat: true + text: history.undoStack[history.undoCount-index-1].getReadableString() + + + onClicked: { + history.undoMultipleDefered(index+1) + } + } + } + } + + Text { + anchors.left: parent.left + anchors.top: undoColumn.top + text: "< Undo" + color: sysPaletteIn.windowText + transform: Rotation { origin.x: 30; origin.y: 30; angle: 270} + height: 60 + width: 20 + visible: history.undoCount > 0 + } + } +} diff --git a/qml/LogGraph.qml b/qml/LogGraph.qml index fd4947a..6d4e0d8 100644 --- a/qml/LogGraph.qml +++ b/qml/LogGraph.qml @@ -59,6 +59,9 @@ ApplicationWindow { TabButton { text: qsTr("Settings") } + TabButton { + text: qsTr("History") + } } StackLayout { @@ -68,6 +71,7 @@ ApplicationWindow { anchors.topMargin: 5 anchors.leftMargin: 5 anchors.bottom: parent.bottom + anchors.bottomMargin: 20 width: parent.width - 10 currentIndex: sidebarSelector.currentIndex z: -1 @@ -82,6 +86,10 @@ ApplicationWindow { id: settings onChanged: drawCanvas.requestPaint() } + + HistoryBrowser { + id: historyBrowser + } } } @@ -142,6 +150,7 @@ ApplicationWindow { var data = JSON.parse(Helper.load(filename)) var error = ""; if(Object.keys(data).includes("type") && data["type"] == "logplotv1") { + history.clear() settings.saveFilename = filename settings.xzoom = data["xzoom"] settings.yzoom = data["yzoom"] diff --git a/qml/ObjectLists.qml b/qml/ObjectLists.qml index 6aad4db..4762296 100644 --- a/qml/ObjectLists.qml +++ b/qml/ObjectLists.qml @@ -90,7 +90,7 @@ ListView { anchors.leftMargin: 5 onClicked: { history.addToHistory(new HistoryLib.EditedVisibility( - objEditor.obj.name, objEditor.objType, this.checked + Objects.currentObjects[objType][index].name, objType, this.checked )) Objects.currentObjects[objType][index].visible = this.checked objectListList.changed() diff --git a/qml/js/objects.js b/qml/js/objects.js index e4edb69..4fbbff7 100644 --- a/qml/js/objects.js +++ b/qml/js/objects.js @@ -1195,7 +1195,6 @@ class RepartitionFunction extends ExecutableObject { draw(canvas, ctx) { var currentY = 0; var keys = Object.keys(this.probabilities).map(idx => parseInt(idx)).sort((a,b) => a-b) - console.log("Keys", keys) if(canvas.visible(keys[0],this.probabilities[keys[0]].replace(/,/g, '.'))) { canvas.drawLine(ctx, 0, @@ -1213,7 +1212,6 @@ class RepartitionFunction extends ExecutableObject { var idx = keys[i]; currentY += parseFloat(this.probabilities[idx].replace(/,/g, '.')); if(canvas.visible(idx,currentY) || canvas.visible(keys[i+1],currentY)) { - console.log("Drawing", idx, Math.max(0,canvas.x2px(idx)), canvas.y2px(currentY), Math.min(canvas.canvasSize.width,canvas.x2px(keys[i+1])), canvas.y2px(currentY)) canvas.drawLine(ctx, Math.max(0,canvas.x2px(idx)), canvas.y2px(currentY), diff --git a/run.py b/run.py index 730665b..bdec8bc 100644 --- a/run.py +++ b/run.py @@ -31,7 +31,7 @@ pwd = os.getcwd() os.chdir(os.path.dirname(os.path.realpath(__file__))) -tempfile = tempfile.mkstemp(suffix = '.png')[1] +tempfile = tempfile.mkstemp(suffix='.png')[1] def get_linux_theme(): des = {