diff --git a/source/RobotAPI/libraries/skills_gui/CMakeLists.txt b/source/RobotAPI/libraries/skills_gui/CMakeLists.txt index fc814c041b943c66c9486f45d074f5fed4ff764e..e0c518a468b90a948fe79b4babade9ccc797434b 100644 --- a/source/RobotAPI/libraries/skills_gui/CMakeLists.txt +++ b/source/RobotAPI/libraries/skills_gui/CMakeLists.txt @@ -7,6 +7,7 @@ armarx_set_target("Library: ${LIB_NAME}") set(LIBRARIES ArmarXCore ArmarXCoreInterfaces + ArmarXGuiBase RobotAPISkillsCore RobotAPISkillsManager RobotAPIInterfaces @@ -61,7 +62,6 @@ set(SOURCES skill_details/ProfileMenuWidget.cpp skill_details/SkillDetailsTreeWidget.cpp - PeriodicUpdateWidget.cpp SkillMemoryGui.cpp gui_utils.cpp StatusLabel.cpp @@ -104,7 +104,6 @@ set(HEADERS skill_details/ProfileMenuWidget.h skill_details/SkillDetailsTreeWidget.h - PeriodicUpdateWidget.h SkillMemoryGui.h gui_utils.h StatusLabel.h diff --git a/source/RobotAPI/libraries/skills_gui/PeriodicUpdateWidget.cpp b/source/RobotAPI/libraries/skills_gui/PeriodicUpdateWidget.cpp deleted file mode 100644 index b2274864b4b9b14630202a7005767cbc614fe9b1..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/skills_gui/PeriodicUpdateWidget.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#include "PeriodicUpdateWidget.h" - -#include <cmath> - -#include <QCheckBox> -#include <QDoubleSpinBox> -#include <QHBoxLayout> -#include <QPushButton> -#include <QTimer> - -namespace armarx::skills::gui -{ - PeriodicUpdateWidget::PeriodicUpdateWidget(double frequency, double maxFrequency) - { - setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Minimum); - - QLayout* vlayout = new QVBoxLayout(); - QLayout* hlayout = new QHBoxLayout(); - this->setLayout(vlayout); - - const int margin = 0; - hlayout->setContentsMargins(margin, margin, margin, margin); - - _updateButton = new QPushButton("Update", this); - _autoCheckBox = new QCheckBox("Auto Update", this); - _frequencySpinBox = new QDoubleSpinBox(this); - _frequencySpinBox->setValue(frequency); - _frequencySpinBox->setMinimum(0); - _frequencySpinBox->setMaximum(maxFrequency); - _frequencySpinBox->setSingleStep(0.5); - _frequencySpinBox->setSuffix(" Hz"); - - hlayout->addWidget(_updateButton); - hlayout->addWidget(_autoCheckBox); - hlayout->addWidget(_frequencySpinBox); - - vlayout->addItem(hlayout); - - - _timer = new QTimer(this); - _updateTimerFrequency(); - _frequencySpinBox->setEnabled(_autoCheckBox->isChecked()); - - - // Private connections. - connect(_autoCheckBox, &QCheckBox::toggled, this, &This::_toggleAutoUpdates); - connect(_frequencySpinBox, - &QDoubleSpinBox::editingFinished, - this, - &This::_updateTimerFrequency); - - // Public connections. - connect(_updateButton, &QPushButton::pressed, this, &This::updateSingle); - connect(_timer, &QTimer::timeout, this, &This::updatePeriodic); - - connect(this, &This::updateSingle, this, &This::update); - connect(this, &This::updatePeriodic, this, &This::update); - - // See `startTimerIfEnabled` for the signal reasoning. - // qOverload is required because `QTimer::start()` is overloaded. - connect(this, &This::startTimerSignal, _timer, qOverload<>(&QTimer::start)); - connect(this, &This::stopTimerSignal, _timer, &QTimer::stop); - } - - QPushButton* - PeriodicUpdateWidget::updateButton() - { - return _updateButton; - } - - int - PeriodicUpdateWidget::getUpdateIntervalMs() const - { - return static_cast<int>(std::round(1000 / _frequencySpinBox->value())); - } - - void - PeriodicUpdateWidget::startTimerIfEnabled() - { - /* A QTimer can only be started and stopped within its own thread (the thread for which - * it has the greatest affinity). Since this method can be called from any thread, we - * need to take a detour through these signals, which can be emitted from any thread and - * will always be caught in this object's (and thus the timer's) native thread. - */ - if (_autoCheckBox->isChecked()) - { - emit startTimerSignal(); - } - else - { - emit stopTimerSignal(); - } - } - - void - PeriodicUpdateWidget::stopTimer() - { - // See `startTimerIfEnabled` for the signal reasoning. - emit stopTimerSignal(); - } - - void - PeriodicUpdateWidget::_updateTimerFrequency() - { - _timer->setInterval(getUpdateIntervalMs()); - } - - void - PeriodicUpdateWidget::_toggleAutoUpdates(bool enabled) - { - // This method is already a slot, so it doesn't need to use the timer signals. - _frequencySpinBox->setEnabled(enabled); - if (enabled) - { - _timer->start(); - } - else - { - _timer->stop(); - } - } - - QCheckBox* - PeriodicUpdateWidget::autoCheckBox() - { - return _autoCheckBox; - } - - QDoubleSpinBox* - PeriodicUpdateWidget::frequencySpinBox() - { - return _frequencySpinBox; - } - - QTimer* - PeriodicUpdateWidget::timer() - { - return _timer; - } - -} // namespace armarx diff --git a/source/RobotAPI/libraries/skills_gui/PeriodicUpdateWidget.h b/source/RobotAPI/libraries/skills_gui/PeriodicUpdateWidget.h deleted file mode 100644 index e53f1a415d6452208fdbce0ff62628957054c451..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/skills_gui/PeriodicUpdateWidget.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include <QWidget> - - -class QCheckBox; -class QDoubleSpinBox; -class QPushButton; -class QTimer; - -namespace armarx::skills::gui -{ - - class PeriodicUpdateWidget : public QWidget - { - Q_OBJECT - using This = PeriodicUpdateWidget; - - public: - PeriodicUpdateWidget(double frequency = 2.0, double maxFrequency = 60); - - - QTimer* timer(); - - QCheckBox* autoCheckBox(); - QDoubleSpinBox* frequencySpinBox(); - QPushButton* updateButton(); - - bool isAutoEnabled() const; - double getUpdateFrequency() const; - int getUpdateIntervalMs() const; - - void startTimerIfEnabled(); - void stopTimer(); - - - public slots: - - signals: - - void update(); - - void updateSingle(); - void updatePeriodic(); - - private slots: - - void _updateTimerFrequency(); - void _toggleAutoUpdates(bool enabled); - - signals: - - void startTimerSignal(); - void stopTimerSignal(); - - private: - QPushButton* _updateButton; - QCheckBox* _autoCheckBox; - QDoubleSpinBox* _frequencySpinBox; - - QPushButton* _collapseAllButton; - - QTimer* _timer; - }; - -} // namespace armarx diff --git a/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h b/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h index e8962eb867180240b691a49df3c1262ac3fd109f..64361f811ef2251ad679fad0c2efa1395a5aa563 100644 --- a/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h +++ b/source/RobotAPI/libraries/skills_gui/SkillMemoryGui.h @@ -9,9 +9,10 @@ #include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXGui/libraries/ArmarXGuiBase/widgets/PeriodicUpdateWidget.h> + #include "RobotAPI/libraries/skills_gui/StatusLabel.h" -#include "./PeriodicUpdateWidget.h" #include "./aron_tree_widget/widgets/SkillDescriptionWidget.h" #include "./executions/SkillExecutionTreeWidget.h" #include "./memory/SkillManagerWrapper.h"