mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
搭建PVB架构,实现前端的基础布局、菜单、表格、图示等功能
This commit is contained in:
226
src/pv/PvApp.cpp
Normal file
226
src/pv/PvApp.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
#include "PvApp.h"
|
||||
#include "PvUser.h"
|
||||
#include "TimeUtils.h"
|
||||
|
||||
|
||||
#define FONT_NAME "微软雅黑"
|
||||
|
||||
void PvApp::setPvUser(PARAM* p, PvUser* pvuser)
|
||||
{
|
||||
p->user = pvuser;
|
||||
}
|
||||
|
||||
PvUser* PvApp::getPvUser(PARAM* p)
|
||||
{
|
||||
return static_cast<PvUser*>(p->user);
|
||||
}
|
||||
|
||||
int PvApp::pvid(PARAM* p)
|
||||
{
|
||||
auto pvuser = PvApp::getPvUser(p);
|
||||
return (++pvuser->pvidIndex);
|
||||
}
|
||||
|
||||
void PvApp::reset(PARAM* p)
|
||||
{
|
||||
// 清理event回调
|
||||
auto pvuser = PvApp::getPvUser(p);
|
||||
pvuser->mapEventCallback.clear();
|
||||
pvuser->pvidIndex = 0;
|
||||
}
|
||||
|
||||
EPvCode PvApp::getPvCode(std::string name)
|
||||
{
|
||||
static std::map<std::string, EPvCode> mapPvCode =
|
||||
{
|
||||
{"系统总览", EPvCode::MASK_HOME},
|
||||
{"运行监控", EPvCode::MASK_RUNNING},
|
||||
{"预测管理", EPvCode::MASK_FORECAST},
|
||||
{"储能充放电预测", EPvCode::MASK_FORECAST_STORAGE},
|
||||
{"光伏发电预测", EPvCode::MASK_FORECAST_SOLAR},
|
||||
{"充电负荷预测", EPvCode::MASK_FORECAST_CHARGE},
|
||||
{"统计分析", EPvCode::MASK_STAT},
|
||||
{"储能设备运行分析", EPvCode::MASK_STAT_STORAGE},
|
||||
{"光伏设备运行分析", EPvCode::MASK_STAT_SOLAR},
|
||||
{"充电设备运行分析", EPvCode::MASK_STAT_CHARGE},
|
||||
{"系统管理", EPvCode::MASK_SYSMGR},
|
||||
{"用户管理", EPvCode::MASK_MGR_USER},
|
||||
{"角色管理", EPvCode::MASK_MGR_ROLE},
|
||||
{"权限管理", EPvCode::MASK_MGR_PERMISSION},
|
||||
{"场站管理", EPvCode::MASK_MGR_STATION},
|
||||
{"设备管理", EPvCode::MASK_MGR_DEVICE},
|
||||
{"策略管理", EPvCode::MASK_MGR_POLICY},
|
||||
{"系统日志", EPvCode::MASK_MGR_SYSLOG},
|
||||
{"告警日志", EPvCode::MASK_MGR_ALERTLOG},
|
||||
};
|
||||
auto iter = mapPvCode.find(name);
|
||||
if (iter != mapPvCode.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EPvCode::NUL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PvApp::bind(PARAM* p, PvEvent eid, int pvid, std::function<void(std::string text)> cb)
|
||||
{
|
||||
auto pvuser = PvApp::getPvUser(p);
|
||||
if (pvuser)
|
||||
{
|
||||
std::string event = std::to_string((int)eid) + ":" + std::to_string((int)pvid);
|
||||
pvuser->mapEventCallback[event] = cb;
|
||||
}
|
||||
}
|
||||
|
||||
void PvApp::dispatch(PARAM* p, PvEvent eid, int pvid, std::string text)
|
||||
{
|
||||
auto pvuser = PvApp::getPvUser(p);
|
||||
if (pvuser)
|
||||
{
|
||||
std::string event = std::to_string((int)eid) + ":" + std::to_string((int)pvid);
|
||||
auto iter = pvuser->mapEventCallback.find(event);
|
||||
if (iter != pvuser->mapEventCallback.end())
|
||||
{
|
||||
(iter->second)(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int PvApp::widget(PARAM* p, int parent, int x, int y, int w, int h)
|
||||
{
|
||||
int id = PvApp::pvid(p);
|
||||
pvQWidget(p, id, parent);
|
||||
pvSetGeometry(p, id, x, y, w, h);
|
||||
return id;
|
||||
}
|
||||
|
||||
int PvApp::label(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
|
||||
{
|
||||
int id = PvApp::pvid(p);
|
||||
pvQLabel(p, id, parent);
|
||||
pvSetGeometry(p, id, x, y, w, h);
|
||||
pvSetFont(p, id, FONT_NAME, 14, 1, 0, 0, 0);
|
||||
pvSetFontColor(p, id, 255, 255, 255);
|
||||
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
|
||||
if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); }
|
||||
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);
|
||||
pvSetAlignment(p, id, AlignCenter);
|
||||
return id;
|
||||
}
|
||||
|
||||
int PvApp::button(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
|
||||
{
|
||||
int id = PvApp::pvid(p);
|
||||
pvQPushButton(p, id, parent);
|
||||
pvSetGeometry(p, id, x, y, w, h);
|
||||
pvSetFont(p, id, FONT_NAME, 14, 1, 0, 0, 0);
|
||||
pvSetFontColor(p, id, 255, 255, 255);
|
||||
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
|
||||
if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); }
|
||||
return id;
|
||||
}
|
||||
|
||||
int PvApp::image(PARAM* p, int parent, int x, int y, int w, int h, const char* filename)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector<std::string>& vecItems)
|
||||
{
|
||||
int id = PvApp::pvid(p);
|
||||
pvQComboBox(p, id, parent, 0, 0);
|
||||
pvSetGeometry(p, id, x, y, w, h);
|
||||
pvSetStyleSheet(p, id, QSS_COMBOX_14.c_str());
|
||||
for (int i=0; i<vecItems.size(); ++i)
|
||||
{
|
||||
pvInsertItem(p, id, i, NULL, vecItems[i].c_str());
|
||||
}
|
||||
PvApp::image(p, id, w-h, 0, h, h, "downFill.png");
|
||||
return id;
|
||||
}
|
||||
|
||||
int PvApp::lineEdit(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);
|
||||
pvSetGeometry(p, id, x, y, w, h);
|
||||
pvSetStyleSheet(p, id, QSS_LINEEDIT.c_str());
|
||||
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
|
||||
return id;
|
||||
}
|
||||
|
||||
PvRect::PvRect()
|
||||
{
|
||||
}
|
||||
|
||||
PvRect::PvRect(int ix, int iy, int width, int height)
|
||||
: x(ix), y(iy), w(width), h(height)
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user