From: Joel Holdsworth Date: Sat, 1 Nov 2014 10:42:48 +0000 (+0000) Subject: TraceGroup: Added ungroup item X-Git-Tag: pulseview-0.3.0~453 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0a51d1c122784a9052058c79ec2099b1ed104a22;p=pulseview.git TraceGroup: Added ungroup item --- diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index bc63d7f2..af756d49 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -22,10 +22,13 @@ #include +#include + #include "tracegroup.h" using std::pair; using std::shared_ptr; +using std::vector; namespace pv { namespace view { @@ -103,9 +106,14 @@ bool TraceGroup::pt_in_label_rect(int left, int right, const QPoint &point) QMenu* TraceGroup::create_context_menu(QWidget *parent) { - (void)parent; + QMenu *const menu = new QMenu(parent); - return NULL; + QAction *const ungroup = new QAction(tr("Ungroup"), this); + ungroup->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); + connect(ungroup, SIGNAL(triggered()), this, SLOT(on_ungroup())); + menu->addAction(ungroup); + + return menu; } pv::widgets::Popup* TraceGroup::create_popup(QWidget *parent) @@ -125,5 +133,20 @@ void TraceGroup::update_viewport() _owner->update_viewport(); } +void TraceGroup::on_ungroup() +{ + const vector< shared_ptr > items( + child_items().begin(), child_items().end()); + clear_child_items(); + + for (shared_ptr r : items) { + _owner->add_child_item(r); + r->set_v_offset(r->v_offset() + v_offset()); + } + + _owner->remove_child_item(shared_from_this()); + appearance_changed(); +} + } // namespace view } // namespace pv diff --git a/pv/view/tracegroup.h b/pv/view/tracegroup.h index a9f5558f..341a2a88 100644 --- a/pv/view/tracegroup.h +++ b/pv/view/tracegroup.h @@ -109,6 +109,9 @@ public: int owner_v_offset() const; void update_viewport(); + +private Q_SLOTS: + void on_ungroup(); }; } // view