diff options
| author | Aleix Pol <aleixpol@kde.org> | 2015-10-16 14:21:09 (GMT) |
|---|---|---|
| committer | Aleix Pol <aleixpol@kde.org> | 2015-10-16 14:21:09 (GMT) |
| commit | 70d80c4770298ac8bb413f944bc9419dd3ed89f5 (patch) | |
| tree | 6028c4c645dcdb56770be3a7605507adb2fa2057 | |
| parent | e60128613acc6285f6f258c13b6ce49a2216ad69 (diff) | |
Fix some issues in the PaginateModel
ModelTest for king
| -rw-r--r-- | discover/PaginateModel.cpp | 19 | ||||
| -rw-r--r-- | discover/PaginateModel.h | 1 |
2 files changed, 15 insertions, 5 deletions
diff --git a/discover/PaginateModel.cpp b/discover/PaginateModel.cpp index 8cb9d5b..9d1c858 100644 --- a/discover/PaginateModel.cpp +++ b/discover/PaginateModel.cpp @@ -52,8 +52,13 @@ int PaginateModel::pageSize() const void PaginateModel::setPageSize(int count) { if (count != m_pageSize) { - int difference = count - m_pageSize; - if(difference>0) { + const int oldSize = rowsByPageSize(m_pageSize); + const int newSize = rowsByPageSize(count); + const int difference = newSize - oldSize; + qDebug() << "oldold" << oldSize << difference; + if (difference==0) { + m_pageSize = count; + } else if(difference>0) { beginInsertRows(QModelIndex(), m_pageSize, m_pageSize+difference); m_pageSize = count; endInsertRows(); @@ -115,10 +120,14 @@ QHash< int, QByteArray > PaginateModel::roleNames() const return m_sourceModel ? m_sourceModel->roleNames() : QAbstractItemModel::roleNames(); } +int PaginateModel::rowsByPageSize(int size) const +{ + return !m_sourceModel ? 0 : qMin(m_sourceModel->rowCount()-m_firstItem, size); +} + int PaginateModel::rowCount(const QModelIndex& parent) const { - int ret = parent.isValid() || !m_sourceModel ? 0 : qMin(m_sourceModel->rowCount()-m_firstItem, m_pageSize); - return ret; + return parent.isValid() ? 0 : rowsByPageSize(m_pageSize); } QModelIndex PaginateModel::mapToSource(const QModelIndex& idx) const @@ -274,7 +283,7 @@ void PaginateModel::_k_sourceRowsAboutToBeInserted(const QModelIndex& parent, in return; } - int insertedCount = end-start; + int insertedCount = end-start-1; if(insertedCount > m_pageSize) { beginResetModel(); } else { diff --git a/discover/PaginateModel.h b/discover/PaginateModel.h index 93c9735..930c89e 100644 --- a/discover/PaginateModel.h +++ b/discover/PaginateModel.h @@ -93,6 +93,7 @@ class PaginateModel : public QAbstractListModel void pageCountChanged(); private: + int rowsByPageSize(int size) const; int m_firstItem; int m_pageSize; QAbstractItemModel* m_sourceModel; |
