Finally I could do lazy loading, but not as I expected.
I am reading X amount of rows and building parent and child relationship. as we keep on scroll down I am getting remaining data by using canFetchMore() and fetchMore() functions.
once I get the data I am appending this data to existing data by forming parent and child relationship.
1. The 1st problem is, I am not able to delete the old data, If I tried to delete old data and keep only new data I am not able to see any scroll bars.
2. the 2nd problem is when I have huge data, As the user keep on scroll down, scroll bar is becoming small. if we have a huge amount of data it becoming difficult for the user to really go to the end of the view and wait for the result to fetch and once results got fetched then come to know that there are some more records are available and still scroll down.
for the second problem I tried to create vertical scroll bar and set a value for it and then set it to the view. but It did not workout.
could you please suggest some solution for this 2 problems.
Below is the code snippet, please suggest how to delete old data and maintain only current records in a memory.
bool TreeModel
::canFetchMore(const QModelIndex &parent
) const {
if(m_totalRowCount > m_lastFetchedRowNumber)
{
return true;
}
return false;
}
void TreeModel::fetchMore(const QModelIndex& parent)
{
int readRows = 1000; //reading 1000 records/rows every time
if( m_totalRowCount < ( readRows + m_lastFetchedRowNumber ) ) //boundary condition
{
readRows = m_totalRowCount - m_lastFetchedRowNumber;
}
qint64 l_lastInsertedRow = m_lastreadRowIndex;
//m_parent is my parent, I tried by doing this; delete m_parrent; m_parrent = createParentItem(); // but it did not workout.
emit fetchMoreData(readRows); // will fetch readRows no.of rows, may vary depends on logic(next fetch would start from a row which Level is 0) I have written.
// I have written a logic so that every time I will get 0 as 1st row, so every time I insert data, parent must me QModelIndex()
beginInsertRows
(QModelIndex(), l_lastInsertedRow, m_lastreadRowIndex
-1);
endInsertRows();
}
bool TreeModel::canFetchMore(const QModelIndex &parent ) const
{
if(m_totalRowCount > m_lastFetchedRowNumber)
{
return true;
}
return false;
}
void TreeModel::fetchMore(const QModelIndex& parent)
{
int readRows = 1000; //reading 1000 records/rows every time
if( m_totalRowCount < ( readRows + m_lastFetchedRowNumber ) ) //boundary condition
{
readRows = m_totalRowCount - m_lastFetchedRowNumber;
}
qint64 l_lastInsertedRow = m_lastreadRowIndex;
//m_parent is my parent, I tried by doing this; delete m_parrent; m_parrent = createParentItem(); // but it did not workout.
emit fetchMoreData(readRows); // will fetch readRows no.of rows, may vary depends on logic(next fetch would start from a row which Level is 0) I have written.
// I have written a logic so that every time I will get 0 as 1st row, so every time I insert data, parent must me QModelIndex()
beginInsertRows(QModelIndex(), l_lastInsertedRow, m_lastreadRowIndex-1);
endInsertRows();
}
To copy to clipboard, switch view to plain text mode
Thanks in advance.
Bookmarks