X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fviews%2Ftabular_decoder%2Fview.cpp;h=2283d68ce780d0300f9d4b3a05464ff88f2089b8;hb=009fc9ae42ecccd3802f549b39c19a2ba895959d;hp=00f6e20a5d00120381d61a36fa134eaf2e945c7a;hpb=6d46525fb5566856d01deac5a7787699b17cc4e4;p=pulseview.git diff --git a/pv/views/tabular_decoder/view.cpp b/pv/views/tabular_decoder/view.cpp index 00f6e20a..2283d68c 100644 --- a/pv/views/tabular_decoder/view.cpp +++ b/pv/views/tabular_decoder/view.cpp @@ -45,6 +45,7 @@ using pv::data::decode::Decoder; using pv::util::Timestamp; using std::make_shared; +using std::max; using std::shared_ptr; namespace pv { @@ -56,6 +57,12 @@ const char* SaveTypeNames[SaveTypeCount] = { "CSV, fields quoted" }; +const char* ViewModeNames[ViewModeCount] = { + "Show all", + "Show all and focus on newest", + "Show visible in main view" +}; + QSize QCustomTableView::minimumSizeHint() const { QSize size(QTableView::sizeHint()); @@ -82,6 +89,8 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : // Note: Place defaults in View::reset_view_state(), not here parent_(parent), decoder_selector_(new QComboBox()), + hide_hidden_cb_(new QCheckBox()), + view_mode_selector_(new QComboBox()), save_button_(new QToolButton()), save_action_(new QAction(this)), table_view_(new QCustomTableView()), @@ -102,13 +111,27 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : toolbar->addWidget(decoder_selector_); toolbar->addSeparator(); toolbar->addWidget(save_button_); + toolbar->addSeparator(); + toolbar->addWidget(view_mode_selector_); + toolbar->addSeparator(); + toolbar->addWidget(hide_hidden_cb_); connect(decoder_selector_, SIGNAL(currentIndexChanged(int)), this, SLOT(on_selected_decoder_changed(int))); + connect(view_mode_selector_, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_view_mode_changed(int))); + connect(hide_hidden_cb_, SIGNAL(toggled(bool)), + this, SLOT(on_hide_hidden_changed(bool))); // Configure widgets decoder_selector_->setSizeAdjustPolicy(QComboBox::AdjustToContents); + for (int i = 0; i < ViewModeCount; i++) + view_mode_selector_->addItem(ViewModeNames[i], QVariant::fromValue(i)); + + hide_hidden_cb_->setText(tr("Hide Hidden Rows/Classes")); + hide_hidden_cb_->setChecked(true); + // Configure actions save_action_->setText(tr("&Save...")); save_action_->setIcon(QIcon::fromTheme("document-save-as", @@ -123,7 +146,7 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : for (int i = 0; i < SaveTypeCount; i++) { QAction *const action = save_menu->addAction(tr(SaveTypeNames[i])); - action->setData(qVariantFromValue(i)); + action->setData(QVariant::fromValue(i)); } save_button_->setMenu(save_menu); @@ -134,11 +157,12 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : table_view_->setModel(model_); table_view_->setSelectionBehavior(QAbstractItemView::SelectRows); table_view_->setSelectionMode(QAbstractItemView::ContiguousSelection); - table_view_->setSortingEnabled(true); + table_view_->setSortingEnabled(false); table_view_->sortByColumn(0, Qt::AscendingOrder); const int font_height = QFontMetrics(QApplication::font()).height(); table_view_->verticalHeader()->setDefaultSectionSize((font_height * 5) / 4); + table_view_->verticalHeader()->setVisible(false); table_view_->horizontalHeader()->setStretchLastSection(true); table_view_->horizontalHeader()->setCascadingSectionResizes(true); @@ -155,9 +179,17 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) : connect(table_view_->horizontalHeader(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(on_table_header_requested(const QPoint&))); + // Set up metadata event handler + session_.metadata_obj_manager()->add_observer(this); + reset_view_state(); } +View::~View() +{ + session_.metadata_obj_manager()->remove_observer(this); +} + ViewType View::get_type() const { return ViewTypeTabularDecoder; @@ -223,13 +255,20 @@ void View::remove_decode_signal(shared_ptr signal) void View::save_settings(QSettings &settings) const { ViewBase::save_settings(settings); + + settings.setValue("view_mode", view_mode_selector_->currentIndex()); + settings.setValue("hide_hidden", hide_hidden_cb_->isChecked()); } void View::restore_settings(QSettings &settings) { - // Note: It is assumed that this function is only called once, - // immediately after restoring a previous session. ViewBase::restore_settings(settings); + + if (settings.contains("view_mode")) + view_mode_selector_->setCurrentIndex(settings.value("view_mode").toInt()); + + if (settings.contains("hide_hidden")) + hide_hidden_cb_->setChecked(settings.value("hide_hidden").toBool()); } void View::reset_data() @@ -303,7 +342,7 @@ void View::save_data_as_csv(unsigned int save_type) const if (table_view_->horizontalHeader()->isSectionHidden(column)) continue; - const QModelIndex idx = model_->index(row, column, QModelIndex()); + const QModelIndex idx = model_->index(row, column); QString s = model_->data(idx, Qt::DisplayRole).toString(); if (save_type == SaveTypeCSVEscaped) @@ -360,6 +399,36 @@ void View::on_selected_decoder_changed(int index) update_data(); } +void View::on_hide_hidden_changed(bool checked) +{ + model_->set_hide_hidden(checked); + + // Force repaint, otherwise the new selection isn't shown for some reason + table_view_->viewport()->update(); +} + +void View::on_view_mode_changed(int index) +{ + if (index == ViewModeVisible) { + MetadataObject *md_obj = + session_.metadata_obj_manager()->find_object_by_type(MetadataObjMainViewRange); + assert(md_obj); + + int64_t start_sample = md_obj->value(MetadataValueStartSample).toLongLong(); + int64_t end_sample = md_obj->value(MetadataValueEndSample).toLongLong(); + + model_->set_sample_range(max((int64_t)0, start_sample), + max((int64_t)0, end_sample)); + } else { + // Reset the model's data range + model_->set_sample_range(0, 0); + } + + if (index == ViewModeLatest) + table_view_->scrollTo(model_->index(model_->rowCount() - 1, 0), + QAbstractItemView::PositionAtBottom); +} + void View::on_signal_name_changed(const QString &name) { (void)name; @@ -390,8 +459,14 @@ void View::on_signal_color_changed(const QColor &color) void View::on_new_annotations() { - if (!delayed_view_updater_.isActive()) - delayed_view_updater_.start(); + if (view_mode_selector_->currentIndex() == ViewModeLatest) { + update_data(); + table_view_->scrollTo(model_->index(model_->rowCount() - 1, 0), + QAbstractItemView::PositionAtBottom); + } else { + if (!delayed_view_updater_.isActive()) + delayed_view_updater_.start(); + } } void View::on_decoder_reset() @@ -494,6 +569,33 @@ void View::on_table_header_toggled(bool checked) 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(); + + model_->set_sample_range(max((int64_t)0, start_sample), + max((int64_t)0, end_sample)); + } + + if (obj->type() == MetadataObjMousePos) { + QModelIndex first_visual_idx = table_view_->indexAt(table_view_->rect().topLeft()); + QModelIndex last_visual_idx = table_view_->indexAt(table_view_->rect().bottomLeft()); + + model_->update_highlighted_rows(first_visual_idx, last_visual_idx, + obj->value(MetadataValueStartSample).toLongLong()); + } +} + void View::perform_delayed_view_update() { update_data();