From 289b4fd02cb0e92a37c51a8842f693a8e48617ed Mon Sep 17 00:00:00 2001 From: octaeder <102688820+octaeder@users.noreply.github.com> Date: Sun, 21 Jan 2024 16:09:43 +0100 Subject: [PATCH] Messages Pane: Copy any data of all issues to clip and consolidate redundant code --- src/latexlogwidget.cpp | 42 +++++++++++++++++++++++------------------- src/latexlogwidget.h | 6 ++++-- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/latexlogwidget.cpp b/src/latexlogwidget.cpp index 18e1bd2da7..6be774a017 100644 --- a/src/latexlogwidget.cpp +++ b/src/latexlogwidget.cpp @@ -55,14 +55,14 @@ LatexLogWidget::LatexLogWidget(QWidget *parent) : errorTable->setModel(proxyModel); QAction *act = new QAction(tr("&Copy"), errorTable); - connect(act, SIGNAL(triggered()), SLOT(copyMessage())); + connect(act, SIGNAL(triggered()), SLOT(copyRow())); errorTable->addAction(act); - act = new QAction(tr("&Copy All"), errorTable); - connect(act, SIGNAL(triggered()), SLOT(copyAllMessages())); - errorTable->addAction(act); - act = new QAction(tr("&Copy All With Line Numbers"), errorTable); + act = new QAction(tr("Copy All With Line &Numbers"), errorTable); connect(act, SIGNAL(triggered()), SLOT(copyAllMessagesWithLineNumbers())); errorTable->addAction(act); + act = new QAction(tr("Copy &All"), errorTable); + connect(act, SIGNAL(triggered()), SLOT(copyAllRows())); + errorTable->addAction(act); errorTable->setContextMenuPolicy(Qt::ActionsContextMenu); log = new LogEditor(this); @@ -207,7 +207,7 @@ void LatexLogWidget::copy() if (log->isVisible()) log->copy(); else - copyMessage(); + copyRow(); } // TODO what is this for? @@ -233,29 +233,33 @@ void LatexLogWidget::gotoLogLine(int logLine) gotoLogEntry(logModel->logLineNumberToLogEntryNumber(logLine)); } -void LatexLogWidget::copyMessage() +void LatexLogWidget::copyRow() { QModelIndex curMessage = proxyModel->mapToSource(errorTable->currentIndex()); if (!curMessage.isValid()) return; - curMessage = logModel->index(curMessage.row(), 3); - REQUIRE(QApplication::clipboard()); - QApplication::clipboard()->setText(logModel->data(curMessage, Qt::DisplayRole).toString()); + copyRowsWithColumnRange(curMessage.row(),1,0,3); } -void LatexLogWidget::copyAllMessages() +void LatexLogWidget::copyAllMessagesWithLineNumbers() { - QStringList result; - for (int i = 0; i < logModel->count(); i++) - result << logModel->data(logModel->index(i, 3), Qt::DisplayRole).toString(); - REQUIRE(QApplication::clipboard()); - QApplication::clipboard()->setText(result.join("\n")); + copyRowsWithColumnRange(0,logModel->count(),2,3); } -void LatexLogWidget::copyAllMessagesWithLineNumbers() +void LatexLogWidget::copyAllRows() +{ + copyRowsWithColumnRange(0,logModel->count(),0,3); +} + +void LatexLogWidget::copyRowsWithColumnRange(int firstRow, int rows, int first, int last) { QStringList result; - for (int i = 0; i < logModel->count(); i++) - result << logModel->data(logModel->index(i, 2), Qt::DisplayRole).toString() + ": " + logModel->data(logModel->index(i, 3), Qt::DisplayRole).toString(); + for (int i = firstRow; i < firstRow + rows; i++) { + QString columns; + for (int j = first; j < last; j++) { + columns += logModel->data(logModel->index(i, j), Qt::DisplayRole).toString() + ": "; + } + result << columns + logModel->data(logModel->index(i, last), Qt::DisplayRole).toString(); + } REQUIRE(QApplication::clipboard()); QApplication::clipboard()->setText(result.join("\n")); } diff --git a/src/latexlogwidget.h b/src/latexlogwidget.h index bfbebffedf..f684d82b07 100644 --- a/src/latexlogwidget.h +++ b/src/latexlogwidget.h @@ -39,8 +39,8 @@ private slots: void clickedOnLogModelIndex(const QModelIndex &index); void gotoLogEntry(int logEntryNumber); void gotoLogLine(int logLine); - void copyMessage(); - void copyAllMessages(); + void copyRow(); + void copyAllRows(); void copyAllMessagesWithLineNumbers(); void setWidgetVisibleFromAction(bool visible); void setInfo(const QString &message); @@ -56,6 +56,8 @@ private slots: LogEditor *log; QLabel *infoLabel; QAction *displayTableAction, *displayLogAction, *filterErrorAction, *filterWarningAction, *filterBadBoxAction; + + void copyRowsWithColumnRange(int firstRow, int rows, int first, int last); }; #endif // LATEXLOGWIDGET_H