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

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.

Related

Highlight NSTableView rows as if right-clicked

I'd like to make an NSTableView highlight its selected rows as if one was right-clicked.
When a selected row is right-clicked (and if the table view implements a menu), the view draws a rectangle at the perimeter of each block of selected rows. This is the default behaviour. See below:
I want the table to do that outside of the context of a right-click. FYI, this is to implement a custom dragging Destination Feedback Style to make clear that some action will be applied on the selected rows.
I can programmatically select rows, but not make them highlight in this way.
Still, Appkit must have some method for that since it does it upon right-click.
I could find a solution involving subclassing NSTableView or NSTableRowView, but there may be a simple solution.
Thanks.

Want to re-instantiate a component when navigating to same aux route

I have a list of items with Actions drop-down for each item in the left-section of page. I also have a right rail which displays a different component based on action type selected. I'm using aux-route to accomplish this.
One of the Action the user can take is "edit" where in a form is displayed to edit the metadata of the list item. While editing, user can click on + button next to some of the input field to add another input field dynamically.
Now my problem is, when the edit-form is open for a list item and I click edit on another item in the list, I wanted my edit-component to be re-instantiated.
Because the aux-route is same for all the list items for edit-action, edit-view is not instantiated once again. Is there a way to achieve it?
Right now fixed it with RouteReuseStrategy

Display one data tree in two different views

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.

Drop dialog on a list page not disappearing automatically

When I add a drop-dialog to a list page, the drop dialog drops down when I click on it, but does not disappear when I click somewhere else.
I am trying to add my own drop-dialog, but I can reproduce this issue with standard Dynamics AX objects. I guess I am just missing some property on an object, but I just cannot figure out which one.
If you want to reproduce my problem in order to solve it, do the following:
Create a new Form. (Form 1)
Change the FormTemplate property to ListPage (Click on Yes)
Add the query MainAccountListPage to the DataSources
Create an ActionPanTab.
Add a Drop-dialog button with the menu item MainAccountListPageBalanceParameters.
Save and open the new List page by right clicking and choosing open. (or open the menu item)
In my case, when I click on Parameters, the drop dialog drops down. When I then click outside the drop-dialog, it disappears as it should.
Create a new display menu item. Set the object to the new list page (Form 1)
Drag the Menu item to any menu. I added mine to General ledger (Common)
Restore, open new workspace. Click on the new menu item in the general ledger menu.
Click on “parameters” and click outside the drop dialog.
When I do this the drop dialog does not disappear again. You can see this same drop dialog working fine on the Main Accounts list page. I have tried changing properties on both menu items, on the menu, on the form etc. I have tried different drop dialogs and different list pages. It always works on the details page and when opened from the AOT.
Am I missing a property? Is the entire way I am adding the drop dialog wrong?
The answer to the above example is.. add the MainAccountDetailPart Form part to the list page's (Form1) Parts.
With my other example, EcoResProductPerCompanyListPage, I had to add the EcoResProductVariantsPerCompanyFactBox to Parts.
I have no idea why this is, but adding a part to a list page fixes the drop dialogs. For example, adding MainAccountDetailPart Form part to a new list page not only fixes the MainAccountListPageBalanceParameters in my example, but it also fixes any other drop dialog that previously did not want to close. Removing the part the breaks all the drop dialogs in the list page again.
Thanks, FH-Inway, for the suggestion, I would have never have found the answer without your method. The solution really surprised me!

Can I make QCompleter complete inline and show a popup

Qt 4.5 (PyQt 4.6.1)
I'm looking for a widget similar to a QComboBox that automatically filters its entries to the ones starting with the input in the text field. There are around 300 items in the combo box.
I've tried two approaches:
QLineEdit with QCompleter
Advantages
Filtering the items works.
Disadvantages
Doesn't show a popup if the text field is empty.
Doesn't do inline completion.
Allows to insert items not in the list.
Editable QComboBox with insertion set to no
Advantages
Nice popup
Completes inline in the text field.
Disadvantages
No filtering
Input is only possible in either the text field or the popup. Clicking on the popup doesn't select the best-matching item in the popup.
What I need
A popup to select the items.
Slow tippers should be able to start tipping the name of an item and the popup switches to the best matching one.
Preferably I should filter the items so that only partially-matching items are shown.
Concerning you first try with QLineEdit, you can set the completionMode to do it inline.
For your second try, you can add a QCompleter object to you QCombBox in order to filter your items as you want.The QCompleter member of the QComboBox is to offer an easy way to use QCompleter.
Anyway, if you are not satisfied with this method, you can manage a QCompleter object by yourself. This allows you to choose how item list is display (using any views) and to define items order in the list. See basic QCompleter details.

Resources