diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 9a6c995..4b64564 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -566,13 +566,29 @@ quint64 LinechartPlot::getPlotInterval() **/ void LinechartPlot::setPlotInterval(int interval) { - plotInterval = interval; - QMap::iterator j; - for(j = data.begin(); j != data.end(); ++j) - { - TimeSeriesData* d = data.value(j.key()); - d->setInterval(interval); + //Only ever increase the amount of stored data, + // so that we allow the user to change between + // different intervals without constantly losing + // data points + if((unsigned)interval > plotInterval) { + + QMap::iterator j; + for(j = data.begin(); j != data.end(); ++j) + { + TimeSeriesData* d = data.value(j.key()); + d->setInterval(interval); + } } + plotInterval = interval; + if(plotInterval > 5*60*1000) //If the interval is longer than 4 minutes, change the time scale step to 2 minutes + timeScaleStep = 2*60*1000; + else if(plotInterval >= 4*60*1000) //If the interval is longer than 4 minutes, change the time scale step to 1 minutes + timeScaleStep = 1*60*1000; + else if(plotInterval >= 60*1000) //If the interval is longer than a minute, change the time scale step to 30 seconds + timeScaleStep = 30*1000; + else + timeScaleStep = DEFAULT_SCALE_INTERVAL; + } /** diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 459022c..1c154f9 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -207,10 +207,9 @@ void LinechartWidget::createLayout() createActions(); // Setup the plot group box area layout - QGridLayout* layout = new QGridLayout(ui.diagramGroupBox); - mainLayout = layout; - layout->setSpacing(4); - layout->setMargin(2); + QVBoxLayout* vlayout = new QVBoxLayout(ui.diagramGroupBox); + vlayout->setSpacing(4); + vlayout->setMargin(2); // Create plot container widget activePlot = new LinechartPlot(this, sysid); @@ -221,9 +220,10 @@ void LinechartWidget::createLayout() // activePlot = getPlot(0); // plotContainer->setPlot(activePlot); - layout->addWidget(activePlot, 0, 0, 1, 6); - layout->setRowStretch(0, 10); - layout->setRowStretch(1, 1); + vlayout->addWidget(activePlot); + + QHBoxLayout *hlayout = new QHBoxLayout; + vlayout->addLayout(hlayout); // Logarithmic scaling button scalingLogButton = createButton(this); @@ -231,8 +231,7 @@ void LinechartWidget::createLayout() scalingLogButton->setCheckable(true); scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis")); scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis")); - layout->addWidget(scalingLogButton, 1, 0); - layout->setColumnStretch(0, 0); + hlayout->addWidget(scalingLogButton); // Averaging spin box averageSpinBox = new QSpinBox(this); @@ -242,8 +241,7 @@ void LinechartWidget::createLayout() averageSpinBox->setValue(200); setAverageWindow(200); averageSpinBox->setMaximum(9999); - layout->addWidget(averageSpinBox, 1, 1); - layout->setColumnStretch(1, 0); + hlayout->addWidget(averageSpinBox); connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); // Log Button @@ -251,8 +249,7 @@ void LinechartWidget::createLayout() logButton->setToolTip(tr("Start to log curve data into a CSV or TXT file")); logButton->setWhatsThis(tr("Start to log curve data into a CSV or TXT file")); logButton->setText(tr("Start Logging")); - layout->addWidget(logButton, 1, 2); - layout->setColumnStretch(2, 0); + hlayout->addWidget(logButton); connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); // Ground time button @@ -260,17 +257,37 @@ void LinechartWidget::createLayout() timeButton->setText(tr("Ground Time")); timeButton->setToolTip(tr("Overwrite timestamp of data from vehicle with ground receive time. Helps if the plots are not visible because of missing or invalid onboard time.")); timeButton->setWhatsThis(tr("Overwrite timestamp of data from vehicle with ground receive time. Helps if the plots are not visible because of missing or invalid onboard time.")); - layout->addWidget(timeButton, 1, 3); - layout->setColumnStretch(3, 0); + hlayout->addWidget(timeButton); connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); connect(timeButton, SIGNAL(clicked()), this, SLOT(writeSettings())); + hlayout->addStretch(); + + QLabel *timeScaleLabel = new QLabel("Time axis:"); + hlayout->addWidget(timeScaleLabel); + + timeScaleCmb = new QComboBox(this); + timeScaleCmb->addItem("10 seconds", 10); + timeScaleCmb->addItem("20 seconds", 20); + timeScaleCmb->addItem("30 seconds", 30); + timeScaleCmb->addItem("40 seconds", 40); + timeScaleCmb->addItem("50 seconds", 50); + timeScaleCmb->addItem("1 minute", 60); + timeScaleCmb->addItem("2 minutes", 60*2); + timeScaleCmb->addItem("3 minutes", 60*3); + timeScaleCmb->addItem("4 minutes", 60*4); + timeScaleCmb->addItem("5 minutes", 60*5); + timeScaleCmb->addItem("10 minutes", 60*10); + //timeScaleCmb->setSizeAdjustPolicy(QComboBox::AdjustToContents); + timeScaleCmb->setMinimumContentsLength(12); + + hlayout->addWidget(timeScaleCmb); + connect(timeScaleCmb, SIGNAL(currentIndexChanged(int)), this, SLOT(timeScaleChanged(int))); + // Initialize the "Show units" checkbox. This is configured in the .ui file, so all // we do here is attach the clicked() signal. connect(ui.showUnitsCheckBox, SIGNAL(clicked()), this, SLOT(writeSettings())); - ui.diagramGroupBox->setLayout(layout); - // Add actions averageSpinBox->setValue(activePlot->getAverageWindow()); @@ -288,6 +305,11 @@ void LinechartWidget::createLayout() connect(scalingLogButton, SIGNAL(toggled(bool)), this, SLOT(toggleLogarithmicScaling(bool))); } +void LinechartWidget::timeScaleChanged(int index) +{ + activePlot->setPlotInterval(timeScaleCmb->itemData(index).toInt()*1000); +} + void LinechartWidget::toggleLogarithmicScaling(bool checked) { if(checked) diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index e9caf11..de090b9 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -123,6 +123,10 @@ public slots: /** @brief Select all curves */ void selectAllCurves(bool all); +private slots: + /** Called when the user changes the time scale combobox. */ + void timeScaleChanged(int index); + protected: void addCurveToList(QString curve); void removeCurveFromList(QString curve); @@ -156,7 +160,7 @@ protected: QAction* addNewCurve; ///< Add curve candidate to the active curves QMenu* curveMenu; - QGridLayout* mainLayout; + QComboBox *timeScaleCmb; QToolButton* scalingLogButton; QToolButton* logButton;