Forum
Sign Up
× DataGrid for Qt.C++

3.2 release returns incorrect selection iterator

5 years 10 months ago #1 by Pascal
After updating to 3.2 below code consistently returns the previously selected row and not the currently selected. Reverted back to 3.1 and issue was not present.
Something wrong with my code ? Behaviour changed in 3.2 ?
int modelRowIndex = -1;

Qtitan::GridTableView *view = ui->grid->view<Qtitan::GridTableView>();
GridSelectionIterator *selection = view->selectionIterator();

while (!selection->end()) {
   if (selection->row()->type() == GridRow::DataRow) {
      modelRowIndex = selection->row()->modelRowIndex();
      break;
   }
   selection->next();
}

if (modelRowIndex >= 0) {
   QModelIndex idx = m_pTableModel->index(modelRowIndex,MyTableModel::id);
   int no = m_pTableModel->data(idx).toInt();

Please Log in or Create an account to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #2 by Developer Machines
No, behavior has not changed and I can't reproduce it. Please see screenshot.
Please note, row's indexes starting with 0 value.

Could you please check it in multiselect.exe demo?
Attachments:
Last edit: 5 years 10 months ago by Developer Machines.

Please Log in or Create an account to join the conversation.

More
5 years 10 months ago #3 by Pascal
Hi,

thanks for taking the time to check this. I found the issue.

What I forgot to mention (and that was key for the issue) is that the above code which uses the selectionIterator is called from a slot called by 'focusRowChanged(int,int)' signal.

Probably not the best way to find the model Row index, but it worked up until 3.1. Starting 3.2, the focusRowChanged signal is fired before the selectionIterator is updated with the newly focussed row.

I changed the code to use the newRowIdx passed through the focusRowChanged SIGNAL to fetch the modelRowIndex through the modelController->getGridRow()->modelRowIndex() function. This looks more consistent and less prone to timings between focus and selection.

Code now looks like:
...
QObject::connect(view,SIGNAL(focusRowChanged(int,int)),this,SLOT(showdetail(int,int)));
...    
void TransactionsDialog::showdetail(int oRowIdx, int nRowIdx) {
  ...
  int modelRowIndex = view->modelController()->getGridRow(nRowIdx)->modelRowIndex();
  ...
}

Can you confirm this is the best way to get access to the index within the model when inside the focusRowChanged event handler ?

After more than 2 years using the datagrid, I'm still struggling to find the correct way to achieve something. There is a lot of functionality and very much to discover I'm sure, but not enough time to experiment. That is why a good forum would be great for everyone using the grid.

Thanks for the good work on the grid, I like what you have done with the 3.x release !

Pascal.

Please Log in or Create an account to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #4 by Developer Machines
>>Can you confirm this is the best way to get access to the index within the model when inside the focusRowChanged event handler ?

Absolutely. Your code is valid. In the focusRowChanged handler all indexes that were selected should be in the actual state. It is an issue in datagrid. We will check it and add fix to the next update. Many thanks for your hint about the issue.
Last edit: 5 years 10 months ago by Developer Machines.

Please Log in or Create an account to join the conversation.

More
  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Moderators: Developer MachinesEduard
Time to create page: 0.133 seconds

Developer Newsletter

Join our Developer Machines newsletter to get informed on all the latest releases of the commercial components for Qt.C++, Delphi FireMonkey, updates and general knowledges.

Quick Support

Should you need any additional information about our products or licensing, please contact us at the following email addresses:

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

Get in Touch

If you would like to purchase our products or services, but don’t know how to do it the right way, please feel free to contact us:

  • This email address is being protected from spambots. You need JavaScript enabled to view it.( any questions related to our products or services )
  • This email address is being protected from spambots. You need JavaScript enabled to view it.( questions related to licensing )