[companion][logsDialog]Updated qCustomPlot. Made fly sessions selection instantaneous.

This commit is contained in:
Grieb
2015-04-14 01:39:31 -03:00
parent e3bdffd051
commit 208f80f07e
11 changed files with 28425 additions and 17327 deletions
+97 -99
View File
@@ -33,12 +33,16 @@ logsDialog::logsDialog(QWidget *parent) :
colors.append(Qt::blue);
pen.setWidthF(1.5);
ui->customPlot->setInteractions(QCustomPlot::iRangeDrag | QCustomPlot::iRangeZoom | QCustomPlot::iSelectAxes |
QCustomPlot::iSelectLegend | QCustomPlot::iSelectPlottables | QCustomPlot::iSelectTitle | QCustomPlot::iSelectItems);
ui->customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical);
ui->customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical);
ui->customPlot->yAxis->setRange(-1100, 1100);
ui->customPlot->setTitle(tr("Telemetry logs"));
// create and prepare a plot title layout element
QCPPlotTitle *title = new QCPPlotTitle(ui->customPlot);
title->setText(tr("Telemetry logs"));
// title->setFont(QFont("sans", 12, QFont::Bold));
// add it to the main plot layout
ui->customPlot->plotLayout()->insertRow(0);
ui->customPlot->plotLayout()->addElement(0, 0, title);
ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom |
QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);
ui->customPlot->xAxis->setLabel(tr("Time (hh:mm:ss)"));
ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
@@ -47,17 +51,13 @@ logsDialog::logsDialog(QWidget *parent) :
ui->customPlot->xAxis->setRange(now.addSecs(-60*60*2).toTime_t(),
now.toTime_t());
ui->customPlot->legend->setVisible(true);
ui->customPlot->yAxis->setTickLabels(false);
ui->customPlot->yAxis->setAutoTickCount(10);
ui->customPlot->yAxis2->setTicks(false);
ui->customPlot->setRangeZoomFactor(2, 2);
QFont legendFont = font();
legendFont.setPointSize(10);
ui->customPlot->legend->setFont(legendFont);
ui->customPlot->legend->setSelectedFont(legendFont);
ui->customPlot->legend->setSelectable(QCPLegend::spItems); // legend box shall not be selectable, only legend items
ui->customPlot->legend->setVisible(false);
QString Path=g.gePath();
if (Path.isEmpty() || !QFile(Path).exists()) {
ui->mapsButton->hide();
@@ -69,11 +69,11 @@ logsDialog::logsDialog(QWidget *parent) :
connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make left axes transfer its ranges to right axes:
// make left axes transfer its range to right axes:
connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(setRangeyAxis2(QCPRange)));
// connect some interaction slots:
connect(ui->customPlot, SIGNAL(titleDoubleClick(QMouseEvent*)), this, SLOT(titleDoubleClick()));
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->customPlot, SIGNAL(plottableDoubleClick(QCPAbstractPlottable *, QMouseEvent *)), this, SLOT(plottableItemDoubleClick(QCPAbstractPlottable *, QMouseEvent *)));
@@ -87,15 +87,16 @@ logsDialog::~logsDialog()
delete ui;
}
void logsDialog::titleDoubleClick()
void logsDialog::titleDoubleClick(QMouseEvent *evt, QCPPlotTitle *title)
{
// 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, ui->customPlot->title(), &ok);
QString newTitle = QInputDialog::getText(this, tr("Plot Title Change"),
tr("New plot title:"), QLineEdit::Normal, title->text(), &ok);
if (ok)
{
ui->customPlot->setTitle(newTitle);
title->setText(newTitle);
ui->customPlot->replot();
}
}
@@ -103,7 +104,6 @@ void logsDialog::titleDoubleClick()
void logsDialog::axisLabelDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part)
{
// Set an axis label by double clicking on it
if (part == QCPAxis::spAxisLabel) // only react when the actual axis label is clicked, not tick label or axis backbone
{
bool ok;
@@ -155,18 +155,24 @@ void logsDialog::selectionChanged()
if (plotLock) return;
// handle bottom axis and tick labels as one selectable object:
if (ui->customPlot->xAxis->selected().testFlag(QCPAxis::spAxis) || ui->customPlot->xAxis->selected().testFlag(QCPAxis::spTickLabels))
if (ui->customPlot->xAxis->selectedParts().testFlag(QCPAxis::spAxis) ||
ui->customPlot->xAxis->selectedParts().testFlag(QCPAxis::spTickLabels))
{
ui->customPlot->xAxis->setSelected(QCPAxis::spAxis|QCPAxis::spTickLabels);
ui->customPlot->xAxis->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels);
}
// make left and right axes be selected synchronously,
// and handle axis and tick labels as one selectable object:
if (ui->customPlot->yAxis->selected().testFlag(QCPAxis::spAxis) || ui->customPlot->yAxis->selected().testFlag(QCPAxis::spTickLabels) ||
ui->customPlot->yAxis2->selected().testFlag(QCPAxis::spAxis) || ui->customPlot->yAxis2->selected().testFlag(QCPAxis::spTickLabels))
if (ui->customPlot->yAxis->selectedParts().testFlag(QCPAxis::spAxis) ||
ui->customPlot->yAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
ui->customPlot->yAxis2->selectedParts().testFlag(QCPAxis::spAxis) ||
ui->customPlot->yAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
{
ui->customPlot->yAxis->setSelected(QCPAxis::spAxis|QCPAxis::spTickLabels);
ui->customPlot->yAxis->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels);
if (hasyAxis2) {
ui->customPlot->yAxis2->setSelected(QCPAxis::spAxis|QCPAxis::spTickLabels);
ui->customPlot->yAxis2->setSelectedParts(QCPAxis::spAxis |
QCPAxis::spTickLabels);
}
}
@@ -355,12 +361,12 @@ void logsDialog::mousePress()
// if an axis is selected, only allow the direction of that axis to be dragged
// if no axis is selected, both directions may be dragged
if (ui->customPlot->xAxis->selected().testFlag(QCPAxis::spAxis))
ui->customPlot->setRangeDrag(ui->customPlot->xAxis->orientation());
else if (ui->customPlot->yAxis->selected().testFlag(QCPAxis::spAxis))
ui->customPlot->setRangeDrag(ui->customPlot->yAxis->orientation());
if (ui->customPlot->xAxis->selectedParts().testFlag(QCPAxis::spAxis))
ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->xAxis->orientation());
else if (ui->customPlot->yAxis->selectedParts().testFlag(QCPAxis::spAxis))
ui->customPlot->axisRect()->setRangeDrag(ui->customPlot->yAxis->orientation());
else
ui->customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical);
ui->customPlot->axisRect()->setRangeDrag(Qt::Horizontal | Qt::Vertical);
}
void logsDialog::mouseWheel()
@@ -375,9 +381,9 @@ void logsDialog::mouseWheel()
orientation|=Qt::Vertical;
}
if (orientation) {
ui->customPlot->setRangeZoom((Qt::Orientation)orientation);
ui->customPlot->axisRect()->setRangeZoom((Qt::Orientation)orientation);
} else {
ui->customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical);
ui->customPlot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
}
}
@@ -399,19 +405,19 @@ void logsDialog::removeAllGraphs()
ui->customPlot->replot();
}
void logsDialog::moveLegend()
{
if (QAction* contextAction = qobject_cast<QAction*>(sender())) // make sure this slot is really called by a context menu action, so it carries the data we need
{
bool ok;
int dataInt = contextAction->data().toInt(&ok);
if (ok)
{
ui->customPlot->legend->setPositionStyle((QCPLegend::PositionStyle)dataInt);
ui->customPlot->replot();
}
}
}
// void logsDialog::moveLegend()
// {
// if (QAction* contextAction = qobject_cast<QAction*>(sender())) // make sure this slot is really called by a context menu action, so it carries the data we need
// {
// bool ok;
// int dataInt = contextAction->data().toInt(&ok);
// if (ok)
// {
// ui->customPlot->legend->setPositionStyle((QCPLegend::PositionStyle)dataInt);
// ui->customPlot->replot();
// }
// }
// }
void logsDialog::on_fileOpen_BT_clicked()
{
@@ -531,72 +537,60 @@ bool logsDialog::cvsFileParse()
csvlog.clear();
return false;
}
double lastvalue=0;
double tmp;
ui->sessions_CB->addItem("---");
for (int i=1; i<n; i++) {
QString tstamp=csvlog.at(i).at(0)+QString(" ")+csvlog.at(i).at(1);
double lastvalue = 0;
double tmp;
for (int i = 1; i < n; i++) {
QString tstamp = csvlog.at(i).at(0) + QString(" ") + csvlog.at(i).at(1);
if (csvlog.at(i).at(1).contains(".")) {
tmp=QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss.zzz").toTime_t();
tmp+=csvlog.at(i).at(1).mid(csvlog.at(i).at(1).indexOf(".")).toDouble();
tmp = QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss.zzz").toTime_t();
tmp += csvlog.at(i).at(1).mid(csvlog.at(i).at(1).indexOf(".")).toDouble();
} else {
tmp=QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss").toTime_t();
tmp = QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss").toTime_t();
}
if (tmp>(lastvalue+60)) {
ui->sessions_CB->addItem(tstamp, tmp);
lastvalue=tmp;
if (tmp > (lastvalue+60)) {
ui->sessions_CB->addItem(tstamp, i - 1);
lastvalue = tmp;
} else {
lastvalue=tmp;
lastvalue = tmp;
}
}
plotLock=false;
return true;
}
void logsDialog::on_sessions_CB_currentIndexChanged(int index)
{
if (plotLock)
return;
plotLock=true;
double start=0;
double stop=-1;
if (index!=0) {
start=ui->sessions_CB->itemData(index,Qt::UserRole).toDouble();
if (index<(ui->sessions_CB->count()-1)) {
stop=ui->sessions_CB->itemData(index+1,Qt::UserRole).toDouble();
}
}
// if (ui->logTable->item(i-1,1)->isSelected()) {
if (plotLock) return;
plotLock = true;
ui->logTable->clearSelection();
if (start>0) {
int n=csvlog.count();
double tmp;
ui->logTable->setSelectionBehavior(QAbstractItemView::SelectRows);
for (int i=1; i<n; i++) {
QString tstamp=csvlog.at(i).at(0)+QString(" ")+csvlog.at(i).at(1);
if (csvlog.at(i).at(1).contains(".")) {
tmp=QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss.zzz").toTime_t();
tmp+=csvlog.at(i).at(1).mid(csvlog.at(i).at(1).indexOf(".")).toDouble();
} else {
tmp=QDateTime::fromString(tstamp, "yyyy-MM-dd HH:mm:ss").toTime_t();
}
if (stop>0) {
if (tmp==start) {
ui->logTable->selectionModel()->select(ui->logTable->model()->index(i-1,0), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
} else if (tmp>start && tmp<stop) {
ui->logTable->selectionModel()->select(ui->logTable->model()->index(i-1,0), QItemSelectionModel::Select|QItemSelectionModel::Rows);
}
} else {
if (tmp==start) {
ui->logTable->selectionModel()->select(ui->logTable->model()->index(i-1,0), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
} else if (tmp>start) {
ui->logTable->selectionModel()->select(ui->logTable->model()->index(i-1,0), QItemSelectionModel::Select|QItemSelectionModel::Rows);
}
}
if (index != 0) {
int bottom;
if (index < ui->sessions_CB->count() - 1) {
bottom = ui->sessions_CB->itemData(index + 1, Qt::UserRole).toInt();
} else {
bottom = ui->logTable->rowCount();
}
QModelIndex topLeft = ui->logTable->model()->index(
ui->sessions_CB->itemData(index, Qt::UserRole).toInt(), 0 , QModelIndex());
QModelIndex bottomRight = ui->logTable->model()->index(
bottom - 1, ui->logTable->columnCount() - 1, QModelIndex());
QItemSelection selection(topLeft, bottomRight);
ui->logTable->selectionModel()->select(selection, QItemSelectionModel::Select);
}
plotLock=false;
plotLock = false;
plotLogs();
}
@@ -609,20 +603,22 @@ void logsDialog::plotLogs()
return;
}
QElapsedTimer timer;
timer.start();
plotsCollection plots;
QList<QTableWidgetSelectionRange> selections = ui->logTable->selectedRanges();
int rowCount = selections.length();
QModelIndexList selection = ui->logTable->selectionModel()->selectedRows();
int rowCount = selection.length();
bool hasLogSelection;
QVarLengthArray<int> selectedRows;
if (rowCount) {
hasLogSelection = true;
foreach (QTableWidgetSelectionRange range, selections) {
for (int i = range.topRow(); i <= range.bottomRow(); i++) {
selectedRows.append(i);
}
foreach (QModelIndex index, selection) {
selectedRows.append(index.row());
}
qSort(selectedRows.begin(), selectedRows.end());
} else {
hasLogSelection = false;
rowCount = ui->logTable->rowCount();
@@ -789,6 +785,8 @@ void logsDialog::plotLogs()
ui->customPlot->legend->setVisible(true);
ui->customPlot->replot();
qDebug() << timer.elapsed();
}
void logsDialog::setRangeyAxis2(QCPRange range)