Skip to content

Commit

Permalink
chore(cpn): Upgrade to qcustomplot 2.1.1 (#4248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Horne authored Oct 27, 2023
1 parent 31fad8b commit b5f0ab3
Show file tree
Hide file tree
Showing 6 changed files with 35,619 additions and 19,387 deletions.
67 changes: 38 additions & 29 deletions companion/src/logsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ LogsDialog::LogsDialog(QWidget *parent) :
pen.setWidthF(1.0);

// create and prepare a plot title layout element
QCPPlotTitle *title = new QCPPlotTitle(ui->customPlot);
QCPTextElement *title = new QCPTextElement(ui->customPlot);
QFont titlefont = font();
titlefont.setBold(true);
title->setText(tr("Telemetry logs"));
title->setFont(titlefont);

// add it to the main plot layout
ui->customPlot->plotLayout()->insertRow(0);
Expand All @@ -69,11 +72,15 @@ LogsDialog::LogsDialog(QWidget *parent) :
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);

axisRect = ui->customPlot->axisRect();

// configure bottom axis to show time instead of number:
axisRect->axis(QCPAxis::atBottom)->setLabel(tr("Time (hh:mm:ss)"));
axisRect->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
axisRect->axis(QCPAxis::atBottom)->setDateTimeFormat("hh:mm:ss");
QSharedPointer<QCPAxisTickerDateTime> timeTicker(new QCPAxisTickerDateTime);
timeTicker->setDateTimeFormat("hh:mm:ss");
axisRect->axis(QCPAxis::atBottom)->setTicker(timeTicker);
QDateTime now = QDateTime::currentDateTime();
axisRect->axis(QCPAxis::atBottom)->setRange(now.addSecs(-60*60*2).toTime_t(), now.toTime_t());
axisRect->axis(QCPAxis::atBottom)->setRange(now.addSecs(-60 * 60 * 2).toTime_t(), now.toTime_t());

axisRect->axis(QCPAxis::atLeft)->setTickLabels(false);
axisRect->addAxis(QCPAxis::atLeft);
axisRect->addAxis(QCPAxis::atRight);
Expand Down Expand Up @@ -103,37 +110,42 @@ LogsDialog::LogsDialog(QWidget *parent) :
ui->SaveSession_PB->setEnabled(false);

// connect slot that ties some axis selections together (especially opposite axes):
connect(ui->customPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
connect(ui->customPlot, &QCustomPlot::selectionChangedByUser, this, &LogsDialog::selectionChanged);
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress(QMouseEvent*)));
connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
connect(ui->customPlot, &QCustomPlot::mousePress, this, &LogsDialog::mousePress);
connect(ui->customPlot, &QCustomPlot::mouseWheel, this, &LogsDialog::mouseWheel);

// make left axes transfer its range to right axes:
connect(axisRect->axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChangeRanges(QCPRange)));

connect(axisRect->axis(QCPAxis::atLeft), static_cast<void(QCPAxis::*)(const QCPRange&)>(&QCPAxis::rangeChanged), this, &LogsDialog::yAxisChangeRanges);
// connect some interaction slots:
connect(ui->customPlot, SIGNAL(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)));
connect(ui->customPlot, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
connect(ui->customPlot, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));
connect(ui->FieldsTW, SIGNAL(itemSelectionChanged()), this, SLOT(plotLogs()));
connect(ui->logTable, SIGNAL(itemSelectionChanged()), this, SLOT(plotLogs()));
connect(ui->Reset_PB, SIGNAL(clicked()), this, SLOT(plotLogs()));
connect(ui->SaveSession_PB, SIGNAL(clicked()), this, SLOT(saveSession()));
connect(title, &QCPTextElement::doubleClicked, this, &LogsDialog::titleDoubleClicked);
connect(ui->customPlot, &QCustomPlot::axisDoubleClick, this, &LogsDialog::axisLabelDoubleClick);
connect(ui->customPlot, &QCustomPlot::legendDoubleClick, this, &LogsDialog::legendDoubleClick);
connect(ui->FieldsTW, &QTableWidget::itemSelectionChanged, this, &LogsDialog::plotLogs);
connect(ui->logTable, &QTableWidget::itemSelectionChanged, this, &LogsDialog::plotLogs);
connect(ui->Reset_PB, &QPushButton::clicked, this, &LogsDialog::plotLogs);
connect(ui->SaveSession_PB, &QPushButton::clicked, this, &LogsDialog::saveSession);
connect(ui->fileOpen_PB, &QPushButton::clicked, this, &LogsDialog::fileOpen);
connect(ui->mapsButton, &QPushButton::clicked, this, &LogsDialog::mapsButtonClicked);
connect(ui->sessions_CB, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &LogsDialog::sessionsCurrentIndexChanged);
}

LogsDialog::~LogsDialog()
{
delete ui;
}

