实现系统管理表格操作接口、分页操作

This commit is contained in:
lixiaoyuan
2025-08-22 19:06:50 +08:00
parent 7e965b6fb4
commit 7fe51ea362
56 changed files with 2234 additions and 1304 deletions

View File

@@ -5,7 +5,7 @@
#include "pv/pages/MaskPageStat.h"
#include "pv/pages/MaskPageSysmgr.h"
#include "common/DataFields.h"
#include "common/Fields.h"
#include <iostream>
#include <iomanip>
#include <ctime>
@@ -24,14 +24,14 @@ std::string GetDateTimeWeekday()
int MaskMain::initUI()
{
pvSetStyleSheet(p, PV_ID_MAIN, "color: white; font: normal 14px \"微软雅黑\";");
//pvSetStyleSheet(p, PV_ID_MAIN, "color: white; font: normal 14px \"微软雅黑\";");
ui.bkg = PvApp::pvid(p);
PvApp::image(p, 0, 0, 0, 1920, 1080, "bkg.png");
ui.datetime = PvApp::label(p, PV_ID_MAIN, 10, 30, 420, 30, GetDateTimeWeekday(), "font: bold 18px;");
ui.datetime = PvApp::label(p, PV_ID_MAIN, 10, 30, 420, 30, GetDateTimeWeekday(), qss::label(20));
pvSetAlignment(p, ui.datetime, AlignCenter);
int idStationTitle = PvApp::label(p, 0, 620, 0, 660, 90, "能源站监控与运行管理系统", "font:bold 48px \"Microsoft YaHei\"; color:white");
int idStationTitle = PvApp::label(p, 0, 620, 0, 660, 90, "能源站监控与运行管理系统", qss::label(48));
pvSetAlignment(p, idStationTitle, AlignCenter);
// 初始化子页面
@@ -82,7 +82,7 @@ int MaskMain::initUI()
std::string& title = vecMenuItems[i];
EPvCode statusTmp = PvApp::getPvCode(title);
int x = x0 + (w+margin)*i;
int id = PvApp::button(p, 0, x, y, w, h, title, (statusTmp == pvcode_) ? STYLE_BTN_ACTIVE : STYLE_BTN);
int id = PvApp::button(p, 0, x, y, w, h, title, (statusTmp == pvcode_) ? qss::BTN_ACTIVE : qss::BTN);
mapMenuInfo_[id] = std::make_pair(title, statusTmp);
}
}

View File

@@ -102,10 +102,8 @@ int PvApp::label(PARAM* p, int parent, int x, int y, int w, int h, std::string t
int id = PvApp::pvid(p);
pvQLabel(p, id, parent);
pvSetGeometry(p, id, x, y, w, h);
pvSetFont(p, id, FONT_NAME, 14, 1, 0, 0, 0);
pvSetFontColor(p, id, 255, 255, 255);
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); }
pvSetStyleSheet(p, id, qss.empty() ? qss::label().c_str() : qss.c_str());
return id;
}
int PvApp::labelAlignCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
@@ -120,10 +118,8 @@ int PvApp::button(PARAM* p, int parent, int x, int y, int w, int h, std::string
int id = PvApp::pvid(p);
pvQPushButton(p, id, parent);
pvSetGeometry(p, id, x, y, w, h);
pvSetFont(p, id, FONT_NAME, 14, 1, 0, 0, 0);
pvSetFontColor(p, id, 255, 255, 255);
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); }
pvSetStyleSheet(p, id, qss.empty() ? qss::button().c_str() : qss.c_str());
return id;
}
@@ -141,7 +137,7 @@ int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::v
int id = PvApp::pvid(p);
pvQComboBox(p, id, parent, 0, 0);
pvSetGeometry(p, id, x, y, w, h);
pvSetStyleSheet(p, id, QSS_COMBOX_14.c_str());
pvSetStyleSheet(p, id, qss::COMBOX_14.c_str());
for (int i=0; i<vecItems.size(); ++i)
{
pvInsertItem(p, id, i, NULL, vecItems[i].c_str());
@@ -155,7 +151,20 @@ int PvApp::lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::strin
int id = PvApp::pvid(p);
pvQLineEdit(p, id, parent);
pvSetGeometry(p, id, x, y, w, h);
pvSetStyleSheet(p, id, QSS_LINEEDIT.c_str());
pvSetStyleSheet(p, id, qss::LINEEDIT.c_str());
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
return id;
}
int PvApp::textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss)
{
static std::string qssTextEdit =
"QTextEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}"
"QTextEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}";
int id = PvApp::pvid(p);
pvQMultiLineEdit(p, id, parent, true, 10);
pvSetGeometry(p, id, x, y, w, h);
pvSetStyleSheet(p, id, qssTextEdit.c_str());
if (!text.empty()) { pvSetText(p, id, text.c_str()); }
return id;
}

View File

@@ -102,6 +102,8 @@ public:
static int combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector<std::string>& vecItems);
static int lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = "");
static int textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = "");
};
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,6 +1,11 @@
#include "PvPopWidget.h"
PvPopWidget::PvPopWidget(PARAM* p, int width, int height) : PvObject(p), width(width), height(height)
const std::string POP_OPER_NEW = "新增";
const std::string POP_OPER_EDIT = "编辑";
const std::string POP_OPER_DEL = "删除";
PvPopWidget::PvPopWidget(PARAM* p, int width, int height, std::string name)
: PvObject(p), width(width), height(height), name(name)
{
pvid = PvApp::widget(p, PV_ID_MAIN, 0, 0, 1920, 1080);
PvApp::label(p, pvid, 0, 0, 1920, 1080, "", "background-color: rgba(30,30,30,180);");
@@ -12,62 +17,97 @@ PvPopWidget::PvPopWidget(PARAM* p, int width, int height) : PvObject(p), width(w
PvApp::label(p, ui.widget, 0, 0, 60, height, "", "background-color: transparent; border: 0 solid rgb(42, 149, 245); border-width: 5px 0 5px 5px;");
PvApp::label(p, ui.widget, width-60, 0, 60, height, "", "background-color: transparent; border: 0 solid rgb(42, 149, 245); border-width: 5px 5px 5px 0;");
ui.title = PvApp::label(p, ui.widget, 20, 10, width-20, 30, "", "font: bold 20px;");
PvApp::label(p, ui.widget, 20, 40, width*0.5-20, 3, "", QSS_UNDERLINE);
ui.title = PvApp::label(p, ui.widget, 20, 10, width-20, 30, name, qss::label(20));
PvApp::label(p, ui.widget, 20, 40, width*0.5-20, 3, "", qss::QSS_UNDERLINE);
{
int w = 100, h = 40, offset = 50;
int x = (width- w*2 - offset) *0.5;
int y = height - h - 40;
int btnOk = PvApp::button(p, ui.widget, x, y, w, h, "确定", QSS_BTN_CONFIRM);
int btnOk = PvApp::button(p, ui.widget, x, y, w, h, "确定", qss::BTN_CONFIRM);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnOk, [=](std::string) {
this->show(false);
if (callbackConfirm) { callbackConfirm(); }
});
int btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", QSS_BTN_CANCEL);
int btnCancel = PvApp::button(p, ui.widget, x+w+offset, y, w, h, "取消", qss::BTN_CANCEL);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnCancel, [=](std::string) {
this->show(false);
});
}
ui.msg = PvApp::label(p, ui.widget, 50, height-110, width-100, 24, "", qss::label(14, "red"));
}
std::shared_ptr<PvPopWidget::ParamLine> PvPopWidget::addParamLine(std::string type, std::string key, std::string title, int x, int y, bool editable/* = true*/)
{
auto line = std::make_shared<ParamLine>(type, key);
mapLines[key] = line;
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, qss::label(15));
if (type == "lineEdit")
{
line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, "");
}
else if (type == "combox")
{
line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, {});
}
else if (type == "textEdit")
{
line->widget = PvApp::textEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight*4, "");
}
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
line->val = text;
});
if (!editable) { pvSetEnabled(p, line->widget, 0); }
return line;
}
void PvPopWidget::addParamLineEdit(std::string key, std::string title, int x, int y, bool editable/*= true*/)
{
auto line = std::make_shared<ParamLine>("lineEdit", key);
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, "font: bold 14px;");
line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, "");
if (!editable) { pvSetEnabled(p, line->widget, 0); }
mapLines[key] = line;
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
line->val = text;
});
this->addParamLine("lineEdit", key, title, x, y, editable);
}
void PvPopWidget::addParamTextEdit(std::string key, std::string title, int x, int y, bool editable/* = true*/)
{
this->addParamLine("textEdit", key, title, x, y, editable);
}
void PvPopWidget::addParamCombox(std::string key, std::string title, int x, int y, std::vector<std::string> items)
{
auto line = std::make_shared<ParamLine>("combox", key);
PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, "font: bold 14px;");
line->widget = PvApp::combox(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, items);
mapLines[key] = line;
PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) {
line->val = text;
});
auto line = this->addParamLine("combox", key, title, x, y, true);
line->items = items;
for (int i = 0; i<items.size(); ++i)
{
pvInsertItem(p, line->widget, i, NULL, items[i].c_str());
}
}
void PvPopWidget::setParamText(std::shared_ptr<ParamLine> line, std::string text)
{
if (line->type == "lineEdit")
line->val = text;
if (line->type == "combox")
{
pvSetText(p, line->widget, text.c_str());
}
else if (line->type == "combox")
{
int index = 0;
for (int i = 0; i<line->items.size(); ++i)
int index = -1;
for (int i = 0; i<line->items.size(); ++i)
{
if (line->items[i] == text) { index = i; break; }
if (line->items[i] == text)
{
line->val = line->items[i];
pvSetCurrentItem(p, line->widget, i);
index = i;
break;
}
}
pvSetCurrentItem(p, line->widget, index);
if (index == -1 && line->items.size() > 0)
{
line->val = line->items[0];
pvSetCurrentItem(p, line->widget, 0);
}
}
else
{
pvClear(p, line->widget);
pvSetText(p, line->widget, text.c_str());
}
}
@@ -80,34 +120,78 @@ void PvPopWidget::setParamText(std::string key, std::string text)
}
}
void PvPopWidget::setTitle(std::string title)
void PvPopWidget::setStatus(std::string text)
{
pvSetText(p, ui.title, title.c_str());
status = text;
if (!name.empty()) text = name + "-" + text;
pvSetText(p, ui.title, text.c_str());
}
void PvPopWidget::setData(DataFields fields)
void PvPopWidget::setMsg(std::string msg)
{
pvSetText(p, ui.msg, msg.c_str());
}
void PvPopWidget::setData(const Fields& fields)
{
dataOrigin = fields;
for (auto iter = mapLines.begin(); iter != mapLines.end(); ++iter)
{
auto& line = iter->second;
this->setParamText(line, fields.getStr(line->key));
this->setParamText(line, dataOrigin.value(line->key));
}
}
DataFields PvPopWidget::getData()
Fields PvPopWidget::getData()
{
DataFields fields;
for (auto iter = mapLines.begin(); iter!=mapLines.end(); ++iter)
Fields fields;
for (auto it = mapLines.begin(); it!=mapLines.end(); ++it)
{
auto& line = iter->second;
fields.set(line->key, line->val);
fields.set(it->second->key, it->second->val);
}
return fields;
}
Fields PvPopWidget::getChangedData()
{
Fields fields;
for (auto it = mapLines.begin(); it!=mapLines.end(); ++it)
{
auto& key = it->second->key;
auto& val = it->second->val;
if (primaryKeys.hasKey(key) || val != dataOrigin.value(key))
{
fields.set(key, val);
}
}
return fields;
}
void PvPopWidget::checkChangedData(Fields& fields)
{
auto& mapItems = fields.map();
for (auto it = mapItems.begin(); it!= mapItems.end(); ++it)
{
auto& key = it->first;
auto& val = it->second;
if (!primaryKeys.hasKey(key) && val == dataOrigin.value(key))
{
mapItems.erase(it);
}
}
}
void PvPopWidget::setLineGeometry(int wKey, int wVal, int h)
{
lineKeyWidth = wKey;
lineValWidth = wVal;
lineHeight = h;
}
void PvPopWidget::setPrimaryKeys(std::vector<std::string> keys)
{
for (auto& k : keys)
{
primaryKeys.set(k, "");
}
}

