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.
This commit is contained in:
2021-09-14 12:11:30 +02:00
parent 1ad53a354f
commit 5b75b8cb7e
4 changed files with 22 additions and 2 deletions

View File

@@ -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 &currentIndex : 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();

View File

@@ -110,6 +110,8 @@ private:
QAction *gotoAction;
QAction *editAction;
QAction *deleteAction;
QAction *selectAllAction;
QAction *deselectAllAction;
QItemSelectionModel *internalSelectionModel;
};

View File

@@ -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);

View File

@@ -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()