Delaying the opening of a NSPopUpButton - nstableview

I've encountered the same problem as this one:
This one.
It has never been answered so far. In two words:
When you place a NSPopUpButtonCell in a NSTableView, the popUp opens before the selection in the tableView has changed.
If the menu of the popUp relies on the selection of a row of the tableView, it will be updated too late.
Solution 1: differ the opening of the popUp with a block which calls [super] a few nanoseconds later. But I don't know which method I must override.
Solution 2: use other bindings that I'm currently using (the popUp contains the NSSet of the entity selected in the table, I'm using a different controller, not the table's one, and I bind its content set to myTable.selection.theSet.
Is there something else I could do? Thanks !

Yes, if you use a view-based tableView, you can bind the popUp through the cellView it’s inside (like the other table objects you bind in this mode), and so it’s completely unambiguous and doesn’t depend on the selection.
In view-based mode, each cell in each row have is assigned an ‘objectValue’ from your original data, so you can bind directly to it, like ‘objectValue.popUpContents’.

Related

How to figure out the index of a ToggleGroup's selected toggle?

I'm trying to select an item from a list that's sorted the same way as a ToggleGroup I have besides it. However, I found that toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()) always returns -1 (visible in the IndexOutOfBoundsException thrown as I pass it). Is there another way of figuring out the index, or am I at a loss with my approach and need to figure out something completely different?
UPDATE: Apparently, for the first time an item is selected (I have this code attached to changes of selectedToggleProperty()), it works fine (I just get no notice of it because the elements I make visible have no proper layout). However, when an item is selected while another item already is selected, getselectedToggle() becomes null, causing aforementioned behavior.
All of the JavaFX toggle controls have a property called UserData. You should use that to create the links between the toggles and data list. Relying on the index of the toggles in the toggle group is probably a bad idea.

Data Binding issue while navigation & routing?

Today I faced a strange issue (could be a silly one) for data binding while navigating to 2nd view which is showing List of data coming from OData model and Panel at the bottom
I have replicate the code into this link - http://plnkr.co/edit/ClZqvo?p=info (You can run this as well through RUN on the Top) - Kindly run it in chrome with disabled security (Due to CORS issue)
Now the problem is when I am navigating to 2nd view (OData Table) and then Select any List Item, you will see in the bottom, the Panel will reflect the selected item (as I have used BindElement method to bind the path). After this I clicked back and then my 1st view will appear (JSON table) again I clicked on Next Button and then 2nd view will appear again. When I select the same item which I have selected previously then this time Panel will not show the selected items. This issue is coming only when I navigate back and forth and select the same item. Not able to understand what caused this?
But if I choose any other item then it will show me the selected item.
Anyone having any idea about this?
~Rahul
This is common issue when using bindElement, I have faced it too. It might be failing to resolve context of referenced entity. So, fields are not binded with respective values.
As a alternative you can use setBindingContext to bind fields within panel.
Since you are using named model, it should be specified as argument to setBindingContext.
So your code will be like
onSelect: function(oEvent) {
var oContext = oEvent.getSource().getBindingContext("odataModel");
var oProductDetailPanel = this.getView().byId("prodDetailsPanel");
oProductDetailPanel.setBindingContext(oContext, "odataModel");
}

Flex: accessing child through navigating the hiererachy

I have a generic function to build rows of controls (each row comprising of sliders, radio buttons, reset buttons, text display) etc, and some functionality to change underlying data based on these
As I didn't want to write specific code for each row, I had code written by which I can detect the row on which there has been a mouseevent, and though the row access each individual control
The hierarchy used is titleWindow (part of popup)->skinnable container->HGroup->control
When I trace for a radiobutton, I get the path as follows Electric_Modify.TitleWindowSkin2620._TitleWindowSkin_Group1.contents.contentGroup.0.RadioButton2645
The '0' before the radioButton stands for the first Hgroup id->named as 0
I tried accessing the radio button as follows- 5th element in the HGroup
((this.contentGroup.getChildAt(row)as Group).getChildAt(4) as RadioButton).enabled=false;
and get a message "Cannot access a property or method of a null object reference" on this line. How should I navigate the hierarchy to reach the element?
You should be using getElementAt(...) and not getChildAt(...).
The get element functions represent a "higher level" element hierarchy which is needed to make skinning easier.
((this.getElementAt(row) as IVisualElementContainer).getElementAt(4) as RadioButton).enabled = false;
It should look something like that, but the exact hierarchy depends on what's in your app.
#drkstr
Thanks for your input... I thought of an alternate approach that worked for me...I mapped out the parent of the HGroup via
parent1=hgrp.parent; and then referenced these buttons as follows
((parent1.getChildAt(row)as Group).getChildAt(4) as RadioButton)
This works like a dream...I presume your suggestion would let me jump across the intermediate layers
#J_A_X/ #Constantiner: Thanks for the suggestion. I have no idea why we didn't think through and go down the DataGroup path. Prima facie seems simpler... we got to creating the UI controls in MXML laying out controls serially,and when it came to making it generic, we literally replicated the MXML approach in AS. Started off easy, till it caused problems like above. We will fix this to a better approach, when we upgrade versions. It works for now

