]> sigrok.org Git - pulseview.git/commitdiff
Add generic "Create marker here" context menu entry
authorSoeren Apel <redacted>
Tue, 16 Oct 2018 22:39:54 +0000 (00:39 +0200)
committerSoeren Apel <redacted>
Tue, 16 Oct 2018 22:51:01 +0000 (00:51 +0200)
manual/analysis.txt
pv/views/trace/decodetrace.cpp
pv/views/trace/ruler.cpp
pv/views/trace/ruler.hpp
pv/views/trace/trace.cpp
pv/views/trace/trace.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 034f969a81029c48fffd954531dee77a584965c6..7aa487b488b4416d839fdf8337a07ff901711aa1 100644 (file)
@@ -43,7 +43,8 @@ image::pv_cursors_markers.png[]
 
 Markers are movable indicators that you can create wherever you like on the
 time scale - just double-click on it and it'll create one for you where your
-mouse cursor is at the time, or use the context menu when right-clicking.
+mouse cursor is at the time, or use the context menu when right-clicking on
+the ruler or a signal trace.
 You can click on its label and you'll have the option to change its name, or
 drag it to reposition it.
 
index 2797891138ffcd691b4c65ce241bb720547f2583..1f9e4c4e1b9bd7e0e2af3dad77817b33fec7f1bc 100644 (file)
@@ -328,6 +328,23 @@ QMenu* DecodeTrace::create_header_context_menu(QWidget *parent)
 
 QMenu* DecodeTrace::create_view_context_menu(QWidget *parent, QPoint &click_pos)
 {
+       // Get entries from default menu before adding our own
+       QMenu *const menu = new QMenu(parent);
+
+       QMenu* default_menu = Trace::create_view_context_menu(parent, click_pos);
+       if (default_menu) {
+               for (QAction *action : default_menu->actions()) {
+                       menu->addAction(action);
+                       if (action->parent() == default_menu)
+                               action->setParent(menu);
+               }
+               delete default_menu;
+
+               // Add separator if needed
+               if (menu->actions().length() > 0)
+                       menu->addSeparator();
+       }
+
        try {
                selected_row_ = &visible_rows_[get_row_at_point(click_pos)];
        } catch (out_of_range&) {
@@ -339,8 +356,6 @@ QMenu* DecodeTrace::create_view_context_menu(QWidget *parent, QPoint &click_pos)
                get_view_sample_range(click_pos.x(), click_pos.x() + 1);
        selected_sample_range_ = make_pair(sample_range.first, numeric_limits<uint64_t>::max());
 
-       QMenu *const menu = new QMenu(parent);
-
        if (decode_signal_->is_paused()) {
                QAction *const resume =
                        new QAction(tr("Resume decoding"), this);
index a085de29123cba27181414134c5e0673f2d642f7..675a39f9bd1b6ece887af2c9bd927e496e84a109 100644 (file)
@@ -114,7 +114,7 @@ QString Ruler::format_time_with_distance(
                return pv::util::format_time_minutes(t, precision, sign);
 }
 
-pv::util::Timestamp Ruler::get_time_from_x_pos(uint32_t x)
+pv::util::Timestamp Ruler::get_time_from_x_pos(uint32_t x) const
 {
        return view_.ruler_offset() + ((double)x + 0.5) * view_.scale();
 }
@@ -318,7 +318,7 @@ void Ruler::invalidate_tick_position_cache()
 
 void Ruler::on_createMarker()
 {
-       view_.add_flag(get_time_from_x_pos(context_menu_x_pos_));
+       view_.add_flag(get_time_from_x_pos(mouse_down_point_.x()));
 }
 
 void Ruler::on_toggleHoverMarker()
index 8c1876cced37f5e2598f655a51e309eff0c4fbd7..40aa31bfefb4a9f42887b41d3035464a21994b33 100644 (file)
@@ -117,7 +117,7 @@ public:
                unsigned precision = 0,
                bool sign = true);
 
-       pv::util::Timestamp get_time_from_x_pos(uint32_t x);
+       pv::util::Timestamp get_time_from_x_pos(uint32_t x) const;
 
 protected:
        virtual void contextMenuEvent(QContextMenuEvent *event) override;
index bbd0115fb65af00512508c7129d3e6399b12a3a2..0a1fdf30684fc7bd800fc061f5fc7425a385c401 100644 (file)
@@ -26,7 +26,9 @@
 #include <QFormLayout>
 #include <QKeyEvent>
 #include <QLineEdit>
+#include <QMenu>
 
+#include "ruler.hpp"
 #include "trace.hpp"
 #include "tracepalette.hpp"
 #include "view.hpp"
@@ -180,6 +182,34 @@ QMenu* Trace::create_header_context_menu(QWidget *parent)
        return menu;
 }
 
+QMenu* Trace::create_view_context_menu(QWidget *parent, QPoint &click_pos)
+{
+       context_menu_x_pos_ = click_pos.x();
+
+       // Get entries from default menu before adding our own
+       QMenu *const menu = new QMenu(parent);
+
+       QMenu* default_menu = TraceTreeItem::create_view_context_menu(parent, click_pos);
+       if (default_menu) {
+               for (QAction *action : default_menu->actions()) {
+                       menu->addAction(action);
+                       if (action->parent() == default_menu)
+                               action->setParent(menu);
+               }
+               delete default_menu;
+
+               // Add separator if needed
+               if (menu->actions().length() > 0)
+                       menu->addSeparator();
+       }
+
+       QAction *const create_marker_here = new QAction(tr("Create marker here"), this);
+       connect(create_marker_here, SIGNAL(triggered()), this, SLOT(on_create_marker_here()));
+       menu->addAction(create_marker_here);
+
+       return menu;
+}
+
 pv::widgets::Popup* Trace::create_popup(QWidget *parent)
 {
        using pv::widgets::Popup;
@@ -373,6 +403,17 @@ void Trace::on_coloredit_changed(const QColor &color)
        base_->set_color(color);
 }
 
+void Trace::on_create_marker_here() const
+{
+       View *view = owner_->view();
+       assert(view);
+
+       const Ruler *ruler = view->ruler();
+       QPoint p = ruler->mapFrom(view, QPoint(context_menu_x_pos_, 0));
+
+       view->add_flag(ruler->get_time_from_x_pos(p.x()));
+}
+
 } // namespace trace
 } // namespace views
 } // namespace pv
