Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/plot yaxis2 #383

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 72 additions & 58 deletions pages/pageloganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

static const int dataTableColName = 0;
static const int dataTableColValue = 1;
static const int dataTableColPlot = 2;
static const int dataTableColAltAxis = 3;
static const int dataTableColY1 = 2;
static const int dataTableColY2 = 3;
static const int dataTableColScale = 4;

PageLogAnalysis::PageLogAnalysis(QWidget *parent) :
Expand Down Expand Up @@ -82,14 +82,28 @@ PageLogAnalysis::PageLogAnalysis(QWidget *parent) :

ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColName, QHeaderView::Interactive);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColValue, QHeaderView::Stretch);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColY1, QHeaderView::Fixed);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColY2, QHeaderView::Fixed);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColScale, QHeaderView::Fixed);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColAltAxis, QHeaderView::Fixed);
ui->dataTable->horizontalHeader()->setSectionResizeMode(dataTableColPlot, QHeaderView::Fixed);

ui->dataTable->setColumnWidth(dataTableColAltAxis, 30);
ui->dataTable->setColumnWidth(dataTableColPlot, 45);
ui->dataTable->setColumnWidth(dataTableColY1, 30);
ui->dataTable->setColumnWidth(dataTableColY2, 30);
ui->dataTable->setColumnWidth(dataTableColScale, 60);

connect(ui->dataTable, &QTableWidget::itemChanged, [this](QTableWidgetItem *item) {
if (item->checkState() == Qt::Checked) {
if (item->column() == dataTableColY1){
ui->dataTable->item(item->row(), dataTableColY2)->setCheckState(Qt::Unchecked);
}
if (item->column() == dataTableColY2) {
ui->dataTable->item(item->row(), dataTableColY1)->setCheckState(Qt::Unchecked);
}
}
if (item->column() > dataTableColValue) {
updateGraphs();
}
});

m3dView = new Vesc3DView(this);
m3dView->setMinimumWidth(200);
m3dView->setRollPitchYaw(20, 20, 0);
Expand Down Expand Up @@ -761,9 +775,14 @@ void PageLogAnalysis::updateGraphs()
}

for (int row = 0; row < ui->dataTable->rowCount(); ++row) {
QTableWidgetItem *item = ui->dataTable->item(row, dataTableColPlot);
QTableWidgetItem *item;
item = ui->dataTable->item(row, dataTableColY1);
if (item && item->checkState() == Qt::Checked) {
uniqueRows.insert(ui->dataTable->model()->index(row, 0));
uniqueRows.insert(ui->dataTable->model()->index(row, dataTableColName));
}
item = ui->dataTable->item(row, dataTableColY2);
if (item && item->checkState() == Qt::Checked) {
uniqueRows.insert(ui->dataTable->model()->index(row, dataTableColName));
}
}

Expand Down Expand Up @@ -799,7 +818,7 @@ void PageLogAnalysis::updateGraphs()
int row = rows.at(r).row();
double rowScale = 1.0;
if(QDoubleSpinBox *sb = qobject_cast<QDoubleSpinBox*>
(ui->dataTable->cellWidget(row, 2))) {
(ui->dataTable->cellWidget(row, dataTableColScale))) {
rowScale = sb->value();
}

Expand Down Expand Up @@ -836,20 +855,19 @@ void PageLogAnalysis::updateGraphs()

auto row = rows.at(i).row();

bool altAxis = false;
bool y2Axis = false;

