MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / CustomNodeDialog

Method CustomNodeDialog

bt_editor/custom_node_dialog.cpp:10–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <QModelIndexList>
9
10CustomNodeDialog::CustomNodeDialog(const NodeModels &models,
11 QString to_edit,
12 QWidget *parent):
13 QDialog(parent),
14 ui(new Ui::CustomNodeDialog),
15 _models(models),
16 _editing(false)
17{
18 ui->setupUi(this);
19 setWindowTitle("Custom TreeNode Editor");
20
21 ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive);
22 ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
23 ui->tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Interactive);
24 ui->tableWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
25
26 QSettings settings;
27 restoreGeometry(settings.value("CustomNodeDialog/geometry").toByteArray());
28 ui->tableWidget->horizontalHeader()->restoreState( settings.value("CustomNodeDialog/header").toByteArray() );
29
30 if( to_edit.isEmpty() == false)
31 {
32 auto model_it = models.find(to_edit);
33 if( model_it != models.end())
34 {
35 _editing =true;
36 ui->lineEdit->setText( to_edit );
37
38 const auto& model = model_it->second;
39 for( const auto& port_it : model.ports )
40 {
41 int row = ui->tableWidget->rowCount();
42 ui->tableWidget->setRowCount(row+1);
43
44 ui->tableWidget->setItem(row,0, new QTableWidgetItem(port_it.first) );
45 QComboBox* combo_direction = new QComboBox;
46 combo_direction->addItem("Input");
47 combo_direction->addItem("Output");
48 combo_direction->addItem("In/Out");
49 switch( port_it.second.direction )
50 {
51 case BT::PortDirection::INPUT : combo_direction->setCurrentIndex(0); break;
52 case BT::PortDirection::OUTPUT: combo_direction->setCurrentIndex(1); break;
53 case BT::PortDirection::INOUT : combo_direction->setCurrentIndex(2); break;
54 }
55
56 ui->tableWidget->setCellWidget(row,1, combo_direction );
57 ui->tableWidget->setItem(row,2, new QTableWidgetItem(port_it.second.default_value) );
58 ui->tableWidget->setItem(row,3, new QTableWidgetItem(port_it.second.description) );
59 }
60
61 if( model.type == NodeType::ACTION )
62 {
63 ui->comboBox->setCurrentIndex(0);
64 }
65 else if( model.type == NodeType::CONDITION )
66 {
67 ui->comboBox->setCurrentIndex(1);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected