GUI: copy selected warnings

This commit is contained in:
Daniel Marjamäki 2018-04-13 17:31:51 +02:00
parent ff2c376fe8
commit c4c678383e
2 changed files with 29 additions and 111 deletions

View File

@ -604,7 +604,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
this, SLOT(context(int))); this, SLOT(context(int)));
} }
// Add menuitems to copy full path/filename to clipboard // Add popup menuitems
if (mContextItem) { if (mContextItem) {
if (mApplications->getApplicationCount() > 0) { if (mApplications->getApplicationCount() > 0) {
menu.addSeparator(); menu.addSeparator();
@ -612,22 +612,13 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
//Create an action for the application //Create an action for the application
QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu); QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu);
QAction *copyfilename = new QAction(tr("Copy filename"), &menu); QAction *copy = new QAction(tr("Copy"), &menu);
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 *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);
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu); QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
if (multipleSelection) { if (multipleSelection) {
copyfilename->setDisabled(true);
copypath->setDisabled(true);
copymessage->setDisabled(true);
copymessageid->setDisabled(true);
copylinenr->setDisabled(true);
hideallid->setDisabled(true); hideallid->setDisabled(true);
opencontainingfolder->setDisabled(true); opencontainingfolder->setDisabled(true);
} }
@ -638,11 +629,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addAction(recheckSelectedFiles); menu.addAction(recheckSelectedFiles);
menu.addSeparator(); menu.addSeparator();
menu.addAction(copyfilename); menu.addAction(copy);
menu.addAction(copypath);
menu.addAction(copymessage);
menu.addAction(copymessageid);
menu.addAction(copylinenr);
menu.addSeparator(); menu.addSeparator();
menu.addAction(hide); menu.addAction(hide);
menu.addAction(hideallid); menu.addAction(hideallid);
@ -651,11 +638,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addAction(opencontainingfolder); menu.addAction(opencontainingfolder);
connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(recheckSelectedFiles())); connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(recheckSelectedFiles()));
connect(copyfilename, SIGNAL(triggered()), this, SLOT(copyFilename())); connect(copy, SIGNAL(triggered()), this, SLOT(copy()));
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(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()));
@ -858,69 +841,35 @@ QString ResultsTree::askFileDir(const QString &file)
return mCheckPath; return mCheckPath;
} }
void ResultsTree::copyFilename() void ResultsTree::copy()
{ {
copyPathToClipboard(mContextItem, false); if (!mSelectionModel)
}
void ResultsTree::copyFullPath()
{
copyPathToClipboard(mContextItem, true);
}
void ResultsTree::copyMessage()
{
if (!mContextItem)
return; return;
// Make sure we are working with the first column QModelIndexList selectedRows = mSelectionModel->selectedRows();
if (mContextItem->column() != 0) QString text;
mContextItem = mContextItem->parent()->child(mContextItem->row(), 0); foreach (QModelIndex index, selectedRows) {
QStandardItem *item = mModel.itemFromIndex(index);
QVariantMap data = mContextItem->data().toMap(); if (!item->parent())
continue;
QString message; if (item->parent()->parent())
if (data["inconclusive"].toBool()) { item = item->parent();
message = tr("[Inconclusive]"); QVariantMap data = item->data().toMap();
message += " "; if (!data.contains("id"))
} continue;
message += data["message"].toString(); QString inconclusive = data["inconclusive"].toBool() ? ",inconclusive" : "";
text += '[' + data["file"].toString() + ':' + QString::number(data["line"].toInt())
QClipboard *clipboard = QApplication::clipboard(); + "] ("
clipboard->setText(message); + QString::fromStdString(Severity::toString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data["severity"].toInt()))) + inconclusive
+ ") "
+ data["message"].toString()
+ " ["
+ data["id"].toString()
+ "]\n";
} }
void ResultsTree::copyMessageId()
{
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 messageId = data["id"].toString();
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(messageId); clipboard->setText(text);
}
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()
@ -1099,12 +1048,6 @@ void ResultsTree::quickStartApplication(const QModelIndex &index)
startApplication(mModel.itemFromIndex(index)); startApplication(mModel.itemFromIndex(index));
} }
void ResultsTree::copyPathToClipboard(QStandardItem *target, bool fullPath)
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(getFilePath(target, fullPath));
}
QString ResultsTree::getFilePath(QStandardItem *target, bool fullPath) QString ResultsTree::getFilePath(QStandardItem *target, bool fullPath)
{ {
if (target) { if (target) {

View File

@ -252,34 +252,9 @@ protected slots:
void context(int application); void context(int application);
/** /**
* @brief Slot for context menu item to copy filename to clipboard * @brief Slot for context menu item to copy selection to clipboard
*
*/ */
void copyFilename(); void copy();
/**
* @brief Slot for context menu item to copy full path to clipboard
*
*/
void copyFullPath();
/**
* @brief Slot for context menu item to the current error message to clipboard
*
*/
void copyMessage();
/**
* @brief Slot for context menu item to the current error message Id to clipboard
*
*/
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