2021-04-06 17:06:09 +00:00
|
|
|
/**
|
|
|
|
* 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 <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 = []
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|