A lot of history changes
+ History item labels are now RichText which allows for better representation of certain items. + History item labels are now multiline + History item labels now have a very small separator to distinguish them from each other. + Separating history actions into components
This commit is contained in:
parent
73877a0dd4
commit
3119c3f9dc
12 changed files with 423 additions and 259 deletions
|
@ -20,6 +20,7 @@ import QtQuick 2.12
|
||||||
import QtQml 2.12
|
import QtQml 2.12
|
||||||
import "../js/objects.js" as Objects
|
import "../js/objects.js" as Objects
|
||||||
import "../js/historylib.js" as HistoryLib
|
import "../js/historylib.js" as HistoryLib
|
||||||
|
import "../js/history/common.js" as HistoryCommon
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\qmltype History
|
\qmltype History
|
||||||
|
@ -209,5 +210,6 @@ Item {
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
HistoryLib.history = historyObj
|
HistoryLib.history = historyObj
|
||||||
|
HistoryCommon.themeTextColor = sysPalette.windowText
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,6 @@ ScrollView {
|
||||||
*/
|
*/
|
||||||
property int actionWidth: width-20
|
property int actionWidth: width-20
|
||||||
|
|
||||||
/*!
|
|
||||||
\qmlproperty int HistoryBrowser::actionHeight
|
|
||||||
Height of the actions.
|
|
||||||
*/
|
|
||||||
property int actionHeight: 40
|
|
||||||
/*!
|
/*!
|
||||||
\qmlproperty int HistoryBrowser::darkTheme
|
\qmlproperty int HistoryBrowser::darkTheme
|
||||||
true when the system is running with a dark theme, false otherwise.
|
true when the system is running with a dark theme, false otherwise.
|
||||||
|
@ -72,7 +67,7 @@ ScrollView {
|
||||||
HistoryItem {
|
HistoryItem {
|
||||||
id: redoButton
|
id: redoButton
|
||||||
width: actionWidth
|
width: actionWidth
|
||||||
height: actionHeight
|
//height: actionHeight
|
||||||
isRedo: true
|
isRedo: true
|
||||||
idx: index
|
idx: index
|
||||||
darkTheme: historyBrowser.darkTheme
|
darkTheme: historyBrowser.darkTheme
|
||||||
|
@ -96,7 +91,7 @@ ScrollView {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: redoColumn.bottom
|
anchors.top: redoColumn.bottom
|
||||||
width: actionWidth
|
width: actionWidth
|
||||||
height: actionHeight
|
height: 40
|
||||||
color: sysPalette.highlight
|
color: sysPalette.highlight
|
||||||
Text {
|
Text {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
@ -120,7 +115,7 @@ ScrollView {
|
||||||
HistoryItem {
|
HistoryItem {
|
||||||
id: undoButton
|
id: undoButton
|
||||||
width: actionWidth
|
width: actionWidth
|
||||||
height: actionHeight
|
//height: actionHeight
|
||||||
isRedo: false
|
isRedo: false
|
||||||
idx: index
|
idx: index
|
||||||
darkTheme: historyBrowser.darkTheme
|
darkTheme: historyBrowser.darkTheme
|
||||||
|
|
|
@ -59,6 +59,14 @@ Button {
|
||||||
*/
|
*/
|
||||||
readonly property var historyAction: isRedo ? history.redoStack[idx] : history.undoStack[history.undoCount-idx-1]
|
readonly property var historyAction: isRedo ? history.redoStack[idx] : history.undoStack[history.undoCount-idx-1]
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\qmlproperty int HistoryItem::actionHeight
|
||||||
|
Base height of the action.
|
||||||
|
*/
|
||||||
|
readonly property int actionHeight: 40
|
||||||
|
|
||||||
|
height: Math.max(actionHeight, label.height + 15)
|
||||||
|
|
||||||
LinearGradient {
|
LinearGradient {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
start: Qt.point(0, 0)
|
start: Qt.point(0, 0)
|
||||||
|
@ -74,7 +82,7 @@ Button {
|
||||||
width: 18
|
width: 18
|
||||||
height: 18
|
height: 18
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: (parent.height-height)/2
|
anchors.leftMargin: 6
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
color: sysPalette.windowText
|
color: sysPalette.windowText
|
||||||
|
@ -85,19 +93,21 @@ Button {
|
||||||
id: label
|
id: label
|
||||||
anchors.left: icon.right
|
anchors.left: icon.right
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.leftMargin: 4
|
anchors.leftMargin: 6
|
||||||
anchors.rightMargin: (parent.height-height)/2
|
anchors.rightMargin: 10
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
text: historyAction.getReadableString()
|
text: historyAction.getHTMLString()
|
||||||
|
textFormat: Text.RichText
|
||||||
clip: true
|
clip: true
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
//text: historyAction.getReadableString()
|
//text: historyAction.getReadableString()
|
||||||
|
|
||||||
ToolTip.visible: hovered
|
ToolTip.visible: hovered
|
||||||
ToolTip.delay: 200
|
ToolTip.delay: 200
|
||||||
ToolTip.text: label.text
|
ToolTip.text: historyAction.getReadableString()
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if(isRedo)
|
if(isRedo)
|
||||||
|
@ -105,6 +115,14 @@ Button {
|
||||||
else
|
else
|
||||||
history.undoMultipleDefered(+idx+1)
|
history.undoMultipleDefered(+idx+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
color: sysPalette. window
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
height: 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ ListView {
|
||||||
color: obj.color
|
color: obj.color
|
||||||
title: qsTr("Pick new color for %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
|
title: qsTr("Pick new color for %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
history.addToHistory(new HistoryLib.EditedProperty(
|
history.addToHistory(new HistoryLib.ColorChanged(
|
||||||
obj.name, objType, "color",
|
obj.name, objType, "color",
|
||||||
obj.color, color.toString()
|
obj.color, color.toString()
|
||||||
))
|
))
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pragma library
|
||||||
|
|
||||||
|
.import "editproperty.js" as EP
|
||||||
|
.import "../objects.js" as Objects
|
||||||
|
|
||||||
|
|
||||||
|
class ColorChanged extends EP.EditedProperty {
|
||||||
|
// Action used everytime when an object's color is changed
|
||||||
|
type(){return 'ColorChanged'}
|
||||||
|
|
||||||
|
icon(){return 'appearance'}
|
||||||
|
|
||||||
|
|
||||||
|
color(darkVer=false){return darkVer ? 'purple' : 'plum'}
|
||||||
|
|
||||||
|
getReadableString() {
|
||||||
|
return qsTr("%1 %2's color changed from %3 to %4.")
|
||||||
|
.arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
|
||||||
|
.arg(this.previousValue).arg(this.newValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
formatColor(color) {
|
||||||
|
return `<span style="background: ${color}; color: white; font-family: monospace; border: solid 1px ${color}; border-style: outset; padding: 4px;"> </span>`
|
||||||
|
}
|
||||||
|
|
||||||
|
getHTMLString() {
|
||||||
|
return qsTr("%1 %2's color changed from %3 to %4.")
|
||||||
|
.arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
|
||||||
|
.arg(this.formatColor(this.previousValue)).arg(this.formatColor(this.newValue))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
.pragma library
|
.pragma library
|
||||||
|
|
||||||
|
var themeTextColor;
|
||||||
|
|
||||||
|
|
||||||
class Action {
|
class Action {
|
||||||
// Type of the action done.
|
// Type of the action done.
|
||||||
|
@ -39,7 +41,18 @@ class Action {
|
||||||
return [this.targetName, this.targetType]
|
return [this.targetName, this.targetType]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String used in the toolkit
|
||||||
getReadableString() {
|
getReadableString() {
|
||||||
return 'Unknown action'
|
return 'Unknown action'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns an HTML tag containing the icon of a type
|
||||||
|
getIconRichText(type) {
|
||||||
|
return `<img source="../icons/objects/${type}.svg" style="color: ${themeTextColor};" width=18 height=18></img>`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String used in the preview
|
||||||
|
getHTMLString() {
|
||||||
|
return this.getReadableString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pragma library
|
||||||
|
|
||||||
|
.import "../objects.js" as Objects
|
||||||
|
.import "common.js" as C
|
||||||
|
|
||||||
|
class CreateNewObject extends C.Action {
|
||||||
|
// Action used for the creation of an object
|
||||||
|
type(){return 'CreateNewObject'}
|
||||||
|
|
||||||
|
icon(){return 'create'}
|
||||||
|
|
||||||
|
color(darkVer=false){return darkVer ? 'green' : 'lime'}
|
||||||
|
|
||||||
|
constructor(targetName = "", targetType = "Point", properties = []) {
|
||||||
|
super(targetName, targetType)
|
||||||
|
this.targetProperties = properties
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
var targetIndex = Objects.getObjectsName(this.targetType).indexOf(this.targetName)
|
||||||
|
Objects.currentObjects[this.targetType][targetIndex].delete()
|
||||||
|
Objects.currentObjects[this.targetType].splice(targetIndex, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
redo() {
|
||||||
|
Objects.createNewRegisteredObject(this.targetType, this.targetProperties)
|
||||||
|
}
|
||||||
|
|
||||||
|
export() {
|
||||||
|
return [this.targetName, this.targetType, this.targetProperties]
|
||||||
|
}
|
||||||
|
|
||||||
|
getReadableString() {
|
||||||
|
return qsTr("New %1 %2 created.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pragma library
|
||||||
|
|
||||||
|
.import "../objects.js" as Objects
|
||||||
|
.import "create.js" as Create
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteObject extends Create.CreateNewObject {
|
||||||
|
// Action used at the deletion of an object. Basicly the same thing as creating a new object, except Redo & Undo are reversed.
|
||||||
|
type(){return 'DeleteObject'}
|
||||||
|
|
||||||
|
icon(){return 'delete'}
|
||||||
|
|
||||||
|
color(darkVer=false){return darkVer ? 'darkred' : 'salmon'}
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
super.redo()
|
||||||
|
}
|
||||||
|
|
||||||
|
redo() {
|
||||||
|
super.undo()
|
||||||
|
}
|
||||||
|
|
||||||
|
getReadableString() {
|
||||||
|
return qsTr("%1 %2 deleted.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
/**
|
||||||
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pragma library
|
||||||
|
|
||||||
|
.import "../objects.js" as Objects
|
||||||
|
.import "../mathlib.js" as MathLib
|
||||||
|
.import "../objs/common.js" as Common
|
||||||
|
.import "common.js" as C
|
||||||
|
|
||||||
|
class EditedProperty extends C.Action {
|
||||||
|
// Action used everytime an object's property has been changed
|
||||||
|
type(){return 'EditedProperty'}
|
||||||
|
|
||||||
|
icon(){return 'modify'}
|
||||||
|
|
||||||
|
color(darkVer=false){return darkVer ? 'darkslateblue' : 'cyan'}
|
||||||
|
|
||||||
|
constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true, valueIsExpressionNeedingImport = false) {
|
||||||
|
super(targetName, targetType)
|
||||||
|
this.targetProperty = targetProperty
|
||||||
|
this.targetPropertyReadable = qsTranslate("prop", this.targetProperty)
|
||||||
|
this.previousValue = previousValue
|
||||||
|
this.newValue = newValue
|
||||||
|
this.propertyType = Objects.types[targetType].properties()[targetProperty]
|
||||||
|
if(valueIsExpressionNeedingImport) {
|
||||||
|
if(this.propertyType == "Expression") {
|
||||||
|
this.previousValue = new MathLib.Expression(this.previousValue);
|
||||||
|
this.newValue = new MathLib.Expression(this.newValue);
|
||||||
|
} else if(this.propertyType == "Domain") {
|
||||||
|
this.previousValue = MathLib.parseDomain(this.previousValue);
|
||||||
|
this.newValue = MathLib.parseDomain(this.newValue);
|
||||||
|
} else {
|
||||||
|
// Objects
|
||||||
|
this.previousValue = Objects.getObjectByName(this.previousValue);
|
||||||
|
this.newValue = Objects.getObjectByName(this.newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.previousValue
|
||||||
|
}
|
||||||
|
|
||||||
|
redo() {
|
||||||
|
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
export() {
|
||||||
|
if(this.previousValue instanceof MathLib.Expression) {
|
||||||
|
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.toEditableString(), this.newValue.toEditableString(), true]
|
||||||
|
} else if(this.previousValue instanceof Common.DrawableObject) {
|
||||||
|
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true]
|
||||||
|
} else {
|
||||||
|
return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getReadableString() {
|
||||||
|
let prev = "";
|
||||||
|
let next = "";
|
||||||
|
if(this.propertyType instanceof Object) {
|
||||||
|
switch(this.propertyType.type) {
|
||||||
|
case "Enum":
|
||||||
|
prev = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
|
||||||
|
next = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
|
||||||
|
break;
|
||||||
|
case "ObjectType":
|
||||||
|
prev = this.previousValue.name
|
||||||
|
next = this.newValue.name
|
||||||
|
break;
|
||||||
|
case "List":
|
||||||
|
prev = this.previousValue.join(",")
|
||||||
|
next = this.newValue.name.join(",")
|
||||||
|
break;
|
||||||
|
case "Dict":
|
||||||
|
prev = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'")
|
||||||
|
next = JSON.stringify(this.newValue).replace("'", "\\'").replace('"', "'")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prev = this.previousValue == null ? "null" : this.previousValue.toString()
|
||||||
|
next = this.newValue == null ? "null" : this.newValue.toString()
|
||||||
|
}
|
||||||
|
return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
|
||||||
|
.arg(this.targetPropertyReadable)
|
||||||
|
.arg(Objects.types[this.targetType].displayType())
|
||||||
|
.arg(this.targetName).arg(prev).arg(next)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pragma library
|
||||||
|
|
||||||
|
.import "editproperty.js" as EP
|
||||||
|
.import "../objects.js" as Objects
|
||||||
|
|
||||||
|
|
||||||
|
class NameChanged extends EP.EditedProperty {
|
||||||
|
// Action used everytime an object's property has been changed
|
||||||
|
type(){return 'NameChanged'}
|
||||||
|
|
||||||
|
icon(){return 'name'}
|
||||||
|
|
||||||
|
|
||||||
|
color(darkVer=false){return darkVer ? 'darkorange' : 'orange'}
|
||||||
|
|
||||||
|
constructor(targetName = "", targetType = "Point", newName = "") {
|
||||||
|
super(targetName, targetType, "name", targetName, newName)
|
||||||
|
}
|
||||||
|
|
||||||
|
export() {
|
||||||
|
return [this.targetName, this.targetType, this.newValue]
|
||||||
|
}
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
Objects.getObjectByName(this.newValue, this.targetType)['name'] = this.previousValue
|
||||||
|
}
|
||||||
|
|
||||||
|
redo() {
|
||||||
|
Objects.getObjectByName(this.previousValue, this.targetType)['name'] = this.newValue
|
||||||
|
}
|
||||||
|
|
||||||
|
getReadableString() {
|
||||||
|
return qsTr('Name of %1 %2 changed to %3.')
|
||||||
|
.arg(Objects.types[this.targetType].displayType())
|
||||||
|
.arg(this.targetName).arg(this.newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pragma library
|
||||||
|
|
||||||
|
.import "editproperty.js" as EP
|
||||||
|
|
||||||
|
|
||||||
|
class EditedVisibility extends EP.EditedProperty {
|
||||||
|
// Action used when an object's shown or hidden.
|
||||||
|
type(){return 'EditedVisibility'}
|
||||||
|
|
||||||
|
icon(){return 'visibility'}
|
||||||
|
|
||||||
|
color(darkVer=false){
|
||||||
|
return this.newValue ?
|
||||||
|
(darkVer ? 'darkgray' : 'whitesmoke') :
|
||||||
|
(darkVer ? 'dimgray' : 'lightgray')
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(targetName = "", targetType = "Point", newValue = true) {
|
||||||
|
super(targetName, targetType, "visible", !newValue, newValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
export() {
|
||||||
|
return [this.targetName, this.targetType, this.newValue]
|
||||||
|
}
|
||||||
|
|
||||||
|
getReadableString() {
|
||||||
|
if(this.newValue) {
|
||||||
|
return qsTr('%1 %2 shown.').arg(this.targetType).arg(this.targetName)
|
||||||
|
} else {
|
||||||
|
return qsTr('%1 %2 hidden.').arg(this.targetType).arg(this.targetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,255 +20,24 @@
|
||||||
// Each type of event is repertoried as an action that can be listed for everything that's undoable.
|
// Each type of event is repertoried as an action that can be listed for everything that's undoable.
|
||||||
.pragma library
|
.pragma library
|
||||||
|
|
||||||
.import "objects.js" as Objects
|
.import "history/common.js" as Common
|
||||||
.import "parameters.js" as P
|
.import "history/create.js" as Create
|
||||||
.import "objs/common.js" as Common
|
.import "history/delete.js" as Delete
|
||||||
.import "utils.js" as Utils
|
.import "history/editproperty.js" as EP
|
||||||
.import "mathlib.js" as MathLib
|
.import "history/visibility.js" as V
|
||||||
|
.import "history/name.js" as Name
|
||||||
|
.import "history/color.js" as Color
|
||||||
|
|
||||||
var history = null;
|
var history = null;
|
||||||
|
|
||||||
class Action {
|
|
||||||
// Type of the action done.
|
|
||||||
type(){return 'Unknown'}
|
|
||||||
|
|
||||||
// Icon of the action to be used in history browser.
|
|
||||||
icon(){return 'unknown'}
|
|
||||||
|
|
||||||
// Color associated with the action.
|
|
||||||
color(darkVer=false){return darkVer ? 'black' : 'white'}
|
|
||||||
|
|
||||||
// TargetName is the name of the object that's targeted by the event.
|
|
||||||
constructor(targetName = "", targetType = "Point") {
|
|
||||||
this.targetName = targetName
|
|
||||||
this.targetType = targetType
|
|
||||||
}
|
|
||||||
|
|
||||||
undo() {}
|
|
||||||
|
|
||||||
redo() {}
|
|
||||||
|
|
||||||
export() {
|
|
||||||
return [this.targetName, this.targetType]
|
|
||||||
}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
return 'Unknown action'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CreateNewObject extends Action {
|
var Action = Common.Action
|
||||||
// Action used for the creation of an object
|
var CreateNewObject = Create.CreateNewObject
|
||||||
type(){return 'CreateNewObject'}
|
var DeleteObject = Delete.DeleteObject
|
||||||
|
var EditedProperty = EP.EditedProperty
|
||||||
icon(){return 'create'}
|
var EditedVisibility = V.EditedVisibility
|
||||||
|
var NameChanged = Name.NameChanged
|
||||||
color(darkVer=false){return darkVer ? 'green' : 'lime'}
|
var ColorChanged = Color.ColorChanged
|
||||||
|
|
||||||
constructor(targetName = "", targetType = "Point", properties = []) {
|
|
||||||
super(targetName, targetType)
|
|
||||||
this.targetProperties = properties
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
undo() {
|
|
||||||
var targetIndex = Objects.getObjectsName(this.targetType).indexOf(this.targetName)
|
|
||||||
Objects.currentObjects[this.targetType][targetIndex].delete()
|
|
||||||
Objects.currentObjects[this.targetType].splice(targetIndex, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
redo() {
|
|
||||||
Objects.createNewRegisteredObject(this.targetType, this.targetProperties)
|
|
||||||
}
|
|
||||||
|
|
||||||
export() {
|
|
||||||
return [this.targetName, this.targetType, this.targetProperties]
|
|
||||||
}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
return qsTr("New %1 %2 created.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DeleteObject extends CreateNewObject {
|
|
||||||
// Action used at the deletion of an object. Basicly the same thing as creating a new object, except Redo & Undo are reversed.
|
|
||||||
type(){return 'DeleteObject'}
|
|
||||||
|
|
||||||
icon(){return 'delete'}
|
|
||||||
|
|
||||||
color(darkVer=false){return darkVer ? 'darkred' : 'salmon'}
|
|
||||||
|
|
||||||
undo() {
|
|
||||||
super.redo()
|
|
||||||
}
|
|
||||||
|
|
||||||
redo() {
|
|
||||||
super.undo()
|
|
||||||
}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
return qsTr("%1 %2 deleted.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EditedProperty extends Action {
|
|
||||||
// Action used everytime an object's property has been changed
|
|
||||||
type(){return 'EditedProperty'}
|
|
||||||
|
|
||||||
icon(){return 'modify'}
|
|
||||||
|
|
||||||
color(darkVer=false){return darkVer ? 'darkslateblue' : 'cyan'}
|
|
||||||
|
|
||||||
constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true, valueIsExpressionNeedingImport = false) {
|
|
||||||
super(targetName, targetType)
|
|
||||||
this.targetProperty = targetProperty
|
|
||||||
this.targetPropertyReadable = qsTranslate("prop", this.targetProperty)
|
|
||||||
this.previousValue = previousValue
|
|
||||||
this.newValue = newValue
|
|
||||||
this.propertyType = Objects.types[targetType].properties()[targetProperty]
|
|
||||||
if(valueIsExpressionNeedingImport) {
|
|
||||||
if(this.propertyType == "Expression") {
|
|
||||||
this.previousValue = new MathLib.Expression(this.previousValue);
|
|
||||||
this.newValue = new MathLib.Expression(this.newValue);
|
|
||||||
} else if(this.propertyType == "Domain") {
|
|
||||||
this.previousValue = MathLib.parseDomain(this.previousValue);
|
|
||||||
this.newValue = MathLib.parseDomain(this.newValue);
|
|
||||||
} else {
|
|
||||||
// Objects
|
|
||||||
this.previousValue = Objects.getObjectByName(this.previousValue);
|
|
||||||
this.newValue = Objects.getObjectByName(this.newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
undo() {
|
|
||||||
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.previousValue
|
|
||||||
}
|
|
||||||
|
|
||||||
redo() {
|
|
||||||
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.newValue
|
|
||||||
}
|
|
||||||
|
|
||||||
export() {
|
|
||||||
if(this.previousValue instanceof MathLib.Expression) {
|
|
||||||
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.toEditableString(), this.newValue.toEditableString(), true]
|
|
||||||
} else if(this.previousValue instanceof Common.DrawableObject) {
|
|
||||||
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true]
|
|
||||||
} else {
|
|
||||||
return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
let prev = "";
|
|
||||||
let next = "";
|
|
||||||
if(this.propertyType instanceof Object) {
|
|
||||||
switch(this.propertyType.type) {
|
|
||||||
case "Enum":
|
|
||||||
prev = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
|
|
||||||
next = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
|
|
||||||
break;
|
|
||||||
case "ObjectType":
|
|
||||||
prev = this.previousValue.name
|
|
||||||
next = this.newValue.name
|
|
||||||
break;
|
|
||||||
case "List":
|
|
||||||
prev = this.previousValue.join(",")
|
|
||||||
next = this.newValue.name.join(",")
|
|
||||||
break;
|
|
||||||
case "Dict":
|
|
||||||
prev = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'")
|
|
||||||
next = JSON.stringify(this.newValue).replace("'", "\\'").replace('"', "'")
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
prev = this.previousValue == null ? "null" : this.previousValue.toString()
|
|
||||||
next = this.newValue == null ? "null" : this.newValue.toString()
|
|
||||||
}
|
|
||||||
return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
|
|
||||||
.arg(this.targetPropertyReadable)
|
|
||||||
.arg(Objects.types[this.targetType].displayType())
|
|
||||||
.arg(this.targetName).arg(prev).arg(next)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class EditedVisibility extends EditedProperty {
|
|
||||||
// Action used everytime an object's property has been changed
|
|
||||||
type(){return 'EditedVisibility'}
|
|
||||||
|
|
||||||
icon(){return 'visibility'}
|
|
||||||
|
|
||||||
color(darkVer=false){
|
|
||||||
return this.newValue ?
|
|
||||||
(darkVer ? 'darkgray' : 'whitesmoke') :
|
|
||||||
(darkVer ? 'dimgray' : 'lightgray')
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(targetName = "", targetType = "Point", newValue = true) {
|
|
||||||
super(targetName, targetType, "visible", !newValue, newValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
export() {
|
|
||||||
return [this.targetName, this.targetType, this.newValue]
|
|
||||||
}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
if(this.newValue) {
|
|
||||||
return qsTr('%1 %2 shown.').arg(this.targetType).arg(this.targetName)
|
|
||||||
} else {
|
|
||||||
return qsTr('%1 %2 hidden.').arg(this.targetType).arg(this.targetName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NameChanged extends EditedProperty {
|
|
||||||
// Action used everytime an object's property has been changed
|
|
||||||
type(){return 'NameChanged'}
|
|
||||||
|
|
||||||
icon(){return 'name'}
|
|
||||||
|
|
||||||
|
|
||||||
color(darkVer=false){return darkVer ? 'darkorange' : 'orange'}
|
|
||||||
|
|
||||||
constructor(targetName = "", targetType = "Point", newName = "") {
|
|
||||||
super(targetName, targetType, "name", targetName, newName)
|
|
||||||
}
|
|
||||||
|
|
||||||
export() {
|
|
||||||
return [this.targetName, this.targetType, this.newValue]
|
|
||||||
}
|
|
||||||
|
|
||||||
undo() {
|
|
||||||
Objects.getObjectByName(this.newValue, this.targetType)['name'] = this.previousValue
|
|
||||||
}
|
|
||||||
|
|
||||||
redo() {
|
|
||||||
Objects.getObjectByName(this.previousValue, this.targetType)['name'] = this.newValue
|
|
||||||
}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
return qsTr('Name of %1 %2 changed to %3.')
|
|
||||||
.arg(Objects.types[this.targetType].displayType())
|
|
||||||
.arg(this.targetName).arg(this.newValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ColorChanged extends EditedProperty {
|
|
||||||
// Action used everytime an object's property has been changed
|
|
||||||
type(){return 'ColorChanged'}
|
|
||||||
|
|
||||||
icon(){return 'appearance'}
|
|
||||||
|
|
||||||
|
|
||||||
color(darkVer=false){return darkVer ? 'purple' : 'plum'}
|
|
||||||
|
|
||||||
getReadableString() {
|
|
||||||
return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
|
|
||||||
.arg(QT_TRANSLATE_NOOP('prop','color'))
|
|
||||||
.arg(Objects.types[this.targetType].displayType())
|
|
||||||
.arg(this.targetName).arg(this.previousValue).arg(this.newValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var Actions = {
|
var Actions = {
|
||||||
"Action": Action,
|
"Action": Action,
|
||||||
|
|
Loading…
Reference in a new issue