QTableWidget and QGraphicsItem sync selection - pyside2

I have a QTableWidget with a list of QTableWidgetItems and also a matching number of QGraphicsItems in a different display.
I want their selection to be synchronised where if I select a table widget item, it selects the corresponding QgraphicsItem and vice versa. I already have this data and have it implemented, however it causes some kind of cycle because when
object A (QTableWidgetItem) is selected, it selects object B (QGraphicsItem), then that triggers the object A (QTableWidgetItem) to be selected again, which triggers object B (QGraphicsItem) and so on. How do you avoid this kind of loop, while still having the functionality ?
Thanks :)

Related

Bind each row of NSTableView to separate property of object?

I have a main NSArrayController bound to an NSTableView with each row containing an instance of MyObject. MyObject has about 30 properties, but the NSTableView only has 5 columns (to show the most important properties). When a row (or more) is selected I have another NSTableView (a detail view) which shows all the properties, one per row. The detail table has two columns, one for the property name and one for the property value.
I have this working right now but my detail NSTableView uses a data source rather than bindings. This works fine as long as I notify my detail controller (which manages the data source) of a change in the main selection so that it can reload the detail table.
While it is easy to detect a change in selection, it is harder to detect a change in one of the properties of a selected object. I see elsewhere on StackOverflow, that one way to do this is to have a dummy property and use keyPathsForValuesAffectingValueForKey. Does this work well performance-wise?
Is there some other/better way to build my detail NSTableView/NSArrayController so that each row represents one property of the selected objects on the main NSTableView/NSArrayController? I'd like to use bindings if possible.

Cocoa bindings issue with three tableviews

im a osx-dev noob that is trying to build an application with three table views that will show the content of a core data store entity. But each table view is filtered on the attribute "status" of the entity.
the problem occurs when i also want to show the selected entity in textfields. I'm using three different array controllers with different fetch predicates. But in a textfield i can only bind the value to one array controller.
should i ditch the bindings and do it all programaticly or is there a simple solution to this? :)
here is an screenshot so you can grasp my app description.
Keep bindings to populate the text fields if it satisfies what you want to do with this GUI. I'd add an NSObjectController to control the one entity those fields represent. If you want the user's changes to those fields persisted, bindings are still awesome.
But I think with three tables that might control what's displayed in the text fields, you're going to need to have some sort of non-binding glue code that determines which of the tables wins. You can probably do everything you want by implementing some of the NSTableViewDelegate protocol.
If the text fields should display the last entity that the user clicked in any of the tables, simply have each table call the same tableViewSelectionDidChange delegate function. All three tables could have the same delegate. You can then call setContent on the NSObjectController from that function.
You could also use similar glue code to prevent more than one selection in any of the three tables, by having the same delegate function deselect everything in the other tables either through the view or the controller. But that's up to you and needs consideration of whether you want multiple selection, etc.

Backbone.js Use View to Manipulate Another View

My question is mostly conceptual about Backbone.js, but I can mock up some code if my question is unclear.
Consider a case where I have 2 sections on a website. A list of items as one view and another view that has a dropdown to select how the list of items should be sorted. Obviously, the list of items is associated with a collection of models that stores the actual data that populates the list. But I'm unsure the best approach for triggering the collection to be sorted differently when the other view's dropdown changes. Should I be changing the actual order of the collection, or just render the view in the order that I want in the view?
Also, is it a good idea to use a model for the dropdown to keep track of the state of the dropdown, and bind the list of items view to that model so that I know when to rerender the list of items?
You could take several roads here. Here's a few:
Use a router. The router would hold your views, or at least the top-level view (cleaner), and your dropdown view would trigger a route change, which would pass the information along to the view. Best if you want clean URLs.
Make a pointer to the list view in the dropdown view. When the dropdown view receives the change event, it explicitly tells the list view to update. (IMO a terrible approach, but listed here for completeness.)
Back everything with models. (Like you suggest in your last question.) The dropdown view would be backed by a model, and the list view could bind to that model's events. (Again, the list view still has to know about the dropdown model—not ideal.)
Make an event manager. When your dropdown recevies a change, you trigger 'sort' and anything that cares can listen to that event. This isn't a trivial solution but isn't overly complex either. Your list view could then register its intent to listen to the sort event with the event manager, thereby abstracting the actual view inside the event manager and away from the dropdown view.
1 & 4 are effectively the same thing, just depending on whether you want a router or not.
Basically my heuristic with these sorts of scenarios is "nothing should know about things it doesn't need to know about." Applied here, that means that your views shouldn't know about each other.

Making a table's display dependent on the selection in another table in Interface Builder

I've got a window set up with two NSTableViews. In Core Data I have two entities set up, one of them containing members of the other, larger grouping (e.g. cars and manufacturers). I've got entry pages set up for each entity and they play nicely there (no faulting when trying to select from a many-to-one in a drop menu). What I'm trying to do now is take that one step further so that when I select a manufacturer in the main NSTableView, the list of cars related to that manufacuturer will appear in the second NSTableView.
I've tried using bindings similar to what I've done for the manufacturer popup button, feeding the value from the cars entity, however it's simply showing a list of all the car entries, regardless of which manufacturer I select. I don't see any options for a predicate to filter it, however, and if I set the binding's key path to manufacturer.cars, it shows a relationship fault. How can I filter what gets displayed in the child table?
Have two NSArrayControllers. Bind the contentArray of the cars controller to the manufacturers controller; the controller key is selection (i.e., the selected manufacturer), and the model key path is that of the property containing the manufacturer's cars.
Then, bind the cars table view's columns to properties of the cars controller's arrangedObjects.

Binding a table column containing NSPopUpButtons

I've got a table one column of which uses an NSPopUpButtonCell. Try as I might, I can't seem to figure out the way to properly bind everything the way I want it. Here's what I'm trying to do:
I have an NSArrayController plucking items from a managed object context, called 'Field Values'. This is to be used to populate the popup menu for each item (i.e. the list of available choices). I can bind this by selecting the cell in IB and binding its content/objects/values to 'Field Values'.arrangedObjects and 'Field Values'.arrangedObjects.name as appropriate (to get the represented object and the visible title).
I then want to bind the column in such a way that the selected value in each row comes from an array in my controller class, again made visible (and only edited through) another NSArrayController.
So far I've managed to set it up so that every popup menu contains the list of available fields, and that the default value is selected in each of them. Actually selecting an item has no effect, however— it just snaps back to its initial value. I've also managed to find some other variations on this, such as the menu being populated with the selected values, or containing the name of all available values, and the selection containing the -description of the 'none' value I added.
I'm sure I'm missing something fairly simple, but I'm not sure what it is. Presumably there's some subtlety I've missed in how to bind this sort of data (i.e. the Content vs. Content Object vs. Content Value things), but I'm damned if I can see it right now.
Many thanks in advance :o)
I've got a similar set up with a table view, although the data source isn't Core Data based, but I saw one thing you might double check that could be a subtle difference. In my setup for the table column, I have the table column itself bound via content, contentValues, and selectedObject. However, it looks like it's also possible to do the bindings on the actual NSPopUpButtonCell instead. Perhaps it works when the bindings are on the table column, but not when they're on the actual cell? Anyway, there's one thing that might be worth looking into.
Never bind to scroll view, table view or cell.
However, ever bind to table columns.
Watch the title of the Inspector window to be certain of what you're binding.

Resources