Compare commits

...

2 commits

Author SHA1 Message Date
6abbbe5e61
Adding picker for properties (x,y,labelX)
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-24 03:51:42 +02:00
5cef8e23fa
Fixing several issues with repartition
+ Underscores being automatically removed from the name the moment it's edited.
+ Fixing issue with function name change.
2023-05-24 03:17:21 +02:00
6 changed files with 93 additions and 40 deletions

View file

@ -18,6 +18,7 @@
import QtQuick
import QtQuick.Controls
import Qt.labs.platform as Native
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
import "../../js/objects.js" as Objects
import "../../js/historylib.js" as HistoryLib
@ -43,6 +44,11 @@ Repeater {
Object whose properties to list and edit.
*/
property var obj
/*!
\qmlproperty var CustomPropertyList::positionPicker
Reference to the global PositionPicker QML object.
*/
property var positionPicker
readonly property var textTypes: ['Domain', 'string', 'number']
readonly property var comboBoxTypes: ['ObjectType', 'Enum']
@ -94,7 +100,7 @@ Repeater {
// Setting for text & number settings as well as domains
Setting.TextSetting {
height: 30
height: 30
label: propertyLabel
icon: `settings/custom/${propertyIcon}.svg`
isDouble: propertyType == 'number'
@ -123,15 +129,15 @@ Repeater {
}
// D.MessageDialog {
// id: parsingErrorDialog
// title: qsTranslate("expression", "LogarithmPlotter - Parsing error")
// text: ""
// function showDialog(propName, propValue, error) {
// text = qsTranslate("error", "Error while parsing expression for property %1:\n%2\n\nEvaluated expression: %3").arg(propName).arg(error).arg(propValue)
// open()
// }
// }
Native.MessageDialog {
id: parsingErrorDialog
title: qsTranslate("expression", "LogarithmPlotter - Parsing error")
text: ""
function showDialog(propName, propValue, error) {
text = qsTranslate("error", "Error while parsing expression for property %1:\n%2\n\nEvaluated expression: %3").arg(propName).arg(error).arg(propValue)
open()
}
}
}
}
@ -255,29 +261,68 @@ Repeater {
}
delegate: Component {
Loader {
//height: customPropComment.height + customPropText.height + customPropCheckBox.height + customPropCombo.height + customPropListDict.height
Row {
width: dlgProperties.width
property string propertyName: modelData[0]
property var propertyType: modelData[1]
property string propertyLabel: qsTranslate('prop',propertyName)
property string propertyIcon: Utils.camelCase2readable(propertyName)
spacing: 5
sourceComponent: {
if(propertyName.startsWith('comment'))
return commentComponent
else if(propertyType == 'boolean')
return checkboxComponent
else if(paramTypeIn(propertyType, ['Expression']))
return expressionEditorComponent
else if(paramTypeIn(propertyType, textTypes))
return textEditorComponent
else if(paramTypeIn(propertyType, comboBoxTypes))
return comboBoxComponent
else if(paramTypeIn(propertyType, listTypes))
return listDictEditorComponent
else
return {}
Loader {
id: propertyEditor
width: dlgProperties.width - pointerButton.width
property string propertyName: modelData[0]
property var propertyType: modelData[1]
property string propertyLabel: qsTranslate('prop',propertyName)
property string propertyIcon: Utils.camelCase2readable(propertyName)
sourceComponent: {
if(propertyName.startsWith('comment'))
return commentComponent
else if(propertyType == 'boolean')
return checkboxComponent
else if(paramTypeIn(propertyType, ['Expression']))
return expressionEditorComponent
else if(paramTypeIn(propertyType, textTypes))
return textEditorComponent
else if(paramTypeIn(propertyType, comboBoxTypes))
return comboBoxComponent
else if(paramTypeIn(propertyType, listTypes))
return listDictEditorComponent
else
return {}
}
}
Button {
id: pointerButton
height: parent.height
width: visible ? height : 0
anchors.verticalCenter: parent.verticalCenter
property bool isXProp: ['labelX', 'x'].includes(propertyEditor.propertyName)
property bool isYProp: ['y'].includes(propertyEditor.propertyName)
visible: isXProp || isYProp
ToolTip.visible: hovered
ToolTip.text: qsTr("Pick on graph")
Setting.Icon {
id: icon
width: 18
height: 18
anchors.centerIn: parent
color: sysPalette.windowText
source: '../icons/common/position.svg'
}
onClicked: {
positionPicker.objType = objType
positionPicker.objName = obj.name
positionPicker.pickX = isXProp
positionPicker.pickY = isYProp
positionPicker.propertyX = propertyEditor.propertyName
positionPicker.propertyY = propertyEditor.propertyName
positionPicker.visible = true
objEditor.close()
}
}
}
}

View file

@ -55,6 +55,11 @@ Popup.BaseDialog {
Instance of the object being edited.
*/
property var obj: Objects.currentObjects[objType][objIndex]
/*!
\qmlproperty var EditorDialog::posPicker
Reference to the global PositionPicker QML object.
*/
property var posPicker
title: "LogarithmPlotter"
width: 350
@ -143,6 +148,7 @@ Popup.BaseDialog {
CustomPropertyList {
id: dlgCustomProperties
obj: objEditor.obj
positionPicker: posPicker
onChanged: {
obj.update()

View file

@ -116,6 +116,8 @@ ScrollView {
// Object editor
Editor.Dialog {
id: objEditor
posPicker: positionPicker
}
/*!

View file

@ -119,7 +119,7 @@ Item {
focus: true
text: control.defValue
selectByMouse: true
onEditingFinished: {
onEditingFinished: function() {
if(insertButton.focus || insertPopup.focus) return
var value = text
if(control.isInt) value = Math.max(control.min,parseInt(value).toString()=="NaN"?control.min:parseInt(value))

View file

@ -96,14 +96,14 @@ class RepartitionFunction extends Common.ExecutableObject {
draw(canvas, ctx) {
var currentY = 0;
var keys = Object.keys(this.probabilities).map(idx => parseInt(idx)).sort((a,b) => a-b)
if(canvas.visible(keys[0],this.probabilities[keys[0]].replace(/,/g, '.'))) {
if(canvas.isVisible(keys[0],this.probabilities[keys[0]].replace(/,/g, '.'))) {
canvas.drawLine(ctx,
0,
canvas.y2px(0),
canvas.x2px(keys[0]),
canvas.y2px(0)
)
if(canvas.visible(keys[0],0)) {
if(canvas.isVisible(keys[0],0)) {
ctx.beginPath();
ctx.arc(canvas.x2px(keys[0])+4,canvas.y2px(0), 4, Math.PI / 2, 3 * Math.PI / 2);
ctx.stroke();
@ -112,26 +112,26 @@ class RepartitionFunction extends Common.ExecutableObject {
for(var i = 0; i < keys.length-1; i++) {
var idx = keys[i];
currentY += parseFloat(this.probabilities[idx].replace(/,/g, '.'));
if(canvas.visible(idx,currentY) || canvas.visible(keys[i+1],currentY)) {
if(canvas.isVisible(idx,currentY) || canvas.isVisible(keys[i+1],currentY)) {
canvas.drawLine(ctx,
Math.max(0,canvas.x2px(idx)),
canvas.y2px(currentY),
Math.min(canvas.canvasSize.width,canvas.x2px(keys[i+1])),
canvas.y2px(currentY)
)
if(canvas.visible(idx,currentY)) {
if(canvas.isVisible(idx,currentY)) {
ctx.beginPath();
ctx.arc(canvas.x2px(idx),canvas.y2px(currentY), 4, 0, 2 * Math.PI);
ctx.fill();
}
if(canvas.visible(keys[i+1],currentY)) {
if(canvas.isVisible(keys[i+1],currentY)) {
ctx.beginPath();
ctx.arc(canvas.x2px(keys[i+1])+4,canvas.y2px(currentY), 4, Math.PI / 2, 3 * Math.PI / 2);
ctx.stroke();
}
}
}
if(canvas.visible(keys[keys.length-1],currentY+parseFloat(this.probabilities[keys[keys.length-1]]))) {
if(canvas.isVisible(keys[keys.length-1],currentY+parseFloat(this.probabilities[keys[keys.length-1]]))) {
canvas.drawLine(ctx,
Math.max(0,canvas.x2px(keys[keys.length-1])),
canvas.y2px(currentY+parseFloat(this.probabilities[keys[keys.length-1]].replace(/,/g, '.'))),

View file

@ -316,8 +316,8 @@ function parseName(str, removeUnallowed = true) {
[/([^a-z]|^)gps(i)?([^a-z]|$)/g, '$1Ψ$3'],
[/([^a-z]|^)gom(ega)?([^a-z]|$)/g, '$1Ω$3'],
// Underscores
[/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
[/_([^" ]+)/g, function(match, p1) { return textsub(p1) }],
// [/_\(([^_]+)\)/g, function(match, p1) { return textsub(p1) }],
// [/_([^" ]+)/g, function(match, p1) { return textsub(p1) }],
// Array elements
[/\[([^\]\[]+)\]/g, function(match, p1) { return textsub(p1) }],
// Removing