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:
parent
d637d414e1
commit
3c5ab13a6d
|
@ -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,38 +870,57 @@ void ResultsTree::copyFullPath()
|
||||||
|
|
||||||
void ResultsTree::copyMessage()
|
void ResultsTree::copyMessage()
|
||||||
{
|
{
|
||||||
if (mContextItem) {
|
if (!mContextItem)
|
||||||
// Make sure we are working with the first column
|
return;
|
||||||
if (mContextItem->column() != 0)
|
|
||||||
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
|
|
||||||
|
|
||||||
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;
|
QVariantMap data = mContextItem->data().toMap();
|
||||||
if (data["inconclusive"].toBool()) {
|
|
||||||
message = tr("[Inconclusive]");
|
|
||||||
message += " ";
|
|
||||||
}
|
|
||||||
message += data["message"].toString();
|
|
||||||
|
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QString message;
|
||||||
clipboard->setText(message);
|
if (data["inconclusive"].toBool()) {
|
||||||
|
message = tr("[Inconclusive]");
|
||||||
|
message += " ";
|
||||||
}
|
}
|
||||||
|
message += data["message"].toString();
|
||||||
|
|
||||||
|
QClipboard *clipboard = QApplication::clipboard();
|
||||||
|
clipboard->setText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultsTree::copyMessageId()
|
void ResultsTree::copyMessageId()
|
||||||
{
|
{
|
||||||
if (mContextItem) {
|
if (!mContextItem)
|
||||||
// Make sure we are working with the first column
|
return;
|
||||||
if (mContextItem->column() != 0)
|
|
||||||
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0);
|
|
||||||
QVariantMap data = mContextItem->data().toMap();
|
|
||||||
|
|
||||||
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();
|
QString messageId = data["id"].toString();
|
||||||
clipboard->setText(messageId);
|
|
||||||
}
|
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()
|
void ResultsTree::hideResult()
|
||||||
|
|
|
@ -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
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue