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