From 5b75b8cb7e166304355b8ad52039a10a997b480b Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Tue, 14 Sep 2021 12:11:30 +0200 Subject: [PATCH] Fix a bug in TraceScroller and improve comment selection. Comments will now stay selected when dragging the view. Deselection can be achieved by triggering the deselectAll action in the context menu, by deselecting the comments in the comment view or by right-clicking a specific comment in the plot. --- .../traceAnalyzer/businessObjects/commentmodel.cpp | 14 ++++++++++++++ .../traceAnalyzer/businessObjects/commentmodel.h | 2 ++ DRAMSys/traceAnalyzer/presentation/traceplot.cpp | 5 +++-- .../traceAnalyzer/presentation/tracescroller.cpp | 3 +++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/DRAMSys/traceAnalyzer/businessObjects/commentmodel.cpp b/DRAMSys/traceAnalyzer/businessObjects/commentmodel.cpp index ebe15216..c6cdad28 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/commentmodel.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/commentmodel.cpp @@ -43,6 +43,8 @@ CommentModel::CommentModel(QObject *parent) : QAbstractTableModel(parent), gotoAction(new QAction("Goto comment", this)), editAction(new QAction("Edit comment", this)), deleteAction(new QAction("Delete comment", this)), + selectAllAction(new QAction("Select all comments", this)), + deselectAllAction(new QAction("Deselect all comments", this)), internalSelectionModel(new QItemSelectionModel(this, this)) { setUpActions(); @@ -69,6 +71,16 @@ void CommentModel::setUpActions() for (const QModelIndex ¤tIndex : indexes) removeComment(currentIndex); }); + + QObject::connect(selectAllAction, &QAction::triggered, this, [=](){ + QModelIndex topLeft = index(0, 0); + QModelIndex bottomRight = index(rowCount() - 1, columnCount() - 1); + internalSelectionModel->select(QItemSelection(topLeft, bottomRight), + QItemSelectionModel::Select | QItemSelectionModel::Rows); + }); + + QObject::connect(deselectAllAction, &QAction::triggered, + internalSelectionModel, &QItemSelectionModel::clearSelection); } int CommentModel::rowCount(const QModelIndex &parent) const @@ -168,6 +180,8 @@ void CommentModel::openContextMenu() QMenu *menu = new QMenu(); menu->addActions({gotoAction, editAction, deleteAction}); + menu->addSeparator(); + menu->addActions({selectAllAction, deselectAllAction}); QObject::connect(menu, &QMenu::aboutToHide, [=]() { menu->deleteLater(); diff --git a/DRAMSys/traceAnalyzer/businessObjects/commentmodel.h b/DRAMSys/traceAnalyzer/businessObjects/commentmodel.h index 93249781..a9e165a6 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/commentmodel.h +++ b/DRAMSys/traceAnalyzer/businessObjects/commentmodel.h @@ -110,6 +110,8 @@ private: QAction *gotoAction; QAction *editAction; QAction *deleteAction; + QAction *selectAllAction; + QAction *deselectAllAction; QItemSelectionModel *internalSelectionModel; }; diff --git a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp index 905088a7..c6d4133e 100644 --- a/DRAMSys/traceAnalyzer/presentation/traceplot.cpp +++ b/DRAMSys/traceAnalyzer/presentation/traceplot.cpp @@ -739,7 +739,7 @@ void TracePlot::SelectComment(int x) const QModelIndex index = commentModel->hoveredComment(timespan); if (!index.isValid()) - commentModel->selectionModel()->clearSelection(); + return; if (keyPressData.ctrlPressed) commentModel->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Toggle | QItemSelectionModel::Rows); @@ -758,8 +758,9 @@ Timespan TracePlot::hoveredTimespan(int x) const void TracePlot::openContextMenu(const QPoint &pos, const QPoint &mouseDown) { contextMenuMouseDown = mouseDown; + Timespan timespan = hoveredTimespan(mouseDown.x()); - if (commentModel->selectionModel()->hasSelection()) + if (commentModel->hoveredComment(timespan).isValid()) commentModel->openContextMenu(); else contextMenu->exec(pos); diff --git a/DRAMSys/traceAnalyzer/presentation/tracescroller.cpp b/DRAMSys/traceAnalyzer/presentation/tracescroller.cpp index feaab60e..12d34018 100644 --- a/DRAMSys/traceAnalyzer/presentation/tracescroller.cpp +++ b/DRAMSys/traceAnalyzer/presentation/tracescroller.cpp @@ -130,6 +130,9 @@ void TraceScroller::connectNavigatorQ_SIGNALS() { QObject::connect(navigator, SIGNAL(currentTraceTimeChanged()), this, SLOT(currentTraceTimeChanged())); + + QObject::connect(navigator, SIGNAL(selectedTransactionsChanged()), this, + SLOT(selectedTransactionsChanged())); } Timespan TraceScroller::GetCurrentTimespan()