+void AnnotationCollectionModel::set_sample_range(uint64_t start_sample, uint64_t end_sample)
+{
+ // Check if there's even anything to reset
+ if ((start_sample == end_sample) && (start_index_ == end_index_))
+ return;
+
+ if (!dataset_ || dataset_->empty() || (end_sample == 0)) {
+ start_index_ = 0;
+ end_index_ = 0;
+ start_sample_ = 0;
+ end_sample_ = 0;
+
+ dataChanged(QModelIndex(), QModelIndex());
+ layoutChanged();
+ return;
+ }
+
+ start_sample_ = start_sample;
+ end_sample_ = end_sample;
+
+ // Determine first and last indices into the annotation list
+ int64_t i = -1;
+ bool ann_outside_range;
+ do {
+ i++;
+
+ if (i == (int64_t)dataset_->size()) {
+ start_index_ = 0;
+ end_index_ = 0;
+
+ dataChanged(QModelIndex(), QModelIndex());
+ layoutChanged();
+ return;
+ }
+ const Annotation* ann = (*dataset_)[i];
+ ann_outside_range =
+ ((ann->start_sample() < start_sample) && (ann->end_sample() < start_sample));
+ } while (ann_outside_range);
+ start_index_ = i;
+
+ // Ideally, we would be able to set end_index_ to the last annotation that
+ // is within range. However, as annotations in the list are sorted by
+ // start sample and hierarchy level, we may encounter this scenario:
+ // [long annotation that spans across view]
+ // [short annotations that aren't seen]
+ // [short annotations that are seen]
+ // ..in which our output would only show the first long annotations.
+ // For this reason, we simply show everything after the first visible
+ // annotation for now.
+
+ end_index_ = dataset_->size();
+
+ dataChanged(index(0, 0), index((end_index_ - start_index_), 0));
+ layoutChanged();
+}
+