license: remove FSF postal address from boiler plate license text
[pulseview.git] / pv / view / viewwidget.cpp
index 2a97eefc2dc1577b4afa7596fedf12a32114914c..ce5c27a83dce2a3c6784dcda17e5d0b2e018b9b7 100644 (file)
@@ -14,8 +14,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <QApplication>
@@ -31,7 +30,8 @@ using std::shared_ptr;
 using std::vector;
 
 namespace pv {
-namespace view {
+namespace views {
+namespace TraceView {
 
 ViewWidget::ViewWidget(View &parent) :
        QWidget(&parent),
@@ -73,8 +73,7 @@ bool ViewWidget::accept_drag() const
        const bool any_time_items_selected = any_of(items.begin(), items.end(),
                [](const shared_ptr<TimeItem> &i) { return i->selected(); });
 
-       if (any_row_items_selected && !any_time_items_selected)
-       {
+       if (any_row_items_selected && !any_time_items_selected) {
                // Check all the drag items share a common owner
                TraceTreeItemOwner *item_owner = nullptr;
                for (shared_ptr<TraceTreeItem> r : trace_tree_items)
@@ -86,9 +85,7 @@ bool ViewWidget::accept_drag() const
                        }
 
                return true;
-       }
-       else if (any_time_items_selected && !any_row_items_selected)
-       {
+       } else if (any_time_items_selected && !any_row_items_selected) {
                return true;
        }
 
@@ -212,8 +209,7 @@ void ViewWidget::mouse_left_release_event(QMouseEvent *event)
 
        if (item_dragging_)
                view_.restack_all_trace_tree_items();
-       else
-       {
+       else {
                if (!ctrl_pressed) {
                        for (shared_ptr<ViewItem> i : items)
                                if (mouse_down_item_ != i)
@@ -227,9 +223,10 @@ void ViewWidget::mouse_left_release_event(QMouseEvent *event)
        item_dragging_ = false;
 }
 
-bool ViewWidget::touch_event(QTouchEvent *e)
+bool ViewWidget::touch_event(QTouchEvent *event)
 {
-       (void)e;
+       (void)event;
+
        return false;
 }
 
@@ -254,16 +251,23 @@ void ViewWidget::mousePressEvent(QMouseEvent *event)
 {
        assert(event);
 
-       mouse_down_point_ = event->pos();
-       mouse_down_item_ = get_mouse_over_item(event->pos());
-
-       if (event->button() & Qt::LeftButton)
+       /* Ignore right click events as they will open context menus when
+        * used on trace labels. Those menus prevent ViewWidget::mouseReleaseEvent()
+        * to be triggered upon button release, making mouse_down_item_
+        * hold the last reference to a view item that might have been deleted
+        * from the context menu, preventing it from being freed as intended.
+        */
+       if (event->button() & Qt::LeftButton) {
+               mouse_down_point_ = event->pos();
+               mouse_down_item_ = get_mouse_over_item(event->pos());
                mouse_left_press_event(event);
+       }
 }
 
 void ViewWidget::mouseReleaseEvent(QMouseEvent *event)
 {
        assert(event);
+
        if (event->button() & Qt::LeftButton)
                mouse_left_release_event(event);
 
@@ -271,18 +275,16 @@ void ViewWidget::mouseReleaseEvent(QMouseEvent *event)
        mouse_down_item_ = nullptr;
 }
 
-void ViewWidget::mouseMoveEvent(QMouseEvent *e)
+void ViewWidget::mouseMoveEvent(QMouseEvent *event)
 {
-       assert(e);
-       mouse_point_ = e->pos();
-
-       if (!e->buttons())
-               item_hover(get_mouse_over_item(e->pos()));
-       else if (e->buttons() & Qt::LeftButton)
-       {
-               if (!item_dragging_)
-               {
-                       if ((e->pos() - mouse_down_point_).manhattanLength() <
+       assert(event);
+       mouse_point_ = event->pos();
+
+       if (!event->buttons())
+               item_hover(get_mouse_over_item(event->pos()));
+       else if (event->buttons() & Qt::LeftButton) {
+               if (!item_dragging_) {
+                       if ((event->pos() - mouse_down_point_).manhattanLength() <
                                QApplication::startDragDistance())
                                return;
 
@@ -293,9 +295,7 @@ void ViewWidget::mouseMoveEvent(QMouseEvent *e)
                }
 
                // Do the drag
-               drag_items(e->pos() - mouse_down_point_);
-
-               update();
+               drag_items(event->pos() - mouse_down_point_);
        }
 }
 
@@ -305,5 +305,6 @@ void ViewWidget::leaveEvent(QEvent*)
        update();
 }
 
-} // namespace view
+} // namespace TraceView
+} // namespace views
 } // namespace pv