Added a sorting filter in the all watches window
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / allwatchbrowser.cpp
1 //
2 // allwatchbrowser.cpp - All Watch
3 //
4 // by Jean-Paul Mari
5 //
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7 //
8 // Who When What
9 // --- ---------- -----------------------------------------------------------
10 // JPM 12/07/2017 Created this file
11 // JPM 09/14/2018 Added a status bar, better status report and set information values in a tab
12 // JPM 10/05/2018 Added a sorting filter
13 //
14
15 // STILL TO DO:
16 // Better presentation
17 // To set the information display at the right
18 //
19
20 //#define AW_DEBUGNUMVARIABLE 4415 // Set the global variable number to debug
21 #ifndef AW_DEBUGNUMVARIABLE
22 #define AW_STARTNUMVARIABLE 0 // Must be kept to 0 in case of no debug is required
23 #else
24 #define AW_STARTNUMVARIABLE AW_DEBUGNUMVARIABLE - 1
25 #endif
26
27
28 #include "debugger/allwatchbrowser.h"
29 #include "memory.h"
30 #include "debugger/DBGManager.h"
31
32
33 //
34 AllWatchBrowserWindow::AllWatchBrowserWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
35 layout(new QVBoxLayout),
36 #ifdef AW_LAYOUTTEXTS
37 text(new QTextBrowser),
38 #else
39 TableView(new QTableView),
40 model(new QStandardItemModel),
41 #endif
42 NbWatch(0),
43 statusbar(new QStatusBar),
44 PtrWatchInfo(NULL)
45 {
46 setWindowTitle(tr("All Watch"));
47
48 // Set the font
49 QFont fixedFont("Lucida Console", 8, QFont::Normal);
50 fixedFont.setStyleHint(QFont::TypeWriter);
51
52 #ifdef AW_LAYOUTTEXTS
53 // Set original layout
54 text->setFont(fixedFont);
55 layout->addWidget(text);
56 #else
57 // Set the new layout with proper identation and readibility
58 model->setColumnCount(3);
59 model->setHeaderData(0, Qt::Horizontal, QObject::tr("Name"));
60 model->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
61 model->setHeaderData(2, Qt::Horizontal, QObject::tr("Type"));
62 // Information table
63 TableView->setModel(model);
64 TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
65 TableView->setShowGrid(0);
66 TableView->setFont(fixedFont);
67 TableView->verticalHeader()->setDefaultSectionSize(TableView->verticalHeader()->minimumSectionSize());
68 TableView->verticalHeader()->setDefaultAlignment(Qt::AlignRight);
69 layout->addWidget(TableView);
70 #endif
71
72 // Status bar
73 layout->addWidget(statusbar);
74 setLayout(layout);
75 }
76
77
78 //
79 AllWatchBrowserWindow::~AllWatchBrowserWindow(void)
80 {
81 Reset();
82 }
83
84
85 //
86 void AllWatchBrowserWindow::Reset(void)
87 {
88 free(PtrWatchInfo);
89 NbWatch = 0;
90 PtrWatchInfo = NULL;
91 }
92
93
94 //
95 void AllWatchBrowserWindow::RefreshContents(void)
96 {
97 char msg[100];
98 #ifdef AW_LAYOUTTEXTS
99 char string[1024];
100 #endif
101 QString WatchAll;
102 size_t Error = AW_NOERROR;
103 char *PtrValue;
104
105 if (isVisible())
106 {
107 if (!NbWatch)
108 {
109 // Pre-catch the information for each global variables
110 if (NbWatch = DBGManager_GetNbGlobalVariables())
111 {
112 PtrWatchInfo = (WatchInfo *)calloc(NbWatch, sizeof(WatchInfo));
113
114 for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)
115 {
116 PtrWatchInfo[i].PtrVariableName = DBGManager_GetGlobalVariableName(i + 1);
117 PtrWatchInfo[i].TypeTag = DBGManager_GetGlobalVariableTypeTag(i + 1);
118 #ifdef AW_LAYOUTTEXTS
119 PtrWatchInfo[i].addr = DBGManager_GetGlobalVariableAdr(i + 1);
120 if (!strlen(PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1)))
121 {
122 PtrWatchInfo[i].PtrVariableBaseTypeName = (char *)"<font color='#ff0000'>N/A</font>";
123 }
124 #else
125 PtrWatchInfo[i].PtrVariableBaseTypeName = DBGManager_GetGlobalVariableTypeName(i + 1);
126 #endif
127 }
128 }
129 }
130 #ifndef AW_LAYOUTTEXTS
131 TableView->setSortingEnabled(false);
132 model->setRowCount(0);
133 #endif
134 if (NbWatch)
135 {
136 for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)
137 {
138 if ((PtrWatchInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure)))
139 {
140 #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)
141 //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);
142 PtrValue = NULL;
143 #else
144 PtrValue = NULL;
145 #endif
146 }
147 else
148 {
149 PtrValue = DBGManager_GetGlobalVariableValue(i + 1);
150 }
151 #ifdef AW_LAYOUTTEXTS
152 if (i)
153 {
154 WatchAll += QString("<br>");
155 }
156 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>");
157 WatchAll += QString(string);
158 #else
159 model->insertRow(i);
160 model->setItem(i, 0, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableName)));
161 model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue)));
162 model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableBaseTypeName)));
163 #endif
164 }
165 #ifdef AW_LAYOUTTEXTS
166 text->clear();
167 text->setText(WatchAll);
168 #else
169 TableView->setSortingEnabled(true);
170 #endif
171 sprintf(msg, "Ready");
172 }
173 else
174 {
175 sprintf(msg, "No watches");
176 Error = AW_NOALLWATCH;
177 }
178
179 // Display status bar
180 if (Error)
181 {
182 if ((Error & AW_WARNING))
183 {
184 statusbar->setStyleSheet("background-color: lightyellow; font: bold");
185 }
186 else
187 {
188 statusbar->setStyleSheet("background-color: tomato; font: bold");
189 }
190 }
191 else
192 {
193 statusbar->setStyleSheet("background-color: lightgreen; font: bold");
194 }
195 statusbar->showMessage(QString(msg));
196 }
197 }
198
199
200 //
201 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)
202 {
203 if (e->key() == Qt::Key_Escape)
204 {
205 hide();
206 }
207 }
208