Skip to content

Commit eecfba3

Browse files
committed
Finished Matrix Visializer.
1 parent 3eb4aaf commit eecfba3

File tree

6 files changed

+158
-1
lines changed

6 files changed

+158
-1
lines changed

src/SeerMatrixVisualizerWidget.cpp

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "SeerMatrixVisualizerWidget.h"
2+
#include "SeerHelpPageDialog.h"
23
#include "SeerUtl.h"
34
#include <QtWidgets/QMessageBox>
45
#include <QtWidgets/QFileDialog>
@@ -11,6 +12,8 @@
1112
#include <QtCore/QSettings>
1213
#include <QtCore/QDebug>
1314
#include <QtGlobal>
15+
#include <algorithm>
16+
#include <cmath>
1417

1518
SeerMatrixVisualizerWidget::SeerMatrixVisualizerWidget (QWidget* parent) : QWidget(parent) {
1619

@@ -38,6 +41,7 @@ SeerMatrixVisualizerWidget::SeerMatrixVisualizerWidget (QWidget* parent) : QWidg
3841

3942
// Connect things.
4043
QObject::connect(refreshToolButton, &QToolButton::clicked, this, &SeerMatrixVisualizerWidget::handleRefreshButton);
44+
QObject::connect(helpToolButton, &QToolButton::clicked, this, &SeerMatrixVisualizerWidget::handleHelpButton);
4145
QObject::connect(variableNameLineEdit, &SeerHistoryLineEdit::returnPressed, this, &SeerMatrixVisualizerWidget::handleVariableNameLineEdit);
4246
QObject::connect(variableNameLineEdit, &SeerHistoryLineEdit::editingFinished, this, &SeerMatrixVisualizerWidget::handleVariableNameLineEdit);
4347
QObject::connect(matrixRowsLineEdit, &SeerHistoryLineEdit::returnPressed, this, &SeerMatrixVisualizerWidget::handleRefreshButton);
@@ -424,6 +428,14 @@ void SeerMatrixVisualizerWidget::handleRefreshButton () {
424428
emit evaluateMemoryExpression(_memoryId, variableAddressLineEdit->text(), bytes);
425429
}
426430

431+
void SeerMatrixVisualizerWidget::handleHelpButton () {
432+
433+
SeerHelpPageDialog* help = new SeerHelpPageDialog;
434+
help->loadFile(":/seer/resources/help/MatrixVisualizer.md");
435+
help->show();
436+
help->raise();
437+
}
438+
427439
void SeerMatrixVisualizerWidget::handleVariableNameLineEdit () {
428440

429441
setVariableName (variableNameLineEdit->text());
@@ -540,7 +552,84 @@ void SeerMatrixVisualizerWidget::handleMatrixDisplayFormatComboBox (int index) {
540552
}
541553

542554
void SeerMatrixVisualizerWidget::handleDataChanged () {
543-
return; // Do nothing for now.
555+
556+
// Update the meta information.
557+
558+
// Clear everything.
559+
countLineEdit->setText("");
560+
rowsLineEdit->setText("");
561+
columnsLineEdit->setText("");
562+
minimumLineEdit->setText("");
563+
maximumLineEdit->setText("");
564+
sumLineEdit->setText("");
565+
averageLineEdit->setText("");
566+
medianLineEdit->setText("");
567+
rmsLineEdit->setText("");
568+
569+
570+
// If there's nothing to show, just return.
571+
if (matrixTableWidget->dataCount() <= 0) {
572+
return;
573+
}
574+
575+
if (matrixTableWidget->dataValues().count() <= 0) {
576+
return;
577+
}
578+
579+
// Make a copy of the values for us to play with.
580+
QVector<double> values = matrixTableWidget->dataValues();
581+
582+
// Fill in counts.
583+
countLineEdit->setText(QString::number(matrixTableWidget->dataCount()));
584+
rowsLineEdit->setText(QString::number(matrixTableWidget->dataRows()));
585+
columnsLineEdit->setText(QString::number(matrixTableWidget->dataColumns()));
586+
587+
// Calculate statistics.
588+
double val = 0.0;
589+
double min = 0.0;
590+
double max = 0.0;
591+
double sum = 0.0;
592+
double sum2 = 0.0;
593+
double avg = 0.0;
594+
double med = 0.0;
595+
double rms = 0.0;
596+
597+
for (int i=0; i<values.size(); i++) {
598+
599+
val = values[i];
600+
601+
min = std::min(min, val);
602+
max = std::max(max, val);
603+
sum += val;
604+
sum2 += std::pow(val, 2);
605+
}
606+
607+
avg = sum / values.size();
608+
rms = std::sqrt(sum2 / values.size());
609+
610+
// Post them.
611+
minimumLineEdit->setText(QString::number(min));
612+
maximumLineEdit->setText(QString::number(max));
613+
sumLineEdit->setText(QString::number(sum));
614+
averageLineEdit->setText(QString::number(avg));
615+
rmsLineEdit->setText(QString::number(rms));
616+
617+
// For median, we need to sort the values. So do this last.
618+
std::sort(values.begin(), values.end());
619+
620+
// If the number of elements is odd, the median is the middle element
621+
if (values.size() % 2 != 0) {
622+
med = values[values.size() / 2];
623+
}else{
624+
double mid1 = values[values.size() / 2 - 1];
625+
double mid2 = values[values.size() / 2];
626+
627+
med = (mid1 + mid2) / 2.0;
628+
}
629+
630+
medianLineEdit->setText(QString::number(med));
631+
632+
return;
544633
}
545634

546635
void SeerMatrixVisualizerWidget::writeSettings() {

src/SeerMatrixVisualizerWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SeerMatrixVisualizerWidget : public QWidget, protected Ui::SeerMatrixVisua
3434

3535
protected slots:
3636
void handleRefreshButton ();
37+
void handleHelpButton ();
3738
void handleVariableNameLineEdit ();
3839
void handleElementRowsLineEdit ();
3940
void handleElementColumnsLineEdit ();

src/SeerMatrixWidget.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ unsigned long SeerMatrixWidget::dataSize () const {
8383
return 0;
8484
}
8585

86+
int SeerMatrixWidget::dataCount () const {
87+
88+
if (_data == 0) {
89+
return 0;
90+
}
91+
92+
if (elementSize() < 1) {
93+
return 0;
94+
}
95+
96+
return _data->size() / elementSize();
97+
}
98+
8699
unsigned long SeerMatrixWidget::elementSize () const {
87100

88101
if (dataType() == SeerMatrixWidget::Int16MatrixType) {
@@ -141,6 +154,11 @@ QString SeerMatrixWidget::dataTypeString () const {
141154
return "???";
142155
}
143156

157+
const QVector<double>& SeerMatrixWidget::dataValues () const {
158+
159+
return _dataValues;
160+
}
161+
144162
void SeerMatrixWidget::setData(SeerMatrixWidget::DataStorage* pData) {
145163

146164
if (_data) {

src/SeerMatrixWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class SeerMatrixWidget: public QTableWidget {
5454
int dataRows () const;
5555
int dataColumns () const;
5656
unsigned long dataSize () const;
57+
int dataCount () const;
5758

5859
signals:
5960
void dataChanged ();

src/resource.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<file>resources/help/BasicStructVisualizer.md</file>
6666
<file>resources/help/MemoryVisualizer.md</file>
6767
<file>resources/help/ArrayVisualizer.md</file>
68+
<file>resources/help/MatrixVisualizer.md</file>
6869
<file>resources/help/ImageVisualizer.md</file>
6970
<file>resources/help/StackInfoBrowser.md</file>
7071
<file>resources/help/VariableRegisterInfoBrowser.md</file>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Matrix Visualizer
2+
3+
### Introduction
4+
5+
The Matrix Visualizer shows the contents of an array as a matrix, a number of rows and an number of columns.
6+
7+
The Matrix Visualizer is made up of 3 main parts:
8+
9+
* Input parameters
10+
* Values table
11+
* Statistic information
12+
13+
### Input parameters
14+
15+
This part of the Visualizer specifies the array to view. Here are the details for an array.
16+
17+
* Variable name of the array. The name name should resolve to an address.
18+
* Number of rows and columns. The total length of the array is determined from this.
19+
* Array offset. How many elements to initially skip. Default 0 (start at the begining of the array).
20+
* Array stride. How the elements are accessed in the array. Default 1 (use every element). 2 would access every second element.
21+
* Array data type.
22+
* Refresh.
23+
24+
By having array offset and array stride, it's possible to handle oddly constructed arrays.
25+
26+
### Values table
27+
28+
This part of the Visualizer shows the array's values as a matrix. The number of rows and number of columns reflect the values
29+
entered in the input parameters.
30+
31+
Note, the array offset and array stride is taken into account.
32+
33+
### Statistic information
34+
35+
These statistical values are calculated from the array values.
36+
37+
* Count of values
38+
* Count of number of rows
39+
* Count of number of columns
40+
* Minimum value of values
41+
* Maximum value of values
42+
* Sum of values
43+
* Average value
44+
* Median value
45+
* RMS value
46+
47+

0 commit comments

Comments
 (0)