Files
energy_storage/src/pv/PvApp.cpp

236 lines
6.0 KiB
C++
Raw Normal View History

#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);
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
pvSetStyleSheet(p, id, qss.empty() ? qss::label().c_str() : 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);
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);
//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;
}
int PvApp::textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
static std::string qssTextEdit =
"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);}";
int id = PvApp::pvid(p);
pvQMultiLineEdit(p, id, parent, true, 10);
pvSetGeometry(p, id, x, y, w, h);
pvSetStyleSheet(p, id, qssTextEdit.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;
}