From 6d027d612c216fda1175897f775b5ef68e11d30e Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sun, 5 Sep 2021 22:16:54 +0800 Subject: [PATCH] - feature: context menu for breakpoint view - feature: update breakpoint line when delete/insert lines --- RedPandaIDE/debugger.cpp | 37 ++++++++++++++++++++++++++++++++++ RedPandaIDE/debugger.h | 4 ++++ RedPandaIDE/editor.cpp | 28 +++++++++++++++++++++++--- RedPandaIDE/editor.h | 1 + RedPandaIDE/mainwindow.cpp | 41 ++++++++++++++++++++++++++++++++++++++ RedPandaIDE/mainwindow.h | 8 +++++--- RedPandaIDE/mainwindow.ui | 16 +++++++++++++-- 7 files changed, 127 insertions(+), 8 deletions(-) diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 0df0b2a6..3a9b12cb 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -172,6 +172,13 @@ void Debugger::deleteBreakpoints(const Editor *editor) deleteBreakpoints(editor->filename()); } +void Debugger::deleteBreakpoints() +{ + for (int i=mBreakpointModel->breakpoints().size()-1;i>=0;i--) { + removeBreakpoint(i); + } +} + void Debugger::removeBreakpoint(int line, const Editor *editor) { removeBreakpoint(line,editor->filename()); @@ -1548,6 +1555,36 @@ PBreakpoint BreakpointModel::breakpoint(int index) const return mList[index]; } +void BreakpointModel::onFileDeleteLines(const QString &filename, int startLine, int count) +{ + beginResetModel(); + for (int i = mList.count()-1;i>=0;i--){ + PBreakpoint breakpoint = mList[i]; + if (breakpoint->filename == filename + && breakpoint->line>=startLine) { + if (breakpoint->line >= startLine+count) { + breakpoint->line -= count; + } else { + mList.removeAt(i); + } + } + } + endResetModel(); +} + +void BreakpointModel::onFileInsertLines(const QString &filename, int startLine, int count) +{ + beginResetModel(); + for (int i = mList.count()-1;i>=0;i--){ + PBreakpoint breakpoint = mList[i]; + if (breakpoint->filename == filename + && breakpoint->line>=startLine) { + breakpoint->line+=count; + } + } + endResetModel(); +} + BacktraceModel::BacktraceModel(QObject *parent):QAbstractTableModel(parent) { diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 5fc1cec4..6f95a6c0 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -111,6 +111,9 @@ public: PBreakpoint setBreakPointCondition(int index, const QString& condition); const QList& breakpoints() const; PBreakpoint breakpoint(int index) const; +public slots: + void onFileDeleteLines(const QString& filename, int startLine, int count); + void onFileInsertLines(const QString& filename, int startLine, int count); private: QList mList; }; @@ -182,6 +185,7 @@ public: void addBreakpoint(int line, const QString& filename); void deleteBreakpoints(const QString& filename); void deleteBreakpoints(const Editor* editor); + void deleteBreakpoints(); void removeBreakpoint(int line, const Editor* editor); void removeBreakpoint(int line, const QString& filename); void removeBreakpoint(int index); diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 7ef1f8d3..f1710652 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1165,11 +1165,33 @@ void Editor::onTipEvalValueReady(const QString &value) void Editor::onLinesDeleted(int first, int count) { pMainWindow->caretList().linesDeleted(this,first,count); + pMainWindow->debugger()->breakpointModel()->onFileDeleteLines(mFilename,first,count); + resetBreakpoints(); + if (!pSettings->editor().syntaxCheckWhenLineChanged()) { + //todo: update syntax issues + } } void Editor::onLinesInserted(int first, int count) { pMainWindow->caretList().linesInserted(this,first,count); + pMainWindow->debugger()->breakpointModel()->onFileInsertLines(mFilename,first,count); + resetBreakpoints(); + if (!pSettings->editor().syntaxCheckWhenLineChanged()) { + //todo: update syntax issues + } +} + +void Editor::resetBreakpoints() +{ + mBreakpointLines.clear(); + foreach (const PBreakpoint& breakpoint, + pMainWindow->debugger()->breakpointModel()->breakpoints()) { + if (breakpoint->filename == mFilename) { + mBreakpointLines.insert(breakpoint->line); + } + } + invalidate(); } QChar Editor::getCurrentChar() @@ -2503,9 +2525,8 @@ void Editor::reformat() { if (readOnly()) return; - QFile file(":/codes/formatdemo.cpp"); - if (!file.open(QFile::ReadOnly)) - return; + //we must remove all breakpoints and syntax issues + onLinesDeleted(1,lines()->count()); QByteArray content = lines()->text().toUtf8(); QStringList args = pSettings->codeFormatter().getArguments(); QByteArray newContent = runAndGetOutput("astyle.exe", @@ -2516,6 +2537,7 @@ void Editor::reformat() selectAll(); setSelText(QString::fromUtf8(newContent)); reparse(); + checkSyntaxInBack(); pMainWindow->updateEditorActions(); } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 13170137..d748f00f 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -154,6 +154,7 @@ private slots: void onLinesInserted(int first,int count); private: + void resetBreakpoints(); QChar getCurrentChar(); bool handleSymbolCompletion(QChar key); bool handleParentheseCompletion(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index ea78a3e3..94df0d4b 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1200,6 +1200,39 @@ void MainWindow::buildContextMenus() mSearchResultModel.clear(); }); + //context menu signal for breakpoints view + ui->tblBreakpoints->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->tblBreakpoints,&QWidget::customContextMenuRequested, + this, &MainWindow::onBreakpointsViewContextMenu); + mBreakpointViewPropertyAction = createActionFor( + tr("Breakpoint condition..."), + ui->tblBreakpoints); + connect(mBreakpointViewPropertyAction,&QAction::triggered, + [this](){ + int index =ui->tblBreakpoints->selectionModel()->currentIndex().row(); + + PBreakpoint breakpoint = debugger()->breakpointModel()->breakpoint( + index + ); + if (breakpoint) { + bool isOk; + QString s=QInputDialog::getText(this, + tr("Break point condition"), + tr("Enter the condition of the breakpoint:"), + QLineEdit::Normal, + breakpoint->condition,&isOk); + if (isOk) { + pMainWindow->debugger()->setBreakPointCondition(index,s); + } + } + }); + mBreakpointViewRemoveAllAction = createActionFor( + tr("Remove all breakpoints"), + ui->tblBreakpoints); + connect(mBreakpointViewRemoveAllAction,&QAction::triggered, + [this](){ + pMainWindow->debugger()->deleteBreakpoints(); + }); } void MainWindow::maximizeEditor() @@ -1300,6 +1333,14 @@ void MainWindow::onSearchViewContextMenu(const QPoint &pos) menu.exec(ui->searchHistoryPanel->mapToGlobal(pos)); } +void MainWindow::onBreakpointsViewContextMenu(const QPoint &pos) +{ + QMenu menu(this); + menu.addAction(mBreakpointViewPropertyAction); + menu.addAction(mBreakpointViewRemoveAllAction); + menu.exec(ui->tblBreakpoints->mapToGlobal(pos)); +} + void MainWindow::onEditorContextMenu(const QPoint &pos) { Editor * editor = mEditorList->getEditor(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 42d9402b..537d67d0 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -145,6 +145,7 @@ private slots: void onWatchViewContextMenu(const QPoint& pos); void onTableIssuesContextMenu(const QPoint& pos); void onSearchViewContextMenu(const QPoint& pos); + void onBreakpointsViewContextMenu(const QPoint& pos); void on_actionNew_triggered(); @@ -350,13 +351,14 @@ private: QAction * mSearchViewClearAction; QAction * mSearchViewClearAllAction; + //actions for breakpoint view + QAction * mBreakpointViewPropertyAction; + QAction * mBreakpointViewRemoveAllAction; + // QWidget interface protected: void closeEvent(QCloseEvent *event) override; void showEvent(QShowEvent* event) override; - - // QWidget interface -protected: void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; }; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 03a89dd7..615e90e9 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -255,7 +255,7 @@ QTabWidget::South - 3 + 4 @@ -467,7 +467,7 @@ QTabWidget::North - 2 + 1 @@ -517,6 +517,12 @@ + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + Qt::ElideNone @@ -546,6 +552,12 @@ + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + Qt::ElideNone