- feature: context menu for issue table

- feature: copy current item's description in issue table
This commit is contained in:
royqh1979@gmail.com 2021-09-05 13:51:07 +08:00
parent d232cd85d3
commit 2d0a06fef7
4 changed files with 118 additions and 5 deletions

View File

@ -10,7 +10,6 @@
#include "widgets/cpudialog.h" #include "widgets/cpudialog.h"
#include "widgets/filepropertiesdialog.h" #include "widgets/filepropertiesdialog.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox> #include <QComboBox>
#include <QDesktopServices> #include <QDesktopServices>
@ -619,7 +618,6 @@ void MainWindow::checkSyntaxInBack(Editor *e)
return; return;
mCheckSyntaxInBack=true; mCheckSyntaxInBack=true;
e->clearSyntaxIssues();
ui->tableIssues->clearIssues(); ui->tableIssues->clearIssues();
mCompilerManager->checkSyntax(e->filename(),e->lines()->text(), mCompilerManager->checkSyntax(e->filename(),e->lines()->text(),
e->fileEncoding() == ENCODING_ASCII); e->fileEncoding() == ENCODING_ASCII);
@ -639,7 +637,6 @@ bool MainWindow::compile(bool rebuild)
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor != NULL ) {
editor->clearSyntaxIssues();
ui->tableIssues->clearIssues(); ui->tableIssues->clearIssues();
if (editor->modified()) { if (editor->modified()) {
if (!editor->save(false,false)) if (!editor->save(false,false))
@ -1107,11 +1104,37 @@ void MainWindow::doAutoSave(Editor *e)
e->saveFile(filename); e->saveFile(filename);
} }
//static void limitActionShortCutScope(QAction* action,QWidget* scopeWidget) {
// action->setParent(scopeWidget);
// action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
//}
QAction* MainWindow::createActionFor(
const QString& text,
QWidget* parent,
QKeySequence shortcut) {
QAction* action= new QAction(text,parent);
if (!shortcut.isEmpty())
action->setShortcut(shortcut);
action->setPriority(QAction::HighPriority);
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
parent->addAction(action);
return action;
}
void MainWindow::buildContextMenus() 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);
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);
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);
@ -1119,6 +1142,47 @@ void MainWindow::buildContextMenus()
connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested, connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested,
this, &MainWindow::onEditorTabContextMenu); this, &MainWindow::onEditorTabContextMenu);
ui->tableIssues->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableIssues,&QWidget::customContextMenuRequested,
this, &MainWindow::onTableIssuesContextMenu);
mTableIssuesCopyAction = createActionFor(
tr("Copy"),
ui->tableIssues,
QKeySequence("Ctrl+C"));
connect(mTableIssuesCopyAction,&QAction::triggered,
[this](){
QModelIndex index = ui->tableIssues->selectionModel()->currentIndex();
PCompileIssue issue = ui->tableIssues->issue(index);
if (issue) {
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(issue->description);
}
});
mTableIssuesCopyAllAction = createActionFor(
tr("Copy all"),
ui->tableIssues,
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";
});
mTableIssuesClearAction = createActionFor(
tr("Clear"),
ui->tableIssues);
connect(mTableIssuesClearAction,&QAction::triggered,
[this](){
qDebug()<<"Clear";
ui->tableIssues->clearIssues();
});
} }
void MainWindow::maximizeEditor() void MainWindow::maximizeEditor()
@ -1201,6 +1265,18 @@ void MainWindow::onWatchViewContextMenu(const QPoint &pos)
menu.exec(ui->watchView->mapToGlobal(pos)); menu.exec(ui->watchView->mapToGlobal(pos));
} }
void MainWindow::onTableIssuesContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(mTableIssuesCopyAction);
menu.addAction(mTableIssuesCopyAllAction);
menu.addSeparator();
menu.addAction(mTableIssuesSaveAction);
menu.addSeparator();
menu.addAction(mTableIssuesClearAction);
menu.exec(ui->tableIssues->mapToGlobal(pos));
}
void MainWindow::onEditorContextMenu(const QPoint &pos) void MainWindow::onEditorContextMenu(const QPoint &pos)
{ {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();

View File

@ -134,12 +134,17 @@ private:
void buildContextMenus(); void buildContextMenus();
void maximizeEditor(); void maximizeEditor();
void openShell(const QString& folder, const QString& shellCommand); void openShell(const QString& folder, const QString& shellCommand);
QAction* createActionFor(const QString& text,
QWidget* parent,
QKeySequence shortcut=QKeySequence());
private slots: private slots:
void onAutoSaveTimeout(); void onAutoSaveTimeout();
void onWatchViewContextMenu(const QPoint& pos);
void onFileChanged(const QString& path); void onFileChanged(const QString& path);
void onWatchViewContextMenu(const QPoint& pos);
void onTableIssuesContextMenu(const QPoint& pos);
void on_actionNew_triggered(); void on_actionNew_triggered();
void on_EditorTabsLeft_tabCloseRequested(int index); void on_EditorTabsLeft_tabCloseRequested(int index);
@ -329,6 +334,11 @@ private:
bool mSystemTurnedOff; bool mSystemTurnedOff;
QPoint mEditorContextMenuPos; QPoint mEditorContextMenuPos;
QAction * mTableIssuesCopyAction;
QAction * mTableIssuesCopyAllAction;
QAction * mTableIssuesSaveAction;
QAction * mTableIssuesClearAction;
// QWidget interface // QWidget interface
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;

View File

@ -255,7 +255,7 @@
<enum>QTabWidget::South</enum> <enum>QTabWidget::South</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tabIssues"> <widget class="QWidget" name="tabIssues">
<attribute name="icon"> <attribute name="icon">
@ -1104,6 +1104,9 @@
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+X</string> <string>Ctrl+X</string>
</property> </property>
<property name="shortcutContext">
<enum>Qt::WidgetWithChildrenShortcut</enum>
</property>
</action> </action>
<action name="actionCopy"> <action name="actionCopy">
<property name="icon"> <property name="icon">
@ -1117,6 +1120,9 @@
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+C</string> <string>Ctrl+C</string>
</property> </property>
<property name="shortcutContext">
<enum>Qt::WidgetWithChildrenShortcut</enum>
</property>
</action> </action>
<action name="actionPaste"> <action name="actionPaste">
<property name="icon"> <property name="icon">
@ -1130,6 +1136,9 @@
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+V</string> <string>Ctrl+V</string>
</property> </property>
<property name="shortcutContext">
<enum>Qt::WidgetWithChildrenShortcut</enum>
</property>
</action> </action>
<action name="actionSelectAll"> <action name="actionSelectAll">
<property name="text"> <property name="text">
@ -1138,6 +1147,9 @@
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+A</string> <string>Ctrl+A</string>
</property> </property>
<property name="shortcutContext">
<enum>Qt::WidgetWithChildrenShortcut</enum>
</property>
</action> </action>
<action name="actionIndent"> <action name="actionIndent">
<property name="icon"> <property name="icon">

View File

@ -2,6 +2,9 @@
#include "../utils.h" #include "../utils.h"
#include <QHeaderView> #include <QHeaderView>
#include "../settings.h" #include "../settings.h"
#include "../mainwindow.h"
#include "../editor.h"
#include "../editorlist.h"
IssuesTable::IssuesTable(QWidget *parent): IssuesTable::IssuesTable(QWidget *parent):
@ -44,11 +47,21 @@ void IssuesModel::addIssue(PCompileIssue issue)
void IssuesModel::clearIssues() void IssuesModel::clearIssues()
{ {
QSet<QString> issueFiles;
foreach(const PCompileIssue& issue, mIssues) {
if (!(issue->filename.isEmpty())){
issueFiles.insert(issue->filename);
}
}
if (mIssues.size()>0) { if (mIssues.size()>0) {
beginRemoveRows(QModelIndex(),0,mIssues.size()-1); beginRemoveRows(QModelIndex(),0,mIssues.size()-1);
mIssues.clear(); mIssues.clear();
endRemoveRows(); endRemoveRows();
} }
foreach (const QString& filename, issueFiles) {
Editor *e=pMainWindow->editorList()->getOpenedEditorByFilename(filename);
e->clearSyntaxIssues();
}
} }
void IssuesModel::setErrorColor(QColor color) void IssuesModel::setErrorColor(QColor color)
@ -82,6 +95,8 @@ void IssuesTable::addIssue(PCompileIssue issue)
PCompileIssue IssuesTable::issue(const QModelIndex &index) PCompileIssue IssuesTable::issue(const QModelIndex &index)
{ {
if (!index.isValid())
return PCompileIssue();
return issue(index.row()); return issue(index.row());
} }