54 const std::vector<std::string>& providers,
56 QDialog(parent), coreSegmentID(
std::make_unique<
armem::MemoryID>(providerSegmentID))
59 QWidget* activeProviderWidget =
nullptr;
61 if (providers.empty())
63 ARMARX_INFO <<
"No providers available. Will use free text.";
64 _providerSegmentName = new QLineEdit(this);
66 _providerSegmentName->setText(
67 QString::fromStdString(providerSegmentID.providerSegmentName));
69 activeProviderWidget = _providerSegmentName;
73 ARMARX_INFO <<
"Providers available. Will use dropdown list.";
75 _providerSegmentNameSelection = new QComboBox(this);
78 for (const auto& provider : providers)
80 _providerSegmentNameSelection->addItem(QString::fromStdString(provider));
86 _providerSegmentNameSelection->setCurrentText(
87 QString::fromStdString(providerSegmentID.providerSegmentName));
89 activeProviderWidget = _providerSegmentNameSelection;
93 _entityName =
new QLineEdit(
this);
95 _buttonBox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
this);
98 new QLabel(
"Enter provider segment name and entity name for new entity:");
99 QFont font = instruction->font();
101 instruction->setFont(font);
103 QGridLayout* grid =
new QGridLayout();
106 grid->addWidget(
new QLabel(
"Core Segment ID"), 0, col);
108 new QLabel(QString::fromStdString(providerSegmentID.getCoreSegmentID().str()) +
"/"),
113 grid->addWidget(
new QLabel(
"Provider Segment Name"), 0, col);
115 grid->addWidget(activeProviderWidget, 1, col);
118 grid->addWidget(
new QLabel(
"/"), 1, col);
121 grid->addWidget(
new QLabel(
"Entity Name"), 0, col);
122 grid->addWidget(_entityName, 1, col);
126 QVBoxLayout* layout =
new QVBoxLayout();
128 layout->addWidget(instruction);
129 layout->addLayout(grid);
130 layout->addWidget(_buttonBox);
133 connect(_buttonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept);
134 connect(_buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject);
136 auto enableOkIfReady = [
this]()
138 bool hasValidProviderName =
false;
139 if (_providerSegmentNameSelection !=
nullptr)
141 hasValidProviderName =
true;
144 if (_providerSegmentName !=
nullptr)
146 hasValidProviderName = not _providerSegmentName->text().isEmpty();
149 const bool hasEntity = not _entityName->text().isEmpty();
151 _buttonBox->button(QDialogButtonBox::Ok)
152 ->setEnabled(hasValidProviderName and hasEntity);
155 if (_providerSegmentName !=
nullptr)
157 connect(_providerSegmentName, &QLineEdit::textChanged,
this, enableOkIfReady);
160 connect(_entityName, &QLineEdit::textChanged,
this, enableOkIfReady);