diff --git a/ComponentBasic/EntityDocks.cpp b/ComponentBasic/EntityDocks.cpp index 56d3e8b..d8b7e15 100644 --- a/ComponentBasic/EntityDocks.cpp +++ b/ComponentBasic/EntityDocks.cpp @@ -1,8 +1,13 @@ #include "EntityDocks.h" #include +#include +#include +QMutex DeduceFramework::_static_mutex; QList> deduct_each(std::shared_ptr item) { + QMutexLocker loc(&DeduceFramework::_static_mutex); + QList> rets; auto immediate = std::make_shared(item); @@ -20,6 +25,7 @@ QList> deduct_each(std::shared_ptr item) QList> DeduceFramework::_accept_stack; void DeduceFramework::accept(const QList>& set) { + QMutexLocker loc(&DeduceFramework::_static_mutex); _accept_stack.append(set); } @@ -29,9 +35,13 @@ void DeduceFramework::deduceBegin(std::shared_ptr ins) { auto dt = QTime::currentTime(); - auto ret_list_set = QtConcurrent::blockingMapped( - _entity_map_over_0xffff.values(), deduct_each - ); + DeduceFramework::_static_mutex.lock(); + auto items = _entity_map_over_0xffff.values(); + for(auto item : _templets_within_0x2ff_0xffff.values()) + items.append(item); + DeduceFramework::_static_mutex.unlock(); + + auto ret_list_set = QtConcurrent::blockingMapped(items, deduct_each); _accept_stack.clear(); for (auto vlist : ret_list_set) @@ -182,17 +192,17 @@ void DeduceFramework::execute(std::shared_ptr map, case EntityOperateType::NEW: { nins->_success_mark = true; auto ent_t = std::make_shared(); + ent_t->resetID(0x2ff); ent_t->resetTemplet(in->_template_name); + auto desc_p = std::make_shared(); ent_t->append(desc_p); // 提取所有的模板id auto _tm_ins = _templets_within_0x2ff_0xffff.values(); QList allids; - std::transform(_templets_within_0x2ff_0xffff.begin(), - _templets_within_0x2ff_0xffff.end(), - std::back_inserter(allids), - [](std::shared_ptr i) { return i->entityID(); }); + std::transform(_templets_within_0x2ff_0xffff.begin(), _templets_within_0x2ff_0xffff.end(), + std::back_inserter(allids), [](std::shared_ptr i) { return i->entityID(); }); // 重置模板id while (allids.contains(ent_t->entityID())) { diff --git a/ComponentBasic/EntityDocks.h b/ComponentBasic/EntityDocks.h index d01f44f..b748f18 100644 --- a/ComponentBasic/EntityDocks.h +++ b/ComponentBasic/EntityDocks.h @@ -4,6 +4,7 @@ #include "componentbasic.h" #include #include +#include class COMPONENTBASIC_EXPORT ComponentFactory : public Serializable { private: @@ -62,6 +63,7 @@ public slots: void deduceBegin(std::shared_ptr ins); public: + static QMutex _static_mutex; static QList> _accept_stack; DeduceFramework(); diff --git a/ComponentBasic/InvisibleComponent.cpp b/ComponentBasic/InvisibleComponent.cpp index 20b77a2..6b126c3 100644 --- a/ComponentBasic/InvisibleComponent.cpp +++ b/ComponentBasic/InvisibleComponent.cpp @@ -31,6 +31,9 @@ void ComponentsInfoPull::execute(std::shared_ptr map, auto array = QJsonArray(); for (auto ins : comp_list) { + if(ins->name() == this->name()) + continue; + auto info_comp = QJsonObject(); info_comp["component_type"] = ins->name(); ins->saveTo(info_comp); diff --git a/SimsWorld/TempletAssemble.cpp b/SimsWorld/TempletAssemble.cpp index 2edb029..d6e508d 100644 --- a/SimsWorld/TempletAssemble.cpp +++ b/SimsWorld/TempletAssemble.cpp @@ -5,14 +5,99 @@ #include #include #include +#include -TempletAssemble::TempletAssemble(std::shared_ptr fmk, QWidget *parent) + +void TempletAssemble::deduce_start() +{ + auto request = std::make_shared(); + request->reset(-1, RtEntityManager::const_id); + emit this->backend_deduce_request(request); +} + +#include +void TempletAssemble::reply_accept(const QList>& 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(msg); + this->_component_types->addItems(conv->_component_types); + for (auto info : conv->_entity_templets.keys()) { + auto templat_id = conv->_entity_templets[info]; + if ((QList{RtEntityManager::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(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 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(); + req->reset(-1, template_id); + this->_bind_framework->accept(QList>{req}); +} + +#include +void TempletAssemble::append_templet() +{ + auto value = QInputDialog::getText(this, u8"输入模板类型", u8"名称"); + if (value.isEmpty()) + return; + + auto app = std::make_shared(); + app->reset(-1, RtEntityManager::const_id); + app->_operate_code = (int)EntityOperateType::NEW; + app->_template_name = value; + + auto query = std::make_shared(); + query->reset(-1, RtEntityManager::const_id); + + _bind_framework->accept(QList>() << app << query); +} + +TempletAssemble::TempletAssemble(std::shared_ptr 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"添加模板",this)), + _t_add(new QPushButton(u8"添加模板", this)), _t_remove(new QPushButton(u8"移除模板", this)), + _right_widget(new QWidget(this)), _templet_name(new QLineEdit(this)), _component_types(new QComboBox(this)), _comp_add(new QPushButton(u8"添加组件", this)), @@ -21,6 +106,12 @@ TempletAssemble::TempletAssemble(std::shared_ptr fmk, QWidget * _component_model(new QStandardItemModel(this)), _apply(new QPushButton(u8"应用", 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"类型模板配置"); this->setMinimumSize(800, 600); @@ -32,13 +123,13 @@ TempletAssemble::TempletAssemble(std::shared_ptr fmk, QWidget * 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); - auto right_widget = new QWidget(this); - split->addWidget(right_widget); - auto rlayout = new QGridLayout(right_widget); + split->addWidget(_right_widget); + auto rlayout = new QGridLayout(_right_widget); rlayout->addWidget(new QLabel(u8"模板名称", this), 0, 0); rlayout->addWidget(_templet_name, 0, 1, 1, 4); rlayout->addWidget(new QLabel(u8"组件类型", this), 1, 0); @@ -46,8 +137,16 @@ TempletAssemble::TempletAssemble(std::shared_ptr fmk, QWidget * 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(); + ins->reset(-1, RtEntityManager::const_id); + _bind_framework->accept(QList>{ins}); + + connect(this->_bind_timer, &QTimer::timeout, this, &TempletAssemble::deduce_start); + this->_bind_timer->start(100); } diff --git a/SimsWorld/TempletAssemble.h b/SimsWorld/TempletAssemble.h index accaf38..793d65c 100644 --- a/SimsWorld/TempletAssemble.h +++ b/SimsWorld/TempletAssemble.h @@ -4,6 +4,7 @@ #include #include #include +#include #include class TempletAssemble : public QDialog @@ -11,11 +12,13 @@ class TempletAssemble : public QDialog Q_OBJECT private: std::shared_ptr _bind_framework; + QTimer *const _bind_timer; QListView *const _templet_present; QStandardItemModel *const _templet_model; QPushButton *const _t_add, *const _t_remove; + QWidget *const _right_widget; QLineEdit *const _templet_name; QComboBox *const _component_types; QPushButton *const _comp_add, *const _comp_remove; @@ -23,10 +26,19 @@ private: QStandardItemModel *const _component_model; QPushButton *const _apply; + void deduce_start(); + void reply_accept(const QList>& set); + void complete_accept(std::shared_ptr ins); + + void show_templet_content(const QModelIndex& target); + + void append_templet(); + public: TempletAssemble(std::shared_ptr fmk, QWidget *p = nullptr); virtual ~TempletAssemble() = default; - +signals: + void backend_deduce_request(std::shared_ptr ins); };