124 lines
3.9 KiB
C++
124 lines
3.9 KiB
C++
#include "BehaviorConfigurationPanel.h"
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include <QPushButton>
|
|
|
|
BehaviorMapConfigurationPanel::BehaviorMapConfigurationPanel(QWidget* p)
|
|
:QFrame(p),
|
|
_root_name(new QLineEdit(this)),
|
|
_variable_table(new QTableView(this)),
|
|
_variable_model(new QStandardItemModel(this))
|
|
{
|
|
setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
|
|
auto p_layout = new QGridLayout(this);
|
|
p_layout->addWidget(new QLabel(u8"行为树名称:", this));
|
|
p_layout->addWidget(_root_name, 0, 1, 1, 3);
|
|
|
|
auto addVar = new QPushButton(u8"添加变量", this);
|
|
auto rmVar = new QPushButton(u8"删除变量", this);
|
|
p_layout->addWidget(addVar, 0, 4);
|
|
p_layout->addWidget(rmVar, 0, 5);
|
|
|
|
p_layout->addWidget(_variable_table, 1, 0, 3, 6);
|
|
_variable_table->setModel(_variable_model);
|
|
_variable_model->setHorizontalHeaderLabels(QStringList()
|
|
<< u8"输入/输出" << u8"变量名" << u8"变量类型");
|
|
|
|
p_layout->setColumnStretch(1, 1);
|
|
|
|
|
|
connect(addVar, &QPushButton::clicked, [=](){
|
|
VariableAdd dia(this->_bind_node, this);
|
|
dia.exec();
|
|
});
|
|
}
|
|
|
|
#include <BehaviorEditor.h>
|
|
void BehaviorMapConfigurationPanel::setTarget(NodePresent* ins)
|
|
{
|
|
this->_bind_graph = ins;
|
|
this->_bind_node = std::dynamic_pointer_cast<BehaviorMapNode>(ins->logicalBind());
|
|
_variable_model->removeRows(0, _variable_model->rowCount());
|
|
|
|
_root_name->setText(_bind_node->typeName());
|
|
for (auto key : _bind_node->inputVariableKeys()) {
|
|
auto ins_prop = _bind_node->getVariable(key);
|
|
QList<QStandardItem*> row;
|
|
row << new QStandardItem(u8"输入");
|
|
row << new QStandardItem(key);
|
|
row << new QStandardItem(ins_prop->topicString());
|
|
std::for_each(row.begin(), row.end(),
|
|
[](QStandardItem* ins) {ins->setEditable(false); }
|
|
);
|
|
|
|
_variable_model->appendRow(row);
|
|
}
|
|
|
|
for (auto key : _bind_node->outputVariableKeys()) {
|
|
auto ins_prop = _bind_node->getVariable(key);
|
|
QList<QStandardItem*> row;
|
|
row << new QStandardItem(u8"输出");
|
|
row << new QStandardItem(key);
|
|
row << new QStandardItem(ins_prop->topicString());
|
|
std::for_each(row.begin(), row.end(),
|
|
[](QStandardItem* ins) { ins->setEditable(false); }
|
|
);
|
|
|
|
_variable_model->appendRow(row);
|
|
}
|
|
|
|
for (auto key : _bind_node->internalVariableKeys()) {
|
|
auto ins_prop = _bind_node->getVariable(key);
|
|
QList<QStandardItem*> row;
|
|
row << new QStandardItem(u8"内部");
|
|
row << new QStandardItem(key);
|
|
row << new QStandardItem(ins_prop->topicString());
|
|
std::for_each(row.begin(), row.end(),
|
|
[](QStandardItem* ins) {ins->setEditable(false); }
|
|
);
|
|
|
|
_variable_model->appendRow(row);
|
|
}
|
|
}
|
|
|
|
VariableAdd::VariableAdd(std::shared_ptr<BehaviorMapNode> node, QWidget* parent)
|
|
: QDialog(parent), _bind_node(node),
|
|
_io_type(new QComboBox(this)),
|
|
_data_type(new QComboBox(this)),
|
|
_var_name(new QLineEdit(this))
|
|
{
|
|
setWindowTitle(u8"添加变量");
|
|
|
|
auto d_layout = new QGridLayout(this);
|
|
d_layout->addWidget(new QLabel(u8"输入/输出", this));
|
|
d_layout->addWidget(_io_type, 0, 1, 1, 2);
|
|
d_layout->addWidget(new QLabel(u8"变量类型", this), 1, 0);
|
|
d_layout->addWidget(_data_type, 1, 1, 1, 2);
|
|
d_layout->addWidget(new QLabel(u8"变量名", this), 2, 0);
|
|
d_layout->addWidget(_var_name, 2, 1, 1, 2);
|
|
|
|
auto cancel = new QPushButton(u8"取消");
|
|
auto yes = new QPushButton(u8"确定");
|
|
d_layout->addWidget(yes, 3, 0);
|
|
d_layout->addWidget(cancel, 3, 2);
|
|
|
|
connect(cancel, &QPushButton::clicked, this, &QDialog::reject);
|
|
connect(yes, &QPushButton::clicked, this, &VariableAdd::appendVariable);
|
|
|
|
_io_type->addItems(QStringList()<<u8"输入"<<u8"输出");
|
|
_data_type->addItems(_bind_node->getKernal()->dataTypes());
|
|
}
|
|
|
|
void VariableAdd::appendVariable()
|
|
{
|
|
auto iotype = this->_io_type->currentText();
|
|
IO_TYPE typemark = IO_TYPE::INPUT;
|
|
if(iotype == u8"输出")
|
|
typemark = IO_TYPE::OUTPUT;
|
|
|
|
auto type_topic = this->_data_type->currentText();
|
|
auto type_o = this->_bind_node->getKernal()->getData(type_topic);
|
|
auto type_def = std::dynamic_pointer_cast<TopicData>(type_o->newDefault());
|
|
this->_bind_node->setVariable(this->_var_name->text(), typemark, type_def);
|
|
}
|