List properties! Starting Sequences

This commit is contained in:
Adsooi 2020-12-26 00:59:57 +01:00
parent f0d795478f
commit 5af98c67b0
3 changed files with 168 additions and 98 deletions

View file

@ -1,24 +1,42 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQml.Models 2.12
ListView { Column {
id: control id: control
signal changed() signal changed()
property string label: ''
property bool dictionaryMode: false property bool dictionaryMode: false
property bool keyType: "string" property string keyType: "string"
property bool valueType: "string" property string valueType: "string"
property string preKeyLabel: "" property string preKeyLabel: ""
property string postKeyLabel: ": " property string postKeyLabel: ": "
property var keyRegexp: /^.+$/ property var keyRegexp: /^.+$/
property var valueRegexp: /^.+$/ property var valueRegexp: /^.+$/
property bool forbidAdding: false
property alias model: repeater.model
Text {
id: labelItem
height: 30
verticalAlignment: TextInput.AlignVCenter
color: sysPalette.windowText
text: control.label +": "
}
Repeater {
id: repeater
width: control.width
model: ListModel {} model: ListModel {}
delegate: Row { Row {
height: 30 id: defRow
width: control.width height: addEntryBtn.height
width: parent.width
Text { Text {
id: preKeyText id: preKeyText
@ -33,18 +51,18 @@ ListView {
visible: control.dictionaryMode visible: control.dictionaryMode
height: parent.height height: parent.height
width: visible ? 50 : 0 width: visible ? 50 : 0
validator: RegularExpressionValidator { validator: RegExpValidator {
regularExpression: control.keyRegexp regExp: control.keyRegexp
} }
verticalAlignment: TextInput.AlignVCenter verticalAlignment: TextInput.AlignVCenter
horizontalAlignment: TextInput.AlignHCenter horizontalAlignment: TextInput.AlignHCenter
color: sysPalette.windowText color: sysPalette.windowText
text: visible ? model.get(index).key : false text: visible ? control.model.get(index).key : false
selectByMouse: true selectByMouse: true
onEditingFinished: { onEditingFinished: {
var value = text var value = text
if(control.keyType == 'int') { if(control.keyType == 'int') {
value = parseFloat(value) value = parseInt(value)
if(value.toString()=="NaN") if(value.toString()=="NaN")
value = "" value = ""
} }
@ -53,8 +71,8 @@ ListView {
if(value.toString()=="NaN") if(value.toString()=="NaN")
value = "" value = ""
} }
if(value != "") { if(value != "" && valueInput.acceptableInput) {
model.setProperty(index, 'key', value) control.model.setProperty(index, 'key', value)
control.changed() control.changed()
} }
} }
@ -72,19 +90,19 @@ ListView {
TextField { TextField {
id: valueInput id: valueInput
height: parent.height height: parent.height
width: parent.width - preKeyText.width - keyInput.width - postKeyText.width width: parent.width - x
validator: RegularExpressionValidator { validator: RegExpValidator {
regularExpression: control.valueRegexp regExp: control.valueRegexp
} }
verticalAlignment: TextInput.AlignVCenter verticalAlignment: TextInput.AlignVCenter
horizontalAlignment: TextInput.AlignHCenter horizontalAlignment: TextInput.AlignHCenter
color: sysPalette.windowText color: sysPalette.windowText
text: visible ? model.get(index).key : false text: visible ? control.model.get(index).key : false
selectByMouse: true selectByMouse: true
onEditingFinished: { onEditingFinished: {
var value = text var value = text
if(control.valueType == 'int') { if(control.valueType == 'int') {
value = parseFloat(value) value = parseInt(value)
if(value.toString()=="NaN") if(value.toString()=="NaN")
value = "" value = ""
} }
@ -93,19 +111,20 @@ ListView {
if(value.toString()=="NaN") if(value.toString()=="NaN")
value = "" value = ""
} }
if(value != "") { if(value != "" && keyInput.acceptableInput) {
model.setProperty(index, 'value', value) control.model.setProperty(index, 'value', value)
control.changed() control.changed()
} }
} }
} }
} }
}
footer: Button { Button {
id: addEntryBtn id: addEntryBtn
visible: !control.forbidAdding
text: '+ Add Entry' text: '+ Add Entry'
width: control.width width: control.width
height: visible ? implicitHeight : 0
onClicked: { onClicked: {
control.model.append({ control.model.append({
@ -115,22 +134,25 @@ ListView {
} }
} }
function import(importer) { function importModel(importer) {
model.clear() model.clear()
if(dictionaryMode) { for(var key in importer)
for(var key in importer) model.append({ model.append({
key: key, key: key,
value: importer[value] value: importer[key]
}) })
} else {
for(var key in importer) model.append({
key: key,
value: importer[value]
})
}
} }
function export() { function exportModel() {
if(d if(dictionaryMode) {
var ret = {}
for(var i = 0; i < model.count; i++)
ret[model.get(i).key] = model.get(i).value
return ret
} else {
var ret = []
for(var i = 0; i < model.count; i++)
ret.push(model.get(i).value)
}
} }
} }

View file

@ -257,7 +257,7 @@ ListView {
id: dlgCustomProperties id: dlgCustomProperties
Item { Item {
height: 30 height: customPropListDict.visible ? customPropListDict.height : 30
width: dlgProperties.width width: dlgProperties.width
property string label: Utils.camelCase2readable(modelData[0]) property string label: Utils.camelCase2readable(modelData[0])
@ -266,7 +266,7 @@ ListView {
height: 30 height: 30
width: parent.width width: parent.width
visible: modelData[0].startsWith('comment') visible: modelData[0].startsWith('comment')
text: visible ? modelData[1] : '' text: visible ? modelData[1].replace('{name}', objEditor.obj.name) : ''
color: sysPalette.windowText color: sysPalette.windowText
} }
@ -341,6 +341,32 @@ ListView {
objectListList.update() objectListList.update()
} }
} }
ListSetting {
id: customPropListDict
width: parent.width
visible: typeof modelData[1] == 'object' && 'type' in modelData[1] && (modelData[1].type == 'List' || modelData[1].type == 'Dict')
label: parent.label
dictionaryMode: visible ? modelData[1].type == 'Dict' : false
keyType: dictionaryMode ? modelData[1].keyType : 'string'
valueType: visible ? modelData[1].type : 'string'
preKeyLabel: (dictionaryMode ? modelData[1].preKeyLabel : modelData[1].label).replace('{name}', objEditor.obj.name)
postKeyLabel: (dictionaryMode ? modelData[1].postKeyLabel : '').replace('{name}', objEditor.obj.name)
keyRegexp: dictionaryMode ? modelData[1].keyFormat : /^.+$/
valueRegexp: visible ? modelData[1].format : /^.+$/
forbidAdding: visible ? modelData[1].forbidAdding : false
onChanged: {
Objects.currentObjects[objEditor.objType][objEditor.objIndex][modelData[0]] = exportModel()
}
Component.onCompleted: {
console.log('Visible', visible, modelData[0], modelData[1])
console.log('Type', ('type' in modelData[1]), modelData[1].type)
if(visible) importModel(objEditor.obj[modelData[0]])
}
}
} }
} }
} }
@ -385,7 +411,7 @@ ListView {
function update() { function update() {
objectListList.changed() objectListList.changed()
for(var objType in objectListList.model) { for(var objType in objectListList.listViews) {
objectListList.listViews[objType].model = Objects.currentObjects[objType] objectListList.listViews[objType].model = Objects.currentObjects[objType]
} }
} }

View file

@ -36,22 +36,27 @@ function getNewName(allowedLetters) {
} }
class List { class List {
constructor(type, format=/^.+$/, label = '') { constructor(type, format = /^.+$/, label = '', forbidAdding = false) {
// type can be string, int and double. // type can be string, int and double.
this.type = type this.type = 'List'
this.valueType = type
this.format = format this.format = format
this.label = label this.label = label
this.forbidAdding = forbidAdding
} }
} }
class Dictionary { class Dictionary {
constructor(type, keyType = 'string', format = /^.+$/, keyFormat = /^.+$/, preKeyLabel = '', postKeyLabel = ': ') { constructor(type, keyType = 'string', format = /^.+$/, keyFormat = /^.+$/, preKeyLabel = '', postKeyLabel = ': ', forbidAdding = false) {
// type & keyType can be string, int and double. // type & keyType can be string, int and double.
this.type = type this.type = 'Dict'
this.valueType = type
this.keyType = keyType this.keyType = keyType
this.format = format this.format = format
this.keyFormat = keyFormat
this.preKeyLabel = preKeyLabel this.preKeyLabel = preKeyLabel
this.postKeyLabel = postKeyLabel this.postKeyLabel = postKeyLabel
this.forbidAdding = forbidAdding
} }
} }
@ -938,7 +943,23 @@ class CursorX extends DrawableObject {
} }
} }
class Sequence extends ExecutableObject {
static type(){return 'Sequence'}
static typeMultiple(){return 'Sequences'}
static properties() {return {
'defaultExpression': new Dictionary('string', 'int', /^.+$/, /^(\d+)$/, '{name}[n+', '] = ', true),
'comment1': 'NOTE: Use {name}[n] to refer to uₙ, u[n+1] for uₙ₊₁...',
'markedValues': new Dictionary('string', 'int', /^.+$/, /^(\d+)$/, '{name}[', '] = '),
}}
constructor(name = null, visible = true, color = null, labelContent = 'name + value',
defaultExp = {1: "u[n]"}, markedValues = {0: 0}) {
if(name == null) name = getNewName('uvwPSUVWabcde')
super(name, visible, color, labelContent)
this.defaultExpression = defaultExp
this.markedValues = markedValues
}
}
const types = { const types = {
'Point': Point, 'Point': Point,
@ -947,7 +968,8 @@ const types = {
'Somme gains Bode': SommeGainsBode, 'Somme gains Bode': SommeGainsBode,
'Phase Bode': PhaseBode, 'Phase Bode': PhaseBode,
'Somme phases Bode': SommePhasesBode, 'Somme phases Bode': SommePhasesBode,
'X Cursor': CursorX 'X Cursor': CursorX,
'Sequence': Sequence
} }
var currentObjects = {} var currentObjects = {}