mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 03:09:24 +08:00
上传项目代码
This commit is contained in:
184
src/widgets/MainWindow.cpp
Normal file
184
src/widgets/MainWindow.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
static std::string DatetimeNow(char c1 = '-', char c2 = ':', char c3 = ' ')
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "%Y" << c1 << "%m" << c1 << "%d" << c3 << "%H" << c2 << "%M" << c2 << "%S";
|
||||
std::string fmt = ss.str();
|
||||
ss.str("");
|
||||
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
ss << std::put_time(std::localtime(&t), fmt.c_str());
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static const std::string STY_BTN_MENU =
|
||||
"QPushButton{background:rgba(50,128,218,200);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 18px;}"
|
||||
"QPushButton:hover{background-color:rgb(32,164,128);}"
|
||||
"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
|
||||
"QPushButton:disabled{color:rgb(150,150,150);}";
|
||||
|
||||
static const std::string STY_BTN_MENU_ACTIVE =
|
||||
"QPushButton{background:rgba(32,164,128,200);color:white;border-radius:5px;border:2px solid rgb(10,255,215);font:bold 18px;}"
|
||||
"QPushButton:hover{background-color:rgb(32,164,128);}"
|
||||
"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
|
||||
"QPushButton:disabled{color:rgb(150,150,150);}";
|
||||
|
||||
|
||||
void Menu::init(
|
||||
QWidget* parent,
|
||||
int x, int y,
|
||||
std::vector<std::string>& vecMenuId,
|
||||
std::function<void(std::string id)> cb)
|
||||
{
|
||||
int num = vecMenuId.size();
|
||||
x = (1920 - (num*110 - 10))*0.5;
|
||||
|
||||
cb_ = cb;
|
||||
for (int i = 0; i<num; i++)
|
||||
{
|
||||
std::string menuName = vecMenuId[i];
|
||||
auto btn = std::make_shared<QPushButton>(parent);
|
||||
btn->setGeometry(x+i*110, y, 100, 35);
|
||||
btn->setText(menuName.c_str());
|
||||
btn->setFont(QFont("微软雅黑"));
|
||||
if (menuName == curMenuId_)
|
||||
{
|
||||
btn->setStyleSheet(STY_BTN_MENU_ACTIVE.c_str());
|
||||
activeBtn_ = btn.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
btn->setStyleSheet(STY_BTN_MENU.c_str());
|
||||
}
|
||||
vecBtn_.push_back(btn);
|
||||
QObject::connect(btn.get(), &QPushButton::clicked, this, &Menu::onMenuBtnClicked);
|
||||
}
|
||||
}
|
||||
void Menu::onMenuBtnClicked()
|
||||
{
|
||||
QPushButton* btn = qobject_cast<QPushButton*>(sender());
|
||||
std::string menuName = btn->text().toStdString();
|
||||
|
||||
if (menuName == curMenuId_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
curMenuId_ = menuName;
|
||||
if (activeBtn_) { activeBtn_->setStyleSheet(STY_BTN_MENU.c_str()); }
|
||||
activeBtn_ = btn;
|
||||
activeBtn_->setStyleSheet(STY_BTN_MENU_ACTIVE.c_str());
|
||||
|
||||
if (cb_) { cb_(curMenuId_); }
|
||||
}
|
||||
|
||||
#include "WebHandler.h"
|
||||
#include <QWebChannel>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
webView = std::make_shared<QWebEngineView>(this);
|
||||
|
||||
MyWebHandler* myWebHandler = new MyWebHandler();
|
||||
QWebChannel* webChannel = new QWebChannel();
|
||||
webChannel->registerObject("cppNative", myWebHandler);
|
||||
webView->page()->setWebChannel(webChannel);
|
||||
|
||||
webView->setGeometry(0, 0, 1920, 1080);
|
||||
// 默认设置透明, 解决加载时的白屏闪烁
|
||||
webView->page()->setBackgroundColor(Qt::transparent);
|
||||
|
||||
webView->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
//webView.load(QUrl("https://www.baidu.com"));
|
||||
webView->load(QUrl("file:///assets/html/main.html"));
|
||||
//connect(wWebView.get(), &QWebEngineView::loadFinished, this, &MyWidget::slotLoadFinished);
|
||||
|
||||
//std::string htmlContent = "HelloWorld";
|
||||
//webView->setHtml(htmlContent.c_str(), QUrl("file:///assets/html/"));
|
||||
webView->show();
|
||||
return;
|
||||
|
||||
QUI::label(labBkg_, this, 0, 0, 1920, 1080, "");
|
||||
labBkg_.setPixmap(QPixmap("assets/ui/bkg01.png"));
|
||||
|
||||
// 顶部区域: 显示系统信息、时间、登录用户信息
|
||||
//QUI::label(labBkgHead_, this, 0, 0, 1920, 114, "");
|
||||
//labBkgHead_.setPixmap(QPixmap("assets/ui/bkg_head.png"));
|
||||
|
||||
// 系统名称
|
||||
QUI::label(labTitle_, this, 100, 20, 520, 50, "", "font:bold 42px;color:white;");
|
||||
// 时钟标签
|
||||
QUI::label(labTime_, this, 50, 25, 320, 40, DatetimeNow().c_str(), "");
|
||||
labTime_.setFont(QFont("微软雅黑", 16, 1000));
|
||||
|
||||
//wPage_ = std::make_shared<WidgetPageHome>(this);
|
||||
//wPage_->setGeometry(0, 115, 1920, 1080-115);
|
||||
//wPage_->show();
|
||||
|
||||
this->initMenu();
|
||||
|
||||
// 登录框
|
||||
wLogin_.setParent(this);
|
||||
wLogin_.show();
|
||||
|
||||
connect(&wLogin_, &WidgetLogin::signalLoginSuccess, this, &MainWindow::slotLoginSuccess);
|
||||
|
||||
QObject::connect(&timer_, &QTimer::timeout, this, &MainWindow::onTimeout);
|
||||
timer_.start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::initMenu()
|
||||
{
|
||||
std::vector<std::string> vecMenuId =
|
||||
{
|
||||
"系统总览", "运行监控", "预测监控", "统计分析", "安全管理", "系统管理", "服务管理", "参数管理"
|
||||
};
|
||||
|
||||
menu_ = std::make_shared<Menu>();
|
||||
menu_->init(this, 740, 1030, vecMenuId, [=](std::string menuId) { this->onMenuClicked(menuId); });
|
||||
|
||||
// 考虑处理二级菜单
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
auto& size = event->size();
|
||||
if (webView)
|
||||
{
|
||||
webView->resize(size);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::slotLoginSuccess()
|
||||
{
|
||||
wLogin_.hide();
|
||||
onMenuClicked("系统总览");
|
||||
}
|
||||
|
||||
void MainWindow::onMenuClicked(std::string menuId)
|
||||
{
|
||||
auto w = WidgetPage::create(this, menuId);
|
||||
if (w)
|
||||
{
|
||||
w->setGeometry(0, 90, 1920, 950);
|
||||
wPage_ = w;
|
||||
wPage_->show();
|
||||
//wPage_->updateData();
|
||||
}
|
||||
else
|
||||
{
|
||||
wPage_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onTimeout()
|
||||
{
|
||||
if (wPage_)
|
||||
{
|
||||
//wPage_->updateData();
|
||||
}
|
||||
labTime_.setText(DatetimeNow().c_str());
|
||||
}
|
||||
55
src/widgets/MainWindow.h
Normal file
55
src/widgets/MainWindow.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <QMainWindow>
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
#include <vector>
|
||||
#include <QTimer>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "uihelper.h"
|
||||
#include "WidgetLogin.h"
|
||||
#include "WidgetPage.h"
|
||||
|
||||
class Menu : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
std::string curMenuId_;
|
||||
std::vector<std::shared_ptr<QPushButton>> vecBtn_;
|
||||
QPushButton* activeBtn_ = NULL;
|
||||
std::function<void(std::string id)> cb_ = nullptr;
|
||||
|
||||
void init(QWidget* parent, int x, int y, std::vector<std::string>& vecMenuId, std::function<void(std::string id)> cb);
|
||||
void onMenuBtnClicked();
|
||||
};
|
||||
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWindow();
|
||||
void initMenu();
|
||||
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
public slots:
|
||||
void slotLoginSuccess();
|
||||
void onMenuClicked(std::string menuId);
|
||||
void onTimeout();
|
||||
|
||||
public:
|
||||
QLabel labBkg_;
|
||||
QLabel labBkgHead_;
|
||||
QLabel labTitle_;
|
||||
QLabel labTime_;
|
||||
|
||||
WidgetLogin wLogin_;
|
||||
|
||||
QTimer timer_;
|
||||
|
||||
std::shared_ptr<WidgetPage> wPage_ = nullptr;
|
||||
|
||||
std::shared_ptr<Menu> menu_ = nullptr;
|
||||
|
||||
std::shared_ptr<QWebEngineView> webView;
|
||||
};
|
||||
604
src/widgets/WebHandler.cpp
Normal file
604
src/widgets/WebHandler.cpp
Normal file
@@ -0,0 +1,604 @@
|
||||
#include "WebHandler.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include "common/Utils.h"
|
||||
#include "common/Logger.h"
|
||||
#include "Snowflake.h"
|
||||
#include "app/Dao.h"
|
||||
|
||||
static void JSsetResPaginaion(QVariantMap& result, std::vector<DataFields>& data, int page, int pageSize, int count, int code, string err)
|
||||
{
|
||||
result["code"] = code;
|
||||
result["err"] = "操作成功";
|
||||
result["count"] = count;
|
||||
result["page"] = page;
|
||||
result["pageSize"] = pageSize;
|
||||
|
||||
QVariantList listRow;
|
||||
for (auto& fields: data)
|
||||
{
|
||||
QVariantMap row;
|
||||
for (auto& field: fields.fields())
|
||||
{
|
||||
row[field.first.c_str()] = field.second.c_str();
|
||||
}
|
||||
listRow << row;
|
||||
}
|
||||
result["data"] = listRow;
|
||||
}
|
||||
|
||||
static void JSgetReqParam(QString key, QVariantMap& params, DataFields& fields)
|
||||
{
|
||||
if (params.contains(key)) fields.set(key.toStdString(), params[key].toString().toStdString());
|
||||
}
|
||||
|
||||
void MyWebHandler::setNativeText(const QString& text)
|
||||
{
|
||||
nativeText_ = text;
|
||||
emit signalNativeTextChanged(text);
|
||||
}
|
||||
|
||||
void MyWebHandler::log(const QString& text)
|
||||
{
|
||||
XLOGD() << "[JS] " << text.toStdString();
|
||||
}
|
||||
|
||||
QString MyWebHandler::readFile(const QString& filename)
|
||||
{
|
||||
//std::string filePath = "assets/html/系统管理/index.html"; //filename.toStdString();
|
||||
std::filesystem::path filePath = std::filesystem::u8path(filename.toStdString());
|
||||
XLOGD() << "[cppNative] readFile: " << filePath;
|
||||
std::ifstream ifs(filePath);
|
||||
if (ifs.is_open())
|
||||
{
|
||||
// 获取文件大小
|
||||
ifs.seekg(0, std::ios::end);
|
||||
std::streamsize size = ifs.tellg();
|
||||
XLOGD() << "[cppNative] readFile [" << filePath << "] success, data size=" << size;
|
||||
|
||||
// 定位回文件开始,读取文件内容到缓冲区
|
||||
ifs.seekg(0, std::ios::beg);
|
||||
std::string buf(size, '\0');
|
||||
ifs.read(&buf[0], size);
|
||||
ifs.close();
|
||||
return buf.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
XLOGD() << "[cppNative] readFile [" << filePath << "] failed.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
QVariantMap MyWebHandler::queryUserList(int page, int pageSize)
|
||||
{
|
||||
XLOGD() << "[cppNative] queryUserList";
|
||||
std::vector<DataFields> res;
|
||||
DAO::queryUser(res);
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertUser(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("account", params, fields);
|
||||
fields.set("passwd", "123456");
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("gender", params, fields);
|
||||
JSgetReqParam("age", params, fields);
|
||||
JSgetReqParam("phone", params, fields);
|
||||
JSgetReqParam("email", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
XLOGD() << "[cppNative] insertUser: params=" << fields.to_str();
|
||||
|
||||
bool ret = DAO::insertUser(fields);
|
||||
|
||||
|
||||
|
||||
// 设置用户角色
|
||||
std::string user_id = fields.get_str("user_id");
|
||||
if (params.contains("role_id")) {
|
||||
|
||||
int role_id = params["role_id"].toInt();
|
||||
DataFields fieldsUserRole;
|
||||
fieldsUserRole.set("user_id", user_id);
|
||||
fieldsUserRole.set("role_id", role_id);
|
||||
fieldsUserRole.set("create_time", Utils::timeNowStr());
|
||||
auto dao = DAO::get("user_role");
|
||||
ret = dao->insertFields(fieldsUserRole);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int MyWebHandler::deleteUser(const QString& userId) { return 1; }
|
||||
|
||||
int MyWebHandler::updateUser(const QString& userId, QVariantMap params)
|
||||
{
|
||||
XLOGD() << "[cppNative] updateUser";
|
||||
|
||||
int ret = 1;
|
||||
DataFields fields;
|
||||
|
||||
JSgetReqParam("account", params, fields);
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("gender", params, fields);
|
||||
JSgetReqParam("age", params, fields);
|
||||
JSgetReqParam("phone", params, fields);
|
||||
JSgetReqParam("email", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (params.size() > 0)
|
||||
{
|
||||
ret = DAO::updateUserById(userId.toStdString(), fields);
|
||||
XLOGD() << "updateUser: ret=" << ret;
|
||||
}
|
||||
|
||||
if (params.contains("role_id")) {
|
||||
int role_id = params["role_id"].toInt();
|
||||
fields.clear();
|
||||
fields.set("user_id", userId.toStdString());
|
||||
fields.set("role_id", role_id);
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
//fields.set("update_by", "");
|
||||
|
||||
auto dao = DAO::get("user_role");
|
||||
std::vector<std::string> keysUpdate = {"role_id", "update_time"};
|
||||
bool res = dao->duplicateUpdate(fields, keysUpdate);
|
||||
ret = ret ? 0 : 1;
|
||||
XLOGD() << "updateUser, update role, ret=" << ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// ================================================================================================================
|
||||
// 角色管理接口
|
||||
QVariantMap MyWebHandler::queryRoleList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("role");
|
||||
bool ret = dao->exec("SELECT * FROM role;", res);
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
|
||||
XLOGD() << "[cppNative] queryRoleList " << (ret ? "success." : "failed.");
|
||||
return result;
|
||||
}
|
||||
int MyWebHandler::insertRole(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
if (params.contains("name")) fields.set("name", params["name"].toString().toStdString());
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (params.contains("describe")) fields.set("describe", params["describe"].toString().toStdString());
|
||||
|
||||
// 数据表 role_id 是自增id
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
auto dao = DAO::get("role");
|
||||
bool ret = dao->insertFields(fields);
|
||||
return ret ? 0: 1;
|
||||
}
|
||||
int MyWebHandler::deleteRole(const QString& roleId) { return 1; }
|
||||
int MyWebHandler::updateRole(const QString& roleId, QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
if (fields.size() <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
std::string sqlC = " WHERE role_id='" + roleId.toStdString() + "'";
|
||||
auto dao = DAO::get("role");
|
||||
bool ret = dao->updateFields(fields, sqlC);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
QVariantList MyWebHandler::queryRolePermissionList(int roleId)
|
||||
{
|
||||
std::vector<DataFields> result;
|
||||
std::string sql = "SELECT p.permission_id, p.name, rp.role_id, rp.is_open FROM permission p "
|
||||
"LEFT JOIN role_permission rp ON(rp.permission_id = p.permission_id AND rp.role_id = '" + std::to_string(roleId) +"') WHERE p.is_open='1';";
|
||||
|
||||
auto dao = DAO::get("role_permission");
|
||||
bool ret = dao->exec(sql, result);
|
||||
|
||||
QVariantList listRow;
|
||||
for (auto& fields: result)
|
||||
{
|
||||
QVariantMap row;
|
||||
for (auto& field: fields.fields())
|
||||
{
|
||||
row[field.first.c_str()] = field.second.c_str();
|
||||
}
|
||||
listRow << row;
|
||||
}
|
||||
return listRow;
|
||||
};
|
||||
int MyWebHandler::updateRolePermission(int roleId, QVariantList params)
|
||||
{
|
||||
auto dao = DAO::get("role_permission");
|
||||
|
||||
std::string sql = "DELETE FROM role_permission WHERE role_id='" + std::to_string(roleId) + "';";
|
||||
bool ret = dao->exec(sql);
|
||||
|
||||
std::vector<DataFields> vecFields;
|
||||
for (QVariant& item: params)
|
||||
{
|
||||
if (item.canConvert<QVariantMap>())
|
||||
{
|
||||
QVariantMap itemMap = item.toMap();
|
||||
DataFields fields;
|
||||
fields.set("role_id", roleId);
|
||||
JSgetReqParam("permission_id", itemMap, fields);
|
||||
JSgetReqParam("is_open", itemMap, fields);
|
||||
vecFields.push_back(fields);
|
||||
}
|
||||
}
|
||||
ret = dao->insertFields(vecFields);
|
||||
return ret ? 0 : 1;
|
||||
};
|
||||
|
||||
// ================================================================================================================
|
||||
// 权限管理接口
|
||||
QVariantMap MyWebHandler::queryPermissionList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("permission");
|
||||
bool ret = dao->exec("SELECT * FROM permission;", res);
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertPermission(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("permission");
|
||||
bool ret = dao->insertFields(fields);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
int MyWebHandler::deletePermission(const QString& permissionId) { return 1; }
|
||||
int MyWebHandler::updatePermission(const QString& permissionId, QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("permission");
|
||||
std::string sqlC = " WHERE permission_id='" + permissionId.toStdString() + "'";
|
||||
bool ret = dao->updateFields(fields, sqlC);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
// ================================================================================================================
|
||||
// 设备管理接口
|
||||
QVariantMap MyWebHandler::queryDeviceList(int page, int pageSize)
|
||||
{
|
||||
XLOGD() << "queryDeviceList:";
|
||||
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("device");
|
||||
bool ret = dao->exec("SELECT * FROM device;", res);
|
||||
XLOGD() << "queryDeviceList: size=" << res.size();
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertDevice(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("code", params, fields);
|
||||
JSgetReqParam("model", params, fields);
|
||||
JSgetReqParam("factory", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("device");
|
||||
bool ret = dao->insertFields(fields);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
int MyWebHandler::deleteDevice(const QString& deviceId) { return 1; }
|
||||
int MyWebHandler::updateDevice(const QString& deviceId, QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("code", params, fields);
|
||||
JSgetReqParam("model", params, fields);
|
||||
JSgetReqParam("factory", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("device");
|
||||
std::string sqlC = "WHERE device_id='" + deviceId.toStdString() + "'";
|
||||
auto ret = dao->updateFields(fields, sqlC);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
QVariantList MyWebHandler::queryDeviceTypeList()
|
||||
{
|
||||
const std::vector<std::pair<int, std::string>> vecTypeDef =
|
||||
{
|
||||
{1, "光伏设备"},
|
||||
{2, "储能设备"},
|
||||
{3, "充电设备"},
|
||||
{4, "逆变器"},
|
||||
{5, "汇流箱"},
|
||||
{6, "电表"},
|
||||
};
|
||||
|
||||
QVariantList result;
|
||||
for (auto& item: vecTypeDef)
|
||||
{
|
||||
QVariantMap row;
|
||||
row["id"] = item.first;
|
||||
row["name"] = item.second.c_str();
|
||||
result << row;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ================================================================================================================
|
||||
// 计费管理接口
|
||||
QVariantMap MyWebHandler::queryPriceList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("price");
|
||||
bool ret = dao->exec("SELECT * FROM price;", res);
|
||||
XLOGD() << "queryPriceList: size=" << res.size();
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
int MyWebHandler::insertPrice(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("price");
|
||||
bool ret = dao->insertFields(fields);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
int MyWebHandler::deletePrice(const QString& priceId) { return 1; }
|
||||
int MyWebHandler::updatePrice(const QString& priceId, QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
std::string sqlC = "WHERE price_id='" + priceId.toStdString() + "'";
|
||||
auto dao = DAO::get("price");
|
||||
auto ret = dao->updateFields(fields, sqlC);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
QVariantList MyWebHandler::queryPriceTypeList()
|
||||
{
|
||||
const std::vector<std::pair<int, std::string>> vecTypeDef =
|
||||
{
|
||||
{1, "充电计费"},
|
||||
};
|
||||
|
||||
QVariantList result;
|
||||
for (auto& item: vecTypeDef)
|
||||
{
|
||||
QVariantMap row;
|
||||
row["id"] = item.first;
|
||||
row["name"] = item.second.c_str();
|
||||
result << row;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantMap MyWebHandler::queryPolicyList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("policy");
|
||||
bool ret = dao->exec("SELECT * FROM policy;", res);
|
||||
XLOGD() << "queryPolicyList: size=" << res.size();
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertPolicy(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("value", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("policy");
|
||||
bool ret = dao->insertFields(fields);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
int MyWebHandler::deletePolicy(const QString& policyId) { return 1; }
|
||||
|
||||
int MyWebHandler::updatePolicy(const QString& policyId, QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("value", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
std::string sqlC = "WHERE policy_id='" + policyId.toStdString() + "'";
|
||||
auto dao = DAO::get("policy");
|
||||
auto ret = dao->updateFields(fields, sqlC);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
QVariantList MyWebHandler::queryPolicyTypeList()
|
||||
{
|
||||
const std::vector<std::pair<int, std::string>> vecTypeDef =
|
||||
{
|
||||
{1, "发电策略"},
|
||||
{2, "储能策略"},
|
||||
{3, "充电策略"},
|
||||
};
|
||||
|
||||
QVariantList result;
|
||||
for (auto& item: vecTypeDef)
|
||||
{
|
||||
QVariantMap row;
|
||||
row["id"] = item.first;
|
||||
row["name"] = item.second.c_str();
|
||||
result << row;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
QVariantMap MyWebHandler::querySyslogList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("system_log");
|
||||
bool ret = dao->exec("SELECT * FROM system_log;", res);
|
||||
XLOGD() << "querySyslogList: size=" << res.size();
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
QVariantMap MyWebHandler::querySecPolicyList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("sec_policy");
|
||||
bool ret = dao->exec("SELECT * FROM sec_policy;", res);
|
||||
XLOGD() << "querySecPolicyList: size=" << res.size();
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
int MyWebHandler::insertSecPolicy(QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("code", params, fields);
|
||||
JSgetReqParam("level", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("action", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("create_time", Utils::timeNowStr());
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
auto dao = DAO::get("sec_policy");
|
||||
bool ret = dao->insertFields(fields);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
int MyWebHandler::updateSecPolicy(const QString& policyId, QVariantMap params)
|
||||
{
|
||||
DataFields fields;
|
||||
JSgetReqParam("name", params, fields);
|
||||
JSgetReqParam("type", params, fields);
|
||||
JSgetReqParam("code", params, fields);
|
||||
JSgetReqParam("level", params, fields);
|
||||
JSgetReqParam("describe", params, fields);
|
||||
JSgetReqParam("action", params, fields);
|
||||
JSgetReqParam("is_open", params, fields);
|
||||
if (fields.size() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fields.set("update_time", Utils::timeNowStr());
|
||||
|
||||
std::string sqlC = "WHERE sec_policy_id='" + policyId.toStdString() + "'";
|
||||
auto dao = DAO::get("sec_policy");
|
||||
auto ret = dao->updateFields(fields, sqlC);
|
||||
return ret ? 0 : 1;
|
||||
}
|
||||
|
||||
QVariantMap MyWebHandler::querySecRecordList(int page, int pageSize)
|
||||
{
|
||||
std::vector<DataFields> res;
|
||||
auto dao = DAO::get("sec_record");
|
||||
bool ret = dao->exec("SELECT * FROM sec_record;", res);
|
||||
XLOGD() << "querySecRecordList: size=" << res.size();
|
||||
|
||||
QVariantMap result;
|
||||
JSsetResPaginaion(result, res, page, pageSize, res.size(), 0, "操作成功");
|
||||
return result;
|
||||
};
|
||||
|
||||
int MyWebHandler::insertSecRecord(QVariantMap params) {};
|
||||
int MyWebHandler::updateSecRecord(const QString& policyId, QVariantMap params) {};
|
||||
106
src/widgets/WebHandler.h
Normal file
106
src/widgets/WebHandler.h
Normal file
@@ -0,0 +1,106 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#include <QVariantList>
|
||||
|
||||
class MyWebHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
//Q_PROPERTY(QString nativeText READ nativeText MEMBER m_nativeText NOTIFY signalNativeTextChanged FINAL)
|
||||
|
||||
public:
|
||||
explicit MyWebHandler(QObject* parent = nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
QString nativeText() const { return nativeText_; }
|
||||
|
||||
|
||||
signals:
|
||||
//在C++中定义的信号,可以在JS端监听此信号接收消息
|
||||
void signalNativeTextChanged(const QString& text);
|
||||
|
||||
void singalReadFileFinished(const QString& text);
|
||||
|
||||
public slots:
|
||||
//C++ 端的公共槽函数,可以在JS端调用。
|
||||
void setNativeText(const QString& text);
|
||||
|
||||
void log(const QString& text);
|
||||
|
||||
QString readFile(const QString& filename);
|
||||
|
||||
// ================================================================================================================
|
||||
// 用户管理接口
|
||||
QVariantMap queryUserList(int page, int pageSize);
|
||||
int insertUser(QVariantMap params);
|
||||
int deleteUser(const QString& userId);
|
||||
int updateUser(const QString& userId, QVariantMap params);
|
||||
|
||||
// ================================================================================================================
|
||||
// 角色管理接口
|
||||
/**
|
||||
* 查询角色列表, pageSize !=0 时分页查询
|
||||
* @param [int page]: 当前的页码
|
||||
* @param [int pageSize]: 一页的数据条数,0: 不分页; >0: 分页
|
||||
*/
|
||||
QVariantMap queryRoleList(int page, int pageSize);
|
||||
int insertRole(QVariantMap params);
|
||||
int deleteRole(const QString& roleId);
|
||||
int updateRole(const QString& roleId, QVariantMap params);
|
||||
|
||||
QVariantList queryRolePermissionList(int roleId);
|
||||
int updateRolePermission(int roleId, QVariantList params);
|
||||
|
||||
// ================================================================================================================
|
||||
// 权限管理接口
|
||||
QVariantMap queryPermissionList(int page, int pageSize);
|
||||
int insertPermission(QVariantMap params);
|
||||
int deletePermission(const QString& permissionId);
|
||||
int updatePermission(const QString& permissionId, QVariantMap params);
|
||||
|
||||
// ================================================================================================================
|
||||
// 设备管理接口
|
||||
QVariantMap queryDeviceList(int page, int pageSize);
|
||||
int insertDevice(QVariantMap params);
|
||||
int deleteDevice(const QString& deviceId);
|
||||
int updateDevice(const QString& deviceId, QVariantMap params);
|
||||
QVariantList queryDeviceTypeList();
|
||||
|
||||
// ================================================================================================================
|
||||
// 计费管理接口
|
||||
QVariantMap queryPriceList(int page, int pageSize);
|
||||
int insertPrice(QVariantMap params);
|
||||
int deletePrice(const QString& priceId);
|
||||
int updatePrice(const QString& priceId, QVariantMap params);
|
||||
QVariantList queryPriceTypeList();
|
||||
|
||||
// ================================================================================================================
|
||||
// 策略管理接口
|
||||
QVariantMap queryPolicyList(int page, int pageSize);
|
||||
int insertPolicy(QVariantMap params);
|
||||
int deletePolicy(const QString& policyId);
|
||||
int updatePolicy(const QString& policyId, QVariantMap params);
|
||||
QVariantList queryPolicyTypeList();
|
||||
|
||||
// ================================================================================================================
|
||||
// 系统日志接口
|
||||
QVariantMap querySyslogList(int page, int pageSize);
|
||||
|
||||
// ================================================================================================================
|
||||
// 安全策略
|
||||
QVariantMap querySecPolicyList(int page, int pageSize);
|
||||
int insertSecPolicy(QVariantMap params);
|
||||
int updateSecPolicy(const QString& policyId, QVariantMap params);
|
||||
|
||||
// ================================================================================================================
|
||||
// 安全日志记录
|
||||
QVariantMap querySecRecordList(int page, int pageSize);
|
||||
int insertSecRecord(QVariantMap params);
|
||||
int updateSecRecord(const QString& policyId, QVariantMap params);
|
||||
|
||||
public:
|
||||
QString nativeText_;
|
||||
};
|
||||
78
src/widgets/WidgetLogin.cpp
Normal file
78
src/widgets/WidgetLogin.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "WidgetLogin.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "app/Application.h"
|
||||
|
||||
WidgetLogin::WidgetLogin()
|
||||
{
|
||||
this->resize(1920, 1080);
|
||||
|
||||
|
||||
QUI::label(labBkg_, this, 0, 0, 1920, 1080, "");
|
||||
labBkg_.setPixmap(QPixmap("assets/ui/bkgLogin.png"));
|
||||
|
||||
int w = 517;
|
||||
int h = 534;
|
||||
int x = (1920 - w) *0.5;
|
||||
int y = (1080 - h) *0.5;
|
||||
|
||||
//QUI::label(labLoginBkg_, this, x, y, w, h, "");
|
||||
//labLoginBkg_.setPixmap(QPixmap("assets/ui/login.png"));
|
||||
|
||||
|
||||
QUI::lineedit(lineUsername_, this, 870, 447, 300, 36);
|
||||
QUI::lineedit(linePasswd_, this, 870, 510, 300, 36);
|
||||
|
||||
std::string sty = "QLineEdit {"
|
||||
" background-color: #2859b0;" // 背景颜色
|
||||
" color: #ffffff;" // 文字颜色
|
||||
" border: 0px solid #ccc;" // 边框
|
||||
" border-radius: 5px;" // 圆角
|
||||
" padding: 5px;" // 内边距
|
||||
" font-size: 16px;" // 字体大小
|
||||
" font-weight: bold;" // 字体加粗
|
||||
"}";
|
||||
lineUsername_.setStyleSheet(sty.c_str());
|
||||
linePasswd_.setStyleSheet(sty.c_str());
|
||||
|
||||
// 提示信息框
|
||||
QUI::label(labMsg_, this, 838, 630, 350, 36, "");
|
||||
|
||||
// 登录按钮
|
||||
QUI::button(btnLoigin_, this, 838, 588, 338, 46, "登 入", "background-color:#2a82e4; color:white;font-size: 14px;font-weight:bold;");
|
||||
QObject::connect(&btnLoigin_, &QPushButton::clicked, this, &WidgetLogin::slotBtnCilckLogin);
|
||||
}
|
||||
|
||||
|
||||
void WidgetLogin::slotBtnCilckLogin()
|
||||
{
|
||||
if (0)
|
||||
{
|
||||
std::string account = lineUsername_.text().toStdString();
|
||||
std::string passwd = linePasswd_.text().toStdString();
|
||||
std::string err;
|
||||
|
||||
if (account.empty())
|
||||
{
|
||||
labMsg_.setText(std::string("请输入用户名" + err).c_str());
|
||||
return;
|
||||
}
|
||||
if (passwd.empty())
|
||||
{
|
||||
labMsg_.setText(std::string("请输入用密码" + err).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto& op = Application::instance().getOperator();
|
||||
bool ret = op.login(account, passwd, err);
|
||||
if (!ret)
|
||||
{
|
||||
labMsg_.setText(std::string("登录失败:" + err).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查登录用户名和密码
|
||||
emit signalLoginSuccess();
|
||||
}
|
||||
31
src/widgets/WidgetLogin.h
Normal file
31
src/widgets/WidgetLogin.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "uihelper.h"
|
||||
|
||||
class WidgetLogin : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
WidgetLogin();
|
||||
|
||||
signals:
|
||||
void signalLoginSuccess();
|
||||
|
||||
public slots:
|
||||
void slotBtnCilckLogin();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
QLabel labBkg_;
|
||||
QLabel labLoginBkg_;
|
||||
|
||||
QLineEdit lineUsername_;
|
||||
QLineEdit linePasswd_;
|
||||
|
||||
QLabel labMsg_;
|
||||
|
||||
QPushButton btnLoigin_;
|
||||
};
|
||||
25
src/widgets/WidgetPage.cpp
Normal file
25
src/widgets/WidgetPage.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "WidgetPage.h"
|
||||
|
||||
#include "pages/WidgetPageHome.h"
|
||||
#include "pages/WidgetPageOverview.h"
|
||||
#include "pages/WidgetPageRunning.h"
|
||||
#include "pages/WidgetPageWeb.h"
|
||||
|
||||
std::shared_ptr<WidgetPage> WidgetPage::create(QWidget* parent, std::string name)
|
||||
{
|
||||
std::shared_ptr<WidgetPage> w = nullptr;
|
||||
if (name == "系统总览")
|
||||
{
|
||||
w = std::make_shared<WidgetPageOverview>(parent);
|
||||
}
|
||||
else if (name == "运行监控")
|
||||
{
|
||||
w = std::make_shared<WidgetPageRunning>(parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
w = std::make_shared<WidgetPageWeb>(parent, name);
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
17
src/widgets/WidgetPage.h
Normal file
17
src/widgets/WidgetPage.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "uihelper.h"
|
||||
|
||||
|
||||
class WidgetPage : public QWidget
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<WidgetPage> create(QWidget* parent, std::string name);
|
||||
|
||||
WidgetPage(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void updateData() {};
|
||||
|
||||
};
|
||||
41
src/widgets/WidgetWeb.cpp
Normal file
41
src/widgets/WidgetWeb.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "WidgetWeb.h"
|
||||
|
||||
WebHandler::WebHandler(QObject* parent)
|
||||
: QObject {parent}
|
||||
{
|
||||
webChannel = new QWebChannel();
|
||||
// 注册C++对象到QWebChannel,这样远端的QWebChannel也会生成一个对应的JS对象
|
||||
// 在JS中引入 qwebchannel.js, 使用 channel.objects.webNative 获取注册的“webNative”
|
||||
webChannel->registerObject("webNative", this);
|
||||
}
|
||||
|
||||
void WebHandler::setNativeText(const QString& text)
|
||||
{
|
||||
m_nativeText = text;
|
||||
qDebug() << QString("setNativeText:") << text;
|
||||
emit signalNativeTextChanged(text);
|
||||
}
|
||||
|
||||
WidgetWeb::WidgetWeb(QWidget* parent) : QWebEngineView(parent)
|
||||
{
|
||||
webHandler_ = new WebHandler();
|
||||
this->page()->setWebChannel(webHandler_->webChannel);
|
||||
this->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
}
|
||||
|
||||
void WidgetWeb::loadHtml(std::string url)
|
||||
{
|
||||
// "file:///assets/html/echarts//maptest.html"
|
||||
this->load(QUrl(url.c_str()));
|
||||
connect(this, &QWebEngineView::loadFinished, this, &WidgetWeb::slotLoadFinished);
|
||||
}
|
||||
|
||||
void WidgetWeb::invikeJS(QString jscode)
|
||||
{
|
||||
//QString jscode = QString("showalert('%1')").arg("Hello QtWebEngine!");
|
||||
this->page()->runJavaScript(jscode, [](const QVariant& v) { qDebug() << v.toString(); });
|
||||
}
|
||||
|
||||
void WidgetWeb::slotLoadFinished(bool ret)
|
||||
{
|
||||
}
|
||||
48
src/widgets/WidgetWeb.h
Normal file
48
src/widgets/WidgetWeb.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWebChannel>
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
#include <string>
|
||||
|
||||
class WebHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString nativeText READ nativeText MEMBER m_nativeText NOTIFY signalNativeTextChanged FINAL)
|
||||
|
||||
public:
|
||||
explicit WebHandler(QObject* parent = nullptr);
|
||||
|
||||
QString nativeText() const { return m_nativeText; }
|
||||
|
||||
signals:
|
||||
//在C++中定义的信号,可以在JS端监听此信号接收消息
|
||||
void signalNativeTextChanged(const QString& text);
|
||||
|
||||
public slots:
|
||||
//C++ 端的公共槽函数,可以在JS端调用。
|
||||
void setNativeText(const QString& text);
|
||||
|
||||
public:
|
||||
QString m_nativeText;
|
||||
QWebChannel* webChannel;
|
||||
};
|
||||
|
||||
|
||||
class WidgetWeb : public QWebEngineView
|
||||
{
|
||||
public:
|
||||
WidgetWeb(QWidget* parent);
|
||||
|
||||
void loadHtml(std::string url);
|
||||
|
||||
void invikeJS(QString jscode);
|
||||
|
||||
// slots
|
||||
void slotLoadFinished(bool ret);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
WebHandler* webHandler_;
|
||||
|
||||
};
|
||||
0
src/widgets/pages/WidgetPageDevice.cpp
Normal file
0
src/widgets/pages/WidgetPageDevice.cpp
Normal file
0
src/widgets/pages/WidgetPageDevice.h
Normal file
0
src/widgets/pages/WidgetPageDevice.h
Normal file
203
src/widgets/pages/WidgetPageHome.cpp
Normal file
203
src/widgets/pages/WidgetPageHome.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
#include "WidgetPageHome.h"
|
||||
|
||||
#include "common/TimeUtils.h"
|
||||
#include "common/Utils.h"
|
||||
|
||||
static std::vector<double> RANDT(int n, int min, int max)
|
||||
{
|
||||
std::vector<double> v(n);
|
||||
for (int i = 0; i<n; i++) { v[i] = Utils::random(min, max); }
|
||||
return v;
|
||||
}
|
||||
|
||||
class InfoItem : public QWidget
|
||||
{
|
||||
public:
|
||||
QLabel labTitle_;
|
||||
QLabel labVal_;
|
||||
QLabel labUnit_;
|
||||
|
||||
InfoItem::InfoItem(QWidget* parent, QRect rt, std::string title, std::string unit, std::string v="")
|
||||
: QWidget(parent)
|
||||
{
|
||||
this->setGeometry(rt);
|
||||
QUI::setBackground(this, "InfoCardItem", QColor(200, 200, 200, 30));
|
||||
|
||||
int xHalf = rt.width()/2;
|
||||
int yHalf = rt.height()/2;
|
||||
QUI::label(labTitle_, this, 0, 0, rt.width(), yHalf-10, title);
|
||||
labTitle_.setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
|
||||
QUI::label(labVal_, this, 0, yHalf, xHalf+20, 30, v, "font:bold 24px;color:rgb(38,220,172);");
|
||||
labVal_.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
QUI::label(labUnit_, this, xHalf+30, yHalf, 30, 30, unit);
|
||||
}
|
||||
|
||||
void InfoItem::setVal(std::string v)
|
||||
{
|
||||
labVal_.setText(v.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
class EnvItem
|
||||
{
|
||||
public:
|
||||
QLabel labBkg_;
|
||||
QLabel labIcon_;
|
||||
QLabel labVal_;
|
||||
|
||||
EnvItem(QWidget* parent, int x, int y, std::string icon, std::string v)
|
||||
{
|
||||
QUI::label(labBkg_, parent, x, y, 60, 60, "", "background-color:rgb(42, 74, 132);border-radius:30px;");
|
||||
QUI::label(labIcon_, parent, x+6, y+6, 48, 48, "");
|
||||
labIcon_.setPixmap(QPixmap(icon.c_str()));
|
||||
QUI::label(labVal_, parent, x-10, y+65, 80, 40, v, "font:bold 14px;color:white;");
|
||||
labVal_.setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
};
|
||||
void WidgetPageHome::slotLoadFinished(bool bOK)
|
||||
{
|
||||
QString jsCode = QString("showalert('%1')").arg("Hello QtWebEngine!");
|
||||
wWebView->page()->runJavaScript(jsCode, [](const QVariant& v) { qDebug() << v.toString(); });
|
||||
}
|
||||
WidgetPageHome::WidgetPageHome(QWidget* parent) : WidgetPage(parent)
|
||||
{
|
||||
const std::string STY_VAL = "font:bold 18px;color:rgb(38,220,172);";
|
||||
const int H = 300;
|
||||
|
||||
// 地图
|
||||
//QUI::label(labMapBkg_, this, 500, 10, 920, H*3-10, "");
|
||||
//labMapBkg_.setPixmap(QPixmap("assets/ui/bkg_map.png"));
|
||||
|
||||
wWebView = std::make_shared<QWebEngineView>(this);
|
||||
wWebView->setGeometry(500, 10, 920, H*3-10);
|
||||
|
||||
wWebView->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
//webEngineView.load(QUrl("https://www.baidu.com"));
|
||||
wWebView->load(QUrl("file:///assets/echarts/HTML/maptest.html"));
|
||||
|
||||
connect(wWebView.get(), &QWebEngineView::loadFinished, this, &WidgetPageHome::slotLoadFinished);
|
||||
|
||||
//std::string htmlContent = "HelloWorld";
|
||||
//webEngineView.setHtml(htmlContent.c_str());
|
||||
wWebView->show();
|
||||
|
||||
panelStation_ = std::make_shared<Panel>(this, QRect(10, 10, 480, H-10), "信息概览");
|
||||
{
|
||||
QWidget* wParent = panelStation_.get();
|
||||
infoNum1_ = std::make_shared<InfoItem>(wParent, QRect(20, 50, 210, 100), "风电设备数量", "台", "5");
|
||||
infoNum2_ = std::make_shared<InfoItem>(wParent, QRect(240, 50, 210, 100), "光伏设备数量", "台", "27");
|
||||
infoNum3_ = std::make_shared<InfoItem>(wParent, QRect(20, 160, 210, 100), "储能设备", "台", "16");
|
||||
infoNum4_ = std::make_shared<InfoItem>(wParent, QRect(240, 160, 210, 100), "充电设备", "台", "12");
|
||||
}
|
||||
|
||||
panelStat_ = std::make_shared<Panel>(this, QRect(10, 10+H, 480, H-10), "统计信息");
|
||||
{
|
||||
int x = 40; int y = 50;
|
||||
int w = 180;
|
||||
int h = 60; int h1 = 40;
|
||||
QWidget* wParent = panelStat_.get();
|
||||
labSwapCount_ = QUI::labelPairV(wParent, x, y, w, h, h1, "风电今日发电量", "100.000");
|
||||
labElectCount_ = QUI::labelPairV(wParent, x + 200, y, w, h, h1, "风电累计发电量", "100.000");
|
||||
labSwapCountDay_ = QUI::labelPairV(wParent, x, y += (h+10), w, h, h1, "光伏今日发电量", "100.000");
|
||||
labElectCountDay_ = QUI::labelPairV(wParent, x+ 200, y, w, h, h1, "光伏累计发电量", "100.000");
|
||||
labCarbonCount_ = QUI::labelPairV(wParent, x, y += (h+10), w, h, h1, "信息5", "100.000");
|
||||
labP1_ = QUI::labelPairV(wParent, x+ 200, y, w, h, h1, "信息4", "100.000");
|
||||
}
|
||||
|
||||
|
||||
panelEnv_ = std::make_shared<Panel>(this, QRect(10, 10+H*2, 480, H-10), "环境信息");
|
||||
{
|
||||
QWidget* wParent = panelEnv_.get();
|
||||
|
||||
int x = 40;
|
||||
int y = 50;
|
||||
|
||||
envTemperature_ = std::make_shared<EnvItem>(wParent, x, y, "./assets/ui/temperature.png", "温度\n31℃");
|
||||
envHumidity_ = std::make_shared<EnvItem>(wParent, x+100, y, "./assets/ui/humidity.png", "湿度\n42%");
|
||||
envWind_ = std::make_shared<EnvItem>(wParent, x+200, y, "./assets/ui/windsSolid.png", "风速\n1.5m/s");
|
||||
envSolar_ = std::make_shared<EnvItem>(wParent, x+300, y, "./assets/ui/brightness.png", "辐照度\n120W/m2");
|
||||
|
||||
y += 120;
|
||||
QUI::label(labProgressCpu_, wParent, 40, y, 100, 24, "CPU使用率");
|
||||
progressCpu_ = std::make_shared<ProgressView>(wParent, 120, y, 24);
|
||||
progressCpu_->setVal(30);
|
||||
|
||||
y += 40;
|
||||
QUI::label(labProgressMem_, wParent, 40, y, 100, 24, "内存使用率");
|
||||
progressMem_ = std::make_shared<ProgressView>(wParent, 120, y, 24);
|
||||
progressMem_->setVal(60);
|
||||
|
||||
y += 40;
|
||||
QUI::label(labProgressDisk_, wParent, 40, y, 100, 24, "磁盘使用率");
|
||||
progressDisk_ = std::make_shared<ProgressView>(wParent, 120, y, 24);
|
||||
progressDisk_->setVal(60);
|
||||
}
|
||||
|
||||
int y = 10;
|
||||
int h = 280;
|
||||
panelSwap_ = std::make_shared<Panel>(this, QRect(1430, 10+H*0, 480, H-10), "信息1");
|
||||
{
|
||||
//chartbar1_ = std::make_shared<ChartBarView>(panelSwap_.get(), QRect(0, 30, 480, h-20), 7);
|
||||
//chartbar1_->addItem("数据1");
|
||||
//chartbar1_->addItem("数据2");
|
||||
//chartbar1_->addItem("数据3");
|
||||
//chartbar1_->addItem("数据4");
|
||||
}
|
||||
|
||||
y += (h+10);
|
||||
panel2_ = std::make_shared<Panel>(this, QRect(1430, 10+H*1, 480, H-10), "信息2");
|
||||
{
|
||||
//chartbar2_ = std::make_shared<ChartBarView>(panel2_.get(), QRect(0, 30, 480, h-20), 7);
|
||||
//chartbar2_->addItem("数据1");
|
||||
//chartbar2_->addItem("数据2");
|
||||
//chartbar2_->addItem("数据3");
|
||||
}
|
||||
|
||||
y += (h+10);
|
||||
panel3_ = std::make_shared<Panel>(this, QRect(1430, 10+H*2, 480, H-10), "信息3");
|
||||
{
|
||||
chartbar3_ = std::make_shared<ChartBarView>(panel3_.get(), QRect(0, 30, 480, h-20), 7);
|
||||
chartbar3_->addItem("数据1");
|
||||
chartbar3_->addItem("数据2");
|
||||
|
||||
// 测试数据
|
||||
//chartbar3_->updateItem(0, RANDT(7, 1, 10));
|
||||
//chartbar3_->updateItem(1, RANDT(7, 1, 10));
|
||||
}
|
||||
|
||||
|
||||
//chartbar1_->updateItem(0, RANDT(7, 1, 10));
|
||||
//chartbar1_->updateItem(1, RANDT(7, 1, 10));
|
||||
//chartbar1_->updateItem(2, RANDT(7, 1, 10));
|
||||
//chartbar1_->updateItem(3, RANDT(7, 1, 10));
|
||||
|
||||
//chartbar2_->updateItem(0, RANDT(7, 1, 10));
|
||||
//chartbar2_->updateItem(1, RANDT(7, 1, 10));
|
||||
//chartbar2_->updateItem(2, RANDT(7, 1, 10));
|
||||
|
||||
|
||||
|
||||
//panelPower_ = std::make_shared<Panel>(this, QRect(500, 590, 920, 280), "今日负荷曲线");
|
||||
//{
|
||||
// QWidget* wParent = panelPower_.get();
|
||||
// chartline7_ = std::make_shared<ChartLineView>(wParent, QRect(10, 30, 900, 240));
|
||||
// chartline7_->addItem("数据1");
|
||||
// chartline7_->addItem("数据2");
|
||||
// chartline7_->setAxisYLeft(-1, 1, 7);
|
||||
|
||||
// //double t0 = TimeUtils::datetime2tms(TimeUtils::now_date() + " 00:00:00");
|
||||
// //double tx = t0;
|
||||
// //int n = 360;
|
||||
// //std::vector<std::pair<double, double>> vd0(n+1);
|
||||
// //std::vector<std::pair<double, double>> vd1(n+1);
|
||||
// //for (int i = 0; i<=n; i++)
|
||||
// //{
|
||||
// // tx = t0 + i*(86400/n)*1000;
|
||||
// // vd0[i] = {tx, sin(2*3.1415926*float(i*2)/float(360))};
|
||||
// // vd1[i] = {tx, cos(2*3.1415926*float(i*2)/float(360))};
|
||||
// //}
|
||||
// //chartline7_->setAxisX(t0, tx, 13, "hh:mm");
|
||||
// //chartline7_->updateItem(0, vd0);
|
||||
// //chartline7_->updateItem(1, vd1);
|
||||
//}
|
||||
};
|
||||
64
src/widgets/pages/WidgetPageHome.h
Normal file
64
src/widgets/pages/WidgetPageHome.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "WidgetPage.h"
|
||||
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
class InfoItem;
|
||||
class EnvItem;
|
||||
|
||||
class WidgetPageHome : public WidgetPage
|
||||
{
|
||||
public:
|
||||
WidgetPageHome(QWidget* parent);
|
||||
void slotLoadFinished(bool bOK);
|
||||
|
||||
QLabel labTitle_;
|
||||
|
||||
QLabel labMapBkg_;
|
||||
|
||||
std::shared_ptr<Panel> panelStation_;
|
||||
std::shared_ptr<InfoItem> infoNum2_;
|
||||
std::shared_ptr<InfoItem> infoNum1_;
|
||||
std::shared_ptr<InfoItem> infoNum3_;
|
||||
std::shared_ptr<InfoItem> infoNum4_;
|
||||
|
||||
|
||||
std::shared_ptr<Panel> panelSwap_;
|
||||
std::shared_ptr<ChartBarView> chartbar1_;
|
||||
|
||||
std::shared_ptr<Panel> panel2_;
|
||||
std::shared_ptr<ChartBarView> chartbar2_;
|
||||
|
||||
std::shared_ptr<Panel> panel3_;
|
||||
std::shared_ptr<ChartBarView> chartbar3_;
|
||||
|
||||
|
||||
std::shared_ptr<Panel> panelStat_;
|
||||
std::shared_ptr<LabelPairV> labSwapCount_;
|
||||
std::shared_ptr<LabelPairV> labSwapCountDay_;
|
||||
std::shared_ptr<LabelPairV> labElectCount_;
|
||||
std::shared_ptr<LabelPairV> labElectCountDay_;
|
||||
std::shared_ptr<LabelPairV> labCarbonCount_;
|
||||
std::shared_ptr<LabelPairV> labP1_;
|
||||
|
||||
std::shared_ptr<Panel> panelEnv_;
|
||||
std::shared_ptr<Panel> panelPower_;
|
||||
|
||||
QLabel labProgressCpu_;
|
||||
std::shared_ptr<ProgressView> progressCpu_;
|
||||
|
||||
QLabel labProgressMem_;
|
||||
std::shared_ptr<ProgressView> progressMem_;
|
||||
|
||||
QLabel labProgressDisk_;
|
||||
std::shared_ptr<ProgressView> progressDisk_;
|
||||
|
||||
std::shared_ptr<EnvItem> envTemperature_;
|
||||
std::shared_ptr<EnvItem> envHumidity_;
|
||||
std::shared_ptr<EnvItem> envWind_;
|
||||
std::shared_ptr<EnvItem> envSolar_;
|
||||
|
||||
std::shared_ptr<ChartLineView> chartline_;
|
||||
|
||||
std::shared_ptr<QWebEngineView> wWebView = nullptr;
|
||||
};
|
||||
173
src/widgets/pages/WidgetPageOverview.cpp
Normal file
173
src/widgets/pages/WidgetPageOverview.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
#include "WidgetPageOverview.h"
|
||||
#include "common/TimeUtils.h"
|
||||
#include "common/Utils.h"
|
||||
static std::vector<double> RANDT(int n, int min, int max)
|
||||
{
|
||||
std::vector<double> v(n);
|
||||
for (int i = 0; i<n; i++) { v[i] = Utils::random(min, max); }
|
||||
return v;
|
||||
}
|
||||
|
||||
WidgetPageOverview::WidgetPageOverview(QWidget* parent) : WidgetPage(parent)
|
||||
{
|
||||
{
|
||||
panel1_ = std::make_shared<Panel>(this, QRect(10, 10, 490, 300), "运行状况");
|
||||
QWidget* wParent = panel1_.get();
|
||||
|
||||
labBkg_ = QUI::label(wParent, 10, 40, 150, 250, "", "border:1px solid rgb(27, 88, 105);background-color:rgba(200,200,200,30)");
|
||||
|
||||
labDaysK_ = QUI::label(wParent, 10, 180, 150, 30, "安全运行时间", "color:white;font: bold 20px;");
|
||||
labDaysK_->setAlignment(Qt::AlignCenter);
|
||||
|
||||
labDaysV_ = QUI::label(wParent, 10, 100, 105, 50, "223", "color:rgb(77, 215, 240);font: bold 40px;");
|
||||
labDaysV_->setAlignment(Qt::AlignBottom | Qt::AlignRight);
|
||||
|
||||
labDaysT_ = QUI::label(wParent, 120, 105, 40, 40, "天", "color:white;font: bold 14px;");
|
||||
labDaysT_->setAlignment(Qt::AlignBottom);
|
||||
|
||||
int x = 170; int y = 40;
|
||||
int w = 150; int h = 77;
|
||||
labp1_ = std::make_shared<LabelParam>(wParent, "站内风机设备", "100", "台", x, y, w, h);
|
||||
labp2_ = std::make_shared<LabelParam>(wParent, "站内光伏设备", "100", "台", x += (w+10), y, w, h);
|
||||
|
||||
labp3_ = std::make_shared<LabelParam>(wParent, "当日入网电量", "31.58", "Kwh", x = 170, y += (h+10), w, h);
|
||||
labp4_ = std::make_shared<LabelParam>(wParent, "累计入网设备", "54763.01", "Kwh", x += (w+10), y, w, h);
|
||||
|
||||
labp5_ = std::make_shared<LabelParam>(wParent, "累计充放电量", "387.13", "台", x = 170, y += (h+10), w, h);
|
||||
labp6_ = std::make_shared<LabelParam>(wParent, "累计碳减排量", "66.72", "吨", x += (w+10), y, w, h);
|
||||
}
|
||||
|
||||
{
|
||||
panel2_ = std::make_shared<Panel>(this, QRect(10, 320, 490, 300), "光伏设备");
|
||||
QWidget* wParent = panel2_.get();
|
||||
|
||||
int x = 10; int y = 40;
|
||||
int w = 150; int h = 50;
|
||||
labp21_ = std::make_shared<LabelParam>(wParent, "日累计发电量", "223", "Kwh", x, y, w, h);
|
||||
labp22_ = std::make_shared<LabelParam>(wParent, "日上网电量", "100", "Kwh", x += (w+10), y, w, h);
|
||||
labp23_ = std::make_shared<LabelParam>(wParent, "日发电时长", "152", "h", x += (w+10), y, w, h);
|
||||
|
||||
chartbar2_ = std::make_shared<ChartBarView>(wParent, QRect(10, 95, 470, 210), 5);
|
||||
chartbar2_->addItem("日累计发电量");
|
||||
chartbar2_->addItem("日上网电量");
|
||||
chartbar2_->addItem("日发电时长");
|
||||
chartbar2_->updateItem(0, RANDT(7, 1, 10));
|
||||
chartbar2_->updateItem(1, RANDT(7, 1, 10));
|
||||
chartbar2_->updateItem(2, RANDT(7, 1, 10));
|
||||
}
|
||||
|
||||
{
|
||||
panel3_ = std::make_shared<Panel>(this, QRect(10, 630, 490, 300), "储能设备");
|
||||
QWidget* wParent = panel3_.get();
|
||||
|
||||
int x = 10; int y = 40;
|
||||
int w = 225; int h = 50;
|
||||
labp31_ = std::make_shared<LabelParam>(wParent, "日累计充电电量", "223.23", "Kwh", x, y, w, h);
|
||||
labp32_ = std::make_shared<LabelParam>(wParent, "日累计放电电量", "123.01", "Kwh", x += (w+20), y, w, h);
|
||||
|
||||
chartbar3_ = std::make_shared<ChartBarView>(wParent, QRect(10, 95, 470, 210), 5);
|
||||
chartbar3_->addItem("日累充电电量");
|
||||
chartbar3_->addItem("日上放电电量");
|
||||
chartbar3_->updateItem(0, RANDT(7, 1, 10));
|
||||
chartbar3_->updateItem(1, RANDT(7, 1, 10));
|
||||
}
|
||||
{
|
||||
panel4_ = std::make_shared<Panel>(this, QRect(1420, 10, 490, 300), "负荷设备");
|
||||
QWidget* wParent = panel4_.get();
|
||||
|
||||
int x = 10; int y = 40;
|
||||
int w = 150; int h = 50;
|
||||
labp41_ = std::make_shared<LabelParam>(wParent, "日用电功率", "223.23", "Kw", x, y, w, h);
|
||||
labp42_ = std::make_shared<LabelParam>(wParent, "日用电次数", "126", "次", x += (w+10), y, w, h);
|
||||
labp43_ = std::make_shared<LabelParam>(wParent, "日用电电量", "53.62", "Kwh", x += (w+10), y, w, h);
|
||||
|
||||
chartbar4_ = std::make_shared<ChartBarView>(wParent, QRect(10, 95, 470, 210), 5);
|
||||
chartbar4_->addItem("日用电功率");
|
||||
chartbar4_->addItem("日用电次数");
|
||||
chartbar4_->addItem("日用电电量");
|
||||
chartbar4_->updateItem(0, RANDT(7, 1, 10));
|
||||
chartbar4_->updateItem(1, RANDT(7, 1, 10));
|
||||
chartbar4_->updateItem(2, RANDT(7, 1, 10));
|
||||
}
|
||||
{
|
||||
panel5_ = std::make_shared<Panel>(this, QRect(1420, 320, 490, 300), "充电设备");
|
||||
QWidget* wParent = panel5_.get();
|
||||
|
||||
int x = 10; int y = 40;
|
||||
int w = 225; int h = 50;
|
||||
labp51_ = std::make_shared<LabelParam>(wParent, "日时间利用率", "58", "%", x, y, w, h);
|
||||
labp52_ = std::make_shared<LabelParam>(wParent, "日功率利用率", "61", "%", x += (w+20), y, w, h);
|
||||
chartbar5_ = std::make_shared<ChartBarView>(wParent, QRect(10, 95, 470, 210), 5);
|
||||
chartbar5_->addItem("日时间利用率");
|
||||
chartbar5_->addItem("日功率利用率");
|
||||
chartbar5_->updateItem(0, RANDT(7, 1, 10));
|
||||
chartbar5_->updateItem(1, RANDT(7, 1, 10));
|
||||
}
|
||||
{
|
||||
panel6_ = std::make_shared<Panel>(this, QRect(1420, 630, 490, 300), "告警信息");
|
||||
QWidget* wParent = panel6_.get();
|
||||
|
||||
int x = 10; int y = 40;
|
||||
int w = 150; int h = 50;
|
||||
labp61_ = std::make_shared<LabelParam>(wParent, "日光伏设备告警", "5", "次", x, y, w, h);
|
||||
labp62_ = std::make_shared<LabelParam>(wParent, "日储能设备告警", "2", "次", x += (w+10), y, w, h);
|
||||
labp63_ = std::make_shared<LabelParam>(wParent, "日负荷设备告警", "3", "次", x += (w+10), y, w, h);
|
||||
|
||||
chartbar6_ = std::make_shared<ChartBarView>(wParent, QRect(10, 95, 470, 210), 5);
|
||||
chartbar6_->addItem("光伏设备");
|
||||
chartbar6_->addItem("储能设备");
|
||||
chartbar6_->addItem("负荷设备");
|
||||
chartbar6_->updateItem(0, RANDT(7, 1, 10));
|
||||
chartbar6_->updateItem(1, RANDT(7, 1, 10));
|
||||
chartbar6_->updateItem(2, RANDT(7, 1, 10));
|
||||
}
|
||||
|
||||
{
|
||||
panel7_ = std::make_shared<Panel>(this, QRect(510, 680, 900, 250), "功率与辐照度");
|
||||
QWidget* wParent = panel7_.get();
|
||||
|
||||
chartline7_ = std::make_shared<ChartLineView>(wParent, QRect(10, 50, 880, 200));
|
||||
chartline7_->addItem("功率");
|
||||
chartline7_->addItem("辐照度");
|
||||
chartline7_->setAxisYLeft(-1, 1, 5);
|
||||
|
||||
double t0 = TimeUtils::datetime2tms(TimeUtils::now_date() + " 00:00:00");
|
||||
double tx = t0;
|
||||
int n = 360;
|
||||
std::vector<std::pair<double, double>> vd0(n+1);
|
||||
std::vector<std::pair<double, double>> vd1(n+1);
|
||||
for (int i = 0; i<=n; i++)
|
||||
{
|
||||
tx = t0 + i*(86400/n)*1000;
|
||||
vd0[i] = {tx, sin(2*3.1415926*float(i*2)/float(360))};
|
||||
vd1[i] = {tx, cos(2*3.1415926*float(i*2)/float(360))};
|
||||
}
|
||||
chartline7_->setAxisX(t0, tx, 13, "hh:mm");
|
||||
chartline7_->updateItem(0, vd0);
|
||||
chartline7_->updateItem(1, vd1);
|
||||
}
|
||||
|
||||
{
|
||||
wWebView = std::make_shared<QWebEngineView>(this);
|
||||
wWebView->setGeometry(510, 100, 900, 560);
|
||||
// 默认设置透明, 解决加载时的白屏闪烁
|
||||
wWebView->page()->setBackgroundColor(Qt::transparent);
|
||||
|
||||
wWebView->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
//webEngineView.load(QUrl("https://www.baidu.com"));
|
||||
wWebView->load(QUrl("file:///assets/echarts/HTML/maptest.html"));
|
||||
|
||||
//connect(wWebView.get(), &QWebEngineView::loadFinished, this, &WidgetPageHome::slotLoadFinished);
|
||||
|
||||
//std::string htmlContent = "HelloWorld";
|
||||
//webEngineView.setHtml(htmlContent.c_str());
|
||||
wWebView->show();
|
||||
|
||||
//lab712_.setPixmap(QPixmap(icon.c_str()));
|
||||
|
||||
iconp1_ = std::make_shared<IconParam>(this, "光照", "27.2", "Lux", 600, 40, QColor(246, 155, 82));
|
||||
iconp2_ = std::make_shared<IconParam>(this, "风速", "1.2", "m/s", 800, 40, QColor(155, 216, 1));
|
||||
iconp3_ = std::make_shared<IconParam>(this, "环境温度", "27.2", "℃", 1000, 40, QColor(61, 254, 250));
|
||||
iconp4_ = std::make_shared<IconParam>(this, "环境湿度", "27.2", "%", 1200, 40, QColor(216, 61, 108));
|
||||
}
|
||||
}
|
||||
110
src/widgets/pages/WidgetPageOverview.h
Normal file
110
src/widgets/pages/WidgetPageOverview.h
Normal file
@@ -0,0 +1,110 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WidgetPage.h"
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
class LabelParam
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<QLabel> labBkg_;
|
||||
std::shared_ptr<QLabel> labKey_;
|
||||
std::shared_ptr<QLabel> labVal_;
|
||||
std::shared_ptr<QLabel> labTail_;
|
||||
|
||||
LabelParam(QWidget* parent, std::string k, std::string v, std::string t, int x, int y, int w, int h)
|
||||
{
|
||||
labBkg_ = QUI::label(parent, x, y, w, h, "", "background-color:rgba(100,100,100,50)");
|
||||
labKey_ = QUI::label(parent, x, y, w, h*0.5, k, "color:white;font: bold 16px;");
|
||||
labVal_ = QUI::label(parent, x, y+h*0.5, w*float(2.0/3.0), h*0.5, v, "color:rgb(77, 215, 240);font:bold 16px;");
|
||||
labTail_ = QUI::label(parent, x+w*float(2.0/3.0)+5, y+h*0.5, w*float(1.0/3.0), h*0.5, t, "color:white;font: bold 12px;");
|
||||
|
||||
labKey_->setAlignment(Qt::AlignCenter);
|
||||
labVal_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
labTail_->setAlignment(Qt::AlignVCenter);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class IconParam
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<QLabel> lab711_;
|
||||
std::shared_ptr<QLabel> lab712_;
|
||||
std::shared_ptr<QLabel> lab713_;
|
||||
std::shared_ptr<QLabel> lab714_;
|
||||
|
||||
std::string tail;
|
||||
|
||||
IconParam(QWidget* parent, std::string k, std::string v, std::string t, int x, int y, QColor color= QColor(61, 254, 250))
|
||||
{
|
||||
tail = t;
|
||||
std::stringstream ss;
|
||||
ss << color.red() << "," << color.green() << "," << color.blue();
|
||||
lab711_ = QUI::label(parent, x, y, 5, 50, "", "background-color:rgb(" + ss.str() + ")");
|
||||
lab712_ = QUI::label(parent, x + 10, y, 50, 50, "", "background-color:rgba(" + ss.str() + ",50)");
|
||||
lab713_ = QUI::label(parent, x + 10 + 60, y, 100, 25, k, "font: normal 16px; color:white");
|
||||
lab714_ = QUI::label(parent, x + 10 + 60, y+25, 100, 25, v+tail, "font: normal 16px; color:white");
|
||||
}
|
||||
};
|
||||
|
||||
class WidgetPageOverview : public WidgetPage
|
||||
{
|
||||
public:
|
||||
WidgetPageOverview(QWidget* parent);
|
||||
|
||||
std::shared_ptr<Panel> panel1_;
|
||||
std::shared_ptr<QLabel> labBkg_;
|
||||
std::shared_ptr<QLabel> labDaysK_;
|
||||
std::shared_ptr<QLabel> labDaysV_;
|
||||
std::shared_ptr<QLabel> labDaysT_;
|
||||
|
||||
std::shared_ptr<LabelParam> labp1_;
|
||||
std::shared_ptr<LabelParam> labp2_;
|
||||
std::shared_ptr<LabelParam> labp3_;
|
||||
std::shared_ptr<LabelParam> labp4_;
|
||||
std::shared_ptr<LabelParam> labp5_;
|
||||
std::shared_ptr<LabelParam> labp6_;
|
||||
|
||||
|
||||
std::shared_ptr<Panel> panel2_;
|
||||
std::shared_ptr<LabelParam> labp21_;
|
||||
std::shared_ptr<LabelParam> labp22_;
|
||||
std::shared_ptr<LabelParam> labp23_;
|
||||
std::shared_ptr<ChartBarView> chartbar2_;
|
||||
|
||||
std::shared_ptr<Panel> panel3_;
|
||||
std::shared_ptr<LabelParam> labp31_;
|
||||
std::shared_ptr<LabelParam> labp32_;
|
||||
std::shared_ptr<ChartBarView> chartbar3_;
|
||||
|
||||
std::shared_ptr<Panel> panel4_;
|
||||
std::shared_ptr<LabelParam> labp41_;
|
||||
std::shared_ptr<LabelParam> labp42_;
|
||||
std::shared_ptr<LabelParam> labp43_;
|
||||
std::shared_ptr<ChartBarView> chartbar4_;
|
||||
|
||||
std::shared_ptr<Panel> panel5_;
|
||||
std::shared_ptr<LabelParam> labp51_;
|
||||
std::shared_ptr<LabelParam> labp52_;
|
||||
std::shared_ptr<ChartBarView> chartbar5_;
|
||||
|
||||
std::shared_ptr<Panel> panel6_;
|
||||
std::shared_ptr<LabelParam> labp61_;
|
||||
std::shared_ptr<LabelParam> labp62_;
|
||||
std::shared_ptr<LabelParam> labp63_;
|
||||
std::shared_ptr<ChartBarView> chartbar6_;
|
||||
|
||||
std::shared_ptr<Panel> panel7_;
|
||||
std::shared_ptr<ChartLineView> chartline7_;
|
||||
|
||||
std::shared_ptr<QWebEngineView> wWebView = nullptr;
|
||||
|
||||
std::shared_ptr<IconParam> iconp1_;
|
||||
std::shared_ptr<IconParam> iconp2_;
|
||||
std::shared_ptr<IconParam> iconp3_;
|
||||
std::shared_ptr<IconParam> iconp4_;
|
||||
|
||||
};
|
||||
359
src/widgets/pages/WidgetPageRunning.cpp
Normal file
359
src/widgets/pages/WidgetPageRunning.cpp
Normal file
@@ -0,0 +1,359 @@
|
||||
#include "WidgetPageRunning.h"
|
||||
#include "common/Logger.h"
|
||||
|
||||
static void ReviseQueuePos(int i, int maxCol, int w, int h, int& x, int& y)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
if (i%maxCol == 0)
|
||||
{
|
||||
x = 0;
|
||||
y += (h);
|
||||
}
|
||||
else
|
||||
{
|
||||
x += (w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PanelCard : public Panel
|
||||
{
|
||||
public:
|
||||
QLabel labIcon_;
|
||||
QLabel labName_;
|
||||
QLabel labTyle_;
|
||||
QLabel labStatus_;
|
||||
std::map<std::string, std::pair<std::shared_ptr<QLabel>, std::shared_ptr<QLabel>>> mapLabParams_;
|
||||
|
||||
std::string styLabelK_ = "QLabel {font:bold 15px;color:rgb(166, 184, 221);}";
|
||||
std::string styLabel_ = "QLabel {font:bold 15px;color:white;}";
|
||||
|
||||
PanelCard(QWidget* parent, QRect rt, std::string type) : Panel(parent, rt, "")
|
||||
{
|
||||
//this->setObjectName("MyPanel");
|
||||
//std::string sty = "#MyPanel {background-color:rgb(8, 54, 91);border:1px solid rgba(255,255,255,10);border-radius:15px;}";
|
||||
this->setAutoFillBackground(true);
|
||||
//this->setStyleSheet(sty.c_str());
|
||||
this->setBackground(QColor(8, 54, 91), "border:1px solid rgba(255,255,255,10);border-radius:15px;");
|
||||
|
||||
QUI::labelImage(labIcon_, this, 10, 20, 64, 64, "assets/ui/solarPanel.png");
|
||||
QUI::label(labName_, this, 90, 20, 120, 20, "#NAME", styLabel_);
|
||||
QUI::label(labStatus_, this, 90, 40, 120, 20, "#STATUS", styLabel_);
|
||||
QUI::label(labTyle_, this, 90, 60, 120, 20, type, "QLabel {font:bold 15px;color:rgb(8, 165, 255);}");
|
||||
}
|
||||
|
||||
void setIcon(std::string icon)
|
||||
{
|
||||
labIcon_.setPixmap(QPixmap(icon.c_str()));
|
||||
}
|
||||
void setName(std::string name)
|
||||
{
|
||||
labName_.setText(name.c_str());
|
||||
}
|
||||
void setStatus(int status)
|
||||
{
|
||||
std::vector<std::string> VEC_STATUS = {"运行", "空闲", "离线", "故障"};
|
||||
if (status >=0 && status <=3)
|
||||
{
|
||||
labStatus_.setText(VEC_STATUS[status].c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
labStatus_.setText("#STATUS");
|
||||
}
|
||||
}
|
||||
void setParam(std::string k, std::string v)
|
||||
{
|
||||
std::shared_ptr<QLabel> labK = nullptr;
|
||||
std::shared_ptr<QLabel> labV = nullptr;
|
||||
|
||||
auto iter = mapLabParams_.find(k);
|
||||
if (iter == mapLabParams_.end())
|
||||
{
|
||||
int y = 100 + mapLabParams_.size() * 24;
|
||||
labK = QUI::label(this, 20, y, 80, 20, k + ":", styLabelK_);
|
||||
labV = QUI::label(this, 110, y, 120, 20, v, styLabel_);
|
||||
mapLabParams_[k] = {labK, labV};
|
||||
}
|
||||
else
|
||||
{
|
||||
labV = iter->second.second;
|
||||
labV->setText(v.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void enterEvent(QEvent* e) override
|
||||
{
|
||||
this->setBackground(QColor(30, 100, 100, 120), "border: 1px solid white;border-radius:15px;");
|
||||
}
|
||||
virtual void leaveEvent(QEvent* e) override
|
||||
{
|
||||
this->setBackground(QColor(8, 54, 91), "border:1px solid rgba(255,255,255,10);border-radius:15px;");
|
||||
}
|
||||
};
|
||||
|
||||
class PanelDeviceDetail : public Panel
|
||||
{
|
||||
public:
|
||||
PanelDeviceDetail(QWidget* parent, QRect rt) : Panel(parent, rt)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class PanelDeviceWind : public PanelDeviceDetail
|
||||
{
|
||||
public:
|
||||
std::vector<std::shared_ptr<PanelCard>> vecCards_;
|
||||
|
||||
PanelDeviceWind(QWidget* parent, QRect rt) : PanelDeviceDetail(parent, rt)
|
||||
{
|
||||
int col = 5;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int W = 280;
|
||||
int H = 320;
|
||||
for (int i = 0; i<col; i++)
|
||||
{
|
||||
ReviseQueuePos(i, 5, W+10, H+10, x, y);
|
||||
auto card = std::make_shared<PanelCard>(this, QRect(x+10, y+10, W, H), "风机");
|
||||
card->setIcon("assets/ui/icon1.png");
|
||||
card->setName("风电设备-" + std::to_string(i+1));
|
||||
card->setStatus(0);
|
||||
vecCards_.push_back(card);
|
||||
|
||||
card->setParam("位置", "能源站xxxx-xxx");
|
||||
card->setParam("工作状态", "发电/空闲");
|
||||
card->setParam("在线状态", "在线/离线");
|
||||
card->setParam("故障状态", "正常/故障");
|
||||
card->setParam("电压", "220 V");
|
||||
card->setParam("电流", "50 A");
|
||||
card->setParam("额定功率", "30 KW");
|
||||
card->setParam("实时功率", "28 KW");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PanelDeviceSolar : public PanelDeviceDetail
|
||||
{
|
||||
public:
|
||||
std::vector<std::shared_ptr<PanelCard>> vecCards_;
|
||||
|
||||
PanelDeviceSolar(QWidget* parent, QRect rt) : PanelDeviceDetail(parent, rt)
|
||||
{
|
||||
int col = 5;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int W = 280;
|
||||
int H = 320;
|
||||
for (int i = 0; i<col; i++)
|
||||
{
|
||||
ReviseQueuePos(i, 5, W+10, H+10, x, y);
|
||||
std::string type = (i==0) ? "逆变器" : (i==1 ? "汇流箱" : "光伏板");
|
||||
auto card = std::make_shared<PanelCard>(this, QRect(x+10, y+10, W, H), type);
|
||||
card->setIcon("assets/ui/solarPanel.png");
|
||||
card->setName("设备-" + std::to_string(i+1));
|
||||
card->setStatus(0);
|
||||
vecCards_.push_back(card);
|
||||
card->setParam("位置", "能源站xxxx-xxx");
|
||||
card->setParam("电压", "220V");
|
||||
card->setParam("电流", "0.5A");
|
||||
card->setParam("额定功率", "22kw");
|
||||
card->setParam("实时功率", "6.83kw");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PanelDeviceEnergyStorage : public PanelDeviceDetail
|
||||
{
|
||||
public:
|
||||
std::vector<std::shared_ptr<PanelCard>> vecCards_;
|
||||
|
||||
PanelDeviceEnergyStorage(QWidget* parent, QRect rt) : PanelDeviceDetail(parent, rt)
|
||||
{
|
||||
int col = 10;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int W = 280;
|
||||
int H = 320;
|
||||
for (int i = 0; i<col; i++)
|
||||
{
|
||||
ReviseQueuePos(i, 5, W+10, H+10, x, y);
|
||||
auto card = std::make_shared<PanelCard>(this, QRect(x+10, y+10, W, H), "储能电池");
|
||||
card->setIcon("assets/ui/energyStorage.png");
|
||||
card->setName("储能设备-" + std::to_string(i+1));
|
||||
card->setStatus(0);
|
||||
vecCards_.push_back(card);
|
||||
card->setParam("位置", "能源站xxxx-xxx");
|
||||
card->setParam("电压", "220V");
|
||||
card->setParam("电流", "0.5A");
|
||||
card->setParam("额定功率", "22kw");
|
||||
card->setParam("实时功率", "6.83kw");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PanelDeviceCharge : public PanelDeviceDetail
|
||||
{
|
||||
public:
|
||||
std::vector<std::shared_ptr<PanelCard>> vecCards_;
|
||||
|
||||
PanelDeviceCharge(QWidget* parent, QRect rt) : PanelDeviceDetail(parent, rt)
|
||||
{
|
||||
int col = 5;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int W = 280;
|
||||
int H = 320;
|
||||
for (int i = 0; i<col; i++)
|
||||
{
|
||||
ReviseQueuePos(i, 5, W+10, H+10, x, y);
|
||||
auto card = std::make_shared<PanelCard>(this, QRect(x+10, y+10, W, H), "充电机");
|
||||
card->setIcon("assets/ui/charger.png");
|
||||
card->setName("充电设备-" + std::to_string(i+1));
|
||||
card->setStatus(0);
|
||||
vecCards_.push_back(card);
|
||||
card->setParam("位置", "能源站xxxx-xxx");
|
||||
card->setParam("电压", "220V");
|
||||
card->setParam("电流", "0.5A");
|
||||
card->setParam("额定功率", "22kw");
|
||||
card->setParam("实时功率", "6.83kw");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class PanelCardCamera
|
||||
{
|
||||
public:
|
||||
Panel panel_;
|
||||
QLabel labName_;
|
||||
QLabel labVideo_;
|
||||
|
||||
PanelCardCamera(QWidget* parent, QRect rt, std::string type) : panel_(parent, rt, "")
|
||||
{
|
||||
panel_.setObjectName("MyPanel");
|
||||
std::string sty = "#MyPanel {background-color:rgb(8, 54, 91);border:1px solid rgba(255,255,255,10);border-radius:15px;}";
|
||||
panel_.setAutoFillBackground(true);
|
||||
panel_.setStyleSheet(sty.c_str());
|
||||
|
||||
QUI::label(labName_, &panel_, 10, 10, rt.width()-20, 30, "xxx监控点", "font:bold 16px; color:white;");
|
||||
QUI::labelImage(labVideo_, &panel_, 10, 40, rt.width()-20, rt.height()-50, "assets/ui/camera.png");
|
||||
}
|
||||
};
|
||||
|
||||
class PanelDeviceSecurity : public PanelDeviceDetail
|
||||
{
|
||||
public:
|
||||
std::vector<std::shared_ptr<PanelCardCamera>> vecCards_;
|
||||
|
||||
PanelDeviceSecurity(QWidget* parent, QRect rt) : PanelDeviceDetail(parent, rt)
|
||||
{
|
||||
int col = 6;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int W = 410;
|
||||
int H = 308;
|
||||
for (int i = 0; i<col; i++)
|
||||
{
|
||||
ReviseQueuePos(i, 3, W+50, H+50, x, y);
|
||||
auto card = std::make_shared<PanelCardCamera>(this, QRect(x+50, y+50, W, H), "");
|
||||
vecCards_.push_back(card);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static PanelDevice* g_activePanel_ = nullptr;
|
||||
class PanelDevice : public Panel
|
||||
{
|
||||
public:
|
||||
PanelDevice(QWidget* parent, QRect rt, std::string title) : Panel(parent, rt, title)
|
||||
{
|
||||
this->setBackground(QColor(29,54,102), "border:0px solid white; border-radius:5px;");
|
||||
}
|
||||
void setBackgroundStatus(int flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
this->setBackground(QColor(29, 100, 102), "border: 1px solid white;");
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setBackground(QColor(29, 54, 102), "border:0px solid white; border-radius:5px;");
|
||||
}
|
||||
}
|
||||
void setActive(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
g_activePanel_ = this;
|
||||
}
|
||||
setBackgroundStatus(flag);
|
||||
if (panelDetail_)
|
||||
{
|
||||
panelDetail_->setVisible(flag);
|
||||
}
|
||||
}
|
||||
virtual void enterEvent(QEvent* e) override
|
||||
{
|
||||
setBackgroundStatus(1);
|
||||
}
|
||||
virtual void leaveEvent(QEvent* e) override
|
||||
{
|
||||
if (g_activePanel_ != this)
|
||||
{
|
||||
setBackgroundStatus(0);
|
||||
}
|
||||
}
|
||||
void mousePressEvent(QMouseEvent* e) override
|
||||
{
|
||||
if (e->button() == Qt::LeftButton)
|
||||
{
|
||||
if (g_activePanel_ != this)
|
||||
{
|
||||
if (g_activePanel_) { g_activePanel_->setActive(false); }
|
||||
this->setActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setDetailPanel(std::shared_ptr<PanelDeviceDetail> panelDetail)
|
||||
{
|
||||
panelDetail_ = panelDetail;
|
||||
}
|
||||
|
||||
std::shared_ptr<PanelDeviceDetail> panelDetail_ = nullptr;
|
||||
};
|
||||
|
||||
WidgetPageRunning::WidgetPageRunning(QWidget* parent) : WidgetPage(parent)
|
||||
{
|
||||
// 设备类型Panel
|
||||
int H = 180;
|
||||
int i = 0;
|
||||
|
||||
//panel1_ = std::make_shared<PanelDevice>(this, QRect(10, 10+H*0, 380, H-10), "风电设备");
|
||||
//panel1_->setDetailPanel(std::make_shared<PanelDeviceWind>(this, QRect(400, 10, 1490, 900)));
|
||||
//panel1_->setActive(true);
|
||||
|
||||
panel2_ = std::make_shared<PanelDevice>(this, QRect(10, 10+H*(i++), 380, H-10), "光伏设备");
|
||||
panel2_->setDetailPanel(std::make_shared<PanelDeviceSolar>(this, QRect(400, 10, 1490, 900)));
|
||||
panel2_->setActive(false);
|
||||
|
||||
panel3_ = std::make_shared<PanelDevice>(this, QRect(10, 10+H*(i++), 380, H-10), "储能设备");
|
||||
panel3_->setDetailPanel(std::make_shared<PanelDeviceEnergyStorage>(this, QRect(400, 10, 1490, 900)));
|
||||
panel3_->setActive(false);
|
||||
|
||||
panel4_ = std::make_shared<PanelDevice>(this, QRect(10, 10+H*(i++), 380, H-10), "充电设备");
|
||||
panel4_->setDetailPanel(std::make_shared<PanelDeviceCharge>(this, QRect(400, 10, 1490, 900)));
|
||||
panel4_->setActive(false);
|
||||
|
||||
panel5_ = std::make_shared<PanelDevice>(this, QRect(10, 10+H*(i++), 380, H-10), "安防设备");
|
||||
panel5_->setDetailPanel(std::make_shared<PanelDeviceSecurity>(this, QRect(400, 10, 1490, 900)));
|
||||
panel5_->setActive(false);
|
||||
|
||||
panel2_->setActive(true);
|
||||
|
||||
//panelDevice_ = std::make_shared<Panel>(this, QRect(420, 10, 1490, 900), "");
|
||||
//{
|
||||
//}
|
||||
}
|
||||
23
src/widgets/pages/WidgetPageRunning.h
Normal file
23
src/widgets/pages/WidgetPageRunning.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "WidgetPage.h"
|
||||
|
||||
class PanelDevice;
|
||||
class PanelDeviceDetail;
|
||||
|
||||
class WidgetPageRunning : public WidgetPage
|
||||
{
|
||||
public:
|
||||
WidgetPageRunning(QWidget* parent);
|
||||
|
||||
std::shared_ptr<PanelDevice> panel1_;
|
||||
std::shared_ptr<PanelDevice> panel2_;
|
||||
std::shared_ptr<PanelDevice> panel3_;
|
||||
std::shared_ptr<PanelDevice> panel4_;
|
||||
std::shared_ptr<PanelDevice> panel5_;
|
||||
|
||||
std::shared_ptr<Panel> panelDevice_;
|
||||
|
||||
std::shared_ptr<PanelDeviceDetail> panelDeviceDetial_;
|
||||
|
||||
};
|
||||
54
src/widgets/pages/WidgetPageWeb.cpp
Normal file
54
src/widgets/pages/WidgetPageWeb.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "WidgetPageWeb.h"
|
||||
#include <iostream>
|
||||
|
||||
WidgetPageWeb::WidgetPageWeb(QWidget* parent, std::string name) : WidgetPage(parent)
|
||||
{
|
||||
wWebView = std::make_shared<QWebEngineView>(this);
|
||||
wWebView->setGeometry(0, 0, 1920, 900);
|
||||
|
||||
jsHandler = new JsHandler();
|
||||
|
||||
webChannel = new QWebChannel();
|
||||
// 注册C++对象到QWebChannel,这样远端的QWebChannel也会生成一个对应的JS对象
|
||||
// 在JS中引入 qwebchannel.js, 使用 channel.objects.webNative 获取注册的“webNative”
|
||||
webChannel->registerObject("webNative", jsHandler);
|
||||
wWebView->page()->setWebChannel(webChannel);
|
||||
wWebView->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
//webEngineView.load(QUrl("https://www.baidu.com"));
|
||||
|
||||
std::string url = "file:///assets/html/" + name + "/index.html";
|
||||
|
||||
std::cout << "===> url=" << url << std::endl;
|
||||
wWebView->load(QUrl(url.c_str()));
|
||||
|
||||
// 默认设置透明,解决加载过程中白屏
|
||||
wWebView->page()->setBackgroundColor(Qt::transparent);
|
||||
|
||||
// 加载进度
|
||||
connect(wWebView.get(), &QWebEngineView::loadProgress, [=](int progress)
|
||||
{
|
||||
//pWebEngineView->page()->setBackgroundColor(Qt::transparent);
|
||||
});
|
||||
|
||||
|
||||
connect(wWebView.get(), &QWebEngineView::loadFinished, this, &WidgetPageWeb::slotLoadFinished);
|
||||
connect(jsHandler, &JsHandler::signalShowWebView, this, &WidgetPageWeb::slotShowWebView);
|
||||
|
||||
//std::string htmlContent = "HelloWorld";
|
||||
//webEngineView.setHtml(htmlContent.c_str());
|
||||
wWebView->hide();
|
||||
|
||||
//webView = std::make_shared<WidgetWeb>(this);
|
||||
}
|
||||
|
||||
void WidgetPageWeb::slotLoadFinished(bool isOk)
|
||||
{
|
||||
//QString jsCode = QString("showalert('%1')").arg("Hello QtWebEngine!");
|
||||
//wWebView->page()->runJavaScript(jsCode, [](const QVariant& v) { qDebug() << v.toString(); });
|
||||
wWebView->show();
|
||||
}
|
||||
|
||||
void WidgetPageWeb::slotShowWebView()
|
||||
{
|
||||
wWebView->show();
|
||||
}
|
||||
57
src/widgets/pages/WidgetPageWeb.h
Normal file
57
src/widgets/pages/WidgetPageWeb.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "WidgetPage.h"
|
||||
|
||||
#include <QWebChannel>
|
||||
#include <QtWebEngineWidgets/QWebEngineView>
|
||||
|
||||
|
||||
class JsHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//Q_PROPERTY(QString nativeText READ nativeText MEMBER m_nativeText NOTIFY signalNativeTextChanged FINAL)
|
||||
explicit JsHandler(QObject* parent = nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
QString nativeText() const { return m_nativeText; }
|
||||
|
||||
signals:
|
||||
//在C++中定义的信号,可以在JS端监听此信号接收消息
|
||||
void signalNativeTextChanged(const QString& text);
|
||||
void signalShowWebView();
|
||||
|
||||
public slots:
|
||||
void showWebView()
|
||||
{
|
||||
emit signalShowWebView();
|
||||
}
|
||||
|
||||
//C++ 端的公共槽函数,可以在JS端调用。
|
||||
void setNativeText(const QString& text)
|
||||
{
|
||||
m_nativeText = text;
|
||||
qDebug() << QString("run JS call CPP: setNativeText:") << text;
|
||||
emit signalNativeTextChanged("HelloWorld");
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_nativeText;
|
||||
};
|
||||
|
||||
|
||||
class WidgetPageWeb : public WidgetPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
WidgetPageWeb(QWidget* parent, std::string name);
|
||||
|
||||
void slotLoadFinished(bool isOk);
|
||||
void slotShowWebView();
|
||||
|
||||
public:
|
||||
std::shared_ptr<QWebEngineView> wWebView = nullptr;
|
||||
QWebChannel* webChannel = nullptr;
|
||||
JsHandler* jsHandler = nullptr;
|
||||
};
|
||||
845
src/widgets/uihelper.cpp
Normal file
845
src/widgets/uihelper.cpp
Normal file
@@ -0,0 +1,845 @@
|
||||
#include "uihelper.h"
|
||||
|
||||
static QFont g_font("微软雅黑", 10);
|
||||
|
||||
std::string UiStyle::BTN =
|
||||
"QPushButton{background-color:rgba(150,150,150,80);border-radius:5px;font:bold 16px;color:white;border:2px solid gray;}"
|
||||
"QPushButton:hover{background-color:rgba(150,150,150,100);border:2px solid white;}"
|
||||
"QPushButton:pressed{border-width:3px 0 0 3px;border-style:inset;color:white;}";
|
||||
|
||||
std::shared_ptr<QLabel> QUI::label(QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty)
|
||||
{
|
||||
auto lab = std::make_shared<QLabel>(parent);
|
||||
lab->setGeometry(x, y, w, h);
|
||||
lab->setText(text.c_str());
|
||||
lab->setFont(g_font);
|
||||
if (!sty.empty())
|
||||
{
|
||||
lab->setStyleSheet(sty.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
lab->setStyleSheet("QLabel {color:white;}");
|
||||
}
|
||||
return lab;
|
||||
}
|
||||
|
||||
void QUI::label(QLabel& lab, QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty)
|
||||
{
|
||||
lab.setParent(parent);
|
||||
lab.setGeometry(x, y, w, h);
|
||||
lab.setText(text.c_str());
|
||||
lab.setFont(g_font);
|
||||
if (!sty.empty())
|
||||
{
|
||||
lab.setStyleSheet(sty.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
lab.setStyleSheet("QLabel {color:white;}");
|
||||
}
|
||||
}
|
||||
|
||||
void QUI::labelImage(QLabel& lab, QWidget* parent, int x, int y, int w, int h, std::string img)
|
||||
{
|
||||
lab.setParent(parent);
|
||||
lab.setGeometry(x, y, w, h);
|
||||
lab.setPixmap(QPixmap(img.c_str()));
|
||||
}
|
||||
|
||||
std::shared_ptr<LabelPairH> QUI::labelPair(QWidget* parent, int x, int y, int w, int h, int w1, std::string k, std::string v)
|
||||
{
|
||||
return std::make_shared<LabelPairH>(parent, QRect(x, y, w, h), w1, k, v);
|
||||
}
|
||||
|
||||
std::shared_ptr<LabelPairV> QUI::labelPairV(QWidget* parent, int x, int y, int w, int h, int h1, std::string k, std::string v)
|
||||
{
|
||||
auto labPair = std::make_shared<LabelPairV>(parent, QRect(x, y, w, h), h1, k, v);
|
||||
const std::string STY_VAL = "font:bold 18px;color:rgb(38,220,172);";
|
||||
labPair->setValStyle(STY_VAL);
|
||||
return labPair;
|
||||
}
|
||||
|
||||
void QUI::button(QPushButton& btn, QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty)
|
||||
{
|
||||
btn.setParent(parent);
|
||||
btn.setGeometry(x, y, w, h);
|
||||
btn.setText(text.c_str());
|
||||
btn.setFont(g_font);
|
||||
if (!sty.empty())
|
||||
{
|
||||
btn.setStyleSheet(sty.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
QPushButton* QUI::button(QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty/* = ""*/)
|
||||
{
|
||||
QPushButton* btn = new QPushButton(parent);
|
||||
btn->setGeometry(x, y, w, h);
|
||||
btn->setText(text.c_str());
|
||||
btn->setFont(g_font);
|
||||
if (!sty.empty())
|
||||
{
|
||||
btn->setStyleSheet(sty.c_str());
|
||||
}
|
||||
return btn;
|
||||
}
|
||||
|
||||
//std::shared_ptr<QComboBox> QUI::combox(QWidget* parent, int x, int y, int w, int h, std::vector<std::string>& items)
|
||||
//{
|
||||
// std::shared_ptr<QComboBox> comb = std::make_shared<QComboBox>(parent);
|
||||
// comb->setGeometry(x, y, w, h);
|
||||
// QStringList strlist;
|
||||
// for (auto& s: items)
|
||||
// {
|
||||
// strlist << s.c_str();
|
||||
// }
|
||||
// comb->insertItems(0, strlist);
|
||||
// return comb;
|
||||
//}
|
||||
|
||||
void QUI::combox(QComboBox& comb, QWidget* parent, int x, int y, int w, int h, std::vector<std::string> items, std::string v/* = ""*/)
|
||||
{
|
||||
comb.setParent(parent);
|
||||
comb.setGeometry(x, y, w, h);
|
||||
QStringList strlist;
|
||||
for (auto& s: items)
|
||||
{
|
||||
strlist << s.c_str();
|
||||
}
|
||||
comb.insertItems(0, strlist);
|
||||
if (!v.empty())
|
||||
{
|
||||
comb.setCurrentText(v.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void QUI::lineedit(QLineEdit& line, QWidget* parent, int x, int y, int w, int h)
|
||||
{
|
||||
line.setParent(parent);
|
||||
line.setGeometry(x, y, w, h);
|
||||
}
|
||||
|
||||
void QUI::setBackground(QWidget* w, std::string name, QColor color, std::string border)
|
||||
{
|
||||
if (!w) { return; }
|
||||
w->setObjectName(name.c_str());
|
||||
std::string sty = "#" + name + "{background-color:rgba("
|
||||
+ std::to_string(color.red())
|
||||
+ "," + std::to_string(color.green())
|
||||
+ "," + std::to_string(color.blue())
|
||||
+ "," + std::to_string(color.alpha())
|
||||
+ ");" + border + "}";
|
||||
w->setAutoFillBackground(true);
|
||||
w->setStyleSheet(sty.c_str());
|
||||
}
|
||||
|
||||
Panel::Panel(QWidget* parent, QRect rt, std::string title) : QWidget(parent)
|
||||
{
|
||||
this->setGeometry(rt);
|
||||
|
||||
// 设置背景色:方法一
|
||||
//QPalette palette(this->palette());
|
||||
//palette.setColor(QPalette::Background, QColor(29, 54, 102)); // 设置背景色
|
||||
//this->setAutoFillBackground(true);
|
||||
//this->setPalette(palette);
|
||||
|
||||
// 设置背景色:方法二
|
||||
//this->setObjectName("PanelBase");
|
||||
//this->setStyleSheet("#PanelBase{background-color:rgb(30,50,100);border-radius:5px;}");
|
||||
|
||||
// 设置背景色
|
||||
QUI::setBackground(this, "PanelBase", QColor(29, 54, 102, 50));
|
||||
setMouseTracking(true);
|
||||
if (!title.empty())
|
||||
{
|
||||
// 渐变
|
||||
std::string styBkg = "background-color:qlineargradient(x1:0,y1:0, x2:1,y2:0,stop:0 rgb(3,208,242),stop:0.9 rgba(3,208,242,0));";
|
||||
// background-color:rgba(3, 208, 242, 200);
|
||||
QUI::label(labBkg_, this, 10, 30, this->width()-20, 2, "", styBkg);
|
||||
QUI::label(labIcon_, this, 10, 7, 6, 16, "", "background-color:rgb(33, 255, 210);");
|
||||
QUI::label(labTitle_, this, 20, 5, this->width(), 20, title.c_str(), "color:rgb(99, 196, 216);font:bold 16px;");
|
||||
}
|
||||
|
||||
this->show();
|
||||
}
|
||||
|
||||
void Panel::setBackground(QColor color, std::string border)
|
||||
{
|
||||
QUI::setBackground(this, "PanelBase", color, border);
|
||||
}
|
||||
|
||||
ChartBarView::ChartBarView(QWidget* parent, QRect rt, int xfrag)
|
||||
: QChartView(parent)
|
||||
, xfrag_(xfrag)
|
||||
{
|
||||
QFont font("微软雅黑", 9);
|
||||
this->setGeometry(rt);
|
||||
QColor labColor(255, 255, 255);
|
||||
|
||||
QUI::label(labTitle_, this, 0, 0, this->width(), 24, "");
|
||||
labTitle_.setAlignment(Qt::AlignHCenter);
|
||||
labTitle_.setFont(QFont("微软雅黑", 12, 100));
|
||||
|
||||
this->setFont(QFont("微软雅黑", 8));
|
||||
chart_ = std::make_shared<QChart>();
|
||||
chart_->setTitleFont(font);
|
||||
chart_->setMargins(QMargins(0,0,0,0));
|
||||
//chart_->setAnimationOptions(QChart::SeriesAnimations); // 动画方式
|
||||
setChart(chart_.get());
|
||||
|
||||
// === 初始化序列 ==============================================================
|
||||
series_ = std::make_shared<QBarSeries>();
|
||||
series_->setBarWidth(0.8);
|
||||
chart_->addSeries(series_.get());
|
||||
|
||||
// === 初始化X轴 ==============================================================
|
||||
// 创建 X 轴并设置其分类标签
|
||||
QStringList ticksX;
|
||||
for (int i = 1; i <= xfrag; ++i) {
|
||||
ticksX << QString::number(i);
|
||||
}
|
||||
axisX_ = std::make_shared<QBarCategoryAxis>();
|
||||
axisX_->setLabelsColor(labColor); // 设置X轴的颜色
|
||||
axisX_->setGridLineVisible(false);
|
||||
axisX_->append(ticksX); // 将分类标签添加到 X 轴
|
||||
chart_->addAxis(axisX_.get(), Qt::AlignBottom); // 将 X 轴添加到图表底部
|
||||
series_->attachAxis(axisX_.get()); // 将柱状图系列与 X 轴关联
|
||||
|
||||
// === 初始化Y轴 ==============================================================
|
||||
axisYLeft_ = std::make_shared<QValueAxis>();
|
||||
axisYLeft_->setGridLineColor(QColor(200, 200, 200, 100));
|
||||
axisYLeft_->setTickCount(6);
|
||||
axisYLeft_->setRange(0, 10); // 设置 Y 轴的范围为 0 到 100
|
||||
chart_->addAxis(axisYLeft_.get(), Qt::AlignLeft); // 将 Y 轴添加到图表左侧
|
||||
series_->attachAxis(axisYLeft_.get()); // 将柱状图系列与 Y 轴关联
|
||||
axisYLeft_->setLabelsColor(labColor);
|
||||
|
||||
// 设置背景色
|
||||
this->setBackground(QColor(30, 50, 100, 50));
|
||||
|
||||
// === 初始化柱体 ==============================================================
|
||||
//QBarSet* set1 = new QBarSet("10/01");
|
||||
//for (int i = 1; i <= xfrag; ++i) { *set1 << i; }
|
||||
//series_->append(set1);
|
||||
//this->addBar("日换电次数1");
|
||||
//this->addBar("日换电次数2");
|
||||
//this->addBar("日换电次数3");
|
||||
//this->addBar("日换电次数4");
|
||||
|
||||
//// === 示例:更新bar的数据
|
||||
//set1->replace(0, 8);
|
||||
|
||||
//// === 示例:更新X轴
|
||||
//QStringList ticksX2;
|
||||
//for (int i = 1; i <= xfrag; ++i) {
|
||||
// ticksX2 << QString::number(100+i);
|
||||
//}
|
||||
//axisX_->setCategories(ticksX2);
|
||||
|
||||
chart_->axisX()->setLabelsFont(font);
|
||||
chart_->axisY()->setLabelsFont(font);
|
||||
chart_->axisX()->setTitleFont(font);
|
||||
chart_->axisY()->setTitleFont(font);
|
||||
|
||||
// 设置图例在图表中的位置
|
||||
// 参数1: 水平位置
|
||||
// 参数2: 垂直位置
|
||||
// 参数3: 对齐方式
|
||||
// , Qt::HorizontalAlignment::Right, Qt::VerticalAlignment::Top
|
||||
|
||||
// 附着图表
|
||||
//chart_->legend()->attachToChart();
|
||||
//// 位于图表上方
|
||||
//chart_->legend()->setAlignment(Qt::AlignTop);
|
||||
//// 位于图表下方
|
||||
//chart_->legend()->setAlignment(Qt::AlignBottom);
|
||||
//// 位于图表左侧
|
||||
//chart_->legend()->setAlignment(Qt::AlignLeft);
|
||||
//// 位于图表右侧
|
||||
//chart_->legend()->setAlignment(Qt::AlignRight);
|
||||
//// 不附着图表
|
||||
//chart_->legend()->detachFromChart();
|
||||
chart_->legend()->setFont(g_font);
|
||||
chart_->legend()->setLabelColor(labColor);
|
||||
chart_->legend()->setAlignment(Qt::AlignTop);
|
||||
//chart_->legend()->setGeometry(QRectF(50, 0, this->width(), 24));
|
||||
//chart_->legend()->update();
|
||||
}
|
||||
|
||||
void ChartBarView::setTitle(std::string title)
|
||||
{
|
||||
//chart_->setTitle(title.c_str());
|
||||
labTitle_.setText(title.c_str());
|
||||
labTitle_.setGeometry(0, 10, this->width(), 24);
|
||||
|
||||
QMargins margin;
|
||||
margin.setTop(40);
|
||||
chart_->setMargins(margin);
|
||||
chart_->legend()->setGeometry(QRectF(50, 20, this->width(), 24));
|
||||
}
|
||||
|
||||
std::shared_ptr<QChart> ChartBarView::chart()
|
||||
{
|
||||
return chart_;
|
||||
}
|
||||
|
||||
QBarSet& ChartBarView::addItem(std::string name)
|
||||
{
|
||||
int index = series_->barSets().size();
|
||||
QBarSet* barSet = new QBarSet(name.c_str());
|
||||
//bar初始化数据
|
||||
for (int i = 1; i <= xfrag_; ++i) { *barSet << 0; }
|
||||
//// === 示例:更新bar的数据
|
||||
//barSet->replace(0, 8);
|
||||
series_->append(barSet);
|
||||
chart_->legend()->setGeometry(QRectF(50, 0, this->width(), 24));
|
||||
return *barSet;
|
||||
}
|
||||
|
||||
void ChartBarView::updateItem(int index, std::vector<double>& vd)
|
||||
{
|
||||
QBarSet* barSet = this->getBar(index);
|
||||
if (barSet)
|
||||
{
|
||||
for (int i = 0; i < xfrag_ && i< vd.size(); ++i)
|
||||
{
|
||||
barSet->replace(i, vd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QBarSet* ChartBarView::getBar(int index)
|
||||
{
|
||||
auto lstBarSet = series_->barSets();
|
||||
if (index < lstBarSet.size())
|
||||
{
|
||||
return lstBarSet[index];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ChartBarView::setBackground(QColor& color)
|
||||
{
|
||||
//this->setAutoFillBackground(true);
|
||||
//QPalette palette;
|
||||
//palette.setColor(QPalette::Window, color); // 设置背景色
|
||||
//this->setPalette(palette);
|
||||
|
||||
QUI::setBackground(this, "ChartBarView", color);
|
||||
//this->setObjectName("ChartBarView");
|
||||
//this->setStyleSheet("#ChartBarView{background-color:rgb(29,54,102);border-radius:5px;}");
|
||||
|
||||
chart_->setBackgroundBrush(QBrush(QColor(100,100,100,0))); // 设置背景色
|
||||
chart_->setBackgroundVisible(true);
|
||||
}
|
||||
|
||||
void ChartBarView::setAxisXTick(std::vector<std::string>& vecTick)
|
||||
{
|
||||
QStringList ticks;
|
||||
for (int i = 0; i < xfrag_ && i<vecTick.size(); ++i) {
|
||||
ticks << vecTick[i].c_str();
|
||||
}
|
||||
axisX_->setCategories(ticks);
|
||||
}
|
||||
|
||||
ChartLineView::ChartLineView(QWidget* parent, QRect rt) : QChartView(parent)
|
||||
{
|
||||
QColor labColor(255, 255, 255);
|
||||
QUI::setBackground(this, "ChartLineView1", QColor(30, 50, 100, 50));
|
||||
this->setGeometry(rt);
|
||||
// 图表视图
|
||||
//QChartView* chartView = new QChartView(chart, wParent);
|
||||
|
||||
//this->setGeometry(10, 30, 900, 240);
|
||||
//this->setRenderHint(QPainter::Antialiasing); // 反锯齿绘制
|
||||
|
||||
// 图表
|
||||
chart_ = std::make_shared<QChart>();
|
||||
chart_->setBackgroundBrush(QBrush(QColor(100, 100, 100, 0))); // 设置背景色
|
||||
chart_->setBackgroundVisible(true);
|
||||
//chart_->setAnimationOptions(QChart::SeriesAnimations); // 动画方式
|
||||
//chart_->setTheme(QtCharts::QChart::ChartThemeBlueNcs); // 设置主题
|
||||
//chart_->setTitle("方位角数据"); // 设置标题
|
||||
chart_->setMargins(QMargins(0, 0, 0, 0));
|
||||
this->setChart(chart_.get());
|
||||
|
||||
QDateTime curDateTIme = QDateTime::currentDateTime();
|
||||
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
|
||||
|
||||
// x轴(时间轴方式)
|
||||
axisX = std::make_shared<QDateTimeAxis>();
|
||||
axisX->setLabelsColor(labColor);
|
||||
//axisX->setTitleText("时间(分:秒)"); // x轴显示标题
|
||||
axisX->setGridLineVisible(false); // 隐藏背景网格X轴框线
|
||||
axisX->setFormat("hh:mm"); // x轴格式
|
||||
axisX->setLabelsAngle(0); // x轴显示的文字倾斜角度
|
||||
axisX->setTickCount(10); // 轴上点的个数
|
||||
axisX->setRange(curDateTIme, curDateTIme.addSecs(10)); // 范围
|
||||
axisX->setLabelsFont(QFont("微软雅黑", 9));
|
||||
|
||||
// y轴
|
||||
axisY = std::make_shared<QValueAxis>();
|
||||
axisY->setGridLineColor(QColor(200, 200, 200, 100));
|
||||
axisY->setLabelsColor(labColor);
|
||||
//AxisY->setTitleText("角度"); // y轴显示标题
|
||||
axisY->setRange(0, 20); // 范围
|
||||
axisY->setTickCount(6); // 轴上点的个数
|
||||
axisY->setGridLineVisible(true); // 背景网格Y轴框线
|
||||
axisY->setLabelsFont(QFont("微软雅黑", 9));
|
||||
|
||||
chart_->addAxis(axisX.get(), Qt::AlignBottom); // 设置x轴位置
|
||||
chart_->addAxis(axisY.get(), Qt::AlignLeft); // 设置y轴位置
|
||||
|
||||
// 图例
|
||||
//chart_->legend()->detachFromChart();
|
||||
chart_->legend()->setFont(g_font);
|
||||
chart_->legend()->setLabelColor(labColor);
|
||||
chart_->legend()->setVisible(true); // 图例显示
|
||||
chart_->legend()->setAlignment(Qt::AlignTop); // 图例向下居中
|
||||
}
|
||||
|
||||
void ChartLineView::addItem(std::string name)
|
||||
{
|
||||
auto series = std::make_shared< QLineSeries>();
|
||||
chart_->addSeries(series.get()); // 添加线段
|
||||
series->attachAxis(axisX.get()); // 线段依附的x轴
|
||||
series->attachAxis(axisY.get()); // 线段依附的y轴
|
||||
series->setName(name.c_str()); // 线段名称,在图例会显示
|
||||
vecSeries_.push_back(series);
|
||||
//series->setPen(QPen(Qt::red, 0.6, Qt::SolidLine)); // 设置线段pen
|
||||
}
|
||||
|
||||
//#include "common/TimeUtils.h"
|
||||
void ChartLineView::updateItem(int index, std::vector<std::pair<double, double>>& vd)
|
||||
{
|
||||
if (index >= vecSeries_.size()) { return; }
|
||||
|
||||
auto& series = vecSeries_[index];
|
||||
series->clear();
|
||||
for (int i = 0; i < vd.size(); ++i)
|
||||
{
|
||||
series->append(vd[i].first, vd[i].second);
|
||||
}
|
||||
|
||||
//int64_t t0 = TimeUtils::datetime2tms(TimeUtils::now_date() + " 00:00:00");
|
||||
//int64_t tx = t0;
|
||||
//for (int i = 0; i<=240; i++)
|
||||
//{
|
||||
// tx = t0 + (i*360)*1000;
|
||||
// series->append(tx, qrand()%18);
|
||||
//}
|
||||
//this->setAxisX(t0, tx, 13);
|
||||
//this->setAxisYLeft(0, 20, 6);
|
||||
|
||||
//QDateTime t0 = QDateTime::fromString("2024-11-28 00:00:00", "yyyy-MM-dd hh:mm:ss");
|
||||
//QDateTime tx;
|
||||
//for (int i = 0; i<=240; i++)
|
||||
//{
|
||||
// tx = t0.addSecs(i*360);
|
||||
// series->append(tx.toMSecsSinceEpoch(), qrand()%18);
|
||||
//}
|
||||
//this->setAxisX(t0.toMSecsSinceEpoch(), tx.toMSecsSinceEpoch(), 13);
|
||||
//this->setAxisYLeft(0, 20, 6);
|
||||
}
|
||||
void ChartLineView::setAxisX(double min, double max, int tickCount, std::string fmt)
|
||||
{
|
||||
axisX->setRange(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); // 范围
|
||||
axisX->setTickCount(tickCount); // 轴上点的个数
|
||||
axisX->setFormat(fmt.c_str());
|
||||
}
|
||||
|
||||
void ChartLineView::setAxisYLeft(double min, double max, double tickCount, std::string fmt)
|
||||
{
|
||||
axisY->setRange(min, max);
|
||||
axisY->setTickCount(tickCount);
|
||||
axisY->setLabelFormat(fmt.c_str());
|
||||
}
|
||||
|
||||
ProgressView::ProgressView(QWidget* parent, int x, int y, int h, int w, int d, int n)
|
||||
: QWidget(parent)
|
||||
, num_(n)
|
||||
{
|
||||
this->setGeometry(x, y, (w+d)*num_+4+42, h);
|
||||
this->show();
|
||||
vecBar_.resize(num_);
|
||||
|
||||
const std::string STY_LAB = "font:bold 14px;color:white;";
|
||||
|
||||
QUI::label(labBarBkg_, this, 0, 0, width(), height(), "", "border-width:1px;border-style:solid;border-color:rgba(40,169,222,255);");
|
||||
for (int i = 0; i < num_; i++)
|
||||
{
|
||||
vecBar_[i] = QUI::label(this, 2+i*(w+d), 2, w, height() - 4, "", "background-color:rgba(255,255,255,30);");
|
||||
}
|
||||
QUI::label(labVal_, this, width()-42, 0, 40, height(), "100%", STY_LAB);
|
||||
//labVal_.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
void ProgressView::setVal(int v)
|
||||
{
|
||||
if (v<0) { v = 0; }
|
||||
if (v>100) { v = 100; }
|
||||
labVal_.setText(QString::number(v) + "%");
|
||||
float c = float(v)*0.01;
|
||||
int index = c*float(num_) - 1;
|
||||
for (int i = 0; i<num_; i++)
|
||||
{
|
||||
int r = 0 + 255.0f*float(i)/float(num_);
|
||||
int g = 255 - 255.0f*float(i)/float(num_);
|
||||
std::string strColor = "background-color:rgba(" + std::to_string(r) + "," + std::to_string(g) + ",0,255);";
|
||||
vecBar_[i]->setStyleSheet(index>=i ? strColor.c_str() : "background-color:rgba(255,255,255,30);");
|
||||
}
|
||||
}
|
||||
|
||||
LabelPairV::LabelPairV(QWidget* parent, QRect rt, int h, std::string k, std::string v)
|
||||
{
|
||||
QUI::label(labV_, parent, rt.x(), rt.y(), rt.width(), h, v);
|
||||
QUI::label(labK_, parent, rt.x(), rt.y()+h, rt.width(), rt.height()-h, k);
|
||||
labV_.setAlignment(Qt::AlignCenter);
|
||||
labK_.setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
void LabelPairV::setVal(std::string v, std::string sty/* = ""*/)
|
||||
{
|
||||
labV_.setText(v.c_str());
|
||||
if (!sty.empty()) { labV_.setStyleSheet(sty.c_str()); }
|
||||
}
|
||||
void LabelPairV::setValStyle(std::string sty)
|
||||
{
|
||||
labV_.setStyleSheet(sty.c_str());
|
||||
}
|
||||
void LabelPairV::setKeyStyle(std::string sty)
|
||||
{
|
||||
labK_.setStyleSheet(sty.c_str());
|
||||
}
|
||||
void LabelPairV::setStyle(std::string styK, std::string styV /*= ""*/)
|
||||
{
|
||||
this->setKeyStyle(styK);
|
||||
this->setValStyle(styV);
|
||||
}
|
||||
|
||||
LabelPairH::LabelPairH(QWidget* parent, QRect rt, int w, std::string k, std::string v)
|
||||
{
|
||||
QUI::label(labK_, parent, rt.x(), rt.y(), w, rt.height(), k);
|
||||
QUI::label(labV_, parent, rt.x()+w, rt.y(), rt.width()-w, rt.height(), v);
|
||||
}
|
||||
|
||||
void LabelPairH::setVal(std::string v, std::string sty/* = ""*/)
|
||||
{
|
||||
labV_.setText(v.c_str());
|
||||
if (!sty.empty()) { labV_.setStyleSheet(sty.c_str()); }
|
||||
}
|
||||
|
||||
void LabelPairH::setValStyle(std::string sty)
|
||||
{
|
||||
labV_.setStyleSheet(sty.c_str());
|
||||
}
|
||||
|
||||
void LabelPairH::setKeyStyle(std::string sty)
|
||||
{
|
||||
labK_.setStyleSheet(sty.c_str());
|
||||
}
|
||||
void LabelPairH::setStyle(std::string styK, std::string styV /*= ""*/)
|
||||
{
|
||||
this->setKeyStyle(styK);
|
||||
this->setValStyle(styV);
|
||||
}
|
||||
|
||||
static const std::string STY_TAB_BTN = R"(
|
||||
QPushButton { background-color:rgb(240,120,0);border-radius:0px;font:bold 14px;color:white;border:1px solid #20a481; }
|
||||
QPushButton:hover { background-color:rgba(32,164,128,255);color:white; }
|
||||
QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;color:white;}
|
||||
)";
|
||||
|
||||
static const std::string STY_TAB = R"(
|
||||
QTableWidget
|
||||
{
|
||||
background-color:rgb(37, 89, 120);
|
||||
alternate-background-color:rgb(57, 103, 130);
|
||||
color:white;
|
||||
font:bold 13px;
|
||||
selection-background-color:rgba(53, 125, 203, 100);
|
||||
}
|
||||
QTableWidget::item {padding-left:0px;text-align:center;color:rgba(255,255,255,200);}
|
||||
QTableWidget::item:selected {color:#FFFFFF; background: rgba(53, 125, 203,100);}
|
||||
)";
|
||||
|
||||
|
||||
//QTableWidget::item:hover
|
||||
//{
|
||||
// color:#FFFFFF;
|
||||
// background: #4B4B4D;
|
||||
//}
|
||||
|
||||
//QHeaderView::section,QTableCornerButton:section
|
||||
//{
|
||||
// text-align:center;
|
||||
// padding:3px;
|
||||
// margin:0px;
|
||||
// color:#DCDCDC;
|
||||
// border:1px solid #242424;
|
||||
// border-left-width:0px;
|
||||
// border-right-width:1px;
|
||||
// border-top-width:0px;
|
||||
// border-bottom-width:1px;
|
||||
// background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #646464,stop:1 #525252);
|
||||
// }
|
||||
//QHeaderView::section:selected
|
||||
//{
|
||||
// color:#FFFFFF;
|
||||
// border:1px solid #242424;
|
||||
//}
|
||||
//QScrollBar:vertical{
|
||||
// width:8px;
|
||||
// border-style:flat;
|
||||
// border-radius: 4px;
|
||||
// border:0px;
|
||||
// background: #19191A;
|
||||
//}
|
||||
//QScrollBar::handle:vertical{
|
||||
// background: rgba(255,255,255,0.50);
|
||||
// border-radius: 4px;
|
||||
// width:8px;
|
||||
// min-height:91px;
|
||||
// border-style:flat;
|
||||
//}
|
||||
//QScrollBar::handle:vertical::hover{
|
||||
// background: rgba(255,255,255,0.90);
|
||||
// border-radius: 4px;
|
||||
// width:8px;
|
||||
//}
|
||||
//QScrollBar::handle:vertical::pressed{
|
||||
// background: rgba(255,255,255,0.90);
|
||||
// border-radius:4px;
|
||||
// width:8px;
|
||||
//}
|
||||
//QScrollBar::sub-page:vertical {
|
||||
// background: #19191A;
|
||||
//border-style:flat;
|
||||
//}
|
||||
//QScrollBar::add-page:vertical {
|
||||
// background: #19191A;
|
||||
//border-style:flat;
|
||||
//}
|
||||
//QScrollBar::add-line:vertical{
|
||||
// background: #19191A;
|
||||
//}
|
||||
//QScrollBar::sub-line:vertical {
|
||||
// background: #19191A;
|
||||
//}
|
||||
//QScrollBar:horizontal{
|
||||
// height:8px;
|
||||
// border-style:flat;
|
||||
// border-radius: 4px;
|
||||
// border:0px;
|
||||
//background: #19191A;
|
||||
//}
|
||||
//QScrollBar::handle:horizontal{
|
||||
// background: rgba(255,255,255,0.50);
|
||||
// border-radius: 4px;
|
||||
// height:8px;
|
||||
// min-width:91px;
|
||||
// border-style:flat;
|
||||
//}
|
||||
//QScrollBar::handle:horizontal::hover{
|
||||
// background: rgba(255,255,255,0.90);
|
||||
// border-radius: 4px;
|
||||
// height:8px;
|
||||
//}
|
||||
//QScrollBar::handle:horizontal::pressed{
|
||||
// background: rgba(255,255,255,0.90);
|
||||
// border-radius:4px;
|
||||
// height:8px;
|
||||
//}
|
||||
//QScrollBar::sub-page:horizontal {
|
||||
// background: #19191A;
|
||||
// border-style:flat;
|
||||
//}
|
||||
//QScrollBar::add-page:horizontal {
|
||||
// background: #19191A;
|
||||
// border-style:flat;
|
||||
//}
|
||||
//QScrollBar::sub-line:horizontal {
|
||||
// background: #19191A;
|
||||
//}
|
||||
//QScrollBar::add-line:horizontal{
|
||||
// background: #19191A;
|
||||
//}
|
||||
|
||||
static const std::string STY_TAB_HEADER = R"(
|
||||
QHeaderView {background:rgb(46,53,97); font:bold 15px;}
|
||||
QHeaderView::section {background:rgb(46,53,97);color:white;border:1px solid gray;}
|
||||
)";
|
||||
|
||||
TableBase::TableBase(QWidget* parent, int rowMax, int colMax)
|
||||
{
|
||||
widget_ = std::make_shared<QTableWidget>(rowMax, colMax, parent);
|
||||
//this->setItemDelegate(new MyTableItemDelegate(this));
|
||||
|
||||
// "alternate-background-color:rgb(11,231,255);background-color:rgb(222,191,255);"
|
||||
widget_->setStyleSheet(STY_TAB.c_str());
|
||||
// 交替颜色
|
||||
widget_->setAlternatingRowColors(true);
|
||||
// 单元格编辑()
|
||||
widget_->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
// 选中一行
|
||||
widget_->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
// === 水平表头
|
||||
auto horiHeader = widget_->horizontalHeader();
|
||||
horiHeader->setFixedHeight(40);
|
||||
horiHeader->setStyleSheet(STY_TAB_HEADER.c_str());
|
||||
|
||||
// === 垂直表头
|
||||
auto vertHeader = widget_->verticalHeader();
|
||||
// 隐藏垂直表头
|
||||
vertHeader->setVisible(false);
|
||||
// 设置默认行高
|
||||
vertHeader->setDefaultSectionSize(32);
|
||||
}
|
||||
|
||||
TableBase::~TableBase()
|
||||
{
|
||||
widget_->clearContents();
|
||||
}
|
||||
|
||||
void TableBase::setGeometry(int x, int y, int w, int h)
|
||||
{
|
||||
if (widget_)
|
||||
{
|
||||
widget_->setGeometry(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
void TableBase::setHeaderH(std::vector<std::string> vecHeader)
|
||||
{
|
||||
widget_->setColumnCount(vecHeader.size());
|
||||
QStringList strList;
|
||||
for (int i = 0; i<vecHeader.size(); ++i) { strList << vecHeader[i].c_str(); }
|
||||
widget_->setHorizontalHeaderLabels(strList);
|
||||
}
|
||||
|
||||
void TableBase::setHeaderWidth(std::vector<int> vecWidth)
|
||||
{
|
||||
for (int i = 0; i<vecWidth.size(); ++i)
|
||||
{
|
||||
if (vecWidth[i] > 0)
|
||||
{
|
||||
widget_->setColumnWidth(i, vecWidth[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TableBase::setOperate(std::vector<std::string> vecOperate, std::function<void(int, std::string)> cb)
|
||||
{
|
||||
cbOper_ = cb;
|
||||
vecOperate_ = vecOperate;
|
||||
//if (vecOperate_.size() > 0)
|
||||
{
|
||||
int colCount = widget_->columnCount();
|
||||
widget_->setColumnCount(colCount + 1);
|
||||
widget_->setHorizontalHeaderItem(colCount, new QTableWidgetItem("操作"));
|
||||
widget_->horizontalHeader()->setSectionResizeMode(colCount, QHeaderView::Stretch);
|
||||
}
|
||||
}
|
||||
|
||||
void TableBase::setRowData(int row, std::vector<std::string> vd)
|
||||
{
|
||||
int rowCount = widget_->rowCount();
|
||||
if (row >= rowCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int dataColCount = widget_->columnCount();
|
||||
if (vecOperate_.size() > 0)
|
||||
{
|
||||
dataColCount--;
|
||||
// 创建操作按钮
|
||||
if (vecWidgetOper_.size() != rowCount)
|
||||
{
|
||||
vecWidgetOper_.resize(rowCount, NULL);
|
||||
}
|
||||
std::shared_ptr<QWidget> wOpt = vecWidgetOper_[row];
|
||||
if (!wOpt)
|
||||
{
|
||||
wOpt = std::make_shared<QWidget>();
|
||||
wOpt->setMaximumSize(QSize(400, 40));
|
||||
vecWidgetOper_[row] = wOpt;
|
||||
|
||||
for (int i = 0; i<vecOperate_.size(); i++)
|
||||
{
|
||||
std::string operText = vecOperate_[i];
|
||||
QPushButton* btn = QUI::button(wOpt.get(), 5+85*i, 5, 80, 24, operText, UiStyle::BTN);
|
||||
QObject::connect(btn, &QPushButton::clicked, widget_.get(), [=]() { this->onOperate(row, operText); });
|
||||
}
|
||||
widget_->setCellWidget(row, dataColCount, wOpt.get());
|
||||
}
|
||||
}
|
||||
for (int col = 0; col<dataColCount; col++)
|
||||
{
|
||||
if (col < vd.size())
|
||||
{
|
||||
QTableWidgetItem* item = widget_->item(row, col);
|
||||
if (!item)
|
||||
{
|
||||
item = new QTableWidgetItem();
|
||||
widget_->setItem(row, col, item);
|
||||
}
|
||||
item->setText(vd[col].c_str());
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TableBase::clear()
|
||||
{
|
||||
if (!widget_) { return; }
|
||||
widget_->clearContents();
|
||||
vecWidgetOper_.clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<QTableWidget> TableBase::widget()
|
||||
{
|
||||
return widget_;
|
||||
}
|
||||
|
||||
void TableBase::onOperate(int row, std::string oper)
|
||||
{
|
||||
auto curItem = widget_->item(row, 0);
|
||||
widget_->setCurrentItem(curItem);
|
||||
|
||||
if (cbOper_) { cbOper_(row, oper); }
|
||||
|
||||
//curItem->setFlags(curItem->flags() | Qt::ItemIsEditable);
|
||||
//QPushButton* btn = qobject_cast<QPushButton*>(sender());
|
||||
//std::string text = btn->text().toStdString();
|
||||
}
|
||||
|
||||
PageCtrl::PageCtrl(QWidget* parent, QRect rt, int pageSize) : QWidget(parent), pageSize_(pageSize)
|
||||
{
|
||||
this->setGeometry(rt);
|
||||
QUI::setBackground(this, "PageCtrl", QColor(255, 0, 0, 30));
|
||||
|
||||
int x = 10;
|
||||
QUI::label(labTotal_, this, x, 5, 100, 24, "共0条");
|
||||
QUI::button(btnFirst_, this, x += 110, 5, 60, 24, "首页");
|
||||
QUI::button(btnPrev_, this, x += 70, 5, 60, 24, "上一页");
|
||||
QUI::label(labPage_, this, x += 70, 5, 100, 25, "0/0");
|
||||
QUI::button(btnNext_, this, x += 110, 5, 60, 24, "下一页");
|
||||
QUI::button(btnLast_, this, x += 70, 5, 60, 24, "尾页");
|
||||
|
||||
labPage_.setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
void PageCtrl::setPage(int pageId, int total)
|
||||
{
|
||||
curPage_ = pageId;
|
||||
int pageCount = total/pageSize_;
|
||||
if (total%pageSize_ > 0) { pageCount++; }
|
||||
|
||||
std::string s = "共" + std::to_string(total) + "条";
|
||||
labTotal_.setText(s.c_str());
|
||||
|
||||
s = std::to_string(curPage_) + "/" + std::to_string(pageCount);
|
||||
labPage_.setText(s.c_str());
|
||||
}
|
||||
207
src/widgets/uihelper.h
Normal file
207
src/widgets/uihelper.h
Normal file
@@ -0,0 +1,207 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QtCharts/QChart>
|
||||
#include <QChartView>
|
||||
#include <QBarSeries>
|
||||
#include <QBarSet>
|
||||
#include <QBarCategoryAxis>
|
||||
#include <QValueAxis>
|
||||
#include <QDateTimeAxis>
|
||||
#include <QDateTime>
|
||||
#include <QLineSeries>
|
||||
#include <QSplineSeries>
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QHeaderView>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
|
||||
using namespace QtCharts;
|
||||
|
||||
using MapLabelPair = std::map<std::string, std::pair<std::shared_ptr<QLabel>, std::shared_ptr<QLabel>>>;
|
||||
|
||||
class LabelPairH;
|
||||
class LabelPairV;
|
||||
|
||||
class UiStyle
|
||||
{
|
||||
public:
|
||||
static std::string BTN;
|
||||
};
|
||||
|
||||
class QUI
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<QLabel> label(QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty="");
|
||||
|
||||
static void label(QLabel& lab, QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty = "");
|
||||
|
||||
static void labelImage(QLabel& lab, QWidget* parent, int x, int y, int w, int h, std::string img);
|
||||
|
||||
static std::shared_ptr<LabelPairH> labelPair(QWidget* parent, int x, int y, int w, int h, int w1, std::string k, std::string v="");
|
||||
static std::shared_ptr<LabelPairV> labelPairV(QWidget* parent, int x, int y, int w, int h, int h1, std::string k, std::string v = "");
|
||||
|
||||
static void button(QPushButton& btn, QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty = "");
|
||||
static QPushButton* button(QWidget* parent, int x, int y, int w, int h, std::string text, std::string sty = "");
|
||||
|
||||
//static std::shared_ptr<QComboBox> combox(QWidget* parent, int x, int y, int w, int h, std::vector<std::string>& items);
|
||||
|
||||
static void combox(QComboBox& comb, QWidget* parent, int x, int y, int w, int h, std::vector<std::string> items, std::string v="");
|
||||
|
||||
static void lineedit(QLineEdit& line, QWidget* parent, int x, int y, int w, int h);
|
||||
|
||||
static void setBackground(QWidget* w, std::string name, QColor color=QColor(29, 54, 102), std::string border="border-radius:5px;");
|
||||
};
|
||||
|
||||
class Panel : public QWidget
|
||||
{
|
||||
public:
|
||||
Panel(QWidget* parent, QRect rt, std::string title="");
|
||||
void setBackground(QColor color, std::string border="border-radius:1px;border:1px solid gray;");
|
||||
QLabel labBkg_;
|
||||
QLabel labIcon_;
|
||||
QLabel labTitle_;
|
||||
};
|
||||
|
||||
|
||||
class ChartBarView : public QChartView
|
||||
{
|
||||
public:
|
||||
ChartBarView(QWidget* parent, QRect rt, int xfrag=5);
|
||||
|
||||
void setTitle(std::string title);
|
||||
|
||||
std::shared_ptr<QChart> chart();
|
||||
|
||||
QBarSet& addItem(std::string name);
|
||||
void updateItem(int index, std::vector<double>& vd);
|
||||
QBarSet* getBar(int index);
|
||||
|
||||
void setBackground(QColor& color);
|
||||
|
||||
void setAxisXTick(std::vector<std::string>& vecTick);
|
||||
|
||||
public:
|
||||
std::shared_ptr<QChart> chart_;
|
||||
std::shared_ptr<QBarSeries> series_;
|
||||
|
||||
// X轴
|
||||
std::shared_ptr<QBarCategoryAxis> axisX_;
|
||||
// Y轴左侧
|
||||
std::shared_ptr<QValueAxis> axisYLeft_;
|
||||
|
||||
int xfrag_;
|
||||
|
||||
QLabel labTitle_;
|
||||
};
|
||||
|
||||
class ChartLineView : QChartView
|
||||
{
|
||||
public:
|
||||
ChartLineView(QWidget* parent, QRect rt);
|
||||
void setAxisX(double min, double max, int tickCount, std::string fmt = "hh:mm");
|
||||
void setAxisYLeft(double min, double max, double tickCount, std::string fmt = "%0.1f");
|
||||
void addItem(std::string name);
|
||||
void updateItem(int index, std::vector<std::pair<double, double>>& vd);
|
||||
private:
|
||||
std::shared_ptr<QChart> chart_;
|
||||
std::shared_ptr<QDateTimeAxis> axisX;
|
||||
std::shared_ptr<QValueAxis> axisY;
|
||||
std::vector<std::shared_ptr<QLineSeries>> vecSeries_;
|
||||
};
|
||||
|
||||
class ProgressView : public QWidget
|
||||
{
|
||||
public:
|
||||
ProgressView(QWidget* parent, int x, int y, int h, int w=3, int d=1, int n=50);
|
||||
void setVal(int v);
|
||||
|
||||
int num_;
|
||||
QLabel labVal_;
|
||||
QLabel labBarBkg_;
|
||||
std::vector<std::shared_ptr<QLabel>> vecBar_;
|
||||
};
|
||||
|
||||
class LabelPairV
|
||||
{
|
||||
public:
|
||||
LabelPairV(QWidget* parent, QRect rt, int w, std::string k, std::string v);
|
||||
void setVal(std::string v, std::string sty = "");
|
||||
void setValStyle(std::string sty);
|
||||
void setKeyStyle(std::string sty);
|
||||
void setStyle(std::string styK, std::string styV = "");
|
||||
QLabel labK_;
|
||||
QLabel labV_;
|
||||
};
|
||||
|
||||
class LabelPairH
|
||||
{
|
||||
public:
|
||||
LabelPairH(QWidget* parent, QRect rt, int w, std::string k, std::string v);
|
||||
void setVal(std::string v, std::string sty="");
|
||||
void setValStyle(std::string sty);
|
||||
void setKeyStyle(std::string sty);
|
||||
void setStyle(std::string styK, std::string styV="");
|
||||
QLabel labK_;
|
||||
QLabel labV_;
|
||||
};
|
||||
|
||||
|
||||
class TableBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableBase(QWidget* parent, int rowMax, int colMax);
|
||||
|
||||
~TableBase();
|
||||
|
||||
void setGeometry(int x, int y, int w, int h);
|
||||
|
||||
void setHeaderH(std::vector<std::string> vecHeader);
|
||||
|
||||
void setHeaderWidth(std::vector<int> vecWidth);
|
||||
|
||||
void setOperate(std::vector<std::string> vecOperate, std::function<void(int, std::string)> cb);
|
||||
|
||||
void setRowData(int row, std::vector<std::string> vd);
|
||||
|
||||
void clear();
|
||||
|
||||
std::shared_ptr<QTableWidget> widget();
|
||||
|
||||
public:
|
||||
void onOperate(int row, std::string oper);
|
||||
|
||||
private:
|
||||
std::vector<std::string> vecOperate_;
|
||||
std::vector<std::shared_ptr<QWidget>> vecWidgetOper_;
|
||||
std::function<void(int, std::string)> cbOper_ = nullptr;
|
||||
std::shared_ptr<QTableWidget> widget_;
|
||||
};
|
||||
|
||||
class PageCtrl : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PageCtrl(QWidget* parent, QRect rt, int pageSize=10);
|
||||
void setPage(int pageId, int total);
|
||||
|
||||
int pageSize_ = 0;
|
||||
int curPage_ = 0;
|
||||
|
||||
QLabel labTotal_;
|
||||
QLabel labPage_;
|
||||
|
||||
QPushButton btnPrev_;
|
||||
QPushButton btnNext_;
|
||||
QPushButton btnFirst_;
|
||||
QPushButton btnLast_;
|
||||
};
|
||||
Reference in New Issue
Block a user