5 #include "pagination.h" 7 #include <QtCore/QLoggingCategory> 12 Q_LOGGING_CATEGORY(C_PAGINATION,
"cutelyst.utils.pagination", QtWarningMsg)
16 if (itemsPerPage <= 0) {
17 qCWarning(C_PAGINATION) <<
"Invalid number of items per page:" << itemsPerPage
18 <<
"failing back to 1";
22 if (currentPage <= 0) {
23 qCWarning(C_PAGINATION) <<
"Invalid current page:" << currentPage <<
"failing back to 1";
28 qCWarning(C_PAGINATION) <<
"Invalid number of page links:" << pageLinks
29 <<
"failing back to 1";
33 insert(u
"limit"_s, itemsPerPage);
34 insert(u
"offset"_s, (currentPage - 1) * itemsPerPage);
35 insert(u
"currentPage"_s, currentPage);
36 insert(u
"current"_s, currentPage);
38 const int resultLastPage = ((numberOfItems - 1) / itemsPerPage) + 1;
39 currentPage = std::ranges::min(currentPage, resultLastPage);
41 const int startPage = (currentPage < pageLinks + 1) ? 1 : currentPage - pageLinks;
42 const int endPage = std::ranges::min((pageLinks * 2) + startPage, resultLastPage);
45 for (
int i = startPage; i <= endPage; ++i) {
48 insert(u
"enableFirst"_s, currentPage > 1);
49 insert(u
"enableLast"_s, currentPage != resultLastPage);
51 insert(u
"lastPage"_s, resultLastPage);
52 insert(u
"numberOfItems"_s, numberOfItems);
61 return value(u
"limit"_s).toInt();
66 return value(u
"offset"_s).toInt();
71 if (itemsPerPage <= 0) {
72 qCWarning(C_PAGINATION) <<
"Invalid number of items per page:" << itemsPerPage
73 <<
"failing back to 1";
76 if (currentPage <= 0) {
77 qCWarning(C_PAGINATION) <<
"Invalid current page:" << currentPage <<
"failing back to 1";
80 return (currentPage - 1) * itemsPerPage;
85 return value(u
"currentPage"_s).toInt();
90 return value(u
"lastPage"_s).toInt();
95 return value(u
"numberOfItems"_s).toInt();
100 return value(u
"enableFirst"_s).toBool();
105 return value(u
"enableLast"_s).toBool();
113 #include "moc_pagination.cpp"
QVariant fromValue(T &&value)
The Cutelyst namespace holds all public Cutelyst API.
void append(QList< T > &&value)