cutelyst  4.9.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 26 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 Cutelyst::Pagination::currentPage ( ) const

Returns the current page number.

Referenced by offset().

◆ enableFirst()

bool Cutelyst::Pagination::enableFirst ( ) const

Returns true if the first page link should be enabled.

◆ enableLast()

bool Cutelyst::Pagination::enableLast ( ) const

Returns true if the last page link should be enabled.

◆ lastPage()

int Cutelyst::Pagination::lastPage ( ) const

Returns the number of the last page.

◆ limit()

int Cutelyst::Pagination::limit ( ) const

Returns the number os items per page.

◆ numberOfItems()

int Cutelyst::Pagination::numberOfItems ( ) const

Returns the total number of items.

◆ offset() [1/2]

int Cutelyst::Pagination::offset ( ) const

Returns the current page offset for use in SQL.

◆ 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> Cutelyst::Pagination::pages ( ) const

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

Property Documentation

◆ currentPage

int Pagination::currentPage
read

Returns the current page number.

Definition at line 40 of file pagination.h.

◆ enableFirst

bool Pagination::enableFirst
read

Returns true if the first page link should be enabled.

Definition at line 52 of file pagination.h.

◆ enableLast

bool Pagination::enableLast
read

Returns true if the last page link should be enabled.

Definition at line 56 of file pagination.h.

◆ lastPage

int Pagination::lastPage
read

Returns the number of the last page.

Definition at line 44 of file pagination.h.

◆ limit

int Pagination::limit
read

Returns the number os items per page.

Definition at line 32 of file pagination.h.

◆ numberOfItems

int Pagination::numberOfItems
read

Returns the total number of items.

Definition at line 48 of file pagination.h.

◆ offset

int Pagination::offset
read

Returns the current page offset for use in SQL.

Definition at line 36 of file pagination.h.

◆ pages

QVector< int > Pagination::pages
read

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

Definition at line 60 of file pagination.h.