- feature: context menu for breakpoint view

- feature: update breakpoint line when delete/insert lines
This commit is contained in:
royqh1979 2021-09-05 22:16:54 +08:00
parent a1fe8c38b1
commit 6d027d612c
7 changed files with 127 additions and 8 deletions

View File

@ -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)
{

View File

@ -111,6 +111,9 @@ public:
PBreakpoint setBreakPointCondition(int index, const QString& condition);
const QList<PBreakpoint>& 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<PBreakpoint> 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);

View File

@ -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();
}

View File

@ -154,6 +154,7 @@ private slots:
void onLinesInserted(int first,int count);
private:
void resetBreakpoints();
QChar getCurrentChar();
bool handleSymbolCompletion(QChar key);
bool handleParentheseCompletion();

View File

@ -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();

View File

@ -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;
};

View File

@ -255,7 +255,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>3</number>
<number>4</number>
</property>
<widget class="QWidget" name="tabIssues">
<attribute name="icon">
@ -467,7 +467,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabDebugConsole">
<attribute name="title">
@ -517,6 +517,12 @@
</property>
<item>
<widget class="QTableView" name="tblStackTrace">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
@ -546,6 +552,12 @@
</property>
<item>
<widget class="QTableView" name="tblBreakpoints">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>