156 lines
5.1 KiB
C++
156 lines
5.1 KiB
C++
#include "TempletAssemble.h"
|
||
#include <QLineEdit>
|
||
#include <QGridLayout>
|
||
#include <QVBoxLayout>
|
||
#include <QSplitter>
|
||
#include <QLabel>
|
||
#include <QGroupBox>
|
||
#include <QDebug>
|
||
#include <ComponentsInfoPull.h>
|
||
#include <componentinfo_access.h>
|
||
|
||
|
||
void TempletAssemble::deduce_start()
|
||
{
|
||
auto request = std::make_shared<DeduceRequest>();
|
||
request->reset(-1, RtEntityManager::const_id);
|
||
emit this->backend_deduce_request(request);
|
||
}
|
||
|
||
#include <QJsonArray>
|
||
void TempletAssemble::reply_accept(const QList<std::shared_ptr<WsMessage>>& msg_set)
|
||
{
|
||
for (auto msg : msg_set) {
|
||
if (msg->topicString() == TypesQueryResult().topicString()) {
|
||
_templet_model->clear();
|
||
_component_types->clear();
|
||
_right_widget->setEnabled(false);
|
||
|
||
auto conv = std::static_pointer_cast<TypesQueryResult>(msg);
|
||
this->_component_types->addItems(conv->_component_types);
|
||
for (auto info : conv->_entity_templets.keys()) {
|
||
auto templat_id = conv->_entity_templets[info];
|
||
if ((QList<uint64_t>{ RtEntityManager::const_id, RtResourceManager::const_id })
|
||
.contains(templat_id))
|
||
continue;
|
||
|
||
auto cell = new QStandardItem(info);
|
||
cell->setData(templat_id);
|
||
cell->setEditable(false);
|
||
_templet_model->appendRow(cell);
|
||
}
|
||
}
|
||
if (msg->topicString() == ComponentDatasQueryResult().topicString()) {
|
||
this->_right_widget->setEnabled(true);
|
||
auto conv = std::dynamic_pointer_cast<ComponentDatasQueryResult>(msg);
|
||
|
||
auto name = conv->_entity_json["entity_templet"].toString();
|
||
_templet_name->setText(name);
|
||
this->_component_model->clear();
|
||
|
||
auto json_array = conv->_entity_json["component_list"].toArray();
|
||
for (auto idx = 0; idx < json_array.count(); ++idx) {
|
||
auto obj = json_array.at(idx).toObject();
|
||
auto comp_name = obj["component_type"].toString();
|
||
|
||
auto row = new QStandardItem(comp_name);
|
||
this->_component_model->appendRow(row);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void TempletAssemble::complete_accept(std::shared_ptr<RespondDefault> ins) {}
|
||
|
||
void TempletAssemble::show_templet_content(const QModelIndex& target)
|
||
{
|
||
if (!target.isValid())
|
||
return;
|
||
|
||
auto item = this->_templet_model->itemFromIndex(target);
|
||
auto template_id = item->data().toULongLong();
|
||
auto req = std::make_shared<ComponentDatasQuery>();
|
||
req->reset(-1, template_id);
|
||
this->_bind_framework->accept(QList<std::shared_ptr<WsMessage>>{req});
|
||
}
|
||
|
||
#include <QInputDialog>
|
||
void TempletAssemble::append_templet()
|
||
{
|
||
auto value = QInputDialog::getText(this, u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
if (value.isEmpty())
|
||
return;
|
||
|
||
auto app = std::make_shared<TempletOperate>();
|
||
app->reset(-1, RtEntityManager::const_id);
|
||
app->_operate_code = (int)EntityOperateType::NEW;
|
||
app->_template_name = value;
|
||
|
||
auto query = std::make_shared<TypesQuery>();
|
||
query->reset(-1, RtEntityManager::const_id);
|
||
|
||
_bind_framework->accept(QList<std::shared_ptr<WsMessage>>() << app << query);
|
||
}
|
||
|
||
TempletAssemble::TempletAssemble(std::shared_ptr<DeduceFramework> fmk, QWidget* parent)
|
||
:QDialog(parent),
|
||
_bind_framework(fmk),
|
||
_bind_timer(new QTimer(this)),
|
||
_templet_present(new QListView(this)),
|
||
_templet_model(new QStandardItemModel(this)),
|
||
_t_add(new QPushButton(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>", this)),
|
||
_t_remove(new QPushButton(u8"<EFBFBD>Ƴ<EFBFBD>ģ<EFBFBD><EFBFBD>", this)),
|
||
_right_widget(new QWidget(this)),
|
||
_templet_name(new QLineEdit(this)),
|
||
_component_types(new QComboBox(this)),
|
||
_comp_add(new QPushButton(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", this)),
|
||
_comp_remove(new QPushButton(u8"<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", this)),
|
||
_component_present(new QListView(this)),
|
||
_component_model(new QStandardItemModel(this)),
|
||
_apply(new QPushButton(u8"Ӧ<EFBFBD><EFBFBD>", this))
|
||
{
|
||
connect(this, &TempletAssemble::backend_deduce_request, _bind_framework.get(), &DeduceFramework::deduceBegin);
|
||
connect(_bind_framework.get(), &DeduceFramework::reply, this, &TempletAssemble::reply_accept);
|
||
connect(_templet_present, &QListView::clicked, this, &TempletAssemble::show_templet_content);
|
||
connect(_t_add, &QPushButton::clicked, this, &TempletAssemble::append_templet);
|
||
|
||
|
||
setWindowTitle(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||
this->setMinimumSize(800, 600);
|
||
|
||
auto layout = new QVBoxLayout(this);
|
||
auto split = new QSplitter(this);
|
||
layout->addWidget(split);
|
||
|
||
auto left_widget = new QGroupBox(u8"ģ<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>", this);
|
||
split->addWidget(left_widget);
|
||
auto llayout = new QGridLayout(left_widget);
|
||
llayout->addWidget(_templet_present, 0, 0, 3, 2);
|
||
_templet_present->setModel(_templet_model);
|
||
llayout->addWidget(_t_add, 3, 0);
|
||
llayout->addWidget(_t_remove, 3, 1);
|
||
|
||
|
||
split->addWidget(_right_widget);
|
||
auto rlayout = new QGridLayout(_right_widget);
|
||
rlayout->addWidget(new QLabel(u8"ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", this), 0, 0);
|
||
rlayout->addWidget(_templet_name, 0, 1, 1, 4);
|
||
rlayout->addWidget(new QLabel(u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", this), 1, 0);
|
||
rlayout->addWidget(_component_types, 1, 1, 1, 2);
|
||
rlayout->addWidget(_comp_add, 1, 3);
|
||
rlayout->addWidget(_comp_remove, 1, 4);
|
||
rlayout->addWidget(_component_present, 2, 0, 3, 5);
|
||
_component_present->setModel(_component_model);
|
||
rlayout->addWidget(_apply, 5, 0, 1, 5);
|
||
|
||
rlayout->setColumnStretch(1, 1);
|
||
split->setStretchFactor(1, 1);
|
||
|
||
auto ins = std::make_shared<TypesQuery>();
|
||
ins->reset(-1, RtEntityManager::const_id);
|
||
_bind_framework->accept(QList<std::shared_ptr<WsMessage>>{ins});
|
||
|
||
connect(this->_bind_timer, &QTimer::timeout, this, &TempletAssemble::deduce_start);
|
||
this->_bind_timer->start(100);
|
||
}
|