Skip to content

Commit

Permalink
Messages Pane: Copy any data of all issues to clip
Browse files Browse the repository at this point in the history
and consolidate redundant code
  • Loading branch information
octaeder committed Jan 25, 2024
1 parent 0f6372d commit 289b4fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
42 changes: 23 additions & 19 deletions src/latexlogwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -207,7 +207,7 @@ void LatexLogWidget::copy()
if (log->isVisible())
log->copy();
else
copyMessage();
copyRow();
}

// TODO what is this for?
Expand All @@ -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"));
}
Expand Down
6 changes: 4 additions & 2 deletions src/latexlogwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

0 comments on commit 289b4fd

Please sign in to comment.