From: Soeren Apel Date: Tue, 16 Oct 2018 22:39:54 +0000 (+0200) Subject: Add generic "Create marker here" context menu entry X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;ds=sidebyside;h=79b53a1ae;hp=3263ed2dcaead74cd66f132e1120d832b2a63faf;p=pulseview.git Add generic "Create marker here" context menu entry --- diff --git a/manual/analysis.txt b/manual/analysis.txt index 034f969..7aa487b 100644 --- a/manual/analysis.txt +++ b/manual/analysis.txt @@ -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. diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 2797891..1f9e4c4 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -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::max()); - QMenu *const menu = new QMenu(parent); - if (decode_signal_->is_paused()) { QAction *const resume = new QAction(tr("Resume decoding"), this); diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index a085de2..675a39f 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -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() diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index 8c1876c..40aa31b 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -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; diff --git a/pv/views/trace/trace.cpp b/pv/views/trace/trace.cpp index bbd0115..0a1fdf3 100644 --- a/pv/views/trace/trace.cpp +++ b/pv/views/trace/trace.cpp @@ -26,7 +26,9 @@ #include #include #include +#include +#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 diff --git a/pv/views/trace/trace.hpp b/pv/views/trace/trace.hpp index 0b4ecce..2b98811 100644 --- a/pv/views/trace/trace.hpp +++ b/pv/views/trace/trace.hpp @@ -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 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_; diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 375f575..aee84a2 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -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_); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 4bde31d..7b63d06 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -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);