We want all operations over the graphs (like Zoom or Scroll) to be protected for the case when no data is loaded or no graphs are plotted. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- kernel-shark/src/KsGLWidget.cpp | 22 ++++++++++++++++++++-- kernel-shark/src/KsGLWidget.hpp | 2 ++ kernel-shark/src/KsTraceGraph.cpp | 9 +++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/kernel-shark/src/KsGLWidget.cpp b/kernel-shark/src/KsGLWidget.cpp index ce68052..e930006 100644 --- a/kernel-shark/src/KsGLWidget.cpp +++ b/kernel-shark/src/KsGLWidget.cpp @@ -88,9 +88,11 @@ void KsGLWidget::paintGL() glClear(GL_COLOR_BUFFER_BIT); + if (isEmpty()) + return; + /* Draw the time axis. */ - if(_data) - _drawAxisX(size); + _drawAxisX(size); /* Process and draw all graphs by using the built-in logic. */ _makeGraphs(_cpuList, _taskList); @@ -127,6 +129,13 @@ void KsGLWidget::reset() _model.reset(); } +/** Check if the widget is empty (not showing anything). */ +bool KsGLWidget::isEmpty() const { + return !_data || + !_data->size() || + (!_cpuList.size() && !_taskList.size()); +} + /** Reimplemented event handler used to receive mouse press events. */ void KsGLWidget::mousePressEvent(QMouseEvent *event) { @@ -198,6 +207,9 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event) size_t row; bool ret; + if (isEmpty()) + return; + if (_rubberBand.isVisible()) _rangeBoundStretched(_posInRange(event->pos().x())); @@ -224,6 +236,9 @@ void KsGLWidget::mouseMoveEvent(QMouseEvent *event) /** Reimplemented event handler used to receive mouse release events. */ void KsGLWidget::mouseReleaseEvent(QMouseEvent *event) { + if (isEmpty()) + return; + if (event->button() == Qt::LeftButton) { size_t posMouseRel = _posInRange(event->pos().x()); int min, max; @@ -251,6 +266,9 @@ void KsGLWidget::wheelEvent(QWheelEvent * event) { int zoomFocus; + if (isEmpty()) + return; + if (_mState->activeMarker()._isSet && _mState->activeMarker().isVisible()) { /* diff --git a/kernel-shark/src/KsGLWidget.hpp b/kernel-shark/src/KsGLWidget.hpp index e141b0a..3d428b1 100644 --- a/kernel-shark/src/KsGLWidget.hpp +++ b/kernel-shark/src/KsGLWidget.hpp @@ -41,6 +41,8 @@ public: void reset(); + bool isEmpty() const; + /** Reprocess all graphs. */ void update() {resizeGL(width(), height());} diff --git a/kernel-shark/src/KsTraceGraph.cpp b/kernel-shark/src/KsTraceGraph.cpp index 324f36e..2e48372 100644 --- a/kernel-shark/src/KsTraceGraph.cpp +++ b/kernel-shark/src/KsTraceGraph.cpp @@ -234,6 +234,9 @@ void KsTraceGraph::_zoomOut() void KsTraceGraph::_quickZoomIn() { + if (_glWindow.isEmpty()) + return; + /* Bin size will be 100 ns. */ _glWindow.model()->quickZoomIn(100); if (_mState->activeMarker()._isSet && @@ -249,6 +252,9 @@ void KsTraceGraph::_quickZoomIn() void KsTraceGraph::_quickZoomOut() { + if (_glWindow.isEmpty()) + return; + _glWindow.model()->quickZoomOut(); } @@ -646,6 +652,9 @@ void KsTraceGraph::_updateGraphs(GraphActions action) double k; int bin; + if (_glWindow.isEmpty()) + return; + /* * Set the "Key Pressed" flag. The flag will stay set as long as the user * keeps the corresponding action button pressed. -- 2.20.1