+ if (action)
+ save_type = action->data().toInt();
+
+ save_data_as_csv(save_type);
+}
+
+void View::on_table_item_clicked(const QModelIndex& index)
+{
+ (void)index;
+
+ // Force repaint, otherwise the new selection isn't shown for some reason
+ table_view_->viewport()->update();
+}
+
+void View::on_table_item_double_clicked(const QModelIndex& index)
+{
+ const QModelIndex src_idx = filter_proxy_model_->mapToSource(index);
+
+ const Annotation* ann = static_cast<const Annotation*>(src_idx.internalPointer());
+ assert(ann);
+
+ shared_ptr<views::ViewBase> main_view = session_.main_view();
+
+ main_view->focus_on_range(ann->start_sample(), ann->end_sample());
+}
+
+void View::on_table_header_requested(const QPoint& pos)
+{
+ QMenu* menu = new QMenu(this);
+
+ for (int i = 0; i < table_view_->horizontalHeader()->count(); i++) {
+ int column = table_view_->horizontalHeader()->logicalIndex(i);
+
+ const QString title =
+ filter_proxy_model_->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString();
+ QAction* action = new QAction(title, this);
+
+ action->setCheckable(true);
+ action->setChecked(!table_view_->horizontalHeader()->isSectionHidden(column));
+ action->setData(column);
+
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(on_table_header_toggled(bool)));
+
+ menu->addAction(action);
+ }
+
+ menu->popup(table_view_->horizontalHeader()->viewport()->mapToGlobal(pos));
+}
+
+void View::on_table_header_toggled(bool checked)
+{
+ QAction* action = qobject_cast<QAction*>(QObject::sender());
+ assert(action);
+
+ const int column = action->data().toInt();
+
+ table_view_->horizontalHeader()->setSectionHidden(column, !checked);
+}
+
+void View::on_metadata_object_changed(MetadataObject* obj,
+ MetadataValueType value_type)
+{
+ // Check if we need to update the model's data range. We only work on the
+ // end sample value because the start sample value is updated first and
+ // we don't want to update the model twice
+ if ((view_mode_selector_->currentIndex() == ViewModeVisible) &&
+ (obj->type() == MetadataObjMainViewRange) &&
+ (value_type == MetadataValueEndSample)) {
+
+ int64_t start_sample = obj->value(MetadataValueStartSample).toLongLong();
+ int64_t end_sample = obj->value(MetadataValueEndSample).toLongLong();
+
+ filter_proxy_model_->set_sample_range(max((int64_t)0, start_sample),
+ max((int64_t)0, end_sample));
+ }
+
+ if (obj->type() == MetadataObjMousePos) {
+ QModelIndex first_visible_idx =
+ filter_proxy_model_->mapToSource(filter_proxy_model_->index(0, 0));
+ QModelIndex last_visible_idx =
+ filter_proxy_model_->mapToSource(filter_proxy_model_->index(filter_proxy_model_->rowCount() - 1, 0));
+
+ if (first_visible_idx.isValid()) {
+ const QModelIndex first_highlighted_idx =
+ model_->update_highlighted_rows(first_visible_idx, last_visible_idx,
+ obj->value(MetadataValueStartSample).toLongLong());
+
+ if (view_mode_selector_->currentIndex() == ViewModeVisible) {
+ const QModelIndex idx = filter_proxy_model_->mapFromSource(first_highlighted_idx);
+ table_view_->scrollTo(idx, QAbstractItemView::EnsureVisible);
+ }
+
+ // Force repaint, otherwise the table doesn't immediately update for some reason
+ table_view_->viewport()->update();
+ }
+ }