Skip to content

Commit 8d08357

Browse files
versatdanmar
authored andcommitted
GUI: Enhance context menu for analysis log (danmar#1014)
*Add context menu entry for copying selected log entry *Add context menu entry for copying the complete log *Do not show context menu if analysis log is empty *Renamed function log_clear to logClear so it matches the coding style in the GUI
1 parent a3bf023 commit 8d08357

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

gui/resultsview.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <QDir>
3030
#include <QDate>
3131
#include <QMenu>
32+
#include <QClipboard>
3233
#include "common.h"
3334
#include "erroritem.h"
3435
#include "resultsview.h"
@@ -406,17 +407,47 @@ void ResultsView::debugError(const ErrorItem &item)
406407
mUI.mListLog->addItem(item.ToString());
407408
}
408409

409-
void ResultsView::log_clear()
410+
void ResultsView::logClear()
410411
{
411412
mUI.mListLog->clear();
412413
}
413414

415+
void ResultsView::logCopyEntry()
416+
{
417+
const QListWidgetItem * item = mUI.mListLog->currentItem();
418+
if(nullptr != item)
419+
{
420+
QClipboard *clipboard = QApplication::clipboard();
421+
clipboard->setText(item->text());
422+
}
423+
}
424+
425+
void ResultsView::logCopyComplete()
426+
{
427+
QString logText;
428+
for(int i=0; i < mUI.mListLog->count(); ++i)
429+
{
430+
const QListWidgetItem * item = mUI.mListLog->item(i);
431+
if(nullptr != item)
432+
{
433+
logText += item->text();
434+
}
435+
}
436+
QClipboard *clipboard = QApplication::clipboard();
437+
clipboard->setText(logText);
438+
}
439+
414440
void ResultsView::on_mListLog_customContextMenuRequested(const QPoint &pos)
415441
{
416-
QPoint globalPos = mUI.mListLog->mapToGlobal(pos);
442+
if(mUI.mListLog->count() > 0)
443+
{
444+
QPoint globalPos = mUI.mListLog->mapToGlobal(pos);
417445

418-
QMenu contextMenu;
419-
contextMenu.addAction(tr("Clear Log"), this, SLOT(log_clear()));
446+
QMenu contextMenu;
447+
contextMenu.addAction(tr("Clear Log"), this, SLOT(logClear()));
448+
contextMenu.addAction(tr("Copy this Log entry"), this, SLOT(logCopyEntry()));
449+
contextMenu.addAction(tr("Copy complete Log"), this, SLOT(logCopyComplete()));
420450

421-
contextMenu.exec(globalPos);
451+
contextMenu.exec(globalPos);
452+
}
422453
}

gui/resultsview.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,17 @@ public slots:
314314
/**
315315
* \brief Clear log messages
316316
*/
317-
void log_clear();
317+
void logClear();
318+
319+
/**
320+
* \brief Copy selected log message entry
321+
*/
322+
void logCopyEntry();
323+
324+
/**
325+
* \brief Copy all log messages
326+
*/
327+
void logCopyComplete();
318328

319329
protected:
320330
/**

0 commit comments

Comments
 (0)