if (QTableWidgetItem *aaWidget = ui->dataTable->item(row, dataTableColAltAxis)) {
altAxis = (aaWidget->checkState() == Qt::Checked);
if(QTableWidgetItem *y2Widget = ui->dataTable->item(row, dataTableColY2)) {
y2Axis = (y2Widget->checkState() == Qt::Checked);
}

if (altAxis) {
if(y2Axis){
ui->plot->addGraph(ui->plot->xAxis, ui->plot->yAxis2);
ui->plot->yAxis2->setVisible(true);
} else {
} else{
ui->plot->addGraph();
}


ui->plot->graph(i)->setPen(pen);
ui->plot->graph(i)->setName(names.at(i));
ui->plot->graph(i)->setData(xAxis, yAxes.at(i));
Expand Down Expand Up @@ -1017,13 +1035,13 @@ void PageLogAnalysis::updateDataAndPlot(double time)
if (header.isTimeStamp) {
QTime t(0, 0, 0, 0);
t = t.addMSecs(value * 1000);
ui->dataTable->item(ind, 1)->setText(t.toString("hh:mm:ss.zzz"));
ui->dataTable->item(ind, dataTableColValue)->setText(t.toString("hh:mm:ss.zzz"));
} else {
ui->dataTable->item(ind, 1)->setText(
ui->dataTable->item(ind, dataTableColValue)->setText(
QString::number(value, 'f', header.precision) + " " + header.unit);
}
} else {
ui->dataTable->item(ind, 1)->setText(Commands::faultToStr(mc_fault_code(round(value))).mid(11));
ui->dataTable->item(ind, dataTableColValue)->setText(Commands::faultToStr(mc_fault_code(round(value))).mid(11));
}

ind++;
Expand Down Expand Up @@ -1148,46 +1166,42 @@ void PageLogAnalysis::logListRefresh()
void PageLogAnalysis::addDataItem(QString name, bool hasScale, double scaleStep, double scaleMax)
{
ui->dataTable->setRowCount(ui->dataTable->rowCount() + 1);
auto item1 = new QTableWidgetItem(name);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColName, item1);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColValue, new QTableWidgetItem(""));
auto currentRow = ui->dataTable->rowCount() - 1;

auto nameItem = new QTableWidgetItem(name);
ui->dataTable->setItem(currentRow, dataTableColName, nameItem);

ui->dataTable->setItem(currentRow, dataTableColValue, new QTableWidgetItem(""));

if (hasScale) {
QDoubleSpinBox *sb = new QDoubleSpinBox;
sb->setSingleStep(scaleStep);
sb->setValue(1.0);
sb->setMaximum(scaleMax);
// Prevent mouse wheel focus to avoid changing the selection
sb->setFocusPolicy(Qt::StrongFocus);
ui->dataTable->setCellWidget(ui->dataTable->rowCount() - 1, dataTableColScale, sb);
ui->dataTable->setCellWidget(currentRow, dataTableColScale, sb);
connect(sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) {
(void)value;
updateGraphs();
});
(void)value;
updateGraphs();
});

// Y1
QTableWidgetItem *y1Item = new QTableWidgetItem("");
y1Item->setCheckState(Qt::Unchecked);
ui->dataTable->setItem(currentRow, dataTableColY1, y1Item);

// Y2
QTableWidgetItem *y2Item = new QTableWidgetItem("");
y2Item->setCheckState(Qt::Unchecked);
ui->dataTable->setItem(currentRow, dataTableColY2, y2Item);

} else {
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColScale, new QTableWidgetItem("N/A"));
ui->dataTable->setItem(currentRow, dataTableColScale, new QTableWidgetItem("N/A"));
}

// Axis
QTableWidgetItem *axisItem = new QTableWidgetItem("");
axisItem->setCheckState(Qt::Unchecked);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColAltAxis, axisItem);

connect(ui->dataTable, &QTableWidget::itemChanged, [this, axisItem](QTableWidgetItem *item) {
if (item == axisItem){
updateGraphs();
}
});

// Plot
QTableWidgetItem *plotItem = new QTableWidgetItem("");
plotItem->setCheckState(Qt::Unchecked);
ui->dataTable->setItem(ui->dataTable->rowCount() - 1, dataTableColPlot, plotItem);
connect(ui->dataTable, &QTableWidget::itemChanged, [this, plotItem](QTableWidgetItem *item) {
if (item == plotItem){
updateGraphs();
}
});
}

