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

View File

@ -275,6 +275,12 @@ protected slots:
*/
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
*