]> sigrok.org Git - pulseview.git/blobdiff - pv/views/trace/view.cpp
Allow for a context menu in the view area
[pulseview.git] / pv / views / trace / view.cpp
index 3cb26ec400be3028d005b4c3b8d3b61d1c7a2a50..99e75bfdc9ec72de6281d86b3d922e626a5911a5 100644 (file)
@@ -38,6 +38,7 @@
 #include <QApplication>
 #include <QEvent>
 #include <QFontMetrics>
+#include <QMenu>
 #include <QMouseEvent>
 #include <QScrollBar>
 #include <QVBoxLayout>
@@ -385,7 +386,7 @@ void View::restore_settings(QSettings &settings)
                        boost::archive::text_iarchive ia(ss);
                        ia >> boost::serialization::make_nvp("ruler_shift", shift);
                        ruler_shift_ = shift;
-               } catch (boost::archive::archive_exception) {
+               } catch (boost::archive::archive_exception&) {
                        qDebug() << "Could not restore the view ruler shift";
                }
        }
@@ -400,7 +401,7 @@ void View::restore_settings(QSettings &settings)
                        ia >> boost::serialization::make_nvp("offset", offset);
                        // This also updates ruler_offset_
                        set_offset(offset);
-               } catch (boost::archive::archive_exception) {
+               } catch (boost::archive::archive_exception&) {
                        qDebug() << "Could not restore the view offset";
                }
        }
@@ -619,8 +620,6 @@ Trace::SegmentDisplayMode View::segment_display_mode() const
 
 void View::set_segment_display_mode(Trace::SegmentDisplayMode mode)
 {
-       trigger_markers_.clear();
-
        segment_display_mode_ = mode;
 
        for (shared_ptr<Signal> signal : signals_)
@@ -1055,8 +1054,10 @@ void View::update_scroll()
                vscrollbar->setRange(extents.first - areaSize.height(),
                        extents.second);
 
-       if (scroll_needs_defaults_)
+       if (scroll_needs_defaults_) {
                set_scroll_default();
+               scroll_needs_defaults_ = false;
+       }
 }
 
 void View::reset_scroll()
@@ -1251,6 +1252,17 @@ bool View::eventFilter(QObject *object, QEvent *event)
        return QObject::eventFilter(object, event);
 }
 
+void View::contextMenuEvent(QContextMenuEvent *event)
+{
+       const shared_ptr<ViewItem> r = viewport_->get_mouse_over_item(event->pos());
+       if (!r)
+               return;
+
+       QMenu *menu = r->create_view_context_menu(this);
+       if (menu)
+               menu->exec(event->globalPos());
+}
+
 void View::resizeEvent(QResizeEvent* event)
 {
        // Only adjust the top margin if we shrunk vertically
@@ -1297,6 +1309,7 @@ void View::extents_changed(bool horz, bool vert)
                (horz ? TraceTreeItemHExtentsChanged : 0) |
                (vert ? TraceTreeItemVExtentsChanged : 0);
 
+       lazy_event_handler_.stop();
        lazy_event_handler_.start();
 }