+ dataset_ = all_annotations_;
+
+ if (!dataset_ || dataset_->empty()) {
+ prev_segment_ = current_segment;
+ return;
+ }
+
+ const size_t new_row_count = dataset_->size() - 1;
+
+ // Force the view associated with this model to update when the segment changes
+ if (prev_segment_ != current_segment) {
+ dataChanged(index(0, 0), index(new_row_count, 0));
+ layoutChanged();
+ } else {
+ // Force the view associated with this model to update when we have more annotations
+ if (prev_last_row_ < new_row_count) {
+ dataChanged(index(prev_last_row_, 0), index(new_row_count, 0));
+ layoutChanged();
+ }
+ }
+
+ prev_segment_ = current_segment;
+ prev_last_row_ = new_row_count;
+}
+
+void AnnotationCollectionModel::set_hide_hidden(bool hide_hidden)
+{
+ 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);