View File

@@ -1,7 +1,11 @@
#pragma once
#include "PvApp.h"
#include "DataFields.h"
#include "Fields.h"
extern const std::string POP_OPER_NEW;
extern const std::string POP_OPER_EDIT;
extern const std::string POP_OPER_DEL;
class PvPopWidget : public PvObject
{
@@ -16,10 +20,14 @@ public:
ParamLine(std::string type, std::string key) : type(type), key(key) {}
};
PvPopWidget(PARAM* p, int width, int height);
PvPopWidget(PARAM* p, int width, int height, std::string name);
std::shared_ptr<ParamLine> addParamLine(std::string type, std::string key, std::string title, int x, int y, bool editable = true);
void addParamLineEdit(std::string key, std::string title, int x, int y, bool editable=true);
void addParamTextEdit(std::string key, std::string title, int x, int y, bool editable = true);
void addParamCombox(std::string key, std::string title, int x, int y, std::vector<std::string> items);
void setParamText(std::shared_ptr<ParamLine> line, std::string text);
@@ -27,13 +35,23 @@ public:
void setCallbackConfirm(std::function<void()> callback) { callbackConfirm = callback; };
void setTitle(std::string title);
void setStatus(std::string text);
void setMsg(std::string msg);
void setData(const Fields& fields);
Fields getData();
Fields getChangedData();
void checkChangedData(Fields& fields);
void setData(DataFields fields);
DataFields getData();
void setLineGeometry(int wKey, int wVal, int h);
void setPrimaryKeys(std::vector<std::string> keys);
std::string name;
std::string status;
int width {800};
int height {600};
@@ -44,10 +62,13 @@ public:
struct {
int widget;
int title;
int msg;
} ui;
std::map<std::string, std::shared_ptr<ParamLine>> mapLines;
DataFields data;
std::function<void()> callbackConfirm = nullptr;
Fields dataOrigin;
Fields primaryKeys;
};

178
src/pv/PvStyle.cpp Normal file
View File

@@ -0,0 +1,178 @@
#include "PvStyle.h"
#include <sstream>
std::string BUTTON()
{
return "";
}
namespace qss
{
std::string label(int fontSize, std::string color, std::string bkgcolor, std::string border)
{
if (color.empty()) { color = "white"; };
if (bkgcolor.empty()) { bkgcolor = "transparent"; };
if (border.empty()) { border = "none"; };
std::stringstream ss;
ss << "QLabel { "
<< "font: bold " << fontSize << "px \"微软雅黑\"; "
<< "color: " << color << "; "
<< "background-color: " << bkgcolor << "; "
<< "border: " << border << "; "
<<"} QLabel:disabled {color:rgb(150, 150, 150);}";
return ss.str();
}
std::string button(int fontSize, std::string color, std::string bkgcolor, std::string border)
{
if (color.empty()) { color = "white"; };
if (bkgcolor.empty()) { bkgcolor = "rgb(39, 161, 136)"; };
if (border.empty()) { border = "none"; };
std::stringstream ss;
ss << "QPushButton {"
<< "border-radius: 5px;"
<< "font: bold " << fontSize << "px \"微软雅黑\";"
<< "color: " << color << ";"
<< "background-color:" << bkgcolor << ";"
<< "border:" << border << "; }"
<< "QPushButton:hover {background-color:rgb(10, 125, 215); border:2px solid rgb(1, 239, 255); color:rgb(1, 239, 255)}"
<< "QPushButton:pressed { border-width:2px 0 0 2px;background-color:rgb(150,150,150);border-style:inset;}"
<< "QPushButton:disabled { color:rgb(150,150,150);}";
return ss.str();
}
const std::string LABEL_BKG_1 = qss::label(14, "", "rgb(5, 47, 77)", "none; border-radius:5px");
const std::string LABEL_BKG_2 = qss::label(14, "", "rgb(8, 54, 91)", "none; border-radius:5px");
const std::string LABEL_BOX = qss::label(14, "", "rgba(200,200,200,20)", "none; border-radius:2px")
+ "QLabel:hover {border: 1px solid rgb(1, 183, 209);}";
const std::string QSS_BOX_ACTIVE =
"QLabel { background-color:rgb(7, 72, 111); border:2px solid;border-color:rgb(1, 183, 209); border-radius:2px;font:bold 16px;color:white; }"
"QLabel:hover {border: 1px solid rgb(1, 183, 209);}"
"QLabel:disabled { color:rgb(150,150,150);}";
const std::string LABEL_TITLE = qss::label(16, "rgb(99, 196, 216)", "", "none; padding-top: 0px;");
const std::string LABEL_KEY = qss::label(13, "rgb(180,180,180)", "", "");
const std::string LABEL_VAL = qss::label(14, "", "", "");
const std::string BTN =
"QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px;}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:2px 0 0 2px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
const std::string BTN_ACTIVE =
"QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:2px solid rgb(1,239,255);color:rgb(1,239,255);font:bold 18px;}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
const std::string BTN_CONFIRM =
"QPushButton { background-color:rgb(28, 145, 138); border-radius:10px; border: none; color:white; font:bold 18px;}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
const std::string BTN_CANCEL =
"QPushButton { background-color:rgb(200, 200, 200);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px;}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
const std::string QSS_BTN_MGR =
"QPushButton { background-color:rgb(10, 34, 63); border-radius:5px; border:1px solid rgb(33, 105, 195); color:white; font:bold 16px;}"
"QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}"
//"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }"
"QPushButton:disabled{color:rgb(150,150,150);}";
const std::string QSS_BTN_MGR_ACTIVE =
"QPushButton { background-color:rgb(39, 161, 136);border-radius:5px; border:1px solid rgb(68, 167, 252);color:white;font:bold 16px; }"
"QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }"
"QPushButton:disabled { color:rgb(150,150,150); }";
const std::string COMBOX =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 16px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
const std::string COMBOX_14 =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 14px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
const std::string LINEEDIT =
"QLineEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 15px;}"
"QLineEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}";
const std::string STYLE_TITLE_ICON =
"padding-top: 0px;"
"background-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 71, 105, 255),stop:1 rgba(0, 71, 105, 0));"
"border-radius: 0px; color:white; font: bold 16px; border-left: 8px solid rgba(33,255,210);";
const std::string QSS_UNDERLINE =
"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0,stop:0 rgba(9,194,207,200),stop:1 rgba(9,194,207,0));";
//"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 transparent, stop:%1 red, stop:1 blue);"
///////////////////////////////////////////////////////////////////////////////////////////////////
/// === 表格
///////////////////////////////////////////////////////////////////////////////////////////////////
/// === 表格
const std::string QSS_TABLE =
qss::label(15, "", "rgb(7, 46, 74)", "1px solid rgb(28, 121, 122)");
// 表头标签
const std::string QSS_TABLE_HEAD =
qss::label(15, "", "rgb(18, 93, 113)", "1px solid rgb(120, 120, 120); border-style:inset solid");
//"background-color: rgb(18, 93, 113); color:rgb(255, 255, 255); font:bold 16px;"
//"border-width:1 1 1 1px; border-style:inset solid; border-color:rgb(120, 120, 120);";
// 单元格
const std::string QSS_TABLE_CELL = qss::label(14, "", "", "none; padding-left: 10px");
const std::string QSS_TABLE_BTN_VIEW =
"QPushButton { background-color: rgb(7, 46, 74); color:white; border-radius:2px; border:none; font:bold 14px;}"
"QPushButton:hover { border: 1px solid white;}"
"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
// 表格行的斑马色0
const std::string QSS_TABLE_ROW_0 =
"background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);";
// 表格行的斑马色1
const std::string QSS_TABLE_ROW_1 =
"background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);";
// 表格行的高亮显示
const std::string QSS_TABLE_ROW_HIGHLIGHT =
"background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);";
const std::string QSS_CARD_DEVICE =
"QLabel { background-color:rgb(8, 54, 91); border:0px solid rgb(120, 120, 120); border-radius:5px; font:bold 14px; color:white; }"
"QLabel:hover {border: 2px solid rgb(79, 129, 255); border-radius:2px;}"
"QLabel:disabled { color:rgb(150,150,150);}";
}

View File

