]> sigrok.org Git - pulseview.git/blobdiff - pv/data/decode/rowdata.cpp
TabularDecView: Make the model/view work
[pulseview.git] / pv / data / decode / rowdata.cpp
index 80d56aabb41c8fda4da8a89fc795241638ba4563..fc1480a117c590278b57fd57846d55f38f668fec 100644 (file)
@@ -49,7 +49,7 @@ uint64_t RowData::get_annotation_count() const
 }
 
 void RowData::get_annotation_subset(
-       vector<const pv::data::decode::Annotation*> &dest,
+       deque<const pv::data::decode::Annotation*> &dest,
        uint64_t start_sample, uint64_t end_sample) const
 {
        // Determine whether we must apply per-class filtering or not
@@ -68,7 +68,6 @@ void RowData::get_annotation_subset(
 
        if (all_ann_classes_enabled) {
                // No filtering, send everyting out as-is
-               dest.reserve(dest.size() + annotations_.size());
                for (const auto& annotation : annotations_)
                        if ((annotation.end_sample() > start_sample) &&
                                (annotation.start_sample() <= end_sample))
@@ -82,9 +81,8 @@ void RowData::get_annotation_subset(
                                if (c->visible)
                                        class_visible[c->id] = 1;
 
-                       dest.reserve(dest.size() + annotations_.size());
                        for (const auto& annotation : annotations_)
-                               if ((class_visible[annotation.ann_class()]) &&
+                               if ((class_visible[annotation.ann_class_id()]) &&
                                        (annotation.end_sample() > start_sample) &&
                                        (annotation.start_sample() <= end_sample))
                                        dest.push_back(&annotation);
@@ -92,8 +90,10 @@ void RowData::get_annotation_subset(
        }
 }
 
-void RowData::emplace_annotation(srd_proto_data *pdata)
+const Annotation* RowData::emplace_annotation(srd_proto_data *pdata)
 {
+       const Annotation* result = nullptr;
+
        // We insert the annotation in a way so that the annotation list
        // is sorted by start sample. Otherwise, we'd have to sort when
        // painting, which is expensive
@@ -110,11 +110,15 @@ void RowData::emplace_annotation(srd_proto_data *pdata)
                if (it != annotations_.begin())
                        it++;
 
-               annotations_.insert(it, Annotation(pdata, row_));
+               it = annotations_.emplace(it, pdata, row_);
+               result = &(*it);
        } else {
                annotations_.emplace_back(pdata, row_);
+               result = &(annotations_.back());
                prev_ann_start_sample_ = pdata->start_sample;
        }
+
+       return result;
 }
 
 }  // namespace decode