25 #include <ArmarXGui/interface/WidgetDescription.h>
32 #include <QVBoxLayout>
33 #include <QHBoxLayout>
35 #include <QSpacerItem>
36 #include <QFormLayout>
37 #include <QDoubleSpinBox>
42 #include <QDoubleValidator>
45 #include <QStandardItemModel>
46 #include <QStyledItemDelegate>
48 #pragma GCC diagnostic push
49 #pragma GCC diagnostic ignored "-Wpedantic"
50 #include <qwt_slider.h>
53 #pragma GCC diagnostic pop
74 VBoxLayoutPtr ptr = VBoxLayoutPtr::dynamicCast(p);
76 setLayout(
new QVBoxLayout);
77 layout()->setContentsMargins(0, 0, 0, 0);
78 for (
const WidgetPtr& childPtr : ptr->children)
80 layout()->addWidget(
addChild(childPtr));
93 HBoxLayoutPtr ptr = HBoxLayoutPtr::dynamicCast(p);
95 setLayout(
new QHBoxLayout);
96 layout()->setContentsMargins(0, 0, 0, 0);
97 for (
const WidgetPtr& childPtr : ptr->children)
99 layout()->addWidget(
addChild(childPtr));
111 FormLayoutPtr ptr = FormLayoutPtr::dynamicCast(p);
113 auto l =
new QFormLayout;
115 layout()->setContentsMargins(0, 0, 0, 0);
116 for (
const FormLayoutElementPtr& child : ptr->children)
118 if (child->childIsSpanning)
123 if (child->labelWidget)
128 l->addRow(QString::fromStdString(child->label),
addChild(child->child));
140 FormLayoutElementPtr ptr = FormLayoutElementPtr::dynamicCast(p);
142 auto l =
new QFormLayout;
144 layout()->setContentsMargins(0, 0, 0, 0);
145 if (ptr->childIsSpanning)
149 if (ptr->labelWidget)
153 l->addRow(QString::fromStdString(ptr->label),
addChild(ptr->child));
164 GroupBoxPtr ptr = GroupBoxPtr::dynamicCast(p);
166 auto ltop =
new QHBoxLayout;
168 layout()->setContentsMargins(0, 0, 0, 0);
169 QGroupBox* grp =
new QGroupBox;
170 ltop->addWidget(grp);
171 grp->setTitle(QString::fromStdString(ptr->label));
172 auto l =
new QHBoxLayout;
174 l->setContentsMargins(0, 9, 0, 0);
186 setLayout(
new QVBoxLayout);
187 layout()->setContentsMargins(0, 0, 0, 0);
188 layout()->addItem(
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
202 setLayout(
new QVBoxLayout);
203 layout()->setContentsMargins(0, 0, 0, 0);
204 layout()->addItem(
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
218 setFrameShape(QFrame::HLine);
219 setFrameShadow(QFrame::Sunken);
233 setFrameShape(QFrame::VLine);
234 setFrameShadow(QFrame::Sunken);
248 auto ptr = LabelPtr::dynamicCast(p);
250 setLayout(
new QVBoxLayout);
251 layout()->setContentsMargins(0, 0, 0, 0);
252 layout()->addWidget(
new QLabel(QString::fromStdString(ptr->text)));
267 auto ptr = VariantWidgetPtr::dynamicCast(p);
270 setLayout(
new QVBoxLayout);
272 layout()->setContentsMargins(0, 0, 0, 0);
273 layout()->addWidget(child);
285 else if (
data->ice_id() == VariantWidgetContent::SingleVariant::ice_staticId())
287 child->
update(VariantWidgetContent::SingleVariantPtr::dynamicCast(
data)->content);
289 else if (
data->ice_id() == VariantWidgetContent::VariantMap::ice_staticId())
291 child->
update(VariantWidgetContent::VariantMapPtr::dynamicCast(
data)->content);
293 else if (
data->ice_id() == VariantWidgetContent::VariantSeq::ice_staticId())
295 child->
update(VariantWidgetContent::VariantSeqPtr::dynamicCast(
data)->content);
309 CheckBoxPtr ptr = CheckBoxPtr::dynamicCast(p);
312 setLayout(
new QVBoxLayout);
313 layout()->setContentsMargins(0, 0, 0, 0);
314 child =
new QCheckBox {QString::fromStdString(ptr->label)};
315 child->setChecked(ptr->defaultValue);
316 layout()->addWidget(child);
317 connect(child, SIGNAL(clicked(
bool)),
this, SLOT(
contentUpdated()));
338 IntSpinBoxPtr ptr = IntSpinBoxPtr::dynamicCast(p);
341 setLayout(
new QVBoxLayout);
342 layout()->setContentsMargins(0, 0, 0, 0);
343 child =
new QSpinBox {};
344 child->setMaximum(ptr->max);
345 child->setMinimum(ptr->min);
346 child->setValue(ptr->defaultValue);
347 layout()->addWidget(child);
348 connect(child, SIGNAL(valueChanged(
int)),
this, SLOT(
contentUpdated()));
369 DoubleSpinBoxPtr ptr = DoubleSpinBoxPtr::dynamicCast(p);
372 setLayout(
new QVBoxLayout);
373 layout()->setContentsMargins(0, 0, 0, 0);
374 child =
new QDoubleSpinBox {};
375 child->setMaximum(ptr->max);
376 child->setMinimum(ptr->min);
377 child->setDecimals(ptr->decimals);
378 child->setValue(ptr->defaultValue);
379 child->setSingleStep((ptr->max - ptr->min) / ptr->steps);
380 layout()->addWidget(child);
381 connect(child, SIGNAL(valueChanged(
double)),
this, SLOT(
contentUpdated()));
388 QDoubleSpinBox* child;
402 FloatSpinBoxPtr ptr = FloatSpinBoxPtr::dynamicCast(p);
405 setLayout(
new QVBoxLayout);
406 layout()->setContentsMargins(0, 0, 0, 0);
407 child =
new QDoubleSpinBox {};
408 child->setMaximum(ptr->max);
409 child->setMinimum(ptr->min);
410 child->setDecimals(ptr->decimals);
411 child->setValue(ptr->defaultValue);
412 child->setSingleStep((ptr->max - ptr->min) / ptr->steps);
413 layout()->addWidget(child);
414 connect(child, SIGNAL(valueChanged(
double)),
this, SLOT(
contentUpdated()));
418 return {{
getName(),
new Variant(
static_cast<float>(child->value()))}};
421 QDoubleSpinBox* child;
434 void paint(QPainter* painter_,
const QStyleOptionViewItem& option_,
const QModelIndex& index_)
const override
436 QStyleOptionViewItem& refToNonConstOption =
const_cast<QStyleOptionViewItem&
>(option_);
437 refToNonConstOption.showDecorationSelected =
false;
440 QStyledItemDelegate::paint(painter_, refToNonConstOption, index_);
449 StringComboBoxPtr ptr = StringComboBoxPtr::dynamicCast(p);
452 setLayout(
new QVBoxLayout);
453 layout()->setContentsMargins(0, 0, 0, 0);
454 child =
new QComboBox {};
455 multiSelect = ptr->multiSelect;
458 model =
new QStandardItemModel(ptr->options.size() + 1, 1);
459 QStandardItem* item =
new QStandardItem(
"Please select items");
460 item->setFlags(Qt::NoItemFlags);
461 model->setItem(0, 0, item);
464 for (
const auto& opt : ptr->options)
466 QStandardItem* item =
new QStandardItem(QString::fromStdString(opt));
468 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
469 item->setData(Qt::Unchecked, Qt::CheckStateRole);
471 model->setItem(row, 0, item);
475 model->setParent(child);
476 child->setModel(model);
478 child->setItemDelegate(delegate);
479 child->setCurrentIndex(-1);
483 for (
const auto& opt : ptr->options)
485 child->addItem(QString::fromStdString(opt));
488 child->setCurrentIndex(child->findText(QString::fromStdString(ptr->options.at(ptr->defaultIndex))));
490 layout()->addWidget(child);
492 connect(child, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
contentUpdated()));
499 for (
int i = 0; i < child->model()->rowCount(); ++i)
501 if (model->item(i)->checkState() == Qt::Checked)
504 list->addVariant(child->itemText(i).toStdString());
512 return {{
getName(),
new Variant{child->currentText().toStdString()}}};
516 QPointer<QStandardItemModel> model =
nullptr;
518 bool multiSelect =
false;
532 LineEditPtr ptr = LineEditPtr::dynamicCast(p);
535 setLayout(
new QVBoxLayout);
536 layout()->setContentsMargins(0, 0, 0, 0);
537 child =
new QLineEdit {};
538 child->setText(QString::fromStdString(ptr->defaultValue));
539 layout()->addWidget(child);
540 connect(child, SIGNAL(editingFinished()),
this, SLOT(
contentUpdated()));
561 DoubleLineEditPtr ptr = DoubleLineEditPtr::dynamicCast(p);
564 setLayout(
new QVBoxLayout);
565 layout()->setContentsMargins(0, 0, 0, 0);
566 child =
new QLineEdit {};
567 child->setText(QString::number(ptr->defaultValue));
568 child->setValidator(
new QDoubleValidator {
this});
569 layout()->addWidget(child);
570 connect(child, SIGNAL(editingFinished()),
this, SLOT(
contentUpdated()));
591 FloatLineEditPtr ptr = FloatLineEditPtr::dynamicCast(p);
594 setLayout(
new QVBoxLayout);
595 layout()->setContentsMargins(0, 0, 0, 0);
596 child =
new QLineEdit {};
597 child->setText(QString::number(ptr->defaultValue));
598 child->setValidator(
new QDoubleValidator {
this});
599 layout()->addWidget(child);
600 connect(child, SIGNAL(editingFinished()),
this, SLOT(
contentUpdated()));
604 return {{
getName(),
new Variant{
static_cast<float>(child->text().toDouble())}}};
622 IntSliderPtr ptr = IntSliderPtr::dynamicCast(p);
625 setLayout(
new QVBoxLayout);
626 layout()->setContentsMargins(0, 0, 0, 0);
627 child =
new QSlider {};
628 child->setMaximum(ptr->max);
629 child->setMinimum(ptr->min);
630 child->setValue(ptr->defaultValue);
631 layout()->addWidget(child);
632 connect(child, SIGNAL(valueChanged(
int)),
this, SLOT(
contentUpdated()));
653 DoubleSliderPtr ptr = DoubleSliderPtr::dynamicCast(p);
656 setLayout(
new QVBoxLayout);
657 layout()->setContentsMargins(0, 0, 0, 0);
658 child =
new QwtSlider {
this};
659 child->setScale(ptr->min, ptr->max);
660 child->setOrientation(Qt::Horizontal);
661 child->setValue(ptr->defaultValue);
662 doubleLabel =
new QLabel(QString::number(ptr->defaultValue,
'g', 4),
this);
663 layout()->addWidget(child);
664 connect(child, SIGNAL(valueChanged(
double)),
this, SLOT(
contentUpdated()));
676 doubleLabel->setText(QString::number(child->value(),
'g', 4));
687 FloatSliderPtr ptr = FloatSliderPtr::dynamicCast(p);
690 setLayout(
new QHBoxLayout);
691 layout()->setContentsMargins(0, 0, 0, 0);
692 child =
new QwtSlider {
this};
693 child->setScale(ptr->min, ptr->max);
694 child->setOrientation(Qt::Horizontal);
695 child->setValue(ptr->defaultValue);
696 floatLabel =
new QLabel(QString::number(ptr->defaultValue,
'g', 4),
this);
697 layout()->addWidget(child);
698 layout()->addWidget(floatLabel);
699 connect(child, SIGNAL(valueChanged(
double)),
this, SLOT(
contentUpdated()));
703 return {{
getName(),
new Variant(
static_cast<float>(child->value()))}};
711 floatLabel->setText(QString::number(child->value(),
'g', 4));
722 std::map<std::string, VariantBasePtr> result;
749 setLayout(
new QVBoxLayout);
750 setName(
".ErrorMessageWidget");
751 layout()->setContentsMargins(0, 0, 0, 0);
752 QLabel* label =
new QLabel {QString::fromStdString(errorMessage)};
753 layout()->addWidget(label);
754 label->setStyleSheet(
"QLabel { background-color : yellow; color : red; }");
760 return new ErrorMessageWidget {
"Null WidgetPtr"};
762 auto type = p->ice_id();
770 QObject::connect(w, SIGNAL(valueChangedSignal(std::string,
VariantBasePtr)), listener, SLOT(valueChangedSlot(std::string,
VariantBasePtr)));
774 catch (std::exception& e)
776 return new ErrorMessageWidget {
"DescribedWidgetFactory for " + type +
" threw exception\n" + e.what()};
780 return new ErrorMessageWidget {
"DescribedWidgetFactory for " + type +
" threw exception"};
785 return new ErrorMessageWidget {
"No DescribedWidgetFactory for " + type};
787 return new ErrorMessageWidget {
"makeDescribedWidget: Unknown error"};
792 if (ptr && ptr->framed)
794 setFrameShape(QFrame::StyledPanel);
800 setFrameShape(QFrame::NoFrame);
801 setFrameShadow(QFrame::Raised);