@@ -1,136 +1,66 @@
#pragma once
#include <string>
static std::string QSS_BTN_CONFIRM =
"QPushButton { background-color:rgb(28, 145, 138); border-radius:10px; border: none; color:white; font:bold 18px \"Microsoft YaHei\";}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
namespace qss
{
std::string label(int fontSize = 14, std::string color = "", std::string bkgcolor = "", std::string border = "");
static std::string QSS_BTN_CANCEL =
"QPushButton { background-color:rgb(200, 200, 200);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px \"Microsoft YaHei\";}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
std::string button(int fontSize = 14, std::string color = "", std::string bkgcolor = "", std::string border = "");
static std::string QSS_COMBOX =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 16px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
extern const std::string LABEL_BKG_1;
extern const std::string LABEL_BKG_2;
extern const std::string LABEL_BOX;
extern const std::string LABEL_KEY;
extern const std::string LABEL_VAL;
static std::string QSS_COMBOX_14 =
"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(5, 47, 77); border-radius: 5px; color:white; font: bold 14px;}"
"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px;}"
"QComboBox::drop-down { border-radius: 5px; width: 30px; }"
"QComboBox:disabled { color:rgb(150,150,150);}";
extern const std::string BTN;
extern const std::string BTN_ACTIVE;
extern const std::string BTN_CONFIRM;
extern const std::string BTN_CANCEL;
static std::string QSS_LINEEDIT =
"QLineEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 5px; color:white; font: bold 14px;}"
"QLineEdit:disabled { border: 1px solid gray; color:rgb(150,150,150);}";
extern const std::string COMBOX;
extern const std::string COMBOX_14;
static std::string STYLE_BTN =
"QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:0px solid rgb(10,120,215);color:white;font:bold 18px \"Microsoft YaHei\";}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
extern const std::string LINEEDIT;
static std::string STYLE_BTN_ACTIVE =
"QPushButton { background-color:rgb(4, 96, 142);border-radius:10px;border:2px solid rgb(1,239,255);color:rgb(1,239,255);font:bold 18px \"Microsoft YaHei\";}"
"QPushButton:hover { background-color:rgb(10,125,215);border:2px solid rgb(1,239,255);color:rgb(1,239,255)}"
"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 std::string QSS_LABEL_BKG_1 =
"QLabel { background-color:rgb(5, 47, 77); border:none; border-radius:5px; }"
"QLabel:disabled { color:rgb(150,150,150);}";
static std::string QSS_LABEL_BKG_2 =
"QLabel { background-color:rgb(8, 54, 91); border:none; border-radius:5px; }"
"QLabel:disabled { color:rgb(150,150,150);}";
extern const std::string QSS_BOX_ACTIVE;
static std::string QSS_BOX =
"QLabel { background-color:rgba(200,200,200,20); border:0px solid;border-color:rgb(5,255,255);border-radius:2px;font:bold 16px;color:white; }"
"QLabel:hover {border: 1px solid rgb(1, 183, 209);}"
"QLabel:disabled { color:rgb(150,150,150);}";
extern const std::string LABEL_TITLE;
static std::string QSS_BOX_ACTIVE =
"QLabel { background-color:rgb(7, 72, 111); border:2px solid;border-color:rgb(1, 183, 209); border-radius:2px;font:bold 16px;color:white; }"
"QLabel:hover {border: 1px solid rgb(1, 183, 209);}"
"QLabel:disabled { color:rgb(150,150,150);}";
extern const std::string STYLE_TITLE_ICON;
static std::string QSS_TITLE =
"QLabel { background:transparent; color: rgb(99, 196, 216); font: bold 16px; border: none; padding-top: 0px;}"
"QLabel:disabled { color:rgb(150,150,150);}";
extern const std::string QSS_UNDERLINE;
static std::string STYLE_TITLE_ICON =
"padding-top: 0px;"
"background-color: qlineargradient(x1:0, y1:1, x2:0, y2:0, stop:0 rgba(0, 71, 105, 255),stop:1 rgba(0, 71, 105, 0));"
"border-radius: 0px; color:white; font: bold 16px; border-left: 8px solid rgba(33,255,210);";
extern const std::string QSS_BTN_MGR;
static std::string QSS_UNDERLINE =
"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0,stop:0 rgba(9,194,207,200),stop:1 rgba(9,194,207,0));";
extern const std::string QSS_BTN_MGR_ACTIVE;
const std::string QSS_BTN_MGR =
"QPushButton { background-color:rgb(10, 34, 63); border-radius:5px; border:1px solid rgb(33, 105, 195); color:white; font:bold 18px \"Microsoft YaHei\";}"
"QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}"
//"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }"
"QPushButton:disabled{color:rgb(150,150,150);}";
//"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 transparent, stop:%1 red, stop:1 blue);"
const std::string QSS_BTN_MGR_ACTIVE =
"QPushButton { background-color:rgb(33, 105, 195);border-radius:5px; border:1px solid rgb(68, 167, 252);color:white;font:bold 18px \"Microsoft YaHei\"; }"
"QPushButton:hover { background-color:rgb(10,125,215); border:2px solid rgb(1,239,255); color:rgb(1,239,255)}"
"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset; }"
"QPushButton:disabled { color:rgb(150,150,150); }";
///////////////////////////////////////////////////////////////////////////////////////////////////
/// === 表格
extern const std::string QSS_TABLE;
// 表头
extern const std::string QSS_TABLE_HEAD;
// 单元格
extern const std::string QSS_TABLE_CELL;
//"background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 transparent, stop:%1 red, stop:1 blue);"
extern const std::string QSS_TABLE_BTN_VIEW;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// === 表格
static const std::string QSS_TABLE =
"border: 1px solid rgb(28, 121, 122); background-color:rgb(7, 46, 74);";
// 表头
static const std::string QSS_TABLE_HEAD =
"background-color: rgb(18, 93, 113); color:rgb(255, 255, 255); font:bold 16px;"
"border-width:1 1 1 1px; border-style:inset solid; border-color:rgb(120, 120, 120);";
// 单元格
static const std::string QSS_TABLE_CELL =
"background-color:transparent; color:rgb(255,255,255); font:bold 15px;padding-left:1;"
"border-width:0 0 0 0px; border-style:inset solid; border-color:rgba(180,180,180,200);";
// 表格行的斑马色0
extern const std::string QSS_TABLE_ROW_0;
// 表格行的斑马色1
extern const std::string QSS_TABLE_ROW_1;
// 表格行的高亮显示
extern const std::string QSS_TABLE_ROW_HIGHLIGHT;
static const std::string QSS_TABLE_BTN_VIEW =
"QPushButton { background-color: rgb(28, 145, 138); color:white; border-radius:2px; border:none; font:bold 14px;}"
"QPushButton:hover { border: 1px solid white;}"
"QPushButton:pressed { border-width:3px 0 0 3px;border-style:inset;}"
"QPushButton:disabled { color:rgb(150,150,150);}";
const std::string BTN_NEW = // 78, 149, 143
"QPushButton{background-color:rgb(38,233,233);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 18px;}"
"QPushButton:hover{background-color:rgb(10,125,215);}"
"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled{color:rgb(150,150,150);}";
extern const std::string QSS_CARD_DEVICE;
const std::string BTN_EDIT =
"QPushButton{background-color:rgb(248,147,45);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 15px;}"
"QPushButton:hover{background-color:rgb(10,125,215);}"
"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled{color:rgb(150,150,150);}";
};
const std::string BTN_DELETE =
"QPushButton{background-color:rgb(252,83,83);color:white;border-radius:5px;border:2px solid rgb(10,120,215);font:bold 15px;}"
"QPushButton:hover{background-color:rgb(10,125,215);}"
"QPushButton:pressed{border-width:3px 0 0 3px;background-color:rgb(150,150,150);border-style:inset;}"
"QPushButton:disabled{color:rgb(150,150,150);}";
// 表格行的斑马色0
static const std::string QSS_TABLE_ROW_0 =
"background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);";
// 表格行的斑马色1
static const std::string QSS_TABLE_ROW_1 =
"background-color:rgb(7, 46, 74); border-width:0 0 1 0px; border-style:inset solid; border-color:rgba(120,120,120, 100);";
// 表格行的高亮显示
static const std::string QSS_TABLE_ROW_HIGHLIGHT =
"background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);";

View File

