Various minor whitespace and consistency fixes.
[pulseview.git] / pv / view / view.cpp
index 7de1c792c06fa9880eee2d295e4cc8fc9672ef19..c6a6afd323dcccac191061bfac65c640bac36c68 100644 (file)
@@ -48,6 +48,7 @@
 #include "ruler.hpp"
 #include "signal.hpp"
 #include "tracegroup.hpp"
+#include "triggermarker.hpp"
 #include "view.hpp"
 #include "viewport.hpp"
 
@@ -114,6 +115,7 @@ View::View(Session &session, QWidget *parent) :
        show_cursors_(false),
        cursors_(new CursorPair(*this)),
        next_flag_text_('A'),
+       trigger_markers_(),
        hover_point_(-1, -1)
 {
        connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
@@ -207,6 +209,10 @@ vector< shared_ptr<TimeItem> > View::time_items() const
        items.push_back(cursors_);
        items.push_back(cursors_->first());
        items.push_back(cursors_->second());
+
+       for (auto trigger_marker : trigger_markers_)
+               items.push_back(trigger_marker);
+
        return items;
 }
 
@@ -402,8 +408,7 @@ pair<Timestamp, Timestamp> View::get_time_extents() const
 {
        boost::optional<Timestamp> left_time, right_time;
        const set< shared_ptr<SignalData> > visible_data = get_visible_data();
-       for (const shared_ptr<SignalData> d : visible_data)
-       {
+       for (const shared_ptr<SignalData> d : visible_data) {
                const vector< shared_ptr<Segment> > segments =
                        d->segments();
                for (const shared_ptr<Segment> &s : segments) {
@@ -462,8 +467,10 @@ void View::add_flag(const Timestamp& 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);
 }
 
@@ -518,6 +525,12 @@ void View::restack_all_trace_tree_items()
                i->animate_to_layout_v_offset();
 }
 
+void View::trigger_event(util::Timestamp location)
+{
+       trigger_markers_.push_back(shared_ptr<TriggerMarker>(
+               new TriggerMarker(*this, location)));
+}
+
 void View::get_scroll_layout(double &length, Timestamp &offset) const
 {
        const pair<Timestamp, Timestamp> extents = get_time_extents();
@@ -713,8 +726,7 @@ vector< shared_ptr<Trace> > View::extract_new_traces_for_channels(
 {
        vector< shared_ptr<Trace> > filtered_traces;
 
-       for (const auto &channel : channels)
-       {
+       for (const auto &channel : channels) {
                const auto map_iter = signal_map.find(channel);
                if (map_iter == signal_map.end())
                        continue;
@@ -779,7 +791,7 @@ bool View::eventFilter(QObject *object, QEvent *event)
 
 bool View::viewportEvent(QEvent *e)
 {
-       switch(e->type()) {
+       switch (e->type()) {
        case QEvent::Paint:
        case QEvent::MouseButtonPress:
        case QEvent::MouseButtonRelease:
@@ -790,7 +802,6 @@ bool View::viewportEvent(QEvent *e)
        case QEvent::TouchUpdate:
        case QEvent::TouchEnd:
                return false;
-
        default:
                return QAbstractScrollArea::viewportEvent(e);
        }
@@ -906,8 +917,7 @@ void View::signals_changed()
                signal_map[sig->channel()] = sig;
 
        // Populate channel groups
-       for (auto entry : sr_dev->channel_groups())
-       {
+       for (auto entry : sr_dev->channel_groups()) {
                const shared_ptr<sigrok::ChannelGroup> &group = entry.second;
 
                if (group->channels().size() <= 1)
@@ -1005,9 +1015,12 @@ void View::signals_changed()
 
 void View::capture_state_updated(int state)
 {
-       if (state == Session::Running)
+       if (state == Session::Running) {
                set_time_unit(util::TimeUnit::Samples);
 
+               trigger_markers_.clear();
+       }
+
        if (state == Session::Stopped) {
                // After acquisition has stopped we need to re-calculate the ticks once
                // as it's otherwise done when the user pans or zooms, which is too late