Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120027

BarCategoryAxis does not allow to delete most of elements in categories

    XMLWordPrintable

Details

    Description

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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            luqiaochen Luqiao Chen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes