I want to be able to drag an item (actually a whole row) from a QTableView that has a QSqlTableModel as it's model.
QSqlTableModel::flags(const QModelIndex &index) doesn't return Qt::ItemIsDragEnabled. Does that mean the only way I can get this to work is if I subclass QSqlTableModel and reimplement the flags() method?
Thats seems like overkill just to drag the item.
Yes. It is the only way to get it to work.
Related
I have an array that I use to populate my pickerView, a simple string array. The issue is that I need the first item to be something like "Choose team".
The only way I have achieved that is the add the first item in the array to be "Choose team", but this messes up the array structure for me and I wonder if there is another way of doing this.
So, can I add a default value to a UIPickerValue, if no: how would you have solved this issue?
There is no easy way to add a default value. You can duplicate the array and add the string to the duplicated version for display but then you have to be careful about indexing issues. If the array's value changes programmatically, it can be a disaster. This duplication thing is not a good design anyway.
Alternatively, you can add a fixed label on right side of each picker values. Here is the example
Fixed labels in the selection bar of a UIPickerView
I have downloaded familyTree project and it doesn't have the ability to search for an specific family member!
I have added a search button to it, and in the handler method section, I need the code that searches for a member that has the specified socialID , and select it (scroll it to the sight, and make it blue (selected)). But I don't know how to programmatically select a treeItem, and make it visible and selected?
My code:
#FXML
private void btnSearch_click(ActionEvent event){
for(TreeItem<FamilyMember> treeItem:root.getChildren()){
if(treeItem.getValue().getNationality().toString()=="22"){
// treeView.setSelectionModel(item);
treeView.getSelectionModel().select(treeItem);
//it still doesnt select the item with nationality=="22"
break;
}
}
}
You can select the item with
treeView.getSelectionModel().select(item);
and if you still need to scroll (I think selecting it might automatically scroll to it), do
treeView.scrollTo(treeView.getRow(item));
A couple of notes:
I do not understand the for loop. Why are you doing
TreeItem<FamilyMember> item = root.getChildren().get(i);
and why are you creating the index i? What is wrong with the treeItem variable you already defined in the loop syntax? Isn't this necessarily exactly the same thing as item?
You need to read How do I compare strings in Java?
I am using GWT 2.4's new DataGrid in a project. I configured the DataGrid with a pagesize of 50.
The available screen is not big enough to display all items and thus a vertical scrollbar is shown (this is actually the main purpose for using a DataGrid in the first place).
I attached a SingleSelectionModel to the DataGrid in order to be able to select items.
This works fine so far.
However I also have another widget with which the user can interact. Based on that user action a item from the DataGrid should be selected.
Sometimes the selected item is not in the visible screen region and the user has to scroll down in the DataGrid to see it.
Is there any way to automatically or manually scroll down, so that the selected item is visible?
I checked the JavaDocs of the DataGrid and found no appropriate method or function for doing that.
Don't know if this works, but you could try to get the row element for the selection and use the scrollIntoView Method.
Example Code:
dataGrid.getRowElement(INDEX_OF_SELECTED_ITEM).scrollIntoView();
The answer above works pretty well, though if the grid is wider than your window and has a horizontal scroll bar, it also scrolls all the way to the right which is pretty annoying. I was able to get it to scroll down and stay scrolled left by getting the first cell in the selected row and then having it scroll that into view.
dataGrid.getRowElement(dataGrid.getVisibleItems().indexOf(object)).getCells().getItem(0).scrollIntoView();
Don't have time to try it out, but DataGrid implements the interface HasRows, and HasRows has, among other things, a method called setVisibleRange. You just need to figure out the row number of the item that you want to focus on, and then set the visible range from that number n to n+50. That way the DataGrid will reset to put that item at the top (or near the top if it is in the last 50 elements of the list backing the DataGrid). Don't forget to redraw your DataGrid.
Have you already looked at this? If so, I'd be surprised that it didn't work.
Oh, and since this is one widget talking to another, you probably have some messaging set up and some message handlers so that when the user interacts with that second widget and "selects" the item, the message fires on the EventBus and a handler for that message fixes up the DataGrid along the lines I've described. I think you'll have to do this wiring yourself.
My solution, a little better:
dataGrid.getRow(model).scrollIntoView();
I got a Out of bounds exception doing the above.
I solved it getting the ScrollPanel in the DataGrid and used .scrollToTop() and so on on the ScrollPanel. However, to access the ScrollPanel in the DataGrid I had to use this comment:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6865
As Kem pointed out, it's annoying the "scrollToRight" effect after the scrollIntoView. After me, Kem's solution gives a better behaviour than the base one as usually the first columns in a table are the more meaningful.
I improved a bit his approach, which scrolls horizontally to the first column of the row we want to be visible, by calculating the first visible column on the left before applying the scroll and then scrolling to it.
A final note: Columns absolute left is tested against "51". This is a value I found "experimentally" by looking the JS values in the browser's developer tool, I think it depends on the table's style, you may need to change/calculate it.
Below the code:
public void scrollIntoView(T next) {
int index = datagrid.getVisibleItems().indexOf(next);
NodeList<TableCellElement> cells = datagrid.getRowElement(index).getCells();
int firstVisibleIndex = -1;
for(int i=0; i<cells.getLength() && firstVisibleIndex<0;i++)
if(UIObject.isVisible(cells.getItem(i)) && (cells.getItem(i).getAbsoluteLeft() > 51) && (cells.getItem(i).getAbsoluteTop() > 0))
firstVisibleIndex = i;
cells.getItem(firstVisibleIndex>=0? firstVisibleIndex : 0).scrollIntoView();
}
Sorry for such a confusing title but it's hard to explain in a few words what I'm trying to accomplish. I'll try to explain the best I can. Ok, I'm parsing data from a xml file. It's constructed like so:
<item1>
<subitem1>text</subitem1>
<subitem2>text</subitem2>
<subitem3>text</subitem3>
<subitem4>text</subitem4>
<subitem5>text</subitem5>
</item1>
<item2>
<subitem1>text</subitem1>
<subitem2>text</subitem2>
<subitem3>text</subitem3>
<subitem4>text</subitem4>
<subitem5>text</subitem5>
</item2>
<item3>
<subitem1>text</subitem1>
<subitem2>text</subitem2>
<subitem3>text</subitem3>
<subitem4>text</subitem4>
<subitem5>text</subitem5>
</item3>
so on and so on...
So basically I want to display each item into a separate row in a UITableView and put each subitem into it's parent's row/cell as a label to display the info about it's parent "item".
Also, I need to be able to sort each item by one of it's subitems i.e. let's say subitem4. If subitem4 is equal to some string then it would display that item into the UITableView however if subitem4 isn't equal to that string I compare it to then that item wouldn't get displayed in the UITableView. As of right now I really don't have any working code because I'm not sure how to go about making this work. I don't know how I would do this because I have 1 array right now with all of the subitems together and I'm just separating each subitem and putting them into separate arrays so I can distinguish between each item row, I'm do it with the following code:
int totalNames = [Names count];
id name = [Names objectAtIndex:1];
[listOfItems addObject:name];
I'm pretty sure I'm going about this the wrong way. There must be a better way to do this logically. Any help or advice would be much appreciated. I'm mentally exhausted with this. Thanks.
Use classes.
Make each Item an instance of a class. make each subitem a property of the class. then have one array of the objects. then can sort based on a particular property or whatever.
This is a followup to this question:
UINavigationController + UITableView + UISearchBar + UISplitViewController
Is there any way to make it so the solution above doesn't make it unfilter the results? In my case you see the entire list pop back up (during the animation) when you deactivate the search in viewWillDisappear, and if you do it in viewDidDisappear then it seems to be too late and the next view is once again below/ontop of the bar. Any other solution?
OK, I've got your answer-
Here are the steps that worked for me [containing some pseudocode]:
1) Since you are searching you are most certainly already overriding ShouldReloadForSearch- So just add piece of code that saves/stores the forSeachString.
2) This one may vary quite a bit depending on your app- but the gist for this step is that you need to clear out the stored search string [set to null] if no search results are loaded. I did this in my UITableViewSource. I have 2 constructors- one for the full dataset and another on for the filtered [search results] dataset. So I just set it to null in my full dataset constructor. Yeah, you could do it differently no doubt but that's how I did it.
3) Next, do as the original "answer" states and call SetActive - [self.searchDisplayController setActive:NO];. They advocated doing it in override of ViewDidAppear. I didn't do that... I did this immediately after I pushed the next UIViewController in my RowSelected override.
4) Last, within your UIViewController that has the UISearchDisplayController attached- check for your saved search string and if it exists then do the following: 1) call SetActive again BUT this time with a true parameter ie setActive:YES... then 2) set the searchBar text to your saved search string value. I did this in the ViewWillAppear override.
Long story short... this worked for me AND it maintains the search results. Setting the searchBar text in step 4 is the key... this effectively gets the filter to persist.
Hope this helps someone
I ended up fixing this by changing where the search bar showed up (instead of going over the navigation bar, its tied to the table like in the email inbox). This fixed the issue and made it look more like the Apple apps.