2025-08-20 19:00:22 +08:00
|
|
|
|
#ifndef _PvTable_H_
|
|
|
|
|
|
#define _PvTable_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
|
|
#include "PvApp.h"
|
2025-08-22 19:06:50 +08:00
|
|
|
|
#include "Fields.h"
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2025-08-28 18:42:37 +08:00
|
|
|
|
int widget {PV_ID_NUL};
|
2025-08-20 19:00:22 +08:00
|
|
|
|
std::vector<int> vecCells {};
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2025-08-28 18:42:37 +08:00
|
|
|
|
PvTable(PARAM* p, int parent, int x, int y, int w, int rowCount, Options& option);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
void setRowVisible(int irow, bool v);
|
|
|
|
|
|
void highlight(int irow, bool v);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
void addOperate(std::vector<std::string> vecOpt);
|
|
|
|
|
|
void setOperateCallback(CallbackTableOpt cb);
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
void setRow(int irow, Fields& d);
|
|
|
|
|
|
void setRow(int irow, std::vector<std::string> vd);
|
|
|
|
|
|
Fields row(int irow);
|
|
|
|
|
|
Fields rowMapping(int irow);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void mappingData(Fields& fields);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
int rowCount();
|
|
|
|
|
|
int colCount();
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
std::vector<Fields> data();
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
PvTable::Head& header(int col);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2025-08-28 18:42:37 +08:00
|
|
|
|
Options option;
|
|
|
|
|
|
PvRect rect;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
std::vector<PvTable::Head> vecHeads;
|
|
|
|
|
|
std::vector<PvTable::Row> vecRows;
|
|
|
|
|
|
std::vector<Fields> vecData;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
vector<pair<int, vector<int>>> vecOper;
|
|
|
|
|
|
int nrow;
|
|
|
|
|
|
int ncol;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
int posCol = 0;
|
|
|
|
|
|
|
|
|
|
|
|
CallbackTableOpt callbackOper = nullptr;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PvPagination : public PvObject
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
2025-08-22 19:06:50 +08:00
|
|
|
|
PvPagination(PARAM* p, int parent, int x, int y, int n);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void setPage(int index, int count);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int page();
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void setCallback(std::function<void(int index)> func);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void activePage(int index, bool invoke=false);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
// 当前显示的页码索引, 从1开始
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int pageIndex = 1;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 总页数
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int pageCount = 0;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 上一页按钮
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int btnPrev = PV_ID_NUL;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 下一页按钮
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int btnNext = PV_ID_NUL;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int btnActive = PV_ID_NUL;
|
|
|
|
|
|
|
|
|
|
|
|
int labelInfo = PV_ID_NUL;
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
// 页码列表(最多显示6个页码按钮,前3页和后3页) <按钮ID, 页码>
|
2025-08-22 19:06:50 +08:00
|
|
|
|
std::vector<pair<int, int>> vecBtn;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
function<void(int)> callback = nullptr;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// === PageTable ===
|
|
|
|
|
|
class PvPopWidget;
|
|
|
|
|
|
class PageTable : public PvMask
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
2025-08-26 18:36:25 +08:00
|
|
|
|
PageTable(PARAM* p);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
void setPage(int pageIndex, int pageSize, int count) {}
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-26 18:36:25 +08:00
|
|
|
|
std::shared_ptr<PvPopWidget> addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys);
|
|
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
void showPop(int index, std::string optr, Fields fields);
|
2025-08-26 18:36:25 +08:00
|
|
|
|
void hidePop(int index);
|
|
|
|
|
|
|
|
|
|
|
|
void updateDataFromDB();
|
|
|
|
|
|
|
|
|
|
|
|
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) {}
|
|
|
|
|
|
virtual void onOperate(int row, int col, std::string oper) {};
|
|
|
|
|
|
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
|
|
|
|
|
|
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
|
|
|
|
|
|
|
|
|
|
|
|
int pageSize {15};
|
|
|
|
|
|
int pageIndex {0};
|
|
|
|
|
|
PvTable::Options option;
|
|
|
|
|
|
std::shared_ptr<PvTable> table;
|
|
|
|
|
|
std::shared_ptr<PvPagination> pagination;
|
|
|
|
|
|
std::vector<std::shared_ptr<PvPopWidget>> vecPop;
|
2025-08-28 18:42:37 +08:00
|
|
|
|
Fields curRowData;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ! _PvTable_H_
|