cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::Pagination Class Reference

Helper to calculate values for paginating result lists. More...

#include <Cutelyst/Plugins/Utils/Pagination>

Inheritance diagram for Cutelyst::Pagination:

Public Member Functions

 Pagination (int numberOfItems, int itemsPerPage, int currentPage, int pageLinks=10)
 
virtual ~Pagination ()
 
int currentPage () const
 
bool enableFirst () const
 
bool enableLast () const
 
int lastPage () const
 
int limit () const
 
int numberOfItems () const
 
int offset () const
 
QVector< int > pages () const
 

Static Public Member Functions

static int offset (int itemsPerPage, int currentPage)
 

Properties

int currentPage
 
bool enableFirst
 
bool enableLast
 
int lastPage
 
int limit
 
int numberOfItems
 
int offset
 
QVector< int > pages
 

Detailed Description

The Pagination plugin is a little helper class to calculate different values for paginating result lists from for example database queries. If you have a result set of for example 123 records and want to show 10 per page, you can use this class to calculate the pagination.

Logging category
cutelyst.utils.pagination
Logging with Cutelyst

Definition at line 25 of file pagination.h.

Constructor & Destructor Documentation

◆ Pagination()

Pagination::Pagination ( int  numberOfItems,
int  itemsPerPage,
int  currentPage,
int  pageLinks = 10 
)

Contructs a new Pagination object with the given parameters.

Parameters
numberOfItemsshould be set to the total of items to be displayed
itemsPerPagethe desired number of items per page
currentPagethe current 1 indexed page (first page is 1) usually from the query url
pageLinksthe number of page links that should be generated, for example 3 -> 11, 12, 13

Definition at line 13 of file pagination.cpp.

References QList::append(), and QVariant::fromValue().

◆ ~Pagination()

Pagination::~Pagination ( )
virtual

Destroys the Pagination object.

Definition at line 59 of file pagination.cpp.

Member Function Documentation

◆ currentPage()

int Pagination::currentPage ( ) const

Returns the current page number.

Definition at line 87 of file pagination.cpp.

◆ enableFirst()

bool Pagination::enableFirst ( ) const

Returns true if the first page link should be enabled.

Definition at line 102 of file pagination.cpp.

◆ enableLast()

bool Pagination::enableLast ( ) const

Returns true if the last page link should be enabled.

Definition at line 107 of file pagination.cpp.

◆ lastPage()

int Pagination::lastPage ( ) const

Returns the number of the last page.

Definition at line 92 of file pagination.cpp.

◆ limit()

int Pagination::limit ( ) const

Returns the number os items per page.

Definition at line 63 of file pagination.cpp.

◆ numberOfItems()

int Pagination::numberOfItems ( ) const

Returns the total number of items.

Definition at line 97 of file pagination.cpp.

◆ offset() [1/2]

int Pagination::offset ( ) const

Returns the current page offset for use in SQL.

Definition at line 68 of file pagination.cpp.

◆ offset() [2/2]

int Pagination::offset ( int  itemsPerPage,
int  currentPage 
)
static

Returns the current page offset for use in SQL taking the number of items per page and the current page.

Definition at line 73 of file pagination.cpp.

References currentPage.

◆ pages()

QVector< int > Pagination::pages ( ) const

Returns the list of pages, with each page number as the integer.

Definition at line 112 of file pagination.cpp.

Property Documentation

◆ currentPage

int Cutelyst::Pagination::currentPage
read

Returns the current page number.

Definition at line 39 of file pagination.h.

Referenced by offset().

◆ enableFirst

bool Cutelyst::Pagination::enableFirst
read

Returns true if the first page link should be enabled.

Definition at line 51 of file pagination.h.

◆ enableLast

bool Cutelyst::Pagination::enableLast
read

Returns true if the last page link should be enabled.

Definition at line 55 of file pagination.h.

◆ lastPage

int Cutelyst::Pagination::lastPage
read

Returns the number of the last page.

Definition at line 43 of file pagination.h.

◆ limit

int Cutelyst::Pagination::limit
read

Returns the number os items per page.

Definition at line 31 of file pagination.h.

◆ numberOfItems

int Cutelyst::Pagination::numberOfItems
read

Returns the total number of items.

Definition at line 47 of file pagination.h.

◆ offset

int Cutelyst::Pagination::offset
read

Returns the current page offset for use in SQL.

Definition at line 35 of file pagination.h.

◆ pages

QVector<int> Cutelyst::Pagination::pages
read

Returns the list of pages, with each page number as the integer.

Definition at line 59 of file pagination.h.