@@ -1,5 +1,6 @@
#include "PvTable.h"
#include "PvStyle.h"
#include "pv/PvApp.h"
static const string STYLE_BKG =
"border-width:1 1 1 1px; border-style:outset solid; border-color:rgba(180,180,180,255);"
@@ -8,469 +9,424 @@ static const string STYLE_BKG =
//*********************************************************************************************************************
// PvTable
PvTable::PvTable(PARAM* p, int parent, int x, int y, int w, int row, Options& opts)
//: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* row + (opts.show_header ? (opts.header_height) : 0))),
: PvObject(p), option_(opts), nRow_(row), nCol_(0)
//: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* row + (opts.show_header ? (opts.header_height) : 0))),
: PvObject(p), option_(opts), nRow_(row), nCol_(0)
{
// 计算表格的显示区域
int h = opts.row_height* row + (opts.show_header ? (opts.head_height) : 0);
rect_.set(x, y, w, h);
// 表格的主窗体QWidget设置样式无效
pvid_ = PvApp::widget(p, parent, x, y, w, h+1);
// 表格的背景色和边框样式
PvApp::label(p, pvid_, 0, 0, w, h+1, "", QSS_TABLE);
// 计算表格的显示区域
int h = opts.row_height* row + (opts.show_header ? (opts.head_height) : 0);
rect_.set(x, y, w, h);
// 表格的主窗体QWidget设置样式无效
pvid_ = PvApp::widget(p, parent, x, y, w, h+1);
// 表格的背景色和边框样式
PvApp::label(p, pvid_, 0, 0, w, h+1, "", qss::QSS_TABLE);
vecHead_.resize(0);
vecRows_.resize(nRow_);
vecData_.resize(nRow_);
vecHead_.resize(0);
vecRows_.resize(nRow_);
vecData_.resize(nRow_);
// 创建行高亮显示背景
for (int row = 0; row < nRow_; row++)
{
int y = item_posy(row);
string qss = (row % 2 != 0) ? QSS_TABLE_ROW_0 : QSS_TABLE_ROW_1;
int rowBkg = PvApp::label(p, pvid_, 1, y, rect_.w-2, option_.row_height, "", qss);
pvHide(p, rowBkg);
vecRows_[row].bkg = rowBkg;
}
// 创建行高亮显示背景
for (int row = 0; row < nRow_; row++)
{
int y = item_posy(row);
string qss = (row % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1;
int rowBkg = PvApp::label(p, pvid_, 1, y, rect_.w-2, option_.row_height, "", qss);
pvHide(p, rowBkg);
vecRows_[row].bkg = rowBkg;
}
}
void PvTable::addHead(string id, string text, int width, vector<pair<string, string>> mapping)
{
vecHead_.push_back(Head(id, text, width, mapping));
nCol_ = vecHead_.size();
vecHead_.push_back(Head(id, text, width, mapping));
nCol_ = vecHead_.size();
if (width <= -1)
{
width = rect_.w-1 - posCol_;
}
int col = nCol_ - 1;
if (width <= -1) { width = rect_.w-1 - posCol_; }
int col = nCol_ - 1;
// 创建表头的标签
if (option_.show_header)
{
vecHead_[col].pvid = PvApp::label(p, pvid_, posCol_, 0, width, option_.head_height, text, QSS_TABLE_HEAD);
}
// 创建表头的标签
if (option_.show_header)
{
vecHead_[col].pvid = PvApp::label(p, pvid_, posCol_, 0, width, option_.head_height, text, qss::QSS_TABLE_HEAD);
}
// 创建列的单元格
for (int row = 0; row < nRow_; ++row)
{
int y = item_posy(row);
int pvid = PvApp::label(p, pvid_, posCol_, y, width, option_.row_height, "", QSS_TABLE_CELL);
vecRows_[row].vecCells.push_back(pvid);
PvApp::bind(p, MOUSE_OVER_EVENT, pvid, [=](string s) { highlight(row, (s == "1")); });
}
posCol_ += width;
// 创建列的单元格
for (int row = 0; row < nRow_; ++row)
{
int y = item_posy(row);
int pvid = PvApp::label(p, pvid_, posCol_, y, width, option_.row_height, "", qss::QSS_TABLE_CELL);
vecRows_[row].vecCells.push_back(pvid);
PvApp::bind(p, MOUSE_OVER_EVENT, pvid, [=](string s) { highlight(row, (s == "1")); });
}
posCol_ += width;
}
void PvTable::addHead(vector<string> vec_text)
{
int colSize = vec_text.size();
int x = 0;
for (int i = 0; i < vec_text.size(); ++i)
{
int w = float(rect_.w-1) * float(i+1) / float(colSize);
string text = vec_text[i];
this->addHead(text, text, w-x);
x = w;
}
int colSize = vec_text.size();
int x = 0;
for (int i = 0; i < vec_text.size(); ++i)
{
int w = float(rect_.w-1) * float(i+1) / float(colSize);
string text = vec_text[i];
this->addHead(text, text, w-x);
x = w;
}
}
void PvTable::setRowVisible(int row, bool v)
{
if (row < 0 || row >= vecRows_.size())
{
return;
}
auto& rowItem = vecRows_[row];
if (rowItem.visible != v)
{
rowItem.visible = v;
rowItem.visible ? pvShow(p, rowItem.bkg) : pvHide(p, rowItem.bkg);
if (!v)
{
for (int col = 0; col<rowItem.vecCells.size(); ++col)
{
pvSetText(p, rowItem.vecCells[col], "");
}
}
}
if (row < 0 || row >= vecRows_.size())
{
return;
}
auto& rowItem = vecRows_[row];
if (rowItem.visible != v)
{
rowItem.visible = v;
rowItem.visible ? pvShow(p, rowItem.bkg) : pvHide(p, rowItem.bkg);
if (!v)
{
for (int col = 0; col<rowItem.vecCells.size(); ++col)
{
pvSetText(p, rowItem.vecCells[col], "");
}
}
}
}
void PvTable::highlight(int row, bool v)
{
string qss = ((row % 2 != 0) ? QSS_TABLE_ROW_0 : QSS_TABLE_ROW_1);
if (vecRows_.size() > 0 && row <= vecRows_.size())
{
if (v) { qss = "background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; }
pvSetStyleSheet(p, vecRows_[row].bkg, qss.c_str());
}
string qss = ((row % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1);
if (vecRows_.size() > 0 && row <= vecRows_.size())
{
if (v) { qss = "background-color:rgba(14,45,60,200);border:1px solid rgba(255,0,0,100);"; }
pvSetStyleSheet(p, vecRows_[row].bkg, qss.c_str());
}
}
void PvTable::addOperate(vector<string> vecOpt)
{
// 创建表头的标签
if (option_.show_header)
{
PvApp::label(p, pvid_, posCol_, 0, rect_.w - posCol_, option_.head_height, "操作", QSS_TABLE_HEAD);
}
for (int row = 0; row < nRow_; ++row)
{
int y = item_posy(row);
int btn_opt = PvApp::label(p, pvid_, posCol_, y, rect_.w - posCol_, option_.row_height, "", QSS_TABLE_CELL);
//PvInstance::bind_event(p, MOUSE_OVER_EVENT, btn_opt, [=](string s) { highlight(row, (s == "1")); });
vecOpt_.push_back({ btn_opt, vector<int>() });
auto& vec_opt_btn_ = vecOpt_.back().second;
// 创建表头的标签
if (option_.show_header)
{
PvApp::label(p, pvid_, posCol_, 0, rect_.w - posCol_, option_.head_height, "操作", qss::QSS_TABLE_HEAD);
}
for (int row = 0; row < nRow_; ++row)
{
int y = item_posy(row);
int cellWidget = PvApp::label(p, pvid_, posCol_, y, rect_.w - posCol_, option_.row_height, "", qss::QSS_TABLE_CELL);
//PvInstance::bind_event(p, MOUSE_OVER_EVENT, btn_opt, [=](string s) { highlight(row, (s == "1")); });
vecOpt_.push_back({ cellWidget, vector<int>() });
auto& vec_opt_btn_ = vecOpt_.back().second;
int x = 5, w = 60;
for (int i = 0; i < vecOpt.size(); i++)
{
auto& title = vecOpt[i];
w = 20 + 15 * title.size() / 3;
int btn = PvApp::button(p, btn_opt, x, 4, w, 24, title, QSS_TABLE_BTN_VIEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
if (cbOperate_) { cbOperate_(row, 0, title); }
});
vec_opt_btn_.push_back(btn);
x += (w + 5);
}
pvHide(p, btn_opt);
}
int x = 5, w = 60;
for (int i = 0; i < vecOpt.size(); i++)
{
auto& title = vecOpt[i];
w = 20 + 15 * title.size() / 3;
int btn = PvApp::button(p, cellWidget, x, 4, w, 24, title, qss::button(14, "", "", "none; border-radius: 0px"));
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
if (cbOperate_) { cbOperate_(row, 0, title); }
});
vec_opt_btn_.push_back(btn);
x += (w + 5);
}
pvHide(p, cellWidget);
}
}
void PvTable::setOperateCallback(CallbackTableOpt cb)
{
cbOperate_ = cb;
cbOperate_ = cb;
};
void PvTable::set_text(PARAM* p, int row, int col, string text, string style)
{
if (row < nRow_ && col < nCol_)
{
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
if (!style.empty())
{
int idx = row + 1;
if (idx % 2 != 0)
{
style = item_base_style_ + style;
}
else
{
style = item_base_style_ + style;
}
if (row < nRow_ && col < nCol_)
{
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
if (!style.empty())
{
int idx = row + 1;
if (idx % 2 != 0)
{
style = item_base_style_ + style;
}
else
{
style = item_base_style_ + style;
}
//style = "qproperty-alignment:AlignCenter;" + style + "}";
string s = "QLabel{" + style + "} QLabel:disabled{color:rgb(150,150,150)}";
pvSetStyleSheet(p, vecRows_[row].vecCells[col], s.c_str());
}
}
//style = "qproperty-alignment:AlignCenter;" + style + "}";
string s = "QLabel{" + style + "} QLabel:disabled{color:rgb(150,150,150)}";
pvSetStyleSheet(p, vecRows_[row].vecCells[col], s.c_str());
}
}
}
void PvTable::setRowData(int row, DataFields& d)
void PvTable::setRowData(int row, Fields& d)
{
if (row >= nRow_) { return; }
if (row >= nRow_) { return; }
vecData_[row] = d;
for (int col = 0; col < vecHead_.size(); ++col)
{
auto& head = vecHead_[col];
string text = d.getStr(head.id);
text = head.getMapping(text);
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
}
setRowVisible(row, true);
this->setOperateVisible(row, d.size() > 0);
vecData_[row] = d;
for (int col = 0; col < vecHead_.size(); ++col)
{
auto& head = vecHead_[col];
string text = d.value(head.id);
text = head.getMapping(text);
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
}
setRowVisible(row, true);
this->setOperateVisible(row, d.size() > 0);
}
void PvTable::setRowData(int row, std::vector<std::string> vd)
{
if (row >= nRow_) { return; }
pvShow(p, vecRows_[row].bkg);
for (int col = 0; col < vecHead_.size(); ++col)
{
if (col < vd.size()) {
auto& head = vecHead_[col];
string text = head.getMapping(vd[col]);
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
}
}
setRowVisible(row, true);
this->setOperateVisible(row, vd.size() > 0);
if (row >= nRow_) { return; }
pvShow(p, vecRows_[row].bkg);
for (int col = 0; col < vecHead_.size(); ++col)
{
if (col < vd.size()) {
auto& head = vecHead_[col];
string text = head.getMapping(vd[col]);
pvSetText(p, vecRows_[row].vecCells[col], text.c_str());
}
}
setRowVisible(row, true);
this->setOperateVisible(row, vd.size() > 0);
}
DataFields& PvTable::getRowdata(int row)
Fields PvTable::getRowData(int row)
{
static DataFields tmp;
return (row >= 0 && row < vecData_.size()) ? vecData_[row] : tmp;
static Fields tmp;
return (row >= 0 && row < vecData_.size()) ? vecData_[row] : tmp;
}
void PvTable::mappingData(Fields& fields)
{
for (int i=0; i< vecHead_.size(); ++i)
{
auto& head = vecHead_[i];
if (fields.hasKey(head.id))
{
auto& val = fields.value(head.id);
val = head.getMapping(val);
}
}
}
void PvTable::set_border_visible(PARAM* p, bool v)
{
v ? pvShow(p, border_id_) : pvHide(p, border_id_);
v ? pvShow(p, border_id_) : pvHide(p, border_id_);
}
int PvTable::item_posy(int row)
{
return option_.show_header ? row * option_.row_height + option_.head_height : row * option_.row_height;
return option_.show_header ? row * option_.row_height + option_.head_height : row * option_.row_height;
}
//void PvTable::set_item_btn_callback(CallbackTableOpt cb)
//{
// //cb_opt_ = cb;
//}
void PvTable::add_col_button(PARAM* p, int col, string title, PvRect& rt, string style)
{
if (col >= nCol_)
{
return;
}
for (int row = 0; row < nRow_; ++row)
{
int id = PvApp::button(p, vecRows_[row].vecCells[col], rt.x, rt.y, rt.w, rt.h, title, style);
pvHide(p, id);
vec_col_item_btn_[row].push_back(id);
//PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s)
//{
// if (cb_operate_)
// {
// cb_operate_(row, col, title);
// }
//});
}
}
string GetTableItemButtonStyle(string title)
{
static unordered_map<string, string> map_style =
{
//{PV::OPT_NEW, PvStyle::BTN_NEW},
//{PV::OPT_EDIT, PvStyle::BTN_EDIT},
//{PV::OPT_DEL, PvStyle::BTN_DELETE}
};
string style = map_style[title];
if (style.empty())
{
style = BTN_EDIT;
}
return style;
if (col >= nCol_)
{
return;
}
for (int row = 0; row < nRow_; ++row)
{
int id = PvApp::button(p, vecRows_[row].vecCells[col], rt.x, rt.y, rt.w, rt.h, title, style);
pvHide(p, id);
vec_col_item_btn_[row].push_back(id);
//PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s)
//{
// if (cb_operate_)
// {
// cb_operate_(row, col, title);
// }
//});
}
}
void PvTable::add_col_button(PARAM* p, int col, vector<string> vec_title)
{
int x = 5;
int w = 0;
for (int i = 0; i < vec_title.size(); i++)
{
auto& title = vec_title[i];
w = 20 + 20 * title.size() / 3;
this->add_col_button(p, col, title, PvRect(x, 3, w, 28), BTN_EDIT);
x += (w + 5);
}
int x = 5;
int w = 0;
for (int i = 0; i < vec_title.size(); i++)
{
auto& title = vec_title[i];
w = 20 + 20 * title.size() / 3;
this->add_col_button(p, col, title, PvRect(x, 3, w, 28), qss::button());
x += (w + 5);
}
}
void PvTable::setOperateVisible(int row, bool v, int id)
{
if (row < vecOpt_.size())
{
auto& vec_opt_btn = vecOpt_[row].second;
int pvid = id < 0 ? vecOpt_[row].first : ((id < vec_opt_btn.size()) ? vec_opt_btn[id] : PV_ID_NUL);
v ? pvShow(p, pvid) : pvHide(p, pvid);
}
if (row < vecOpt_.size())
{
auto& vec_opt_btn = vecOpt_[row].second;
int pvid = id < 0 ? vecOpt_[row].first : ((id < vec_opt_btn.size()) ? vec_opt_btn[id] : PV_ID_NUL);
v ? pvShow(p, pvid) : pvHide(p, pvid);
}
}
int PvTable::border_id()
{
return border_id_;
return border_id_;
}
int PvTable::rows()
{
return nRow_;
return nRow_;
}
int PvTable::colums()
{
return nCol_;
return nCol_;
}
vector<DataFields> PvTable::data()
vector<Fields> PvTable::data()
{
return vecData_;
return vecData_;
}
PvTable::Head& PvTable::header(int col)
{
return vecHead_[col];
return vecHead_[col];
}
static const string STYLE_NORMAL =
"QPushButton{background-color:rgba(255,255,255,30);border-radius:0px;font:bold 16px;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;}";
"QPushButton { background-color:rgba(255,255,255,30);border-radius:0px;font:bold 16px ;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;}"
"QPushButton:disabled { color: gray; border-color: gray; }";
static const string STYLE_ACTIVE =
"QPushButton{background-color:rgba(32,164,128,255);border-radius:0px;font:bold 16px;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;}";
"QPushButton { background-color:rgba(32,164,128,255);border-radius:0px;font:bold 16px ;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;}"
"QPushButton:disabled { color: gray; border-color: gray; }";
PvPagination::PvPagination(PARAM* p, int parent, const PvRect& rt)
: PvObject(p)
PvPagination::PvPagination(PARAM* p, int parent, int x, int y, int n)
: PvObject(p)
{
pvid_ = PvApp::label(p, parent, rt.x, rt.y, rt.w, rt.h, "", "");
// 分页控件
int x = 0;
int y = 0;
btn_prev_ = PvApp::button(p, pvid_, x, y, 30, 30, "<", STYLE_NORMAL);
for (int i = 1; i <= 7; i++)
{
int id = PvApp::button(p, pvid_, x += 32, y, 30, 30, std::to_string(i), STYLE_NORMAL);
vec_btn_page_.push_back({id, 0});
//PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, id, [=](string s) { this->on_click_page(id); });
}
btn_next_ = PvApp::button(p, pvid_, x += 32, y, 30, 30, ">", STYLE_NORMAL);
pvid = PvApp::label(p, parent, x, y, 2*32 + 80, 30, "", "border: 0px solid gray;");
//PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, btn_prev_, [=](string e) { this->on_click_prev(); });
//PvInstance::bind_event(p, PvEvent::BUTTON_EVENT, btn_next_, [=](string e) { this->on_click_next(); });
// 分页控件
btnPrev = PvApp::button(p, pvid, 0, 0, 30, 30, "<", STYLE_NORMAL);
for (int i = 0; i < n; i++)
{
int btn = PvApp::button(p, pvid, (i+1)*32, 0, 30, 30, std::to_string(i+1), STYLE_NORMAL);
pvHide(p, btn);
vecBtn.push_back({btn, i});
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](string) { this->activePage(i, true); });
}
btnNext = PvApp::button(p, pvid, 32, 0, 30, 30, ">", STYLE_NORMAL);
labelInfo = PvApp::label(p, pvid, 2*32, 0, 80, 30, " 共0页", qss::label(14, "rgb(27, 220, 224)"));
this->set_page(0, 0);
pvSetEnabled(p, btnPrev, 0);
pvSetEnabled(p, btnNext, 0);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnPrev, [=](string e) { this->activePage(--pageIndex, true); });
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNext, [=](string e) { this->activePage(++pageIndex, true); });
}
void PvPagination::set_page(int page_id, int max_page)
void PvPagination::setPage(int index, int count)
{
this->active_page_button(p, page_id, page_id_);
pageIndex = index;
pageCount = count;
page_id_ = page_id;
page_count_ = max_page;
int x = 32;
int y = 0;// table_->rect().h + 16;
for (int i = 0; i < vec_btn_page_.size(); ++i)
{
auto& btn_info = vec_btn_page_[i];
auto btnid = btn_info.first;
int idx = i + 1;
if (idx > page_count_)
{
pvHide(p, btnid);
}
else
{
pvShow(p, btnid);
if (page_count_ > 7)
{
if (idx == 4)
{
idx = 0;
}
else if (idx > 4)
{
idx = page_count_ - (7 - idx);
}
}
btn_info.second = idx;
string text = to_string(idx);
if (text.empty() || text == "0")
{
text = "...";
pvSetEnabled(p, btnid, false);
}
pvMove(p, btnid, x, y);
pvSetText(p, btnid, text.c_str());
if (page_id == idx)
{
this->active_page_button(p, page_id, page_id_);
page_id_ = page_id;
}
x += (32);
}
}
pvMove(p, btn_next_, x, y);
for (int i = 0; i < vecBtn.size(); ++i)
{
auto& btn = vecBtn[i];
auto btnid = btn.first;
int idx = i + 1;
if (idx > pageCount)
{
pvHide(p, btnid);
}
else
{
pvShow(p, btnid);
//if (pageCount > 7)
//{
// if (idx == 4)
// {
// idx = 0;
// }
// else if (idx > 4)
// {
// idx = pageCount - (7 - idx);
// }
//}
//btn.second = idx;
//string text = to_string(idx);
//if (text.empty() || text == "0")
//{
// text = "...";
// pvSetEnabled(p, btnid, false);
//}
////pvMove(p, btnid, x, y);
//pvSetText(p, btnid, text.c_str());
//if (idx == idx)
//{
// this->active_page_button(p, idx, pageIndex);
// pageIndex = idx;
//}
//x += (32);
}
}
int x = (count+1)*32;
pvMove(p, btnNext, x, 0);
pvMove(p, labelInfo, x+=32, 0);
pvSetText(p, labelInfo, ("" + std::to_string(count) + "").c_str());
pvResize(p, pvid, x += 81, 30);
this->activePage(pageIndex);
}
int PvPagination::pageid()
int PvPagination::page()
{
return page_id_;
return pageIndex;
};
void PvPagination::active_page_button(PARAM* p, int new_pageid, int old_pageid)
void PvPagination::activePage(int index, bool invoke)
{
for (int i = 0; i < vec_btn_page_.size(); i++)
{
auto& item = vec_btn_page_[i];
if (item.second != 0)
{
if (item.second == old_pageid)
{
pvSetStyleSheet(p, item.first, STYLE_NORMAL.c_str());
}
if (item.second == new_pageid)
{
pvSetStyleSheet(p, item.first, STYLE_ACTIVE.c_str());
}
}
}
if (pageCount == 0)
{
pageIndex = 0;
return;
}
pageIndex = index;
if (pageIndex < 0){ pageIndex = 0; }
if (pageIndex >= pageCount) { pageIndex = pageCount - 1; }
pvSetEnabled(p, btnPrev, pageIndex != 0);
pvSetEnabled(p, btnNext, (pageIndex != pageCount - 1));
if (btnActive != PV_ID_NUL) { pvSetStyleSheet(p, btnActive, STYLE_NORMAL.c_str()); }
btnActive = vecBtn[pageIndex].first;
pvSetStyleSheet(p, btnActive, STYLE_ACTIVE.c_str());
if (invoke)
{
if (callback) callback(pageIndex);
}
}
void PvPagination::set_goto_page_callback(std::function<void(int pageidx)> cb)
void PvPagination::setCallback(std::function<void(int index)> func)
{
cb_goto_ = cb;
callback = func;
}
void PvPagination::on_click_page(int btnid)
{
for (int i = 0; i < vec_btn_page_.size(); ++i)
{
auto& item = vec_btn_page_[i];
if (btnid == item.first)
{
int page_id = item.second;
if (cb_goto_) { cb_goto_(page_id); }
return;
}
}
}
void PvPagination::on_click_prev()
{
if (page_id_ <= 1)
{
return;
}
if (cb_goto_)
{
cb_goto_(page_id_ - 1);
}
}
void PvPagination::on_click_next()
{
if (page_id_ >= page_count_)
{
return;
}
if (cb_goto_)
{
cb_goto_(page_id_ + 1);
}
}
PvPageTable::PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts)
//: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* rows + (opts.show_header ? (opts.header_height) : 0)))
: PvObject(p)
: PvObject(p)
{
int h = opts.row_height* rows + (opts.show_header ? (opts.head_height) : 0);
int pvid_ = PvApp::widget(p, parent, x, y, w, h);
table_ = make_shared<PvTable>(p, pvid_, 0, 0, w, rows, opts);
int h = opts.row_height* rows + (opts.show_header ? (opts.head_height) : 0);
int pvid_ = PvApp::widget(p, parent, x, y, w, h);
table_ = make_shared<PvTable>(p, pvid_, 0, 0, w, rows, opts);
}
shared_ptr<PvTable> PvPageTable::getTable()
{
return table_;
return table_;
}

