Skip to content

Commit 046cea0

Browse files
author
Mich
committed
Fixed insane Y-axis graph scaling if single flat graph is currently visible
1 parent a7a8a63 commit 046cea0

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

src/mainwindow.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ void MainWindow::setupTable()
3737
void MainWindow::processTable(QStringList labels, QList<double> values)
3838
{
3939
static QList<int> tableMissingCount;
40-
static QList<int> tableIntervalList;
4140

4241
foreach (auto label, labels)
4342
{
@@ -473,7 +472,7 @@ void MainWindow::createChart()
473472
connect(ui->widgetChart, SIGNAL(mousePress(QMouseEvent *)), this, SLOT(chartMousePressHandler(QMouseEvent *)));
474473
connect(ui->widgetChart, SIGNAL(selectionChangedByUser()), this, SLOT(chartSelectionChanged()));
475474
connect(ui->widgetChart, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(chartContextMenuRequest(QPoint)));
476-
connect(ui->widgetChart, SIGNAL(beforeReplot()), this, SLOT(chartRunAutoTrackSlot()));
475+
connect(ui->widgetChart, SIGNAL(beforeReplot()), this, SLOT(chartBeforeReplotSlot()));
477476

478477
// ui->widgetChart->setNotAntialiasedElements(QCP::aeAll);
479478

@@ -484,7 +483,8 @@ void MainWindow::createChart()
484483
}
485484
}
486485

487-
void MainWindow::chartRunAutoTrackSlot()
486+
// Auto-scroll X and rescale Y
487+
void MainWindow::chartBeforeReplotSlot()
488488
{
489489
if (ui->checkBoxAutoTrack->isChecked() && ui->widgetChart->graphCount() > 0)
490490
{
@@ -496,15 +496,23 @@ void MainWindow::chartRunAutoTrackSlot()
496496

497497
if (ui->checkBoxAutoRescaleY->isChecked())
498498
{
499-
bool atLeastOneGraphVisible = false, onlyFlatGraphsVisible = false;
499+
bool atLeastOneGraphVisible = false, atLeastOneNotFlat = false;
500500

501501
for (auto i = 0; i < ui->widgetChart->graphCount(); ++i)
502502
{
503503
if (ui->widgetChart->graph(i)->visible())
504+
{
504505
atLeastOneGraphVisible = true;
506+
507+
bool foundRange = false;
508+
QCPRange valueRange = ui->widgetChart->graph(i)->data().data()->valueRange(foundRange);
509+
510+
if (foundRange && abs(valueRange.upper - valueRange.lower) >= 0.1)
511+
atLeastOneNotFlat = true;
512+
}
505513
}
506514

507-
if (atLeastOneGraphVisible == true) //*&& onlyFlatGraphsVisible == false*//
515+
if (atLeastOneGraphVisible && atLeastOneNotFlat)
508516
{
509517
ui->widgetChart->yAxis->rescale(true);
510518
ui->widgetChart->yAxis->scaleRange(1.20);
@@ -715,9 +723,9 @@ void MainWindow::showPointValue(QMouseEvent *event)
715723
"<td>Y: %L3</td>"
716724
"</tr>"
717725
"</table>")
718-
.arg(graph->name())
719-
.arg(QTime::fromMSecsSinceStartOfDay(temp.x() * 1000).toString("hh:mm:ss:zzz"))
720-
.arg(QString::number(temp.y(), 'f', 5)),
726+
.arg(graph->name())
727+
.arg(QTime::fromMSecsSinceStartOfDay(temp.x() * 1000).toString("hh:mm:ss:zzz"))
728+
.arg(QString::number(temp.y(), 'f', 5)),
721729
ui->widgetChart, ui->widgetChart->rect());
722730
}
723731

@@ -866,9 +874,9 @@ void MainWindow::processChart(QStringList labelList, QList<double> numericDataLi
866874
}
867875

868876
if (canAddGraph && ui->widgetChart->graphCount() < ui->spinBoxMaxGraphs->value() &&
869-
((ui->comboBoxGraphDisplayMode->currentIndex() == 0) ||
870-
(ui->comboBoxGraphDisplayMode->currentIndex() == 1 &&
871-
ui->lineEditCustomParsingRules->text().simplified().contains(label, Qt::CaseSensitivity::CaseSensitive))))
877+
((ui->comboBoxGraphDisplayMode->currentIndex() == 0) ||
878+
(ui->comboBoxGraphDisplayMode->currentIndex() == 1 &&
879+
ui->lineEditCustomParsingRules->text().simplified().contains(label, Qt::CaseSensitivity::CaseSensitive))))
872880
{
873881
ui->widgetChart->addGraph();
874882
ui->widgetChart->graph()->setName(label);
@@ -1010,6 +1018,11 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
10101018
ui->checkBoxShowLegend->toggle();
10111019
}
10121020
}
1021+
1022+
if (event->key() == Qt::Key_F1)
1023+
{
1024+
QWhatsThis::enterWhatsThisMode();
1025+
}
10131026
}
10141027

10151028
void MainWindow::sendSerial(QString message)
@@ -2018,3 +2031,8 @@ void MainWindow::on_pushButtonSaveRAMBuffer_clicked()
20182031

20192032
parser.appendSetToMemory(newlabelList, newDataList, newTimeList, text);
20202033
}
2034+
2035+
void MainWindow::on_actionUser_guide_triggered()
2036+
{
2037+
QWhatsThis::enterWhatsThisMode();
2038+
}

src/mainwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private slots:
5656
void chartContextMenuRequest(QPoint pos);
5757
void chartMouseDoubleClickHandler(QMouseEvent *event);
5858
void chartMousePressHandler(QMouseEvent *event);
59-
void chartRunAutoTrackSlot();
59+
void chartBeforeReplotSlot();
6060
void chartSelectionChanged();
6161
void comboBoxSendReturnPressedSlot();
6262
void hideAllGraphs();
@@ -131,6 +131,8 @@ private slots:
131131
void showSelectedGraph();
132132
void showSelectedGraphExclusively();
133133
void updateDeviceList();
134+
void on_actionUser_guide_triggered();
135+
134136
private:
135137
// QCompleter *completer;
136138
FileReader fileReader;

src/mainwindow.ui

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,9 @@
13881388
<pointsize>9</pointsize>
13891389
</font>
13901390
</property>
1391+
<property name="whatsThis">
1392+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the main text browser. Received messages and notification will be displayed here.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
1393+
</property>
13911394
<property name="lineWrapMode">
13921395
<enum>QTextEdit::NoWrap</enum>
13931396
</property>
@@ -2335,6 +2338,7 @@
23352338
<property name="title">
23362339
<string>Help</string>
23372340
</property>
2341+
<addaction name="actionUser_guide"/>
23382342
<addaction name="actionWhat_s_new"/>
23392343
<addaction name="actionAbout_Qt"/>
23402344
</widget>
@@ -2412,7 +2416,7 @@
24122416
</action>
24132417
<action name="actionWhat_s_new">
24142418
<property name="text">
2415-
<string>What's new ?</string>
2419+
<string>Changelog</string>
24162420
</property>
24172421
</action>
24182422
<action name="actionAbout_Qt">
@@ -2462,6 +2466,11 @@
24622466
<string>Print Log...</string>
24632467
</property>
24642468
</action>
2469+
<action name="actionUser_guide">
2470+
<property name="text">
2471+
<string>Enter &quot;What's this ?&quot;</string>
2472+
</property>
2473+
</action>
24652474
</widget>
24662475
<layoutdefault spacing="6" margin="11"/>
24672476
<customwidgets>

0 commit comments

Comments
 (0)