Log Viewer: add a second legend and reference to axes in the legends.

This commit is contained in:
Grieb
2015-05-21 22:08:47 -03:00
parent 46ccd15924
commit 3609e2df56
2 changed files with 60 additions and 21 deletions
+59 -21
View File
@@ -56,10 +56,25 @@ logsDialog::logsDialog(QWidget *parent) :
axisRect->axis(QCPAxis::atLeft)->setTickLabels(false); axisRect->axis(QCPAxis::atLeft)->setTickLabels(false);
axisRect->addAxis(QCPAxis::atLeft);
axisRect->addAxis(QCPAxis::atRight);
axisRect->axis(QCPAxis::atLeft, 1)->setVisible(false);
axisRect->axis(QCPAxis::atRight, 1)->setVisible(false);
QFont legendFont = font(); QFont legendFont = font();
legendFont.setPointSize(10); legendFont.setPointSize(10);
ui->customPlot->legend->setFont(legendFont); ui->customPlot->legend->setFont(legendFont);
ui->customPlot->legend->setSelectedFont(legendFont); ui->customPlot->legend->setSelectedFont(legendFont);
axisRect->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignLeft);
rightLegend = new QCPLegend;
axisRect->insetLayout()->addElement(rightLegend, Qt::AlignTop | Qt::AlignRight);
rightLegend->setLayer("legend");
rightLegend->setFont(legendFont);
rightLegend->setSelectedFont(legendFont);
rightLegend->setVisible(false);
ui->customPlot->setAutoAddPlottableToLegend(false);
QString Path=g.gePath(); QString Path=g.gePath();
if (Path.isEmpty() || !QFile(Path).exists()) { if (Path.isEmpty() || !QFile(Path).exists()) {
@@ -167,11 +182,11 @@ void logsDialog::selectionChanged()
(axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spAxis) || (axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spTickLabels)) axisRect->axis(QCPAxis::atRight)->selectedParts().testFlag(QCPAxis::spTickLabels))
) || ( ) || (
axisRect->axisCount(QCPAxis::atLeft) == 2 && axisRect->axis(QCPAxis::atLeft, 1)->visible() &&
(axisRect->axis(QCPAxis::atLeft, 1)->selectedParts().testFlag(QCPAxis::spAxis) || (axisRect->axis(QCPAxis::atLeft, 1)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atLeft, 1)->selectedParts().testFlag(QCPAxis::spTickLabels)) axisRect->axis(QCPAxis::atLeft, 1)->selectedParts().testFlag(QCPAxis::spTickLabels))
) || ( ) || (
axisRect->axisCount(QCPAxis::atRight) == 2 && axisRect->axis(QCPAxis::atRight)->visible() &&
(axisRect->axis(QCPAxis::atRight, 1)->selectedParts().testFlag(QCPAxis::spAxis) || (axisRect->axis(QCPAxis::atRight, 1)->selectedParts().testFlag(QCPAxis::spAxis) ||
axisRect->axis(QCPAxis::atRight, 1)->selectedParts().testFlag(QCPAxis::spTickLabels)) axisRect->axis(QCPAxis::atRight, 1)->selectedParts().testFlag(QCPAxis::spTickLabels))
) )
@@ -181,10 +196,10 @@ void logsDialog::selectionChanged()
if (axisRect->axis(QCPAxis::atRight)->visible()) { 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) { if (axisRect->axis(QCPAxis::atLeft, 1)->visible()) {
axisRect->axis(QCPAxis::atLeft, 1)->setSelectedParts(QCPAxis::spAxis | axisRect->axis(QCPAxis::atLeft, 1)->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels); QCPAxis::spTickLabels);
if (axisRect->axisCount(QCPAxis::atRight) == 2) { if (axisRect->axis(QCPAxis::atRight, 1)->visible()) {
axisRect->axis(QCPAxis::atRight, 1)->setSelectedParts(QCPAxis::spAxis | axisRect->axis(QCPAxis::atRight, 1)->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels); QCPAxis::spTickLabels);
} }
@@ -197,6 +212,7 @@ void logsDialog::selectionChanged()
{ {
QCPGraph *graph = ui->customPlot->graph(i); QCPGraph *graph = ui->customPlot->graph(i);
QCPPlottableLegendItem *item = ui->customPlot->legend->itemWithPlottable(graph); QCPPlottableLegendItem *item = ui->customPlot->legend->itemWithPlottable(graph);
if (item == NULL) item = rightLegend->itemWithPlottable(graph);
if (item->selected() || graph->selected()) if (item->selected() || graph->selected())
{ {
item->setSelected(true); item->setSelected(true);
@@ -415,16 +431,17 @@ void logsDialog::removeAllGraphs()
{ {
ui->customPlot->clearGraphs(); ui->customPlot->clearGraphs();
ui->customPlot->legend->setVisible(false); ui->customPlot->legend->setVisible(false);
rightLegend->clearItems();
rightLegend->setVisible(false);
axisRect->axis(QCPAxis::atRight)->setSelectedParts(QCPAxis::spNone); 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)->setSelectedParts(QCPAxis::spNone);
axisRect->axis(QCPAxis::atLeft)->setTickLabels(false); axisRect->axis(QCPAxis::atLeft)->setTickLabels(false);
if (axisRect->axisCount(QCPAxis::atLeft) == 2) { axisRect->axis(QCPAxis::atLeft, 1)->setVisible(false);
axisRect->removeAxis(axisRect->axis(QCPAxis::atLeft, 1)); axisRect->axis(QCPAxis::atLeft, 1)->setSelectedParts(QCPAxis::spNone);
} axisRect->axis(QCPAxis::atRight, 1)->setVisible(false);
if (axisRect->axisCount(QCPAxis::atRight) == 2) { axisRect->axis(QCPAxis::atRight, 1)->setSelectedParts(QCPAxis::spNone);
axisRect->removeAxis(axisRect->axis(QCPAxis::atRight, 1)); axisRect->axis(QCPAxis::atBottom)->setSelectedParts(QCPAxis::spNone);
}
ui->customPlot->replot(); ui->customPlot->replot();
} }
@@ -759,36 +776,58 @@ void logsDialog::plotLogs()
axisRect->axis(QCPAxis::atRight)->setRange(yAxesRanges[firstRight].min, axisRect->axis(QCPAxis::atRight)->setRange(yAxesRanges[firstRight].min,
yAxesRanges[firstRight].max); yAxesRanges[firstRight].max);
axisRect->axis(QCPAxis::atRight)->setVisible(true); axisRect->axis(QCPAxis::atRight)->setVisible(true);
}
if (yAxesRanges[secondLeft].max != INVALID_MAX) { rightLegend->setVisible(true);
axisRect->addAxis(QCPAxis::atLeft);
axisRect->axis(QCPAxis::atLeft, 1)->setRange(yAxesRanges[secondLeft].min,
yAxesRanges[secondLeft].max);
}
if (yAxesRanges[secondRight].max != INVALID_MAX) { if (yAxesRanges[secondLeft].max != INVALID_MAX) {
axisRect->addAxis(QCPAxis::atRight); axisRect->axis(QCPAxis::atLeft, 1)->setVisible(true);
axisRect->axis(QCPAxis::atRight, 1)->setRange(yAxesRanges[secondRight].min, axisRect->axis(QCPAxis::atLeft, 1)->setRange(yAxesRanges[secondLeft].min,
yAxesRanges[secondRight].max); yAxesRanges[secondLeft].max);
if (yAxesRanges[secondRight].max != INVALID_MAX) {
axisRect->axis(QCPAxis::atRight, 1)->setVisible(true);
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++) {
switch (plots.coords[i].yaxis) { switch (plots.coords[i].yaxis) {
case firstLeft: case firstLeft:
ui->customPlot->addGraph(); ui->customPlot->addGraph();
if (yAxesRanges[secondLeft].max != INVALID_MAX) {
ui->customPlot->graph(i)->setName(plots.coords.at(i).name + tr(" (L1)"));
} else {
ui->customPlot->graph(i)->setName(plots.coords.at(i).name);
}
ui->customPlot->legend->addItem(
new QCPPlottableLegendItem(ui->customPlot->legend, ui->customPlot->graph(i)));
break; break;
case firstRight: case firstRight:
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom), ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom),
axisRect->axis(QCPAxis::atRight)); axisRect->axis(QCPAxis::atRight));
if (yAxesRanges[secondRight].max != INVALID_MAX) {
ui->customPlot->graph(i)->setName(plots.coords.at(i).name + tr(" (R1)"));
} else {
ui->customPlot->graph(i)->setName(plots.coords.at(i).name);
}
rightLegend->addItem(
new QCPPlottableLegendItem(rightLegend, ui->customPlot->graph(i)));
break; break;
case secondLeft: case secondLeft:
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom), ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom),
axisRect->axis(QCPAxis::atLeft, 1)); axisRect->axis(QCPAxis::atLeft, 1));
ui->customPlot->graph(i)->setName(plots.coords.at(i).name + tr(" (L2)"));
ui->customPlot->legend->addItem(
new QCPPlottableLegendItem(ui->customPlot->legend, ui->customPlot->graph(i)));
break; break;
case secondRight: case secondRight:
ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom), ui->customPlot->addGraph(axisRect->axis(QCPAxis::atBottom),
axisRect->axis(QCPAxis::atRight, 1)); axisRect->axis(QCPAxis::atRight, 1));
ui->customPlot->graph(i)->setName(plots.coords.at(i).name + tr(" (R2)"));
rightLegend->addItem(
new QCPPlottableLegendItem(rightLegend, ui->customPlot->graph(i)));
break; break;
default: default:
break; break;
@@ -798,7 +837,6 @@ void logsDialog::plotLogs()
plots.coords.at(i).y); plots.coords.at(i).y);
pen.setColor(colors.at(i % colors.size())); pen.setColor(colors.at(i % colors.size()));
ui->customPlot->graph(i)->setPen(pen); ui->customPlot->graph(i)->setPen(pen);
ui->customPlot->graph(i)->setName(plots.coords.at(i).name);
} }
ui->customPlot->legend->setVisible(true); ui->customPlot->legend->setVisible(true);
+1
View File
@@ -67,6 +67,7 @@ private:
QList<QStringList> csvlog; QList<QStringList> csvlog;
Ui::logsDialog *ui; Ui::logsDialog *ui;
QCPAxisRect *axisRect; QCPAxisRect *axisRect;
QCPLegend *rightLegend;
bool cvsFileParse(); bool cvsFileParse();
bool plotLock; bool plotLock;
QString logFilename; QString logFilename;