From ca9f14444460b26944e0afaff1abb7a03ccb533f Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sun, 5 Sep 2021 21:05:38 +0800 Subject: [PATCH] - feature: search panel's context menu - feature: handle double click on backtrace view - feature: handle double click on breakpoints view --- RedPandaIDE/debugger.cpp | 15 ++++++ RedPandaIDE/debugger.h | 2 + RedPandaIDE/editor.cpp | 8 +-- RedPandaIDE/editor.h | 4 +- RedPandaIDE/mainwindow.cpp | 69 +++++++++++++++++++++++- RedPandaIDE/mainwindow.h | 11 ++++ RedPandaIDE/mainwindow.ui | 6 +-- RedPandaIDE/widgets/searchresultview.cpp | 34 ++++++++++++ RedPandaIDE/widgets/searchresultview.h | 6 +++ 9 files changed, 145 insertions(+), 10 deletions(-) diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index f3aac1de..0df0b2a6 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -1541,6 +1541,13 @@ const QList &BreakpointModel::breakpoints() const return mList; } +PBreakpoint BreakpointModel::breakpoint(int index) const +{ + if (index<0 && index>=mList.count()) + return PBreakpoint(); + return mList[index]; +} + BacktraceModel::BacktraceModel(QObject *parent):QAbstractTableModel(parent) { @@ -1627,6 +1634,14 @@ const QList &BacktraceModel::backtraces() const return mList; } +PTrace BacktraceModel::backtrace(int index) const +{ + if (index>=0 && index < mList.count()){ + return mList[index]; + } + return PTrace(); +} + WatchModel::WatchModel(QObject *parent):QAbstractItemModel(parent) { diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index a863d584..5fc1cec4 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -110,6 +110,7 @@ public: void removeBreakpoint(int index); PBreakpoint setBreakPointCondition(int index, const QString& condition); const QList& breakpoints() const; + PBreakpoint breakpoint(int index) const; private: QList mList; }; @@ -127,6 +128,7 @@ public: void clear(); void removeTrace(int index); const QList& backtraces() const; + PTrace backtrace(int index) const; private: QList mList; }; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index d95813a7..7ef1f8d3 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -904,18 +904,18 @@ void Editor::copyAsHTML() QGuiApplication::clipboard()->setMimeData(mimeData); } -void Editor::setCaretPosition(int line, int col) +void Editor::setCaretPosition(int line, int aChar) { this->uncollapseAroundLine(line); - this->setCaretXYCentered(true,BufferCoord{col,line}); + this->setCaretXYCentered(true,BufferCoord{aChar,line}); } -void Editor::setCaretPositionAndActivate(int line, int col) +void Editor::setCaretPositionAndActivate(int line, int aChar) { this->uncollapseAroundLine(line); if (!this->hasFocus()) this->activate(); - this->setCaretXYCentered(true,BufferCoord{col,line}); + this->setCaretXYCentered(true,BufferCoord{aChar,line}); } void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueType errorType, const QString &hint) diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index a22dd5e8..13170137 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -119,8 +119,8 @@ public: void copyToClipboard() override; void cutToClipboard() override; void copyAsHTML(); - void setCaretPosition(int line,int col); - void setCaretPositionAndActivate(int line,int col); + void setCaretPosition(int line,int aChar); + void setCaretPositionAndActivate(int line,int aChar); void addSyntaxIssues(int line, int startChar, int endChar, CompileIssueType errorType, const QString& hint); void clearSyntaxIssues(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index e7307048..c65f6e40 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1161,7 +1161,6 @@ void MainWindow::buildContextMenus() QKeySequence("Ctrl+Shift+C")); connect(mTableIssuesCopyAllAction,&QAction::triggered, [this](){ - qDebug()<<"Copy all"; QClipboard* clipboard=QGuiApplication::clipboard(); QMimeData * mimeData = new QMimeData(); mimeData->setText(ui->tableIssues->toTxt()); @@ -1177,6 +1176,28 @@ void MainWindow::buildContextMenus() ui->tableIssues->clearIssues(); }); + //context menu signal for search view + ui->searchHistoryPanel->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->searchHistoryPanel, &QWidget::customContextMenuRequested, + this, &MainWindow::onSearchViewContextMenu); + mSearchViewClearAction = createActionFor( + tr("Remove this search"), + ui->searchHistoryPanel); + connect(mSearchViewClearAction, &QAction::triggered, + [this](){ + int index = ui->cbSearchHistory->currentIndex(); + if (index>=0) { + mSearchResultModel.removeSearchResults(index); + } + }); + mSearchViewClearAllAction = createActionFor( + tr("Clear all searches"), + ui->searchHistoryPanel); + connect(mSearchViewClearAllAction,&QAction::triggered, + [this]() { + mSearchResultModel.clear(); + }); + } void MainWindow::maximizeEditor() @@ -1269,6 +1290,14 @@ void MainWindow::onTableIssuesContextMenu(const QPoint &pos) menu.exec(ui->tableIssues->mapToGlobal(pos)); } +void MainWindow::onSearchViewContextMenu(const QPoint &pos) +{ + QMenu menu(this); + menu.addAction(mSearchViewClearAction); + menu.addAction(mSearchViewClearAllAction); + menu.exec(ui->searchHistoryPanel->mapToGlobal(pos)); +} + void MainWindow::onEditorContextMenu(const QPoint &pos) { Editor * editor = mEditorList->getEditor(); @@ -2438,3 +2467,41 @@ void MainWindow::on_actionFile_Properties_triggered() } } +void MainWindow::on_searchView_doubleClicked(const QModelIndex &index) +{ + QString filename; + int line; + int start; + if (mSearchResultTreeModel->getItemFileAndLineChar( + index,filename,line,start)) { + Editor *e = mEditorList->getEditorByFilename(filename); + if (e) { + e->setCaretPositionAndActivate(line,start); + } + } +} + + +void MainWindow::on_tblStackTrace_doubleClicked(const QModelIndex &index) +{ + PTrace trace = mDebugger->backtraceModel()->backtrace(index.row()); + if (trace) { + Editor *e = mEditorList->getEditorByFilename(trace->filename); + if (e) { + e->setCaretPositionAndActivate(trace->line,1); + } + } +} + + +void MainWindow::on_tblBreakpoints_doubleClicked(const QModelIndex &index) +{ + PBreakpoint breakpoint = mDebugger->breakpointModel()->breakpoint(index.row()); + if (breakpoint) { + Editor * e = mEditorList->getEditorByFilename(breakpoint->filename); + if (e) { + e->setCaretPositionAndActivate(breakpoint->line,1); + } + } +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 2521b315..f36c369a 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -144,6 +144,7 @@ private slots: void onWatchViewContextMenu(const QPoint& pos); void onTableIssuesContextMenu(const QPoint& pos); + void onSearchViewContextMenu(const QPoint& pos); void on_actionNew_triggered(); @@ -289,6 +290,12 @@ private slots: void on_actionFile_Properties_triggered(); + void on_searchView_doubleClicked(const QModelIndex &index); + + void on_tblStackTrace_doubleClicked(const QModelIndex &index); + + void on_tblBreakpoints_doubleClicked(const QModelIndex &index); + private: Ui::MainWindow *ui; EditorList *mEditorList; @@ -339,6 +346,10 @@ private: QAction * mTableIssuesCopyAllAction; QAction * mTableIssuesClearAction; + //actions for search result view + QAction * mSearchViewClearAction; + QAction * mSearchViewClearAllAction; + // QWidget interface protected: void closeEvent(QCloseEvent *event) override; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index e10e45b2..03a89dd7 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -255,7 +255,7 @@ QTabWidget::South - 0 + 3 @@ -467,7 +467,7 @@ QTabWidget::North - 1 + 2 @@ -760,7 +760,7 @@ 0 0 946 - 25 + 22 diff --git a/RedPandaIDE/widgets/searchresultview.cpp b/RedPandaIDE/widgets/searchresultview.cpp index 3abf0a5d..75010c8e 100644 --- a/RedPandaIDE/widgets/searchresultview.cpp +++ b/RedPandaIDE/widgets/searchresultview.cpp @@ -111,6 +111,12 @@ void SearchResultModel::clear() emit modelChanged(); } +void SearchResultModel::removeSearchResults(int index) +{ + mSearchResults.removeAt(index); + emit modelChanged(); +} + SearchResultTreeModel::SearchResultTreeModel(SearchResultModel *model, QObject *parent): QAbstractItemModel(parent), mSearchResultModel(model) @@ -216,6 +222,34 @@ SearchResultModel *SearchResultTreeModel::searchResultModel() const return mSearchResultModel; } +bool SearchResultTreeModel::getItemFileAndLineChar(const QModelIndex &index, QString &filename, int &line, int &startChar) +{ + if (!index.isValid()){ + return false; + } + SearchResultTreeItem *item = static_cast(index.internalPointer()); + if (!item) + return false; + + PSearchResults results = mSearchResultModel->currentResults(); + + if (!results ) { + // This is nothing this function is supposed to handle + return false; + } + + SearchResultTreeItem *parent = item->parent; + if (parent==nullptr) { //is filename + return false; + } else { + filename = parent->filename; + line = item->line; + startChar = item->start; + return true; + } + return false; +} + void SearchResultTreeModel::onResultModelChanged() { beginResetModel(); diff --git a/RedPandaIDE/widgets/searchresultview.h b/RedPandaIDE/widgets/searchresultview.h index 7db81968..49bbab23 100644 --- a/RedPandaIDE/widgets/searchresultview.h +++ b/RedPandaIDE/widgets/searchresultview.h @@ -57,6 +57,7 @@ public: PSearchResults currentResults(); void setCurrentIndex(int index); void clear(); + void removeSearchResults(int index); signals: void modelChanged(); void currentChanged(int index); @@ -92,6 +93,11 @@ public: int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; SearchResultModel *searchResultModel() const; + bool getItemFileAndLineChar( + const QModelIndex&index, + QString& filename, + int& line, + int& startChar); public slots: void onResultModelChanged(); private: