2025-08-20 19:00:22 +08:00
|
|
|
|
#include "PvPopWidget.h"
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
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)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
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);");
|
|
|
|
|
|
|
|
|
|
|
|
int x = (1920-width) *0.5;
|
|
|
|
|
|
int y = (1080-height) *0.5;
|
|
|
|
|
|
ui.widget = PvApp::widget(p, pvid, x, y, width, height);
|
2025-08-28 18:42:37 +08:00
|
|
|
|
ui.bkg = PvApp::label(p, ui.widget, 2, 2, width-4, height-4, "", "background-color: rgb(12,39,58); border: 1px solid rgb(31,145,156);");
|
|
|
|
|
|
ui.bkgL = 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;");
|
|
|
|
|
|
ui.bkgR = 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;");
|
2025-08-20 19:00:22 +08:00
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
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);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
int w = 100, h = 40, offset = 50;
|
|
|
|
|
|
int x = (width- w*2 - offset) *0.5;
|
|
|
|
|
|
int y = height - h - 40;
|
|
|
|
|
|
|
2025-08-28 18:42:37 +08:00
|
|
|
|
ui.btnOK = PvApp::button(p, ui.widget, x, y, w, h, "确定", qss::BTN_CONFIRM);
|
|
|
|
|
|
PvApp::bind(p, PvEvent::BUTTON_EVENT, ui.btnOK, [=](std::string) {
|
2025-08-20 19:00:22 +08:00
|
|
|
|
if (callbackConfirm) { callbackConfirm(); }
|
|
|
|
|
|
});
|
2025-08-28 18:42:37 +08:00
|
|
|
|
ui.btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", qss::BTN_CANCEL);
|
|
|
|
|
|
PvApp::bind(p, PvEvent::BUTTON_EVENT, ui.btnCancel, [=](std::string) {
|
2025-08-20 19:00:22 +08:00
|
|
|
|
this->show(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-08-22 19:06:50 +08:00
|
|
|
|
|
|
|
|
|
|
ui.msg = PvApp::label(p, ui.widget, 50, height-110, width-100, 24, "", qss::label(14, "red"));
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
std::shared_ptr<PvPopWidget::ParamLine> PvPopWidget::addParamLine(std::string type, std::string key, std::string title, int x, int y, bool editable/* = true*/)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
auto line = std::make_shared<ParamLine>(type, key);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
mapLines[key] = line;
|
2025-08-22 19:06:50 +08:00
|
|
|
|
|
|
|
|
|
|
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, qss::label(15));
|
2025-08-28 18:42:37 +08:00
|
|
|
|
if (type == "textedit")
|
2025-08-22 19:06:50 +08:00
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
line->widget = PvApp::textedit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, "");
|
2025-08-22 19:06:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (type == "combox")
|
|
|
|
|
|
{
|
|
|
|
|
|
line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, {});
|
|
|
|
|
|
}
|
2025-08-28 18:42:37 +08:00
|
|
|
|
else if (type == "multiTextedit")
|
2025-08-22 19:06:50 +08:00
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
line->widget = PvApp::multiTextedit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight*4, "");
|
2025-08-22 19:06:50 +08:00
|
|
|
|
}
|
2025-08-20 19:00:22 +08:00
|
|
|
|
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
|
|
|
|
|
|
line->val = text;
|
2025-08-28 18:42:37 +08:00
|
|
|
|
if (callbackTextEvent) callbackTextEvent(key, text);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
});
|
2025-08-22 19:06:50 +08:00
|
|
|
|
if (!editable) { pvSetEnabled(p, line->widget, 0); }
|
|
|
|
|
|
return line;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void PvPopWidget::addParamLineEdit(std::string key, std::string title, int x, int y, bool editable/*= true*/)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
this->addParamLine("textedit", key, title, x, y, editable);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void PvPopWidget::addParamTextEdit(std::string key, std::string title, int x, int y, bool editable/* = true*/)
|
|
|
|
|
|
{
|
2025-08-28 18:42:37 +08:00
|
|
|
|
this->addParamLine("multiTextedit", key, title, x, y, editable);
|
2025-08-22 19:06:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PvPopWidget::addParamCombox(std::string key, std::string title, int x, int y, std::vector<std::string> items)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
auto line = this->addParamLine("combox", key, title, x, y, true);
|
|
|
|
|
|
line->items = items;
|
|
|
|
|
|
for (int i = 0; i<items.size(); ++i)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
pvInsertItem(p, line->widget, i, NULL, items[i].c_str());
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
2025-08-22 19:06:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PvPopWidget::setParamText(std::shared_ptr<ParamLine> line, std::string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
line->val = text;
|
|
|
|
|
|
if (line->type == "combox")
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
int index = -1;
|
|
|
|
|
|
for (int i = 0; i<line->items.size(); ++i)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
if (line->items[i] == text)
|
|
|
|
|
|
{
|
|
|
|
|
|
line->val = line->items[i];
|
|
|
|
|
|
pvSetCurrentItem(p, line->widget, i);
|
|
|
|
|
|
index = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (index == -1 && line->items.size() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
line->val = line->items[0];
|
|
|
|
|
|
pvSetCurrentItem(p, line->widget, 0);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
2025-08-28 18:42:37 +08:00
|
|
|
|
// 【注意】combox 设置 item 不会触发 TEXT_EVENT
|
|
|
|
|
|
//if (callbackTextEvent) callbackTextEvent(line->key, line->val);
|
2025-08-22 19:06:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
pvClear(p, line->widget);
|
|
|
|
|
|
pvSetText(p, line->widget, text.c_str());
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PvPopWidget::setParamText(std::string key, std::string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto iter = mapLines.find(key);
|
|
|
|
|
|
if (iter != mapLines.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setParamText(iter->second, text);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void PvPopWidget::setStatus(std::string text)
|
|
|
|
|
|
{
|
|
|
|
|
|
status = text;
|
|
|
|
|
|
if (!name.empty()) text = name + "-" + text;
|
|
|
|
|
|
pvSetText(p, ui.title, text.c_str());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PvPopWidget::setMsg(std::string msg)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
pvSetText(p, ui.msg, msg.c_str());
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
void PvPopWidget::setData(const Fields& fields)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
dataOrigin = fields;
|
2025-08-20 19:00:22 +08:00
|
|
|
|
for (auto iter = mapLines.begin(); iter != mapLines.end(); ++iter)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto& line = iter->second;
|
2025-08-22 19:06:50 +08:00
|
|
|
|
this->setParamText(line, dataOrigin.value(line->key));
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
Fields PvPopWidget::getData()
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
Fields fields;
|
|
|
|
|
|
for (auto it = mapLines.begin(); it!=mapLines.end(); ++it)
|
2025-08-20 19:00:22 +08:00
|
|
|
|
{
|
2025-08-22 19:06:50 +08:00
|
|
|
|
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;
|
2025-08-26 18:36:25 +08:00
|
|
|
|
if (primaryKeys.contains(key) || val != dataOrigin.value(key))
|
2025-08-22 19:06:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
fields.set(key, val);
|
|
|
|
|
|
}
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
return fields;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-22 19:06:50 +08:00
|
|
|
|
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;
|
2025-08-26 18:36:25 +08:00
|
|
|
|
if (!primaryKeys.contains(key) && val == dataOrigin.value(key))
|
2025-08-22 19:06:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
mapItems.erase(it);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 19:00:22 +08:00
|
|
|
|
void PvPopWidget::setLineGeometry(int wKey, int wVal, int h)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineKeyWidth = wKey;
|
|
|
|
|
|
lineValWidth = wVal;
|
|
|
|
|
|
lineHeight = h;
|
2025-08-22 19:06:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PvPopWidget::setPrimaryKeys(std::vector<std::string> keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto& k : keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
primaryKeys.set(k, "");
|
|
|
|
|
|
}
|
2025-08-28 18:42:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PvPopWidget::resize(int width, int height)
|
|
|
|
|
|
{
|
|
|
|
|
|
int x = (1920-width) *0.5;
|
|
|
|
|
|
int y = (1080-height) *0.5;
|
|
|
|
|
|
pvSetGeometry(p, ui.widget, x, y, width, height);
|
|
|
|
|
|
pvSetGeometry(p, ui.bkg, 2, 2, width-4, height-4);
|
|
|
|
|
|
pvSetGeometry(p, ui.bkgL, 0, 0, 60, height);
|
|
|
|
|
|
pvSetGeometry(p, ui.bkgR, width-60, 0, 60, height);
|
|
|
|
|
|
|
|
|
|
|
|
int w = 100, h = 40, offset = 50;
|
|
|
|
|
|
x = (width- w*2 - offset) *0.5;
|
|
|
|
|
|
y = height - h - 40;
|
|
|
|
|
|
pvSetGeometry(p, ui.btnOK, x, y, w, h);
|
|
|
|
|
|
pvSetGeometry(p, ui.btnCancel, x+w+offset, y, w, h);
|
2025-08-20 19:00:22 +08:00
|
|
|
|
}
|