Thread: [Java-gnome-developer] Updating sorted TreeModel
Brought to you by:
afcowie
From: Przemyslaw W. <pw...@o2...> - 2008-12-10 15:03:54
|
Hi all, I'm having troubles updating TreeModel, which is sorted: whenever I update a value in the column by which the model (view?) is sorted, the re-ordering happens and I have no guarantee that all the rows will be iterated over. Moreover, some rows may be iterated more than once. I found a message from Andrew on java-gnome-hackers, which points the same bug (http://article.gmane.org/gmane.comp.gnome.bindings.java.devel/1062): ===== I'll wait to so see what Srichand thinks of this, but I really don't think we should put this stuff on TreeIter. We moved one method only to TreeIter and that was just to make cycling over a model work.* The three methods you are proposing to add above are specialities of TreeStore and really do belong there (actually, they are part of the TreeModel interface, so the open question is whether you ever need the hierarchy methods on a model that is not a TreeStore), and not on TreeIter. [* and even that's sketchy: I am hitting a bug this week where a TreeModel is failing to update because I am making changes to something which affects the sort order while looping over a model's data. I should know better] ===== Any hints on how to achieve this? I'm using java-gnome 4.0.9 on Debian Lenny. Przemek |
From: Andrew C. <an...@op...> - 2008-12-11 09:15:30
|
On Wed, 2008-12-10 at 16:03 +0100, Przemyslaw Wesolek wrote: > I'm having troubles updating TreeModel, which is sorted: whenever I > update a value in the column by which the model (view?) is sorted, the > re-ordering happens and I have no guarantee that all the rows will be > iterated over. Moreover, some rows may be iterated more than once. So this might fall into the category of "putting the wrong TreeModel in the TreeView"? If you're using a TreeModelSort to wrap a ListStore, you put the TreeModelSort into the TreeView. Iterating over the underlying ListStore should, however, remain fine; changes to the sort discriminator won't affect your ability to finish looping over the model. [at least, I've had no problem with it; I did have a case once where the data displayed in the TreeView would wobble a bit as I was updating all the rows because the sorting values were not unique, and so it sometimes flip-flopped a bit when confronted with equal values] Anyway, if you're still stuck you'll need to show us your code (more to the point, to boil your problem down to code that someone can comprehend, or better yet, if it's really a bug, write a TestCase that can go into the test suite). AfC Sydney [If you can't publish your code, then there are other ways of approaching the issue which we can deal with privately] -- Andrew Frederick Cowie Operational Dynamics is an operations and engineering consultancy focusing on IT strategy, organizational architecture, systems review, and effective procedures for change management: enabling successful deployment of mission critical information technology in enterprises, worldwide. http://www.operationaldynamics.com/ Sydney New York Toronto London |
From: Przemyslaw W. <pw...@o2...> - 2008-12-11 10:53:54
|
Andrew Cowie wrote: > On Wed, 2008-12-10 at 16:03 +0100, Przemyslaw Wesolek wrote: >> I'm having troubles updating TreeModel, which is sorted: whenever I >> update a value in the column by which the model (view?) is sorted, the >> re-ordering happens and I have no guarantee that all the rows will be >> iterated over. Moreover, some rows may be iterated more than once. > > So this might fall into the category of "putting the wrong TreeModel in > the TreeView"? > > If you're using a TreeModelSort to wrap a ListStore, you put the > TreeModelSort into the TreeView. That's right, works smoothly. To summarize: 1) Create your model 2) Create TreeModelSort wrapping your model 3) Connect wrapping model to the view 4) Propagate your model changes on the underlying model > [at least, I've had no problem with it; I did have a case once where the > data displayed in the TreeView would wobble a bit as I was updating all > the rows because the sorting values were not unique, and so it sometimes > flip-flopped a bit when confronted with equal values] This is not a big problem for me; my first idea was to synchronize on Gdk.lock before changing the model, maybe this would help (if TreeView is updated in main loop)? > Anyway, if you're still stuck you'll need to show us your code (more to > the point, to boil your problem down to code that someone can > comprehend, or better yet, if it's really a bug, write a TestCase that > can go into the test suite). For sure it is the case you described. Hm, hard to say if it is a bug or not... For me, it is API and reality incompatibility (i.e. iterating over the model misses some rows). Thanks a lot, Przemek |
From: Andrew C. <an...@op...> - 2008-12-11 13:44:51
|
I'm sorry, > That's right, works smoothly. and > Hm, hard to say if it is a bug or not don't go together. What's the problem? AfC Sydney |
From: Przemyslaw W. <pw...@o2...> - 2008-12-11 22:36:03
|
Andrew Cowie wrote: > I'm sorry, > >> That's right, works smoothly. > > and > >> Hm, hard to say if it is a bug or not > > don't go together. > > What's the problem? What I meant is that your solution (wrapping models) works smoothly, but it's not a straight-forward idea -- at least for me. For me the main problem -- call it a bug or a feature request :) -- was the unexpected behavior of iteration process when changing the model, not mentioned in java-gnome or GTK+ API. So if documentation comprehensiveness is considered, it would be nice to mention such iteration breakage possibility around TreeIter. Przemek |
From: Andrew C. <an...@op...> - 2008-12-17 02:18:05
|
On Thu, 2008-12-11 at 23:35 +0100, Przemyslaw Wesolek wrote: > What I meant is that your solution (wrapping models) works smoothly, but > it's not a straight-forward idea -- at least for me. Well, that's what GTK provides as it's mechanism for doing these things, so there's not a whole lot we can do about changing that. I personally find the whole TreeModelSort thing a bit cumbersome, but that's what we have to work with. > unexpected behavior of iteration process when changing the model, That, on the other hand, is something we can attempt to address. If you can suggest what to say in the documentation instead of what is there now, then we can certainly change it to prevent people like you having such misconceptions in the future. See HACKING for how to submit a patch with your proposed improvements. Cheers! AfC Sydney |