2021-04-06 17:06:09 +00:00
|
|
|
/**
|
2021-06-18 21:56:22 +00:00
|
|
|
* LogarithmPlotter - Create graphs with logarithm scales.
|
2021-05-03 15:31:37 +00:00
|
|
|
* Copyright (C) 2021 Ad5001
|
2021-04-06 17:06:09 +00:00
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
2021-04-07 12:51:48 +00:00
|
|
|
import QtQml 2.12
|
2021-04-06 17:06:09 +00:00
|
|
|
import "js/objects.js" as Objects
|
|
|
|
import "js/historylib.js" as HistoryLib
|
|
|
|
|
|
|
|
|
2021-04-07 12:51:48 +00:00
|
|
|
Item {
|
2021-04-06 17:06:09 +00:00
|
|
|
// Using a QtObject is necessary in order to have proper property propagation in QML
|
|
|
|
id: historyObj
|
|
|
|
property int undoCount: 0
|
|
|
|
property int redoCount: 0
|
|
|
|
property var undoStack: []
|
|
|
|
property var redoStack: []
|
|
|
|
|
2021-04-07 12:51:48 +00:00
|
|
|
function clear() {
|
2021-04-06 17:06:09 +00:00
|
|
|
undoStack = []
|
|
|
|
redoStack = []
|
|
|
|
}
|
2021-05-07 22:34:11 +00:00
|
|
|
|
|
|
|
function serialize() {
|
|
|
|
let undoSt = [], redoSt = [];
|
|
|
|
for(let i = 0; i < undoCount; i++)
|
|
|
|
undoSt.push([
|
|
|
|
undoStack[i].type(),
|
|
|
|
undoStack[i].export()
|
|
|
|
]);
|
|
|
|
for(let i = 0; i < redoCount; i++)
|
|
|
|
redoSt.push([
|
|
|
|
redoStack[i].type(),
|
|
|
|
redoStack[i].export()
|
|
|
|
]);
|
|
|
|
return [undoSt, redoSt]
|
|
|
|
}
|
|
|
|
|
|
|
|
function unserialize(undoSt, redoSt) {
|
|
|
|
clear();
|
|
|
|
for(let i = 0; i < undoSt.length; i++)
|
|
|
|
undoStack.push(new HistoryLib.Actions[undoSt[i][0]](...undoSt[i][1]))
|
|
|
|
for(let i = 0; i < redoSt.length; i++)
|
|
|
|
redoStack.push(new HistoryLib.Actions[redoSt[i][0]](...redoSt[i][1]))
|
|
|
|
undoCount = undoSt.length;
|
|
|
|
redoCount = redoSt.length;
|
|
|
|
objectLists.update()
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:06:09 +00:00
|
|
|
|
|
|
|
function addToHistory(action) {
|
|
|
|
if(action instanceof HistoryLib.Action) {
|
|
|
|
console.log("Added new entry to history: " + action.getReadableString())
|
|
|
|
undoStack.push(action)
|
|
|
|
undoCount++;
|
|
|
|
redoStack = []
|
2021-04-07 12:51:48 +00:00
|
|
|
redoCount = 0
|
2021-04-06 17:06:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function undo() {
|
|
|
|
if(undoStack.length > 0) {
|
|
|
|
var action = undoStack.pop()
|
|
|
|
action.undo()
|
|
|
|
objectLists.update()
|
|
|
|
redoStack.push(action)
|
|
|
|
undoCount--;
|
|
|
|
redoCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function redo() {
|
|
|
|
if(redoStack.length > 0) {
|
|
|
|
var action = redoStack.pop()
|
|
|
|
action.redo()
|
|
|
|
objectLists.update()
|
|
|
|
undoStack.push(action)
|
|
|
|
undoCount++;
|
|
|
|
redoCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-07 12:51:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:06:09 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
Objects.history = historyObj
|
|
|
|
Objects.HistoryLib = HistoryLib
|
|
|
|
}
|
|
|
|
}
|