PageWidget.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef PAGEWIDGET_H
  2. #define PAGEWIDGET_H
  3. #include <QComboBox>
  4. #include <QList>
  5. #include <QWidget>
  6. #include "databasemanager.h"
  7. class QLabel;
  8. class QEvent;
  9. struct HeaderInfo {
  10. QString label;
  11. QString prop;
  12. };
  13. namespace Ui {
  14. class PageWidget;
  15. }
  16. class PageWidget : public QWidget {
  17. Q_OBJECT
  18. public:
  19. explicit PageWidget(int blockSize = 3, QWidget *parent = 0);
  20. ~PageWidget();
  21. /*const
  22. * 关键字在成员函数声明和定义中的使用,确保了该函数不会修改对象的状态,提高了代码的安全性和可读性。这对于那些只需要读取对象状态而不需要修改对象状态的函数非常有用*/
  23. int getBlockSize() const;
  24. int getMaxPage() const;
  25. int getCurrentPage() const;
  26. // 其他组件只需要调用这两个函数即可
  27. void setMaxPage(int maxPage); // 当总页数改变时调用
  28. void setCurrentPage(int currentPage, bool signalEmitted = false); // 修改当前页时调用
  29. void showLeft();
  30. QComboBox *getComboBox() const;
  31. protected:
  32. virtual bool eventFilter(QObject *watched, QEvent *e);
  33. signals:
  34. void currentPageChanged(int page);
  35. private:
  36. Ui::PageWidget *ui;
  37. int blockSize;
  38. int maxPage; // 总页数
  39. int currentPage; // 当前页面
  40. QList<QLabel *> *pageLabels;
  41. int PageRecordCount; // 每页显示的记录数量
  42. void setBlockSize(int blockSize);
  43. void updatePageLabels();
  44. void initialize();
  45. void setRecordCount();
  46. void initCombo();
  47. };
  48. #endif // PAGEWIDGET_H