Merge branch 'develop'
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / allwatchbrowser.cpp
index f17b3f4..bd1fd9a 100644 (file)
@@ -10,6 +10,7 @@
 // JPM  12/07/2017  Created this file\r
 // JPM  09/14/2018  Added a status bar, better status report and set information values in a tab\r
 // JPM  April/2019  Added a sorting filter, tableview unique rows creation\r
+// JPM  April/2021  Added a search feature.\r
 //\r
 \r
 // STILL TO DO:\r
@@ -37,6 +38,8 @@
 // \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
@@ -44,12 +47,13 @@ TableView(new QTableView),
 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
-       // Set the font\r
+       // set the font\r
        QFont fixedFont("Lucida Console", 8, QFont::Normal);\r
        fixedFont.setStyleHint(QFont::TypeWriter);\r
 \r
@@ -73,9 +77,20 @@ PtrWatchInfo(NULL)
        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
+\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
@@ -86,6 +101,67 @@ AllWatchBrowserWindow::~AllWatchBrowserWindow(void)
 }\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(((S_VariablesStruct*)PtrWatchInfo[i])->PtrName, 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
@@ -105,15 +181,16 @@ void AllWatchBrowserWindow::RefreshContents(void)
        QString WatchAll;\r
        size_t Error = AW_NOERROR;\r
        char *PtrValue;\r
+       //S_VariablesStruct* Var;\r
 \r
        if (isVisible())\r
        {\r
                if (!NbWatch)\r
                {\r
                        // Pre-catch the information for each global variables\r
-                       if (NbWatch = DBGManager_GetNbGlobalVariables())\r
+                       if (NbWatch = DBGManager_GetNbVariables(NULL))\r
                        {\r
-                               PtrWatchInfo = (WatchInfo *)calloc(NbWatch, sizeof(WatchInfo));\r
+                               PtrWatchInfo = (void**)calloc(NbWatch, sizeof(S_VariablesStruct*));\r
 #ifndef AW_LAYOUTTEXTS\r
 #ifdef AW_SORTINGFILTER\r
                                TableView->setSortingEnabled(false);\r
@@ -122,18 +199,18 @@ void AllWatchBrowserWindow::RefreshContents(void)
 #endif\r
                                for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)\r
                                {\r
-                                       PtrWatchInfo[i].PtrVariableName = DBGManager_GetGlobalVariableName(i + 1);\r
-                                       PtrWatchInfo[i].TypeTag = DBGManager_GetGlobalVariableTypeTag(i + 1);\r
-#ifdef AW_LAYOUTTEXTS\r
-                                       PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);\r
-                                       if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))\r
+                                       if ((PtrWatchInfo[i] = (void*)DBGManager_GetInfosVariable(NULL, i + 1)))\r
                                        {\r
-                                               PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";\r
-                                       }\r
+#ifdef AW_LAYOUTTEXTS\r
+                                               PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);\r
+                                               if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))\r
+                                               {\r
+                                                       PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";\r
+                                               }\r
 #else\r
-                                       PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1);\r
-                                       model->insertRow(i);\r
+                                               model->insertRow(i);\r
 #endif\r
+                                       }\r
                                }\r
                        }\r
                }\r
@@ -142,7 +219,7 @@ void AllWatchBrowserWindow::RefreshContents(void)
                {\r
                        for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)\r
                        {\r
-                               if ((PtrWatchInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure)))\r
+                               if (((S_VariablesStruct*)PtrWatchInfo[i])->TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure))\r
                                {\r
 #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)\r
                                        //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);\r
@@ -153,7 +230,7 @@ void AllWatchBrowserWindow::RefreshContents(void)
                                }\r
                                else\r
                                {\r
-                                       PtrValue = DBGManager_GetGlobalVariableValue(i + 1);\r
+                                       PtrValue = DBGManager_GetVariableValueFromAdr(((S_VariablesStruct*)PtrWatchInfo[i])->Addr, ((S_VariablesStruct*)PtrWatchInfo[i])->TypeEncoding, ((S_VariablesStruct*)PtrWatchInfo[i])->TypeByteSize);\r
                                }\r
 #ifdef AW_LAYOUTTEXTS\r
                                if (i)\r
@@ -163,9 +240,9 @@ void AllWatchBrowserWindow::RefreshContents(void)
                                sprintf(string, "%i : %s | %s | 0x%06X | %s", (i + 1), PtrWatchInfo[i].PtrVariableBaseTypeName, PtrWatchInfo[i].PtrVariableName, (unsigned int)PtrWatchInfo[i].addr, PtrValue ? PtrValue : (char *)"<font color='#ff0000'>N/A</font>");\r
                                WatchAll += QString(string);\r
 #else\r
-                               model->setItem(i, 0, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableName)));\r
+                               model->setItem(i, 0, new QStandardItem(QString("%1").arg(((S_VariablesStruct*)PtrWatchInfo[i])->PtrName)));\r
                                model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue)));\r
-                               model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableBaseTypeName)));\r
+                               model->setItem(i, 2, new QStandardItem(QString("%1").arg(((S_VariablesStruct*)PtrWatchInfo[i])->PtrTypeName)));\r
 #endif\r
                        }\r
 #ifdef AW_LAYOUTTEXTS\r
@@ -205,12 +282,21 @@ void AllWatchBrowserWindow::RefreshContents(void)
 }\r
 \r
 \r
-// \r
+//  Handle keyboard event\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
+       else\r
+       {\r
+               // search symbol\r
+               if (e->key() == Qt::Key_Return)\r
+               {\r
+                       SearchSymbol();\r
+               }\r
+       }\r
 }\r
 \r