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 checkbox behaviour #384

Closed
wants to merge 6 commits into from
Closed
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
164 changes: 102 additions & 62 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,54 @@ 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 && item->column() != dataTableColName) {
updateGraphs();
}
});

connect(ui->dataTable, &QTableWidget::itemClicked, [this](QTableWidgetItem *item) {
printf("itemClicked %d %d %d\n", item->row(), item->column(), item->checkState());

if (item->column() == dataTableColY2){
auto i1 = ui->dataTable->item(item->row(), dataTableColY2);

if(i1->checkState() == Qt::Checked) {
ui->dataTable->item(i1->row(), dataTableColY2)->setCheckState(Qt::Unchecked);

}else if(i1->checkState() == Qt::Unchecked) {
ui->dataTable->item(i1->row(), dataTableColY2)->setCheckState(Qt::Checked);
}
}
if (item->column() == dataTableColY1) {
auto i1 = ui->dataTable->item(item->row(), dataTableColY1);

if(i1->checkState() == Qt::Checked) {
ui->dataTable->item(i1->row(), dataTableColY1)->setCheckState(Qt::Unchecked);

}else if(i1->checkState() == Qt::Unchecked) {
ui->dataTable->item(i1->row(), dataTableColY1)->setCheckState(Qt::Checked);
}
}
});


m3dView = new Vesc3DView(this);
m3dView->setMinimumWidth(200);
m3dView->setRollPitchYaw(20, 20, 0);
Expand Down Expand Up @@ -755,15 +795,20 @@ void PageLogAnalysis::updateGraphs()
{
QSet<QModelIndex> uniqueRows;

auto selectedRows = ui->dataTable->selectionModel()->selectedRows();
for (const QModelIndex &index : selectedRows) {
uniqueRows.insert(index);
}
// auto selectedRows = ui->dataTable->selectionModel()->selectedRows();
// for (const QModelIndex &index : selectedRows) {
// uniqueRows.insert(index);
// }

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, dataTableColName));
}
item = ui->dataTable->item(row, dataTableColY2);
if (item && item->checkState() == Qt::Checked) {
uniqueRows.insert(ui->dataTable->model()->index(row, 0));
uniqueRows.insert(ui->dataTable->model()->index(row, dataTableColName));
}
}

Expand Down Expand Up @@ -799,7 +844,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 +881,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 +1061,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 +1192,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 +1416,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 +1448,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 +1460,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 +1478,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
10 changes: 8 additions & 2 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 @@ -572,7 +578,7 @@
</column>
<column>
<property name="text">
<string>Plot</string>
<string>Y1</string>
</property>
</column>
<column>
Expand Down
Loading