From e4d57d59891ad3c663c75142280f5c5ace3df3e0 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sun, 5 Sep 2021 19:10:54 +0800 Subject: [PATCH] - feature: copy all in issue table --- RedPandaIDE/mainwindow.cpp | 30 ++++++++------------ RedPandaIDE/mainwindow.h | 2 +- RedPandaIDE/widgets/issuestable.cpp | 43 +++++++++++++++++++++++++++++ RedPandaIDE/widgets/issuestable.h | 7 +++-- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 7e9c2578..e7307048 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #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)); } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index e13af3b6..2521b315 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -334,9 +334,9 @@ private: bool mSystemTurnedOff; QPoint mEditorContextMenuPos; + //actions for compile issue table QAction * mTableIssuesCopyAction; QAction * mTableIssuesCopyAllAction; - QAction * mTableIssuesSaveAction; QAction * mTableIssuesClearAction; // QWidget interface diff --git a/RedPandaIDE/widgets/issuestable.cpp b/RedPandaIDE/widgets/issuestable.cpp index 8b302821..29320acf 100644 --- a/RedPandaIDE/widgets/issuestable.cpp +++ b/RedPandaIDE/widgets/issuestable.cpp @@ -17,6 +17,11 @@ IssuesTable::IssuesTable(QWidget *parent): this->setColumnWidth(2,45); } +const QVector &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("") + .arg(tr("Filename")) + .arg(tr("Line")) + .arg(tr("Col")) + .arg(tr("Description"))); + foreach (const PCompileIssue& issue, mModel->issues()) { + result.append(QString("\n") + .arg(issue->filename) + .arg(issue->line) + .arg(issue->column) + .arg(issue->description)); + } + result.append(QString("
%1%2%3%4
%1%2%3%4
")); + 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 &IssuesModel::issues() const +{ + return mIssues; +} + int IssuesModel::count() { return mIssues.size(); diff --git a/RedPandaIDE/widgets/issuestable.h b/RedPandaIDE/widgets/issuestable.h index 87261a6f..7e77eaf8 100644 --- a/RedPandaIDE/widgets/issuestable.h +++ b/RedPandaIDE/widgets/issuestable.h @@ -20,7 +20,7 @@ public slots: void setWarningColor(QColor color); PCompileIssue issue(int row); private: - std::vector mIssues; + QVector 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 &issues() const; }; class IssuesTable : public QTableView @@ -40,12 +41,14 @@ public: explicit IssuesTable(QWidget* parent = nullptr); - const std::vector & issues() const; + const QVector & issues() const; IssuesModel* issuesModel(); void setErrorColor(QColor color); void setWarningColor(QColor color); + QString toHtml(); + QString toTxt(); public slots: void addIssue(PCompileIssue issue);