diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-04-17 16:38:22 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-04-17 16:38:22 +0200 |
commit | 35978072c44f5ec84417da43904e7dad879fc5a4 (patch) | |
tree | d5c98f64eb19796d802d53cd4820bb2b4d17d246 | |
parent | 5b286bc5595196637d60e63ffea106ce73c1aa7c (diff) |
few widgets: use repaint() for no event loop overhead
The Qt event loop overhead formed a decent amount of total CPU
usage. `repaint()' is a direct call.
-rw-r--r-- | cv/video-widget.cpp | 7 | ||||
-rw-r--r-- | gui/main-window.cpp | 6 | ||||
-rw-r--r-- | pose-widget/pose-widget.cpp | 2 | ||||
-rw-r--r-- | spline/spline-widget.cpp | 8 |
4 files changed, 12 insertions, 11 deletions
diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp index e688732c..f4c16776 100644 --- a/cv/video-widget.cpp +++ b/cv/video-widget.cpp @@ -9,8 +9,9 @@ #include "video-widget.hpp" #include <opencv2/imgproc.hpp> -cv_video_widget::cv_video_widget(QWidget* parent) : - QWidget(parent), freshp(false) +cv_video_widget::cv_video_widget(QWidget* parent) : QWidget(parent), + mtx(QMutex::Recursive), + freshp(false) { connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint()), Qt::DirectConnection); timer.start(65); @@ -73,6 +74,6 @@ void cv_video_widget::update_and_repaint() if (freshp) { freshp = false; - update(); + repaint(); } } diff --git a/gui/main-window.cpp b/gui/main-window.cpp index fb036721..1fdfcb53 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -86,7 +86,7 @@ MainWindow::MainWindow() : // timers connect(&config_list_timer, &QTimer::timeout, this, [this]() { refresh_config_list(); }); - connect(&pose_update_timer, SIGNAL(timeout()), this, SLOT(showHeadPose())); + connect(&pose_update_timer, SIGNAL(timeout()), this, SLOT(showHeadPose()), Qt::DirectConnection); connect(&det_timer, SIGNAL(timeout()), this, SLOT(maybe_start_profile_from_executable())); // ctrl+q exits @@ -515,8 +515,8 @@ void MainWindow::display_pose(const double *mapped, const double *raw) ui.pose_display->rotate_async(mapped[Yaw], mapped[Pitch], -mapped[Roll], mapped[TX], mapped[TY], mapped[TZ]); - if (mapping_widget) - mapping_widget->update(); + if (mapping_widget && mapping_widget->isVisible()) + mapping_widget->repaint(); QLCDNumber* raw_[] = { ui.raw_x, ui.raw_y, ui.raw_z, diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 8caf65b7..8f4c4a1b 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -86,7 +86,7 @@ void pose_widget::rotate_async(double xAngle, double yAngle, double zAngle, doub bool expected = true; if (xform.fresh.compare_exchange_weak(expected, false)) { - update(); + repaint(); xform.rotate_async(xAngle, yAngle, zAngle, x, y, z); } } diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index c7dd5e5a..1a39cc23 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -379,7 +379,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e) } } _draw_function = true; - update(); + repaint(); } void spline_widget::mouseMoveEvent(QMouseEvent *e) @@ -433,7 +433,7 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e) setCursor(Qt::ClosedHandCursor); show_tooltip(pix, new_pt); - update(); + repaint(); } else if (sz) { @@ -480,7 +480,7 @@ void spline_widget::mouseReleaseEvent(QMouseEvent *e) else QToolTip::hideText(); - update(); + repaint(); } } @@ -551,7 +551,7 @@ void spline_widget::update_range() _background = QPixmap(); _function = QPixmap(); - update(); + repaint(); } bool spline_widget::point_within_pixel(const QPointF& pt, const QPoint &pixel) |