]> sigrok.org Git - pulseview.git/commitdiff
Header: Keep a shared_ptr of the clicked item
authorJoel Holdsworth <redacted>
Sun, 2 Nov 2014 16:29:29 +0000 (16:29 +0000)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:02 +0000 (10:23 +0000)
pv/view/header.cpp
pv/view/header.h

index b9261f9753d060bdaffbb48ab7c52a35d4a5210b..2ab8ed986568ba4bfeaa36043840b723541ce867 100644 (file)
@@ -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<RowItem> 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<RowItem> 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<RowItem> 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<RowItem> 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)
index 2b182978a905669d1145d9b06149fc8c4ce8aa4c..808de5d5c966aed905da5f2e06a88d5714e3c80a 100644 (file)
@@ -90,6 +90,7 @@ Q_SIGNALS:
 private:
        QPoint _mouse_point;
        QPoint _mouse_down_point;
+       std::shared_ptr<RowItem> _mouse_down_item;
        bool _dragging;
 };