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

View File

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

View File

@ -17,6 +17,11 @@ IssuesTable::IssuesTable(QWidget *parent):
this->setColumnWidth(2,45); this->setColumnWidth(2,45);
} }
const QVector<PCompileIssue> &IssuesTable::issues() const
{
return mModel->issues();
}
IssuesModel *IssuesTable::issuesModel() IssuesModel *IssuesTable::issuesModel()
{ {
return mModel; return mModel;
@ -32,6 +37,39 @@ void IssuesTable::setWarningColor(QColor color)
mModel->setWarningColor(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): IssuesModel::IssuesModel(QObject *parent):
QAbstractTableModel(parent) QAbstractTableModel(parent)
{ {
@ -83,6 +121,11 @@ PCompileIssue IssuesModel::issue(int row)
return mIssues[row]; return mIssues[row];
} }
const QVector<PCompileIssue> &IssuesModel::issues() const
{
return mIssues;
}
int IssuesModel::count() int IssuesModel::count()
{ {
return mIssues.size(); return mIssues.size();

View File

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