]> sigrok.org Git - pulseview.git/blobdiff - pv/views/tabular_decoder/view.cpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / views / tabular_decoder / view.cpp
index 14ae50a2941e8d56d8a532bd1505b566f67921b4..c1d7429080a221d0d3015d66b8f9fdece849ccb2 100644 (file)
@@ -139,6 +139,14 @@ QSize CustomTableView::sizeHint() const
        return minimumSizeHint();
 }
 
+void CustomTableView::keyPressEvent(QKeyEvent *event)
+{
+       if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter))
+               activatedByKey(currentIndex());
+       else
+               QTableView::keyPressEvent(event);
+}
+
 
 View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        ViewBase(session, is_main_view, parent),
@@ -194,7 +202,11 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        save_action_->setText(tr("&Save..."));
        save_action_->setIcon(QIcon::fromTheme("document-save-as",
                QIcon(":/icons/document-save-as.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       save_action_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
+#else
        save_action_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+#endif
        connect(save_action_, SIGNAL(triggered(bool)),
                this, SLOT(on_actionSave_triggered()));
 
@@ -239,6 +251,8 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
                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_, SIGNAL(activatedByKey(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&)));
 
@@ -460,6 +474,9 @@ void View::on_selected_decoder_changed(int index)
        }
 
        update_data();
+
+       // Force repaint, otherwise the new selection isn't shown for some reason
+       table_view_->viewport()->update();
 }
 
 void View::on_hide_hidden_changed(bool checked)
@@ -522,7 +539,8 @@ void View::on_signal_color_changed(const QColor &color)
 {
        (void)color;
 
-       table_view_->update();
+       // Force immediate repaint, otherwise it's updated after the header popup is closed
+       table_view_->viewport()->update();
 }
 
 void View::on_new_annotations()
@@ -599,7 +617,10 @@ void View::on_table_item_clicked(const QModelIndex& index)
 
 void View::on_table_item_double_clicked(const QModelIndex& index)
 {
-       const Annotation* ann = static_cast<const Annotation*>(index.internalPointer());
+       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();
 
@@ -613,7 +634,8 @@ void View::on_table_header_requested(const QPoint& pos)
        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();
+               const QString title =
+                       filter_proxy_model_->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString();
                QAction* action = new QAction(title, this);
 
                action->setCheckable(true);
@@ -644,7 +666,6 @@ void View::on_metadata_object_changed(MetadataObject* obj,
        // 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)) {
@@ -671,6 +692,9 @@ void View::on_metadata_object_changed(MetadataObject* obj,
                                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();
                }
        }
 }