PDA

View Full Version : how to emit signal in the model in this application?



calmspeaker
16th February 2009, 11:43
Hi,
I use boost::circular_buffer as underly data stru in my own model,
I set capacity of circular_buffer in advance. For example , 30000. If I push_back more than 30000 data. the first ones will be deleted.
The question is: What signal should I emit to notice the QTableView to act correctly?

I tyr emit layoutabouttobechanged() layoutChanged(), but the selection stateis not act properly with the data push_back!

Another test is

beginRemoveRows(QModelIndex(),0,alarms.size()-1);
endRemoveRows();
beginInsertRows(QModelIndex(),max_alarm_num-alarms.size(),max_alarm_num-1);
endInsertRows();
It seems work, but I doubt it as in the Qt Assistant

When reimplementing insertRows() in a subclass, you must call this function before inserting data into the model's underlying data store.

abernat
16th February 2009, 17:20
The answer to your question depends on what you want to happen in the view. If you just want the new value to appear in the same place as the old value that was overwritten in the circular_buffer, all you need to do is call dataChanged() for the item that was changed.

If you want it to appear somewhere else in the view(say, the old value was at the top of the table view, and you want the new value to appear at the end of that view) things get a bit more complicated. In this case, you would need to call both beginRemoveRows()/endRemoveRows() and beginInsertRows()/endInsertRows(). The first pair would let the view know that the old value doesn't exist anymore, thus removing it from the top of the table, and the second pair inserts the new data at the end of the view.

calmspeaker
17th February 2009, 01:09
The answer to your question depends on what you want to happen in the view. If you just want the new value to appear in the same place as the old value that was overwritten in the circular_buffer, all you need to do is call dataChanged() for the item that was changed.

In fact, after you push_back datas into the circular_buffer which is full, in the tableview's view, :) all the data has changed. So I think this way is not proper. And I test it in my program, it doesn't work.



If you want it to appear somewhere else in the view(say, the old value was at the top of the table view, and you want the new value to appear at the end of that view) things get a bit more complicated. In this case, you would need to call both beginRemoveRows()/endRemoveRows() and beginInsertRows()/endInsertRows(). The first pair would let the view know that the old value doesn't exist anymore, thus removing it from the top of the table, and the second pair inserts the new data at the end of the view.
I called the two pairs after I changed the circular_buffer's data. But Qt Assistant says call beginRemoveRows() / beginInsertRows() before you changed the data, call endRemoveRows() / endInsertRows() after you changed the data. I cann't do this for according to the size of circular_buffer, I emit different signals.

I use QSortFilterProxyModel to sort and filt the data in the model. My program should work as efficient as it can in the extreme situation which insert about 1000 datas(my own data type) per second.But there is efficient problem when the circular_buffer is full. The cpu load is twice about it when the circular_buffer is not full when I only emit beginInsertRows()/endInsertRows() ! How can I improve it ?