Flag: Added flag time markers
[pulseview.git] / pv / view / view.cpp
index c53c02e3abd44f8242dc7bd1ceaf3d43a38cf02b..e43522577e9c985e3808d5cf5edce5b5c4365017 100644 (file)
@@ -60,7 +60,6 @@ using pv::data::SignalData;
 using pv::data::Segment;
 using pv::util::format_time;
 
-using std::back_inserter;
 using std::deque;
 using std::dynamic_pointer_cast;
 using std::list;
@@ -105,6 +104,7 @@ View::View(Session &session, QWidget *parent) :
        tick_prefix_(0),
        show_cursors_(false),
        cursors_(new CursorPair(*this)),
+       next_flag_text_('A'),
        hover_point_(-1, -1)
 {
        connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
@@ -121,11 +121,6 @@ View::View(Session &session, QWidget *parent) :
        connect(&session_, SIGNAL(frame_ended()),
                this, SLOT(data_updated()));
 
-       connect(cursors_->first().get(), SIGNAL(time_changed()),
-               this, SLOT(marker_time_changed()));
-       connect(cursors_->second().get(), SIGNAL(time_changed()),
-               this, SLOT(marker_time_changed()));
-
        connect(header_, SIGNAL(signals_moved()),
                this, SLOT(on_signals_moved()));
 
@@ -197,7 +192,8 @@ const Viewport* View::viewport() const
 
 vector< shared_ptr<TimeItem> > View::time_items() const
 {
-       vector< shared_ptr<TimeItem> > items;
+       const vector<shared_ptr<Flag>> f(flags());
+       vector<shared_ptr<TimeItem>> items(f.begin(), f.end());
        items.push_back(cursors_);
        items.push_back(cursors_->first());
        items.push_back(cursors_->second());
@@ -369,6 +365,32 @@ std::shared_ptr<CursorPair> View::cursors() const
        return cursors_;
 }
 
+void View::add_flag(double time)
+{
+       flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
+               QString("%1").arg(next_flag_text_))));
+       next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
+               (next_flag_text_ + 1);
+       time_item_appearance_changed(true, true);
+}
+
+void View::remove_flag(std::shared_ptr<Flag> flag)
+{
+       flags_.remove(flag);
+       time_item_appearance_changed(true, true);
+}
+
+vector< std::shared_ptr<Flag> > View::flags() const
+{
+       vector< std::shared_ptr<Flag> > flags(flags_.begin(), flags_.end());
+       stable_sort(flags.begin(), flags.end(),
+               [](const shared_ptr<Flag> &a, const shared_ptr<Flag> &b) {
+                       return a->time() < b->time();
+               });
+
+       return flags;
+}
+
 const QPoint& View::hover_point() const
 {
        return hover_point_;
@@ -615,6 +637,14 @@ void View::row_item_appearance_changed(bool label, bool content)
                viewport_->update();
 }
 
+void View::time_item_appearance_changed(bool label, bool content)
+{
+       if (label)
+               cursorheader_->update();
+       if (content)
+               viewport_->update();
+}
+
 void View::extents_changed(bool horz, bool vert)
 {
        sticky_events_ |=
@@ -728,12 +758,6 @@ void View::data_updated()
        viewport_->update();
 }
 
-void View::marker_time_changed()
-{
-       cursorheader_->update();
-       viewport_->update();
-}
-
 void View::on_signals_moved()
 {
        update_scroll();