]> sigrok.org Git - pulseview.git/commitdiff
TraceGroup: Added ungroup item
authorJoel Holdsworth <redacted>
Sat, 1 Nov 2014 10:42:48 +0000 (10:42 +0000)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:03 +0000 (10:23 +0000)
pv/view/tracegroup.cpp
pv/view/tracegroup.h

index bc63d7f2e9a80ea5576550110cf9589779bdf3ff..af756d49be6bea0a4877433223773d0b3bbc84c2 100644 (file)
 
 #include <algorithm>
 
+#include <QMenu>
+
 #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<RowItem> > items(
+               child_items().begin(), child_items().end());
+       clear_child_items();
+
+       for (shared_ptr<RowItem> 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
index a9f5558f4a381893dcae3d05c9bf36d9a9742243..341a2a8835fac28ea57f7c04c47acd867c199e4c 100644 (file)
@@ -109,6 +109,9 @@ public:
        int owner_v_offset() const;
 
        void update_viewport();
+
+private Q_SLOTS:
+       void on_ungroup();
 };
 
 } // view