From e953dae70c14e9bd28f7014ebf1c692162122a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20=C5=81ukawski?= Date: Wed, 24 May 2023 13:12:46 +0200 Subject: [PATCH] Merge `setAlignment` commands Apparently, CPU usage skyrockets whenever these are split. --- doc/release/yarp_3_8/yarpmotorgui_cpu.md | 8 ++++++++ src/yarpmotorgui/sliderWithTarget.cpp | 22 ++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 doc/release/yarp_3_8/yarpmotorgui_cpu.md diff --git a/doc/release/yarp_3_8/yarpmotorgui_cpu.md b/doc/release/yarp_3_8/yarpmotorgui_cpu.md new file mode 100644 index 0000000000..23ed8d29c8 --- /dev/null +++ b/doc/release/yarp_3_8/yarpmotorgui_cpu.md @@ -0,0 +1,8 @@ +yarpmotorgui_cpu {#yarp_3_8} +----------- + +### tools + +#### `yarpmotorgui` + +* Fixed an issue regarding high CPU usage (#2955). diff --git a/src/yarpmotorgui/sliderWithTarget.cpp b/src/yarpmotorgui/sliderWithTarget.cpp index ad5d3b1d9b..c637edaa8a 100644 --- a/src/yarpmotorgui/sliderWithTarget.cpp +++ b/src/yarpmotorgui/sliderWithTarget.cpp @@ -106,31 +106,25 @@ void SliderWithTarget::paintEvent(QPaintEvent *e) double value = this->value(); double newX = ((double)w / (double)totValues) * ((double)value + abs(this->minimum())); QString label_text = QString("%L1").arg((double)value / sliderStep, 0, 'f', number_of_decimals); - int label_text_siz = label_text.size(); sliderCurrentLabel->setText(label_text); - sliderCurrentLabel->setAlignment(Qt::AlignLeft); - sliderCurrentLabel->setAlignment(Qt::AlignVCenter); + sliderCurrentLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); //these adjustment are required to have the label properly aligned and //to avoid overflow - double newX2 = newX; - if (newX2<0) newX2 = 0; - if (newX2>w-30) newX2 = w-30; - sliderCurrentLabel->setGeometry(newX2, -10, 60, 20); + if (newX<0) newX = 0; + if (newX>w-30) newX = w-30; + sliderCurrentLabel->setGeometry(newX, -10, 60, 20); } if (enableViewTargetValue) { double newX = ((double)w / (double)totValues) * ((double)target + abs(this->minimum())); QString label_text = QString("Ref:%L1").arg((double)target, 0, 'f', number_of_decimals); - int label_text_siz = label_text.size(); sliderTargetLabel->setText(label_text); - sliderCurrentLabel->setAlignment(Qt::AlignLeft); - sliderCurrentLabel->setAlignment(Qt::AlignVCenter); + sliderTargetLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); //these adjustment are required to have the label properly aligned and //to avoid overflow - double newX2 = newX; - if (newX2 < 0) newX2 = 0; - if (newX2 > w - 30) newX2 = w - 30; - sliderTargetLabel->setGeometry(newX2, +10, 60, 20); + if (newX < 0) newX = 0; + if (newX > w - 30) newX = w - 30; + sliderTargetLabel->setGeometry(newX, +10, 60, 20); } else {