25 #include <QFileDialog>
37 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/ui_ProfileDefaultValueEditWidget.h>
49 typeString(typeString),
51 communicator(communicator),
56 QLineEdit* lineEdit =
new QLineEdit;
57 ui->value->insertWidget(eLineEdit, lineEdit);
59 QPushButton* editButton =
new QPushButton(
"Edit");
60 ui->value->insertWidget(eEditButton, editButton);
61 connect(editButton, SIGNAL(clicked()),
this, SLOT(editDefaultButtonClicked()));
63 QPushButton* setButton =
new QPushButton(
"Click to set");
64 setButton->setStyleSheet(
"color: #888;");
65 setButton->setFlat(
true);
66 ui->value->insertWidget(eSetButton, setButton);
67 connect(setButton, SIGNAL(clicked()),
this, SLOT(setButtonClicked()));
73 lineEdit->setValidator(NULL);
79 QValidator* validator =
new QRegExpValidator(rx,
this);
80 lineEdit->setValidator(validator);
84 QRegExp rx(
"(true|false)");
85 QValidator* validator =
new QRegExpValidator(rx,
this);
86 lineEdit->setValidator(validator);
92 QRegExp rx(
"-?\\d+(\\.\\d+)?([eE][+-]?\\d+)?");
93 QValidator* validator =
new QRegExpValidator(rx,
this);
94 lineEdit->setValidator(validator);
97 if (jsonValue.isEmpty())
99 lineEdit->setText(
"");
104 typeString.toUtf8().data()));
105 std::string compressedValue =
107 lineEdit->setText(QString::fromUtf8(compressedValue.c_str()));
111 connect(ui->pushButtonDelete, SIGNAL(clicked()),
this, SLOT(resetValue()));
113 if (jsonValue.size() == 0)
136 this->editable = editable;
137 ui->value->widget(eLineEdit)->setEnabled(editable);
140 std::optional<QString>
143 if (ui->value->currentIndex() == Widget::eLineEdit)
145 return qobject_cast<QLineEdit*>(ui->value->currentWidget())->text();
147 else if (ui->value->currentIndex() == Widget::eEditButton)
155 std::optional<QString>
159 int index = ui->value->currentIndex();
161 if (
index == Widget::eEditButton)
165 else if (
index == Widget::eLineEdit)
167 QLineEdit* valueEdit = qobject_cast<QLineEdit*>(ui->value->currentWidget());
169 valueEdit->text().toUtf8().data(), typeString.toStdString());
170 return QString::fromUtf8(verboseJson.c_str());
176 VariantContainerBasePtr
179 VariantContainerBasePtr result;
181 if (ui->value->currentIndex() == eLineEdit)
183 QLineEdit* valueEdit = qobject_cast<QLineEdit*>(ui->value->currentWidget());
189 variant.
setInt(valueEdit->text().toInt());
193 variant.
setLong(valueEdit->text().toLong());
197 variant.
setBool(valueEdit->text().compare(
"true", Qt::CaseInsensitive) == 0 ||
198 valueEdit->text() ==
"1");
202 variant.
setFloat(valueEdit->text().toFloat());
206 variant.
setDouble(valueEdit->text().toDouble());
210 variant.
setString(valueEdit->text().trimmed().toStdString());
215 else if (ui->value->currentIndex() == eEditButton)
217 if (jsonValue.isEmpty())
224 jsonObject->fromString(jsonValue.toUtf8().data());
228 SerializablePtr obj = jsonObject->deserializeIceObject();
229 result = VariantContainerBasePtr::dynamicCast(obj);
237 catch (std::exception& e)
240 <<
" could not be deserialized: " << e.what();
249 ProfileDefaultValueEditWidget::resetValue()
253 ui->value->setCurrentIndex(eSetButton);
254 ui->pushButtonDelete->setEnabled(
false);
255 ui->pushButtonDelete->hide();
258 auto lineEdit = qobject_cast<QLineEdit*>(ui->value->widget(eLineEdit));
259 lineEdit->setText(
"");
263 ProfileDefaultValueEditWidget::setButtonClicked()
265 ui->pushButtonDelete->setEnabled(
true);
266 ui->pushButtonDelete->show();
273 ui->value->setCurrentIndex(eLineEdit);
278 ui->value->setCurrentIndex(eEditButton);
283 ProfileDefaultValueEditWidget::initEditButton()
287 if (jsonValue.isEmpty())
295 Ice::ValueFactoryPtr factory =
296 communicator->getValueFactoryManager()->find(variantContainerType->typeId);
301 << variantContainerType->typeId;
306 Ice::ValuePtr valPtr = factory->create(variantContainerType->typeId);
307 ARMARX_INFO_S << valPtr.get() <<
" " << SerializablePtr::dynamicCast(valPtr).get();
309 VariantContainerBasePtr container = VariantContainerBasePtr::dynamicCast(valPtr);
315 Ice::ValueFactoryPtr subfactory = communicator->getValueFactoryManager()->find(
316 variantContainerType->subType->typeId);
321 subfactory = IceInternal::factoryTable->getValueFactory(
322 variantContainerType->subType->typeId);
327 Ice::ValuePtr subObj =
328 subfactory->create(variantContainerType->subType->typeId);
329 VariantDataPtr var = VariantDataPtr::dynamicCast(subObj);
332 SingleTypeVariantListPtr::dynamicCast(valPtr);
343 map->addVariant(
"mykey",
Variant(var));
356 jsonObject->serializeIceObject(container);
359 jsonValue = QString::fromStdString(jsonObject->asString(
true));
365 ui->value->widget(eEditButton)->setEnabled(
false);
370 ProfileDefaultValueEditWidget::editDefaultButtonClicked()
373 if (d.exec() == QDialog::Accepted)
375 jsonValue = d.getJson();