Display one data tree in two different views - qt

Hello everyone.
I have a tree of items as shown on image above (Items tree).
I need to display this tree in a way that is shown on an image (Views).
It has two views, Tree View and List view. Tree view should display the whole tree of items, and list view should display properties for a selected item in a tree view. (On an image it displays properties for a cat item)
The way it is implemented right now is displayed at "Current implementation" part of an image. TreeModel contains item tree, and when you click on an item in a TreeView, current item is sent to a ListModel to display it's properties.
The issue thagt i encounter here is that in both views items are editable. In a tree view you can edit item's names, and this change should appear in a list view as well. The same goes for opposite direction. Changing name of a Cat item should reflect on a treeView cat item.
Since it is two different models, the change is made only when you hover over another view.
What i currently did is for a changed item in one of views, i search for a item in a another view via QModelIndex::match() and then just update that part of a view via emit dataChanged(). I am not sure this a good way. So if maybe you can give me some ideas on how this can be done better.
Thank you.

You should have only one model. The QAbstractItemView::setRootIndex method is all you need: you can set the current item in the tree as the root for the table view. Alternatively, you could use a proxy viewmodel to adapt the data for display in a particular form.

Related

NSTableView (or NSOutlineView) column hiding through contextual menu : a "no code" solution

I searched SO for the best solution to this question, found several clues, while not fully satisfying IMO. So I post below my no-code solution.
The goal is to have, as in Finder or other native applications, a contextual menu on the header bar of a table or outline, allowing to select which columns are visibles.
In IB storyboard, add all the columns you need into the table view.
You may set some of them hidden by default.
Ctrl-drag each column from the IB document outline view to the scene controller code view, in order to automatically create weak IBOutlets for each column. The purpose is to be able to target a given column in bindings.
__weak IBOutlet NSTableColumn *my_column;
Add a menu to the storyboard scene with the same number of item as the columns you plan to hide. You do not have to give title to menu items (see next point).
For each menu item, in the bindings pane, add two bindings :
Bind the item title to the column title property through your controller outlet : controller_name.my_column.title. This way the menu item will stay in sync with column title, should the code need to change it.
THIS ONE IS KEY : Bind the value of the menu item to the column hidden property : controller_name.my_column.hidden. Add a NSNegateBoolean transformer for the menu tick to be meaningful.
Attach the menu to header menu : ctrl-click on the table header view and make connection from the menu outlet to the menu created in #3.
That it's. No code beside the IBOutlets added in #2.
The bindings being two ways, un-ticking a menu item will hide the bound column. Also, if the code hides a column the bound menu item will reflect its state.

how to assign properties/explorer view to tree in Javafx?

I have a fall tree with output shown in picture below.In BorderPane "Center" a SplitPane is used to split the view. I want to assign the properties/explorer view to the tree branches & leafs, so that each branch and leaf should have its own properties/explorer view.
My question is this how can i assign this particular split's right side view shown in picture to branch "module" only, and what would be changes if user want this view to be assigned to any leaf. if user click on other branches or leaf this view/properties should not appear. if you need i can provide my sample code,its simple editable tree-view.
i tried but failed. Please
thank you

QT QtreeView show image when tree is expanded and collapsed

I have a requirement in the TreeView where I have to show down arrow image when tree is collapsed and up arrow image when tree is expanded and this is applicable for each parent item in the tree.
My UI will have only 1 column and this arrow images i have to show at the end of the row.
I am using QTreeView and I can see expand and collapse signals.But it does have only index arguement.But I need item rectanlge details to show the image at the end of the row.Could you pls suggest is there any way to achieve this?
Thanks,
The simplest way would be to use QTreeView::setIndexWidget (inherited from QAbstractItemView). With this method, you can set your own widget to render the nodes.
If you have more sophisticated requirements, you need to implement a custom delegate. Please have a look at the QAbstractItemDelegate Class Reference and Designing Delegates. By the use of delegates, you have complete rendering control over your items.

How to use Qt's Model-View programming

I'm trying to display some cards into a QListView but I'm really having trouble understanding how to use Qt's model/view pattern, and I can't find any simple examples.
Basically, I have two classes:
Card - my "model" which contains the name of the card, id, etc.
CardWidget - can load and render a Card object (display the card name and other info)
So how can I use Card and CardWidget to display a list of cards into a ListView? Do I need to change something to my classes, or should QListView be able to display them directly?
If someone could show me the basic steps or point me in the right direction that would be perfect.
See the documentation of QAbstractItemDelegate, which has an example of rendering items in a QTableView.
Its not obvious what you are trying to do here - in a list view, you can render a view of an item which is not the same as having a widget in every cell.
An item delegate can provide a widget as an editor and also how to render a cell's contents.
If you actually want fixed widgets in the view, you could use QListView::openPersistentEditor on all the cells you want a fixed widget for. The item delegate should outline how to create an editor for the cell in question.

Advanced DataGrid Flex 3 - ItemRenderer and Tree display

I am using Advanced DataGrid of Flex 3 with hierarchical data. The itemRenderer is a TextInput which accepts numbers. When I enter data into the given field and click the corresponding expand tree icon for the row, I want the amount entered in tree node should get cascaded to its child rows. But I found the nature of advanced DataGrid erroneous.
When I enter data and click on tree icon, the data is not populated in child windows unless i wont take the focus out from the editing control.
I tried using itemEditEnd, itemFocusOut etc but of no use. I have to explicitly click on any of the other columns and then expand tree.
Am I making any mistake anywhere?
I found solution to my problem, its bit ugly but it works. I had to register two events for textinput as follows
addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, allocateAmount);
addEventListener(FocusEvent.KEY_FOCUS_CHANGE, allocateAmount);
and then by using IViewCursor I could able to update data.

Resources