Hello,
I have to following problem:
I created my own QAbstractTableModel and QSortFilterProxyModel.
The initialization looks like this:
m_model = new QAlarmModel(ui.tableViewAlarms);
m_proxy = new QAlarmSortFilterProxyModel(ui.tableViewAlarms);
//m_proxy->setDynamicSortFilter(true);
m_proxy->setSourceModel(m_model);
ui.tableViewAlarms->setModel(m_proxy);
ui.tableViewAlarms->sortByColumn(0,Qt::AscendingOrder);
m_model = new QAlarmModel(ui.tableViewAlarms);
m_proxy = new QAlarmSortFilterProxyModel(ui.tableViewAlarms);
//m_proxy->setDynamicSortFilter(true);
m_proxy->setSourceModel(m_model);
ui.tableViewAlarms->setModel(m_proxy);
ui.tableViewAlarms->sortByColumn(0,Qt::AscendingOrder);
To copy to clipboard, switch view to plain text mode
Sorting works fine. But I have also a function, which should select the first not acknowledged alarm.
Therefore i have to iterate through the table and look if the alarm at row x is acknowledged or not.
I do it like this:
for(int i=0; (i < m_proxy->rowCount()) && (selRow < 0); ++i)
{
int row = i;
QModelIndex idx
= m_proxy
->index
(row,QAlarmModel
::COL_ALARM);
QModelIndex idx3
= idx2.
sibling(row,QAlarmModel
::COL_H_POINTER);
QAlarm *alarm = (QAlarm*)m_model->data(idx3).toLongLong();
if (alarm && !alarm->m_ack)
{
selRow = row;
ui.tableViewAlarms->selectionModel()->reset();
}
}
for(int i=0; (i < m_proxy->rowCount()) && (selRow < 0); ++i)
{
int row = i;
QModelIndex idx = m_proxy->index(row,QAlarmModel::COL_ALARM);
QModelIndex idx2 = m_proxy->mapToSource(idx);
QModelIndex idx3 = idx2.sibling(row,QAlarmModel::COL_H_POINTER);
QAlarm *alarm = (QAlarm*)m_model->data(idx3).toLongLong();
if (alarm && !alarm->m_ack)
{
selRow = row;
ui.tableViewAlarms->selectionModel()->reset();
ui.tableViewAlarms->selectionModel()->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
}
}
To copy to clipboard, switch view to plain text mode
The problem is, that the loop doesn't start with the first row of the table. Depending on the sort order it starts with the last.
I hope someone can help me. Thanks.
Bookmarks