+ hide_hidden_ = hide_hidden;
+
+ if (hide_hidden_) {
+ dataset_ = &all_annotations_without_hidden_;
+ update_annotations_without_hidden();
+ } else {
+ dataset_ = all_annotations_;
+ all_annotations_without_hidden_.clear(); // To conserve memory
+ }
+
+ if (dataset_)
+ dataChanged(index(0, 0), index(dataset_->size() - 1, 0));
+ else
+ dataChanged(QModelIndex(), QModelIndex());
+
+ layoutChanged();
+}
+
+void AnnotationCollectionModel::update_annotations_without_hidden()
+{
+ uint64_t count = 0;
+
+ if (!all_annotations_ || all_annotations_->empty()) {
+ all_annotations_without_hidden_.clear();
+ return;
+ }
+
+ for (const Annotation* ann : *all_annotations_) {
+ if (!ann->visible())
+ continue;
+
+ if (all_annotations_without_hidden_.size() < (count + 100))
+ all_annotations_without_hidden_.resize(count + 100);
+
+ all_annotations_without_hidden_[count++] = ann;
+ }
+
+ all_annotations_without_hidden_.resize(count);
+}
+
+QModelIndex AnnotationCollectionModel::update_highlighted_rows(QModelIndex first,
+ QModelIndex last, int64_t sample_num)
+{
+ bool has_highlight = false;
+ QModelIndex result;
+
+ highlight_sample_num_ = sample_num;
+
+ if (!dataset_ || dataset_->empty())
+ return result;
+
+ if (sample_num >= 0) {
+ last = last.sibling(last.row() + 1, 0);
+
+ // Check if there are any annotations visible in the table view that
+ // we would need to highlight - only then do we do so
+ QModelIndex index = first;
+ do {
+ const Annotation* ann =
+ static_cast<const Annotation*>(index.internalPointer());
+ assert(ann);
+
+ if (((int64_t)ann->start_sample() <= sample_num) &&
+ ((int64_t)ann->end_sample() >= sample_num)) {
+ result = index;
+ has_highlight = true;
+ break;
+ }
+
+ index = index.sibling(index.row() + 1, 0);
+ } while (index != last);
+ }
+
+ if (has_highlight || had_highlight_before_) {
+ dataChanged(first, last);
+ layoutChanged();
+ }
+
+ had_highlight_before_ = has_highlight;
+
+ return result;
+}
+
+void AnnotationCollectionModel::on_annotation_visibility_changed()
+{
+ if (!hide_hidden_)
+ return;
+
+ update_annotations_without_hidden();
+
+ if (dataset_)
+ dataChanged(index(0, 0), index(dataset_->size() - 1, 0));
+ else
+ dataChanged(QModelIndex(), QModelIndex());