void LogsDialog::titleDoubleClick(QMouseEvent *evt, QCPPlotTitle *title)
void LogsDialog::titleDoubleClicked(QMouseEvent *evt)
{
// Set the plot title by double clicking on it
bool ok;
QString newTitle = QInputDialog::getText(this, tr("Plot Title Change"), tr("New plot title:"), QLineEdit::Normal, title->text(), &ok);
if (ok) {
title->setText(newTitle);
ui->customPlot->replot();
QCPTextElement *title = qobject_cast<QCPTextElement*>(sender());
if (title) {
bool ok;
QString newTitle = QInputDialog::getText(this, tr("Plot Title Change"), tr("New plot title:"), QLineEdit::Normal, title->text(), &ok);
if (ok) {
title->setText(newTitle);
ui->customPlot->replot();
}
}
}

Expand Down Expand Up @@ -231,7 +243,7 @@ void LogsDialog::selectionChanged()
if (item == NULL) item = rightLegend->itemWithPlottable(graph);
if (item->selected() || graph->selected()) {
item->setSelected(true);
graph->setSelected(true);
graph->setSelection(QCPDataSelection(QCPDataRange()));
}
}
}
Expand Down Expand Up @@ -431,7 +443,7 @@ void LogsDialog::exportToGoogleEarth()
QProcess::startDetached(gePath, parameters);
}

void LogsDialog::on_mapsButton_clicked()
void LogsDialog::mapsButtonClicked()
{
ui->FieldsTW->setDisabled(true);
ui->logTable->setDisabled(true);
Expand Down Expand Up @@ -565,7 +577,7 @@ void LogsDialog::removeAllGraphs()
ui->labelCursors->setText("");
}

void LogsDialog::on_fileOpen_BT_clicked()
void LogsDialog::fileOpen()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Select your log file"), g.logDir());
if (!fileName.isEmpty()) {
Expand Down Expand Up @@ -776,7 +788,7 @@ void LogsDialog::setFlightSessions()
}
}

void LogsDialog::on_sessions_CB_currentIndexChanged(int index)
void LogsDialog::sessionsCurrentIndexChanged(int index)
{
if (plotLock) return;
plotLock = true;
Expand Down Expand Up @@ -1126,7 +1138,6 @@ void LogsDialog::addMaxAltitudeMarker(const coords_t & c, QCPGraph * graph) {

// add max altitude marker
tracerMaxAlt = new QCPItemTracer(ui->customPlot);
ui->customPlot->addItem(tracerMaxAlt);
tracerMaxAlt->setGraph(graph);
tracerMaxAlt->setInterpolating(true);
tracerMaxAlt->setStyle(QCPItemTracer::tsSquare);
Expand All @@ -1153,7 +1164,6 @@ void LogsDialog::countNumberOfThrows(const coords_t & c, QCPGraph * graph)

void LogsDialog::addCursor(QCPItemTracer ** cursor, QCPGraph * graph, const QColor & color) {
QCPItemTracer * c = new QCPItemTracer(ui->customPlot);
ui->customPlot->addItem(c);
c->setGraph(graph);
c->setInterpolating(false);
c->setStyle(QCPItemTracer::tsCrosshair);
Expand All @@ -1168,7 +1178,6 @@ void LogsDialog::addCursor(QCPItemTracer ** cursor, QCPGraph * graph, const QCol

void LogsDialog::addCursorLine(QCPItemStraightLine ** line, QCPGraph * graph, const QColor & color) {
QCPItemStraightLine * l = new QCPItemStraightLine(ui->customPlot);
ui->customPlot->addItem(l);
l->point1->setParentAnchor(cursorA->position);
l->point2->setParentAnchor(cursorB->position);
QPen pen(color);
Expand Down
13 changes: 5 additions & 8 deletions companion/src/logsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
* GNU General Public License for more details.
*/

#ifndef _LOGSDIALOG_H_
#define _LOGSDIALOG_H_
#pragma once

#include <QtCore>
#include <QDialog>
Expand Down Expand Up @@ -69,18 +68,18 @@ class LogsDialog : public QDialog
~LogsDialog();

private slots:
void titleDoubleClick(QMouseEvent *evt, QCPPlotTitle *title);
void titleDoubleClicked(QMouseEvent *evt);
void axisLabelDoubleClick(QCPAxis* axis, QCPAxis::SelectablePart part);
void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item);
void selectionChanged();
void mousePress(QMouseEvent * event);
void mouseWheel();
void removeAllGraphs();
void plotLogs();
void on_fileOpen_BT_clicked();
void fileOpen();
void saveSession();
void on_sessions_CB_currentIndexChanged(int index);
void on_mapsButton_clicked();
void sessionsCurrentIndexChanged(int index);
void mapsButtonClicked();
void yAxisChangeRanges(QCPRange range);

private:
Expand Down Expand Up @@ -119,5 +118,3 @@ private slots:


};

#endif // _LOGSDIALOG_H_
15 changes: 12 additions & 3 deletions companion/src/logsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -232,7 +241,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="fileOpen_BT">
<widget class="QPushButton" name="fileOpen_PB">
<property name="text">
<string>Open LogFile</string>
</property>
Expand Down Expand Up @@ -275,7 +284,7 @@
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>18</number>
<number>21</number>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>true</bool>
Expand Down
Loading

0 comments on commit b5f0ab3

Please sign in to comment.