index 0b4ecce49484af09e8b60938afc5c3069cb3d936..2b98811b32ea3506865fc8db5e9e4924644539c7 100644 (file)
@@ -129,6 +129,8 @@ public:
 
        virtual QMenu* create_header_context_menu(QWidget *parent);
 
+       virtual QMenu* create_view_context_menu(QWidget *parent, QPoint &click_pos);
+
        pv::widgets::Popup* create_popup(QWidget *parent);
 
        /**
@@ -192,6 +194,8 @@ private Q_SLOTS:
 
        void on_coloredit_changed(const QColor &color);
 
+       void on_create_marker_here() const;
+
 protected:
        shared_ptr<data::SignalBase> base_;
        QPen axis_pen_;
@@ -199,6 +203,8 @@ protected:
        SegmentDisplayMode segment_display_mode_;
        bool show_hover_marker_;
 
+       uint32_t context_menu_x_pos_;
+
        /// The ID of the currently displayed segment
        int current_segment_;
 
index 375f5754c7750a5277e538044a8d6f122f27fb44..aee84a20be5c1e0fb1aea36c85eb1d5a2af02c18 100644 (file)
@@ -347,6 +347,11 @@ const Viewport* View::viewport() const
        return viewport_;
 }
 
+const Ruler* View::ruler() const
+{
+       return ruler_;
+}
+
 void View::save_settings(QSettings &settings) const
 {
        settings.setValue("scale", scale_);
index 4bde31d6dd17e3f6a5dd417a3397ebb98a3ded77..7b63d064099c46b53d57ce666736a3384abb06e5 100644 (file)
@@ -145,6 +145,8 @@ public:
 
        const Viewport* viewport() const;
 
+       const Ruler* ruler() const;
+
        virtual void save_settings(QSettings &settings) const;
 
        virtual void restore_settings(QSettings &settings);