Compare commits

..

No commits in common. "f76b601139d66cad377f5630a256a415266b8807" and "b8d312bb23bb3b90b324c91ac609d2ec2aef6618" have entirely different histories.

11 changed files with 159 additions and 237 deletions

View file

@ -21,13 +21,14 @@ import QtQuick.Dialogs 1.3 as D
import QtQuick.Controls 2.12
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
import "../js/objects.js" as Objects
import "../js/historylib.js" as HistoryLib
/*!
\qmltype ObjectLists
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Tab of the drawer that allows the user to manage the objects.
This item allows the user to synthetically see all objects, while giving the user the ability
This item allows the user to syntheticly see all objects, while giving the user the ability
to show, hide, delete, change the location and color, as well as opening the editor dialog
for each object.
@ -47,7 +48,7 @@ ScrollView {
ListView {
id: objectsListView
model: Object.keys(Objects.types)
//width: implicitWidth //objectListList.width - (implicitHeight > objectListList.parent.height ? 20 : 0)
width: implicitWidth //objectListList.width - (implicitHeight > objectListList.parent.height ? 20 : 0)
implicitHeight: contentItem.childrenRect.height + footer.height + 10
delegate: ListView {
@ -88,18 +89,146 @@ ScrollView {
}
}
delegate: ObjectRow {
delegate: Item {
id: controlRow
property var obj: Objects.currentObjects[objType][index]
property alias objVisible: objVisibilityCheckBox.checked
height: 40
width: objTypeList.width
obj: Objects.currentObjects[objType][index]
posPicker: positionPicker
onChanged: {
//obj = Objects.currentObjects[objType][index]
objectListList.update()
}
Component.onCompleted: objTypeList.editingRows.push(controlRow)
CheckBox {
id: objVisibilityCheckBox
checked: Objects.currentObjects[objType][index].visible
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 5
onClicked: {
history.addToHistory(new HistoryLib.EditedVisibility(
Objects.currentObjects[objType][index].name, objType, this.checked
))
Objects.currentObjects[objType][index].visible = this.checked
objectListList.changed()
controlRow.obj = Objects.currentObjects[objType][index]
}
ToolTip.visible: hovered
ToolTip.text: checked ?
qsTr("Hide %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name) :
qsTr("Show %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
}
Label {
id: objDescription
anchors.left: objVisibilityCheckBox.right
anchors.right: deleteButton.left
height: parent.height
verticalAlignment: TextInput.AlignVCenter
text: obj.getReadableString()
font.pixelSize: 14
MouseArea {
anchors.fill: parent
onClicked: {
objEditor.obj = Objects.currentObjects[objType][index]
objEditor.objType = objType
objEditor.objIndex = index
//objEditor.editingRow = controlRow
objEditor.show()
}
}
}
Button {
id: pointerButton
width: parent.height - 10
height: width
anchors.right: deleteButton.left
anchors.rightMargin: 5
anchors.topMargin: 5
Setting.Icon {
id: icon
width: 18
height: 18
anchors.centerIn: parent
color: sysPalette.windowText
source: '../icons/common/position.svg'
}
property bool hasXProp: Objects.types[objType].properties().hasOwnProperty('x')
property bool hasYProp: Objects.types[objType].properties().hasOwnProperty('y')
visible: hasXProp || hasYProp
ToolTip.visible: hovered
ToolTip.text: qsTr("Set %1 %2 position").arg(Objects.types[objType].displayType()).arg(obj.name)
onClicked: {
positionPicker.objType = objType
positionPicker.objName = obj.name
positionPicker.pickX = hasXProp
positionPicker.pickY = hasYProp
positionPicker.propertyX = 'x'
positionPicker.propertyY = 'y'
positionPicker.visible = true
}
}
Button {
id: deleteButton
width: parent.height - 10
height: width
anchors.right: colorPickRect.left
anchors.rightMargin: 5
anchors.topMargin: 5
icon.name: 'delete'
icon.source: '../icons/common/delete.svg'
icon.color: sysPalette.buttonText
ToolTip.visible: hovered
ToolTip.text: qsTr("Delete %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
onClicked: {
history.addToHistory(new HistoryLib.DeleteObject(
obj.name, objType, obj.export()
))
Objects.deleteObject(obj.name)
objectListList.update()
}
}
Rectangle {
id: colorPickRect
anchors.right: parent.right
anchors.rightMargin: 5
anchors.topMargin: 5
color: obj.color
width: parent.height - 10
height: width
radius: Math.min(width, height)
border.width: 2
border.color: sysPalette.windowText
MouseArea {
anchors.fill: parent
onClicked: pickColor.open()
}
}
D.ColorDialog {
id: pickColor
color: obj.color
title: qsTr("Pick new color for %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
onAccepted: {
history.addToHistory(new HistoryLib.ColorChanged(
obj.name, objType, obj.color, color.toString()
))
obj.color = color.toString()
controlRow.obj = Objects.currentObjects[objType][index]
objectListList.update()
}
}
}
}

View file

@ -1,196 +0,0 @@
/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution 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/>.
*/
import QtQuick 2.12
import QtQuick.Dialogs 1.3 as D
import QtQuick.Controls 2.12
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
import "../js/objects.js" as Objects
import "../js/historylib.js" as HistoryLib
import "../js/math/latex.js" as LatexJS
/*!
\qmltype ObjectRow
\inqmlmodule eu.ad5001.LogarithmPlotter
\brief Row describing an object.
This item allows the user to see, control, and modify a graph object.
It includes the visibility checkbox, the description label (optionally latex if enabled),
the reposition and delete buttons, and the color picker.
\sa LogarithmPlotter, ObjectCreationGrid, ObjectLists
*/
Item {
id: objectRow
signal changed()
property var obj
property var posPicker
property alias objVisible: objVisibilityCheckBox.checked
property int minHeight: 40
height: objDescription.height
width: obj.typeList.width
CheckBox {
id: objVisibilityCheckBox
checked: obj.visible
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 5
onClicked: {
history.addToHistory(new HistoryLib.EditedVisibility(
obj.name, obj.type, this.checked
))
obj.visible = this.checked
changed()
}
ToolTip.visible: hovered
ToolTip.text: checked ?
qsTr("Hide %1 %2").arg(obj.constructor.displayType()).arg(obj.name) :
qsTr("Show %1 %2").arg(obj.constructor.displayType()).arg(obj.name)
}
Label {
id: objDescription
anchors.left: objVisibilityCheckBox.right
anchors.right: deleteButton.left
height: LatexJS.enabled ? Math.max(parent.minHeight, latexDescription.height+4) : parent.minHeight
verticalAlignment: TextInput.AlignVCenter
text: LatexJS.enabled ? "" : obj.getReadableString()
font.pixelSize: 14
Image {
id: latexDescription
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
visible: LatexJS.enabled
property double depth: 2
property var ltxInfo: visible ? Latex.render(obj.getLatexString(), depth*parent.font.pixelSize+4, parent.color).split(",") : ["","0","0"]
source: visible ? ltxInfo[0] : ""
width: parseInt(ltxInfo[1])/depth
height: parseInt(ltxInfo[2])/depth
}
MouseArea {
anchors.fill: parent
onClicked: {
objEditor.obj = Objects.currentObjects[obj.type][index]
objEditor.objType = obj.type
objEditor.objIndex = index
//objEditor.editingRow = objectRow
objEditor.show()
}
}
}
Button {
id: pointerButton
width: parent.height - 10
height: width
anchors.right: deleteButton.left
anchors.rightMargin: 5
anchors.verticalCenter: parent.verticalCenter
Setting.Icon {
id: icon
width: 18
height: 18
anchors.centerIn: parent
color: sysPalette.windowText
source: '../icons/common/position.svg'
}
property bool hasXProp: obj.constructor.properties().hasOwnProperty('x')
property bool hasYProp: obj.constructor.properties().hasOwnProperty('y')
visible: hasXProp || hasYProp
ToolTip.visible: hovered
ToolTip.text: qsTr("Set %1 %2 position").arg(obj.constructor.displayType()).arg(obj.name)
onClicked: {
console.log(obj.type, obj.name)
posPicker.objType = obj.type
posPicker.objName = obj.name
posPicker.pickX = hasXProp
posPicker.pickY = hasYProp
posPicker.propertyX = 'x'
posPicker.propertyY = 'y'
posPicker.visible = true
}
}
Button {
id: deleteButton
width: parent.minHeight - 10
height: width
anchors.right: colorPickRect.left
anchors.rightMargin: 5
anchors.verticalCenter: parent.verticalCenter
icon.name: 'delete'
icon.source: '../icons/common/delete.svg'
icon.color: sysPalette.buttonText
ToolTip.visible: hovered
ToolTip.text: qsTr("Delete %1 %2").arg(obj.constructor.displayType()).arg(obj.name)
onClicked: {
history.addToHistory(new HistoryLib.DeleteObject(
obj.name, obj.type, obj.export()
))
Objects.deleteObject(obj.name)
changed()
}
}
Rectangle {
id: colorPickRect
anchors.right: parent.right
anchors.rightMargin: 5
anchors.verticalCenter: parent.verticalCenter
color: obj.color
width: parent.minHeight - 10
height: width
radius: Math.min(width, height)
border.width: 2
border.color: sysPalette.windowText
MouseArea {
anchors.fill: parent
onClicked: pickColor.open()
}
}
D.ColorDialog {
id: pickColor
color: obj.color
title: qsTr("Pick new color for %1 %2").arg(obj.constructor.displayType()).arg(obj.name)
onAccepted: {
history.addToHistory(new HistoryLib.ColorChanged(
obj.name, obj.type, obj.color, color.toString()
))
obj.color = color.toString()
changed()
}
}
}

