Search feature in the all watches window
authorJean-Paul Mari <djipi.mari@gmail.com>
Sat, 17 Apr 2021 13:50:21 +0000 (09:50 -0400)
committerJean-Paul Mari <djipi.mari@gmail.com>
Sat, 17 Apr 2021 13:50:21 +0000 (09:50 -0400)
docs/vj_HistoryNotes.txt
src/debugger/allwatchbrowser.cpp
src/debugger/allwatchbrowser.h

index 340e5da..94efdb5 100644 (file)
@@ -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
 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)
 -----------------------------
 
 Release 4a (15th August 2019)
 -----------------------------
index f17b3f4..6aa7d6c 100644 (file)
@@ -37,6 +37,8 @@
 // \r
 AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r
 layout(new QVBoxLayout),\r
 // \r
 AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),\r
 layout(new QVBoxLayout),\r
+symbol(new QLineEdit),\r
+search(new QPushButton(tr("Search"))),\r
 #ifdef AW_LAYOUTTEXTS\r
 text(new QTextBrowser),\r
 #else\r
 #ifdef AW_LAYOUTTEXTS\r
 text(new QTextBrowser),\r
 #else\r
@@ -44,12 +46,13 @@ TableView(new QTableView),
 model(new QStandardItemModel),\r
 #endif\r
 NbWatch(0),\r
 model(new QStandardItemModel),\r
 #endif\r
 NbWatch(0),\r
+CurrentWatch(0),\r
 statusbar(new QStatusBar),\r
 PtrWatchInfo(NULL)\r
 {\r
        setWindowTitle(tr("All Watch"));\r
 \r
 statusbar(new QStatusBar),\r
 PtrWatchInfo(NULL)\r
 {\r
        setWindowTitle(tr("All Watch"));\r
 \r
-       // Set the font\r
+       // set the font\r
        QFont fixedFont("Lucida Console", 8, QFont::Normal);\r
        fixedFont.setStyleHint(QFont::TypeWriter);\r
 \r
        QFont fixedFont("Lucida Console", 8, QFont::Normal);\r
        fixedFont.setStyleHint(QFont::TypeWriter);\r
 \r
@@ -73,9 +76,20 @@ PtrWatchInfo(NULL)
        layout->addWidget(TableView);\r
 #endif\r
 \r
        layout->addWidget(TableView);\r
 #endif\r
 \r
-       // Status bar\r
+       // search bar\r
+       QHBoxLayout * hbox1 = new QHBoxLayout;\r
+       symbol->setPlaceholderText("symbol name");\r
+       hbox1->addWidget(symbol);\r
+       hbox1->addWidget(search);\r
+       layout->addLayout(hbox1);\r
+\r
+       // status bar\r
        layout->addWidget(statusbar);\r
        setLayout(layout);\r
        layout->addWidget(statusbar);\r
        setLayout(layout);\r
+\r
+       // connect slot\r
+       connect(search, SIGNAL(clicked()), this, SLOT(SearchSymbol()));\r
+       connect(symbol, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(SelectSearchSymbol()));\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -86,6 +100,67 @@ AllWatchBrowserWindow::~AllWatchBrowserWindow(void)
 }\r
 \r
 \r
 }\r
 \r
 \r
+// Search the symbol in the watch list\r
+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++)\r
+       {\r
+               // check symbol presence\r
+               if (!symbol->text().compare(PtrWatchInfo[i].PtrVariableName, Qt::CaseSensitive))\r
+               {\r
+                       found = true;\r
+               }\r
+       }\r
+\r
+       if (found)\r
+       {\r
+               // remove previous highlight\r
+               if (CurrentWatch)\r
+               {\r
+                       model->item((int)(CurrentWatch - 1), 0)->setBackground(QColor(255, 255, 255));\r
+                       model->item((int)(CurrentWatch - 1), 1)->setBackground(QColor(255, 255, 255));\r
+                       model->item((int)(CurrentWatch - 1), 2)->setBackground(QColor(255, 255, 255));\r
+               }\r
+               // Get the slider maximum position\r
+               int MaxSlider = TableView->verticalScrollBar()->maximum();              \r
+               // Number of items displayed in the scroll bar slider\r
+               int DeltaSlider = (int)NbWatch - MaxSlider;\r
+               // set the scroll bar\r
+               TableView->verticalScrollBar()->setSliderPosition((int)i - (DeltaSlider / 2) - 1);\r
+               // highlight watch symbol\r
+               CurrentWatch = i;\r
+               model->item((int)(CurrentWatch - 1), 0)->setBackground(QColor(0xff, 0xfa, 0xcd));\r
+               model->item((int)(CurrentWatch - 1), 1)->setBackground(QColor(0xff, 0xfa, 0xcd));\r
+               model->item((int)(CurrentWatch - 1), 2)->setBackground(QColor(0xff, 0xfa, 0xcd));\r
+               // allow new symbol\r
+               symbol->setText("");\r
+       }\r
+       else\r
+       {\r
+               // invalid symbol\r
+               symbol->setStyleSheet("color: red");\r
+       }\r
+
+       // user can enter a symbol
+       symbol->setEnabled(true);
+       symbol->setFocus();
+}
+
+
+//
+void AllWatchBrowserWindow::SelectSearchSymbol(void)\r
+{\r
+       symbol->setStyleSheet("color: black");\r
+}\r
+\r
+\r
 //\r
 void AllWatchBrowserWindow::Reset(void)\r
 {\r
 //\r
 void AllWatchBrowserWindow::Reset(void)\r
 {\r
@@ -205,12 +280,21 @@ void AllWatchBrowserWindow::RefreshContents(void)
 }\r
 \r
 \r
 }\r
 \r
 \r
-// \r
+//  Handle keyboard event\r
 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)\r
 {\r
 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)\r
 {\r
+       // ESC to close / hide the window\r
        if (e->key() == Qt::Key_Escape)\r
        {\r
                hide();\r
        }\r
        if (e->key() == Qt::Key_Escape)\r
        {\r
                hide();\r
        }\r
+       else\r
+       {\r
+               // select the \r
+               if (e->key() == Qt::Key_Return)\r
+               {\r
+                       SearchSymbol();\r
+               }\r
+       }\r
 }\r
 \r
 }\r
 \r
index 70abebe..3f429ad 100644 (file)
@@ -48,6 +48,10 @@ class AllWatchBrowserWindow: public QWidget
        protected:\r
                void keyPressEvent(QKeyEvent *);\r
 \r
        protected:\r
                void keyPressEvent(QKeyEvent *);\r
 \r
+       protected slots:\r
+               void SearchSymbol(void);
+               void SelectSearchSymbol(void);\r
+\r
        private:\r
                QVBoxLayout *layout;\r
 #ifdef AW_LAYOUTTEXTS\r
        private:\r
                QVBoxLayout *layout;\r
 #ifdef AW_LAYOUTTEXTS\r
@@ -59,6 +63,9 @@ class AllWatchBrowserWindow: public QWidget
                QStatusBar *statusbar;\r
                WatchInfo *PtrWatchInfo;\r
                size_t NbWatch;\r
                QStatusBar *statusbar;\r
                WatchInfo *PtrWatchInfo;\r
                size_t NbWatch;\r
+               QPushButton *search;\r
+               QLineEdit* symbol;\r
+               size_t CurrentWatch;\r
 };\r
 \r
 #endif // __ALLWATCHBROWSER_H__\r
 };\r
 \r
 #endif // __ALLWATCHBROWSER_H__\r