mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
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:
parent
b0e3bf8daf
commit
9e5f187f9e
@ -82,7 +82,7 @@ QModelIndex ContentManagerModel::parent(const QModelIndex &index) const
|
|||||||
int ContentManagerModel::rowCount(const QModelIndex &parent) const
|
int ContentManagerModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return m_data.size();
|
return zimCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ContentManagerModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant ContentManagerModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
@ -150,3 +150,21 @@ bool ContentManagerModel::hasChildren(const QModelIndex &parent) const
|
|||||||
return true;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,14 @@ public:
|
|||||||
void setupNodes();
|
void setupNodes();
|
||||||
bool hasChildren(const QModelIndex &parent) const override;
|
bool hasChildren(const QModelIndex &parent) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool canFetchMore(const QModelIndex &parent) const override;
|
||||||
|
void fetchMore(const QModelIndex &parent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QMap<QString, QVariant>> m_data;
|
QList<QMap<QString, QVariant>> m_data;
|
||||||
Node *rootNode;
|
Node *rootNode;
|
||||||
|
int zimCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTENTMANAGERMODEL_H
|
#endif // CONTENTMANAGERMODEL_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user