acquiring tablecell row index - javafx

A simplified view of the problem I'm having....
A TableView TV contains two TableColumns (Name, Value).
A data structure Class obj_data contains two data items, SimpleStringProperty location, and double X. Multiple obj_data objects are stored in an observalable list and used with the TableView TV as it's data source
In the rendering of TableColumn Name, I need to get and the interrogate the value the corresponding X in order to change some visual attribute of the location tableCell..
I've played around with...
nameColumn.setCellValueFactory(new Callback, ObservableValue>()...
to return the value of obj_data element but am having difficulty trying to get the index of the table cell so I can correctly render the "location" field.. Hope this makes sense!
PS: This was so much more simple pre-javaFX with cellrenderers since I could get the row & col locations in the callback arguments!
Thanks in advance!

Related

How to implement a JavaFX table with multiple TableViews and Cell Factories?

I have a table whose list of visible items are filtered by radio buttons at the top of the table. So let's say the radio buttons are A, B, C - if A if chosen the table will only show items of type A, if B is chosen it will show only type B, etc.
I create a separate TableView instance for each selection because the users will be interacting with these filtered values in the table and editing values etc. I have a custom cell factory for each column in my table as well because rows need to be highlighted/frozen according to user input.
So:
for (all values A.. C) {
createNewTableView();
}
private void createNewTableView() {
TableView tableView = new TableView();
...
MyCustomCellFactory customCF = new MyCustomCellFactory();
customCF.setTableView(tableView);
clmn1.setCellFactory(customCF);
...
}
My problem is that when my custom cell factory fires, even through I specifically tell it which instance of table view it belongs to, the table view instance is not the correct one. It's always just the last one I created. I've verified this by checking the instance id's.
So the question is how can I have multiple table view instances with custom cell factories and ensure that I'm always acting on the right one in my custom cell factory code?
Thanks!
The problem actually had to do with not properly instantiating the table columns for each instance of TableView. I posted a simpler example here - JavaFX tabbed pane with a table view on each tab? - and got the answer I needed.

QT: QTableView read cell content

I'm writing a small program with QT creator (QT 5.2.1) under Windows 7 (32 bit) and I'm having problems reading the informations stored in a TableView. My application has 3 elements, a TableView to store text data, a TextBrowser to show info and a buttom.
I modified the TableView properties: when the user selects with the mouse a cell, the full row is selected and multiple row selection is not allowed.
The user select a row and when the buttom is pressed, I would like to read the content of a specific TableView cell and show it in a TextBrowser. In particular, I would like to know the row index of the selected row and read the content of the cell with that row index and a specific column index (example 2).
The pseudo-code is this:
void my_program::on_pushButton_clicked()
{
ui->textBrowser->append("button pressed");
QItemSelectionModel *select = ui->tableView->selectionModel();
int index_row = select->selectedRows();
int index_column = 2;
char cell_data[30] = ??[index_row][index_column]
ui->textBrowser->append(cell_data);
}
The main problem is that select->selectedRows() returns a QModelIndex that is a collection of indexs and I do not know how to convert it to int (since multiple selection are not allowed, it should have only one element).
I would be glad if someone can suggest me a way to proceed.
Thanks
Francesco
edit:
Hi Bogdan, thanks a lot!! I succeed to read the cell content by using
ui->textBrowser->append(ui->tableView->model()->data(ui->tableView->model()->index(2,5)).toString());
this give me the content of the cell in position 2,5.
not sure if this is the best way or not but it works !!.
Can you be a bit more precise about how to iterate the QModeIndexList ? thanks :)
selectedRows() returns QModelIndexList, thus you need to iterate over it and call QModelIndex::data() to get stored data.

Different Qt::CheckStateRole for different views?

Currently I have a simple setup where I maintain a list of bools corresponding to each item in my ListModel:
http://programmingexamples.net/wiki/Qt/ModelView/StringListModelCheckable
However, now what I want to do is have two such lists bools, say IsHot and IsLarge. Then I want to have a ListView that displays each string with a checkbox for one of the bools (the "Hot" view), and a separate ListView that displays each string with a checkbox for the other bool (the "Large" bool). Any hints on how to go about this?
Make your model a table, return the data in two different columns, the cells in these columns will be checkable.
On your list views, call QListView::setModelColumn to set the column the list view displays.
If you want to synchronise scrolling between the lists, you would then be better using a QTableView, so that rows would match up.
Edit to add more detail on returning text and check state.
To return a text and the state of a checkbox from the model you return different data for different roles from the [data] function on your model.
From the manual for Qt::ItemDataRole:
Qt::DisplayRole The key data to be rendered in the form of text. (QString)
Qt::CheckStateRole This role is used to obtain the checked state of an item. (Qt::CheckState)
Both columns in your model would return the same data (the name) for DisplayRole but different data for CheckStateRole

Autofill QComboBox with data from database

I have created a QComboBox delegate which I use for a single column of a QTableView (each cell of that column is an individual combobox), the data which I want to display in my combobox returns from the database as a string of id's separated by a ;
My question is, how do I populate my combobox with this data retrieved by the database.
To clarify: the column in question retrieves specific Id's (4 digit strings), sometimes an object may have multiple Id's (separated by ;), I want to create a combobox for the cells with multiple Id's so the user can select which one they want to work with.
Perhaps something like this would work:
QString data = "Id01;Id02;Id03;Id04;Id05";
QStringList list = data.split(";");
QComboBox *comboBox = new QComboBox;
comboBox->insertItems(0, list);

list controls in flex3

i’m new to RIA, Flex.
Currently i’m using Flex 3.
I have some difficulty in my work.
i have three lists and a button.
depending up on the selected items in first two list and after clicking the button i have to disply the items in details list.can any any one help me
thanks in advance
in first list iam displaying names of employees
in second list displaying managers names
then if i select one employee name and one managers name then after clicking button corresponding employee and managers details should be dispplayed in the third list.
this is my work
presently iam unable to post my code
the problem is with initialising the details list and dynamically changing it.
It sounds like your third "list" isn't going to be a list at all, it will be a DataGrid of some kind, or a form with key/value pairs for the common data each employee and manager share.
Presumably your employee and manager lists are populated from a database, and you get more data than the name with each data object. What you need to do is add an event listener which listens for the change event in each of your first two lists. Then you have an event handler that does something with the result. The following just concatenates all the data from each selectedItem (for our imaginary list1 and list2) and puts it into an ArrayCollection, which is then assigned as the dataProvider for a DataGrid named dg:
private function changeHandler(event:DataGridEvent) : void {
var list1Item:Object = list1.selectedItem;
var list2Item:Object = list2.selectedItem;
var ac:ArrayCollection = new ArrayCollection();
for (prop in list1Item) {
ac.addItem({prop:list1Item[prop]});
}
for (prop in list2Item) {
ac.addItem({prop:list2Item[prop]});
}
dg.dataProvider = ac;
}
This is obviously not how you are going to do this, but it serves as an example. More likely you will have certain properties that you are interested in showing, and those are the ones you will add to the dg dataProvider.
This is as helpful as I can be speaking generally, in the absence of specific descriptions and requirements.

Resources