I have a custom tree model with many items. It has more than 1000000 items at the first level below the top level. When I expand this level in a QTreeView it calls model.hasChildren() for each of these items even though the items are not visible (you would need to scroll down, down, down... to make them visible). The trouble is that my function hasChildren() takes some time especially when called million times (takes about 10 secs - in PySide/PyQt). My questions are:
1) I understand that hasChildren() is called for visible items because it must know whether the item should be expandable (if it has children) or not. But why it is called for invisible items (I mean those which are not inside the visible range and become visible only after scrolling down)? In my view it should be called only when the item is about to become visible. Am I missing somethig?
2) How to work around this issue?
You likely need to override fetchMore/canFetchMore per pyqt docs. Basically when you expand the root, fetchMore() will be called, you will only return a subset of data items; when the user scrolls, the view will ask the root if it can fetch more; if it answers yes, fetchMore() will get called and your model can return more items. This should cause hasChildren() to be called only on the tree items fetched.
Related
I am wondering what would be a stable algorithm that can determine a length of a scrollable carousel.
For example i have a view with left andright button that can go through the whole collection of items.
The items can be repetitive and non-unique. For example :
A<->B<->C<-D->A<->B<->C<->H<->G ( G is connected to A with <->)
Using a bot that can inspect the state and click,
how many times i need to go through the whole list to determine that is the final one ?
thanks
I have configured a Source List as a sidebar on my app. Problem is when I run it all of the groups are collapsed. How do I fix this?
Yes, an outline view will start with its rows collapsed. (You can configure it to remember the last state, but that doesn't help for the first time and may not be what you want anyway. For example, if you change your program to add more groups.)
You need to add code to expand the rows you want expanded after the outline view has been populated. One place to do this would be in a window controller's -windowDidLoad method or an override of a view controller's -loadView method. Also, almost anywhere that you call -reloadData or -reloadItem:... with the root (nil) item.
If the only expandable rows in your source list are the groups — that is, there are only groups and one level of leaf nodes within the groups — then you can do [outlineView expandItem:nil expandChildren:YES] and that will expand all groups. Otherwise, you need to identify which specific items you want expanded and invoke -expandItem:... on each.
i search a lot but no single link found for Expandable listview in Blackberry, i know how to create Expandable list in android ,if someone having idea about Blackberry Expandable listview than please help me.
The standard way to create List on BB is to use the ListField class. This class is extremely efficient but has a couple of drawbacks
All the rows have to be the same height
All the rows have to contiguous on the display
This makes it difficult to use this class to replicate the Android ExpandingListView.
To replicate this look on a BlackBerry device, I suggest a series of VerticalFieldManagers (VFMs). Use one for the whole list, and add to this another for each expandable item. If the item is expanded, add child list entries to the associated VFM, when not expanded, delete the child entries.
This approach will work OK up to a point - adding and removing Fields can slow down the BB device significantly if there are significant number of Fields on display. So if you have, say 20 items in the list, then it will be fine. If you have 2000, it will slow the device down significantly when you expand and contract the list (add and remove the child list items).
You can improve this performance, by making your list items (parent and child) as efficient as possible. I recommend reviewing the code that is used for the ListStyleButtonField that you will find here: http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-managers/ta-p/488276
Update
Just wanted to clarify why ListField does not work directly, and a possible work around.
The problem with ListField is each row has a specific height. To display the child elements you really need to expand the height of the parent item to include the children, which you can't do. So you can't just update the called back paint method (called drawListRow(..) in a ListField) to achieve this look. And the other problem, is that one list item on a ListField is focused as a single entity where as I assume you would want to select the children individually.
Instead, when expanding you can add additional rows, effectively inserting the children items in the list to be drawn. You will have to add these rows with a flag, so that your drawListRow(..) method knows to paint these as children. Reverse on deletion. Note that the children items have to be the same height as everything else.
Having attempted both, I have found the VFM approach easier to manage. I would only consider the ListField approach where the list was large enough to impact performance. And when it is that large, who is going to scroll through that number of entries on their BB? If you are getting to that number, then a paging mechanism would seem more user friendly.
if you mean BlackBerry Java SDK, then take a look at TreeField class.
UPDATE:
In this case the ListField would be the most suitable choice. Implement ListFieldCallback according to your needs and attach it to the ListField instance. When user clicks on an "expandable" list item, then just process this event in ListFieldCallback and repaint your list instance. Here is the tutorial on working with ListField classes.
I am looking for a control many of us probably know, but I don't know it's name and don't have a real screenshot by hand, just this sketch:
In the left box one can select an operation or whatever, which then is moved to the right side. With the up/down arrows on the right, one can move this operation (or whatever kind of meaning the entry has) up or down in the order of execution.
How is this kind of control called? Or is it normally build by developers out of single controls? Is this control available in JavaFX 2? If not, I don't need exactly this control, but a control with the following features:
User can select multiple operations (duplicates allowed) out of all available operations
The user can arrange their order of execution
Thanks for any hint :-)
You need to use multiple controls to build up your interface. Use two ListViews with a MultipleSelectionModel for each (or at least the left one) and add a couple of buttons, that copy selected items from one list to the other and another couple of buttons which modify the position of selected items in the right list view by modifying the view's underlying item list.
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
This is sort of a best practice question, since I can think of a few ways that would work.
I want to implement an outline view. Let's suppose I want to implement the one in OmniFocus (my aim is very similar):
(I refer to the outline view in the main pane of that screenshot, not to the sidebar.)
So my data type is a task. Any task can have subtasks. Each task has one or zero parent tasks. Classic data model for displaying in an outline view, right?
BUT! I would like to offer the user the ability to group these tasks visually by a property of their choice. They could group them by milestone, or by assigned user, or by component… there'll be a bunch of these. And this grouping should appear in the outline view, at the top level of the hierarchy, just like the "Inbox", "Home" and "Work" items in this OmniFocus screenshot.
So it's fairly obvious that to display the grouping, I should use the built in NSOutlineView methods for drawing a group cell: the outlineView:isGroupItem: delegate method. The problem is, this setup is assuming that each item in the outline view is represented by an item in whatever data model I've connected it to: so both my tasks and my group headers have to be represented in the data model.
Therefore, just binding to the Core Data table that represents my tasks is a no-no. I could forego bindings all together and just go back to the old style data source methods, but then I lose a bunch of useful stuff. So is there a middle ground?
I could, for example, create another class TaskTemporaryGroup. I give that class an ivar NSSet that is subtasks, the same key path as could be used on a task to get its children. Then I can bind my set of TaskTemporaryGroup objects to a tree controller, and it'll arrange the whole tree regardless of the fact that the top level items are a different class to those lower down. I'd have to take care when implementing drag and drop, to make sure that the grouping rows can't be arbitrarily dragged about, but it might work.
The other point of contention is that I would like clicking on the table headers to sort the rows within each group, but not to sort the top level groups. I assume NSTreeController applies the sort descriptors to each level of the hierarchy? I could have my TaskTemporaryGroup class return the same thing (i.e. its desired sorting order, that I've calculated separately) for any of the key paths that I want to be able to sort the rest of the cells on, so that to the framework it would look like they stayed in the same order no matter what property they were sorted by. Is this a good way to go or is it a hack?
So, to summarize:
How do people suggest I implement this kind of hierarchy, where the top level is a special case and all subsequent levels are the same kind of object?
Is the way I described, with a class to represent the top level objects that happens to respond to the same key paths as the child objects, a good way to go?
Does anyone have any tips about how to make sorting work well in this scenario?
Or will trying to use bindings for this task cause me a world of hurt?
Thanks,
Amy