cutelyst  4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
pagination.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2015-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef PAGINATION_H
6 #define PAGINATION_H
7 
8 #include <Cutelyst/Plugins/Utils/pagination_export.h>
9 
10 #include <QVariantMap>
11 
12 namespace Cutelyst {
13 
25 class CUTELYST_PLUGIN_UTILS_PAGINATION_EXPORT Pagination : public QVariantMap
26 {
27  Q_GADGET
31  Q_PROPERTY(int limit READ limit CONSTANT)
35  Q_PROPERTY(int offset READ offset CONSTANT)
39  Q_PROPERTY(int currentPage READ currentPage CONSTANT)
43  Q_PROPERTY(int lastPage READ lastPage CONSTANT)
47  Q_PROPERTY(int numberOfItems READ numberOfItems CONSTANT)
51  Q_PROPERTY(bool enableFirst READ enableFirst CONSTANT)
55  Q_PROPERTY(bool enableLast READ enableLast CONSTANT)
59  Q_PROPERTY(QVector<int> pages READ pages CONSTANT)
60 public:
61  Pagination() = default;
70  Pagination(int numberOfItems, int itemsPerPage, int currentPage, int pageLinks = 10);
71 
75  virtual ~Pagination();
76 
80  [[nodiscard]] int limit() const;
81 
85  [[nodiscard]] int offset() const;
86 
91  [[nodiscard]] static int offset(int itemsPerPage, int currentPage);
92 
96  [[nodiscard]] int currentPage() const;
97 
101  [[nodiscard]] int lastPage() const;
102 
106  [[nodiscard]] int numberOfItems() const;
107 
111  bool enableFirst() const;
112 
116  bool enableLast() const;
117 
121  [[nodiscard]] QVector<int> pages() const;
122 };
123 
124 } // namespace Cutelyst
125 Q_DECLARE_METATYPE(Cutelyst::Pagination)
126 
127 #endif // PAGINATION_H
Helper to calculate values for paginating result lists.
Definition: pagination.h:26
The Cutelyst namespace holds all public Cutelyst API.