GUI: Add context menu entry for copying line nr (#1100)

* GUI: Add context menu entry for copying line nr

As requested in ticket 7947 (https://trac.cppcheck.net/ticket/7947) also
copying the line nr is implemented.

* Use early return for the new function and similar ones
This commit is contained in:
Sebastian 2018-03-06 15:34:14 +01:00 committed by Daniel Marjamäki
parent d637d414e1
commit 3c5ab13a6d
2 changed files with 51 additions and 22 deletions

View File

@ -616,6 +616,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
QAction *copypath = new QAction(tr("Copy full path"), &menu); QAction *copypath = new QAction(tr("Copy full path"), &menu);
QAction *copymessage = new QAction(tr("Copy message"), &menu); QAction *copymessage = new QAction(tr("Copy message"), &menu);
QAction *copymessageid = new QAction(tr("Copy message id"), &menu); QAction *copymessageid = new QAction(tr("Copy message id"), &menu);
QAction *copylinenr = new QAction(tr("Copy line nr"), &menu);
QAction *hide = new QAction(tr("Hide"), &menu); QAction *hide = new QAction(tr("Hide"), &menu);
QAction *hideallid = new QAction(tr("Hide all with id"), &menu); QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu); QAction *suppress = new QAction(tr("Suppress selected id(s)"), &menu);
@ -626,6 +627,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
copypath->setDisabled(true); copypath->setDisabled(true);
copymessage->setDisabled(true); copymessage->setDisabled(true);
copymessageid->setDisabled(true); copymessageid->setDisabled(true);
copylinenr->setDisabled(true);
hideallid->setDisabled(true); hideallid->setDisabled(true);
opencontainingfolder->setDisabled(true); opencontainingfolder->setDisabled(true);
} }
@ -640,6 +642,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addAction(copypath); menu.addAction(copypath);
menu.addAction(copymessage); menu.addAction(copymessage);
menu.addAction(copymessageid); menu.addAction(copymessageid);
menu.addAction(copylinenr);
menu.addSeparator(); menu.addSeparator();
menu.addAction(hide); menu.addAction(hide);
menu.addAction(hideallid); menu.addAction(hideallid);
@ -652,6 +655,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
connect(copypath, SIGNAL(triggered()), this, SLOT(copyFullPath())); connect(copypath, SIGNAL(triggered()), this, SLOT(copyFullPath()));
connect(copymessage, SIGNAL(triggered()), this, SLOT(copyMessage())); connect(copymessage, SIGNAL(triggered()), this, SLOT(copyMessage()));
connect(copymessageid, SIGNAL(triggered()), this, SLOT(copyMessageId())); connect(copymessageid, SIGNAL(triggered()), this, SLOT(copyMessageId()));
connect(copylinenr, SIGNAL(triggered()), this, SLOT(copyLineNr()));
connect(hide, SIGNAL(triggered()), this, SLOT(hideResult())); connect(hide, SIGNAL(triggered()), this, SLOT(hideResult()));
connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult())); connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult()));
connect(suppress, SIGNAL(triggered()), this, SLOT(suppressSelectedIds())); connect(suppress, SIGNAL(triggered()), this, SLOT(suppressSelectedIds()));
@ -866,7 +870,9 @@ void ResultsTree::copyFullPath()
void ResultsTree::copyMessage() void ResultsTree::copyMessage()
{ {
if (mContextItem) { if (!mContextItem)
return;
// Make sure we are working with the first column // Make sure we are working with the first column
if (mContextItem->column() != 0) if (mContextItem->column() != 0)
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0); mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
@ -882,12 +888,13 @@ void ResultsTree::copyMessage()
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(message); clipboard->setText(message);
}
} }
void ResultsTree::copyMessageId() void ResultsTree::copyMessageId()
{ {
if (mContextItem) { if (!mContextItem)
return;
// Make sure we are working with the first column // Make sure we are working with the first column
if (mContextItem->column() != 0) if (mContextItem->column() != 0)
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0); mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
@ -897,7 +904,23 @@ void ResultsTree::copyMessageId()
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(messageId); clipboard->setText(messageId);
} }
void ResultsTree::copyLineNr()
{
if (!mContextItem)
return;
// Make sure we are working with the first column
if (mContextItem->column() != 0)
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
QVariantMap data = mContextItem->data().toMap();
QString linenr = data["line"].toString();
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(linenr);
} }
void ResultsTree::hideResult() void ResultsTree::hideResult()

View File

@ -275,6 +275,12 @@ protected slots:
*/ */
void copyMessageId(); void copyMessageId();
/**
* @brief Slot for context menu item to copy the current error line nr to clipboard
*
*/
void copyLineNr();
/** /**
* @brief Slot for context menu item to hide the current error message * @brief Slot for context menu item to hide the current error message
* *