- feature: copy all in issue table

This commit is contained in:
royqh1979 2021-09-05 19:10:54 +08:00
parent 2d0a06fef7
commit e4d57d5989
4 changed files with 60 additions and 22 deletions

View File

@ -17,6 +17,7 @@
#include <QInputDialog>
#include <QLabel>
#include <QMessageBox>
#include <QMimeData>
#include <QTranslator>
#include "settingsdialog/settingsdialog.h"
@ -1124,17 +1125,12 @@ QAction* MainWindow::createActionFor(
void MainWindow::buildContextMenus()
{
// //prevent these action from active when editor not focused
// limitActionShortCutScope(ui->actionCopy,ui->EditorPanel);
// limitActionShortCutScope(ui->actionCut,ui->EditorPanel);
// limitActionShortCutScope(ui->actionSelectAll,ui->EditorPanel);
// limitActionShortCutScope(ui->actionPaste,ui->EditorPanel);
// limitActionShortCutScope(ui->actionSave,ui->EditorPanel);
//context menu signal for the watch view
ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->watchView,&QWidget::customContextMenuRequested,
this, &MainWindow::onWatchViewContextMenu);
//context menu signal for Editor's tabbar
ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->EditorTabsLeft->tabBar(),&QWidget::customContextMenuRequested,
this, &MainWindow::onEditorTabContextMenu);
@ -1142,6 +1138,7 @@ void MainWindow::buildContextMenus()
connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested,
this, &MainWindow::onEditorTabContextMenu);
//context menu signal for Compile Issue view
ui->tableIssues->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableIssues,&QWidget::customContextMenuRequested,
this, &MainWindow::onTableIssuesContextMenu);
@ -1164,22 +1161,19 @@ void MainWindow::buildContextMenus()
QKeySequence("Ctrl+Shift+C"));
connect(mTableIssuesCopyAllAction,&QAction::triggered,
[this](){
qDebug()<<"copy all";
});
mTableIssuesSaveAction = createActionFor(
tr("Save"),
ui->tableIssues,
QKeySequence("Ctrl+S"));
connect(mTableIssuesSaveAction,&QAction::triggered,
[this](){
qDebug()<<"Save";
qDebug()<<"Copy all";
QClipboard* clipboard=QGuiApplication::clipboard();
QMimeData * mimeData = new QMimeData();
mimeData->setText(ui->tableIssues->toTxt());
mimeData->setHtml(ui->tableIssues->toHtml());
clipboard->clear();
clipboard->setMimeData(mimeData);
});
mTableIssuesClearAction = createActionFor(
tr("Clear"),
ui->tableIssues);
connect(mTableIssuesClearAction,&QAction::triggered,
[this](){
qDebug()<<"Clear";
ui->tableIssues->clearIssues();
});
@ -1271,8 +1265,6 @@ void MainWindow::onTableIssuesContextMenu(const QPoint &pos)
menu.addAction(mTableIssuesCopyAction);
menu.addAction(mTableIssuesCopyAllAction);
menu.addSeparator();
menu.addAction(mTableIssuesSaveAction);
menu.addSeparator();
menu.addAction(mTableIssuesClearAction);
menu.exec(ui->tableIssues->mapToGlobal(pos));
}

View File

@ -334,9 +334,9 @@ private:
bool mSystemTurnedOff;
QPoint mEditorContextMenuPos;
//actions for compile issue table
QAction * mTableIssuesCopyAction;
QAction * mTableIssuesCopyAllAction;
QAction * mTableIssuesSaveAction;
QAction * mTableIssuesClearAction;
// QWidget interface

View File

@ -17,6 +17,11 @@ IssuesTable::IssuesTable(QWidget *parent):
this->setColumnWidth(2,45);
}
const QVector<PCompileIssue> &IssuesTable::issues() const
{
return mModel->issues();
}
IssuesModel *IssuesTable::issuesModel()
{
return mModel;
@ -32,6 +37,39 @@ void IssuesTable::setWarningColor(QColor color)
mModel->setWarningColor(color);
}
QString IssuesTable::toHtml()
{
QString result;
result.append(
QString("<table><thead><th>%1</th><th>%2</th><th>%3</th><th>%4</th></thead>")
.arg(tr("Filename"))
.arg(tr("Line"))
.arg(tr("Col"))
.arg(tr("Description")));
foreach (const PCompileIssue& issue, mModel->issues()) {
result.append(QString("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>\n")
.arg(issue->filename)
.arg(issue->line)
.arg(issue->column)
.arg(issue->description));
}
result.append(QString("</table>"));
return result;
}
QString IssuesTable::toTxt()
{
QString result;
foreach (const PCompileIssue& issue, mModel->issues()) {
result.append(QString("%1\t%2\t%3\t%4\n")
.arg(issue->filename)
.arg(issue->line)
.arg(issue->column)
.arg(issue->description));
}
return result;
}
IssuesModel::IssuesModel(QObject *parent):
QAbstractTableModel(parent)
{
@ -83,6 +121,11 @@ PCompileIssue IssuesModel::issue(int row)
return mIssues[row];
}
const QVector<PCompileIssue> &IssuesModel::issues() const
{
return mIssues;
}
int IssuesModel::count()
{
return mIssues.size();

View File

@ -20,7 +20,7 @@ public slots:
void setWarningColor(QColor color);
PCompileIssue issue(int row);
private:
std::vector<PCompileIssue> mIssues;
QVector<PCompileIssue> mIssues;
QColor mErrorColor;
QColor mWarningColor;
@ -31,6 +31,7 @@ public:
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
const QVector<PCompileIssue> &issues() const;
};
class IssuesTable : public QTableView
@ -40,12 +41,14 @@ public:
explicit IssuesTable(QWidget* parent = nullptr);
const std::vector<PCompileIssue> & issues() const;
const QVector<PCompileIssue> & issues() const;
IssuesModel* issuesModel();
void setErrorColor(QColor color);
void setWarningColor(QColor color);
QString toHtml();
QString toTxt();
public slots:
void addIssue(PCompileIssue issue);