void PageLogAnalysis::openLog(QByteArray data)
Expand Down Expand Up @@ -1376,24 +1390,24 @@ void PageLogAnalysis::generateMissingEntries()
void PageLogAnalysis::storeSelection()
{
mSelection.dataLabels.clear();
mSelection.checkedPlotBoxes.clear();
mSelection.checkedY1Boxes.clear();
mSelection.checkedY2Boxes.clear();

// Selected rows
foreach (auto i, ui->dataTable->selectionModel()->selectedRows()) {
mSelection.dataLabels.append(ui->dataTable->item(i.row(), 0)->text());
mSelection.dataLabels.append(ui->dataTable->item(i.row(), dataTableColName)->text());
}

// Selected plot and y2 boxes
for (int row = 0; row < ui->dataTable->rowCount(); row++) {
QTableWidgetItem *itemPlot = ui->dataTable->item(row, dataTableColPlot);
auto rowText = ui->dataTable->item(row, 0)->text();
auto rowText = ui->dataTable->item(row, dataTableColName)->text();

QTableWidgetItem *itemPlot = ui->dataTable->item(row, dataTableColY1);
if (itemPlot->checkState() == Qt::Checked) {
mSelection.checkedPlotBoxes.append(rowText);
mSelection.checkedY1Boxes.append(rowText);
}

QTableWidgetItem *itemY2 = ui->dataTable->item(row, dataTableColAltAxis);
QTableWidgetItem *itemY2 = ui->dataTable->item(row, dataTableColY2);
if (itemY2->checkState() == Qt::Checked) {
mSelection.checkedY2Boxes.append(rowText);
}
Expand All @@ -1408,9 +1422,9 @@ void PageLogAnalysis::restoreSelection()
auto modeOld = ui->dataTable->selectionMode();
ui->dataTable->setSelectionMode(QAbstractItemView::MultiSelection);
for (int row = 0;row < ui->dataTable->rowCount();row++) {
auto rowText = ui->dataTable->item(row, 0)->text();
auto rowText = ui->dataTable->item(row, dataTableColName)->text();
bool selected = false;
bool checkedPlot = false;
bool checkedY1 = false;
bool checkedY2 = false;

foreach (auto i, mSelection.dataLabels) {
Expand All @@ -1420,9 +1434,9 @@ void PageLogAnalysis::restoreSelection()
}
}

foreach (auto i, mSelection.checkedPlotBoxes) {
foreach (auto i, mSelection.checkedY1Boxes) {
if (rowText == i) {
checkedPlot = true;
checkedY1 = true;
break;
}
}
Expand All @@ -1438,12 +1452,12 @@ void PageLogAnalysis::restoreSelection()
ui->dataTable->selectRow(row);
}

if (checkedPlot) {
ui->dataTable->item(row, dataTableColAltAxis)->setCheckState(Qt::Checked);
if (checkedY1) {
ui->dataTable->item(row, dataTableColY1)->setCheckState(Qt::Checked);
}

if (checkedY2) {
ui->dataTable->item(row, dataTableColPlot)->setCheckState(Qt::Checked);
ui->dataTable->item(row, dataTableColY2)->setCheckState(Qt::Checked);
}
}
ui->dataTable->setSelectionMode(modeOld);
Expand Down
2 changes: 1 addition & 1 deletion pages/pageloganalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private slots:

struct SelectoData {
QStringList dataLabels;
QStringList checkedPlotBoxes;
QStringList checkedY1Boxes;
QStringList checkedY2Boxes;
int scrollPos;
};
Expand Down
22 changes: 14 additions & 8 deletions pages/pageloganalysis.ui
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@
<property name="sizeType">
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
Expand Down Expand Up @@ -239,7 +245,7 @@
<enum>QTabWidget::TabShape::Triangular</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
Expand Down Expand Up @@ -562,25 +568,25 @@
</attribute>
<column>
<property name="text">
<string>Name</string>
<string>Y1</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
<string>Y2</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show this data series on the second Y axis to the right&lt;/p&gt;&lt;p&gt;Y axes will be autoscaled independently&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
<column>
<property name="text">
<string>Plot</string>
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Y2</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show this data series on the second Y axis to the right&lt;/p&gt;&lt;p&gt;Y axes will be autoscaled independently&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Value</string>
</property>
</column>
<column>
Expand Down
Loading