kernelshark: fix bug in the behavior of ksglwidget rubber band
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 kernelshark: fix bug in the behavior of ksglwidget rubber band
Accidentally pressing right mouse button while dragging the range will cause the rubber band to behave abnormally. Improved the logic behind range dragging to account for this case. The state of the rubber band will be reset on right click.
--- src/KsGLWidget.cpp | 40 +++++++++++++++++++++++++++------------- src/KsGLWidget.hpp | 2 ++ 2 files changed, 29 insertions(+), 13 deletions(-)
src/KsGLWidget.cpp +27 -13
@@ -190,6 +190,9 @@ void KsGLWidget::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { _posMousePress = _posInRange(event->pos().x()); _rangeBoundInit(_posMousePress); + } else if (event->button() == Qt::RightButton) { + if (_rubberBand.isVisible()) + _rangeBoundCancel(); } }
@@ -262,8 +265,10 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event) if (isEmpty()) return; - if (_rubberBand.isVisible()) - _rangeBoundStretched(_posInRange(event->pos().x())); + if (_rubberBand.isVisible()) { + size_t posMouseRel = _posInRange(event->pos().x()); + _rangeBoundStretched(posMouseRel); + } bin = event->pos().x() - _bin0Offset(); getPlotInfo(event->pos(), &sd, &cpu, &pid);
@@ -291,17 +296,20 @@ void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) return; if (event->button() == Qt::LeftButton) { - size_t posMouseRel = _posInRange(event->pos().x()); - int min, max; - if (_posMousePress < posMouseRel) { - min = _posMousePress - _bin0Offset(); - max = posMouseRel - _bin0Offset(); - } else { - max = _posMousePress - _bin0Offset(); - min = posMouseRel - _bin0Offset(); - } + if (_rubberBand.isVisible()) { + size_t posMouseRel = _posInRange(event->pos().x()); + + int min, max; + if (_posMousePress < posMouseRel) { + min = _posMousePress - _bin0Offset(); + max = posMouseRel - _bin0Offset(); + } else { + max = _posMousePress - _bin0Offset(); + min = posMouseRel - _bin0Offset(); + } - _rangeChanged(min, max); + _rangeChanged(min, max); + } } }
@@ -1132,7 +1140,7 @@ void KsGLWidget::_rangeChanged(int binMin, int binMax) /* The rubber band is no longer needed. Make it invisible. */ _rubberBand.hide(); - if ( (binMax - binMin) < 4) { + if ((binMax - binMin) < 4) { /* Most likely this is an accidental click. Do nothing. */ return; }
@@ -1182,6 +1190,12 @@ void KsGLWidget::_rangeChanged(int binMin, int binMax) } } +void KsGLWidget::_rangeBoundCancel() +{ + /* The rubber band is no longer needed. Make it invisible. */ + _rubberBand.hide(); +} + int KsGLWidget::_posInRange(int x) { int posX;
src/KsGLWidget.hpp +2 -0
@@ -315,6 +315,8 @@ private: void _rangeChanged(int binMin, int binMax); + void _rangeBoundCancel(); + bool _findAndSelect(QMouseEvent *event); bool _find(int bin, int sd, int cpu, int pid,
Signature · 1 line
2.43.0
Hi Mircea,
Looks like this is indeed a bug, however it is hard to reproduce. I had to do a lot of right mouse button clicks before seeing this misbehavior to show up.
I will take the fix, but the patch itself heeds some additional work. See my comments in code below.
Quoted 26 lines · Mircea Cirjaliu
Accidentally pressing right mouse button while dragging the range will cause the rubber band to behave abnormally. Improved the logic behind range dragging to account for this case. The state of the rubber band will be reset on right click.
Signed-off-by Mircea Cirjaliu <[email protected]>--- src/KsGLWidget.cpp | 40 +++++++++++++++++++++++++++------------- src/KsGLWidget.hpp | 2 ++ 2 files changed, 29 insertions(+), 13 deletions(-)src/KsGLWidget.cpp +3
-0@@ -190,6 +190,9 @@ void KsGLWidget::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { _posMousePress = _posInRange(event->pos().x()); _rangeBoundInit(_posMousePress); + } else if (event->button() == Qt::RightButton) { + if (_rubberBand.isVisible()) + _rangeBoundCancel(); } }
src/KsGLWidget.cpp void KsGLWidget::mouseMoveEvent(QMouseEvent *event) · line 271
Quoted 9 lines
src/KsGLWidget.cpp +4
-2@@ -262,8 +265,10 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event) if (isEmpty()) return; - if (_rubberBand.isVisible()) - _rangeBoundStretched(_posInRange(event->pos().x())); + if (_rubberBand.isVisible()) { + size_t posMouseRel = _posInRange(event->pos().x()); + _rangeBoundStretched(posMouseRel); + }
I don't see the point in this change.
src/KsGLWidget.cpp void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) · line 297
Quoted 6 lines
src/KsGLWidget.cpp +0
-0bin = event->pos().x() - _bin0Offset(); getPlotInfo(event->pos(), &sd, &cpu, &pid);@@ -291,17 +296,20 @@ void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) return;
No need to pile if on top of another if here. Just start the function with
if (isEmpty() || !_rubberBand.isVisible()) return;
The rest may stay unchanged.
Quoted 38 lines
src/KsGLWidget.cpp +14
-11if (event->button() == Qt::LeftButton) { - size_t posMouseRel = _posInRange(event->pos().x()); - int min, max; - if (_posMousePress < posMouseRel) { - min = _posMousePress - _bin0Offset(); - max = posMouseRel - _bin0Offset(); - } else { - max = _posMousePress - _bin0Offset(); - min = posMouseRel - _bin0Offset(); - } + if (_rubberBand.isVisible()) { + size_t posMouseRel = _posInRange(event->pos().x()); + + int min, max; + if (_posMousePress < posMouseRel) { + min = _posMousePress - _bin0Offset(); + max = posMouseRel - _bin0Offset(); + } else { + max = _posMousePress - _bin0Offset(); + min = posMouseRel - _bin0Offset(); + } - _rangeChanged(min, max); + _rangeChanged(min, max); + } } }@@ -1132,7 +1140,7 @@ void KsGLWidget::_rangeChanged(int binMin, int binMax) /* The rubber band is no longer needed. Make it invisible. */ _rubberBand.hide(); - if ( (binMax - binMin) < 4) { + if ((binMax - binMin) < 4) { /* Most likely this is an accidental click. Do nothing. */ return; }
src/KsGLWidget.cpp void KsGLWidget::_rangeChanged(int binMin, int binMax) · line 1198
Quoted 9 lines
src/KsGLWidget.cpp +6
-0@@ -1182,6 +1190,12 @@ void KsGLWidget::_rangeChanged(int binMin, int binMax) } } +void KsGLWidget::_rangeBoundCancel() +{ + /* The rubber band is no longer needed. Make it invisible. */ + _rubberBand.hide(); +} +
What is the point in defining a function that does nothing but calling another function.
Thanks,
Yordan
Quoted 16 lines
src/KsGLWidget.cpp +0
-0int KsGLWidget::_posInRange(int x) { int posX;src/KsGLWidget.hpp +2
-0@@ -315,6 +315,8 @@ private: void _rangeChanged(int binMin, int binMax); + void _rangeBoundCancel(); + bool _findAndSelect(QMouseEvent *event); bool _find(int bin, int sd, int cpu, int pid,
Hi Yordan,
I tend to favor debuggability, expressiveness and readability in my coding, even if it makes for longer code or seemingly unnecessary code constructs. I'll leave it to the compiler to optimize variable usage, I wanna make it easy (for me or others) to set a breakpoint or understand what the code is doing.
Quoted 34 lines · Yordan Karadzhov
Hi Mircea,
Looks like this is indeed a bug, however it is hard to reproduce. I had to do a lot of right mouse button clicks before seeing this misbehavior to show up.
I will take the fix, but the patch itself heeds some additional work. See my comments in code below.
Quoted 27 lines · Mircea Cirjaliu
Accidentally pressing right mouse button while dragging the range will cause the rubber band to behave abnormally. Improved the logic behind range dragging to account for this case. The state of the rubber band will be reset on right click.
Signed-off-by Mircea Cirjaliu <[email protected]>---
src/KsGLWidget.cpp | 40 +++++++++++++++++++++++++++------------- src/KsGLWidget.hpp | 2 ++2 files changed, 29 insertions(+), 13 deletions(-)src/KsGLWidget.cpp +3
-0@@ -190,6 +190,9 @@ void KsGLWidget::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { _posMousePress = _posInRange(event->pos().x()); _rangeBoundInit(_posMousePress); + } else if (event->button() == Qt::RightButton) { + if (_rubberBand.isVisible()) + _rangeBoundCancel(); } } @@ -262,8 +265,10 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event)if (
isEmpty())
return;
Quoted 8 lines
Quoted 6 lines
- if (
_rubberBand.isVisible())
- _rangeBoundStretched(_posInRange(event->pos().x())); + if (_rubberBand.isVisible()) {
+size_tposMouseRel = _posInRange(event->pos().x()); +_rangeBoundStretched(posMouseRel);
+ }I don't see the point in this change.
I needed a breakpoint there.
Quoted 9 lines
Quoted 6 lines
bin = event->pos().x() -
_bin0Offset();
getPlotInfo(event->pos(), &sd, &cpu, &pid);src/KsGLWidget.cpp +0
-0@@ -291,17 +296,20 @@ void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) return;No need to pile if on top of another if here. Just start the function with
Quoted 4 lines
if (
isEmpty()|| !_rubberBand.isVisible())
return;The rest may stay unchanged.
Agree with you here, will fix.
Quoted 37 lines
Quoted 37 lines
if (
event->button()==Qt::LeftButton) {
-size_tposMouseRel = _posInRange(event->pos().x());
- int min, max;
- if (_posMousePress< posMouseRel) {
- min =_posMousePress-_bin0Offset();
- max = posMouseRel -_bin0Offset();
- } else {
- max =_posMousePress-_bin0Offset();
- min = posMouseRel -_bin0Offset();
- }
+ if (_rubberBand.isVisible()) {
+size_tposMouseRel = _posInRange(event->pos().x()); +
+ int min, max;
+ if (_posMousePress< posMouseRel) {
+ min =_posMousePress-_bin0Offset();
+ max = posMouseRel -_bin0Offset();
+ } else {
+ max =_posMousePress-_bin0Offset();
+ min = posMouseRel -_bin0Offset();
+ }
-_rangeChanged(min, max);
+_rangeChanged(min, max);
+ }
}
}
@@ -1132,7 +1140,7 @@ voidKsGLWidget::_rangeChanged(int binMin, int binMax)/* The rubber band is no longer needed. Make it invisible. */_rubberBand.hide();
- if ( (binMax - binMin) < 4) {
+ if ((binMax - binMin) < 4) {
/* Most likely this is an accidental click. Do nothing. */ return;
}src/KsGLWidget.cpp +0
-0@@ -1182,6 +1190,12 @@ void KsGLWidget::_rangeChanged(int binMin, int binMax) }
Quoted 8 lines
src/KsGLWidget.cpp void KsGLWidget::_rangeChanged(int binMin, int binMax) · line 1198
Quoted 7 lines
src/KsGLWidget.cpp +5
-0} +void KsGLWidget::_rangeBoundCancel() +{ + /* The rubber band is no longer needed. Make it invisible. */ + _rubberBand.hide(); +} +What is the point in defining a function that does nothing but calling another function.
Layering functionality, i.e. mouse events call _rangeBoundXXX() functions, which instead act on _rubberBand. For improved code readability, also having a properly named logical entry point aids in debugging.
Quoted 4 lines
Thanks,
Yordan
Quoted 13 lines
src/KsGLWidget.hpp private: · line 319
Quoted 13 lines
src/KsGLWidget.cpp +0
-0int KsGLWidget::_posInRange(int x) { int posX;src/KsGLWidget.hpp +1
-0@@ -315,6 +315,8 @@ private: void _rangeChanged(int binMin, int binMax); + void _rangeBoundCancel(); + bool _findAndSelect(QMouseEvent *event); bool _find(int bin, int sd, int cpu, int pid,
Best,
Mircea
Hi Mircea,
Quoted 36 lines · Mircea Cirjaliu
Hi Yordan,
I tend to favor debuggability, expressiveness and readability in my coding, even if it makes for longer code or seemingly unnecessary code constructs. I'll leave it to the compiler to optimize variable usage, I wanna make it easy (for me or others) to set a breakpoint or understand what the code is doing.
Quoted 29 lines · Yordan Karadzhov
Hi Mircea,
Looks like this is indeed a bug, however it is hard to reproduce. I had to do a lot of right mouse button clicks before seeing this misbehavior to show up.
I will take the fix, but the patch itself heeds some additional work. See my comments in code below.
Quoted 21 lines · Mircea Cirjaliu
Accidentally pressing right mouse button while dragging the range will cause the rubber band to behave abnormally. Improved the logic behind range dragging to account for this case. The state of the rubber band will be reset on right click.
Signed-off-by Mircea Cirjaliu <[email protected]>--- src/KsGLWidget.cpp | 40 +++++++++++++++++++++++++++------------- src/KsGLWidget.hpp | 2 ++ 2 files changed, 29 insertions(+), 13 deletions(-)@@ -262,8 +265,10 @@ void
KsGLWidget::mouseMoveEvent(QMouseEvent *event)if (isEmpty())
return;
- if (_rubberBand.isVisible())
- _rangeBoundStretched(_posInRange(event->pos().x()));
+ if (_rubberBand.isVisible()) {
+size_tposMouseRel = _posInRange(event->pos().x());
+_rangeBoundStretched(posMouseRel);
+ }
Quoted 4 lines
Quoted 1 line
I don't see the point in this change.
I needed a breakpoint there.
I understand that this change helped you find the problem, but we are not merging debugging code upstream.
Quoted 17 lines
Quoted 8 lines
Quoted 6 lines
bin = event->pos().x() -
_bin0Offset();getPlotInfo(event->pos(), &sd, &cpu, &pid);(quoted diff) +0
-0@@ -291,17 +296,20 @@ void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) return;Quoted 8 lines
src/KsGLWidget.cpp void KsGLWidget::_rangeChanged(int binMin, int binMax) · line 1198
Quoted 7 lines
src/KsGLWidget.cpp +5
-0} +void KsGLWidget::_rangeBoundCancel() +{ + /* The rubber band is no longer needed. Make it invisible. */ + _rubberBand.hide(); +} +What is the point in defining a function that does nothing but calling another function.
Quoted 3 lines
Layering functionality, i.e. mouse events call
_rangeBoundXXX()functions, which instead act on_rubberBand. For improved code readability, also having a properly named logical entry point aids in debugging.
Again, debugging cannot be a reason for pushing code upstream.
Best,
Yordan
Quoted 20 lines
Quoted 4 lines
Thanks,
YordanQuoted 13 lines
src/KsGLWidget.hpp private: · line 319
Quoted 13 lines
src/KsGLWidget.cpp +0
-0int KsGLWidget::_posInRange(int x) { int posX;src/KsGLWidget.hpp +1
-0@@ -315,6 +315,8 @@ private: void _rangeChanged(int binMin, int binMax); + void _rangeBoundCancel(); + bool _findAndSelect(QMouseEvent *event); bool _find(int bin, int sd, int cpu, int pid,Best,
Mircea