- feature: search panel's context menu

- feature: handle double click on backtrace view
 - feature: handle double click on breakpoints view
This commit is contained in:
royqh1979 2021-09-05 21:05:38 +08:00
parent e4d57d5989
commit ca9f144444
9 changed files with 145 additions and 10 deletions

View File

@ -1541,6 +1541,13 @@ const QList<PBreakpoint> &BreakpointModel::breakpoints() const
return mList; 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) BacktraceModel::BacktraceModel(QObject *parent):QAbstractTableModel(parent)
{ {
@ -1627,6 +1634,14 @@ const QList<PTrace> &BacktraceModel::backtraces() const
return mList; 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) WatchModel::WatchModel(QObject *parent):QAbstractItemModel(parent)
{ {

View File

@ -110,6 +110,7 @@ public:
void removeBreakpoint(int index); void removeBreakpoint(int index);
PBreakpoint setBreakPointCondition(int index, const QString& condition); PBreakpoint setBreakPointCondition(int index, const QString& condition);
const QList<PBreakpoint>& breakpoints() const; const QList<PBreakpoint>& breakpoints() const;
PBreakpoint breakpoint(int index) const;
private: private:
QList<PBreakpoint> mList; QList<PBreakpoint> mList;
}; };
@ -127,6 +128,7 @@ public:
void clear(); void clear();
void removeTrace(int index); void removeTrace(int index);
const QList<PTrace>& backtraces() const; const QList<PTrace>& backtraces() const;
PTrace backtrace(int index) const;
private: private:
QList<PTrace> mList; QList<PTrace> mList;
}; };

View File

@ -904,18 +904,18 @@ void Editor::copyAsHTML()
QGuiApplication::clipboard()->setMimeData(mimeData); QGuiApplication::clipboard()->setMimeData(mimeData);
} }
void Editor::setCaretPosition(int line, int col) void Editor::setCaretPosition(int line, int aChar)
{ {
this->uncollapseAroundLine(line); 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); this->uncollapseAroundLine(line);
if (!this->hasFocus()) if (!this->hasFocus())
this->activate(); 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) void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueType errorType, const QString &hint)

View File

@ -119,8 +119,8 @@ public:
void copyToClipboard() override; void copyToClipboard() override;
void cutToClipboard() override; void cutToClipboard() override;
void copyAsHTML(); void copyAsHTML();
void setCaretPosition(int line,int col); void setCaretPosition(int line,int aChar);
void setCaretPositionAndActivate(int line,int col); void setCaretPositionAndActivate(int line,int aChar);
void addSyntaxIssues(int line, int startChar, int endChar, CompileIssueType errorType, const QString& hint); void addSyntaxIssues(int line, int startChar, int endChar, CompileIssueType errorType, const QString& hint);
void clearSyntaxIssues(); void clearSyntaxIssues();

View File

@ -1161,7 +1161,6 @@ void MainWindow::buildContextMenus()
QKeySequence("Ctrl+Shift+C")); QKeySequence("Ctrl+Shift+C"));
connect(mTableIssuesCopyAllAction,&QAction::triggered, connect(mTableIssuesCopyAllAction,&QAction::triggered,
[this](){ [this](){
qDebug()<<"Copy all";
QClipboard* clipboard=QGuiApplication::clipboard(); QClipboard* clipboard=QGuiApplication::clipboard();
QMimeData * mimeData = new QMimeData(); QMimeData * mimeData = new QMimeData();
mimeData->setText(ui->tableIssues->toTxt()); mimeData->setText(ui->tableIssues->toTxt());
@ -1177,6 +1176,28 @@ void MainWindow::buildContextMenus()
ui->tableIssues->clearIssues(); 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() void MainWindow::maximizeEditor()
@ -1269,6 +1290,14 @@ void MainWindow::onTableIssuesContextMenu(const QPoint &pos)
menu.exec(ui->tableIssues->mapToGlobal(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) void MainWindow::onEditorContextMenu(const QPoint &pos)
{ {
Editor * editor = mEditorList->getEditor(); 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);
}
}
}

View File

@ -144,6 +144,7 @@ private slots:
void onWatchViewContextMenu(const QPoint& pos); void onWatchViewContextMenu(const QPoint& pos);
void onTableIssuesContextMenu(const QPoint& pos); void onTableIssuesContextMenu(const QPoint& pos);
void onSearchViewContextMenu(const QPoint& pos);
void on_actionNew_triggered(); void on_actionNew_triggered();
@ -289,6 +290,12 @@ private slots:
void on_actionFile_Properties_triggered(); 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: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;
@ -339,6 +346,10 @@ private:
QAction * mTableIssuesCopyAllAction; QAction * mTableIssuesCopyAllAction;
QAction * mTableIssuesClearAction; QAction * mTableIssuesClearAction;
//actions for search result view
QAction * mSearchViewClearAction;
QAction * mSearchViewClearAllAction;
// 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>0</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="tabIssues"> <widget class="QWidget" name="tabIssues">
<attribute name="icon"> <attribute name="icon">
@ -467,7 +467,7 @@
<enum>QTabWidget::North</enum> <enum>QTabWidget::North</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="tabDebugConsole"> <widget class="QWidget" name="tabDebugConsole">
<attribute name="title"> <attribute name="title">
@ -760,7 +760,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>946</width> <width>946</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">

View File

@ -111,6 +111,12 @@ void SearchResultModel::clear()
emit modelChanged(); emit modelChanged();
} }
void SearchResultModel::removeSearchResults(int index)
{
mSearchResults.removeAt(index);
emit modelChanged();
}
SearchResultTreeModel::SearchResultTreeModel(SearchResultModel *model, QObject *parent): SearchResultTreeModel::SearchResultTreeModel(SearchResultModel *model, QObject *parent):
QAbstractItemModel(parent), QAbstractItemModel(parent),
mSearchResultModel(model) mSearchResultModel(model)
@ -216,6 +222,34 @@ SearchResultModel *SearchResultTreeModel::searchResultModel() const
return mSearchResultModel; return mSearchResultModel;
} }
bool SearchResultTreeModel::getItemFileAndLineChar(const QModelIndex &index, QString &filename, int &line, int &startChar)
{
if (!index.isValid()){
return false;
}
SearchResultTreeItem *item = static_cast<SearchResultTreeItem *>(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() void SearchResultTreeModel::onResultModelChanged()
{ {
beginResetModel(); beginResetModel();

View File

@ -57,6 +57,7 @@ public:
PSearchResults currentResults(); PSearchResults currentResults();
void setCurrentIndex(int index); void setCurrentIndex(int index);
void clear(); void clear();
void removeSearchResults(int index);
signals: signals:
void modelChanged(); void modelChanged();
void currentChanged(int index); void currentChanged(int index);
@ -92,6 +93,11 @@ public:
int columnCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
SearchResultModel *searchResultModel() const; SearchResultModel *searchResultModel() const;
bool getItemFileAndLineChar(
const QModelIndex&index,
QString& filename,
int& line,
int& startChar);
public slots: public slots:
void onResultModelChanged(); void onResultModelChanged();
private: private: