25 #include <QFormLayout>
27 #include <QTableWidget>
28 #include <QVBoxLayout>
32 #include <ArmarXCore/interface/observers/Complex.h>
33 #include <ArmarXCore/interface/observers/Matrix.h>
34 #include <ArmarXCore/interface/observers/Timestamp.h>
35 #include <ArmarXCore/interface/observers/VariantContainers.h>
54 auto l =
new QVBoxLayout;
55 l->setContentsMargins(0, 0, 0, 0);
62 update(
const VariantDataPtr& p)
override
64 BoolVariantDataPtr
v = BoolVariantDataPtr::dynamicCast(p);
69 label->setText(
v->b ?
"true" :
"false");
72 label->setText(
v->b ?
"True" :
"False");
75 label->setText(
v->b ?
"TRUE" :
"FALSE");
78 label->setText(
v->b ?
"1" :
"0");
81 label->setText(
v->b ?
"X" :
"O");
84 label->setText(
v->b ?
"X" :
" ");
94 BoolVariantData::ice_staticId()};
101 auto l =
new QVBoxLayout;
102 l->setContentsMargins(0, 0, 0, 0);
111 DoubleVariantDataPtr
v = DoubleVariantDataPtr::dynamicCast(p);
113 label->setText(QString::number(
v->d));
120 DoubleVariantData::ice_staticId()};
127 auto l =
new QVBoxLayout;
128 l->setContentsMargins(0, 0, 0, 0);
137 FloatVariantDataPtr
v = FloatVariantDataPtr::dynamicCast(p);
139 label->setText(QString::number(
v->f));
146 FloatVariantData::ice_staticId()};
153 auto l =
new QVBoxLayout;
154 l->setContentsMargins(0, 0, 0, 0);
163 IntVariantDataPtr
v = IntVariantDataPtr::dynamicCast(p);
165 label->setText(QString::number(
v->n));
172 IntVariantData::ice_staticId()};
179 auto l =
new QVBoxLayout;
180 l->setContentsMargins(0, 0, 0, 0);
189 LongVariantDataPtr
v = LongVariantDataPtr::dynamicCast(p);
191 label->setText(QString::number(
v->n));
198 LongVariantData::ice_staticId()};
206 auto l =
new QVBoxLayout;
207 l->setContentsMargins(0, 0, 0, 0);
216 StringVariantDataPtr
v = StringVariantDataPtr::dynamicCast(p);
218 label->setText(QString::fromStdString(
v->s));
225 StringVariantData::ice_staticId()};
232 auto l =
new QVBoxLayout;
233 l->setContentsMargins(0, 0, 0, 0);
242 TimestampBasePtr
v = TimestampBasePtr::dynamicCast(p);
244 label->setText(QString::number(
v->timestamp) + suffix);
252 TimestampBase::ice_staticId()};
259 auto l =
new QFormLayout;
260 l->setContentsMargins(0, 0, 0, 0);
264 l->addRow(
"Real", labelR);
265 l->addRow(
"Imag", labelI);
271 ComplexFloatBasePtr
v = ComplexFloatBasePtr::dynamicCast(p);
273 labelR->setText(QString::number(
v->real));
274 labelI->setText(QString::number(
v->imag));
282 ComplexFloatBase::ice_staticId()};
289 auto l =
new QFormLayout;
290 l->setContentsMargins(0, 0, 0, 0);
294 l->addRow(
"Real", labelR);
295 l->addRow(
"Imag", labelI);
301 ComplexDoubleBasePtr
v = ComplexDoubleBasePtr::dynamicCast(p);
303 labelR->setText(QString::number(
v->real));
304 labelI->setText(QString::number(
v->imag));
312 ComplexDoubleBase::ice_staticId()};
319 auto l =
new QVBoxLayout;
320 l->setContentsMargins(0, 0, 0, 0);
322 table =
new QTableWidget;
329 MatrixDoubleBasePtr
v = MatrixDoubleBasePtr::dynamicCast(p);
331 table->setRowCount(
v->rows);
332 table->setColumnCount(
v->cols);
333 for (
int row = 0; row <
v->rows; ++row)
335 for (
int col = 0; col <
v->cols; ++col)
337 int i = row + col *
v->rows;
338 table->setItem(row, col,
new QTableWidgetItem{QString::number(
v->data.at(i))});
347 MatrixDoubleBase::ice_staticId()};
354 auto l =
new QVBoxLayout;
355 l->setContentsMargins(0, 0, 0, 0);
357 table =
new QTableWidget;
364 MatrixFloatBasePtr
v = MatrixFloatBasePtr::dynamicCast(p);
366 table->setRowCount(
v->rows);
367 table->setColumnCount(
v->cols);
368 for (
int row = 0; row <
v->rows; ++row)
370 for (
int col = 0; col <
v->cols; ++col)
372 int i = row + col *
v->rows;
373 table->setItem(row, col,
new QTableWidgetItem{QString::number(
v->data.at(i))});
382 MatrixFloatBase::ice_staticId()};
395 VariantWidget::reset(Mode newMode)
397 if (mode != Mode::Empty)
400 while (QLayoutItem* item = l->takeAt(0))
402 QWidget* widget = item->widget();
405 widget->deleteLater();
412 if (mode == Mode::Map)
414 l->setHorizontalSpacing(6);
418 l->setHorizontalSpacing(0);
425 if (mode != Mode::SingleEntry)
427 reset(Mode::SingleEntry);
429 updateEntry(
"SingleEntry",
v);
435 if (mode != Mode::Vector)
439 for (std::size_t i = 0; i < vec.size(); ++i)
448 if (mode != Mode::Map)
452 for (
const auto& entry : map)
454 updateEntry(entry.first, entry.second);
459 VariantWidget::updateEntry(
const std::string& name,
const VariantBasePtr&
v)
462 if (entries.count(name))
465 VariantDataWidgetBase* entryOld = entries.at(name);
469 if (mode == Mode::Map)
472 auto label = l->labelForField(entryOld);
473 l->removeWidget(label);
474 label->deleteLater();
476 l->removeWidget(entryOld);
477 entryOld->deleteLater();
483 std::string type =
v->data->ice_id();
484 if (entryOld->getTypeName() != type)
489 int row = getEntryRow(entryOld);
492 l->removeWidget(entryOld);
493 entryOld->deleteLater();
494 l->setWidget(row, QFormLayout::FieldRole, entries[name]);
499 entryOld->update(
v->data);
507 if (mode == Mode::Map)
509 l->addRow(QString::fromStdString(name), entries[name]);
513 l->addRow(
"", entries[name]);
519 VariantWidget::getEntryRow(VariantWidget::VariantDataWidgetBase* entry)
const
523 for (
int row = 0; row < l->rowCount(); ++row)
525 QLayoutItem* it = l->itemAt(row, QFormLayout::FieldRole);
526 if (it && it->widget() == entry)
534 VariantDataWidgets::VariantDataWidgetBase*
540 ErrorMessageWidget(
const std::string& errorMessage)
542 setLayout(
new QVBoxLayout);
544 layout()->setContentsMargins(0, 0, 0, 0);
545 QLabel* label =
new QLabel{QString::fromStdString(errorMessage)};
546 layout()->addWidget(label);
547 label->setStyleSheet(
"QLabel { background-color : yellow; color : red; }");
553 return new ErrorMessageWidget{
"Null VariantBasePtr"};
557 return new ErrorMessageWidget{
"Null VariantBasePtr::data"};
559 auto type = p->data->ice_id();
560 if (VariantDataWidgetFactory::has(type))
568 catch (std::exception& e)
570 return new ErrorMessageWidget{
"VariantDataWidgetFactory for " + type +
571 " threw exception\n" + e.what()};
575 return new ErrorMessageWidget{
"VariantDataWidgetFactory for " + type +
581 return new ErrorMessageWidget{
"No VariantDataWidgetFactory for " + type};
583 return new ErrorMessageWidget{
"makeVariantDataWidget: Unknown error"};