From: Joel Holdsworth Date: Sun, 2 Nov 2014 16:29:29 +0000 (+0000) Subject: Header: Keep a shared_ptr of the clicked item X-Git-Tag: pulseview-0.3.0~457 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f0c0b38f812bfbb2bb1978d40e2ce93f1da3f89d;p=pulseview.git Header: Keep a shared_ptr of the clicked item --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index b9261f97..2ab8ed98 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -137,26 +137,26 @@ void Header::paintEvent(QPaintEvent*) void Header::mouseLeftPressEvent(QMouseEvent *event) { + (void)event; + const bool ctrl_pressed = QApplication::keyboardModifiers() & Qt::ControlModifier; // Clear selection if control is not pressed and this item is unselected - const shared_ptr mouse_over = - get_mouse_over_row_item(event->pos()); - if (!ctrl_pressed && (!mouse_over || !mouse_over->selected())) + if ((!_mouse_down_item || !_mouse_down_item->selected()) && + !ctrl_pressed) for (shared_ptr r : _view) r->select(false); // Set the signal selection state if the item has been clicked - if (mouse_over) { + if (_mouse_down_item) { if (ctrl_pressed) - mouse_over->select(!mouse_over->selected()); + _mouse_down_item->select(!_mouse_down_item->selected()); else - mouse_over->select(true); + _mouse_down_item->select(true); } // Save the offsets of any signals which will be dragged - _mouse_down_point = event->pos(); for (const shared_ptr r : _view) if (r->selected()) r->drag(); @@ -168,6 +168,10 @@ void Header::mouseLeftPressEvent(QMouseEvent *event) void Header::mousePressEvent(QMouseEvent *event) { assert(event); + + _mouse_down_point = event->pos(); + _mouse_down_item = get_mouse_over_row_item(event->pos()); + if (event->button() & Qt::LeftButton) mouseLeftPressEvent(event); } @@ -192,11 +196,11 @@ void Header::mouseLeftReleaseEvent(QMouseEvent *event) { if (!ctrl_pressed) { for (shared_ptr r : _view) - if (mouse_over != r) + if (_mouse_down_item != r) r->select(false); - if (mouse_over) - show_popup(mouse_over); + if (_mouse_down_item) + show_popup(_mouse_down_item); } } @@ -208,6 +212,8 @@ void Header::mouseReleaseEvent(QMouseEvent *event) assert(event); if (event->button() & Qt::LeftButton) mouseLeftReleaseEvent(event); + + _mouse_down_item = nullptr; } void Header::mouseMoveEvent(QMouseEvent *event) diff --git a/pv/view/header.h b/pv/view/header.h index 2b182978..808de5d5 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -90,6 +90,7 @@ Q_SIGNALS: private: QPoint _mouse_point; QPoint _mouse_down_point; + std::shared_ptr _mouse_down_item; bool _dragging; };