Show Editors for All Cells in Row in QTableView

I would like to display editors for all cells in a row when a user begins editing any cell in a QTableView. I have made several attempts but I cannot obtain the correct behaviour.
The only way to open multiple editors is by QAbstractItemView::openPersistentEditor() - attempts to successively call QAbstractItemView::edit() results in only one editor.
I cannot use signals such as clicked() and doubleClicked() from QAbstractItemView to invoke editing, because then it would not respect the edit triggers of the view.
There appears to be no "editing complete" signal. I would like to connect this signal to a slot that calls closePersistentEditor() for cells in the editing row.
Any suggestions would be appreciated.
Thanks!
I hate to be the bearer of bad news, but I can't think of any easy way to do what you want. I can think of a couple of options, each more painful than the last:
You could create a delegate that always shows the editors, and when the user changes the selected row, set that delegate for the newly selected row, and the original delegate for the deselected row.
You could try inheriting from the table view, and overriding the behavior for drawing the appropriate items for everything in the given row. I have no idea how hard this would be, but I doubt it would be trivial.
You could create your own view to display the model. I've never done this, and I'd hate to think about all that would be required to "complete" support the models. However, to match with one specific model, you might be able to get away with it.

How can I tell a QTableWidget to end editing a cell?

I'm showing a popup menu to select some values in a QTableWidget. The lowest item is a "Modify list" entry, when I select it a new window should automatically appear and the QComboBox should vanish and the cell return to a Qt::DisplayRole state.
Now Qt has all those nice API-calls like QTableWidget.edit() and QTableWidget.editItem(), what I'm really looking for is a QTableWidget.endEditing(), preferably without specifying the index of the cell, though I could get that using this call:
table.currentIndex()
… but I don't know if I can guarantee that the current cell is the cell being edited at all times.
Is there an API to close those kind of editors?
QTableWidget inherits 19 public slots from QWidget. One of those is setDisabled(), which should disable input events for that widget and all of its children.
I would try:
table.setDisabled( true );
table.setDisabled( false );
Although you said it does not work for you, there is an alternative method:
If you don't like that (the table loses focus, I believe), you can try using EditTriggers. For example:
table.setEditTriggers( QAbstractItemView::NoEditTriggers );
table.setCurrentItem(None) is what worked for me. (Don’t forget to block signals if you use some cellChanged/itemChanged slot function.)
This is with PyQt. For C++ I think replace None with NULL.
You may be able to use QTableWidget.closePersistentEditor() to close the editor. However, QAbstractItemView.closeEditor() may be closer to what you want, especially since you seem to be comfortable with the QModelIndex-based API and are already using a custom editor widget.
In my case, none of the options worked properly. So, I figured: I need to send the key press event to the line edit itself. The following works with QTreeView but probably does work with any other view or widget that opens a line edit to edit cells.
QWidget* editingWidget = treeView->findChild<QLineEdit*>();
if(editingWidget)
{
QKeyEvent keyPressEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
QApplication::sendEvent(editingWidget, &keyPressEvent);
QApplication::processEvents(); // see note below
}
In my case, I wanted to start editing another field directly when having finished editing one item. That is why I put processEvents there, in most cases you can probably remove that line.
PS: yeah, it's C++, but should be easily adaptable to Python. I found this thread when I searched for the C++ solution, so maybe it helps anyone else, too.
I can't speak for list widgets. But, I got here trying to do something similar.
I was double-clicking a cell, and based on the column, bringing up a sub-form with a list, then when that was closed move to the next appropriate column based on the value selected.
My problem was I could get the value in the cell and "select" the next appropriate cell, but the original cell stayed selected in edit mode!
It finally dawned on me that my double-click was selecting the cell, ie. editing.
A single-click selects the cell but doesn't open an edit mode.
Side note: Never could get that sub-form to act truly modal, so I created a loop in the calling form: while the sub form was visible, with the only code being app.processEvents()

Resources