实现策略配置功能

This commit is contained in:
lixiaoyuan
2025-08-28 18:42:37 +08:00
parent 8f6c83147b
commit dda905cda0
47 changed files with 1311 additions and 863 deletions

View File

@@ -5,6 +5,72 @@
#define FONT_NAME "微软雅黑"
PvRect::PvRect()
{
}
PvRect::PvRect(int ix, int iy, int iw, int ih)
: x(ix), y(iy), w(iw), h(ih)
{
}
PvRect& PvRect::set(int ix, int iy, int iw, int ih)
{
x = ix;
y = iy;
w = iw;
h = ih;
return *this;
}
PvRect& PvRect::setx(int ix)
{
x = ix;
return *this;
}
PvRect& PvRect::sety(int iy)
{
y = iy;
return *this;
}
PvRect& PvRect::setw(int iw)
{
w = iw;
return *this;
}
PvRect& PvRect::seth(int ih)
{
h = ih;
return *this;
}
PvRect& PvRect::shiftx(int ix)
{
x += ix;
return *this;
}
PvRect& PvRect::shifty(int iy)
{
y += iy;
return *this;
}
PvRect& PvRect::shiftw(int iw)
{
w += iw;
return *this;
}
PvRect& PvRect::shifth(int ih)
{
h += ih;
return *this;
}
void PvApp::setPvUser(PARAM* p, PvUser* pvuser)
{
p->user = pvuser;
@@ -23,10 +89,8 @@ int PvApp::pvid(PARAM* p)
void PvApp::reset(PARAM* p)
{
// 清理event回调
auto pvuser = PvApp::getPvUser(p);
pvuser->mapEventCallback.clear();
pvuser->pvidIndex = 0;
if (pvuser) { pvuser->reset(); }
}
EPvCode PvApp::getPvCode(std::string name)
@@ -64,7 +128,6 @@ EPvCode PvApp::getPvCode(std::string name)
}
}
void PvApp::bind(PARAM* p, PvEvent eid, int pvid, std::function<void(std::string text)> cb)
{
auto pvuser = PvApp::getPvUser(p);
@@ -99,13 +162,22 @@ int PvApp::widget(PARAM* p, int parent, int x, int y, int w, int h)
int PvApp::label(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
static const std::string style = "QLabel { border: none; background-color: transparent; } QLabel:disabled { color: gray;}";
int id = PvApp::pvid(p);
pvQLabel(p, id, parent);
pvSetGeometry(p, id, x, y, w, h);
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
pvSetStyleSheet(p, id, qss.empty() ? qss::label().c_str() : qss.c_str());
pvSetStyleSheet(p, id, qss.empty() ? style.c_str() : qss.c_str());
return id;
}
int PvApp::labelCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
int id = PvApp::label(p, parent, x, y, w, h, text, qss);
pvSetAlignment(p, id, AlignCenter);
return id;
}
int PvApp::labelAlignCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
int id = PvApp::label(p, parent, x, y, w, h, text, qss);
@@ -128,7 +200,6 @@ int PvApp::image(PARAM* p, int parent, int x, int y, int w, int h, const char* f
int id = PvApp::pvid(p);
pvQImage(p, id, parent, filename);
pvSetGeometry(p, id, x, y, w, h);
//if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); }
return id;
}
@@ -147,7 +218,7 @@ int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::v
return id;
}
int PvApp::lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
int PvApp::textedit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
int id = PvApp::pvid(p);
pvQLineEdit(p, id, parent);
@@ -157,11 +228,11 @@ int PvApp::lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::strin
return id;
}
int PvApp::textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
int PvApp::multiTextedit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
static std::string style =
"QTextEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}"
"QTextEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}";
"QTextEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 3px; color:white; font: bold 14px;}"
"QTextEdit:disabled { border: none; color: gray;}";
int id = PvApp::pvid(p);
pvQMultiLineEdit(p, id, parent, true, 10);
pvSetGeometry(p, id, x, y, w, h);
@@ -174,7 +245,7 @@ int PvApp::radioButton(PARAM* p, int parent, int x, int y, int w, int h, std::st
{
static std::string style =
"QRadioButton { background-color: transparent; color:white; font: bold 14px \"微软雅黑\";}"
"QRadioButton:disabled { border: none; color:rgb(150,150,150);}";
"QRadioButton:disabled { border: none; color: gray;}";
int id = PvApp::pvid(p);
pvQRadioButton(p, id, parent);
@@ -188,7 +259,7 @@ int PvApp::timeEdit(PARAM* p, int parent, int x, int y, int w, int h)
{
static std::string style =
"QTimeEdit { background-color: rgb(17, 55, 73); border: 1px solid rgb(0, 185, 208); color:white; font: normal 14px \"微软雅黑\";}"
"QTimeEdit:disabled { border: none; color:rgb(150,150,150);}";
"QTimeEdit:disabled { border: none; color: gray;}";
int id = PvApp::pvid(p);
pvQTimeEdit(p, id, parent);
@@ -197,67 +268,15 @@ int PvApp::timeEdit(PARAM* p, int parent, int x, int y, int w, int h)
return id;
}
PvRect::PvRect()
int PvApp::lineLabel(PARAM* p, int parent, PvRect& rect, int w, std::string key, std::string val)
{
int pid = PvApp::label(p, parent, rect.x, rect.y, rect.w, rect.h, key, qss::label(14));
return PvApp::label(p, pid, w, 0, rect.w-w, rect.h, val);
}
PvRect::PvRect(int ix, int iy, int width, int height)
: x(ix), y(iy), w(width), h(height)
int PvApp::lineTextedit(PARAM* p, int parent, PvRect& rect, int w, std::string key, std::string val)
{
int pid = PvApp::label(p, parent, rect.x, rect.y, rect.w, rect.h, key, qss::label(14));
return PvApp::textedit(p, pid, w, 0, rect.w-w, rect.h, val);
}
PvRect& PvRect::set(int ix, int iy, int width, int height)
{
x = ix;
y = iy;
w = width;
h = height;
return *this;
}
PvRect& PvRect::set_x(int ix)
{
x = ix;
return *this;
}
PvRect& PvRect::set_y(int iy)
{
y = iy;
return *this;
}
PvRect& PvRect::set_w(int iw)
{
w = iw;
return *this;
}
PvRect& PvRect::set_h(int ih)
{
h = ih;
return *this;
}
PvRect& PvRect::shift_x(int ix)
{
x += ix;
return *this;
}
PvRect& PvRect::shift_y(int iy)
{
y += iy;
return *this;
}
PvRect& PvRect::shift_w(int iw)
{
w += iw;
return *this;
}
PvRect& PvRect::shift_h(int ih)
{
h += ih;
return *this;
}