Implemented dynamic row adding

The view only adds as many rows as they can be displayed now.
Only scrolling, it adds more
This commit is contained in:
Nikhil Tanwar 2023-06-22 12:54:12 +05:30
parent b0e3bf8daf
commit 9e5f187f9e
2 changed files with 24 additions and 1 deletions

View File

@ -82,7 +82,7 @@ QModelIndex ContentManagerModel::parent(const QModelIndex &index) const
int ContentManagerModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_data.size();
return zimCount;
}
QVariant ContentManagerModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -150,3 +150,21 @@ bool ContentManagerModel::hasChildren(const QModelIndex &parent) const
return true;
}
bool ContentManagerModel::canFetchMore(const QModelIndex &parent) const
{
if (parent.isValid())
return false;
return (zimCount < m_data.size());
}
void ContentManagerModel::fetchMore(const QModelIndex &parent)
{
if (parent.isValid())
return;
int remainder = m_data.size() - zimCount;
int zimsToFetch = qMin(5, remainder);
beginInsertRows(QModelIndex(), zimCount, zimCount + zimsToFetch - 1);
zimCount += zimsToFetch;
endInsertRows();
}

View File

@ -28,9 +28,14 @@ public:
void setupNodes();
bool hasChildren(const QModelIndex &parent) const override;
protected:
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
private:
QList<QMap<QString, QVariant>> m_data;
Node *rootNode;
int zimCount = 0;
};
#endif // CONTENTMANAGERMODEL_H