selection in filterproxymodel
Hi I have a question about how can I get selected rows indexes from QSortFilterProxyModel...(selection behaviour is set to select rows)
in QTableView there is a possibility using this:
msgTableView->selectionModel()->selectedRows()
But when I have to models from which one is filtermodel and it has set second one using
filterModel->setSourceModel(2ndmodel);
then this method of getting a list of indexes is unuseful ...
Can anyone help me to figure it out ?
I think I have to map them somehow to source indexes but dont know how :(
Re: selection in filterproxymodel
Selection is a property of the view, not of the model. If you set a proxy model on the view, you can use its selection model to get selected indexes of the proxy model which you can then map to the source model using its mapToSource() method.
Re: selection in filterproxymodel
Quote:
Originally Posted by
wysota
Selection is a property of the view, not of the model. If you set a proxy model on the view, you can use its selection model to get selected indexes of the proxy model which you can then map to the source model using its mapToSource() method.
Yes but I was actually asking if there is a method to which I would actually passed the whole index list got byt selectionModel()->selectedRows() instead of iterating over all indexes....
Re: selection in filterproxymodel
Take a closer look at QAbstractProxyModel docs. ;)
Re: selection in filterproxymodel
Quote:
Originally Posted by
jpn
man I made it work....but wanted something simpler...it wasnt hard of course...
Code:
foreach
(QModelIndex index, msgTableView
->selectionModel
()->selectedRows
()){ QModelIndex sourceIndex
= filterModel
->mapToSource
(index
);
int row = sourceIndex.row();
for(int i = 0; i < model->columnCount(); i++){
if(i == 0){
sendMsg.id = prepMsg.toString().toULong();
qDebug("Message id = %ld", sendMsg.id);
}
if(i == 1){
sendMsg.flags = prepMsg.toString().toInt();
qDebug("Message flags = %d", sendMsg.flags);
}
if(i == 2){
int length = qMin(sendData.size(), CAN_MSG_LENGTH);
qDebug("LENGTH = %d", length);
memcpy(sendMsg.data, (const unsigned char*)sendData.constData(), length);
sendMsg.length = length;
}
}
parentWindow->getNetworkIfc()->sendCanMsg(&sendMsg);
QVcaCanMsg sharedMsg(&sendMsg);
emit msgHistoryEnqueue(sharedMsg);
}
Re: selection in filterproxymodel
Re: selection in filterproxymodel
Quote:
Originally Posted by
jpn
damn it...yes thats better solution...I remade it your way...But BOTH solutions work ;)
Re: selection in filterproxymodel
Doesn't it do exactly that?
Re: selection in filterproxymodel
Quote:
Originally Posted by
wysota
Doesn't it do exactly that?
damn it...I was talking about something different ;)
Re: selection in filterproxymodel
Please don't modify your previous posts like that. It breaks the flow of the discussion and others can't benefit from it.