#ifndef _PvTable_H_ #define _PvTable_H_ #include #include "PvApp.h" #include "Fields.h" using CallbackTableOpt = std::function; class PvTable : public PvObject { public: struct Options { bool show_header = true; bool show_border = true; int head_height = 40; int row_height = 35; int page_size = 10; int width = 500; }; struct Head { Head() {} Head(std::string hid, std::string htext, int w, std::vector> mapping) : id(hid), text(htext), width(w), vecMaping(mapping) {} std::string id; std::string text; int width = 80; int pvid = PV_ID_NUL; vector> vecMaping; std::string getMapping(std::string s) { std::string v = s; for (auto& item : vecMaping) { if (v == item.first) { v = item.second; } else if (v == item.second) { v = item.first; } } return v; } }; struct Row { bool visible = false; int bkg {PV_ID_NUL}; std::vector vecCells {}; }; public: PvTable(PARAM* p, int parent, int x, int y, int w, int rows, Options& option); void addHead(std::string id, std::string text, int width, std::vector> mapping = {}); void addHead(std::vector vecText); void setRowVisible(int row, bool v); void highlight(int row, bool v); void addOperate(std::vector vecOpt); void setOperateCallback(CallbackTableOpt cb); void set_text(PARAM* p, int row, int col, std::string text, std::string style = ""); void setRowData(int row, Fields& d); void setRowData(int row, std::vector vd); Fields getRowData(int row); void mappingData(Fields& fields); void set_border_visible(PARAM* p, bool v); void add_col_button(PARAM* p, int col, std::string title, PvRect& rt, std::string style); void add_col_button(PARAM* p, int col, std::vector vec_title); void setOperateVisible(int row, bool v, int id = -1); int item_posy(int row); int border_id(); int rows(); int colums(); std::vector data(); PvTable::Head& header(int col); private: int pvid_; PvRect rect_; int border_id_; std::vector vecHead_; std::vector vecRows_; std::vector vecData_; vector>> vecOpt_; int nRow_; int nCol_; string item_base_style_; Options option_; unordered_map> vec_col_item_btn_; CallbackTableOpt cbOperate_ = nullptr; int posCol_ = 0; }; class PvPagination : public PvObject { public: PvPagination(PARAM* p, int parent, int x, int y, int n); void setPage(int index, int count); int page(); void setCallback(std::function func); private: void activePage(int index, bool invoke=false); private: // 当前显示的页码索引, 从1开始 int pageIndex = 1; // 总页数 int pageCount = 0; // 上一页按钮 int btnPrev = PV_ID_NUL; // 下一页按钮 int btnNext = PV_ID_NUL; // 页面跳转按钮 int btn_gopage_ = PV_ID_NUL; int btnActive = PV_ID_NUL; int labelInfo = PV_ID_NUL; // 页码列表(最多显示6个页码按钮,前3页和后3页) <按钮ID, 页码> std::vector> vecBtn; function callback = nullptr; }; class PvPageTable :public PvObject { public: PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts); shared_ptr getTable(); private: shared_ptr table_ = nullptr; shared_ptr page_ctrl_ = nullptr; }; #endif // ! _PvTable_H_