TreeFrogFramework  2.8
tpaginator.h
Go to the documentation of this file.
1 #pragma once
2 #include <QList>
3 #include <TGlobal>
4 
5 
7 public:
8  TPaginator(int itemsTotal = 0, int itemsPerPage = 10, int midRange = 5);
9  TPaginator(const TPaginator &other);
10  virtual ~TPaginator() { }
11 
12  TPaginator &operator=(const TPaginator &other);
13 
14  // Setter
15  void setItemTotalCount(int total);
16  void setItemCountPerPage(int count);
17  void setMidRange(int range);
18  void setCurrentPage(int page);
19 
20  // Getter
21  int itemTotalCount() const { return _itemsTotal; }
22  int numPages() const { return _numPages; }
23  int itemCountPerPage() const { return _itemsPerPage; }
24  int itemCountOfCurrentPage() const;
25  int offset() const;
26  int midRange() const { return _midRange; }
27  virtual QList<int> range() const;
28  int currentPage() const;
29  int firstPage() const { return 1; }
30  int previousPage() const { return std::max(currentPage() - 1, 1); }
31  int nextPage() const { return qMin(currentPage() + 1, _numPages); }
32  int lastPage() const { return _numPages; }
33  bool hasPrevious() const { return (currentPage() >= 2); }
34  bool hasNext() const { return (currentPage() < _numPages); }
35  bool hasPage(int page) const { return (page > 0 && page <= _numPages); }
36 
37 protected:
38  void calculateNumPages(); // Internal use
39 
40 private:
41  int _itemsTotal {0};
42  int _itemsPerPage {10};
43  int _midRange {5};
44  int _numPages {1};
45  int _currentPage {1};
46 };
47 
48 Q_DECLARE_METATYPE(TPaginator)
49 
The TPaginator class provides simple functionality for a pagination bar.
Definition: tpaginator.h:6
int lastPage() const
Returns the last page number.
Definition: tpaginator.h:32
int midRange() const
Returns the number of page numbers to be shown on a pagination bar.
Definition: tpaginator.h:26
bool hasPage(int page) const
Returns true if page is a valid page; otherwise returns false.
Definition: tpaginator.h:35
virtual ~TPaginator()
Definition: tpaginator.h:10
int itemTotalCount() const
Returns the total number of items.
Definition: tpaginator.h:21
int previousPage() const
Returns the page number before the current page.
Definition: tpaginator.h:30
int numPages() const
Returns the total number of pages.
Definition: tpaginator.h:22
int firstPage() const
Returns the first page number, always 1.
Definition: tpaginator.h:29
int nextPage() const
Returns the page number after the current page.
Definition: tpaginator.h:31
int itemCountPerPage() const
Returns the maximum number of items to be shown per page.
Definition: tpaginator.h:23
bool hasNext() const
Returns true if there is at least one page after the current page; otherwise returns false.
Definition: tpaginator.h:34
bool hasPrevious() const
Returns true if there is at least one page before the current page; otherwise returns false.
Definition: tpaginator.h:33
#define T_CORE_EXPORT
Definition: tdeclexport.h:28