Hi,
Some interesting suggestions.
One I'd like to know is how do you block the signal from the model when I'm inserting data? Do I disconnect the signal? The model does emit a signal to my view to tell me that the table needs updating. What I have in my model now is it gets data, stores this in a structure and passes this structure back to the view using a signal, the view then inserts this data into the table and scrolls it. I still have to have a sleep of 10 milliseconds in order for the gui to keep up.
The code below shows the method that gets signalled in the view to update the table :
void CanView::scrolltable( int nCount, CANDATA* pData )
{
for( int i = 0; i < CANAMOUNT; i++ )
{
m_ptreeModel->setCanData( pData[i].m_strId );
m_ptreeModel->setCanData( pData[i].m_strTime );
m_ptreeModel->setCanData( pData[i].m_strData );
strCount.sprintf( "%i", nCount );
m_ptreeModel->setCanData( strCount );
nCount++;
}
ui.tableView->scrollTo( index );
}
void CanView::scrolltable( int nCount, CANDATA* pData )
{
for( int i = 0; i < CANAMOUNT; i++ )
{
m_ptreeModel->setCanData( pData[i].m_strId );
m_ptreeModel->setCanData( pData[i].m_strTime );
m_ptreeModel->setCanData( pData[i].m_strData );
QString strCount;
strCount.sprintf( "%i", nCount );
m_ptreeModel->setCanData( strCount );
nCount++;
}
QModelIndex index = m_ptreeModel->index( nCount, 0 );
ui.tableView->scrollTo( index );
}
To copy to clipboard, switch view to plain text mode
This is signalled every 10 milliseconds from the worker thread which just basically now reads CAN data into a structure. The setCanData method is a public method within the model :
void DATreeModel::setCanData( const QString& strData )
{
beginInsertRows(index, 1, 1);
m_Data.append(strData);
endInsertRows();
}
void DATreeModel::setCanData( const QString& strData )
{
QModelIndex index;
beginInsertRows(index, 1, 1);
m_Data.append(strData);
endInsertRows();
}
To copy to clipboard, switch view to plain text mode
As you can see, this inserts one item of data at a time, maybe the structure should be passed across here? Don't know if this would be quicker or not, the method would change to :
void DATreeModel::setCanData( CANDATA* pData, int nAmountData, int nCount )
{
beginInsertRows( index, 1, nAmount );
for( int i = 0; i < nAmount; i++ )
{
m_Data.append( pData[i]->m_strId );
m_Data.append( pData[i]->m_strTime );
m_Data.append( pData[i]->m_strData );
strCount.sprintf( "%i", nCount );
m_Data.append( strCount );
}
endInsertRows();
}
void DATreeModel::setCanData( CANDATA* pData, int nAmountData, int nCount )
{
QModelIndex index;
beginInsertRows( index, 1, nAmount );
for( int i = 0; i < nAmount; i++ )
{
m_Data.append( pData[i]->m_strId );
m_Data.append( pData[i]->m_strTime );
m_Data.append( pData[i]->m_strData );
QString strCount;
strCount.sprintf( "%i", nCount );
m_Data.append( strCount );
}
endInsertRows();
}
To copy to clipboard, switch view to plain text mode
m_Data is just a QList<QString> container.
Kind regards,
Steve
Bookmarks