-
Task
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.16, 6.5.3
Property categories of BarCategoryAxis is a QStringList which is a list of string on QML side. But it does recognize JavaScript array APIs that can delete elements, e.g. splice() and shift(). The only exception I found is pop() and splice() that only deletes the last element. Nevertheless, normal QML list accepts all the JavaScript APIs.
A reproducer with 5 cases I've tested:
ChartView {
anchors.fill: parent
BarCategoryAxis {
id: categoryAxis
categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
property var myCategories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
}
BarSeries {
axisX: categoryAxis
BarSet {
values: [1, 2, 3, 4, 5, 6]
}
}
}
Button {
text: "Click me"
onClicked: {
// Case 1: splice(5,1), i.e.delete the last element, works
// categoryAxis.categories.splice(5,1)
// Case 2: pop() works
// categoryAxis.categories.pop()
// Case 3: splice(x,1) for any x except 5 does not work properly, that the behavior is expected but with error
// categoryAxis.categories.splice(1,1)
// case 4: shift() does not work, that somehow multiple elements get deleted and with error
// categoryAxis.categories.shift()
// Case 5: splice() and shift() work for "normal" list that I declared as proeprty, and categories accepts being reassigned as a whole
// categoryAxis.myCategories.shift()
// categoryAxis.myCategories.splice(0, 1)
// categoryAxis.myCategories.push("Jul")
// categoryAxis.myCategories.push("Aug")
// categoryAxis.categories = categoryAxis.myCategories
}
}