#include "PvApp.h" #include "PvUser.h" #include "TimeUtils.h" #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; } PvUser* PvApp::getPvUser(PARAM* p) { return static_cast(p->user); } int PvApp::pvid(PARAM* p) { auto pvuser = PvApp::getPvUser(p); return (++pvuser->pvidIndex); } void PvApp::reset(PARAM* p) { auto pvuser = PvApp::getPvUser(p); if (pvuser) { pvuser->reset(); } } EPvCode PvApp::getPvCode(std::string name) { static std::map 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 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) { 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() ? 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); 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); if (!text.empty()) { pvSetText(p, id, text.c_str()); } pvSetStyleSheet(p, id, QSS.empty() ? QSS::button().c_str() : 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); return id; } int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector& vecItems, int index /*= 0*/) { 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