mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
搭建PVB架构,实现前端的基础布局、菜单、表格、图示等功能
This commit is contained in:
174
src/pv/PvTable.h
Normal file
174
src/pv/PvTable.h
Normal file
@@ -0,0 +1,174 @@
|
||||
#ifndef _PvTable_H_
|
||||
#define _PvTable_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "PvApp.h"
|
||||
#include "DataFields.h"
|
||||
|
||||
using CallbackTableOpt = std::function<void(int row, int col, std::string text)>;
|
||||
|
||||
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<std::pair<std::string, std::string>> mapping)
|
||||
: id(hid), text(htext), width(w), vecMaping(mapping) {}
|
||||
|
||||
std::string id;
|
||||
std::string text;
|
||||
int width = 80;
|
||||
int pvid = PV_ID_NUL;
|
||||
vector<pair<string, string>> 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<int> 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<std::pair<std::string, std::string>> mapping = {});
|
||||
void addHead(std::vector<std::string> vecText);
|
||||
|
||||
void setRowVisible(int row, bool v);
|
||||
void highlight(int row, bool v);
|
||||
|
||||
void addOperate(std::vector<std::string> vecOpt);
|
||||
void setOperateCallback(CallbackTableOpt cb);
|
||||
|
||||
void set_text(PARAM* p, int row, int col, std::string text, std::string style = "");
|
||||
|
||||
void setRowData(int row, DataFields& d);
|
||||
void setRowData(int row, std::vector<std::string> vd);
|
||||
|
||||
DataFields& getRowdata(int row);
|
||||
|
||||
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<std::string> 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<DataFields> data();
|
||||
|
||||
PvTable::Head& header(int col);
|
||||
|
||||
private:
|
||||
int pvid_;
|
||||
PvRect rect_;
|
||||
|
||||
int border_id_;
|
||||
|
||||
std::vector<PvTable::Head> vecHead_;
|
||||
std::vector<PvTable::Row> vecRows_;
|
||||
|
||||
std::vector<DataFields> vecData_;
|
||||
|
||||
vector<pair<int, vector<int>>> vecOpt_;
|
||||
int nRow_;
|
||||
int nCol_;
|
||||
|
||||
string item_base_style_;
|
||||
|
||||
Options option_;
|
||||
|
||||
unordered_map<int, vector<int>> vec_col_item_btn_;
|
||||
|
||||
CallbackTableOpt cbOperate_ = nullptr;
|
||||
|
||||
int posCol_ = 0;
|
||||
};
|
||||
|
||||
|
||||
class PvPagination : public PvObject
|
||||
{
|
||||
public:
|
||||
PvPagination(PARAM* p, int parent, const PvRect& rt);
|
||||
|
||||
void set_page(int page_id, int max_page);
|
||||
|
||||
int pageid();
|
||||
|
||||
void set_goto_page_callback(std::function<void(int pageid)> cb);
|
||||
|
||||
private:
|
||||
void on_click_page(int btnid);
|
||||
void on_click_prev();
|
||||
void on_click_next();
|
||||
|
||||
void active_page_button(PARAM* p, int new_pageid, int old_pageid);
|
||||
|
||||
private:
|
||||
int pvid_ = PV_ID_NUL;
|
||||
|
||||
// 当前显示的页码索引, 从1开始
|
||||
int page_id_ = 1;
|
||||
|
||||
// 总页数
|
||||
int page_count_ = 0;
|
||||
|
||||
// 上一页按钮
|
||||
int btn_prev_ = PV_ID_NUL;
|
||||
|
||||
// 下一页按钮
|
||||
int btn_next_ = PV_ID_NUL;
|
||||
|
||||
// 页面跳转按钮
|
||||
int btn_gopage_ = PV_ID_NUL;
|
||||
|
||||
// 页码列表(最多显示6个页码按钮,前3页和后3页) <按钮ID, 页码>
|
||||
std::vector<pair<int, int>> vec_btn_page_;
|
||||
|
||||
function<void(int)> cb_goto_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
class PvPageTable :public PvObject
|
||||
{
|
||||
public:
|
||||
PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts);
|
||||
|
||||
shared_ptr<PvTable> getTable();
|
||||
|
||||
private:
|
||||
shared_ptr<PvTable> table_ = nullptr;
|
||||
shared_ptr<PvPagination> page_ctrl_ = nullptr;
|
||||
};
|
||||
|
||||
#endif // ! _PvTable_H_
|
||||
Reference in New Issue
Block a user