#include "view.hpp"
#include "pv/globalsettings.hpp"
+#include "pv/session.hpp"
#include "pv/util.hpp"
#include "pv/data/decode/decoder.hpp"
// Set up the table view
table_view_->setModel(model_);
+ table_view_->setSelectionBehavior(QAbstractItemView::SelectRows);
+ table_view_->setSelectionMode(QAbstractItemView::SingleSelection);
table_view_->setSortingEnabled(true);
table_view_->sortByColumn(0, Qt::AscendingOrder);
table_view_->horizontalHeader()->setStretchLastSection(true);
table_view_->horizontalHeader()->setCascadingSectionResizes(true);
table_view_->horizontalHeader()->setSectionsMovable(true);
+ table_view_->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
table_view_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
parent->setSizePolicy(table_view_->sizePolicy());
+ connect(table_view_, SIGNAL(clicked(const QModelIndex&)),
+ this, SLOT(on_table_item_clicked(const QModelIndex&)));
+ connect(table_view_, SIGNAL(doubleClicked(const QModelIndex&)),
+ this, SLOT(on_table_item_double_clicked(const QModelIndex&)));
+ connect(table_view_->horizontalHeader(), SIGNAL(customContextMenuRequested(const QPoint&)),
+ this, SLOT(on_table_header_requested(const QPoint&)));
+
reset_view_state();
}
save_data();
}
+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 Annotation* ann = static_cast<const Annotation*>(index.internalPointer());
+
+ 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 = 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::perform_delayed_view_update()
{
update_data();
set_scale_offset(scale.convert_to<double>(), extents.first);
}
+void View::focus_on_range(uint64_t start_sample, uint64_t end_sample)
+{
+ assert(viewport_);
+ const int w = viewport_->width();
+ if (w <= 0)
+ return;
+
+ const double samplerate = session_.get_samplerate();
+
+ const uint64_t sample_delta = (end_sample - start_sample);
+
+ // Note: We add 20% margin on the left and 5% on the right
+ const Timestamp delta = (sample_delta * 1.25) / samplerate;
+
+ const Timestamp scale = max(min(delta / w, MaxScale), MinScale);
+ const Timestamp offset = (start_sample - sample_delta * 0.20) / samplerate;
+
+ set_scale_offset(scale.convert_to<double>(), offset);
+}
+
void View::set_scale_offset(double scale, const Timestamp& offset)
{
// Disable sticky scrolling / always zoom to fit when acquisition runs