UI modifications
[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 and better status report
12 // JPM 09/14/2018 Set information values in a tab
13 //
14
15 // STILL TO DO:
16 // Better presentation
17 // To set the information display at the right
18 //
19
20 //#define AW_DEBUGNUMVARIABLE 177 // 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 model->setRowCount(0);
132 #endif
133 if (NbWatch)
134 {
135 for (uint32_t i = AW_STARTNUMVARIABLE; i < NbWatch; i++)
136 {
137 if ((PtrWatchInfo[i].TypeTag & (DBG_TAG_TYPE_array | DBG_TAG_TYPE_structure)))
138 {
139 #if defined(AW_SUPPORTARRAY) || defined(AW_SUPPORTSTRUCTURE)
140 //PtrValue = (char *)memcpy(Value, &jaguarMainRAM[PtrWatchInfo[i].addr], 20);
141 PtrValue = NULL;
142 #else
143 PtrValue = NULL;
144 #endif
145 }
146 else
147 {
148 PtrValue = DBGManager_GetGlobalVariableValue(i + 1);
149 }
150 #ifdef AW_LAYOUTTEXTS
151 if (i)
152 {
153 WatchAll += QString("<br>");
154 }
155 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>");
156 WatchAll += QString(string);
157 #else
158 model->insertRow(i);
159 model->setItem(i, 0, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableName)));
160 model->setItem(i, 1, new QStandardItem(QString("%1").arg(PtrValue)));
161 model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrWatchInfo[i].PtrVariableBaseTypeName)));
162 #endif
163 }
164 #ifdef AW_LAYOUTTEXTS
165 text->clear();
166 text->setText(WatchAll);
167 #endif
168 sprintf(msg, "Ready");
169 }
170 else
171 {
172 sprintf(msg, "No watches");
173 Error = AW_NOALLWATCH;
174 }
175
176 // Display status bar
177 if (Error)
178 {
179 if ((Error & AW_WARNING))
180 {
181 statusbar->setStyleSheet("background-color: lightyellow; font: bold");
182 }
183 else
184 {
185 statusbar->setStyleSheet("background-color: tomato; font: bold");
186 }
187 }
188 else
189 {
190 statusbar->setStyleSheet("background-color: lightgreen; font: bold");
191 }
192 statusbar->showMessage(QString(msg));
193 }
194 }
195
196
197 //
198 void AllWatchBrowserWindow::keyPressEvent(QKeyEvent * e)
199 {
200 if (e->key() == Qt::Key_Escape)
201 {
202 hide();
203 }
204 }
205