diff --git a/bin/Release/assets/pv/bkgHead.png b/bin/Release/assets/pv/bkgHead.png new file mode 100644 index 0000000..2d130fd Binary files /dev/null and b/bin/Release/assets/pv/bkgHead.png differ diff --git a/bin/Release/assets/pv/play1.png b/bin/Release/assets/pv/play1.png new file mode 100644 index 0000000..051428c Binary files /dev/null and b/bin/Release/assets/pv/play1.png differ diff --git a/bin/Release/assets/pv/pv.bkg.main2.png b/bin/Release/assets/pv/pv.bkg.main2.png index 53a44eb..75d3d71 100644 Binary files a/bin/Release/assets/pv/pv.bkg.main2.png and b/bin/Release/assets/pv/pv.bkg.main2.png differ diff --git a/src/app/AppData.cpp b/src/app/AppData.cpp index b46a387..e782537 100644 --- a/src/app/AppData.cpp +++ b/src/app/AppData.cpp @@ -51,10 +51,11 @@ void AppData::initFromDB() DAO::queryWorkModeDef(dao, result); for (auto& fields: result) { - std::string workModeId = fields.value(DMDefWorkMode::WORK_MODE_ID); + int workModeId = fields.get(DMDefWorkMode::WORK_MODE_ID); std::string name = fields.value(DMDefWorkMode::NAME); - this->mapping.workMode.push_back({workModeId, name}); - str += ("工作模式: {" + workModeId + ":" + name + "},"); + this->mapping.workMode.push_back({std::to_string(workModeId), name}); + this->mapWorkMode[workModeId] = name; + str += ("工作模式: {" + std::to_string(workModeId)+":" + name + "},"); } XLOGD() << str; } @@ -63,10 +64,11 @@ void AppData::initFromDB() DAO::queryPolicyTypeDef(dao, result); for (auto& fields: result) { - std::string policyTypeId = fields.value(DMDefPolicyType::POLICY_TYPE_ID); + int policyTypeId = fields.get(DMDefPolicyType::POLICY_TYPE_ID); std::string name = fields.value(DMDefWorkMode::NAME); - this->mapping.workMode.push_back({policyTypeId, name}); - str += ("策略类型: {" + policyTypeId + ":" + name + "},"); + this->mapping.policyType.push_back({std::to_string(policyTypeId), name}); + this->mapPolicyType[policyTypeId] = name; + str += ("策略类型: {" + std::to_string(policyTypeId) + ":" + name + "},"); } XLOGD() << str; } @@ -78,7 +80,9 @@ void AppData::initFromDB() auto item = std::make_shared(); item->typeId = fields.get(DMDefDeviceType::DEVICE_TYPE_ID); item->name = fields.value(DMDefDeviceType::NAME); - item->attrs = fields.value(DMDefDeviceType::ATTRS); + item->group = fields.value(DMDefDeviceType::GROUP); + item->attr = fields.value(DMDefDeviceType::ATTRS); + item->fieldsAttr.parseJson(item->attr); mapDeviceType[item->typeId] = item; mapping.deviceType.push_back({std::to_string(item->typeId), item->name}); str += ("设备类型: {" + std::to_string(item->typeId) + ":" + item->name + "},"); @@ -106,12 +110,11 @@ void AppData::initFromDB() DAO::queryStationList(dao, result); for (auto& fields: result) { - int stationId = fields.get(DMStation::STATION_ID); - auto station = std::make_shared(stationId); - station->name = fields.value(DMStation::NAME); - station->energyCapacity = fields.get(DMStation::CAPACITY); - this->mapStation[stationId] = station; - str += ("场站: {" + std::to_string(stationId) + ":" + station->name + "},"); + auto station = std::make_shared(); + station->setFields(fields); + this->mapStation[station->id] = station; + mapping.stationName.push_back({std::to_string(station->id), station->name}); + str += ("场站: {" + std::to_string(station->id) + ":" + station->name + "},"); } XLOGD() << str; } @@ -126,6 +129,8 @@ void AppData::initFromDB() if (station) { auto device = Device::create(fields); + auto deviceTypeDef = this->getDeviceTypeDef(device->type); + device->group = deviceTypeDef->group; station->addDevice(deviceId, device); } else @@ -247,9 +252,24 @@ std::shared_ptr AppData::getDevice(int stationId, int deviceId) return nullptr; } -std::unordered_map>& AppData::getDeviceTypeDef() +std::string AppData::getDeviceNameById(int typeId) { - return mapDeviceType; + auto iter = mapDeviceType.find(typeId); + if (iter != mapDeviceType.end()) + { + return iter->second->name; + } + return ""; +} + +std::shared_ptr AppData::getDeviceTypeDef(int typeId) +{ + auto iter = mapDeviceType.find(typeId); + if (iter != mapDeviceType.end()) + { + return iter->second; + } + return nullptr; } void AppData::loadStatData() @@ -261,8 +281,18 @@ void AppData::initUser() { auto dao = DaoEntity::create(""); std::vector result; +} - +int AppData::getWorkModeIdByName(std::string name) +{ + for (auto iter = mapWorkMode.begin(); iter!=mapWorkMode.end(); ++iter) + { + if (iter->second == name) + { + return iter->first; + } + } + return 0; } std::vector AppData::getRoleNames() @@ -331,6 +361,16 @@ std::vector AppData::getPolicyNames() return vec; } +int AppData::getPolicyTypeId(std::string name) +{ + for (auto iter = mapPolicyType.begin(); iter != mapPolicyType.end(); ++iter) + { + if (iter->second == name) { return iter->first; } + } + return 0; +} + + std::vector AppData::getElectPreiodVals(int month) { if (month > 0 && month-1 < vecElectPeriods.size()) diff --git a/src/app/AppData.h b/src/app/AppData.h index 163bf98..23066a1 100644 --- a/src/app/AppData.h +++ b/src/app/AppData.h @@ -5,6 +5,7 @@ #include #include #include +#include "common/Fields.h" class Station; class Device; @@ -16,7 +17,9 @@ struct DeviceType { int typeId {}; std::string name; - std::string attrs; + std::string group; + std::string attr; + Fields fieldsAttr; }; struct Role @@ -47,20 +50,27 @@ public: void init(); void initFromDB(); - std::shared_ptr getStation(int stationId); - std::shared_ptr getStationByName(std::string name); - - std::shared_ptr getDevice(int stationId, int deviceId); - - // 获取设备类型定义 - std::unordered_map>& getDeviceTypeDef(); // 读取统计数据: 今日统计数据,累计统计数据 void loadStatData(); void initUser(); + + std::shared_ptr getStation(int stationId); + + std::shared_ptr getStationByName(std::string name); + + std::shared_ptr getDevice(int stationId, int deviceId); + + std::string getDeviceNameById(int typeId); + + // 获取设备类型定义 + std::shared_ptr getDeviceTypeDef(int typeId); + + int getWorkModeIdByName(std::string name); + /////////////////////////////////////////////////////////////////////////////////////////////// // 获取角色名称列表 std::vector getRoleNames(); @@ -74,6 +84,9 @@ public: std::vector getPolicyTypeNames(); // 获取策略名称 std::vector getPolicyNames(); + // 根据策略类型ID获取策略类型名称 + // 根据策略类型名称获取策略类型ID + int getPolicyTypeId(std::string name); std::vector getElectPreiodVals(int month); @@ -103,6 +116,9 @@ public: VecPairSS deviceType; VecPairSS workMode; + + VecPairSS policyType; + VecPairSS stationName; } mapping; double electPriceSuperPeak {}; diff --git a/src/app/Device.cpp b/src/app/Device.cpp index 6535184..8496dbf 100644 --- a/src/app/Device.cpp +++ b/src/app/Device.cpp @@ -2,7 +2,7 @@ #include "common/Logger.h" #include "common/Utils.h" -#include "protocol/Communicator.h" +#include "protocol/CommEntity.h" #include "common/JsonN.h" //int DeviceEntity::getAttrInt(std::string key) @@ -56,7 +56,7 @@ int Device::startComm() // 创建新的通讯 if (!commEntity) { - commEntity = Communicator::createEntity(attrs); + commEntity = CommEntity::create(attrs); if (!commEntity) { return -1; } } diff --git a/src/app/Device.h b/src/app/Device.h index 12629fa..d206f0e 100644 --- a/src/app/Device.h +++ b/src/app/Device.h @@ -16,15 +16,14 @@ public: int type = -1; std::string name; std::string code; + std::string group; bool isOpen = false; std::string attrsJson = ""; - int err = 0; int online = 0; int status = 0; - //std::map mapAttrs; Fields attrs; @@ -41,16 +40,3 @@ public: static std::shared_ptr create(Fields& fields); }; - - -//class Device -//{ -//public: -// static void add(DataFields& fields); -// -// static std::vector> getDeviceByType(int type); -// -//public: -// static std::map> mapDevices; -//}; - diff --git a/src/app/Station.cpp b/src/app/Station.cpp index e9a97b6..1993126 100644 --- a/src/app/Station.cpp +++ b/src/app/Station.cpp @@ -1,28 +1,70 @@ #include "Station.h" #include "database/DAO.h" #include "database/SQL.h" +#include "common/fields.h" +#include "app/Device.h" -Station::Station(int id) : id(id) + +Station::Station() : id(0) { } +void Station::setFields(Fields& fields) +{ + this->id = fields.get(DMStation::STATION_ID); + this->name = fields.value(DMStation::NAME); + this->energyCapacity = fields.get(DMStation::CAPACITY); + this->workModeId = fields.get(DMStation::WORK_MODE_ID); +} + void Station::addDevice(int deviceId, std::shared_ptr device) { - mapDevice_[deviceId] = device; + mapDevice[deviceId] = device; + mapDeviceGroupNum[device->group]++; } std::shared_ptr Station::getDevice(int deviceId) { - auto iter = mapDevice_.find(deviceId); - if (iter!=mapDevice_.end()) + auto iter = mapDevice.find(deviceId); + if (iter!=mapDevice.end()) { return iter->second; } return nullptr; } +void Station::getDeviceByType(int typeId, std::vector>& res) +{ + for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter) + { + auto device = iter->second; + if (device->type == typeId) + { + res.push_back(device); + } + } +} + +int Station::getDeviceNumByGroup(std::string name) +{ + return mapDeviceGroupNum[name]; +} + +void Station::getDeviceByGroup(std::string name, std::vector>& res) +{ + for (auto iter = mapDevice.begin(); iter!=mapDevice.end(); ++iter) + { + auto device = iter->second; + if (device->group == name) + { + res.push_back(device); + } + } +} + void Station::setWorkMode(int modeId) { + this->workModeId = modeId; std::string sql = SQL(SQL::TYPE::update).table(DMStation::TABLENAME) .update(DMStation::WORK_MODE_ID, std::to_string(modeId)) .where(DMStation::STATION_ID + "=" + std::to_string(id)).str(); @@ -43,4 +85,4 @@ void Station::setPolicy(int policyId) { XLOGE() << "set station policy failed."; } -} \ No newline at end of file +} diff --git a/src/app/Station.h b/src/app/Station.h index c9bebb7..eaba3dc 100644 --- a/src/app/Station.h +++ b/src/app/Station.h @@ -2,27 +2,35 @@ #include #include +#include "common/Fields.h" class Device; class Station { public: - Station(int id); + Station(); + + void setFields(Fields& fields); void addDevice(int deviceId, std::shared_ptr device); std::shared_ptr getDevice(int deviceId); + void getDeviceByType(int typeId, std::vector>& res); + int getDeviceNumByGroup(std::string name); + void getDeviceByGroup(std::string name, std::vector>& res); + void setWorkMode(int modeId); void setPolicy(int policyId); + public: int id {}; std::string name; - int workModeId; // 运行模式 - int runPolicyId; // 运行策略 + int workModeId {}; // 运行模式 + int runPolicyId {}; // 运行策略 // 储能容量 double energyCapacity {}; @@ -77,5 +85,7 @@ public: /////////////////////////////////////////////////////////////////////////////////////////////// /// === 设备信息 === - std::unordered_map> mapDevice_; + std::unordered_map> mapDevice; + + std::map mapDeviceGroupNum; }; \ No newline at end of file diff --git a/src/common/Fields.cpp b/src/common/Fields.cpp index f76961a..23ff4b2 100644 --- a/src/common/Fields.cpp +++ b/src/common/Fields.cpp @@ -1,6 +1,6 @@ #include "Fields.h" #include "common/Utils.h" - +#include "common/JsonN.h" std::string& Fields::value(std::string key) { @@ -14,14 +14,16 @@ bool Fields::contains(std::string key) return (mapFields.find(key) != mapFields.end()); } -std::unordered_map::iterator Fields::remove(string key) +std::string Fields::remove(string key) { + std::string val; auto it = mapFields.find(key); if (it != mapFields.end()) { - it = mapFields.erase(it); + val = it->second; + mapFields.erase(it); } - return it; + return val; } void Fields::append(Fields& datafield) @@ -177,6 +179,13 @@ string Fields::toSqlUpdate(string tableName, std::vector vecKeys, s return oss.str(); } +void Fields::parseJson(std::string jsonstr) +{ + NJsonNode jsonroot; + NJson::parse(jsonstr, jsonroot); - - + for (auto& item : jsonroot.items()) + { + this->set(item.key(), item.value()); + } +} \ No newline at end of file diff --git a/src/common/Fields.h b/src/common/Fields.h index bc9e569..3c1be32 100644 --- a/src/common/Fields.h +++ b/src/common/Fields.h @@ -19,6 +19,8 @@ struct PageInfo class Fields { public: + Fields() {}; + template void set(string key, T val, int precision=6) { @@ -42,7 +44,6 @@ public: return val; } - /** * 获取值 * @param: [string key] 索引名称 @@ -60,7 +61,7 @@ public: * 删除指定索引的值 * @param: [string key] 索引名称 */ - std::unordered_map::iterator remove(string key); + std::string remove(string key); /** * 追加合并 @@ -136,6 +137,8 @@ public: */ string toSqlUpdate(string tableName, std::vector vecKeys, string condition); + void parseJson(std::string jsonstr); + private: std::unordered_map mapFields; }; diff --git a/src/common/JsonN.h b/src/common/JsonN.h index 54eb1cb..ef66330 100644 --- a/src/common/JsonN.h +++ b/src/common/JsonN.h @@ -91,6 +91,15 @@ public: std::cout << "JSON read error: " << e.what() << std::endl; } } + + static void parse(std::string jsonstr, std::vector& vd) + { + NJsonNode jsonroot; + if (NJson::parse(jsonstr, jsonroot)) + { + vd = jsonroot.get>(); + } + } }; diff --git a/src/common/Logger.cpp b/src/common/Logger.cpp index b856756..df98fc0 100644 --- a/src/common/Logger.cpp +++ b/src/common/Logger.cpp @@ -7,7 +7,7 @@ std::mutex g_mutex; -Logger::Logger(Logger::ELogType logtype, std::string filename, int lineEdit) : line_(lineEdit) +Logger::Logger(Logger::ELogType logtype, std::string filename, int edit) : line_(edit) { auto index = filename.find_last_of('\\'); if (index != std::string::npos) diff --git a/src/common/Logger.h b/src/common/Logger.h index 2eb52a6..1322504 100644 --- a/src/common/Logger.h +++ b/src/common/Logger.h @@ -19,7 +19,7 @@ public: }; public: - Logger(Logger::ELogType logType, std::string filename, int lineEdit); + Logger(Logger::ELogType logType, std::string filename, int edit); ~Logger(); std::stringstream& Stream() { return oss_; } diff --git a/src/database/Dao.cpp b/src/database/Dao.cpp index 2e79d3a..98b9830 100644 --- a/src/database/Dao.cpp +++ b/src/database/Dao.cpp @@ -84,6 +84,9 @@ Errcode DAO::insertUser(Fields& params) auto dao = DaoEntity::create(DMUser::TABLENAME); std::string account = params.value(DMUser::ACCOUNT); + std::string userRoleId = params.remove(DMRole::ROLE_ID); + + // step1: 查询 std::vector result; bool ret = dao->exec("SELECT * from user WHERE account='" + account + "';", result); @@ -101,11 +104,14 @@ Errcode DAO::insertUser(Fields& params) { return Errcode::ERR_DB_SQL; } - Fields paramsUserRole; - paramsUserRole.set(DMUser::USER_ID, params.value(DMUser::USER_ID)); - paramsUserRole.set(DMRole::ROLE_ID, params.value(DMRole::ROLE_ID)); - paramsUserRole.set(DMUser::UPDATETIME, createTime); - ret = dao->duplicateUpdate(paramsUserRole, {DMUser::USER_ID}); + if (!userRoleId.empty()) + { + Fields paramsUserRole; + paramsUserRole.set(DMUser::USER_ID, params.value(DMUser::USER_ID)); + paramsUserRole.set(DMRole::ROLE_ID, userRoleId); + paramsUserRole.set(DMUser::UPDATETIME, createTime); + ret = dao->duplicateUpdate(paramsUserRole, {DMUser::USER_ID}); + } return Errcode::OK; } @@ -127,30 +133,28 @@ bool DAO::queryUserList(PageInfo& pageInfo, vector& result) Errcode DAO::updateUserById(Fields& params) { - std::string createTime = Utils::timeStr(); - std::string userId = params.value(DMUser::USER_ID); - std::string roleId = ""; - if (params.contains(DMRole::ROLE_ID)) - { - roleId = params.value(DMRole::ROLE_ID); - params.remove(DMUser::USER_ID); - } - auto dao = DaoEntity::create(DMUser::TABLENAME); - bool ret = dao->updateFields(params, "WHERE " + DMUser::USER_ID + "='" + userId + "'"); - if (!ret) - { - return Errcode::ERR_DB_SQL; - } + std::string createTime = Utils::timeStr(); + std::string userId = params.remove(DMUser::USER_ID); + std::string roleId = params.remove(DMRole::ROLE_ID); + + if (params.size() > 0) + { + bool ret = dao->updateFields(params, "WHERE " + DMUser::USER_ID + "='" + userId + "'"); + if (!ret) + { + return Errcode::ERR_DB_SQL; + } + } if (!roleId.empty()) { dao->setTableName(DMUserRole::TABLENAME); Fields paramsUserRole; - paramsUserRole.set(DMUserRole::USER_ID, params.value(DMUserRole::USER_ID)); - paramsUserRole.set(DMUserRole::ROLE_ID, params.value(DMUserRole::ROLE_ID)); + paramsUserRole.set(DMUserRole::USER_ID, userId); + paramsUserRole.set(DMUserRole::ROLE_ID, roleId); paramsUserRole.set(DMUserRole::UPDATETIME, createTime); - ret = dao->duplicateUpdate(paramsUserRole, {DMUser::USER_ID}); + bool ret = dao->duplicateUpdate(paramsUserRole, {DMUserRole::ROLE_ID}); if (!ret) { return Errcode::ERR_DB_SQL; @@ -298,6 +302,20 @@ Errcode DAO::queryPolicyList(std::shared_ptr dao, vector& res std::string sql = "SELECT * FROM " + DMPolicy::TABLENAME; return DAO::exec(dao, sql, result); } +Errcode DAO::insertPolicy(Fields& params) +{ + return DAO::exec(NULL, params.toSqlInsert(DMPolicy::TABLENAME)); +} +Errcode DAO::updatePolicyById(Fields& params) +{ + std::string policyId = params.value(DMPolicy::POLICY_ID); + if (policyId.empty()) + { + return Errcode::ERR_DB_SQL; + } + std::string sql = params.toSqlUpdate(DMPolicy::TABLENAME, "WHERE " + DMPolicy::POLICY_ID + "='" + policyId + "'"); + return DAO::exec(NULL, sql); +} // 系统日志管理 bool DAO::querySystemLogList(PageInfo& pageInfo, vector& result) diff --git a/src/database/Dao.h b/src/database/Dao.h index a290c18..7388981 100644 --- a/src/database/Dao.h +++ b/src/database/Dao.h @@ -68,6 +68,9 @@ public: static bool queryPolicyList(PageInfo& pageInfo, vector& result); static Errcode queryPolicyList(std::shared_ptr dao, vector& result); + + static Errcode insertPolicy(Fields& params); + static Errcode updatePolicyById(Fields& params); /////////////////////////////////////////////////////////////////////////////////////////////// // === 系统日志管理 === diff --git a/src/database/DaoEntity.cpp b/src/database/DaoEntity.cpp index 16b11ac..9be63fe 100644 --- a/src/database/DaoEntity.cpp +++ b/src/database/DaoEntity.cpp @@ -2,7 +2,7 @@ //#include "PvInstance.h" //#include "spdlogger.h" -MysqlOption DaoEntity::option_; +MysqlOption DaoEntity::option; DaoEntity::DaoEntity(string tb_name) { @@ -12,7 +12,7 @@ DaoEntity::DaoEntity(string tb_name) //opts.password = "123456"; //opts.port = 3306; //opts.dbname = "pvb"; - db_ = make_shared(DaoEntity::option_); + db_ = make_shared(DaoEntity::option); if (!db_->isConnected()) { //Global::data().status_msg = "数据库连接异常!"; @@ -28,15 +28,15 @@ DaoEntity::~DaoEntity() MysqlOption& DaoEntity::mysqlOption() { - return DaoEntity::option_; + return DaoEntity::option; } void DaoEntity::setOption(std::string host, int port, std::string user, std::string pwd, std::string dbname) { - option_.host = host; - option_.port = port; - option_.user = user; - option_.password = pwd; - option_.dbname = dbname; + option.host = host; + option.port = port; + option.user = user; + option.password = pwd; + option.dbname = dbname; } std::shared_ptr DaoEntity::create(string tb_name) @@ -46,13 +46,13 @@ std::shared_ptr DaoEntity::create(string tb_name) bool DaoEntity::execOnce(string sql) { - auto db = make_shared(DaoEntity::option_); + auto db = make_shared(DaoEntity::option); return db->exec(sql); } bool DaoEntity::execOnce(string sql, vector& result) { - auto db = make_shared(DaoEntity::option_); + auto db = make_shared(DaoEntity::option); return db->exec(sql, result); } @@ -130,27 +130,27 @@ bool DaoEntity::insertFields(vector& vec_fields) bool DaoEntity::duplicateUpdate(Fields& fields, const vector& keys) { //insert into device_attr(device_id, attr_id, attr_val) values('26', 'model', '型号1') on duplicate key update attr_val='型号1'; - string s_key; - string s_val; + string key; + string val; for (auto& item : fields.map()) { - if (!s_key.empty()) + if (!key.empty()) { - s_key += ","; s_val += ","; + key += ","; val += ","; } - s_key += (item.first); - s_val += ("'" + item.second + "'"); + key += (item.first); + val += ("'" + item.second + "'"); } - string s_data; + string str; for (auto& k : keys) { - if (!s_data.empty()) + if (!str.empty()) { - s_data += ","; + str += ","; } - s_data += (k + "='" + fields.value(k) + "'"); + str += (k + "='" + fields.value(k) + "'"); } - string sql = "INSERT INTO " + tableName_ + "(" + s_key + ") VALUES (" + s_val + ") ON duplicate KEY UPDATE " + s_data; + string sql = "INSERT INTO " + tableName_ + "(" + key + ") VALUES (" + val + ") ON duplicate KEY UPDATE " + str; return this->db_->exec(sql); } diff --git a/src/database/DaoEntity.h b/src/database/DaoEntity.h index 9b6ef69..0dab9a5 100644 --- a/src/database/DaoEntity.h +++ b/src/database/DaoEntity.h @@ -100,7 +100,7 @@ public: bool updateFields(Fields& fields, vector vecKeys, const string& cond); protected: - static MysqlOption option_; + static MysqlOption option; // mysql 数据库操作对象 std::shared_ptr db_ = nullptr; diff --git a/src/database/DataModelDef.h b/src/database/DataModelDef.h index 2d30d87..6cfb9ec 100644 --- a/src/database/DataModelDef.h +++ b/src/database/DataModelDef.h @@ -98,6 +98,7 @@ namespace DMDefDeviceType const string TABLENAME = "def_device_type"; const string DEVICE_TYPE_ID = "device_type_id"; const string NAME = "name"; + const string GROUP = "group"; const string ATTRS = "attrs"; } diff --git a/src/database/MysqlClient.cpp b/src/database/MysqlClient.cpp index 076732f..d73fbf4 100644 --- a/src/database/MysqlClient.cpp +++ b/src/database/MysqlClient.cpp @@ -3,7 +3,7 @@ //#include "Spdlogger.h" #include "Logger.h" -MysqlClient::MysqlClient(MysqlOption option) : option_(option) +MysqlClient::MysqlClient(MysqlOption option) : option(option) { conn(); } @@ -20,7 +20,7 @@ int MysqlClient::conn() return 0; } mysql_ = mysql_init(nullptr); - MYSQL* ret = mysql_real_connect(mysql_, option_.host.c_str(), option_.user.c_str(), option_.password.c_str(), option_.dbname.c_str(), option_.port, NULL, 0); + MYSQL* ret = mysql_real_connect(mysql_, option.host.c_str(), option.user.c_str(), option.password.c_str(), option.dbname.c_str(), option.port, NULL, 0); if (ret == NULL) { std::string err = mysql_error(mysql_); diff --git a/src/database/MysqlClient.h b/src/database/MysqlClient.h index 9e10bd5..3d5e9e0 100644 --- a/src/database/MysqlClient.h +++ b/src/database/MysqlClient.h @@ -62,7 +62,7 @@ private: MYSQL* mysql_ = nullptr; // 数据库连接信息 - MysqlOption option_; + MysqlOption option; }; #endif // !!! _DbMysql_H_ diff --git a/src/main.cpp b/src/main.cpp index 1287bc5..d655e19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,9 @@ #include "pv/PvApp.h" #include "pv/PvUser.h" +#include "rlsocket.h" +#define wsa rlwsa int main(int argc, char** argv) { // 设置控制台输出为 UTF-8 编码 @@ -52,6 +54,24 @@ int main(int argc, char** argv) std::cout << jsonroot1.dump(); } + std::map mapT; + bool ff = mapT[1]; + + //rlwsa(); + //rlSocket socket("127.0.0.1", 19801, 1); + //int ret = socket.connect(); + //std::string s1 = "helloworld"; + //socket.write(s1.c_str(), s1.size()); + + //std::vector buf(1024, 0); + //while (true) + //{ + // int len = socket.read(&buf[0], 1, 0); + // if (len > 0) + // { + // std::cout << "===>>> " << std::string(buf.begin(), buf.end()); + // } + //} std::cout << "===>>> main start ... " << std::endl; ////std::cout << Snowflake::instance().getId() << std::endl; diff --git a/src/protocol/Communicator.cpp b/src/protocol/CommEntity.cpp similarity index 84% rename from src/protocol/Communicator.cpp rename to src/protocol/CommEntity.cpp index e8fe42d..79457a5 100644 --- a/src/protocol/Communicator.cpp +++ b/src/protocol/CommEntity.cpp @@ -1,7 +1,7 @@ -#include "Communicator.h" +#include "CommEntity.h" #include "TcpEntity.h" -std::shared_ptr Communicator::createEntity(Fields& data) +std::shared_ptr CommEntity::create(Fields& data) { std::string commType = data.value("commType"); std::string ip = data.value("ip"); diff --git a/src/protocol/Communicator.h b/src/protocol/CommEntity.h similarity index 86% rename from src/protocol/Communicator.h rename to src/protocol/CommEntity.h index 7f5a599..6dd03e9 100644 --- a/src/protocol/Communicator.h +++ b/src/protocol/CommEntity.h @@ -11,6 +11,8 @@ public: CommEntity() {} CommEntity(std::string type) : type(type) {} + static std::shared_ptr create(Fields& data); + void setType(std::string type) { this->type = type; } // 启动通讯连接 @@ -30,10 +32,3 @@ public: bool isCloseRequest_ = false; std::string type; }; - - -class Communicator -{ -public: - static std::shared_ptr createEntity(Fields& data); -}; \ No newline at end of file diff --git a/src/protocol/TcpEntity.h b/src/protocol/TcpEntity.h index 0fa2521..0d53bbf 100644 --- a/src/protocol/TcpEntity.h +++ b/src/protocol/TcpEntity.h @@ -7,7 +7,7 @@ #include #include -#include "Communicator.h" +#include "CommEntity.h" using namespace std; diff --git a/src/pv/MaskMain.cpp b/src/pv/MaskMain.cpp index f9d7169..8e13a81 100644 --- a/src/pv/MaskMain.cpp +++ b/src/pv/MaskMain.cpp @@ -20,13 +20,12 @@ std::string GetDateTimeWeekday() return ss.str(); } - - int MaskMain::initUI() { //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"); + PvApp::label(p, PV_ID_MAIN, 0, 0, 1920, 1080, "", "background-color: rgb(1, 32, 54)"); + PvApp::image(p, 0, 0, 0, 1920, 90, "bkgHead.png"); ui.datetime = PvApp::label(p, PV_ID_MAIN, 10, 30, 420, 30, GetDateTimeWeekday(), qss::label(20)); pvSetAlignment(p, ui.datetime, AlignCenter); diff --git a/src/pv/PvApp.cpp b/src/pv/PvApp.cpp index 1e0b93e..87cfcfe 100644 --- a/src/pv/PvApp.cpp +++ b/src/pv/PvApp.cpp @@ -5,6 +5,72 @@ #define FONT_NAME "微软雅黑" +PvRect::PvRect() +{ +} + +PvRect::PvRect(int ix, int iy, int iw, int ih) + : x(ix), y(iy), w(iw), h(ih) +{ +} + +PvRect& PvRect::set(int ix, int iy, int iw, int ih) +{ + x = ix; + y = iy; + w = iw; + h = ih; + return *this; +} + +PvRect& PvRect::setx(int ix) +{ + x = ix; + return *this; +} + +PvRect& PvRect::sety(int iy) +{ + y = iy; + return *this; +} + +PvRect& PvRect::setw(int iw) +{ + w = iw; + return *this; +} + +PvRect& PvRect::seth(int ih) +{ + h = ih; + return *this; +} +PvRect& PvRect::shiftx(int ix) +{ + x += ix; + return *this; +} + +PvRect& PvRect::shifty(int iy) +{ + y += iy; + return *this; +} + +PvRect& PvRect::shiftw(int iw) +{ + w += iw; + return *this; +} + +PvRect& PvRect::shifth(int ih) +{ + h += ih; + return *this; +} + + void PvApp::setPvUser(PARAM* p, PvUser* pvuser) { p->user = pvuser; @@ -23,10 +89,8 @@ int PvApp::pvid(PARAM* p) void PvApp::reset(PARAM* p) { - // 清理event回调 auto pvuser = PvApp::getPvUser(p); - pvuser->mapEventCallback.clear(); - pvuser->pvidIndex = 0; + if (pvuser) { pvuser->reset(); } } EPvCode PvApp::getPvCode(std::string name) @@ -64,7 +128,6 @@ EPvCode PvApp::getPvCode(std::string name) } } - void PvApp::bind(PARAM* p, PvEvent eid, int pvid, std::function cb) { auto pvuser = PvApp::getPvUser(p); @@ -99,13 +162,22 @@ int PvApp::widget(PARAM* p, int parent, int x, int y, int w, int h) int PvApp::label(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) { + static const std::string style = "QLabel { border: none; background-color: transparent; } QLabel:disabled { color: gray;}"; int id = PvApp::pvid(p); pvQLabel(p, id, parent); pvSetGeometry(p, id, x, y, w, h); if (!text.empty()) { pvSetText(p, id, text.c_str()); } - pvSetStyleSheet(p, id, qss.empty() ? qss::label().c_str() : qss.c_str()); + pvSetStyleSheet(p, id, qss.empty() ? style.c_str() : qss.c_str()); return id; } + +int PvApp::labelCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) +{ + int id = PvApp::label(p, parent, x, y, w, h, text, qss); + pvSetAlignment(p, id, AlignCenter); + return id; +} + int PvApp::labelAlignCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) { int id = PvApp::label(p, parent, x, y, w, h, text, qss); @@ -128,7 +200,6 @@ int PvApp::image(PARAM* p, int parent, int x, int y, int w, int h, const char* f int id = PvApp::pvid(p); pvQImage(p, id, parent, filename); pvSetGeometry(p, id, x, y, w, h); - //if (!qss.empty()) { pvSetStyleSheet(p, id, qss.c_str()); } return id; } @@ -147,7 +218,7 @@ int PvApp::combox(PARAM* p, int parent, int x, int y, int w, int h, const std::v return id; } -int PvApp::lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) +int PvApp::textedit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) { int id = PvApp::pvid(p); pvQLineEdit(p, id, parent); @@ -157,11 +228,11 @@ int PvApp::lineEdit(PARAM* p, int parent, int x, int y, int w, int h, std::strin return id; } -int PvApp::textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) +int PvApp::multiTextedit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss) { static std::string style = - "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);}"; + "QTextEdit { background-color: rgb(12, 39, 58); border: 1px solid rgb(18, 251, 255); border-radius: 3px; color:white; font: bold 14px;}" + "QTextEdit:disabled { border: none; color: gray;}"; int id = PvApp::pvid(p); pvQMultiLineEdit(p, id, parent, true, 10); pvSetGeometry(p, id, x, y, w, h); @@ -174,7 +245,7 @@ int PvApp::radioButton(PARAM* p, int parent, int x, int y, int w, int h, std::st { static std::string style = "QRadioButton { background-color: transparent; color:white; font: bold 14px \"微软雅黑\";}" - "QRadioButton:disabled { border: none; color:rgb(150,150,150);}"; + "QRadioButton:disabled { border: none; color: gray;}"; int id = PvApp::pvid(p); pvQRadioButton(p, id, parent); @@ -188,7 +259,7 @@ int PvApp::timeEdit(PARAM* p, int parent, int x, int y, int w, int h) { static std::string style = "QTimeEdit { background-color: rgb(17, 55, 73); border: 1px solid rgb(0, 185, 208); color:white; font: normal 14px \"微软雅黑\";}" - "QTimeEdit:disabled { border: none; color:rgb(150,150,150);}"; + "QTimeEdit:disabled { border: none; color: gray;}"; int id = PvApp::pvid(p); pvQTimeEdit(p, id, parent); @@ -197,67 +268,15 @@ int PvApp::timeEdit(PARAM* p, int parent, int x, int y, int w, int h) return id; } -PvRect::PvRect() +int PvApp::lineLabel(PARAM* p, int parent, PvRect& rect, int w, std::string key, std::string val) { + int pid = PvApp::label(p, parent, rect.x, rect.y, rect.w, rect.h, key, qss::label(14)); + return PvApp::label(p, pid, w, 0, rect.w-w, rect.h, val); } -PvRect::PvRect(int ix, int iy, int width, int height) - : x(ix), y(iy), w(width), h(height) +int PvApp::lineTextedit(PARAM* p, int parent, PvRect& rect, int w, std::string key, std::string val) { + int pid = PvApp::label(p, parent, rect.x, rect.y, rect.w, rect.h, key, qss::label(14)); + return PvApp::textedit(p, pid, w, 0, rect.w-w, rect.h, val); } -PvRect& PvRect::set(int ix, int iy, int width, int height) -{ - x = ix; - y = iy; - w = width; - h = height; - return *this; -} - -PvRect& PvRect::set_x(int ix) -{ - x = ix; - return *this; -} - -PvRect& PvRect::set_y(int iy) -{ - y = iy; - return *this; -} - -PvRect& PvRect::set_w(int iw) -{ - w = iw; - return *this; -} - -PvRect& PvRect::set_h(int ih) -{ - h = ih; - return *this; -} -PvRect& PvRect::shift_x(int ix) -{ - x += ix; - return *this; -} - -PvRect& PvRect::shift_y(int iy) -{ - y += iy; - return *this; -} - -PvRect& PvRect::shift_w(int iw) -{ - w += iw; - return *this; -} - -PvRect& PvRect::shift_h(int ih) -{ - h += ih; - return *this; -} diff --git a/src/pv/PvApp.h b/src/pv/PvApp.h index a878ee7..136783d 100644 --- a/src/pv/PvApp.h +++ b/src/pv/PvApp.h @@ -53,6 +53,51 @@ enum class EPvCode MASK_MGR_ALERTLOG, }; +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// === PvRect +class PvRect +{ +public: + PvRect(); + PvRect(int ix, int iy, int iw, int ih); + + PvRect& set(int ix, int iy, int iw, int ih); + PvRect& setx(int ix); + PvRect& sety(int iy); + PvRect& setw(int iw); + PvRect& seth(int ih); + + PvRect& shiftx(int ix); + PvRect& shifty(int iy); + PvRect& shiftw(int iw); + PvRect& shifth(int ih); + +public: + int x = 0; + int y = 0; + int w = 100; + int h = 30; +}; + +struct PvColor +{ + int r; + int g; + int b; + int a; + + PvColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {} + std::string rgb() + { + return "rgb(" + std::to_string(r) + "," + std::to_string(g) + "," + std::to_string(b) + ")"; + } + std::string rgba() + { + return "rgb(" + std::to_string(r) + "," + std::to_string(g) + "," + std::to_string(b) + "," + std::to_string(a) + ")"; + } +}; + + class PvObject { public: @@ -93,6 +138,8 @@ public: static int label(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); + static int labelCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); + static int labelAlignCenter(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); static int button(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); @@ -101,57 +148,16 @@ public: static int combox(PARAM* p, int parent, int x, int y, int w, int h, const std::vector& vecItems, int index=0); - 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 = ""); - static int textEdit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); + static int multiTextedit(PARAM* p, int parent, int x, int y, int w, int h, std::string text, std::string qss = ""); static int radioButton(PARAM* p, int parent, int x, int y, int w, int h, std::string text); static int timeEdit(PARAM* p, int parent, int x, int y, int w, int h); + + static int lineLabel(PARAM* p, int parent, PvRect& rect, int w, std::string key, std::string val); + + static int lineTextedit(PARAM* p, int parent, PvRect& rect, int w, std::string key, std::string val); }; -/////////////////////////////////////////////////////////////////////////////////////////////////// -/// === PvRect -class PvRect -{ -public: - PvRect(); - - PvRect(int ix, int iy, int width, int height); - - PvRect& set(int ix, int iy, int width, int height); - - PvRect& set_x(int ix); - PvRect& set_y(int iy); - PvRect& set_w(int iw); - PvRect& set_h(int ih); - - PvRect& shift_x(int ix); - PvRect& shift_y(int iy); - PvRect& shift_w(int iw); - PvRect& shift_h(int ih); - -public: - int x = 0; - int y = 0; - int w = 100; - int h = 32; -}; - -struct PvColor -{ - int r; - int g; - int b; - int a; - - PvColor(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {} - std::string rgb() - { - return "rgb(" + std::to_string(r) + "," + std::to_string(g) + "," + std::to_string(b) + ")"; - } - std::string rgba() - { - return "rgb(" + std::to_string(r) + "," + std::to_string(g) + "," + std::to_string(b) + "," + std::to_string(a) + ")"; - } -}; diff --git a/src/pv/PvChart.cpp b/src/pv/PvChart.cpp index 628fa3d..ffdad68 100644 --- a/src/pv/PvChart.cpp +++ b/src/pv/PvChart.cpp @@ -206,7 +206,7 @@ void PvChartBar::updateItem(int index, std::vectorshow(false); }); } @@ -43,20 +43,21 @@ std::shared_ptr PvPopWidget::addParamLine(std::string ty mapLines[key] = line; PvApp::label(p, ui.widget, x, y, lineKeyWidth, lineHeight, title, qss::label(15)); - if (type == "lineEdit") + if (type == "textedit") { - line->widget = PvApp::lineEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight, ""); + line->widget = PvApp::textedit(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") + else if (type == "multiTextedit") { - line->widget = PvApp::textEdit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight*4, ""); + line->widget = PvApp::multiTextedit(p, ui.widget, x+lineKeyWidth, y, lineValWidth, lineHeight*4, ""); } PvApp::bind(p, PvEvent::TEXT_EVENT, line->widget, [=](std::string text) { line->val = text; + if (callbackTextEvent) callbackTextEvent(key, text); }); if (!editable) { pvSetEnabled(p, line->widget, 0); } return line; @@ -64,12 +65,12 @@ std::shared_ptr PvPopWidget::addParamLine(std::string ty void PvPopWidget::addParamLineEdit(std::string key, std::string title, int x, int y, bool editable/*= true*/) { - this->addParamLine("lineEdit", key, title, x, y, editable); + this->addParamLine("textedit", 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); + this->addParamLine("multiTextedit", key, title, x, y, editable); } void PvPopWidget::addParamCombox(std::string key, std::string title, int x, int y, std::vector items) @@ -103,6 +104,8 @@ void PvPopWidget::setParamText(std::shared_ptr line, std::string text line->val = line->items[0]; pvSetCurrentItem(p, line->widget, 0); } + // 【注意】combox 设置 item 不会触发 TEXT_EVENT + //if (callbackTextEvent) callbackTextEvent(line->key, line->val); } else { @@ -194,4 +197,20 @@ void PvPopWidget::setPrimaryKeys(std::vector keys) { primaryKeys.set(k, ""); } +} + +void PvPopWidget::resize(int width, int height) +{ + int x = (1920-width) *0.5; + int y = (1080-height) *0.5; + pvSetGeometry(p, ui.widget, x, y, width, height); + pvSetGeometry(p, ui.bkg, 2, 2, width-4, height-4); + pvSetGeometry(p, ui.bkgL, 0, 0, 60, height); + pvSetGeometry(p, ui.bkgR, width-60, 0, 60, height); + + int w = 100, h = 40, offset = 50; + x = (width- w*2 - offset) *0.5; + y = height - h - 40; + pvSetGeometry(p, ui.btnOK, x, y, w, h); + pvSetGeometry(p, ui.btnCancel, x+w+offset, y, w, h); } \ No newline at end of file diff --git a/src/pv/PvPopWidget.h b/src/pv/PvPopWidget.h index 04348f3..2260a96 100644 --- a/src/pv/PvPopWidget.h +++ b/src/pv/PvPopWidget.h @@ -35,6 +35,8 @@ public: void setCallbackConfirm(std::function callback) { callbackConfirm = callback; }; + void setCallbackTextEvent(std::function callback) { callbackTextEvent = callback; }; + void setStatus(std::string text); void setMsg(std::string msg); @@ -44,11 +46,14 @@ public: Fields getChangedData(); void checkChangedData(Fields& fields); - void setLineGeometry(int wKey, int wVal, int h); void setPrimaryKeys(std::vector keys); + int widget() { return ui.widget; } + + void resize(int width, int height); + std::string name; std::string status; @@ -61,6 +66,11 @@ public: struct { int widget; + int bkg; + int bkgL; + int bkgR; + int btnOK; + int btnCancel; int title; int msg; } ui; @@ -68,6 +78,7 @@ public: std::map> mapLines; std::function callbackConfirm = nullptr; + std::function callbackTextEvent = nullptr; Fields dataOrigin; Fields primaryKeys; diff --git a/src/pv/PvStyle.cpp b/src/pv/PvStyle.cpp index ac26abb..a9a6e0f 100644 --- a/src/pv/PvStyle.cpp +++ b/src/pv/PvStyle.cpp @@ -48,7 +48,7 @@ namespace qss 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") + const std::string LABEL_BOX = qss::label(16, "", "rgba(200,200,200,20)", "none; border-radius:2px") + "QLabel:hover {border: 1px solid rgb(1, 183, 209);}"; const std::string QSS_BOX_ACTIVE = @@ -88,7 +88,6 @@ namespace qss 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);}"; diff --git a/src/pv/PvTable.cpp b/src/pv/PvTable.cpp index b001fa6..6fb837b 100644 --- a/src/pv/PvTable.cpp +++ b/src/pv/PvTable.cpp @@ -9,57 +9,56 @@ static const string STYLE_BKG = //********************************************************************************************************************* // PvTable -PvTable::PvTable(PARAM* p, int parent, int x, int y, int w, int row, Options& opts) +PvTable::PvTable(PARAM* p, int parent, int x, int y, int w, int irow, 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) + : PvObject(p), option(opts), nrow(irow), ncol(0) { // 计算表格的显示区域 - int h = opts.row_height* row + (opts.show_header ? (opts.head_height) : 0); - rect_.set(x, y, w, h); + int h = opts.row_height* irow + (opts.show_header ? (opts.head_height) : 0); + rect.set(x, y, w, h); // 表格的主窗体(QWidget设置样式无效) - pvid_ = PvApp::widget(p, parent, x, y, w, h+1); + pvid = PvApp::widget(p, parent, x, y, w, h+1); // 表格的背景色和边框样式 - PvApp::label(p, pvid_, 0, 0, w, h+1, "", qss::QSS_TABLE); + PvApp::label(p, pvid, 0, 0, w, h+1, "", qss::QSS_TABLE); - vecHead_.resize(0); - vecRows_.resize(nRow_); - vecData_.resize(nRow_); + vecHeads.resize(0); + vecRows.resize(nrow); + vecData.resize(nrow); // 创建行高亮显示背景 - for (int row = 0; row < nRow_; row++) + for (int row = 0; row < nrow; row++) { - int y = item_posy(row); + int y = row * option.row_height + (option.show_header ? option.head_height : 0); 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; + int widgetRow = PvApp::label(p, pvid, 1, y, rect.w-2, option.row_height, "", qss); + pvHide(p, widgetRow); + vecRows[row].widget = widgetRow; } } void PvTable::addHead(string id, string text, int width, vector> mapping) { - vecHead_.push_back(Head(id, text, width, mapping)); - nCol_ = vecHead_.size(); + vecHeads.push_back(Head(id, text, width, mapping)); + ncol = vecHeads.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) + if (option.show_header) { - vecHead_[col].pvid = PvApp::label(p, pvid_, posCol_, 0, width, option_.head_height, text, qss::QSS_TABLE_HEAD); + vecHeads[col].pvid = PvApp::label(p, pvid, posCol, 0, width, option.head_height, text, qss::QSS_TABLE_HEAD); } // 创建列的单元格 - for (int row = 0; row < nRow_; ++row) + 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")); }); + int cellId = PvApp::label(p, vecRows[row].widget, posCol, 0, width, option.row_height, "", qss::QSS_TABLE_CELL); + vecRows[row].vecCells.push_back(cellId); + PvApp::bind(p, MOUSE_OVER_EVENT, cellId, [=](string s) { highlight(row, (s == "1")); }); } - posCol_ += width; + posCol += width; } void PvTable::addHead(vector vec_text) @@ -68,24 +67,24 @@ void PvTable::addHead(vector vec_text) int x = 0; for (int i = 0; i < vec_text.size(); ++i) { - int w = float(rect_.w-1) * float(i+1) / float(colSize); + 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) +void PvTable::setRowVisible(int irow, bool v) { - if (row < 0 || row >= vecRows_.size()) + if (irow < 0 || irow >= vecRows.size()) { return; } - auto& rowItem = vecRows_[row]; + auto& rowItem = vecRows[irow]; if (rowItem.visible != v) { rowItem.visible = v; - rowItem.visible ? pvShow(p, rowItem.bkg) : pvHide(p, rowItem.bkg); + rowItem.visible ? pvShow(p, rowItem.widget) : pvHide(p, rowItem.widget); if (!v) { for (int col = 0; col 0 && row <= vecRows_.size()) + string qss = ((irow % 2 != 0) ? qss::QSS_TABLE_ROW_0 : qss::QSS_TABLE_ROW_1); + if (vecRows.size() > 0 && irow <= 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()); + pvSetStyleSheet(p, vecRows[irow].widget, qss.c_str()); } } void PvTable::addOperate(vector vecOpt) { // 创建表头的标签 - if (option_.show_header) + if (option.show_header) { - PvApp::label(p, pvid_, posCol_, 0, rect_.w - posCol_, option_.head_height, "操作", qss::QSS_TABLE_HEAD); + PvApp::label(p, pvid, posCol, 0, rect.w - posCol, option.head_height, "操作", qss::QSS_TABLE_HEAD); } - for (int row = 0; row < nRow_; ++row) + 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() }); - auto& vec_opt_btn_ = vecOpt_.back().second; - + int cellWidget = PvApp::label(p, vecRows[row].widget, posCol, 0, rect.w - posCol, option.row_height, "", qss::QSS_TABLE_CELL); + vecOper.push_back({ cellWidget, vector() }); + auto& vec_opt_btn_ = vecOper.back().second; int x = 5, w = 60; for (int i = 0; i < vecOpt.size(); i++) { @@ -128,87 +124,66 @@ void PvTable::addOperate(vector vecOpt) 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); } + if (callbackOper) { callbackOper(row, 0, title); } }); vec_opt_btn_.push_back(btn); x += (w + 5); } - pvHide(p, cellWidget); } } void PvTable::setOperateCallback(CallbackTableOpt cb) { - cbOperate_ = cb; + callbackOper = cb; }; -void PvTable::set_text(PARAM* p, int row, int col, string text, string style) +void PvTable::setRow(int irow, Fields& d) { - if (row < nRow_ && col < nCol_) + if (irow >= nrow) { return; } + + vecData[irow] = d; + for (int col = 0; col < vecHeads.size(); ++col) { - 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()); - } - } -} - -void PvTable::setRowData(int row, Fields& d) -{ - if (row >= nRow_) { return; } - - vecData_[row] = d; - for (int col = 0; col < vecHead_.size(); ++col) - { - auto& head = vecHead_[col]; + auto& head = vecHeads[col]; string text = d.value(head.id); text = head.getMapping(text); - pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); + pvSetText(p, vecRows[irow].vecCells[col], text.c_str()); } - setRowVisible(row, true); - this->setOperateVisible(row, d.size() > 0); + setRowVisible(irow, true); } -void PvTable::setRowData(int row, std::vector vd) +void PvTable::setRow(int irow, std::vector vd) { - if (row >= nRow_) { return; } - pvShow(p, vecRows_[row].bkg); - for (int col = 0; col < vecHead_.size(); ++col) + if (irow >= nrow) { return; } + pvShow(p, vecRows[irow].widget); + for (int col = 0; col < vecHeads.size(); ++col) { if (col < vd.size()) { - auto& head = vecHead_[col]; + auto& head = vecHeads[col]; string text = head.getMapping(vd[col]); - pvSetText(p, vecRows_[row].vecCells[col], text.c_str()); + pvSetText(p, vecRows[irow].vecCells[col], text.c_str()); } } - setRowVisible(row, true); - this->setOperateVisible(row, vd.size() > 0); + setRowVisible(irow, true); } -Fields PvTable::getRowData(int row) +Fields PvTable::row(int irow) { - static Fields tmp; - return (row >= 0 && row < vecData_.size()) ? vecData_[row] : tmp; + return (irow >= 0 && irow < vecData.size()) ? vecData[irow] : Fields(); +} + +Fields PvTable::rowMapping(int rowid) +{ + Fields d = this->row(rowid); + this->mappingData(d); + return d; } void PvTable::mappingData(Fields& fields) { - for (int i=0; i< vecHead_.size(); ++i) + for (int i=0; i< vecHeads.size(); ++i) { - auto& head = vecHead_[i]; + auto& head = vecHeads[i]; if (fields.contains(head.id)) { auto& val = fields.value(head.id); @@ -217,82 +192,23 @@ void PvTable::mappingData(Fields& fields) } } -void PvTable::set_border_visible(PARAM* p, bool v) +int PvTable::rowCount() { - v ? pvShow(p, border_id_) : pvHide(p, border_id_); + return this->nrow; } - -int PvTable::item_posy(int row) +int PvTable::colCount() { - return option_.show_header ? row * option_.row_height + option_.head_height : row * option_.row_height; -} - -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); - // } - //}); - } -} - -void PvTable::add_col_button(PARAM* p, int col, vector 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), 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); - } -} - -int PvTable::border_id() -{ - return border_id_; -} - -int PvTable::rows() -{ - return nRow_; -} -int PvTable::colums() -{ - return nCol_; + return this->ncol; } vector PvTable::data() { - return vecData_; + return vecData; } PvTable::Head& PvTable::header(int col) { - return vecHead_[col]; + return vecHeads[col]; } static const string STYLE_NORMAL = @@ -348,32 +264,6 @@ void PvPagination::setPage(int index, int count) 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; @@ -424,7 +314,10 @@ void PvPagination::setCallback(std::function func) PageTable::PageTable(PARAM* p) : PvMask(p) { table = std::make_shared(p, 0, 20, 210, 1880, pageSize, option); - table->setOperateCallback([=](int row, int col, std::string text) { this->onOperate(row, col, text); }); + table->setOperateCallback([=](int irow, int icol, std::string text) { + curRowData = table->row(irow); + this->onOperate(irow, icol, text); + }); pagination = std::make_shared(p, 0, 20, 780, 20); pagination->setCallback([=](int index) @@ -464,7 +357,7 @@ std::shared_ptr PageTable::addPop(int w, int h, int w0, std::string vecPop.push_back(pop); return pop; } -void PageTable::showPop(int index, std::string oper, Fields& fields) +void PageTable::showPop(int index, std::string oper, Fields fields) { XLOGD() << "POP set: data=" << fields.toStr(); table->mappingData(fields); @@ -492,12 +385,12 @@ void PageTable::updateDataFromDB() pageInfo.size = pageSize; pageInfo.index = pageIndex; this->onQueryTable(pageInfo, result); - for (int i = 0; irows(); ++i) + for (int i = 0; irowCount(); ++i) { if (isetRowData(i, result[i]); + table->setRow(i, result[i]); } else { diff --git a/src/pv/PvTable.h b/src/pv/PvTable.h index f8cb866..d5b2311 100644 --- a/src/pv/PvTable.h +++ b/src/pv/PvTable.h @@ -17,8 +17,6 @@ public: bool show_border = true; int head_height = 40; int row_height = 35; - int page_size = 10; - int width = 500; }; struct Head @@ -48,72 +46,52 @@ public: struct Row { bool visible = false; - int bkg {PV_ID_NUL}; + int widget {PV_ID_NUL}; std::vector vecCells {}; }; public: - PvTable(PARAM* p, int parent, int x, int y, int w, int rows, Options& option); + PvTable(PARAM* p, int parent, int x, int y, int w, int rowCount, Options& option); void addHead(std::string id, std::string text, int width, std::vector> mapping = {}); void addHead(std::vector vecText); - void setRowVisible(int row, bool v); - void highlight(int row, bool v); + void setRowVisible(int irow, bool v); + void highlight(int irow, bool v); void addOperate(std::vector vecOpt); void setOperateCallback(CallbackTableOpt cb); - void set_text(PARAM* p, int row, int col, std::string text, std::string style = ""); - void setRowData(int row, Fields& d); - void setRowData(int row, std::vector vd); + void setRow(int irow, Fields& d); + void setRow(int irow, std::vector vd); + Fields row(int irow); + Fields rowMapping(int irow); - Fields getRowData(int row); void mappingData(Fields& fields); - void set_border_visible(PARAM* p, bool v); - - void add_col_button(PARAM* p, int col, std::string title, PvRect& rt, std::string style); - void add_col_button(PARAM* p, int col, std::vector vec_title); - void setOperateVisible(int row, bool v, int id = -1); - - int item_posy(int row); - - int border_id(); - - int rows(); - - int colums(); + int rowCount(); + int colCount(); std::vector data(); PvTable::Head& header(int col); private: - int pvid_; - PvRect rect_; + Options option; + PvRect rect; - int border_id_; + std::vector vecHeads; + std::vector vecRows; + std::vector vecData; - std::vector vecHead_; - std::vector vecRows_; + vector>> vecOper; + int nrow; + int ncol; - std::vector vecData_; - - vector>> vecOpt_; - int nRow_; - int nCol_; - - string item_base_style_; - - Options option_; - - unordered_map> vec_col_item_btn_; - - CallbackTableOpt cbOperate_ = nullptr; - - int posCol_ = 0; + int posCol = 0; + + CallbackTableOpt callbackOper = nullptr; }; @@ -144,9 +122,6 @@ private: // 下一页按钮 int btnNext = PV_ID_NUL; - // 页面跳转按钮 - int btn_gopage_ = PV_ID_NUL; - int btnActive = PV_ID_NUL; int labelInfo = PV_ID_NUL; @@ -170,7 +145,7 @@ public: std::shared_ptr addPop(int w, int h, int w0, std::string name, std::vector primaryKeys); - void showPop(int index, std::string optr, Fields& fields); + void showPop(int index, std::string optr, Fields fields); void hidePop(int index); void updateDataFromDB(); @@ -186,6 +161,7 @@ public: std::shared_ptr table; std::shared_ptr pagination; std::vector> vecPop; + Fields curRowData; }; #endif // ! _PvTable_H_ \ No newline at end of file diff --git a/src/pv/PvUser.cpp b/src/pv/PvUser.cpp index e69de29..5c96dc1 100644 --- a/src/pv/PvUser.cpp +++ b/src/pv/PvUser.cpp @@ -0,0 +1,7 @@ +#include "PvUser.h" + +void PvUser::reset() +{ + mapEventCallback.clear(); + pvidIndex = 0; +} \ No newline at end of file diff --git a/src/pv/PvUser.h b/src/pv/PvUser.h index 0bb5334..ec6cbc9 100644 --- a/src/pv/PvUser.h +++ b/src/pv/PvUser.h @@ -6,6 +6,8 @@ class PvUser { public: + void reset(); + int pvidIndex = 0; std::map> mapEventCallback; }; \ No newline at end of file diff --git a/src/pv/pages/MaskPageHome.cpp b/src/pv/pages/MaskPageHome.cpp index 11f988a..486fa77 100644 --- a/src/pv/pages/MaskPageHome.cpp +++ b/src/pv/pages/MaskPageHome.cpp @@ -11,12 +11,9 @@ void TestPage(PARAM* p) { - auto& appdata = Application::data(); - auto pagination = new PvPagination(p, 0, 600, 160, 20); - pagination->setPage(5, 10); - - int id = PvApp::label(p, 0, 0, 0, 1920, 800, "", qss::label(14, "", "rgb(15, 50, 68)")); - new PanelPolicyPeak(p, id, 0, 0, 1920, 1080); + //auto& appdata = Application::data(); + //auto pagination = new PvPagination(p, 0, 600, 160, 20); + //pagination->setPage(5, 10); } @@ -192,7 +189,6 @@ public: } }; - //background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0,stop:1 rgba(0,255,240,200),stop:0 rgba(0,255,240,0)); int MaskPageHome::initUI(EPvCode pvcode) { @@ -317,11 +313,8 @@ int MaskPageHome::initUI(EPvCode pvcode) this->updateUI(); - - TestPage(p); - return 0; } @@ -342,7 +335,7 @@ void MaskPageHome::updateUI() } pvSetText(p, ui.labelRunDays, "100 天"); - pvSetText(p, ui.labelRunDays, (Utils::toStr(stationNum) + " 个").c_str()); + pvSetText(p, ui.labelStationNum, (Utils::toStr(stationNum) + " 个").c_str()); pvSetText(p, ui.labelEnergyCapacity, (Utils::toStr(energyCapacity) + " kWh").c_str()); pvSetText(p, ui.labelIncome, (Utils::toStr(incomeTotal) + " 元").c_str()); pvSetText(p, ui.labelStorageIn, (Utils::toStr(electStorageIn) + " kWh").c_str()); diff --git a/src/pv/pages/MaskPageRunning.cpp b/src/pv/pages/MaskPageRunning.cpp index ae7d194..397fee3 100644 --- a/src/pv/pages/MaskPageRunning.cpp +++ b/src/pv/pages/MaskPageRunning.cpp @@ -1,6 +1,10 @@ #include "MaskPageRunning.h" #include "app/Application.h" #include "app/AppData.h" +#include "app/Station.h" +#include "app/Device.h" +#include "common/JsonN.h" + static int CreateParamLabel(PARAM* p, int parent, int x, int y, std::string k, std::string v) { @@ -8,21 +12,21 @@ static int CreateParamLabel(PARAM* p, int parent, int x, int y, std::string k, s return PvApp::label(p, parent, x += 70, y, 120, 30, v, qss::LABEL_VAL); } -class BoxCard : PvObject +class CardDevice : PvObject { public: - static std::shared_ptr create(PARAM* p, int parent, int x, int y) + static std::shared_ptr create(PARAM* p, int parent, int x, int y) { - return std::make_shared(p, parent, x, y); + return std::make_shared(p, parent, x, y); } - BoxCard(PARAM* p, int parent, int x, int y) : PvObject(p) + CardDevice(PARAM* p, int parent, int x, int y) : PvObject(p) { 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, ""); - ui.name = PvApp::label(p, card_, 80, 30, 100, 20, ""); + ui.name = PvApp::label(p, card_, 80, 10, 100, 20, ""); + ui.code = 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; @@ -40,14 +44,14 @@ public: // 默认创建 10 个参数标签: int n = 10; - vecParamLabel_.resize(n); + vecParamLabel.resize(n); for (int i = 0; i vecKeys) { - for (int i = 0; i> vecParamLabel_; + std::vector> vecParamLabel; std::map mapParam_; }; @@ -106,135 +110,199 @@ MaskPageRunning::MaskPageRunning(PARAM* p) : PvMask(p) int MaskPageRunning::initUI(EPvCode pvcode) { + auto& appdata = Application::data(); + PvApp::label(p, 0, 10, 100, 1900, 850, "", "background-color: rgb(5, 47, 77); border-radius: 10px;"); 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 vecStationNames = Application::data().getStationNames(); + std::vector vecStationNames = appdata.getStationNames(); PvApp::label(p, 0, 20, 110, 80, 30, "场站切换", "color:white; font: bold 16px;"); - PvApp::combox(p, 0, 100, 110, 150, 30, vecStationNames); + ui.comboxStation = PvApp::combox(p, 0, 100, 110, 150, 30, vecStationNames); if (vecStationNames.size() > 0) { - station_ = Application::data().getStationByName(vecStationNames[0]); + activeStation = appdata.getStationByName(vecStationNames[0]); } PvApp::label(p, 0, 320, 110, 80, 30, "运行模式", "color:white; font: bold 16px;"); - PvApp::combox(p, 0, 400, 110, 200, 30, Application::data().getWorkModes()); + ui.comboxWorkMode = PvApp::combox(p, 0, 400, 110, 200, 30, appdata.getWorkModes(), activeStation->id - 1); PvApp::label(p, 0, 670, 110, 80, 30, "策略名称", "color:white; font: bold 16px;"); - PvApp::combox(p, 0, 750, 110, 200, 30, Application::data().getPolicyNames()); + PvApp::combox(p, 0, 750, 110, 200, 30, appdata.getPolicyNames()); int x = 20, y = 160, w = 200, h = 180; // 储能设备 { - ui.storage.name = "储能设备"; - 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); - pvHide(p, ui.storage.workspace); + this->initModule(storage, "储能设备", x, y, w, h); + storage.workspace = PvApp::widget(p, workspace, 0, 0, 1670, 790); + pvHide(p, storage.workspace); // 创建信息卡片 { vecCard_.resize(12); for (int i=0; iinitModule(solar, "光伏设备", x, y += (h+10), w, h); + solar.workspace = storage.workspace; + pvHide(p, solar.workspace); } // 充电设备 { - ui.charge.name = "充电设备"; - 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; - pvHide(p, ui.charge.workspace); + this->initModule(charge, "充电设备", x, y += (h+10), w, h); + charge.workspace = storage.workspace; + pvHide(p, charge.workspace); } // 环境与安防设备 { - ui.security.name = "环境与安防设备"; - 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); + this->initModule(security, "环境与安防设备", x, y += (h+10), w, h); + security.workspace = PvApp::widget(p, workspace, 0, 0, 1670, 790); + pvHide(p, security.workspace); - 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); - pvHide(p, ui.security.workspace); + { + std::string style = qss::label(20, "white; padding: 0px 0px 0px 10px;", "rgb(8, 54, 91)", "none; border-radius: 5px;"); + for (int i = 0; i<12; ++i) + { + int w = 320, h = 240; + int x = 0+(w+10)*(i%4), y = 0+(h+10)*(i/4); + int cardId = PvApp::label(p, security.workspace, x, y, w, h, "监控点 " + std::to_string(i+1), style); + pvSetAlignment(p, cardId, AlignLeft | AlignTop); + + PvApp::label(p, cardId, 10, 40, w-20, h-50, "", qss::label(14, "", "", "8px solid black; border-radius: 0px;")); + PvApp::image(p, cardId, (w-77)*0.5, 40+(h-40-77)*0.5, 77, 77, "play1.png"); + } + } + { + + int w = 320, h = 50; + int pid = PvApp::label(p, security.workspace, 1320, 10, w, 200, "环境温度信息", qss::label(20, "", "", "none;")); + pvSetAlignment(p, pid, AlignLeft | AlignTop); + PvApp::label(p, pid, 0, 30, w, 5, "", qss::QSS_UNDERLINE); + + int x = 0, y = 50; + PvApp::label(p, pid, x, y, w, h, "", qss::label(14, "", "rgb(16, 105, 125)", "none; border-radius: 5px 5px 0px 0px;")); + PvApp::label(p, pid, x, y, w, h*2, "", qss::label(14, "", "", "1px solid rgb(12, 255, 251); border-radius: 5px;")); + { + w = w/3; + PvApp::labelCenter(p, pid, x, y, w, h, "点位"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "温度"); + PvApp::labelCenter(p, pid, x+w*2, y, w, h, "湿度"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#1"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "20 ℃"); + PvApp::labelCenter(p, pid, x+w*2, y, w, h, "30 %"); + } + } + { + int w = 320, h = 50; + int pid = PvApp::label(p, security.workspace, 1320, 200, w, 500, "消防信息", qss::label(20, "", "", "none;")); + pvSetAlignment(p, pid, AlignLeft | AlignTop); + PvApp::label(p, pid, 0, 30, w, 5, "", qss::QSS_UNDERLINE); + + int x = 0, y = 50; + PvApp::label(p, pid, x, y, w, h, "", qss::label(14, "", "rgb(16, 105, 125)", "none; border-radius: 5px 5px 0px 0px;")); + PvApp::label(p, pid, x, y, w, h*9, "", qss::label(14, "", "", "1px solid rgb(12, 255, 251); border-radius: 5px;")); + { + w = w/2; + PvApp::labelCenter(p, pid, x, y, w, h, "点位"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "烟感状态"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#1"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#2"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#3"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#4"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#5"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#6"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#7"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + PvApp::labelCenter(p, pid, x, y += h, w, h, "#8"); + PvApp::labelCenter(p, pid, x+w, y, w, h, "XXX"); + } + } } - activeBoxPanel(ui.storage); + activeBoxPanel(&storage); { - + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.comboxStation, [=](std::string s) { this->onComboxStation(s); }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.comboxWorkMode, [=](std::string s) { this->onComboxWorkMode(s); }); } return 0; } +void MaskPageRunning::initModule(Module& module, std::string name, int x, int y, int w, int h) +{ + module.name = name; + + int deviceNum = activeStation->getDeviceNumByGroup(name); + int pid = module.widget = PvApp::label(p, 0, x, y, w, h, "", qss::LABEL_BOX); + PvApp::label(p, module.widget, 10, 20, w, 30, module.name, qss::LABEL_TITLE); + pvSetAlignment(p, module.widget, AlignTop | AlignLeft); + module.labelPower = PvApp::lineLabel(p, pid, PvRect(10, 80, 180, 30), 70, "总功率:", "60 W"); + module.labelNum = PvApp::lineLabel(p, pid, PvRect(10, 110, 180, 30), 70, "设备数量:", std::to_string(deviceNum).c_str()); + module.btn = PvApp::button(p, pid, 0, 0, w, h, "", "background-color: transparent;"); +} + + EPvCode MaskPageRunning::onEventButton(int pvid) { - if (pvid == ui.storage.btn) { activeBoxPanel(ui.storage); } - else if (pvid == ui.solar.btn) { activeBoxPanel(ui.solar); } - else if (pvid == ui.charge.btn) { activeBoxPanel(ui.charge); } - else if (pvid == ui.security.btn) { activeBoxPanel(ui.security); } - + if (pvid == storage.btn) { activeBoxPanel(&storage); } + else if (pvid == solar.btn) { activeBoxPanel(&solar); } + else if (pvid == charge.btn) { activeBoxPanel(&charge); } + else if (pvid == security.btn) { activeBoxPanel(&security); } return EPvCode::NUL; } -std::map> mapDeviceTypes = +void MaskPageRunning::activeBoxPanel(Module* module) { - {"储能设备", {"储能预制舱", "储能电池", "储能电池", "储能电池"}}, - {"光伏设备", {"光伏板", "光伏板", "光伏板", "光伏板", "光伏板", "光伏板", "光伏板", "光伏板"}}, - {"充电设备", {"充电桩", "充电桩", "充电桩", "充电桩", "充电桩", "充电桩", "充电桩", "充电桩", "充电桩", "充电桩"}}, -}; -std::map> mapDeviceParams = -{ - {"储能预制舱", {"运行模式", "冷却方式", "实时电压", "额定电压", "实时电流", "额定电流", "实时功率", "额定功率", "功率因数", "电池容量"}}, - {"储能电池", {"实时电压", "额定电压", "实时电流", "额定电流", "实时功率", "额定功率", "功率因数", "电池容量"}}, - {"逆变器", {"实时电压", "额定电压", "实时电流", "额定电流", "实时功率", "额定功率", "功率因数"}}, - {"光伏板", {"实时电压", "额定电压", "实时电流", "额定电流", "实时功率", "额定功率", "功率因数"}}, - {"充电桩", {"实时电压", "额定电压", "实时电流", "额定电流", "实时功率", "额定功率", "功率因数"}}, -}; + if (activeBox) + { + pvSetStyleSheet(p, activeBox->widget, qss::LABEL_BOX.c_str()); + pvHide(p, activeBox->workspace); + } + activeBox = module; + if (activeBox) + { + pvSetStyleSheet(p, activeBox->widget, qss::QSS_BOX_ACTIVE.c_str()); + pvShow(p, activeBox->workspace); + } -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::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); } - - - if (panel.workspace != ui.security.workspace) + auto& appdata = Application::data(); + if (activeBox->workspace != security.workspace) { - std::vector vecDeviceInfo = mapDeviceTypes[panel.name]; + // 更新卡片: + std::vector> vecDevice; + activeStation->getDeviceByGroup(module->name, vecDevice); + + pvSetText(p, module->labelNum, std::to_string(vecDevice.size()).c_str()); // 读取储能设备信息 for (int i = 0; itype); + if (typeDef) + { + std::vector vecKeys; + NJson::parse(typeDef->fieldsAttr.value("key"), vecKeys); + card->setCard(typeDef->name, device->name, device->code); + card->setParamkeys(vecKeys); + } card->show(1); - card->setCard(type, type+"-"+std::to_string(i), type+"-"+std::to_string(i)); - card->setParamkeys(mapDeviceParams[type]); } else { @@ -242,4 +310,38 @@ void MaskPageRunning::activeBoxPanel(BoxPanel& panel) } } } +} + +void MaskPageRunning::updateWorkspace() +{ + +} + +void MaskPageRunning::onComboxStation(std::string stationName) +{ + if (!activeStation) return; + + auto& appdata = Application::data(); + activeStation = appdata.getStationByName(stationName); + + // 更新运行模式和策略 + { + int index = activeStation->workModeId - 1; + if (index < 0) { index = 0; } + pvSetCurrentItem(p, ui.comboxWorkMode, index); + } + + this->activeBoxPanel(activeBox); +} + +void MaskPageRunning::onComboxWorkMode(std::string modeName) +{ + if (!activeStation) return; + + auto& appdata = Application::data(); + + int workModeId = appdata.getWorkModeIdByName(modeName); + activeStation->setWorkMode(workModeId); + + } \ No newline at end of file diff --git a/src/pv/pages/MaskPageRunning.h b/src/pv/pages/MaskPageRunning.h index b97c3b2..4a9cda8 100644 --- a/src/pv/pages/MaskPageRunning.h +++ b/src/pv/pages/MaskPageRunning.h @@ -2,34 +2,48 @@ #include "pv/PvApp.h" -class BoxCard; +class CardDevice; class Station; class MaskPageRunning : public PvMask { public: - struct BoxPanel { + struct Module { std::string name; - int box; + int widget; int btn; int workspace; + + int labelPower; + int labelNum; }; MaskPageRunning(PARAM* p); int initUI(EPvCode pvcode); + void initModule(Module& module, std::string name, int x, int y, int w, int h); virtual EPvCode onEventButton(int pvid); - void activeBoxPanel(BoxPanel& panel); + void activeBoxPanel(Module* module); + + void updateWorkspace(); + + void onComboxStation(std::string stationName); + void onComboxWorkMode(std::string modeName); struct { - BoxPanel storage; - BoxPanel solar; - BoxPanel charge; - BoxPanel security; + int comboxStation; + int comboxWorkMode; } ui; - std::vector> vecCard_; - std::shared_ptr station_ = nullptr; + Module storage; + Module solar; + Module charge; + Module security; + + Module* activeBox {}; + + std::vector> vecCard_; + std::shared_ptr activeStation = nullptr; }; \ No newline at end of file diff --git a/src/pv/pages/PageSysmgr.cpp b/src/pv/pages/PageSysmgr.cpp index 6eb00f3..19de603 100644 --- a/src/pv/pages/PageSysmgr.cpp +++ b/src/pv/pages/PageSysmgr.cpp @@ -5,7 +5,9 @@ #include "database/Dao.h" #include "database/DataModelDef.h" #include "common/Snowflake.h" +#include "pv/pages/PanelPolicy.h" +std::vector g_comboxList_isOpen = {"启用", "禁用"}; /////////////////////////////////////////////////////////////////////////////////////////////////// // === PageUser === @@ -42,7 +44,7 @@ void PageUser::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::queryUserList(pageInfo, result); } -void PageUser::onOperate(int row, int col, std::string oper) +void PageUser::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -52,7 +54,7 @@ void PageUser::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } }; std::string PageUser::onValidation(std::shared_ptr pop, Fields& fields) @@ -84,7 +86,7 @@ PageRole::PageRole(PARAM* p, EPvCode pvcode) : PageTable(p) { auto& appdata = Application::data(); - table->addHead(DMRole::ROLE_ID, "角色编号", 200, {}); + table->addHead(DMRole::ROLE_ID, "角色编号", 180, {}); table->addHead(DMRole::NAME, "角色名称", 200, {}); table->addHead(DMRole::DESCRIBE, "角色描述", 900, {}); table->addHead(DMRole::IS_OPEN, "是否启用", 200, appdata.mapping.isopen); @@ -97,7 +99,7 @@ PageRole::PageRole(PARAM* p, EPvCode pvcode) : PageTable(p) 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->addParamCombox(DMUser::IS_OPEN, "是否启用", x, y += h, g_comboxList_isOpen); pop->addParamTextEdit(DMRole::DESCRIBE, "描述", x, y += h); } @@ -105,7 +107,7 @@ void PageRole::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::queryRoleList(pageInfo, result); } -void PageRole::onOperate(int row, int col, std::string oper) +void PageRole::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -115,7 +117,7 @@ void PageRole::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } } std::string PageRole::onValidation(std::shared_ptr pop, Fields& fields) @@ -133,7 +135,7 @@ std::string PageRole::onPopConfirm(std::shared_ptr pop, Fields& fie PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p) { auto& appdata = Application::data(); - table->addHead(DMPermission::PERMISSION_ID, "权限编号", 200, {}); + table->addHead(DMPermission::PERMISSION_ID, "权限编号", 180, {}); table->addHead(DMPermission::NAME, "权限名称", 200, {}); table->addHead(DMPermission::DESCRIBE, "权限描述", 900, {}); table->addHead(DMPermission::IS_OPEN, "是否启用", 200, appdata.mapping.isopen); @@ -143,17 +145,17 @@ PagePermission::PagePermission(PARAM* p, EPvCode pvcode) : PageTable(p) 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}); + auto pop = this->addPop(500, 600, 240, "角色信息", {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->addParamCombox(DMPermission::IS_OPEN, "是否启用", x, y += h, g_comboxList_isOpen); pop->addParamTextEdit(DMPermission::DESCRIBE, "描述", x, y += h); } void PagePermission::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::queryPermissionList(pageInfo, result); } -void PagePermission::onOperate(int row, int col, std::string oper) +void PagePermission::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -163,7 +165,7 @@ void PagePermission::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } } std::string PagePermission::onValidation(std::shared_ptr pop, Fields& fields) @@ -180,7 +182,7 @@ std::string PagePermission::onPopConfirm(std::shared_ptr pop, Field PageStation::PageStation(PARAM* p, EPvCode pvcode) : PageTable(p) { auto& appdata = Application::data(); - table->addHead(DMStation::STATION_ID, "场站编号", 200, {}); + table->addHead(DMStation::STATION_ID, "场站编号", 180, {}); table->addHead(DMStation::NAME, "场站名称", 200, {}); table->addHead(DMStation::ADDRESS, "地址", 200, {}); table->addHead(DMStation::LONGITUDE, "经度", 200, {}); @@ -200,13 +202,13 @@ PageStation::PageStation(PARAM* p, EPvCode pvcode) : PageTable(p) 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, {"启用", "禁用"}); + pop->addParamCombox(DMStation::STATUS, "状态", x, y += h, g_comboxList_isOpen); } void PageStation::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::queryStationList(pageInfo, result); } -void PageStation::onOperate(int row, int col, std::string oper) +void PageStation::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -216,7 +218,7 @@ void PageStation::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } } std::string PageStation::onValidation(std::shared_ptr pop, Fields& fields) @@ -246,6 +248,7 @@ PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p) { auto& appdata = Application::data(); table->addHead(DMDevice::DEVICE_ID, "设备编号", 120, {}); + table->addHead(DMDevice::STATION_ID, "所属场站", 120, appdata.mapping.stationName); table->addHead(DMDevice::TYPE, "设备类型", 120, appdata.mapping.deviceType); table->addHead(DMDevice::NAME, "设备名称", 180, {}); table->addHead(DMDevice::CODE, "设备编码", 160, {}); @@ -262,20 +265,21 @@ PageDevice::PageDevice(PARAM* p, EPvCode pvcode) : PageTable(p) 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, "类型", x+w, y, appdata.getDeviceTypeNames()); - 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); + pop->addParamCombox(DMDevice::STATION_ID, "所属场站", x+w, y, appdata.getStationNames()); + pop->addParamCombox(DMDevice::TYPE, "类型", x, y += h, appdata.getDeviceTypeNames()); + pop->addParamLineEdit(DMDevice::NAME, "设备名称", x+w, y); + pop->addParamLineEdit(DMDevice::CODE, "设备编码", x, y += h); + pop->addParamLineEdit(DMDevice::MODEL, "设备型号", x+w, y); + pop->addParamLineEdit(DMDevice::FACTORY, "厂家", x, y += h); + pop->addParamLineEdit(DMDevice::TEL, "厂家电话", x+w, y); + pop->addParamCombox(DMDevice::IS_OPEN, "是否启用", x, y += h, g_comboxList_isOpen); + pop->addParamLineEdit(DMDevice::ATTRS, "设备参数", x + w, y); } void PageDevice::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::queryDeviceList(pageInfo, result); } -void PageDevice::onOperate(int row, int col, std::string oper) +void PageDevice::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -285,7 +289,7 @@ void PageDevice::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } } std::string PageDevice::onValidation(std::shared_ptr pop, Fields& fields) @@ -316,12 +320,12 @@ std::string PageDevice::onPopConfirm(std::shared_ptr pop, Fields& f 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->addHead(DMPolicy::POLICY_ID, "策略编号", 120, {}); + table->addHead(DMPolicy::TYPE, "策略类型", 120, appdata.mapping.policyType); + table->addHead(DMPolicy::NAME, "策略名称", 160, {}); + table->addHead(DMPolicy::DESCRIBE, "策略描述", 300, {}); + table->addHead(DMPolicy::VALUE, "策略参数", 900, {}); + table->addHead(DMPolicy::IS_OPEN, "是否启用", 80, appdata.mapping.isopen); table->addOperate({ "编辑"}); int btnNew = PvApp::button(p, PV_ID_MAIN, 20, 160, 80, 35, POP_OPER_NEW); @@ -331,36 +335,78 @@ PagePolicy::PagePolicy(PARAM* p, EPvCode pvcode) : PageTable(p) auto pop = this->addPop(1620, 800, 180, "策略信息", {DMPolicy::POLICY_ID}); //pop->addParamLineEdit(DMPolicy::POLICY_ID, "编号", x, y, false); { - pop->addParamLineEdit("1", "策略名称", x, y); - pop->addParamCombox("2", "策略类型", x+w, y, {"峰谷套利"}); - pop->addParamLineEdit("3", "尖峰电价", x, y += 50); - pop->addParamLineEdit("4", "高峰电价", x+w, y); - pop->addParamLineEdit("5", "平段电价", x+w*2, y); - pop->addParamLineEdit("6", "低谷电价", x+w*3, y); + pop->addParamLineEdit(DMPolicy::NAME, "策略名称", x, y); + pop->addParamCombox(DMPolicy::TYPE, "策略类型", x+w, y, Application::data().getPolicyTypeNames()); + pop->addParamCombox(DMPolicy::IS_OPEN, "是否启用", x, y+=40, g_comboxList_isOpen), + //pop->addParamLineEdit("3", "尖峰电价", x, y += 50); + //pop->addParamLineEdit("4", "高峰电价", x+w, y); + //pop->addParamLineEdit("5", "平段电价", x+w*2, y); + //pop->addParamLineEdit("6", "低谷电价", x+w*3, y); + + pop->setCallbackTextEvent([=](std::string k, std::string text) { + if (k == DMPolicy::TYPE) + { + int policyTypeId = Application::data().getPolicyTypeId(text); + this->setPanel(policyTypeId, "{}"); + } + }); + + panelPeak = std::make_shared(p, pop->widget(), 10, y+=40, 1600, 540); + panelRequire = std::make_shared(p, pop->widget(), 10, y, 620, 220); + panelSelf = std::make_shared(p, pop->widget(), 10, y, 620, 220); } - +} +void PagePolicy::setPanel(int policyTypeId, std::string attrVal) +{ + auto pop = vecPop[0]; + panelPeak->show(0); + panelRequire->show(0); + panelSelf->show(0); + if (policyTypeId == 1) + { + panelPeak->parseAttr(attrVal); + panelPeak->show(1); + pop->resize(1620, 800); + } + else if (policyTypeId == 2) + { + panelRequire->parseAttr(attrVal); + panelRequire->show(1); + pop->resize(640, 600); + } + else if (policyTypeId == 3) + { + panelSelf->parseAttr(attrVal); + panelSelf->show(1); + pop->resize(640, 600); + } +} +std::string PagePolicy::getPanelAttr(int policyTypeId) +{ + std::string attrVal = "{}"; + if (policyTypeId == 1) { attrVal = panelPeak->dumpAttr(); } + else if (policyTypeId == 2) { attrVal = panelRequire->dumpAttr(); } + else if (policyTypeId == 3) { attrVal = panelSelf->dumpAttr(); } + return attrVal; } void PagePolicy::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::queryPolicyList(pageInfo, result); } -void PagePolicy::onOperate(int row, int col, std::string oper) +void PagePolicy::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { - Fields fields; - this->showPop(0, oper, fields); + this->showPop(0, oper, Fields()); + this->setPanel(1, {}); } else if (oper == POP_OPER_EDIT) { - table->getRowData(row); - auto& appdata = Application::data(); - Fields fields; - fields.set("3", appdata.electPriceSuperPeak); - fields.set("4", appdata.electPricePeak); - fields.set("5", appdata.electPriceShoulder); - fields.set("6", appdata.electPriceOffPeak); - this->showPop(0, oper, fields); + int policyTypeId = curRowData.get(DMPolicy::TYPE); + std::string attrVal = curRowData.value(DMPolicy::VALUE); + + this->setPanel(policyTypeId, attrVal); + this->showPop(0, oper, curRowData); } } std::string PagePolicy::onValidation(std::shared_ptr pop, Fields& fields) @@ -369,9 +415,23 @@ std::string PagePolicy::onValidation(std::shared_ptr pop, Fields& f }; std::string PagePolicy::onPopConfirm(std::shared_ptr pop, Fields& fields) { - - - + if (pop->status == POP_OPER_NEW) + { + int policyTypeId = fields.get(DMPolicy::TYPE); + fields.set(DMPolicy::VALUE, this->getPanelAttr(policyTypeId)); + Errcode err = DAO::insertPolicy(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } + else if (pop->status == POP_OPER_EDIT) + { + int policyTypeId = curRowData.get(DMPolicy::TYPE); + fields.set(DMPolicy::POLICY_ID, policyTypeId); + fields.set(DMPolicy::VALUE, this->getPanelAttr(policyTypeId)); + Errcode err = DAO::updatePolicyById(fields); + if (err == Errcode::OK) { return ""; } + else { return "系统错误"; } + } return ""; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -390,7 +450,7 @@ void PageSyslog::onQueryTable(PageInfo& pageInfo, std::vector& result) { DAO::querySystemLogList(pageInfo, result); } -void PageSyslog::onOperate(int row, int col, std::string oper) +void PageSyslog::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -400,7 +460,7 @@ void PageSyslog::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } } std::string PageSyslog::onValidation(std::shared_ptr pop, Fields& fields) @@ -429,7 +489,7 @@ void PageAlertlog::onQueryTable(PageInfo& pageInfo, std::vector& result) { //DAO::queryAlertLogList(pageInfo, result); } -void PageAlertlog::onOperate(int row, int col, std::string oper) +void PageAlertlog::onOperate(int irow, int icol, std::string oper) { if (oper == POP_OPER_NEW) { @@ -439,7 +499,7 @@ void PageAlertlog::onOperate(int row, int col, std::string oper) } else if (oper == POP_OPER_EDIT) { - this->showPop(0, oper, table->getRowData(row)); + this->showPop(0, oper, table->row(irow)); } } std::string PageAlertlog::onValidation(std::shared_ptr pop, Fields& fields) diff --git a/src/pv/pages/PageSysmgr.h b/src/pv/pages/PageSysmgr.h index 7c8f8dc..8cefd81 100644 --- a/src/pv/pages/PageSysmgr.h +++ b/src/pv/pages/PageSysmgr.h @@ -71,17 +71,24 @@ public: /////////////////////////////////////////////////////////////////////////////////////////////////// // === PagePolicy === +class PanelPolicyPeak; +class PanelPolicyRequire; +class PanelPolicySelf; class PagePolicy : public PageTable { public: PagePolicy(PARAM* p, EPvCode pvcode); + void setPanel(int policyTypeId, std::string attrVal); + std::string getPanelAttr(int policyTypeId); virtual void onQueryTable(PageInfo& pageInfo, std::vector& result) override; virtual void onOperate(int row, int col, std::string oper) override; virtual std::string onValidation(std::shared_ptr pop, Fields& fields) override; virtual std::string onPopConfirm(std::shared_ptr pop, Fields& fields) override; - + std::shared_ptr panelPeak {}; + std::shared_ptr panelRequire {}; + std::shared_ptr panelSelf {}; }; /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/pv/pages/PanelPolicy.cpp b/src/pv/pages/PanelPolicy.cpp index bd4a089..eba66db 100644 --- a/src/pv/pages/PanelPolicy.cpp +++ b/src/pv/pages/PanelPolicy.cpp @@ -2,30 +2,55 @@ #include "app/Application.h" #include "app/AppData.h" #include "common/JsonN.h" +#include "common/Utils.h" + +//const std::string QSS_COMBOX_1 = +//"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(255, 89, 0); border-radius: 3px; color: rgb(30,30,30); 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 QSS_COMBOX_2 = +//"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(255, 255, 0); border-radius: 3px; color: rgb(30,30,30); 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 QSS_COMBOX_3 = +//"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(121, 191, 226); border-radius: 3px; color: rgb(30,30,30); 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 QSS_COMBOX_4 = +//"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(0, 255, 58); border-radius: 3px; color: rgb(30,30,30); 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 QSS_COMBOX_1 = -"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(255, 89, 0); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}" -"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}" +"QComboBox { background-color: transparent; border: 1px solid rgb(255, 89, 0); color: rgb(255, 89, 0); border-radius: 3px; font: bold 14px;}" +"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 3px; color:white;}" "QComboBox::drop-down { border-radius: 5px; width: 30px; }" -"QComboBox:disabled { color:rgb(150,150,150);}"; +"QComboBox:disabled {border: none; color: gray;}"; const std::string QSS_COMBOX_2 = -"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(255, 255, 0); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}" -"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}" +"QComboBox { background-color: transparent; border: 1px solid rgb(255, 255, 0); color: rgb(255, 255, 0); border-radius: 3px; font: bold 14px;}" +"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 3px; color:white;}" "QComboBox::drop-down { border-radius: 5px; width: 30px; }" -"QComboBox:disabled { color:rgb(150,150,150);}"; +"QComboBox:disabled { border: none; color: gray;}"; const std::string QSS_COMBOX_3 = -"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(121, 191, 226); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}" -"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}" +"QComboBox { background-color: transparent; border: 1px solid rgb(121, 191, 226); color: rgb(121, 191, 226); border-radius: 3px; font: bold 14px;}" +"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 3px; color:white;}" "QComboBox::drop-down { border-radius: 5px; width: 30px; }" -"QComboBox:disabled { color:rgb(150,150,150);}"; +"QComboBox:disabled { border: none; color: gray;}"; const std::string QSS_COMBOX_4 = -"QComboBox {border: 1px solid rgb(18, 251, 255); background-color: rgb(0, 255, 58); border-radius: 3px; color: rgb(30,30,30); font: bold 14px;}" -"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 5px; color:white;}" +"QComboBox { background-color: transparent; border: 1px solid rgb(0, 255, 58);color: rgb(0, 255, 58); border-radius: 3px; font: bold 14px;}" +"QComboBox QAbstractItemView { border: 1px solid gray; background-color: rgba(8, 54, 91); border-radius: 3px; color:white;}" "QComboBox::drop-down { border-radius: 5px; width: 30px; }" -"QComboBox:disabled { color:rgb(150,150,150);}"; +"QComboBox:disabled { border: none; color: gray;}"; static std::string GetPeriodQss(int v) { @@ -51,182 +76,180 @@ static int GetPeriod(std::string text) else if (text == "低谷") { return 4; } else { return 3; } } -PanelPolicyPeak::PanelPolicyPeak(PARAM* p, int parent, int x, int y, int w, int h) : PvObject(p) +PanelPolicyPeak::PanelPolicyPeak(PARAM* p, int parent, int ix, int iy, int iw, int ih) : PvObject(p) { data.vecPeriods.resize(12, std::vector(24, 3)); ui.parent = parent; - ui.widget = PvApp::widget(p, parent, x, y, w, h); + pvid = PvApp::widget(p, parent, ix, iy, iw, ih); auto& appdata = Application::data(); std::vector vecPeriods = {"尖峰", "高峰", "平段", "低谷"}; ui.vecComboxs.resize(12, std::vector(24, PV_ID_NUL)); + + int x = 0, y = 10, w = 64, h = 30; + for (int row = 0; row<=12; row++) { - int parent = ui.widget; - int x = 10, y = 180, w = 64, h = 30; - for (int row = 0; row<=12; row++) + for (int col = 0; col<=24; ++col) { - for (int col = 0; col<=24; ++col) + std::string text; + if (row == 0) { - std::string text; - if (row == 0) - { - text = (col == 0) ? "月份" : std::to_string(col-1) + "-" + std::to_string(col) + "时"; - } - else - { - text = (col == 0) ? std::to_string(row) : ""; - } - if (row == 0 || col == 0) - { - std::string qssLabel = (row==0) ? qss::label(14, "", "rgb(19, 93, 114)") : ""; - int label = PvApp::label(p, parent, x+w*col, y+h*row, w, h, text, qssLabel); - pvSetAlignment(p, label, AlignCenter); - } - else - { - int periodVal = data.vecPeriods[row-1][col-1]; - int combox = PvApp::combox(p, parent, x+w*col, y+h*row+3, w-3, 24, vecPeriods, periodVal); - pvSetStyleSheet(p, combox, GetPeriodQss(periodVal).c_str()); - ui.vecComboxs[row-1][col-1] = combox; - PvApp::bind(p, PvEvent::TEXT_EVENT, combox, [=](std::string text) { - pvSetStyleSheet(p, combox, GetPeriodQss(text).c_str()); - data.vecPeriods[row-1][col-1] = GetPeriod(text); - }); - } - + text = (col == 0) ? "月份" : std::to_string(col-1) + "-" + std::to_string(col) + "时"; + } + else + { + text = (col == 0) ? std::to_string(row) : ""; + } + if (row == 0 || col == 0) + { + std::string qssLabel = (row==0) ? qss::label(14, "", "rgb(19, 93, 114)") : ""; + int label = PvApp::label(p, pvid, x+w*col, y+h*row, w, h, text, qssLabel); + pvSetAlignment(p, label, AlignCenter); + } + else + { + int periodVal = data.vecPeriods[row-1][col-1]; + int combox = PvApp::combox(p, pvid, x+w*col, y+h*row+3, w-3, 24, vecPeriods, periodVal-1); + pvSetStyleSheet(p, combox, GetPeriodQss(periodVal).c_str()); + ui.vecComboxs[row-1][col-1] = combox; + PvApp::bind(p, PvEvent::TEXT_EVENT, combox, [=](std::string text) { + pvSetStyleSheet(p, combox, GetPeriodQss(text).c_str()); + data.vecPeriods[row-1][col-1] = GetPeriod(text); + }); } - } - - const int H = 24; - int labelPolicy = PvApp::label(p, parent, 20, 600, 300, H, "充电策略"); - ui.radioPolicy1 = PvApp::radioButton(p, labelPolicy, 80, 0, 80, H, "一充一放"); - ui.radioPolicy2 = PvApp::radioButton(p, labelPolicy, 170, 0, 80, H, "两充两放"); - ui.label1 = PvApp::label(p, parent, 10, 640, 610, 90, "第一次充放电过程", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); - pvSetAlignment(p, ui.label1, AlignLeft | AlignTop); - { - int y0 = 70; - int labelChargeT = PvApp::label(p, ui.label1, 10, 30, 300, H, "充电时间"); - ui.attr1TimeCharge0 = PvApp::timeEdit(p, labelChargeT, y0, 0, 60, H); - PvApp::label(p, labelChargeT, 150, 0, 10, H, "--"); - ui.attr1TimeCharge1 = PvApp::timeEdit(p, labelChargeT, 170, 0, 60, H); - - int labelDischargeT = PvApp::label(p, ui.label1, 320, 30, 300, H, "放电时间"); - ui.attr1TimeDischarge0 = PvApp::timeEdit(p, labelDischargeT, y0 = 70, 0, 60, H); - PvApp::label(p, labelDischargeT, y0+=70, 0, 10, H, "--"); - ui.attr1TimeDischarge1 = PvApp::timeEdit(p, labelDischargeT, y0+=20, 0, 60, H); - - int labelPowerIn = PvApp::label(p, ui.label1, 10, 60, 300, H, "充电功率"); - ui.attr1RadioPowerInAuto = PvApp::radioButton(p, labelPowerIn, y0 = 70, 0, 60, H, "自动"); - ui.attr1RadioPowerIn = PvApp::radioButton(p, labelPowerIn, y0 += 60, 0, 64, H, "自定义"); - ui.arrt1LabelPowerIn = PvApp::lineEdit(p, labelPowerIn, y0 += 70, 0, 80, H, ""); - - int labelPowerOut = PvApp::label(p, ui.label1, 320, 60, 300, H, "放电功率"); - ui.attr1RadioPowerOutAuto = PvApp::radioButton(p, labelPowerOut, y0 = 70, 0, 60, H, "自动"); - ui.attr1RadioPowerOut = PvApp::radioButton(p, labelPowerOut, y0 += 60, 0, 64, H, "自定义"); - ui.arrt1LabelPowerOut = PvApp::lineEdit(p, labelPowerOut, y0 += 70, 0, 80, H, ""); - } - - ui.label2 = PvApp::label(p, parent, 630, 640, 610, 90, "第二次充放电过程", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); - pvSetAlignment(p, ui.label2, AlignLeft | AlignTop); - { - int y0 = 70; - int labelChargeT = PvApp::label(p, ui.label2, 10, 30, 300, H, "充电时间"); - XLOGD() << "labelChargeT=" << labelChargeT; - ui.attr2TimeCharge0 = PvApp::timeEdit(p, labelChargeT, y0, 0, 60, H); - PvApp::label(p, labelChargeT, 150, 0, 10, H, "--"); - ui.attr2TimeCharge1 = PvApp::timeEdit(p, labelChargeT, 170, 0, 60, H); - - - - - int labelDischargeT = PvApp::label(p, ui.label2, 320, 30, 300, H, "放电时间"); - ui.attr2TimeDischarge0 = PvApp::timeEdit(p, labelDischargeT, y0 = 70, 0, 60, H); - PvApp::label(p, labelDischargeT, y0 += 70, 0, 10, H, "--"); - ui.attr2TimeDischarge1 = PvApp::timeEdit(p, labelDischargeT, y0 += 20, 0, 60, H); - - int labelPowerIn = PvApp::label(p, ui.label2, 10, 60, 300, H, "充电功率"); - ui.attr2RadioPowerInAuto = PvApp::radioButton(p, labelPowerIn, y0 = 70, 0, 60, H, "自动"); - ui.attr2RadioPowerIn = PvApp::radioButton(p, labelPowerIn, y0 += 60, 0, 64, H, "自定义"); - ui.arrt2LabelPowerIn = PvApp::lineEdit(p, labelPowerIn, y0 += 70, 0, 80, H, ""); - - int labelPowerOut = PvApp::label(p, ui.label2, 320, 60, 300, H, "放电功率"); - ui.attr2RadioPowerOutAuto = PvApp::radioButton(p, labelPowerOut, y0 = 70, 0, 60, H, "自动"); - ui.attr2RadioPowerOut = PvApp::radioButton(p, labelPowerOut, y0 += 60, 0, 64, H, "自定义"); - ui.arrt2LabelPowerOut = PvApp::lineEdit(p, labelPowerOut, y0 += 70, 0, 80, H, ""); - } - - - PvApp::bind(p, PvEvent::RADIOBUTTON_EVENT, ui.radioPolicy1, [=](std::string s) { - this->data.times = 1; - pvHide(p, ui.label2); - //setTimeText(ui.attr2TimeCharge0, ""); - //setTimeText(ui.attr2TimeCharge1, ""); - //setTimeText(ui.attr2TimeDischarge0, ""); - //setTimeText(ui.attr2TimeDischarge1, ""); - //pvSetChecked(p, ui.attr2RadioPowerInAuto, 1); - //pvSetChecked(p, ui.attr2RadioPowerOutAuto, 1); - //pvSetText(p, ui.arrt2LabelPowerOut, ""); - //data.attr2.chargePower = data.attr2.dischargePower = 0.0; - //data.attr2.chargeTimeStart = data.attr2.chargeTimeEnd = data.attr2.dischargeTimeStart = data.attr2.dischargeTimeEnd = ""; - }); - - PvApp::bind(p, PvEvent::RADIOBUTTON_EVENT, ui.radioPolicy2, [=](std::string s) { - this->data.times = 2; - pvShow(p, ui.label2); - }); - - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeCharge0, [=](std::string s) { - data.attr1.chargeTimeStart = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeCharge1, [=](std::string s) { - data.attr1.chargeTimeEnd = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeDischarge0, [=](std::string s) { - data.attr1.dischargeTimeStart = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeDischarge1, [=](std::string s) { - data.attr1.dischargeTimeEnd = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeCharge0, [=](std::string s) { - data.attr2.chargeTimeStart = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeCharge1, [=](std::string s) { - data.attr2.chargeTimeEnd = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeDischarge0, [=](std::string s) { - data.attr2.dischargeTimeStart = s.substr(0, 8); - }); - PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeDischarge1, [=](std::string s) { - data.attr2.dischargeTimeEnd = s.substr(0, 8); - }); - - { - int btn = PvApp::button(p, ui.widget, 10, 750, 100, 30, "DUMP"); - PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { - XLOGD() << dumpAttr(); - }); - } - { - int btn = PvApp::button(p, ui.widget, 110, 750, 100, 30, "PARSE1"); - PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { - std::string s = R"({"cycle":[{"charge_end":"","charge_power":0.0,"charge_start":"","discharge_end":"","discharge_power":0.0,"discharge_start":""}], -"period":[[1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]], -"times":1})"; - parseAttr(s); - }); - } - { - int btn = PvApp::button(p, ui.widget, 210, 750, 100, 30, "PARSE2"); - PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { - std::string s = R"({"cycle":[{"charge_end":"09:00:00","charge_power":0.0,"charge_start":"00:00:00","discharge_end":"","discharge_power":0.0,"discharge_start":""}], -"period":[[1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]], -"times":2})"; - parseAttr(s); - }); } } + + const int H = 24; + int labelPolicy = PvApp::label(p, pvid, 20, y = 420, 300, H, "充电策略"); + ui.radioPolicy1 = PvApp::radioButton(p, labelPolicy, 80, 0, 80, H, "一充一放"); + ui.radioPolicy2 = PvApp::radioButton(p, labelPolicy, 170, 0, 80, H, "两充两放"); + + ui.label1 = PvApp::label(p, pvid, 10, y+=30, 610, 90, "第一次充放电过程", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); + pvSetAlignment(p, ui.label1, AlignLeft | AlignTop); + { + int y0 = 70; + int labelChargeT = PvApp::label(p, ui.label1, 10, 30, 300, H, "充电时间"); + ui.attr1TimeCharge0 = PvApp::timeEdit(p, labelChargeT, y0, 0, 90, H); + PvApp::label(p, labelChargeT, y0 += 100, 0, 10, H, "--"); + ui.attr1TimeCharge1 = PvApp::timeEdit(p, labelChargeT, y0 =+ 20, 0, 90, H); + + int labelDischargeT = PvApp::label(p, ui.label1, 320, 30, 300, H, "放电时间"); + ui.attr1TimeDischarge0 = PvApp::timeEdit(p, labelDischargeT, y0 = 70, 0, 90, H); + PvApp::label(p, labelDischargeT, y0 += 100, 0, 10, H, "--"); + ui.attr1TimeDischarge1 = PvApp::timeEdit(p, labelDischargeT, y0 += 20, 0, 90, H); + + int labelPowerIn = PvApp::label(p, ui.label1, 10, 60, 300, H, "充电功率"); + ui.attr1RadioPowerInAuto = PvApp::radioButton(p, labelPowerIn, y0 = 70, 0, 60, H, "自动"); + ui.attr1RadioPowerIn = PvApp::radioButton(p, labelPowerIn, y0 += 60, 0, 64, H, "自定义"); + ui.arrt1LabelPowerIn = PvApp::textedit(p, labelPowerIn, y0 += 70, 0, 80, H, ""); + + int labelPowerOut = PvApp::label(p, ui.label1, 320, 60, 300, H, "放电功率"); + ui.attr1RadioPowerOutAuto = PvApp::radioButton(p, labelPowerOut, y0 = 70, 0, 60, H, "自动"); + ui.attr1RadioPowerOut = PvApp::radioButton(p, labelPowerOut, y0 += 60, 0, 64, H, "自定义"); + ui.arrt1LabelPowerOut = PvApp::textedit(p, labelPowerOut, y0 += 70, 0, 80, H, ""); + } + + ui.label2 = PvApp::label(p, pvid, 630, y, 610, 90, "第二次充放电过程", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); + pvSetAlignment(p, ui.label2, AlignLeft | AlignTop); + { + int y0 = 70; + int labelChargeT = PvApp::label(p, ui.label2, 10, 30, 300, H, "充电时间"); + XLOGD() << "labelChargeT=" << labelChargeT; + ui.attr2TimeCharge0 = PvApp::timeEdit(p, labelChargeT, y0, 0, 60, H); + PvApp::label(p, labelChargeT, 150, 0, 10, H, "--"); + ui.attr2TimeCharge1 = PvApp::timeEdit(p, labelChargeT, 170, 0, 60, H); + + int labelDischargeT = PvApp::label(p, ui.label2, 320, 30, 300, H, "放电时间"); + ui.attr2TimeDischarge0 = PvApp::timeEdit(p, labelDischargeT, y0 = 70, 0, 60, H); + PvApp::label(p, labelDischargeT, y0 += 70, 0, 10, H, "--"); + ui.attr2TimeDischarge1 = PvApp::timeEdit(p, labelDischargeT, y0 += 20, 0, 60, H); + + int labelPowerIn = PvApp::label(p, ui.label2, 10, 60, 300, H, "充电功率"); + ui.attr2RadioPowerInAuto = PvApp::radioButton(p, labelPowerIn, y0 = 70, 0, 60, H, "自动"); + ui.attr2RadioPowerIn = PvApp::radioButton(p, labelPowerIn, y0 += 60, 0, 64, H, "自定义"); + ui.arrt2LabelPowerIn = PvApp::textedit(p, labelPowerIn, y0 += 70, 0, 80, H, ""); + + int labelPowerOut = PvApp::label(p, ui.label2, 320, 60, 300, H, "放电功率"); + ui.attr2RadioPowerOutAuto = PvApp::radioButton(p, labelPowerOut, y0 = 70, 0, 60, H, "自动"); + ui.attr2RadioPowerOut = PvApp::radioButton(p, labelPowerOut, y0 += 60, 0, 64, H, "自定义"); + ui.arrt2LabelPowerOut = PvApp::textedit(p, labelPowerOut, y0 += 70, 0, 80, H, ""); + } + + + PvApp::bind(p, PvEvent::RADIOBUTTON_EVENT, ui.radioPolicy1, [=](std::string s) { + this->data.times = 1; + pvHide(p, ui.label2); + //setTimeText(ui.attr2TimeCharge0, ""); + //setTimeText(ui.attr2TimeCharge1, ""); + //setTimeText(ui.attr2TimeDischarge0, ""); + //setTimeText(ui.attr2TimeDischarge1, ""); + //pvSetChecked(p, ui.attr2RadioPowerInAuto, 1); + //pvSetChecked(p, ui.attr2RadioPowerOutAuto, 1); + //pvSetText(p, ui.arrt2LabelPowerOut, ""); + //data.attr2.chargePower = data.attr2.dischargePower = 0.0; + //data.attr2.chargeTimeStart = data.attr2.chargeTimeEnd = data.attr2.dischargeTimeStart = data.attr2.dischargeTimeEnd = ""; + }); + + PvApp::bind(p, PvEvent::RADIOBUTTON_EVENT, ui.radioPolicy2, [=](std::string s) { + this->data.times = 2; + pvShow(p, ui.label2); + }); + + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeCharge0, [=](std::string s) { + data.attr1.chargeTimeStart = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeCharge1, [=](std::string s) { + data.attr1.chargeTimeEnd = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeDischarge0, [=](std::string s) { + data.attr1.dischargeTimeStart = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr1TimeDischarge1, [=](std::string s) { + data.attr1.dischargeTimeEnd = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeCharge0, [=](std::string s) { + data.attr2.chargeTimeStart = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeCharge1, [=](std::string s) { + data.attr2.chargeTimeEnd = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeDischarge0, [=](std::string s) { + data.attr2.dischargeTimeStart = s.substr(0, 8); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.attr2TimeDischarge1, [=](std::string s) { + data.attr2.dischargeTimeEnd = s.substr(0, 8); + }); + +// { +// int btn = PvApp::button(p, pvid, 10, y+=100, 90, 30, "DUMP"); +// PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { +// XLOGD() << dumpAttr(); +// }); +// } +// { +// int btn = PvApp::button(p, pvid, 110, y, 90, 30, "PARSE1"); +// PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { +// std::string s = R"({"cycle":[{"charge_end":"","charge_power":0.0,"charge_start":"","discharge_end":"","discharge_power":0.0,"discharge_start":""}], +//"period":[[1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]], +//"times":1})"; +// parseAttr(s); +// }); +// } +// { +// int btn = PvApp::button(p, pvid, 210, y, 90, 30, "PARSE2"); +// PvApp::bind(p, PvEvent::BUTTON_EVENT, btn, [=](std::string) { +// std::string s = R"({"cycle":[ +//{"charge_end":"09:00:00","charge_power":0.0,"charge_start":"00:00:00","discharge_end":"","discharge_power":0.0,"discharge_start":""}, +//{"charge_end":"23:59:00","charge_power":0.0,"charge_start":"20:00:00","discharge_end":"13:00","discharge_power":0.0,"discharge_start":"09:00"} +//], +//"period":[[1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3],[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]], +//"times":2})"; +// parseAttr(s); +// }); +// } } void PanelPolicyPeak::updateUI() @@ -284,7 +307,7 @@ void PanelPolicyPeak::parseAttr(std::string str) periodVal = tmpVal; // 更新UI (时段下拉列表) auto combox = ui.vecComboxs[row][col]; - pvSetCurrentItem(p, combox, periodVal); + pvSetCurrentItem(p, combox, periodVal-1); pvSetStyleSheet(p, combox, GetPeriodQss(periodVal).c_str()); } } @@ -333,7 +356,6 @@ void PanelPolicyPeak::parseAttr(std::string str) } - std::string PanelPolicyPeak::dumpAttr() { NJsonNode jsonroot; @@ -363,4 +385,117 @@ std::string PanelPolicyPeak::dumpAttr() } jsonroot["cycle"] = nodeCycle; return jsonroot.dump(); +} + + +PanelPolicyRequire::PanelPolicyRequire(PARAM* p, int parent, int ix, int iy, int iw, int ih) : PvObject(p) +{ + pvid = PvApp::widget(p, parent, ix, iy, iw, ih); + + int y = 10; + const int H = 24; + ui.label1 = PvApp::label(p, pvid, 10, y, 600, 80, "响应削峰指令", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); + pvSetAlignment(p, ui.label1, AlignLeft | AlignTop); + { + ui.dischargeSoc = PvApp::lineTextedit(p, ui.label1, PvRect(10, 40, 270, H), 100, "电池SOC阈值", ""); + ui.dischargePower = PvApp::lineTextedit(p, ui.label1, PvRect(300, 40, 270, H), 70, "放电功率", ""); + } + + ui.label2 = PvApp::label(p, pvid, 10, y += 90, 600, 90, "响应填谷指令", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); + pvSetAlignment(p, ui.label2, AlignLeft | AlignTop); + { + ui.chargeSoc = PvApp::lineTextedit(p, ui.label2, PvRect(10, 40, 270, H), 100, "电池SOC阈值", ""); + ui.chargePower = PvApp::lineTextedit(p, ui.label2, PvRect(300, 40, 270, H), 70, "充电功率", ""); + } + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.dischargeSoc, [=](std::string s) { + data.dischargeSoc = Utils::toInt(s); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.dischargePower, [=](std::string s) { + data.dischargePower = Utils::toInt(s); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.chargeSoc, [=](std::string s) { + data.chargeSoc = Utils::toInt(s); + }); + PvApp::bind(p, PvEvent::TEXT_EVENT, ui.chargePower, [=](std::string s) { + data.chargePower = Utils::toInt(s); + }); +} + +void PanelPolicyRequire::parseAttr(std::string str) +{ + NJsonNode jsonroot; + bool ret = NJson::parse(str, jsonroot); + if (!ret) + { + return; + } + + NJson::read(jsonroot, "charge_soc", data.chargeSoc); + NJson::read(jsonroot, "charge_power", data.chargePower); + NJson::read(jsonroot, "discharge_soc", data.dischargeSoc); + NJson::read(jsonroot, "discharge_power", data.dischargePower); + + // 更新UI + pvSetText(p, ui.chargeSoc, std::to_string(data.chargeSoc).c_str()); + pvSetText(p, ui.chargePower, std::to_string(data.chargePower).c_str()); + pvSetText(p, ui.dischargeSoc, std::to_string(data.dischargeSoc).c_str()); + pvSetText(p, ui.dischargePower, std::to_string(data.dischargePower).c_str()); +} + +std::string PanelPolicyRequire::dumpAttr() +{ + NJsonNode jsonroot; + jsonroot["discharge_soc"] = data.dischargeSoc; + jsonroot["discharge_power"] = data.dischargePower; + jsonroot["charge_soc"] = data.chargeSoc; + jsonroot["charge_power"] = data.chargePower; + return jsonroot.dump(); +} + +PanelPolicySelf::PanelPolicySelf(PARAM* p, int parent, int ix, int iy, int iw, int ih) : PvObject(p) +{ + pvid = PvApp::widget(p, parent, ix, iy, iw, ih); + + int y = 10; + const int H = 24; + ui.label1 = PvApp::label(p, pvid, 10, y, 600, 120, "响应削峰指令", qss::label(14, "", "", "1px solid rgb(49, 130, 141)")); + pvSetAlignment(p, ui.label1, AlignLeft | AlignTop); + { + ui.usedSoc = PvApp::lineTextedit(p, ui.label1, PvRect(10, 40, 270, H), 100, "自用电量比值", ""); + ui.gridSoc = PvApp::lineTextedit(p, ui.label1, PvRect(10, 80, 270, H), 100, "上网电量比值", ""); + + ui.chargePower = PvApp::lineTextedit(p, ui.label1, PvRect(320, 40, 250, H), 70, "充电功率", ""); + ui.dischargePower = PvApp::lineTextedit(p, ui.label1, PvRect(320, 80, 250, H), 70, "放电功率", ""); + } +} + +void PanelPolicySelf::parseAttr(std::string str) +{ + NJsonNode jsonroot; + bool ret = NJson::parse(str, jsonroot); + if (!ret) + { + return; + } + + NJson::read(jsonroot, "used_soc", data.usedSoc); + NJson::read(jsonroot, "grid_soc", data.gridSoc); + NJson::read(jsonroot, "charge_power", data.chargePower); + NJson::read(jsonroot, "discharge_power", data.dischargePower); + + // 更新UI + pvSetText(p, ui.usedSoc, std::to_string(data.usedSoc).c_str()); + pvSetText(p, ui.gridSoc, std::to_string(data.gridSoc).c_str()); + pvSetText(p, ui.chargePower, std::to_string(data.chargePower).c_str()); + pvSetText(p, ui.dischargePower, std::to_string(data.dischargePower).c_str()); +} + +std::string PanelPolicySelf::dumpAttr() +{ + NJsonNode jsonroot; + jsonroot["used_soc"] = data.usedSoc; + jsonroot["grid_soc"] = data.gridSoc; + jsonroot["charge_power"] = data.chargePower; + jsonroot["discharge_power"] = data.dischargePower; + return jsonroot.dump(); } \ No newline at end of file diff --git a/src/pv/pages/PanelPolicy.h b/src/pv/pages/PanelPolicy.h index dcc083c..3bdb02b 100644 --- a/src/pv/pages/PanelPolicy.h +++ b/src/pv/pages/PanelPolicy.h @@ -6,7 +6,7 @@ class PanelPolicyPeak : public PvObject { public: - PanelPolicyPeak(PARAM* p, int parent, int x, int y, int w, int h); + PanelPolicyPeak(PARAM* p, int parent, int ix, int iy, int iw, int ih); void updateUI(); @@ -17,7 +17,6 @@ public: struct { int parent {}; - int widget {PV_ID_NUL}; int label1 {PV_ID_NUL}; int label2 {PV_ID_NUL}; @@ -72,4 +71,59 @@ public: ChargeAttr attr2; std::vector> vecPeriods; } data; +}; + + +class PanelPolicyRequire : public PvObject +{ +public: + PanelPolicyRequire(PARAM* p, int parent, int ix, int iy, int iw, int ih); + + void parseAttr(std::string str); + std::string dumpAttr(); + + struct { + int label1; + int label2; + + int chargeSoc; + int chargePower; + + int dischargeSoc; + int dischargePower; + } ui; + + struct { + int chargeSoc {}; + int chargePower {}; + + int dischargeSoc {}; + int dischargePower {}; + } data; +}; + +class PanelPolicySelf : public PvObject +{ +public: + PanelPolicySelf(PARAM* p, int parent, int x, int y, int w, int h); + + void parseAttr(std::string str); + std::string dumpAttr(); + + struct { + int label1; + int usedSoc; + int gridSoc; + + int chargePower; + int dischargePower; + } ui; + + struct { + int usedSoc {}; + int gridSoc {}; + + int chargePower {}; + int dischargePower {}; + } data; }; \ No newline at end of file diff --git a/src/pv/pvmain.cpp b/src/pv/pvmain.cpp index 40f2151..838fd2a 100644 --- a/src/pv/pvmain.cpp +++ b/src/pv/pvmain.cpp @@ -4,7 +4,7 @@ void pvInitResource(PARAM* p) { - pvDownloadFile(p, "assets/pv/bkg.png"); + pvDownloadFile(p, "assets/pv/bkgHead.png"); pvDownloadFile(p, "assets/pv/icon1.png"); pvDownloadFile(p, "assets/pv/icon2.png"); pvDownloadFile(p, "assets/pv/icon3.png"); @@ -14,6 +14,7 @@ void pvInitResource(PARAM* p) pvDownloadFile(p, "assets/pv/map.png"); pvDownloadFile(p, "assets/pv/mapMarker.png"); pvDownloadFile(p, "assets/pv/downFill.png"); + pvDownloadFile(p, "assets/pv/play1.png"); } int onPvThreadCleanup(void* ptr) @@ -29,6 +30,7 @@ int pvMain(PARAM* p) // 管理客户端的连接信息 PvUser pvuser; PvApp::setPvUser(p, &pvuser); + XLOGD() << "Browser client connect: s= " << int(p->s) << ", user=" << int(&pvuser); // 客户端断开时回调 pvSetCleanup(p, onPvThreadCleanup, p); @@ -38,7 +40,7 @@ int pvMain(PARAM* p) while (1) { - // 重置控件的ID值 + // 重置控件的ID值、回调函数表 PvApp::reset(p); std::shared_ptr mask; @@ -48,14 +50,13 @@ int pvMain(PARAM* p) pvStartDefinition(p, 2048); if (mask) { - pvSetFont(p, PV_ID_MAIN, "微软雅黑", 12, 1, 0, 0, 0); + pvSetStyleSheet(p, PV_ID_MAIN, "QWidget { color: white; font: bold 14px 微软雅黑; }"); mask->initUI(); } pvQLayoutVbox(p, 0, -1); pvEndDefinition(p); XLOGD() << "===>>> pvidIndex=" << PvApp::pvid(p); - char event[MAX_EVENT_LENGTH]; char text[MAX_EVENT_LENGTH]; int pvid; @@ -68,37 +69,36 @@ int pvMain(PARAM* p) if (mask) { PvApp::dispatch(p, pvEventId, pvid, text); - switch (pvEventId) { case NULL_EVENT: { pvcode = mask->onEventNull(pvid); } break; case BUTTON_EVENT: { - pvcode = mask->onEventButton(pvid); std::cout << "EVENT: (" << pvid << ")BUTTON\n"; + pvcode = mask->onEventButton(pvid); std::cout << "PvEvent: (" << pvid << ") BUTTON\n"; } break; - case TEXT_EVENT: { std::cout << "EVENT: (" << pvid << ")TEXT_EVENT\n"; } break; - case SLIDER_EVENT: { std::cout << "EVENT: (" << pvid << ")SLIDER_EVENT\n"; } break; - case CHECKBOX_EVENT: { std::cout << "EVENT: (" << pvid << ")CHECKBOX_EVENT\n"; } break; - case RADIOBUTTON_EVENT: { std::cout << "EVENT: (" << pvid << ")RADIOBUTTON_EVENT\n"; } break; - case GL_IDLE_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_IDLE_EVENT\n"; } break; - case GL_PAINT_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_PAINT_EVENT\n"; } break; - case GL_INITIALIZE_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_INITIALIZE_EVENT\n"; } break; - case GL_RESIZE_EVENT: { std::cout << "EVENT: (" << pvid << ")GL_RESIZE_EVENT\n"; } break; - case TAB_EVENT: { std::cout << "EVENT: (" << pvid << ")TAB_EVENT\n"; } break; - case TABLE_CLICKED_EVENT: { std::cout << "EVENT: (" << pvid << ")TABLE_CLICKED_EVENT\n"; } break; - case TABLE_TEXT_EVENT: { std::cout << "EVENT: (" << pvid << ")TABLE_TEXT_EVENT\n"; } break; - case SELECTION_EVENT: { std::cout << "EVENT: (" << pvid << ")SELECTION_EVENT\n"; } break; - case CLIPBOARD_EVENT: { std::cout << "EVENT: (" << pvid << ")CLIPBOARD_EVENT\n"; } break; - case BUTTON_PRESSED_EVENT: { std::cout << "EVENT: (" << pvid << ")BUTTON_PRESSED_EVENT\n"; } break; - case BUTTON_RELEASED_EVENT: { std::cout << "EVENT: (" << pvid << ")BUTTON_RELEASED_EVENT\n"; } break; - case RIGHT_MOUSE_EVENT: { std::cout << "EVENT: (" << pvid << ")RIGHT_MOUSE_EVENT\n"; } break; - case KEYBOARD_EVENT: { std::cout << "EVENT: (" << pvid << ")KEYBOARD_EVENT\n"; } break; - case PLOT_MOUSE_MOVED_EVENT: { std::cout << "EVENT: (" << pvid << ")PLOT_MOUSE_MOVED_EVENT\n"; } break; - case PLOT_MOUSE_PRESSED_EVENT: { std::cout << "EVENT: (" << pvid << ")PLOT_MOUSE_PRESSED_EVENT\n"; } break; - case PLOT_MOUSE_RELEASED_EVENT: { std::cout << "EVENT: (" << pvid << ")PLOT_MOUSE_RELEASED_EVENT\n"; } break; - case USER_EVENT: { std::cout << "EVENT: (" << pvid << ")USER_EVENT\n"; } break; - case MOUSE_OVER_EVENT: { /*std::cout << "EVENT: (" << pvid << ")MOUSE_OVER_EVENT\n";*/ } break; + case TEXT_EVENT: { std::cout << "PvEvent: (" << pvid << ") TEXT_EVENT\n"; } break; + case SLIDER_EVENT: { std::cout << "PvEvent: (" << pvid << ") SLIDER_EVENT\n"; } break; + case CHECKBOX_EVENT: { std::cout << "PvEvent: (" << pvid << ") CHECKBOX_EVENT\n"; } break; + case RADIOBUTTON_EVENT: { std::cout << "PvEvent: (" << pvid << ") RADIOBUTTON_EVENT\n"; } break; + case GL_IDLE_EVENT: { std::cout << "PvEvent: (" << pvid << ") GL_IDLE_EVENT\n"; } break; + case GL_PAINT_EVENT: { std::cout << "PvEvent: (" << pvid << ") GL_PAINT_EVENT\n"; } break; + case GL_INITIALIZE_EVENT: { std::cout << "PvEvent: (" << pvid << ") GL_INITIALIZE_EVENT\n"; } break; + case GL_RESIZE_EVENT: { std::cout << "PvEvent: (" << pvid << ") GL_RESIZE_EVENT\n"; } break; + case TAB_EVENT: { std::cout << "PvEvent: (" << pvid << ") TAB_EVENT\n"; } break; + case TABLE_CLICKED_EVENT: { std::cout << "PvEvent: (" << pvid << ") TABLE_CLICKED_EVENT\n"; } break; + case TABLE_TEXT_EVENT: { std::cout << "PvEvent: (" << pvid << ") TABLE_TEXT_EVENT\n"; } break; + case SELECTION_EVENT: { std::cout << "PvEvent: (" << pvid << ") SELECTION_EVENT\n"; } break; + case CLIPBOARD_EVENT: { std::cout << "PvEvent: (" << pvid << ") CLIPBOARD_EVENT\n"; } break; + case BUTTON_PRESSED_EVENT: { /*std::cout << "PvEvent: (" << pvid << ") BUTTON_PRESSED_EVENT\n";*/ } break; + case BUTTON_RELEASED_EVENT: { /*std::cout << "PvEvent: (" << pvid << ") BUTTON_RELEASED_EVENT\n";*/ } break; + case RIGHT_MOUSE_EVENT: { std::cout << "PvEvent: (" << pvid << ") RIGHT_MOUSE_EVENT\n"; } break; + case KEYBOARD_EVENT: { std::cout << "PvEvent: (" << pvid << ") KEYBOARD_EVENT\n"; } break; + case PLOT_MOUSE_MOVED_EVENT: { std::cout << "PvEvent: (" << pvid << ") PLOT_MOUSE_MOVED_EVENT\n"; } break; + case PLOT_MOUSE_PRESSED_EVENT: { std::cout << "PvEvent: (" << pvid << ") PLOT_MOUSE_PRESSED_EVENT\n"; } break; + case PLOT_MOUSE_RELEASED_EVENT: { std::cout << "PvEvent: (" << pvid << ") PLOT_MOUSE_RELEASED_EVENT\n"; } break; + case USER_EVENT: { std::cout << "PvEvent: (" << pvid << ") USER_EVENT\n"; } break; + case MOUSE_OVER_EVENT: { /*std::cout << "PvEvent: (" << pvid << ") MOUSE_OVER_EVENT\n";*/ } break; default: {} break; } } diff --git a/src/widgets/uihelper.cpp b/src/widgets/uihelper.cpp index 47523e9..e856305 100644 --- a/src/widgets/uihelper.cpp +++ b/src/widgets/uihelper.cpp @@ -114,10 +114,10 @@ void QUI::combox(QComboBox& comb, QWidget* parent, int x, int y, int w, int h, s } } -void QUI::lineedit(QLineEdit& lineEdit, QWidget* parent, int x, int y, int w, int h) +void QUI::lineedit(QLineEdit& edit, QWidget* parent, int x, int y, int w, int h) { - lineEdit.setParent(parent); - lineEdit.setGeometry(x, y, w, h); + edit.setParent(parent); + edit.setGeometry(x, y, w, h); } void QUI::setBackground(QWidget* w, std::string name, QColor color, std::string border) @@ -742,7 +742,7 @@ void TableBase::setOperate(std::vector vecOperate, std::function vd) +void TableBase::setRow(int row, std::vector vd) { int rowCount = widget_->rowCount(); if (row >= rowCount) diff --git a/src/widgets/uihelper.h b/src/widgets/uihelper.h index 1ccdd84..59a32ce 100644 --- a/src/widgets/uihelper.h +++ b/src/widgets/uihelper.h @@ -56,7 +56,7 @@ public: static void combox(QComboBox& comb, QWidget* parent, int x, int y, int w, int h, std::vector items, std::string v=""); - static void lineedit(QLineEdit& lineEdit, QWidget* parent, int x, int y, int w, int h); + static void lineedit(QLineEdit& edit, QWidget* parent, int x, int y, int w, int h); static void setBackground(QWidget* w, std::string name, QColor color=QColor(29, 54, 102), std::string border="border-radius:5px;"); }; @@ -170,7 +170,7 @@ public: void setOperate(std::vector vecOperate, std::function cb); - void setRowData(int row, std::vector vd); + void setRow(int row, std::vector vd); void clear();