View file

@ -2,5 +2,5 @@ module eu.ad5001.LogarithmPlotter.ObjectLists
ObjectLists 1.0 ObjectLists.qml
ObjectCreationGrid 1.0 ObjectCreationGrid.qml
ObjectRow 1.0 ObjectRow.qml
EditorDialog 1.0 EditorDialog.qml

View file

@ -48,8 +48,7 @@ Item {
width: parent.width
//smooth: true
visible: false
sourceSize.width: width*2
sourceSize.height: width*2
sourceSize.height: sourceSize.width
}
ColorOverlay {
anchors.fill: img

View file

@ -165,6 +165,7 @@ Item {
"ₜ","¹","²","³","⁴","⁵","⁶",
"⁷","⁸","⁹","⁰","₁","₂","₃",
"₄","₅","₆","₇","₈","₉","₀"
]
Repeater {
model: parent.insertChars.length

View file

@ -16,19 +16,6 @@ var IMEMBER = 'IMEMBER';
var IENDSTATEMENT = 'IENDSTATEMENT';
var IARRAY = 'IARRAY';
// Additional variable characters.
var ADDITIONAL_VARCHARS = [
"α","β","γ","δ","ε","ζ","η",
"π","θ","κ","λ","μ","ξ","ρ",
"ς","σ","τ","φ","χ","ψ","ω",
"Γ","Δ","Θ","Λ","Ξ","Π","Σ",
"Φ","Ψ","Ω","ₐ","ₑ","ₒ","ₓ",
"ₕ","ₖ","ₗ","ₘ","ₙ","ₚ","ₛ",
"ₜ","¹","²","³","⁴","⁵","⁶",
"⁷","⁸","⁹","⁰","₁","₂","₃",
"₄","₅","₆","₇","₈","₉","₀"
]
function Instruction(type, value) {
this.type = type;
this.value = (value !== undefined && value !== null) ? value : 0;
@ -720,7 +707,7 @@ TokenStream.prototype.isName = function () {
var hasLetter = false;
for (; i < this.expression.length; i++) {
var c = this.expression.charAt(i);
if (c.toUpperCase() === c.toLowerCase() && !ADDITIONAL_VARCHARS.includes(c)) {
if (c.toUpperCase() === c.toLowerCase()) {
if (i === this.pos && (c === '$' || c === '_')) {
if (c === '_') {
hasLetter = true;

View file

@ -116,7 +116,7 @@ class EditedProperty extends C.Action {
.arg(this.targetPropertyReadable)
.arg('<b style="font-size: 15px;">&nbsp;' + this.targetName + '&nbsp;</b>')
.arg('<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+this.prev+'&nbsp;</tt>')
.arg('<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+this.next+'&nbsp;</tt>')
.arg('<tt style="background: rgba(128,128,128,0.1);">&nbsp;'+this.next+'</tt>')
// .arg('<b style="font-size: 15px;">' + Objects.types[this.targetType].displayType())
}

View file

@ -200,10 +200,8 @@ class DrawableObject {
if(properties[property] == 'Expression' && this[property] != null) {
// Expressions with dependencies
for(let objName of this[property].requiredObjects()) {
if(objName in C.currentObjectsByName) {
this.requires.push(C.currentObjectsByName[objName])
C.currentObjectsByName[objName].requiredBy.push(this)
}
this.requires.push(C.currentObjectsByName[objName])
C.currentObjectsByName[objName].requiredBy.push(this)
}
if(this[property].cached && this[property].requiredObjects().length > 0)
// Recalculate

View file

@ -52,9 +52,11 @@ class GainBode extends Common.ExecutableObject {
om_0 = Objects.currentObjectsByName[om_0]
if(om_0 == null) {
// Create new point
om_0 = Objects.createNewRegisteredObject('Point', [Common.getNewName('ω'), true, this.color, 'name'])
om_0 = Objects.createNewRegisteredObject('Point')
om_0.name = Common.getNewName('ω')
om_0.labelContent = 'name'
om_0.color = this.color
HistoryLib.history.addToHistory(new HistoryLib.CreateNewObject(om_0.name, 'Point', om_0.export()))
om_0.update()
labelPosition = 'below'
}
om_0.requiredBy.push(this)

View file

@ -51,7 +51,10 @@ class PhaseBode extends Common.ExecutableObject {
om_0 = Objects.currentObjectsByName[om_0]
if(om_0 == null) {
// Create new point
om_0 = Objects.createNewRegisteredObject('Point', [Common.getNewName('ω'), this.color, 'name'])
om_0 = Objects.createNewRegisteredObject('Point')
om_0.name = Common.getNewName('ω')
om_0.color = this.color
om_0.labelContent = 'name'
om_0.labelPosition = this.phase.execute() >= 0 ? 'above' : 'below'
HistoryLib.history.addToHistory(new HistoryLib.CreateNewObject(om_0.name, 'Point', om_0.export()))
labelPosition = 'below'

View file

@ -81,9 +81,9 @@ class Latex(QObject):
return LATEX_PATH is not None and DVIPNG_PATH is not None
@Slot(str, float, QColor, result=str)
def render(self, latex_markup: str, font_size: float, color: QColor) -> str:
def render(self, latex_markup: str, font_size: float, color: QColor = True) -> str:
"""
Prepares and renders a latex string into a png file.
Renders a latex string into a png file.
"""
markup_hash = hash(latex_markup)
export_path = path.join(self.tempdir.name, f'{markup_hash}_{font_size}_{color.rgb()}')
@ -100,7 +100,7 @@ class Latex(QObject):
self.convert_dvi_to_png(latex_path, export_path, font_size, color)
except Exception as e: # One of the processes failed. A message will be sent every time.
raise e
img = QImage(export_path);
img = QImage(export_path + ".png");
# Small hack, not very optimized since we load the image twice, but you can't pass a QImage to QML and expect it to be loaded
return f'{export_path}.png,{img.width()},{img.height()}'
@ -171,7 +171,7 @@ class Latex(QObject):
for i in [".tex", ".aux", ".log"]:
remove(export_path + i)
"""
@Slot(str, float, QColor, result=str)
def render_legacy(self, latexstring, font_size, color = True):
exprpath = path.join(self.tempdir.name, f'{hash(latexstring)}_{font_size}_{color.rgb()}.png')
@ -190,4 +190,3 @@ class Latex(QObject):
img = QImage(exprpath);
# Small hack, not very optimized since we load the image twice, but you can't pass a QImage to QML and expect it to be loaded
return f'{exprpath},{img.width()},{img.height()}'
"""