From 03458eec991b2a88e1159b5726e5eeb930907a26 Mon Sep 17 00:00:00 2001 From: Jean-Paul Mari Date: Sat, 17 Apr 2021 09:50:21 -0400 Subject: [PATCH] Search feature in the all watches window --- docs/vj_HistoryNotes.txt | 3 +- src/debugger/allwatchbrowser.cpp | 90 ++++++++++++++++++++++++++++++-- src/debugger/allwatchbrowser.h | 7 +++ 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/docs/vj_HistoryNotes.txt b/docs/vj_HistoryNotes.txt index 340e5da..94efdb5 100644 --- a/docs/vj_HistoryNotes.txt +++ b/docs/vj_HistoryNotes.txt @@ -36,7 +36,8 @@ Release 5 (TBA) 23) Handle number of M68K cycles used when tracing in debugger mode -- The cycles are displayed in the emulator status window 24) Improve the DWARF source line number reporting -25) Added a #line in the call stack browser window +25) Added a #line in the call stack window +26) Add a search feature in the all watches window Release 4a (15th August 2019) ----------------------------- diff --git a/src/debugger/allwatchbrowser.cpp b/src/debugger/allwatchbrowser.cpp index f17b3f4..6aa7d6c 100644 --- a/src/debugger/allwatchbrowser.cpp +++ b/src/debugger/allwatchbrowser.cpp @@ -37,6 +37,8 @@ // AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog), layout(new QVBoxLayout), +symbol(new QLineEdit), +search(new QPushButton(tr("Search"))), #ifdef AW_LAYOUTTEXTS text(new QTextBrowser), #else @@ -44,12 +46,13 @@ TableView(new QTableView), model(new QStandardItemModel), #endif NbWatch(0), +CurrentWatch(0), statusbar(new QStatusBar), PtrWatchInfo(NULL) { setWindowTitle(tr("All Watch")); - // Set the font + // set the font QFont fixedFont("Lucida Console", 8, QFont::Normal); fixedFont.setStyleHint(QFont::TypeWriter); @@ -73,9 +76,20 @@ PtrWatchInfo(NULL) layout->addWidget(TableView); #endif - // Status bar + // search bar + QHBoxLayout * hbox1 = new QHBoxLayout; + symbol->setPlaceholderText("symbol name"); + hbox1->addWidget(symbol); + hbox1->addWidget(search); + layout->addLayout(hbox1); + + // status bar layout->addWidget(statusbar); setLayout(layout); + + // connect slot + connect(search, SIGNAL(clicked()), this, SLOT(SearchSymbol())); + connect(symbol, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(SelectSearchSymbol())); } @@ -86,6 +100,67 @@ AllWatchBrowserWindow::~AllWatchBrowserWindow(void) } +// Search the symbol in the watch list +void AllWatchBrowserWindow::SearchSymbol(void) +{ + bool found = false; + size_t i; + + // user cannot enter symbol to allow the search + symbol->setDisabled(true); + + // look for the symbol in the watch list + for (i = AW_STARTNUMVARIABLE; (i < NbWatch) && !found; i++) + { + // check symbol presence + if (!symbol->text().compare(PtrWatchInfo[i].PtrVariableName, Qt::CaseSensitive)) + { + found = true; + } + } + + if (found) + { + // remove previous highlight + if (CurrentWatch) + { + model->item((int)(CurrentWatch - 1), 0)->setBackground(QColor(255, 255, 255)); + model->item((int)(CurrentWatch - 1), 1)->setBackground(QColor(255, 255, 255)); + model->item((int)(CurrentWatch - 1), 2)->setBackground(QColor(255, 255, 255)); + } + // Get the slider maximum position + int MaxSlider = TableView->verticalScrollBar()->maximum(); + // Number of items displayed in the scroll bar slider + int DeltaSlider = (int)NbWatch - MaxSlider; + // set the scroll bar + TableView->verticalScrollBar()->setSliderPosition((int)i - (DeltaSlider / 2) - 1); + // highlight watch symbol + CurrentWatch = i; + model->item((int)(CurrentWatch - 1), 0)->setBackground(QColor(0xff, 0xfa, 0xcd)); + model->item((int)(CurrentWatch - 1), 1)->setBackground(QColor(0xff, 0xfa, 0xcd)); + model->item((int)(CurrentWatch - 1), 2)->setBackground(QColor(0xff, 0xfa, 0xcd)); + // allow new symbol + symbol->setText(""); + } + else + { + // invalid symbol + symbol->setStyleSheet("color: red"); + } + + // user can enter a symbol + symbol->setEnabled(true); + symbol->setFocus(); +} + + +// +void AllWatchBrowserWindow::SelectSearchSymbol(void) +{ + symbol->setStyleSheet("color: black"); +} + + // void AllWatchBrowserWindow::Reset(void) { @@ -205,12 +280,21 @@ void AllWatchBrowserWindow::RefreshContents(void) } -// +// Handle keyboard event void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e) { + // ESC to close / hide the window if (e->key() == Qt::Key_Escape) { hide(); } + else + { + // select the + if (e->key() == Qt::Key_Return) + { + SearchSymbol(); + } + } } diff --git a/src/debugger/allwatchbrowser.h b/src/debugger/allwatchbrowser.h index 70abebe..3f429ad 100644 --- a/src/debugger/allwatchbrowser.h +++ b/src/debugger/allwatchbrowser.h @@ -48,6 +48,10 @@ class AllWatchBrowserWindow: public QWidget protected: void keyPressEvent(QKeyEvent *); + protected slots: + void SearchSymbol(void); + void SelectSearchSymbol(void); + private: QVBoxLayout *layout; #ifdef AW_LAYOUTTEXTS @@ -59,6 +63,9 @@ class AllWatchBrowserWindow: public QWidget QStatusBar *statusbar; WatchInfo *PtrWatchInfo; size_t NbWatch; + QPushButton *search; + QLineEdit* symbol; + size_t CurrentWatch; }; #endif // __ALLWATCHBROWSER_H__ -- 2.20.1