oKcerG / SortFilterProxyModel

A nicely exposed QSortFilterProxyModel for QML
MIT License
298 stars 101 forks source link

Updated proxy roles not visible to delegate model #83

Open wingsandsuch opened 3 years ago

wingsandsuch commented 3 years ago

I have the following SortFilterProxyModel with an ExpressionRole that has a name that changes based on some property binding. When I select option 'a' or 'b' I expect that I could use the respective role name, but it seems to not trigger the expression function (no log message) and I get undefined as a return value. Does the SortFilterProxyModel not support the behavior that I want or is QML not recognizing that there is a new role present?


ComboBox{
  id: nameComboBox
  model: ['a','b']
  currentIndex: 0
}

SortFilterProxyModel{
  id: minimumTestModel
  sourceModel: ListModel{
    ListElement{
      unUsed: "you can ignore this"
    }
  }

  proxyRoles: [
    ExpressionRole{
      // dynamic name, should work when 'b' is selected in ComboBox but doesnt
      name: nameComboBox.currentValue
      expression: {
        console.log('trigger')
        return 1
      }
    },
    ExpressionRole{
      // constant name - present in the combobox, works
      name: 'a'
      expression: {
        console.log('trigger')
        return 2
      }
    }
  ]
}
Repeater{
  model: minimumTestModel
  delegate: Text{
    text: model[nameComboBox.currentValue]
  }
}
oKcerG commented 3 years ago

SortFilterProxyModel should support that, maybe Repeater doesn't? I'll investigate