mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
实现削峰套利策略的编辑页面
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "PvTable.h"
|
||||
#include "PvStyle.h"
|
||||
#include "pv/PvApp.h"
|
||||
#include "pv/PvPopWidget.h"
|
||||
|
||||
static const string STYLE_BKG =
|
||||
"border-width:1 1 1 1px; border-style:outset solid; border-color:rgba(180,180,180,255);"
|
||||
@@ -208,7 +209,7 @@ void PvTable::mappingData(Fields& fields)
|
||||
for (int i=0; i< vecHead_.size(); ++i)
|
||||
{
|
||||
auto& head = vecHead_[i];
|
||||
if (fields.hasKey(head.id))
|
||||
if (fields.contains(head.id))
|
||||
{
|
||||
auto& val = fields.value(head.id);
|
||||
val = head.getMapping(val);
|
||||
@@ -417,16 +418,91 @@ void PvPagination::setCallback(std::function<void(int index)> func)
|
||||
callback = func;
|
||||
}
|
||||
|
||||
PvPageTable::PvPageTable(PARAM* p, int parent, int x, int y, int w, int rows, PvTable::Options& opts)
|
||||
//: PvWidget(p, parent, PvRect(x, y, w, opts.item_height* rows + (opts.show_header ? (opts.header_height) : 0)))
|
||||
: PvObject(p)
|
||||
{
|
||||
int h = opts.row_height* rows + (opts.show_header ? (opts.head_height) : 0);
|
||||
int pvid_ = PvApp::widget(p, parent, x, y, w, h);
|
||||
table_ = make_shared<PvTable>(p, pvid_, 0, 0, w, rows, opts);
|
||||
}
|
||||
|
||||
shared_ptr<PvTable> PvPageTable::getTable()
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// === PageTable ===
|
||||
PageTable::PageTable(PARAM* p) : PvMask(p)
|
||||
{
|
||||
return table_;
|
||||
}
|
||||
table = std::make_shared<PvTable>(p, 0, 20, 210, 1880, pageSize, option);
|
||||
table->setOperateCallback([=](int row, int col, std::string text) { this->onOperate(row, col, text); });
|
||||
|
||||
pagination = std::make_shared<PvPagination>(p, 0, 20, 780, 20);
|
||||
pagination->setCallback([=](int index)
|
||||
{
|
||||
pageIndex = index;
|
||||
this->updateDataFromDB();
|
||||
});
|
||||
}
|
||||
std::shared_ptr<PvPopWidget> PageTable::addPop(int w, int h, int w0, std::string name, std::vector<std::string> primaryKeys)
|
||||
{
|
||||
std::shared_ptr<PvPopWidget> pop = std::make_shared<PvPopWidget>(p, w, h, name);
|
||||
pop->lineValWidth = w0;
|
||||
pop->setPrimaryKeys(primaryKeys);
|
||||
pop->setCallbackConfirm([=]()
|
||||
{
|
||||
auto fields = pop->getData();
|
||||
std::string err = this->onValidation(pop, fields);
|
||||
pop->setMsg(err);
|
||||
|
||||
if (err.empty())
|
||||
{
|
||||
XLOGD() << "POP get: data=" << fields.toStr();
|
||||
if (pop->status == POP_OPER_EDIT) { pop->checkChangedData(fields); }
|
||||
XLOGD() << "POP get: data=" << fields.toStr();
|
||||
table->mappingData(fields);
|
||||
XLOGD() << "POP get: data=" << fields.toStr();
|
||||
err = this->onPopConfirm(pop, fields);
|
||||
pop->setMsg(err);
|
||||
if (err.empty())
|
||||
{
|
||||
this->hidePop(0);
|
||||
this->updateDataFromDB();
|
||||
};
|
||||
}
|
||||
});
|
||||
pop->show(0);
|
||||
vecPop.push_back(pop);
|
||||
return pop;
|
||||
}
|
||||
void PageTable::showPop(int index, std::string oper, Fields& fields)
|
||||
{
|
||||
XLOGD() << "POP set: data=" << fields.toStr();
|
||||
table->mappingData(fields);
|
||||
XLOGD() << "POP set: data=" << fields.toStr();
|
||||
if (index < vecPop.size())
|
||||
{
|
||||
auto& pop = vecPop[index];
|
||||
pop->show(true);
|
||||
pop->setStatus(oper);
|
||||
pop->setData(fields);
|
||||
pop->setMsg("");
|
||||
}
|
||||
}
|
||||
void PageTable::hidePop(int index)
|
||||
{
|
||||
if (index < vecPop.size())
|
||||
{
|
||||
vecPop[index]->show(false);
|
||||
}
|
||||
}
|
||||
void PageTable::updateDataFromDB()
|
||||
{
|
||||
std::vector<Fields> result;
|
||||
PageInfo pageInfo;
|
||||
pageInfo.size = pageSize;
|
||||
pageInfo.index = pageIndex;
|
||||
this->onQueryTable(pageInfo, result);
|
||||
for (int i = 0; i<table->rows(); ++i)
|
||||
{
|
||||
if (i<result.size())
|
||||
{
|
||||
auto& fields = result[i];
|
||||
table->setRowData(i, result[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
table->setRowVisible(i, false);
|
||||
}
|
||||
}
|
||||
pagination->setPage(pageInfo.index, pageInfo.total/pageInfo.size + int(pageInfo.total%pageInfo.size != 0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user