MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / tryAdaptCheckBox

Function tryAdaptCheckBox

pj_dialog_host/src/widget_adapters.cpp:419–459  ·  view source on GitHub ↗

Replace a plain QCheckBox with a labelled ToggleSwitch (label on the LEFT, switch on the right). The checkbox is kept hidden+alive so plugin data and the connectWidgetSignals event callback keep flowing through it; the toggle just drives it. No-op for tristate / textless / composite-internal / already adapted checkboxes.

Source from the content-addressed store, hash-verified

417// just drives it. No-op for tristate / textless / composite-internal / already
418// adapted checkboxes.
419static bool tryAdaptCheckBox(QCheckBox* checkbox) {
420 if (checkbox == nullptr || pairedToggleSwitch(checkbox) != nullptr) {
421 return false;
422 }
423 if (checkbox->isTristate() || checkbox->text().isEmpty()) {
424 return false;
425 }
426 QWidget* parent = checkbox->parentWidget();
427 if (parent == nullptr || parent->layout() == nullptr || isInsideHostComposite(checkbox)) {
428 return false;
429 }
430
431 auto* toggle = new ToggleSwitch(parent);
432 toggle->setText(checkbox->text());
433 toggle->setLabelSide(ToggleSwitch::LabelSide::Left);
434 toggle->setToolTip(checkbox->toolTip());
435 toggle->setEnabled(checkbox->isEnabled());
436 toggle->setChecked(checkbox->isChecked(), /*animate=*/false);
437
438 if (!replaceWidgetInLayout(parent, checkbox, toggle)) {
439 delete toggle;
440 return false;
441 }
442 checkbox->setProperty(kToggleSwitchProperty, QVariant::fromValue<QObject*>(toggle));
443 checkbox->setProperty(kToggleDesiredVisibleProperty, !checkbox->isHidden());
444 toggle->setProperty(kToggleCheckBoxProperty, QVariant::fromValue<QObject*>(checkbox));
445 checkbox->hide();
446
447 const QPointer<QCheckBox> cb_ptr(checkbox);
448 QObject::connect(toggle, &ToggleSwitch::toggled, toggle, [cb_ptr](bool checked) {
449 if (cb_ptr != nullptr) {
450 cb_ptr->setChecked(checked);
451 }
452 });
453 QObject::connect(checkbox, &QCheckBox::toggled, toggle, [checkbox, toggle](bool checked) {
454 const QSignalBlocker blocker(toggle);
455 toggle->setChecked(checked, /*animate=*/false);
456 checkbox->hide();
457 });
458 return true;
459}
460
461// --- QTableView interior-only cell grid --------------------------------------
462

Callers 2

adaptCheckBoxesFunction · 0.85
tryAdaptStyledWidgetFunction · 0.85

Calls 13

pairedToggleSwitchFunction · 0.85
isInsideHostCompositeFunction · 0.85
replaceWidgetInLayoutFunction · 0.85
setLabelSideMethod · 0.80
isEmptyMethod · 0.45
textMethod · 0.45
parentWidgetMethod · 0.45
setTextMethod · 0.45
setEnabledMethod · 0.45
isEnabledMethod · 0.45
setCheckedMethod · 0.45
isCheckedMethod · 0.45

Tested by

no test coverage detected