mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现策略配置功能
This commit is contained in:
@@ -9,57 +9,56 @@ static const string STYLE_BKG =
|
||||
|
||||
//*********************************************************************************************************************
|
||||
// PvTable
|
||||
PvTable::PvTable(PARAM* p, int parent, int x, int y, int w, int row, Options& opts)
|
||||
PvTable::PvTable(PARAM* p, int parent, int x, int y, int w, int irow, Options& opts)
|
||||
//: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* row + (opts.show_header ? (opts.header_height) : 0))),
|
||||
: PvObject(p), option_(opts), nRow_(row), nCol_(0)
|
||||
: PvObject(p), option(opts), nrow(irow), ncol(0)
|
||||
{
|
||||
// 计算表格的显示区域
|
||||
int h = opts.row_height* row + (opts.show_header ? (opts.head_height) : 0);
|
||||
rect_.set(x, y, w, h);
|
||||
int h = opts.row_height* irow + (opts.show_header ? (opts.head_height) : 0);
|
||||
rect.set(x, y, w, h);
|
||||
// 表格的主窗体(QWidget设置样式无效)
|
||||
pvid_ = PvApp::widget(p, parent, x, y, w, h+1);
|
||||
pvid = PvApp::widget(p, parent, x, y, w, h+1);
|
||||
// 表格的背景色和边框样式
|
||||
|
||||
PvApp::label(p, pvid_, 0, 0, w, h+1, "", qss::QSS_TABLE);
|
||||
PvApp::label(p, pvid, 0, 0, w, h+1, "", qss::QSS_TABLE);
|
||||
|
||||
vecHead_.resize(0);
|
||||
vecRows_.resize(nRow_);
|
||||
vecData_.resize(nRow_);
|
||||
vecHeads.resize(0);
|
||||
vecRows.resize(nrow);
|
||||
vecData.resize(nrow);
|
||||
|
||||
// 创建行高亮显示背景
|
||||
for (int row = 0; row < nRow_; row++)
|
||||
for (int row = 0; row < nrow; row++)
|
||||
{
|
||||
int y = item_posy(row);
|
||||
int y = row * option.row_height + (option.show_header ? option.head_height : 0);
|
||||
string qss = (row % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1;
|
||||
int rowBkg = PvApp::label(p, pvid_, 1, y, rect_.w-2, option_.row_height, "", qss);
|
||||
pvHide(p, rowBkg);
|
||||
vecRows_[row].bkg = rowBkg;
|
||||
int widgetRow = PvApp::label(p, pvid, 1, y, rect.w-2, option.row_height, "", qss);
|
||||
pvHide(p, widgetRow);
|
||||
vecRows[row].widget = widgetRow;
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::addHead(string id, string text, int width, vector<pair<string, string>> mapping)
|
||||
{
|
||||
vecHead_.push_back(Head(id, text, width, mapping));
|
||||
nCol_ = vecHead_.size();
|
||||
vecHeads.push_back(Head(id, text, width, mapping));
|
||||
ncol = vecHeads.size();
|
||||
|
||||
if (width <= -1) { width = rect_.w-1 - posCol_; }
|
||||
int col = nCol_ - 1;
|
||||
if (width <= -1) { width = rect.w-1 - posCol; }
|
||||
int col = ncol - 1;
|
||||
|
||||
// 创建表头的标签
|
||||
if (option_.show_header)
|
||||
if (option.show_header)
|
||||
{
|
||||
vecHead_[col].pvid = PvApp::label(p, pvid_, posCol_, 0, width, option_.head_height, text, qss::QSS_TABLE_HEAD);
|
||||
vecHeads[col].pvid = PvApp::label(p, pvid, posCol, 0, width, option.head_height, text, qss::QSS_TABLE_HEAD);
|
||||
}
|
||||
|
||||
// 创建列的单元格
|
||||
for (int row = 0; row < nRow_; ++row)
|
||||
for (int row = 0; row < nrow; ++row)
|
||||
{
|
||||
int y = item_posy(row);
|
||||
int pvid = PvApp::label(p, pvid_, posCol_, y, width, option_.row_height, "", qss::QSS_TABLE_CELL);
|
||||
vecRows_[row].vecCells.push_back(pvid);
|
||||
PvApp::bind(p, MOUSE_OVER_EVENT, pvid, [=](string s) { highlight(row, (s == "1")); });
|
||||
int cellId = PvApp::label(p, vecRows[row].widget, posCol, 0, width, option.row_height, "", qss::QSS_TABLE_CELL);
|
||||
vecRows[row].vecCells.push_back(cellId);
|
||||
PvApp::bind(p, MOUSE_OVER_EVENT, cellId, [=](string s) { highlight(row, (s == "1")); });
|
||||
}
|
||||
posCol_ += width;
|
||||
posCol += width;
|
||||
}
|
||||
|
||||
void PvTable::addHead(vector<string> vec_text)
|
||||
@@ -68,24 +67,24 @@ void PvTable::addHead(vector<string> vec_text)
|
||||
int x = 0;
|
||||
for (int i = 0; i < vec_text.size(); ++i)
|
||||
{
|
||||
int w = float(rect_.w-1) * float(i+1) / float(colSize);
|
||||
int w = float(rect.w-1) * float(i+1) / float(colSize);
|
||||
string text = vec_text[i];
|
||||
this->addHead(text, text, w-x);
|
||||
x = w;
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::setRowVisible(int row, bool v)
|
||||
void PvTable::setRowVisible(int irow, bool v)
|
||||
{
|
||||
if (row < 0 || row >= vecRows_.size())
|
||||
if (irow < 0 || irow >= vecRows.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
auto& rowItem = vecRows_[row];
|
||||
auto& rowItem = vecRows[irow];
|
||||
if (rowItem.visible != v)
|
||||
{
|
||||
rowItem.visible = v;
|
||||
rowItem.visible ? pvShow(p, rowItem.bkg) : pvHide(p, rowItem.bkg);
|
||||
rowItem.visible ? pvShow(p, rowItem.widget) : pvHide(p, rowItem.widget);
|
||||
if (!v)
|
||||
{
|
||||
for (int col = 0; col<rowItem.vecCells.size(); ++col)
|
||||
@@ -96,31 +95,28 @@ void PvTable::setRowVisible(int row, bool v)
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::highlight(int row, bool v)
|
||||
void PvTable::highlight(int irow, bool v)
|
||||
{
|
||||
string qss = ((row % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1);
|
||||
if (vecRows_.size() > 0 && row <= vecRows_.size())
|
||||
string qss = ((irow % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1);
|
||||
if (vecRows.size() > 0 && irow <= vecRows.size())
|
||||
{
|
||||
if (v) { qss = "background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; }
|
||||
pvSetStyleSheet(p, vecRows_[row].bkg, qss.c_str());
|
||||
pvSetStyleSheet(p, vecRows[irow].widget, qss.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::addOperate(vector<string> vecOpt)
|
||||
{
|
||||
// 创建表头的标签
|
||||
if (option_.show_header)
|
||||
if (option.show_header)
|
||||
{
|
||||
PvApp::label(p, pvid_, posCol_, 0, rect_.w - posCol_, option_.head_height, "操作", qss::QSS_TABLE_HEAD);
|
||||
PvApp::label(p, pvid, posCol, 0, rect.w - posCol, option.head_height, "操作", qss::QSS_TABLE_HEAD);
|
||||
}
|
||||
for (int row = 0; row < nRow_; ++row)
|
||||
for (int row = 0; row < nrow; ++row)
|
||||
{
|
||||
int y = item_posy(row);
|
||||
int cellWidget = PvApp::label(p, pvid_, posCol_, y, rect_.w - posCol_, option_.row_height, "", qss::QSS_TABLE_CELL);
|
||||
//PvInstance::bind_event(p, MOUSE_OVER_EVENT, btn_opt, [=](string s) { highlight(row, (s == "1")); });
|
||||
vecOpt_.push_back({ cellWidget, vector<int>() });
|
||||
auto& vec_opt_btn_ = vecOpt_.back().second;
|
||||
|
||||
int cellWidget = PvApp::label(p, vecRows[row].widget, posCol, 0, rect.w - posCol, option.row_height, "", qss::QSS_TABLE_CELL);
|
||||
vecOper.push_back({ cellWidget, vector<int>() });
|
||||
auto& vec_opt_btn_ = vecOper.back().second;
|
||||
int x = 5, w = 60;
|
||||
for (int i = 0; i < vecOpt.size(); i++)
|
||||
{
|
||||
@@ -128,87 +124,66 @@ void PvTable::addOperate(vector<string> vecOpt)
|
||||
w = 20 + 15 * title.size() / 3;
|
||||
int btn = PvApp::button(p, cellWidget, x, 4, w, 24, title, qss::button(14, "", "", "none; border-radius: 0px"));
|
||||
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
|
||||
if (cbOperate_) { cbOperate_(row, 0, title); }
|
||||
if (callbackOper) { callbackOper(row, 0, title); }
|
||||
});
|
||||
vec_opt_btn_.push_back(btn);
|
||||
x += (w + 5);
|
||||
}
|
||||
pvHide(p, cellWidget);
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::setOperateCallback(CallbackTableOpt cb)
|
||||
{
|
||||
cbOperate_ = cb;
|
||||
callbackOper = cb;
|
||||
};
|
||||
|
||||
void PvTable::set_text(PARAM* p, int row, int col, string text, string style)
|
||||
void PvTable::setRow(int irow, Fields& d)
|
||||
{
|
||||
if (row < nRow_ && col < nCol_)
|
||||
if (irow >= nrow) { return; }
|
||||
|
||||
vecData[irow] = d;
|
||||
for (int col = 0; col < vecHeads.size(); ++col)
|
||||
{
|
||||
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
|
||||
if (!style.empty())
|
||||
{
|
||||
int idx = row + 1;
|
||||
if (idx % 2 != 0)
|
||||
{
|
||||
style = item_base_style_ + style;
|
||||
}
|
||||
else
|
||||
{
|
||||
style = item_base_style_ + style;
|
||||
}
|
||||
|
||||
//style = "qproperty-alignment:AlignCenter;" + style + "}";
|
||||
string s = "QLabel{" + style + "} QLabel:disabled{color:rgb(150,150,150)}";
|
||||
pvSetStyleSheet(p, vecRows_[row].vecCells[col], s.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::setRowData(int row, Fields& d)
|
||||
{
|
||||
if (row >= nRow_) { return; }
|
||||
|
||||
vecData_[row] = d;
|
||||
for (int col = 0; col < vecHead_.size(); ++col)
|
||||
{
|
||||
auto& head = vecHead_[col];
|
||||
auto& head = vecHeads[col];
|
||||
string text = d.value(head.id);
|
||||
text = head.getMapping(text);
|
||||
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
|
||||
pvSetText(p, vecRows[irow].vecCells[col], text.c_str());
|
||||
}
|
||||
setRowVisible(row, true);
|
||||
this->setOperateVisible(row, d.size() > 0);
|
||||
setRowVisible(irow, true);
|
||||
}
|
||||
|
||||
void PvTable::setRowData(int row, std::vector<std::string> vd)
|
||||
void PvTable::setRow(int irow, std::vector<std::string> vd)
|
||||
{
|
||||
if (row >= nRow_) { return; }
|
||||
pvShow(p, vecRows_[row].bkg);
|
||||
for (int col = 0; col < vecHead_.size(); ++col)
|
||||
if (irow >= nrow) { return; }
|
||||
pvShow(p, vecRows[irow].widget);
|
||||
for (int col = 0; col < vecHeads.size(); ++col)
|
||||
{
|
||||
if (col < vd.size()) {
|
||||
auto& head = vecHead_[col];
|
||||
auto& head = vecHeads[col];
|
||||
string text = head.getMapping(vd[col]);
|
||||
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
|
||||
pvSetText(p, vecRows[irow].vecCells[col], text.c_str());
|
||||
}
|
||||
}
|
||||
setRowVisible(row, true);
|
||||
this->setOperateVisible(row, vd.size() > 0);
|
||||
setRowVisible(irow, true);
|
||||
}
|
||||
|
||||
Fields PvTable::getRowData(int row)
|
||||
Fields PvTable::row(int irow)
|
||||
{
|
||||
static Fields tmp;
|
||||
return (row >= 0 && row < vecData_.size()) ? vecData_[row] : tmp;
|
||||
return (irow >= 0 && irow < vecData.size()) ? vecData[irow] : Fields();
|
||||
}
|
||||
|
||||
Fields PvTable::rowMapping(int rowid)
|
||||
{
|
||||
Fields d = this->row(rowid);
|
||||
this->mappingData(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
void PvTable::mappingData(Fields& fields)
|
||||
{
|
||||
for (int i=0; i< vecHead_.size(); ++i)
|
||||
for (int i=0; i< vecHeads.size(); ++i)
|
||||
{
|
||||
auto& head = vecHead_[i];
|
||||
auto& head = vecHeads[i];
|
||||
if (fields.contains(head.id))
|
||||
{
|
||||
auto& val = fields.value(head.id);
|
||||
@@ -217,82 +192,23 @@ void PvTable::mappingData(Fields& fields)
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::set_border_visible(PARAM* p, bool v)
|
||||
int PvTable::rowCount()
|
||||
{
|
||||
v ? pvShow(p, border_id_) : pvHide(p, border_id_);
|
||||
return this->nrow;
|
||||
}
|
||||
|
||||
int PvTable::item_posy(int row)
|
||||
int PvTable::colCount()
|
||||
{
|
||||
return option_.show_header ? row * option_.row_height + option_.head_height : row * option_.row_height;
|
||||
}
|
||||
|
||||
void PvTable::add_col_button(PARAM* p, int col, string title, PvRect& rt, string style)
|
||||
{
|
||||
if (col >= nCol_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int row = 0; row < nRow_; ++row)
|
||||
{
|
||||
int id = PvApp::button(p, vecRows_[row].vecCells[col], rt.x, rt.y, rt.w, rt.h, title, style);
|
||||
pvHide(p, id);
|
||||
vec_col_item_btn_[row].push_back(id);
|
||||
//PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s)
|
||||
//{
|
||||
// if (cb_operate_)
|
||||
// {
|
||||
// cb_operate_(row, col, title);
|
||||
// }
|
||||
//});
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::add_col_button(PARAM* p, int col, vector<string> vec_title)
|
||||
{
|
||||
int x = 5;
|
||||
int w = 0;
|
||||
for (int i = 0; i < vec_title.size(); i++)
|
||||
{
|
||||
auto& title = vec_title[i];
|
||||
w = 20 + 20 * title.size() / 3;
|
||||
this->add_col_button(p, col, title, PvRect(x, 3, w, 28), qss::button());
|
||||
x += (w + 5);
|
||||
}
|
||||
}
|
||||
|
||||
void PvTable::setOperateVisible(int row, bool v, int id)
|
||||
{
|
||||
if (row < vecOpt_.size())
|
||||
{
|
||||
auto& vec_opt_btn = vecOpt_[row].second;
|
||||
int pvid = id < 0 ? vecOpt_[row].first : ((id < vec_opt_btn.size()) ? vec_opt_btn[id] : PV_ID_NUL);
|
||||
v ? pvShow(p, pvid) : pvHide(p, pvid);
|
||||
}
|
||||
}
|
||||
|
||||
int PvTable::border_id()
|
||||
{
|
||||
return border_id_;
|
||||
}
|
||||
|
||||
int PvTable::rows()
|
||||
{
|
||||
return nRow_;
|
||||
}
|
||||
int PvTable::colums()
|
||||
{
|
||||
return nCol_;
|
||||
return this->ncol;
|
||||
}
|
||||
|
||||
vector<Fields> PvTable::data()
|
||||
{
|
||||
return vecData_;
|
||||
return vecData;
|
||||
}
|
||||
|
||||
PvTable::Head& PvTable::header(int col)
|
||||
{
|
||||
return vecHead_[col];
|
||||
return vecHeads[col];
|
||||
}
|
||||
|
||||
static const string STYLE_NORMAL =
|
||||
@@ -348,32 +264,6 @@ void PvPagination::setPage(int index, int count)
|
||||
else
|
||||
{
|
||||
pvShow(p, btnid);
|
||||
//if (pageCount > 7)
|
||||
//{
|
||||
// if (idx == 4)
|
||||
// {
|
||||
// idx = 0;
|
||||
// }
|
||||
// else if (idx > 4)
|
||||
// {
|
||||
// idx = pageCount - (7 - idx);
|
||||
// }
|
||||
//}
|
||||
//btn.second = idx;
|
||||
//string text = to_string(idx);
|
||||
//if (text.empty() || text == "0")
|
||||
//{
|
||||
// text = "...";
|
||||
// pvSetEnabled(p, btnid, false);
|
||||
//}
|
||||
////pvMove(p, btnid, x, y);
|
||||
//pvSetText(p, btnid, text.c_str());
|
||||
//if (idx == idx)
|
||||
//{
|
||||
// this->active_page_button(p, idx, pageIndex);
|
||||
// pageIndex = idx;
|
||||
//}
|
||||
//x += (32);
|
||||
}
|
||||
}
|
||||
int x = (count+1)*32;
|
||||
@@ -424,7 +314,10 @@ void PvPagination::setCallback(std::function<void(int index)> func)
|
||||
PageTable::PageTable(PARAM* p) : PvMask(p)
|
||||
{
|
||||
table = std::make_shared<PvTable>(p, 0, 20, 210, 1880, pageSize, option);
|
||||
table->setOperateCallback([=](int row, int col, std::string text) { this->onOperate(row, col, text); });
|
||||
table->setOperateCallback([=](int irow, int icol, std::string text) {
|
||||
curRowData = table->row(irow);
|
||||
this->onOperate(irow, icol, text);
|
||||
});
|
||||
|
||||
pagination = std::make_shared<PvPagination>(p, 0, 20, 780, 20);
|
||||
pagination->setCallback([=](int index)
|
||||
@@ -464,7 +357,7 @@ std::shared_ptr<PvPopWidget> PageTable::addPop(int w, int h, int w0, std::string
|
||||
vecPop.push_back(pop);
|
||||
return pop;
|
||||
}
|
||||
void PageTable::showPop(int index, std::string oper, Fields& fields)
|
||||
void PageTable::showPop(int index, std::string oper, Fields fields)
|
||||
{
|
||||
XLOGD() << "POP set: data=" << fields.toStr();
|
||||
table->mappingData(fields);
|
||||
@@ -492,12 +385,12 @@ void PageTable::updateDataFromDB()
|
||||
pageInfo.size = pageSize;
|
||||
pageInfo.index = pageIndex;
|
||||
this->onQueryTable(pageInfo, result);
|
||||
for (int i = 0; i<table->rows(); ++i)
|
||||
for (int i = 0; i<table->rowCount(); ++i)
|
||||
{
|
||||
if (i<result.size())
|
||||
{
|
||||
auto& fields = result[i];
|
||||
table->setRowData(i, result[i]);
|
||||
table->setRow(i, result[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user