2
Copyright 2010 Marco Martin <notmart@gmail.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
20
#include "pagedproxymodel.h"
24
PagedProxyModel::PagedProxyModel(QObject *parent)
25
: QProxyModel(parent),
31
PagedProxyModel::~PagedProxyModel()
35
int PagedProxyModel::totalPages()
41
return model()->rowCount() / m_pageSize;
44
void PagedProxyModel::setCurrentPage(const int page)
46
if (m_currentPage == page) {
54
int PagedProxyModel::currentPage() const
59
void PagedProxyModel::setPageSize(const int size)
61
if (m_pageSize == size) {
69
int PagedProxyModel::pageSize() const
74
void PagedProxyModel::setSourceModel(QObject *source)
76
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(source);
80
setRoleNames(model->roleNames());
84
QObject *PagedProxyModel::sourceModel() const
90
int PagedProxyModel::rowCount(const QModelIndex &parent) const
92
return qMin(m_pageSize, (QProxyModel::rowCount(parent)-m_currentPage*m_pageSize));
95
QVariant PagedProxyModel::data(const QModelIndex &index, int role) const
97
return QProxyModel::data(QProxyModel::index(index.row()+(m_pageSize*m_currentPage), index.column()), role);
100
#include "pagedproxymodel.moc"