]> sigrok.org Git - pulseview.git/commitdiff
Flag: Added delete key support
authorJoel Holdsworth <redacted>
Sat, 20 Dec 2014 08:50:26 +0000 (08:50 +0000)
committerJoel Holdsworth <redacted>
Sun, 28 Dec 2014 18:52:53 +0000 (18:52 +0000)
pv/view/cursorheader.cpp
pv/view/cursorheader.hpp
pv/view/flag.cpp
pv/view/flag.hpp
pv/view/header.cpp
pv/view/marginwidget.cpp
pv/view/timeitem.hpp

index fbc6e2e791d53eccf26140896fae83291f607714..efc9205e06f05a3885b8bc11802420b6725abd54 100644 (file)
@@ -49,7 +49,6 @@ CursorHeader::CursorHeader(View &parent) :
        MarginWidget(parent),
        textHeight_(calculateTextHeight())
 {
-       setMouseTracking(true);
 }
 
 QSize CursorHeader::sizeHint() const
@@ -162,5 +161,18 @@ void CursorHeader::mouseDoubleClickEvent(QMouseEvent *e)
        view_.add_flag(view_.offset() + ((double)e->x() + 0.5) * view_.scale());
 }
 
+void CursorHeader::keyPressEvent(QKeyEvent *e)
+{
+       assert(e);
+
+       if (e->key() == Qt::Key_Delete)
+       {
+               const vector< shared_ptr<TimeItem> > items(view_.time_items());
+               for (auto &i : items)
+                       if (i->selected())
+                               i->delete_pressed();
+       }
+}
+
 } // namespace view
 } // namespace pv
index 8db6408622d76430ac0cd39cece7699aae80f1cc..ff732856ee03f163f0d9e3310552a99d1c9c9c61 100644 (file)
@@ -62,6 +62,9 @@ private:
 
        void mouseDoubleClickEvent(QMouseEvent *e);
 
+       void keyPressEvent(QKeyEvent *e);
+
+private:
        int calculateTextHeight();
 
        std::shared_ptr<TimeItem> mouse_down_item_;
index 53b0feefa07b77c4ecce071b99358490a4fe6012..2ee8ced4972413439d67ba938014c2dee5617e46 100644 (file)
@@ -43,7 +43,8 @@ Flag::Flag(View &view, double time, const QString &text) :
 }
 
 Flag::Flag(const Flag &flag) :
-       TimeMarker(flag.view_, FillColour, flag.time_)
+       TimeMarker(flag.view_, FillColour, flag.time_),
+       std::enable_shared_from_this<pv::view::Flag>(flag)
 {
 }
 
@@ -73,6 +74,11 @@ pv::widgets::Popup* Flag::create_popup(QWidget *parent)
        return popup;
 }
 
+void Flag::delete_pressed()
+{
+       view_.remove_flag(shared_ptr<Flag>(shared_from_this()));
+}
+
 void Flag::on_text_changed(const QString &text)
 {
        text_ = text;
index 659d5cc1c55143aaa88bf45113f980f9a2483cf9..fdebe1c0a6b4139b9675aa57c1771ed151fc7041 100644 (file)
 #ifndef PULSEVIEW_PV_VIEW_FLAG_H
 #define PULSEVIEW_PV_VIEW_FLAG_H
 
+#include <memory>
+
 #include "timemarker.hpp"
 
 namespace pv {
 namespace view {
 
-class Flag : public TimeMarker
+class Flag : public TimeMarker,
+       public std::enable_shared_from_this<pv::view::Flag>
 {
        Q_OBJECT
 
@@ -59,6 +62,8 @@ public:
 
        pv::widgets::Popup* create_popup(QWidget *parent);
 
+       void delete_pressed();
+
 private Q_SLOTS:
        void on_text_changed(const QString &text);
 
index 780b1e3db5f9894c39e845fd6a549e855976038a..4b02c1944d35540bf78f1c220716b213ce4433e4 100644 (file)
@@ -62,9 +62,6 @@ static bool item_selected(shared_ptr<RowItem> r)
 Header::Header(View &parent) :
        MarginWidget(parent)
 {
-       setFocusPolicy(Qt::ClickFocus);
-       setMouseTracking(true);
-
        connect(&view_, SIGNAL(signals_moved()),
                this, SLOT(on_signals_moved()));
 }
index e44233c80291c8a1cb1bdd2a5078ef9d505d6211..f8302f646f73867589e68027580fb8435e378895 100644 (file)
@@ -31,6 +31,8 @@ MarginWidget::MarginWidget(View &parent) :
        dragging_(false)
 {
        setAttribute(Qt::WA_NoSystemBackground, true);
+       setFocusPolicy(Qt::ClickFocus);
+       setMouseTracking(true);
 }
 
 void MarginWidget::clear_selection()
index 80fecb5dda316caa587f6616d6af814b5187d041..8374244215807b5c34e4433c441c8f4a19582e6d 100644 (file)
@@ -29,6 +29,7 @@ namespace view {
 class View;
 
 class TimeItem : public ViewItem
+
 {
        Q_OBJECT