5 #include "pagination.h"
7 #include <QtCore/QLoggingCategory>
11 Q_LOGGING_CATEGORY(C_PAGINATION,
"cutelyst.utils.pagination", QtWarningMsg)
15 if (itemsPerPage <= 0) {
16 qCWarning(C_PAGINATION) <<
"Invalid number of items per page:" << itemsPerPage
17 <<
"failing back to 1";
21 if (currentPage <= 0) {
22 qCWarning(C_PAGINATION) <<
"Invalid current page:" << currentPage <<
"failing back to 1";
27 qCWarning(C_PAGINATION) <<
"Invalid number of page links:" << pageLinks
28 <<
"failing back to 1";
32 insert(QStringLiteral(
"limit"), itemsPerPage);
33 insert(QStringLiteral(
"offset"), (currentPage - 1) * itemsPerPage);
34 insert(QStringLiteral(
"currentPage"), currentPage);
35 insert(QStringLiteral(
"current"), currentPage);
37 int lastPage = (numberOfItems - 1) / itemsPerPage + 1;
38 if (currentPage > lastPage) {
39 currentPage = lastPage;
42 int startPage = (currentPage < pageLinks + 1) ? 1 : currentPage - pageLinks;
43 int endPage = (pageLinks * 2) + startPage;
44 if (lastPage < endPage) {
49 for (
int i = startPage; i <= endPage; ++i) {
52 insert(QStringLiteral(
"enableFirst"), currentPage > 1);
53 insert(QStringLiteral(
"enableLast"), currentPage != lastPage);
55 insert(QStringLiteral(
"lastPage"), lastPage);
56 insert(QStringLiteral(
"numberOfItems"), numberOfItems);
65 return value(QStringLiteral(
"limit")).toInt();
70 return value(QStringLiteral(
"offset")).toInt();
75 if (itemsPerPage <= 0) {
76 qCWarning(C_PAGINATION) <<
"Invalid number of items per page:" << itemsPerPage
77 <<
"failing back to 1";
81 qCWarning(C_PAGINATION) <<
"Invalid current page:" <<
currentPage <<
"failing back to 1";
89 return value(QStringLiteral(
"currentPage")).toInt();
94 return value(QStringLiteral(
"lastPage")).toInt();
99 return value(QStringLiteral(
"numberOfItems")).toInt();
104 return value(QStringLiteral(
"enableFirst")).toBool();
109 return value(QStringLiteral(
"enableLast")).toBool();
114 return value(QStringLiteral(
"pages")).value<
QVector<int>>();
117 #include "moc_pagination.cpp"
The Cutelyst namespace holds all public Cutelyst API.
void append(QList::parameter_type value)
QVariant fromValue(T &&value)