LightsModel.qml 734 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import QtQml.Models 2.1
  2. ListModel {
  3. id: root
  4. readonly property var httpClient: HttpClient {
  5. id: httpClient
  6. onError: {
  7. root.error(text)
  8. root.isLoading = false
  9. }
  10. onReply: {
  11. root.populateModel(data)
  12. root.isLoading = false
  13. }
  14. }
  15. property string serviceUrl: undefined
  16. property bool isLoading: false
  17. signal error(string text)
  18. onServiceUrlChanged: reload()
  19. function reload() {
  20. root.httpClient.get(root.serviceUrl + '/static/channels.js')
  21. root.isLoading = true
  22. }
  23. function populateModel(data) {
  24. data.groups.forEach(function (group) {
  25. root.append(group)
  26. })
  27. }
  28. }