Log Viewer multi-axes. Fixes #2267.

This commit is contained in:
Grieb
2015-05-21 22:08:46 -03:00
parent 22dab11ccf
commit 46ccd15924
2 changed files with 198 additions and 104 deletions
+178 -91
View File
@@ -73,7 +73,7 @@ logsDialog::logsDialog(QWidget *parent) :
connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel())); connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make left axes transfer its range to right axes: // make left axes transfer its range to right axes:
connect(axisRect->axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setRangeyAxis2(QCPRange))); connect(axisRect->axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), this, SLOT(yAxisChangeRanges(QCPRange)));
// connect some interaction slots: // connect some interaction slots:
connect(ui->customPlot, SIGNAL(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*, QCPPlotTitle*))); connect(ui->customPlot, SIGNAL(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)), this, SLOT(titleDoubleClick(QMouseEvent*, QCPPlotTitle*)));
@@ -162,14 +162,33 @@ void logsDialog::selectionChanged()
// and handle axis and tick labels as one selectable object: // and handle axis and tick labels as one selectable object:
if (axisRect->axis(QCPAxis::atLeft)->selectedParts().testFlag(QCPAxis::spAxis) || if (axisRect->axis(QCPAxis::atLeft)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atLeft)->selectedParts().testFlag(QCPAxis::spTickLabels) || axisRect->axis(QCPAxis::atLeft)->selectedParts().testFlag(QCPAxis::spTickLabels) ||
axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spAxis) || (
axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spTickLabels)) axisRect->axis(QCPAxis::atRight)->visible() &&
{ (axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spTickLabels))
) || (
axisRect->axisCount(QCPAxis::atLeft) == 2 &&
(axisRect->axis(QCPAxis::atLeft, 1)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atLeft, 1)->selectedParts().testFlag(QCPAxis::spTickLabels))
) || (
axisRect->axisCount(QCPAxis::atRight) == 2 &&
(axisRect->axis(QCPAxis::atRight, 1)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atRight, 1)->selectedParts().testFlag(QCPAxis::spTickLabels))
)
) {
axisRect->axis(QCPAxis::atLeft)->setSelectedParts(QCPAxis::spAxis | axisRect->axis(QCPAxis::atLeft)->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels); QCPAxis::spTickLabels);
if (hasyAxis2) { if (axisRect->axis(QCPAxis::atRight)->visible()) {
axisRect->axis(QCPAxis::atRight)->setSelectedParts(QCPAxis::spAxis | axisRect->axis(QCPAxis::atRight)->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels); QCPAxis::spTickLabels);
if (axisRect->axisCount(QCPAxis::atLeft) == 2) {
axisRect->axis(QCPAxis::atLeft, 1)->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels);
if (axisRect->axisCount(QCPAxis::atRight) == 2) {
axisRect->axis(QCPAxis::atRight, 1)->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels);
}
}
} }
} }
@@ -340,11 +359,11 @@ void logsDialog::on_mapsButton_clicked()
outputStream << "\t\t\t\t\t\t</SchemaData>\n\t\t\t\t\t</ExtendedData>\n\t\t\t\t</gx:Track>\n\t\t\t</Placemark>\n\t\t</Folder>\n\t</Document>\n</kml>"; outputStream << "\t\t\t\t\t\t</SchemaData>\n\t\t\t\t\t</ExtendedData>\n\t\t\t\t</gx:Track>\n\t\t\t</Placemark>\n\t\t</Folder>\n\t</Document>\n</kml>";
geFile.close(); geFile.close();
QStringList parameters; QStringList parameters;
#ifdef __APPLE__ #ifdef __APPLE__
parameters << "-a"; parameters << "-a";
parameters << gePath; parameters << gePath;
gePath = "/usr/bin/open"; gePath = "/usr/bin/open";
#endif #endif
parameters << geFilename; parameters << geFilename;
QProcess *process = new QProcess(this); QProcess *process = new QProcess(this);
process->start(gePath, parameters); process->start(gePath, parameters);
@@ -352,7 +371,6 @@ void logsDialog::on_mapsButton_clicked()
ui->logTable->setDisabled(false); ui->logTable->setDisabled(false);
} }
void logsDialog::mousePress() void logsDialog::mousePress()
{ {
// if an axis is selected, only allow the direction of that axis to be dragged // if an axis is selected, only allow the direction of that axis to be dragged
@@ -397,8 +415,16 @@ void logsDialog::removeAllGraphs()
{ {
ui->customPlot->clearGraphs(); ui->customPlot->clearGraphs();
ui->customPlot->legend->setVisible(false); ui->customPlot->legend->setVisible(false);
axisRect->axis(QCPAxis::atRight)->setSelectedParts(QCPAxis::spNone);
axisRect->axis(QCPAxis::atRight)->setVisible(false); axisRect->axis(QCPAxis::atRight)->setVisible(false);
axisRect->axis(QCPAxis::atLeft)->setSelectedParts(QCPAxis::spNone);
axisRect->axis(QCPAxis::atLeft)->setTickLabels(false); axisRect->axis(QCPAxis::atLeft)->setTickLabels(false);
if (axisRect->axisCount(QCPAxis::atLeft) == 2) {
axisRect->removeAxis(axisRect->axis(QCPAxis::atLeft, 1));
}
if (axisRect->axisCount(QCPAxis::atRight) == 2) {
axisRect->removeAxis(axisRect->axis(QCPAxis::atRight, 1));
}
ui->customPlot->replot(); ui->customPlot->replot();
} }
@@ -526,7 +552,6 @@ bool logsDialog::cvsFileParse()
return true; return true;
} }
void logsDialog::on_sessions_CB_currentIndexChanged(int index) void logsDialog::on_sessions_CB_currentIndexChanged(int index)
{ {
if (plotLock) return; if (plotLock) return;
@@ -589,9 +614,9 @@ void logsDialog::plotLogs()
coords plotCoords; coords plotCoords;
int plotColumn = plot->row() + 2; // Date and Time first int plotColumn = plot->row() + 2; // Date and Time first
plotCoords.min_y = 999999; plotCoords.min_y = INVALID_MIN;
plotCoords.max_y = -999999; plotCoords.max_y = INVALID_MAX;
plotCoords.secondRange = false; plotCoords.yaxis = firstLeft;
plotCoords.name = plot->text(); plotCoords.name = plot->text();
for (int row = 0; row < rowCount; row++) { for (int row = 0; row < rowCount; row++) {
@@ -638,103 +663,137 @@ void logsDialog::plotLogs()
plots.coords.append(plotCoords); plots.coords.append(plotCoords);
} }
plots.rangeOneMin = plots.coords.at(0).min_y; yAxesRanges[firstLeft].min = plots.coords.at(0).min_y;
plots.rangeOneMax = plots.coords.at(0).max_y; yAxesRanges[firstLeft].max = plots.coords.at(0).max_y;
plots.twoRanges = false; for (int i = firstRight; i < AXES_LIMIT; i++) {
yAxesRanges[i].min = INVALID_MIN;
yAxesRanges[i].max = INVALID_MAX;
}
plots.tooManyRanges = false; plots.tooManyRanges = false;
for (int i = 1; i < plots.coords.size(); i++) { for (int i = 1; i < plots.coords.size(); i++) {
if (plots.tooManyRanges) { double actualRange = yAxesRanges[firstLeft].max - yAxesRanges[firstLeft].min;
if (plots.coords.at(i).min_y < plots.rangeOneMin) {
plots.rangeOneMin = plots.coords.at(i).min_y;
}
if (plots.coords.at(i).max_y > plots.rangeOneMax) {
plots.rangeOneMax = plots.coords.at(i).max_y;
}
continue;
}
double actualRange = plots.rangeOneMax - plots.rangeOneMin;
double thisRange = plots.coords.at(i).max_y - plots.coords.at(i).min_y; double thisRange = plots.coords.at(i).max_y - plots.coords.at(i).min_y;
if (thisRange > actualRange * 1.3 || thisRange * 1.3 < actualRange || while (yAxesRanges[plots.coords.at(i).yaxis].max != INVALID_MAX &&
plots.coords.at(i).min_y > plots.rangeOneMax || (thisRange > actualRange * 1.3 || thisRange * 1.3 < actualRange ||
plots.coords.at(i).max_y < plots.rangeOneMin) { plots.coords.at(i).min_y > yAxesRanges[plots.coords.at(i).yaxis].max ||
plots.coords[i].secondRange = true; plots.coords.at(i).max_y < yAxesRanges[plots.coords.at(i).yaxis].min)
if (plots.twoRanges) { ) {
actualRange = plots.rangeTwoMax - plots.rangeTwoMin;
if (thisRange > actualRange * 1.3 || thisRange * 1.3 < actualRange || switch (plots.coords[i].yaxis) {
plots.coords.at(i).min_y > plots.rangeTwoMax || case firstLeft:
plots.coords.at(i).max_y < plots.rangeTwoMin) { plots.coords[i].yaxis = firstRight;
break;
case firstRight:
plots.coords[i].yaxis = secondLeft;
break;
case secondLeft:
plots.coords[i].yaxis = secondRight;
break;
case secondRight:
plots.tooManyRanges = true; plots.tooManyRanges = true;
plots.twoRanges = false; break;
if (plots.rangeTwoMin < plots.rangeOneMin) { default:
plots.rangeOneMin = plots.rangeTwoMin; break;
}
if (plots.rangeTwoMax > plots.rangeOneMax) {
plots.rangeOneMax = plots.rangeTwoMax;
}
if (plots.coords.at(i).min_y < plots.rangeOneMin) {
plots.rangeOneMin = plots.coords.at(i).min_y;
}
if (plots.coords.at(i).max_y > plots.rangeOneMax) {
plots.rangeOneMax = plots.coords.at(i).max_y;
}
} else {
if (plots.coords.at(i).min_y < plots.rangeTwoMin) {
plots.rangeTwoMin = plots.coords.at(i).min_y;
}
if (plots.coords.at(i).max_y > plots.rangeTwoMax) {
plots.rangeTwoMax = plots.coords.at(i).max_y;
}
}
} else {
plots.twoRanges = true;
plots.rangeTwoMax = plots.coords.at(i).max_y;
plots.rangeTwoMin = plots.coords.at(i).min_y;
} }
if (plots.tooManyRanges) break;
actualRange = yAxesRanges[plots.coords.at(i).yaxis].max
- yAxesRanges[plots.coords.at(i).yaxis].min;
}
if (plots.tooManyRanges) {
break;
} else { } else {
if (plots.coords.at(i).min_y < plots.rangeOneMin) { if (plots.coords.at(i).min_y < yAxesRanges[plots.coords.at(i).yaxis].min) {
plots.rangeOneMin = plots.coords.at(i).min_y; yAxesRanges[plots.coords.at(i).yaxis].min = plots.coords.at(i).min_y;
} }
if (plots.coords.at(i).max_y > plots.rangeOneMax) { if (plots.coords.at(i).max_y > yAxesRanges[plots.coords.at(i).yaxis].max) {
plots.rangeOneMax = plots.coords.at(i).max_y; yAxesRanges[plots.coords.at(i).yaxis].max = plots.coords.at(i).max_y;
} }
} }
} }
if (plots.twoRanges) { if (plots.tooManyRanges) {
rangeRatio = (plots.rangeTwoMax - plots.rangeTwoMin) / yAxesRanges[firstLeft].max = 101;
(plots.rangeOneMax - plots.rangeOneMin); yAxesRanges[firstLeft].min = -1;
rangeyAxisMin = plots.rangeOneMin; yAxesRanges[firstRight].max = INVALID_MAX;
rangeyAxisMax = plots.rangeOneMax; yAxesRanges[firstRight].min = INVALID_MIN;
rangeyAxis2Min = plots.rangeTwoMin; yAxesRanges[secondLeft].max = INVALID_MAX;
rangeyAxis2Max = plots.rangeTwoMax; yAxesRanges[secondLeft].min = INVALID_MIN;
yAxesRanges[secondRight].max = INVALID_MAX;
yAxesRanges[secondRight].min = INVALID_MIN;
hasyAxis2 = true; for (int i = 0; i < plots.coords.size(); i++) {
plots.coords[i].yaxis = firstLeft;
double factor = 100 / (plots.coords.at(i).max_y - plots.coords.at(i).min_y);
for (int j = 0; j < plots.coords.at(i).y.count(); j++) {
plots.coords[i].y[j] = factor * (plots.coords.at(i).y.at(j) - plots.coords.at(i).min_y);
}
}
} else { } else {
hasyAxis2 = false; for (int i = firstRight; i < AXES_LIMIT; i++) {
if (yAxesRanges[i].max == INVALID_MAX) break;
yAxesRatios[i] = (yAxesRanges[i].max - yAxesRanges[i].min) /
(yAxesRanges[firstLeft].max - yAxesRanges[firstLeft].min);
}
} }
removeAllGraphs(); removeAllGraphs();
axisRect->axis(QCPAxis::atBottom)->setRange(plots.min_x, plots.max_x); axisRect->axis(QCPAxis::atBottom)->setRange(plots.min_x, plots.max_x);
axisRect->axis(QCPAxis::atLeft)->setRange(plots.rangeOneMin, plots.rangeOneMax); axisRect->axis(QCPAxis::atLeft)->setRange(yAxesRanges[firstLeft].min,
axisRect->axis(QCPAxis::atLeft)->setTickLabels(true); yAxesRanges[firstLeft].max);
if (plots.twoRanges) { if (plots.tooManyRanges) {
axisRect->axis(QCPAxis::atRight)->setRange(plots.rangeTwoMin, plots.rangeTwoMax); axisRect->axis(QCPAxis::atLeft)->setTickLabels(false);
} else {
axisRect->axis(QCPAxis::atLeft)->setTickLabels(true);
}
if (yAxesRanges[firstRight].max != INVALID_MAX) {
axisRect->axis(QCPAxis::atRight)->setRange(yAxesRanges[firstRight].min,
yAxesRanges[firstRight].max);
axisRect->axis(QCPAxis::atRight)->setVisible(true); axisRect->axis(QCPAxis::atRight)->setVisible(true);
} }
if (yAxesRanges[secondLeft].max != INVALID_MAX) {
axisRect->addAxis(QCPAxis::atLeft);
axisRect->axis(QCPAxis::atLeft, 1)->setRange(yAxesRanges[secondLeft].min,
yAxesRanges[secondLeft].max);
}
if (yAxesRanges[secondRight].max != INVALID_MAX) {
axisRect->addAxis(QCPAxis::atRight);
axisRect->axis(QCPAxis::atRight, 1)->setRange(yAxesRanges[secondRight].min,
yAxesRanges[secondRight].max);
}
for (int i = 0; i < plots.coords.size(); i++) { for (int i = 0; i < plots.coords.size(); i++) {
if (plots.coords.at(i).secondRange && plots.twoRanges) { switch (plots.coords[i].yaxis) {
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom), axisRect->axis(QCPAxis::atRight)); case firstLeft:
} else { ui->customPlot->addGraph();
ui->customPlot->addGraph(); break;
case firstRight:
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom),
axisRect->axis(QCPAxis::atRight));
break;
case secondLeft:
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom),
axisRect->axis(QCPAxis::atLeft, 1));
break;
case secondRight:
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom),
axisRect->axis(QCPAxis::atRight, 1));
break;
default:
break;
} }
ui->customPlot->graph(i)->setData(plots.coords.at(i).x, ui->customPlot->graph(i)->setData(plots.coords.at(i).x,
plots.coords.at(i).y); plots.coords.at(i).y);
pen.setColor(colors.at(i % colors.size())); pen.setColor(colors.at(i % colors.size()));
@@ -746,16 +805,44 @@ void logsDialog::plotLogs()
ui->customPlot->replot(); ui->customPlot->replot();
} }
void logsDialog::setRangeyAxis2(QCPRange range) void logsDialog::yAxisChangeRanges(QCPRange range)
{ {
if (hasyAxis2) { if (axisRect->axis(QCPAxis::atRight)->visible()) {
double lowerChange = (range.lower - rangeyAxisMin) * rangeRatio; double lowerChange = (range.lower - yAxesRanges[firstLeft].min) *
double upperChange = (range.upper - rangeyAxisMax) * rangeRatio; yAxesRatios[firstRight];
rangeyAxisMin = range.lower; double upperChange = (range.upper - yAxesRanges[firstLeft].max) *
rangeyAxisMax = range.upper; yAxesRatios[firstRight];
rangeyAxis2Min += lowerChange;
rangeyAxis2Max += upperChange;
axisRect->axis(QCPAxis::atRight)->setRange(rangeyAxis2Min, rangeyAxis2Max); yAxesRanges[firstRight].min += lowerChange;
yAxesRanges[firstRight].max += upperChange;
axisRect->axis(QCPAxis::atRight)->setRange(yAxesRanges[firstRight].min,
yAxesRanges[firstRight].max);
if (axisRect->axisCount(QCPAxis::atLeft) == 2) {
lowerChange = (range.lower - yAxesRanges[firstLeft].min) *
yAxesRatios[secondLeft];
upperChange = (range.upper - yAxesRanges[firstLeft].max) *
yAxesRatios[secondLeft];
yAxesRanges[secondLeft].min += lowerChange;
yAxesRanges[secondLeft].max += upperChange;
axisRect->axis(QCPAxis::atLeft, 1)->setRange(yAxesRanges[secondLeft].min,
yAxesRanges[secondLeft].max);
if (axisRect->axisCount(QCPAxis::atRight) == 2) {
lowerChange = (range.lower - yAxesRanges[firstLeft].min) *
yAxesRatios[secondRight];
upperChange = (range.upper - yAxesRanges[firstLeft].max) *
yAxesRatios[secondRight];
yAxesRanges[secondRight].min += lowerChange;
yAxesRanges[secondRight].max += upperChange;
axisRect->axis(QCPAxis::atRight, 1)->setRange(yAxesRanges[secondRight].min,
yAxesRanges[secondRight].max);
}
}
yAxesRanges[firstLeft].min = range.lower;
yAxesRanges[firstLeft].max = range.upper;
} }
} }
+20 -13
View File
@@ -5,24 +5,35 @@
#include <QtGui> #include <QtGui>
#include "qcustomplot/qcustomplot.h" #include "qcustomplot/qcustomplot.h"
#define INVALID_MIN 999999
#define INVALID_MAX -999999
enum yaxes_t {
firstLeft = 0,
firstRight,
secondLeft,
secondRight,
AXES_LIMIT // = 4
};
struct coords { struct coords {
QVector<double> x, y; QVector<double> x, y;
double min_y; double min_y;
double max_y; double max_y;
bool secondRange; yaxes_t yaxis;
QString name; QString name;
}; };
struct minMax {
double min;
double max;
};
struct plotsCollection { struct plotsCollection {
QVarLengthArray<struct coords> coords; QVarLengthArray<struct coords> coords;
double min_x; double min_x;
double max_x; double max_x;
bool twoRanges;
bool tooManyRanges; bool tooManyRanges;
double rangeOneMin;
double rangeOneMax;
double rangeTwoMin;
double rangeTwoMax;
}; };
namespace Ui { namespace Ui {
@@ -50,7 +61,7 @@ private slots:
void on_fileOpen_BT_clicked(); void on_fileOpen_BT_clicked();
void on_sessions_CB_currentIndexChanged(int index); void on_sessions_CB_currentIndexChanged(int index);
void on_mapsButton_clicked(); void on_mapsButton_clicked();
void setRangeyAxis2(QCPRange range); void yAxisChangeRanges(QCPRange range);
private: private:
QList<QStringList> csvlog; QList<QStringList> csvlog;
@@ -63,12 +74,8 @@ private:
QVarLengthArray<Qt::GlobalColor> colors; QVarLengthArray<Qt::GlobalColor> colors;
QPen pen; QPen pen;
bool hasyAxis2; double yAxesRatios[AXES_LIMIT];
double rangeRatio; minMax yAxesRanges[AXES_LIMIT];
double rangeyAxisMin;
double rangeyAxisMax;
double rangeyAxis2Min;
double rangeyAxis2Max;
}; };
#endif // LOGSDIALOG_H #endif // LOGSDIALOG_H