View File

@@ -4,7 +4,7 @@
#include <functional>
#include "PvApp.h"
#include "DataFields.h"
#include "Fields.h"
using CallbackTableOpt = std::function<void(int row, int col, std::string text)>;
@@ -66,10 +66,11 @@ public:
void set_text(PARAM* p, int row, int col, std::string text, std::string style = "");
void setRowData(int row, DataFields& d);
void setRowData(int row, Fields& d);
void setRowData(int row, std::vector<std::string> vd);
DataFields& getRowdata(int row);
Fields getRowData(int row);
void mappingData(Fields& fields);
void set_border_visible(PARAM* p, bool v);
@@ -85,7 +86,7 @@ public:
int colums();
std::vector<DataFields> data();
std::vector<Fields> data();
PvTable::Head& header(int col);
@@ -98,7 +99,7 @@ private:
std::vector<PvTable::Head> vecHead_;
std::vector<PvTable::Row> vecRows_;
std::vector<DataFields> vecData_;
std::vector<Fields> vecData_;
vector<pair<int, vector<int>>> vecOpt_;
int nRow_;
@@ -119,43 +120,41 @@ private:
class PvPagination : public PvObject
{
public:
PvPagination(PARAM* p, int parent, const PvRect& rt);
PvPagination(PARAM* p, int parent, int x, int y, int n);
void set_page(int page_id, int max_page);
void setPage(int index, int count);
int pageid();
int page();
void set_goto_page_callback(std::function<void(int pageid)> cb);
void setCallback(std::function<void(int index)> func);
private:
void on_click_page(int btnid);
void on_click_prev();
void on_click_next();
void active_page_button(PARAM* p, int new_pageid, int old_pageid);
void activePage(int index, bool invoke=false);
private:
int pvid_ = PV_ID_NUL;
// 当前显示的页码索引, 从1开始
int page_id_ = 1;
int pageIndex = 1;
// 总页数
int page_count_ = 0;
int pageCount = 0;
// 上一页按钮
int btn_prev_ = PV_ID_NUL;
int btnPrev = PV_ID_NUL;
// 下一页按钮
int btn_next_ = PV_ID_NUL;
int btnNext = PV_ID_NUL;
// 页面跳转按钮
int btn_gopage_ = PV_ID_NUL;
// 页码列表最多显示6个页码按钮,前3页和后3页 <按钮ID, 页码>
std::vector<pair<int, int>> vec_btn_page_;
int btnActive = PV_ID_NUL;
function<void(int)> cb_goto_ = nullptr;
int labelInfo = PV_ID_NUL;
// 页码列表最多显示6个页码按钮,前3页和后3页 <按钮ID, 页码>
std::vector<pair<int, int>> vecBtn;
function<void(int)> callback = nullptr;
};

View File

@@ -4,9 +4,9 @@
static int CreatePanel(PARAM* p, int parentId, int x, int y, int w, int h, std::string title)
{
int id = PvApp::label(p, parentId, x, y, w, h, "", QSS_LABEL_BKG_2);
PvApp::label(p, id, 10, 10, w, 20, title, STYLE_TITLE_ICON);
PvApp::label(p, id, 20, 30, w, 2, "", QSS_UNDERLINE);
int id = PvApp::label(p, parentId, x, y, w, h, "", qss::LABEL_BKG_2);
PvApp::label(p, id, 10, 10, w, 20, title, qss::STYLE_TITLE_ICON);
PvApp::label(p, id, 20, 30, w, 2, "", qss::QSS_UNDERLINE);
return id;
}

View File

