Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some more details on use of setindex! in ListModels #35

Closed
Ph0non opened this issue Feb 10, 2017 · 4 comments
Closed

some more details on use of setindex! in ListModels #35

Ph0non opened this issue Feb 10, 2017 · 4 comments

Comments

@Ph0non
Copy link

Ph0non commented Feb 10, 2017

With interest i read your explainations in https://github.com/barche/QML.jl#listmodel and to change data in a ListModel from QML itself. This is exactly what i need for a new feature for my own code.

For editing a TableView i use code from stackoverflow which works fine (see here). This returns (with no surprise) Null setter for role "2016", not changing value because it is only readable.

Like in your example I added setindex! to addrole

addrole(nuclidesModel, year, n -> round(n.values[i],2), setindex!)

(see here and here)

But obviously i miss something, because this results in a segfault

ErrorException("type Float64 has no field values")
@barche
Copy link
Collaborator

barche commented Feb 10, 2017

The problem here is that the standard setindex! will set the entire nuclide for a row. Here, it is a role for a year so I think you need something like this (untested):

addrole(nuclidesModel, year, n -> round(n.values[i],2), (n, newval, row) -> n[row].values[i] = newval)

n is the list of nuclides, row the row in the table (converted to 1-based) and newval is the value for the role, which is one of the years here and so I guess a Float64.

@Ph0non
Copy link
Author

Ph0non commented Feb 10, 2017

Seems to work. I will test later more to see if it fits all. Thanks for you quick response.

It would be a great example for further use of ListModels in ListView and TableView. At least i will make an example for your repo, if this would be fine for you.

@barche
Copy link
Collaborator

barche commented Feb 10, 2017

Sure, more examples are always welcome, feel free to also improve the readme if it lacks clarity.

@ufechner7
Copy link
Member

In 0.8 ListModel were removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants