mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现系统管理表格操作接口、分页操作
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include "PvPopWidget.h"
|
||||
|
||||
PvPopWidget::PvPopWidget(PARAM* p, int width, int height) : PvObject(p), width(width), height(height)
|
||||
const std::string POP_OPER_NEW = "新增";
|
||||
const std::string POP_OPER_EDIT = "编辑";
|
||||
const std::string POP_OPER_DEL = "删除";
|
||||
|
||||
PvPopWidget::PvPopWidget(PARAM* p, int width, int height, std::string name)
|
||||
: PvObject(p), width(width), height(height), name(name)
|
||||
{
|
||||
pvid = PvApp::widget(p, PV_ID_MAIN, 0, 0, 1920, 1080);
|
||||
PvApp::label(p, pvid, 0, 0, 1920, 1080, "", "background-color: rgba(30,30,30,180);");
|
||||
@@ -12,62 +17,97 @@ PvPopWidget::PvPopWidget(PARAM* p, int width, int height) : PvObject(p), width(w
|
||||
PvApp::label(p, ui.widget, 0, 0, 60, height, "", "background-color: transparent; border: 0 solid rgb(42, 149, 245); border-width: 5px 0 5px 5px;");
|
||||
PvApp::label(p, ui.widget, width-60, 0, 60, height, "", "background-color: transparent; border: 0 solid rgb(42, 149, 245); border-width: 5px 5px 5px 0;");
|
||||
|
||||
ui.title = PvApp::label(p, ui.widget, 20, 10, width-20, 30, "", "font: bold 20px;");
|
||||
PvApp::label(p, ui.widget, 20, 40, width*0.5-20, 3, "", QSS_UNDERLINE);
|
||||
ui.title = PvApp::label(p, ui.widget, 20, 10, width-20, 30, name, qss::label(20));
|
||||
PvApp::label(p, ui.widget, 20, 40, width*0.5-20, 3, "", qss::QSS_UNDERLINE);
|
||||
{
|
||||
int w = 100, h = 40, offset = 50;
|
||||
int x = (width- w*2 - offset) *0.5;
|
||||
int y = height - h - 40;
|
||||
|
||||
int btnOk = PvApp::button(p, ui.widget, x, y, w, h, "确定", QSS_BTN_CONFIRM);
|
||||
int btnOk = PvApp::button(p, ui.widget, x, y, w, h, "确定", qss::BTN_CONFIRM);
|
||||
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnOk, [=](std::string) {
|
||||
this->show(false);
|
||||
if (callbackConfirm) { callbackConfirm(); }
|
||||
});
|
||||
int btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", QSS_BTN_CANCEL);
|
||||
int btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", qss::BTN_CANCEL);
|
||||
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnCancel, [=](std::string) {
|
||||
this->show(false);
|
||||
});
|
||||
}
|
||||
|
||||
ui.msg = PvApp::label(p, ui.widget, 50, height-110, width-100, 24, "", qss::label(14, "red"));
|
||||
}
|
||||
|
||||
std::shared_ptr<PvPopWidget::ParamLine> PvPopWidget::addParamLine(std::string type, std::string key, std::string title, int x, int y, bool editable/* = true*/)
|
||||
{
|
||||
auto line = std::make_shared<ParamLine>(type, key);
|
||||
mapLines[key] = line;
|
||||
|
||||
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, qss::label(15));
|
||||
if (type == "lineEdit")
|
||||
{
|
||||
line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, "");
|
||||
}
|
||||
else if (type == "combox")
|
||||
{
|
||||
line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, {});
|
||||
}
|
||||
else if (type == "textEdit")
|
||||
{
|
||||
line->widget = PvApp::textEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight*4, "");
|
||||
}
|
||||
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
|
||||
line->val = text;
|
||||
});
|
||||
if (!editable) { pvSetEnabled(p, line->widget, 0); }
|
||||
return line;
|
||||
}
|
||||
|
||||
void PvPopWidget::addParamLineEdit(std::string key, std::string title, int x, int y, bool editable/*= true*/)
|
||||
{
|
||||
auto line = std::make_shared<ParamLine>("lineEdit", key);
|
||||
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, "font: bold 14px;");
|
||||
line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, "");
|
||||
if (!editable) { pvSetEnabled(p, line->widget, 0); }
|
||||
mapLines[key] = line;
|
||||
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
|
||||
line->val = text;
|
||||
});
|
||||
this->addParamLine("lineEdit", key, title, x, y, editable);
|
||||
}
|
||||
|
||||
void PvPopWidget::addParamTextEdit(std::string key, std::string title, int x, int y, bool editable/* = true*/)
|
||||
{
|
||||
this->addParamLine("textEdit", key, title, x, y, editable);
|
||||
}
|
||||
|
||||
void PvPopWidget::addParamCombox(std::string key, std::string title, int x, int y, std::vector<std::string> items)
|
||||
{
|
||||
auto line = std::make_shared<ParamLine>("combox", key);
|
||||
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, "font: bold 14px;");
|
||||
line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, items);
|
||||
mapLines[key] = line;
|
||||
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
|
||||
line->val = text;
|
||||
});
|
||||
auto line = this->addParamLine("combox", key, title, x, y, true);
|
||||
line->items = items;
|
||||
for (int i = 0; i<items.size(); ++i)
|
||||
{
|
||||
pvInsertItem(p, line->widget, i, NULL, items[i].c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PvPopWidget::setParamText(std::shared_ptr<ParamLine> line, std::string text)
|
||||
{
|
||||
if (line->type == "lineEdit")
|
||||
line->val = text;
|
||||
if (line->type == "combox")
|
||||
{
|
||||
pvSetText(p, line->widget, text.c_str());
|
||||
}
|
||||
else if (line->type == "combox")
|
||||
{
|
||||
int index = 0;
|
||||
for (int i = 0; i<line->items.size(); ++i)
|
||||
int index = -1;
|
||||
for (int i = 0; i<line->items.size(); ++i)
|
||||
{
|
||||
if (line->items[i] == text) { index = i; break; }
|
||||
if (line->items[i] == text)
|
||||
{
|
||||
line->val = line->items[i];
|
||||
pvSetCurrentItem(p, line->widget, i);
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pvSetCurrentItem(p, line->widget, index);
|
||||
if (index == -1 && line->items.size() > 0)
|
||||
{
|
||||
line->val = line->items[0];
|
||||
pvSetCurrentItem(p, line->widget, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pvClear(p, line->widget);
|
||||
pvSetText(p, line->widget, text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,34 +120,78 @@ void PvPopWidget::setParamText(std::string key, std::string text)
|
||||
}
|
||||
}
|
||||
|
||||
void PvPopWidget::setTitle(std::string title)
|
||||
void PvPopWidget::setStatus(std::string text)
|
||||
{
|
||||
pvSetText(p, ui.title, title.c_str());
|
||||
status = text;
|
||||
if (!name.empty()) text = name + "-" + text;
|
||||
pvSetText(p, ui.title, text.c_str());
|
||||
}
|
||||
|
||||
void PvPopWidget::setData(DataFields fields)
|
||||
void PvPopWidget::setMsg(std::string msg)
|
||||
{
|
||||
pvSetText(p, ui.msg, msg.c_str());
|
||||
}
|
||||
|
||||
void PvPopWidget::setData(const Fields& fields)
|
||||
{
|
||||
dataOrigin = fields;
|
||||
for (auto iter = mapLines.begin(); iter != mapLines.end(); ++iter)
|
||||
{
|
||||
auto& line = iter->second;
|
||||
this->setParamText(line, fields.getStr(line->key));
|
||||
this->setParamText(line, dataOrigin.value(line->key));
|
||||
}
|
||||
}
|
||||
|
||||
DataFields PvPopWidget::getData()
|
||||
Fields PvPopWidget::getData()
|
||||
{
|
||||
DataFields fields;
|
||||
for (auto iter = mapLines.begin(); iter!=mapLines.end(); ++iter)
|
||||
Fields fields;
|
||||
for (auto it = mapLines.begin(); it!=mapLines.end(); ++it)
|
||||
{
|
||||
auto& line = iter->second;
|
||||
fields.set(line->key, line->val);
|
||||
fields.set(it->second->key, it->second->val);
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
Fields PvPopWidget::getChangedData()
|
||||
{
|
||||
Fields fields;
|
||||
for (auto it = mapLines.begin(); it!=mapLines.end(); ++it)
|
||||
{
|
||||
auto& key = it->second->key;
|
||||
auto& val = it->second->val;
|
||||
if (primaryKeys.hasKey(key) || val != dataOrigin.value(key))
|
||||
{
|
||||
fields.set(key, val);
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
void PvPopWidget::checkChangedData(Fields& fields)
|
||||
{
|
||||
auto& mapItems = fields.map();
|
||||
for (auto it = mapItems.begin(); it!= mapItems.end(); ++it)
|
||||
{
|
||||
auto& key = it->first;
|
||||
auto& val = it->second;
|
||||
if (!primaryKeys.hasKey(key) && val == dataOrigin.value(key))
|
||||
{
|
||||
mapItems.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PvPopWidget::setLineGeometry(int wKey, int wVal, int h)
|
||||
{
|
||||
lineKeyWidth = wKey;
|
||||
lineValWidth = wVal;
|
||||
lineHeight = h;
|
||||
}
|
||||
|
||||
void PvPopWidget::setPrimaryKeys(std::vector<std::string> keys)
|
||||
{
|
||||
for (auto& k : keys)
|
||||
{
|
||||
primaryKeys.set(k, "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user