@@ -8,23 +8,23 @@
static int CreatePanel(PARAM* p, int parent, int x, int y, int w, int h, std::string title)
{
int panelId = PvApp::label(p, parent, x, y, w, h, "", QSS_LABEL_BKG_1);
int titleId = PvApp::label(p, panelId, 10, 8, w, 22, title, STYLE_TITLE_ICON);
PvApp::label(p, panelId, 20, 28, w, 2, "", QSS_UNDERLINE);
int panelId = PvApp::label(p, parent, x, y, w, h, "", qss::LABEL_BKG_1);
int titleId = PvApp::label(p, panelId, 10, 8, w, 22, title, qss::STYLE_TITLE_ICON);
PvApp::label(p, panelId, 20, 28, w, 2, "", qss::QSS_UNDERLINE);
return panelId;
}
static int CreatePanel1(PARAM* p, int parent, int x, int y, int w, int h, std::string title)
{
int panelId = PvApp::label(p, parent, x, y, w, h, "", "border: none; background-color: transparent;");
int panelId = PvApp::label(p, parent, x, y, w, h, "");
PvApp::image(p, panelId, 0, 13, 500, 17, "bkgBox.png");
PvApp::label(p, panelId, 20, 0, w-20, 30, title, "background-color: transparent; font: bold 18px;");
PvApp::label(p, panelId, 20, 0, w-20, 30, title);
return panelId;
}
static int CreateCard1(PARAM* p, int parentId, int x, int y, int w, int h, std::string title, std::string val)
{
int id = PvApp::label(p, parentId, x, y, w, h, "", QSS_LABEL_BKG_1);
int id = PvApp::label(p, parentId, x, y, w, h, "", qss::LABEL_BKG_1);
int idTitle = PvApp::label(p, id, 0, h*0.5, w, h*0.5, title, "background:transparent; font: bold 28px;");
int idVal = PvApp::label(p, id, 0, 0, w, h*0.5, val, "background:transparent; font: bold 28px; color:rgb(77,215,240);");
pvSetAlignment(p, idTitle, AlignCenter);
@@ -34,9 +34,9 @@ static int CreateCard1(PARAM* p, int parentId, int x, int y, int w, int h, std::
static int CreateCard2(PARAM* p, int parent, int x, int y, int w, int h, std::string title, std::string val)
{
int id = PvApp::label(p, parent, x, y, w, h, "", QSS_LABEL_BKG_1);
int id = PvApp::label(p, parent, x, y, w, h, "", qss::LABEL_BKG_1);
int idTitle = PvApp::label(p, id, 0, 0, w, h*0.5, title, "background:transparent; font: bold 16px;");
int idTitle = PvApp::label(p, id, 0, 0, w, h*0.5, title);
int idVal = PvApp::label(p, id, 0, h*0.5, w, h*0.5, val, "background:transparent; font: bold 16px; color:rgb(77,215,240);");
pvSetAlignment(p, idTitle, AlignCenter);
pvSetAlignment(p, idVal, AlignCenter);
@@ -54,8 +54,9 @@ static int CreateBox(PARAM* p, int parent, int x, int y, int w, int h, std::stri
PvApp::label(p, id, w-len, h-len, len, len, "", qss + "border-width: 0 2px 2px 0");
PvApp::label(p, id, 0, h-len, len, len, "", qss + "border-width: 0 0 2px 2px");
}
int titleId = PvApp::label(p, id, 0, 0, w, h*0.5, k, "border:none; background-color: transparent; font: bold 14px; padding-bottom: 0px;");
int valId = PvApp::label(p, id, 0, h*0.5, w, h*0.5, val, "border:none; background-color: transparent; font: bold 16px; color:rgb(77, 215, 240);");
// "border:none; background-color: transparent; font: bold 14px; padding-bottom: 0px;"
int titleId = PvApp::label(p, id, 0, 0, w, h*0.5-2, k);
int valId = PvApp::label(p, id, 0, h*0.5+2, w, h*0.5-2, val, qss::label(16, "rgb(77, 215, 240)"));
pvSetAlignment(p, titleId, AlignHCenter | AlignBottom);
pvSetAlignment(p, valId, AlignHCenter | AlignTop);
return valId;
@@ -167,7 +168,7 @@ public:
}
}
void setTitle(std::string title)
void setStatus(std::string title)
{
pvSetText(p, labelTitle, title.c_str());
}
@@ -265,7 +266,7 @@ int MaskPageHome::initUI(EPvCode pvcode)
// 中间区域
{
int panel = PvApp::label(p, 0, x = 10+500+10, y, w = 880, h1+h2+h3+20, "", QSS_LABEL_BKG_1);
int panel = PvApp::label(p, 0, x = 10+500+10, y, w = 880, h1+h2+h3+20, "", qss::LABEL_BKG_1);
////// 饼图
//int left = PvApp::widget(p, panel, 100, 100, 100, 100);
@@ -287,9 +288,9 @@ int MaskPageHome::initUI(EPvCode pvcode)
auto popStation = new PopStation(p);
popStation->show(0);
int btn = PvApp::button(p, panel, 10, 20, 100, 30, "场站一", STYLE_BTN);
int btn = PvApp::button(p, panel, 10, 20, 100, 30, "场站一", qss::BTN);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) {
popStation->setTitle("场站一");
popStation->setStatus("场站一");
pvShow(p, popStation->widget);
});
@@ -301,12 +302,16 @@ int MaskPageHome::initUI(EPvCode pvcode)
}
this->updateUI();
auto pagination = new PvPagination(p, 0, 600, 160, 20);
pagination->setPage(5, 10);
return 0;
}
void MaskPageHome::updateUI()
{
auto& appdata = Application::instance().getAppData();
auto& appdata = Application::data();
int stationNum = appdata.mapStation.size(); // 场站数量
double energyCapacity {}; // 储能容量

View File

@@ -1,18 +1,11 @@
#include "MaskPageRunning.h"
#include "app/Application.h"
static std::string QSS_CARD_DEVICE =
"QLabel { background-color:rgb(8, 54, 91); border:0px solid rgb(120, 120, 120); border-radius:5px; font:bold 14px; color:white; }"
"QLabel:hover {border: 2px solid rgb(79, 129, 255); border-radius:2px;}"
"QLabel:disabled { color:rgb(150,150,150);}";
static std::string QSS_PARAM_K = "border:none; background-color: transparent; color: rgb(180,180,180); font: bold 13px;";
static std::string QSS_PARAM_V = "border:none; background-color: transparent; color: white; font: bold 14px;";
static int CreateParamLabel(PARAM* p, int parent, int x, int y, std::string k, std::string v)
{
PvApp::label(p, parent, x, y, 70, 30, k, QSS_PARAM_K);
return PvApp::label(p, parent, x += 70, y, 120, 30, v, QSS_PARAM_V);
PvApp::label(p, parent, x, y, 70, 30, k, qss::LABEL_KEY);
return PvApp::label(p, parent, x += 70, y, 120, 30, v, qss::LABEL_VAL);
}
class BoxCard : PvObject
@@ -25,25 +18,25 @@ public:
BoxCard(PARAM* p, int parent, int x, int y) : PvObject(p)
{
card_ = PvApp::label(p, parent, x, y, 400, 250, "", QSS_CARD_DEVICE);
card_ = PvApp::label(p, parent, x, y, 400, 250, "", qss::QSS_CARD_DEVICE);
PvApp::label(p, card_, 10, 10, 60, 60, "", "border:none; background-color: rgb(39, 158, 145);");
ui.code = PvApp::label(p, card_, 80, 10, 100, 20, "", "border:none; background-color: transparent;");
ui.name = PvApp::label(p, card_, 80, 30, 100, 20, "", "border:none; background-color: transparent;");
ui.type = PvApp::label(p, card_, 80, 50, 100, 20, "", "border:none; background-color: transparent; color: rgb(8, 161, 249);");
ui.code = PvApp::label(p, card_, 80, 10, 100, 20, "");
ui.name = PvApp::label(p, card_, 80, 30, 100, 20, "");
ui.type = PvApp::label(p, card_, 80, 50, 100, 20, "", qss::label(14, "rgb(8, 161, 249)"));
int x1 = 190;
ui.online = PvApp::labelAlignCenter(p, card_, x1, 10, 70, 30, "在线", QSS_PARAM_V);
ui.running = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "空闲", QSS_PARAM_V);
ui.err = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "正常", QSS_PARAM_V);
ui.online = PvApp::labelAlignCenter(p, card_, x1, 10, 70, 30, "在线", qss::LABEL_VAL);
ui.running = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "空闲", qss::LABEL_VAL);
ui.err = PvApp::labelAlignCenter(p, card_, x1 += 70, 10, 70, 30, "正常", qss::LABEL_VAL);
PvApp::labelAlignCenter(p, card_, x1 = 190, 40, 70, 30, "在线状态", QSS_PARAM_K);
PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "工作状态", QSS_PARAM_K);
PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "故障状态", QSS_PARAM_K);
PvApp::labelAlignCenter(p, card_, x1 = 190, 40, 70, 30, "在线状态", qss::LABEL_KEY);
PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "工作状态", qss::LABEL_KEY);
PvApp::labelAlignCenter(p, card_, x1 += 70, 40, 70, 30, "故障状态", qss::LABEL_KEY);
PvApp::label(p, card_, 10, 80, 80, 30, "运行分析:", QSS_PARAM_K);
PvApp::button(p, card_, 80, 83, 60, 24, "查看", "border:none; border-radius: 5px; background-color: rgb(28, 145, 138); color:white; font: bold 14px;");
PvApp::label(p, card_, 10, 80, 80, 30, "运行分析:", qss::LABEL_KEY);
PvApp::button(p, card_, 80, 83, 60, 24, "查看");
// 默认创建 10 个参数标签:
int n = 10;
@@ -53,8 +46,8 @@ public:
int row = i/2;
int col = i%2;
int h = 25;
vecParamLabel_[i].first = PvApp::label(p, card_, 10 + 200*col, 115 + h*row, 70, h, "参数"+std::to_string(i) + ":", QSS_PARAM_K);
vecParamLabel_[i].second = PvApp::label(p, card_, 10 + 200*col + 70, 115 + h*row, 120, h, "---", QSS_PARAM_V);
vecParamLabel_[i].first = PvApp::label(p, card_, 10 + 200*col, 115 + h*row, 70, h, "参数"+std::to_string(i) + ":", qss::LABEL_KEY);
vecParamLabel_[i].second = PvApp::label(p, card_, 10 + 200*col + 70, 115 + h*row, 120, h, "---", qss::LABEL_VAL);
}
}
@@ -117,13 +110,12 @@ int MaskPageRunning::initUI(EPvCode pvcode)
PvApp::label(p, 0, 10, 150, 220, 790, "", "background-color: rgb(8, 54, 91); border-radius: 10px;");
int workspace = PvApp::label(p, 0, 240, 150, 1670, 790, "", "background-color: rgba(8, 54, 91, 0); border-radius: 10px;");
std::vector<std::string> vecStationNames;
Application::instance().getAppData().getStationNames(vecStationNames);
std::vector<std::string> vecStationNames = Application::data().getStationNames();
PvApp::label(p, 0, 20, 110, 80, 30, "场站切换", "color:white; font: bold 16px;");
PvApp::combox(p, 0, 100, 110, 150, 30, vecStationNames);
if (vecStationNames.size() > 0)
{
station_ = Application::instance().getAppData().getStationByName(vecStationNames[0]);
station_ = Application::data().getStationByName(vecStationNames[0]);
}
PvApp::label(p, 0, 320, 110, 80, 30, "运行模式", "color:white; font: bold 16px;");
@@ -136,8 +128,8 @@ int MaskPageRunning::initUI(EPvCode pvcode)
// 储能设备
{
ui.storage.name = "储能设备";
int pid = ui.storage.box = PvApp::label(p, 0, x, y, w, h, "", QSS_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.storage.name, QSS_TITLE);
int pid = ui.storage.box = PvApp::label(p, 0, x, y, w, h, "", qss::LABEL_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.storage.name, qss::LABEL_TITLE);
ui.storage.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;");
ui.storage.workspace = PvApp::widget(p, workspace, 0, 0, 1670, 790);
@@ -156,8 +148,8 @@ int MaskPageRunning::initUI(EPvCode pvcode)
// 光伏设备
{
ui.solar.name = "光伏设备";
int pid = ui.solar.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", QSS_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, QSS_TITLE);
int pid = ui.solar.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", qss::LABEL_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, qss::LABEL_TITLE);
ui.solar.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;");
ui.solar.workspace = ui.storage.workspace;
@@ -166,8 +158,8 @@ int MaskPageRunning::initUI(EPvCode pvcode)
// 充电设备
{
ui.charge.name = "充电设备";
int pid = ui.charge.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", QSS_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, QSS_TITLE);
int pid = ui.charge.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", qss::LABEL_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.solar.name, qss::LABEL_TITLE);
ui.charge.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;");
ui.charge.workspace = ui.storage.workspace;
@@ -176,8 +168,8 @@ int MaskPageRunning::initUI(EPvCode pvcode)
// 环境与安防设备
{
ui.security.name = "环境与安防设备";
int pid = ui.security.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", QSS_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.security.name, QSS_TITLE);
int pid = ui.security.box = PvApp::label(p, 0, x, y += (h+10), w, h, "", qss::LABEL_BOX);
PvApp::label(p, pid, 10, 0, w-10, 30, ui.security.name, qss::LABEL_TITLE);
ui.security.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;");
ui.security.workspace = PvApp::widget(p, workspace, 0, 0, 1670, 790);
@@ -222,8 +214,8 @@ void MaskPageRunning::activeBoxPanel(BoxPanel& panel)
{
static int activeBox = PV_ID_NUL;
static int activeWorkspace = PV_ID_NUL;
if (activeBox != PV_ID_NUL) { pvSetStyleSheet(p, activeBox, QSS_BOX.c_str()); }
if (activeBox = panel.box) { pvSetStyleSheet(p, activeBox, QSS_BOX_ACTIVE.c_str()); }
if (activeBox != PV_ID_NUL) { pvSetStyleSheet(p, activeBox, qss::LABEL_BOX.c_str()); }
if (activeBox = panel.box) { pvSetStyleSheet(p, activeBox, qss::QSS_BOX_ACTIVE.c_str()); }
if (activeWorkspace != PV_ID_NUL) { pvHide(p, activeWorkspace); }
if (activeWorkspace = panel.workspace) { pvShow(p, activeWorkspace); }

View File

@@ -4,9 +4,9 @@
static int CreatePanel(PARAM* p, int parentId, int x, int y, int w, int h, std::string title)
{
int id = PvApp::label(p, parentId, x, y, w, h, "", QSS_LABEL_BKG_2);
PvApp::label(p, id, 10, 10, w, 20, title, STYLE_TITLE_ICON);
PvApp::label(p, id, 20, 30, w, 2, "", QSS_UNDERLINE);
int id = PvApp::label(p, parentId, x, y, w, h, "", qss::LABEL_BKG_2);
PvApp::label(p, id, 10, 10, w, 20, title, qss::STYLE_TITLE_ICON);
PvApp::label(p, id, 20, 30, w, 2, "", qss::QSS_UNDERLINE);
return id;
}
@@ -52,7 +52,7 @@ static VecStatDef statDef = {
int MaskPageStat::initUI(EPvCode pvcode)
{
PvApp::label(p, PV_ID_MAIN, 10, 100, 1900, 850, "", QSS_LABEL_BKG_1);
PvApp::label(p, PV_ID_MAIN, 10, 100, 1900, 850, "", qss::LABEL_BKG_1);
if (pvcode == EPvCode::MASK_STAT) { pvcode = EPvCode::MASK_STAT_STORAGE; }
std::string curModuleName;
@@ -63,7 +63,7 @@ int MaskPageStat::initUI(EPvCode pvcode)
std::string moduleName = statDef[i].first;
// 创建按钮
bool isActive = (PvApp::getPvCode(moduleName) == pvcode);
int pageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*190), 110, 180, 40, moduleName, isActive ? QSS_BTN_MGR_ACTIVE : QSS_BTN_MGR);
int pageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*190), 110, 180, 40, moduleName, isActive ? qss::QSS_BTN_MGR_ACTIVE : qss::QSS_BTN_MGR);
mapSubpage_[pageBtn] = moduleName;
if (isActive)
{

View File

@@ -1,8 +1,12 @@
#include "MaskPageSysmgr.h"
#include "pv/PvTable.h"
#include <thread>
#include "database/Dao.h"
#include "common/Snowflake.h"
#include "pv/PvTable.h"
#include "pv/PvPopWidget.h"
#include "database/Dao.h"
#include "app/Application.h"
#include "PageSysmgrPop.h"
static void createPvTable(PARAM* p)
{
@@ -69,236 +73,13 @@ static void createPvTable(PARAM* p)
}
class PageTable : public PvMask
{
public:
PageTable(PARAM* p) : PvMask(p)
{
table = std::make_shared<PvTable>(p, 0, 10, 160, 1900, 20, option);
table->setOperateCallback([=](int row, int col, std::string text) { this->onCallbackOperate(row, col, text); });
};
void setPage(int pageIndex, int pageSize, int count) {}
void updateDataFromDB()
{
std::vector<DataFields> result;
PageInfo pageInfo;
this->queryTable(pageInfo, result);
for (int i = 0; i<table->rows(); ++i)
{
if (i<result.size())
{
auto& fields = result[i];
table->setRowData(i, result[i]);
}
else
{
table->setRowVisible(i, false);
}
}
}
virtual void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result) {}
virtual void onCallbackOperate(int row, int col, std::string text) {};
int pageIndex {0};
PvTable::Options option;
std::shared_ptr<PvTable> table;
std::shared_ptr<PvPopWidget> pop;
};
class PageUser : public PageTable
{
public:
PageUser(PARAM* p, EPvCode pvcode) :PageTable(p)
{
table->addHead(DMUser::USER_ID, "用户编号", 180, {});
table->addHead(DMUser::ACCOUNT, "用户名", 180, {});
table->addHead(DMUser::NAME, "姓名", 180, {});
table->addHead(DMUser::GENDER, "性别", 180, {{"1", ""}, {"0",""}});
table->addHead(DMUser::AGE, "年龄", 180, {});
table->addHead(DMUser::PHONE, "手机号", 180, {});
table->addHead(DMUser::EMAIL, "邮箱", 180, {});
table->addHead("role_id", "角色", 180, {});
table->addHead(DMUser::LOGINTIME, "上次登录时间", 200, {});
table->addOperate({"编辑"});
pop = std::make_shared<PvPopWidget>(p, 700, 500);
pop->show(0);
pop->setCallbackConfirm([=]() {
auto fields = pop->getData();
XLOGD() << fields.toStr();
// 保存数据:
DAO::updateUserById(fields);
});
int x = 50, y = 100, w=350, h=60;
pop->addParamLineEdit(DMUser::USER_ID, "用户编号", x, y, false);
pop->addParamCombox(DMRole::ROLE_ID, "角 色", x+w, y, {"系统管理员", "运营管理员", "运营人员"});
pop->addParamLineEdit(DMUser::ACCOUNT, "用 户 名", x, y+=h);
pop->addParamLineEdit(DMUser::NAME, "姓 名", x+w, y);
pop->addParamLineEdit(DMUser::GENDER, "性 别", x, y+=h);
pop->addParamLineEdit(DMUser::AGE, "年 龄", x+w, y);
pop->addParamLineEdit(DMUser::PHONE, "手 机 号", x, y += h);
pop->addParamLineEdit(DMUser::EMAIL, "邮 箱", x+w, y);
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::queryUserList(pageInfo, result);
}
void onCallbackOperate(int row, int col, std::string text)
{
if (text == "编辑")
{
pop->show(1);
pop->setTitle("编辑用户信息");
DataFields fields = table->getRowdata(row);
pop->setData(fields);
}
};
};
class PageRole : public PageTable
{
public:
PageRole(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMRole::ROLE_ID, "角色编号", 200, {});
table->addHead(DMRole::NAME, "角色名称", 200, {});
table->addHead(DMRole::DESCRIBE, "角色描述", 900, {});
table->addHead(DMRole::IS_OPEN, "是否启用", 200, {{"1", ""}, {"0", ""}});
table->addOperate({"编辑", "设置权限"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::queryRoleList(pageInfo, result);
}
};
class PagePermission : public PageTable
{
public:
PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMPermission::PERMISSION_ID,"权限编号", 200, {});
table->addHead(DMPermission::NAME, "权限名称", 200, {});
table->addHead(DMPermission::DESCRIBE, "权限描述", 900, {});
table->addHead(DMPermission::IS_OPEN, "是否启用", 200, {{"1", ""}, {"0", ""}});
table->addOperate({"查看"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::queryPermissionList(pageInfo, result);
}
};
class PageStation : public PageTable
{
public:
PageStation(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMStation::STATION_ID, "场站编号", 200, {});
table->addHead(DMStation::NAME, "场站名称", 200, {});
table->addHead(DMStation::ADDRESS, "地址", 200, {});
table->addHead(DMStation::LONGITUDE, "经度", 200, {});
table->addHead(DMStation::LATITUDE, "维度", 200, {});
table->addHead(DMStation::TEL, "电话", 200, {});
table->addHead(DMStation::STATUS, "状态", 200, {{"0","未启用"}, {"1", "启用"}});
table->addOperate({"查看", "编辑"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::queryStationList(pageInfo, result);
}
};
class PageDevice: public PageTable
{
public:
PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {});
table->addHead(DMDevice::TYPE, "设备类型", 120, {});
table->addHead(DMDevice::NAME, "设备名称", 180, {});
table->addHead(DMDevice::CODE, "设备编码", 160, {});
table->addHead(DMDevice::MODEL, "设备型号", 160, {});
table->addHead(DMDevice::FACTORY, "厂家", 160, {});
table->addHead(DMDevice::TEL, "厂家电话", 160, {});
table->addHead(DMDevice::ATTRS, "设备参数", 460, {});
table->addHead(DMDevice::IS_OPEN, "是否启用", 120, {{"1", ""}, {"0", ""}});
table->addOperate({"查看", "编辑"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::queryDeviceList(pageInfo, result);
}
};
class PagePolicy : public PageTable
{
public:
PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMPolicy::POLICY_ID, "策略编号", 200, {});
table->addHead(DMPolicy::TYPE, "策略类型", 200, {});
table->addHead(DMPolicy::NAME, "策略名称", 200, {});
table->addHead(DMPolicy::DESCRIBE, "策略描述", 400, {});
table->addHead(DMPolicy::VALUE, "策略参数", 400, {});
table->addHead(DMPolicy::IS_OPEN, "是否启用", 200, {{"1", ""}, {"0", ""}});
table->addOperate({"查看", "编辑"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::queryPolicyList(pageInfo, result);
}
};
class PageSyslog : public PageTable
{
public:
PageSyslog(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMSystemLog::LOG_ID, "日志编号", 160, {});
table->addHead(DMSystemLog::TYPE, "日志类型", 160, {});
table->addHead(DMSystemLog::USER_ACCOUNT, "用户", 160, {});
table->addHead(DMSystemLog::CONTENT, "日志详情", 800, {});
table->addHead(DMSystemLog::STATUS, "状态", 160, {});
table->addHead(DMSystemLog::CREATE_TIME, "记录时间", 200, {});
table->addOperate({"查看"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
DAO::querySystemLogList(pageInfo, result);
}
};
class PageAlertlog : public PageTable
{
public:
PageAlertlog(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMAlertLog::LOG_ID, "日志编号", 160, {});
table->addHead(DMAlertLog::TYPE, "日志类型", 160, {});
table->addHead(DMAlertLog::DEVICE_ID, "设备ID", 160, {});
table->addHead(DMAlertLog::CONTENT, "日志详情", 800, {});
table->addHead(DMAlertLog::STATUS, "状态", 160, {});
table->addHead(DMAlertLog::CREATE_TIME, "记录时间", 200, {});
table->addOperate({"查看"});
}
void queryTable(PageInfo& pageInfo, std::vector<DataFields>& result)
{
//DAO::queryAlertLogList(pageInfo, result);
}
};
MaskPageSysmgr::MaskPageSysmgr(PARAM* p) : PvMask(p)
{
}
int MaskPageSysmgr::initUI(EPvCode pvcode)
{
PvApp::label(p, PV_ID_MAIN, 10, 100, 1900, 850, "", QSS_LABEL_BKG_1);
PvApp::label(p, PV_ID_MAIN, 10, 150, 1900, 790, "", qss::LABEL_BKG_1);
if (pvcode == EPvCode::MASK_SYSMGR) { pvcode = EPvCode::MASK_MGR_USER; }
@@ -307,7 +88,7 @@ int MaskPageSysmgr::initUI(EPvCode pvcode)
{
std::string& title = vecPageNames[i];
bool isActive = (PvApp::getPvCode(title) == pvcode);
int idPageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*110), 110, 100, 40, title, isActive ? QSS_BTN_MGR_ACTIVE : QSS_BTN_MGR);
int idPageBtn = PvApp::button(p, PV_ID_MAIN, 10+(i*110), 100, 100, 40, title, isActive ? qss::QSS_BTN_MGR_ACTIVE : qss::QSS_BTN_MGR);
mapSubpage_[idPageBtn] = title;
}

View File

@@ -0,0 +1,518 @@
#include "PageSysmgrPop.h"
#include "app/Application.h"
#include "database/Dao.h"
#include "database/DataModelDef.h"
#include "common/Snowflake.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageTable ===
PageTable::PageTable(PARAM* p) : PvMask(p)
{
table = std::make_shared<PvTable>(p, 0, 20, 210, 1880, pageSize, option);
table->setOperateCallback([=](int row, int col, std::string text) { this->onOperate(row, col, text); });
pagination = std::make_shared<PvPagination>(p, 0, 20, 780, 20);
pagination->setCallback([=](int index)
{
pageIndex = index;
this->updateDataFromDB();
});
}
std::shared_ptr<PvPopWidget> PageTable::addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys)
{
std::shared_ptr<PvPopWidget> pop = std::make_shared<PvPopWidget>(p, w, h, name);
pop->lineValWidth = w0;
pop->setPrimaryKeys(primaryKeys);
pop->setCallbackConfirm([=]()
{
auto fields = pop->getData();
std::string err = this->onValidation(pop, fields);
pop->setMsg(err);
if (err.empty())
{
XLOGD() << "POP get: data=" << fields.toStr();
if (pop->status == POP_OPER_EDIT) { pop->checkChangedData(fields); }
XLOGD() << "POP get: data=" << fields.toStr();
table->mappingData(fields);
XLOGD() << "POP get: data=" << fields.toStr();
err = this->onPopConfirm(pop, fields);
pop->setMsg(err);
if (err.empty())
{
this->hidePop(0);
this->updateDataFromDB();
};
}
});
pop->show(0);
vecPop.push_back(pop);
return pop;
}
void PageTable::showPop(int index, std::string oper, Fields& fields)
{
XLOGD() << "POP set: data=" << fields.toStr();
table->mappingData(fields);
XLOGD() << "POP set: data=" << fields.toStr();
if (index < vecPop.size())
{
auto& pop = vecPop[index];
pop->show(true);
pop->setStatus(oper);
pop->setData(fields);
pop->setMsg("");
}
}
void PageTable::hidePop(int index)
{
if (index < vecPop.size())
{
vecPop[index]->show(false);
}
}
void PageTable::updateDataFromDB()
{
std::vector<Fields> result;
PageInfo pageInfo;
pageInfo.size = pageSize;
pageInfo.index = pageIndex;
this->onQueryTable(pageInfo, result);
for (int i = 0; i<table->rows(); ++i)
{
if (i<result.size())
{
auto& fields = result[i];
table->setRowData(i, result[i]);
}
else
{
table->setRowVisible(i, false);
}
}
pagination->setPage(pageInfo.index, pageInfo.total/pageInfo.size + int(pageInfo.total%pageInfo.size != 0));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageUser ===
PageUser::PageUser(PARAM* p, EPvCode pvcode) :PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMUser::USER_ID, "用户编号", 180, {});
table->addHead(DMUser::ACCOUNT, "用户名", 180, {});
table->addHead(DMUser::NAME, "姓名", 180, {});
table->addHead(DMUser::GENDER, "性别", 180, appdata.mapping.gender);
table->addHead(DMUser::AGE, "年龄", 180, {});
table->addHead(DMUser::PHONE, "手机号", 180, {});
table->addHead(DMUser::EMAIL, "邮箱", 180, {});
table->addHead(DMRole::ROLE_ID, "角色", 180, appdata.mapping.role);
table->addHead(DMUser::LOGINTIME, "上次登录时间", 200, {});
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 50, y = 80, w = 350, h = 60;
auto pop = this->addPop(700, 500, 180, "用户信息", {DMUser::USER_ID});
pop->addParamLineEdit(DMUser::USER_ID, "编号", x, y, false);
pop->addParamCombox(DMRole::ROLE_ID, "角色", x+w, y, appdata.getRoleNames());
pop->addParamLineEdit(DMUser::ACCOUNT, "用户名", x, y += h);
pop->addParamLineEdit(DMUser::NAME, "姓名", x+w, y);
pop->addParamCombox(DMUser::GENDER, "性别", x, y += h, {"", ""});
pop->addParamLineEdit(DMUser::AGE, "年龄", x+w, y);
pop->addParamLineEdit(DMUser::PHONE, "手机号", x, y += h);
pop->addParamLineEdit(DMUser::EMAIL, "邮箱", x+w, y);
}
void PageUser::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryUserList(pageInfo, result);
}
void PageUser::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
};
std::string PageUser::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (fields.value(DMUser::ACCOUNT).empty()) { return "请输入用户名"; }
return "";
};
std::string PageUser::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (pop->status == POP_OPER_NEW)
{
Errcode err = DAO::insertUser(fields);
if (err == Errcode::OK) { return ""; }
else if (err == Errcode::ERR_DB_DUPLICATE) { return "用户名已经存在"; }
else { return "系统错误"; }
}
else if (pop->status == POP_OPER_EDIT)
{
Errcode err = DAO::updateUserById(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
return "";
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageRole ===
PageRole::PageRole(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMRole::ROLE_ID, "角色编号", 200, {});
table->addHead(DMRole::NAME, "角色名称", 200, {});
table->addHead(DMRole::DESCRIBE, "角色描述", 900, {});
table->addHead(DMRole::IS_OPEN, "是否启用", 200, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 180, "角色信息", {DMUser::USER_ID});
pop->addParamLineEdit(DMRole::ROLE_ID, "编号", x, y, false);
pop->addParamLineEdit(DMRole::NAME, "名称", x, y += h);
pop->addParamCombox(DMUser::IS_OPEN, "是否启用", x, y += h, {"启用", "禁用"});
pop->addParamTextEdit(DMRole::DESCRIBE, "描述", x, y += h);
}
void PageRole::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryRoleList(pageInfo, result);
}
void PageRole::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageRole::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageRole::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePermission ===
PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMPermission::PERMISSION_ID, "权限编号", 200, {});
table->addHead(DMPermission::NAME, "权限名称", 200, {});
table->addHead(DMPermission::DESCRIBE, "权限描述", 900, {});
table->addHead(DMPermission::IS_OPEN, "是否启用", 200, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 180, "角色信息", {DMPermission::PERMISSION_ID});
pop->addParamLineEdit(DMPermission::PERMISSION_ID, "编号", x, y, false);
pop->addParamLineEdit(DMPermission::NAME, "名称", x, y += h);
pop->addParamCombox(DMPermission::IS_OPEN, "是否启用", x, y += h, {"启用", "禁用"});
pop->addParamTextEdit(DMPermission::DESCRIBE, "描述", x, y += h);
}
void PagePermission::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryPermissionList(pageInfo, result);
}
void PagePermission::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PagePermission::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PagePermission::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageStation ===
PageStation::PageStation(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMStation::STATION_ID, "场站编号", 200, {});
table->addHead(DMStation::NAME, "场站名称", 200, {});
table->addHead(DMStation::ADDRESS, "地址", 200, {});
table->addHead(DMStation::LONGITUDE, "经度", 200, {});
table->addHead(DMStation::LATITUDE, "维度", 200, {});
table->addHead(DMStation::TEL, "电话", 200, {});
table->addHead(DMStation::STATUS, "状态", 200, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 240, "场站信息", {DMStation::STATION_ID});
pop->addParamLineEdit(DMStation::STATION_ID, "编号", x, y, false);
pop->addParamLineEdit(DMStation::NAME, "名称", x, y += h);
pop->addParamLineEdit(DMStation::ADDRESS, "地址", x, y += h);
pop->addParamLineEdit(DMStation::LONGITUDE, "经度", x, y += h);
pop->addParamLineEdit(DMStation::LATITUDE, "维度", x, y += h);
pop->addParamLineEdit(DMStation::TEL, "电话", x, y += h);
pop->addParamCombox(DMStation::STATUS, "状态", x, y += h, {"启用", "禁用"});
}
void PageStation::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryStationList(pageInfo, result);
}
void PageStation::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageStation::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageStation::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (pop->status == POP_OPER_NEW)
{
Errcode err = DAO::insertStation(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
else if (pop->status == POP_OPER_EDIT)
{
Errcode err = DAO::updateStationById(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageDevice ===
PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {});
table->addHead(DMDevice::TYPE_ID, "设备类型", 120, appdata.mapping.deviceType);
table->addHead(DMDevice::NAME, "设备名称", 180, {});
table->addHead(DMDevice::CODE, "设备编码", 160, {});
table->addHead(DMDevice::MODEL, "设备型号", 160, {});
table->addHead(DMDevice::FACTORY, "厂家", 160, {});
table->addHead(DMDevice::TEL, "厂家电话", 160, {});
table->addHead(DMDevice::ATTRS, "设备参数", 460, {});
table->addHead(DMDevice::IS_OPEN, "是否启用", 120, appdata.mapping.isopen);
table->addOperate({"编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 50, y = 80, w = 350, h = 60;
auto pop = this->addPop(700, 520, 180, "设备信息", {DMDevice::DEVICE_ID});
pop->addParamLineEdit(DMDevice::DEVICE_ID, "设备编号", x, y, false);
pop->addParamCombox(DMDevice::TYPE_ID, "类型", x+w, y, appdata.getDeviceTypes());
pop->addParamLineEdit(DMDevice::NAME, "设备名称", x, y += h);
pop->addParamLineEdit(DMDevice::CODE, "设备编码", x+w, y);
pop->addParamLineEdit(DMDevice::MODEL, "设备型号", x, y += h);
pop->addParamLineEdit(DMDevice::FACTORY, "厂家", x+w, y);
pop->addParamLineEdit(DMDevice::TEL, "厂家电话", x, y += h);
pop->addParamCombox(DMDevice::IS_OPEN, "是否启用", x+w, y, {"启用", "禁用"});
pop->addParamLineEdit(DMDevice::ATTRS, "设备参数", x, y += h);
}
void PageDevice::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryDeviceList(pageInfo, result);
}
void PageDevice::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageDevice::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageDevice::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
if (pop->status == POP_OPER_NEW)
{
Errcode err = DAO::insertDevice(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
else if (pop->status == POP_OPER_EDIT)
{
Errcode err = DAO::updateDeviceById(fields);
if (err == Errcode::OK) { return ""; }
else { return "系统错误"; }
}
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePolicy ===
PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p)
{
auto& appdata = Application::data();
table->addHead(DMPolicy::POLICY_ID, "策略编号", 200, {});
table->addHead(DMPolicy::TYPE, "策略类型", 200, {});
table->addHead(DMPolicy::NAME, "策略名称", 200, {});
table->addHead(DMPolicy::DESCRIBE, "策略描述", 400, {});
table->addHead(DMPolicy::VALUE, "策略参数", 400, {});
table->addHead(DMPolicy::IS_OPEN, "是否启用", 200, appdata.mapping.isopen);
table->addOperate({ "编辑"});
int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW);
PvApp::bind(p, PvEvent::BUTTON_EVENT, btnNew, [=](std::string) { this->onOperate(-1, -1, POP_OPER_NEW); });
int x = 80, y = 80, h = 60;
auto pop = this->addPop(500, 600, 180, "策略信息", {DMPolicy::POLICY_ID});
pop->addParamLineEdit(DMPolicy::POLICY_ID, "编号", x, y, false);
}
void PagePolicy::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::queryPolicyList(pageInfo, result);
}
void PagePolicy::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PagePolicy::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PagePolicy::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageSyslog ===
PageSyslog::PageSyslog(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMSystemLog::LOG_ID, "日志编号", 160, {});
table->addHead(DMSystemLog::TYPE, "日志类型", 160, {});
table->addHead(DMSystemLog::USER_ACCOUNT, "用户", 160, {});
table->addHead(DMSystemLog::CONTENT, "日志详情", 800, {});
table->addHead(DMSystemLog::STATUS, "状态", 160, {});
table->addHead(DMSystemLog::CREATE_TIME, "记录时间", 200, {});
table->addOperate({"查看"});
}
void PageSyslog::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
DAO::querySystemLogList(pageInfo, result);
}
void PageSyslog::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageSyslog::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageSyslog::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageAlertlog ===
PageAlertlog::PageAlertlog(PARAM* p, EPvCode pvcode) : PageTable(p)
{
table->addHead(DMAlertLog::LOG_ID, "日志编号", 160, {});
table->addHead(DMAlertLog::TYPE, "日志类型", 160, {});
table->addHead(DMAlertLog::DEVICE_ID, "设备ID", 160, {});
table->addHead(DMAlertLog::CONTENT, "日志详情", 800, {});
table->addHead(DMAlertLog::STATUS, "状态", 160, {});
table->addHead(DMAlertLog::CREATE_TIME, "记录时间", 200, {});
table->addOperate({"查看"});
}
void PageAlertlog::onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result)
{
//DAO::queryAlertLogList(pageInfo, result);
}
void PageAlertlog::onOperate(int row, int col, std::string oper)
{
if (oper == POP_OPER_NEW)
{
Fields fields;
fields.set(DMUser::USER_ID, Snowflake::instance().getIdStr());
this->showPop(0, oper, fields);
}
else if (oper == POP_OPER_EDIT)
{
this->showPop(0, oper, table->getRowData(row));
}
}
std::string PageAlertlog::onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
};
std::string PageAlertlog::onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields)
{
return "";
}

