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:
Ad5001 2022-01-31 20:17:24 +01:00
parent 73877a0dd4
commit 3119c3f9dc
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
12 changed files with 423 additions and 259 deletions

View file

@ -20,6 +20,7 @@ import QtQuick 2.12
import QtQml 2.12
import "../js/objects.js" as Objects
import "../js/historylib.js" as HistoryLib
import "../js/history/common.js" as HistoryCommon
/*!
\qmltype History
@ -209,5 +210,6 @@ Item {
Component.onCompleted: {
HistoryLib.history = historyObj
HistoryCommon.themeTextColor = sysPalette.windowText
}
}

View file

@ -43,11 +43,6 @@ ScrollView {
*/
property int actionWidth: width-20
/*!
\qmlproperty int HistoryBrowser::actionHeight
Height of the actions.
*/
property int actionHeight: 40
/*!
\qmlproperty int HistoryBrowser::darkTheme
true when the system is running with a dark theme, false otherwise.
@ -72,7 +67,7 @@ ScrollView {
HistoryItem {
id: redoButton
width: actionWidth
height: actionHeight
//height: actionHeight
isRedo: true
idx: index
darkTheme: historyBrowser.darkTheme
@ -96,7 +91,7 @@ ScrollView {
anchors.right: parent.right
anchors.top: redoColumn.bottom
width: actionWidth
height: actionHeight
height: 40
color: sysPalette.highlight
Text {
anchors.verticalCenter: parent.verticalCenter
@ -120,7 +115,7 @@ ScrollView {
HistoryItem {
id: undoButton
width: actionWidth
height: actionHeight
//height: actionHeight
isRedo: false
idx: index
darkTheme: historyBrowser.darkTheme

View file

@ -59,6 +59,14 @@ Button {
*/
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 {
anchors.fill: parent
start: Qt.point(0, 0)
@ -74,7 +82,7 @@ Button {
width: 18
height: 18
anchors.left: parent.left
anchors.leftMargin: (parent.height-height)/2
anchors.leftMargin: 6
anchors.verticalCenter: parent.verticalCenter
color: sysPalette.windowText
@ -85,19 +93,21 @@ Button {
id: label
anchors.left: icon.right
anchors.right: parent.right
anchors.leftMargin: 4
anchors.rightMargin: (parent.height-height)/2
anchors.leftMargin: 6
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 14
text: historyAction.getReadableString()
text: historyAction.getHTMLString()
textFormat: Text.RichText
clip: true
wrapMode: Text.WordWrap
}
//text: historyAction.getReadableString()
ToolTip.visible: hovered
ToolTip.delay: 200
ToolTip.text: label.text
ToolTip.text: historyAction.getReadableString()
onClicked: {
if(isRedo)
@ -105,6 +115,14 @@ Button {
else
history.undoMultipleDefered(+idx+1)
}
Rectangle {
color: sysPalette. window
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 1
}
}

View file

@ -215,7 +215,7 @@ ListView {
color: obj.color
title: qsTr("Pick new color for %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
onAccepted: {
history.addToHistory(new HistoryLib.EditedProperty(
history.addToHistory(new HistoryLib.ColorChanged(
obj.name, objType, "color",
obj.color, color.toString()
))

View file

@ -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;">&nbsp;&nbsp;</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))
}
}

View file

@ -18,6 +18,8 @@
.pragma library
var themeTextColor;
class Action {
// Type of the action done.
@ -39,7 +41,18 @@ class Action {
return [this.targetName, this.targetType]
}
// String used in the toolkit
getReadableString() {
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()
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}
}

View file

@ -20,255 +20,24 @@
// Each type of event is repertoried as an action that can be listed for everything that's undoable.
.pragma library
.import "objects.js" as Objects
.import "parameters.js" as P
.import "objs/common.js" as Common
.import "utils.js" as Utils
.import "mathlib.js" as MathLib
.import "history/common.js" as Common
.import "history/create.js" as Create
.import "history/delete.js" as Delete
.import "history/editproperty.js" as EP
.import "history/visibility.js" as V
.import "history/name.js" as Name
.import "history/color.js" as Color
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 {
// 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)
}
}
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 Action = Common.Action
var CreateNewObject = Create.CreateNewObject
var DeleteObject = Delete.DeleteObject
var EditedProperty = EP.EditedProperty
var EditedVisibility = V.EditedVisibility
var NameChanged = Name.NameChanged
var ColorChanged = Color.ColorChanged
var Actions = {
"Action": Action,