View File

@@ -0,0 +1,137 @@
#pragma once
#include "pv/PvApp.h"
#include "pv/PvTable.h"
#include "pv/PvPopWidget.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageTable ===
class PageTable : public PvMask
{
public:
PageTable(PARAM* p);
void setPage(int pageIndex, int pageSize, int count) {}
std::shared_ptr<PvPopWidget> addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys);
void showPop(int index, std::string optr, Fields& fields);
void hidePop(int index);
void updateDataFromDB();
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) {}
virtual void onOperate(int row, int col, std::string oper) {};
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) { return ""; };
int pageSize {15};
int pageIndex {0};
PvTable::Options option;
std::shared_ptr<PvTable> table;
std::shared_ptr<PvPagination> pagination;
std::vector<std::shared_ptr<PvPopWidget>> vecPop;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageUser ===
class PageUser : public PageTable
{
public:
PageUser(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageRole ===
class PageRole : public PageTable
{
public:
PageRole(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override ;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePermission ===
class PagePermission : public PageTable
{
public:
PagePermission(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageStation ===
class PageStation : public PageTable
{
public:
PageStation(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageDevice ===
class PageDevice : public PageTable
{
public:
PageDevice(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PagePolicy ===
class PagePolicy : public PageTable
{
public:
PagePolicy(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageSyslog ===
class PageSyslog : public PageTable
{
public:
PageSyslog(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// === PageAlertlog ===
class PageAlertlog : public PageTable
{
public:
PageAlertlog(PARAM* p, EPvCode pvcode);
virtual void onQueryTable(PageInfo& pageInfo, std::vector<Fields>& result) override;
virtual void onOperate(int row, int col, std::string oper) override;
virtual std::string onValidation(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
virtual std::string onPopConfirm(std::shared_ptr<PvPopWidget> pop, Fields& fields) override;
};

View File

@@ -48,6 +48,7 @@ int pvMain(PARAM* p)
pvStartDefinition(p, 1024);
if (mask)
{
pvSetFont(p, PV_ID_MAIN, "微软雅黑", 12, 1, 0, 0, 0);
mask->initUI();
}
pvQLayoutVbox(p, 0, -1);