Browse Source

Linechart - Make it possible to change time axis range

QGC4.4
John Tapsell 12 years ago
parent
commit
d046a5f2fd
  1. 28
      src/ui/linechart/LinechartPlot.cc
  2. 56
      src/ui/linechart/LinechartWidget.cc
  3. 6
      src/ui/linechart/LinechartWidget.h

28
src/ui/linechart/LinechartPlot.cc

@ -566,13 +566,29 @@ quint64 LinechartPlot::getPlotInterval()
**/ **/
void LinechartPlot::setPlotInterval(int interval) void LinechartPlot::setPlotInterval(int interval)
{ {
plotInterval = interval; //Only ever increase the amount of stored data,
QMap<QString, TimeSeriesData*>::iterator j; // so that we allow the user to change between
for(j = data.begin(); j != data.end(); ++j) // different intervals without constantly losing
{ // data points
TimeSeriesData* d = data.value(j.key()); if((unsigned)interval > plotInterval) {
d->setInterval(interval);
QMap<QString, TimeSeriesData*>::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;
} }
/** /**

56
src/ui/linechart/LinechartWidget.cc

@ -207,10 +207,9 @@ void LinechartWidget::createLayout()
createActions(); createActions();
// Setup the plot group box area layout // Setup the plot group box area layout
QGridLayout* layout = new QGridLayout(ui.diagramGroupBox); QVBoxLayout* vlayout = new QVBoxLayout(ui.diagramGroupBox);
mainLayout = layout; vlayout->setSpacing(4);
layout->setSpacing(4); vlayout->setMargin(2);
layout->setMargin(2);
// Create plot container widget // Create plot container widget
activePlot = new LinechartPlot(this, sysid); activePlot = new LinechartPlot(this, sysid);
@ -221,9 +220,10 @@ void LinechartWidget::createLayout()
// activePlot = getPlot(0); // activePlot = getPlot(0);
// plotContainer->setPlot(activePlot); // plotContainer->setPlot(activePlot);
layout->addWidget(activePlot, 0, 0, 1, 6); vlayout->addWidget(activePlot);
layout->setRowStretch(0, 10);
layout->setRowStretch(1, 1); QHBoxLayout *hlayout = new QHBoxLayout;
vlayout->addLayout(hlayout);
// Logarithmic scaling button // Logarithmic scaling button
scalingLogButton = createButton(this); scalingLogButton = createButton(this);
@ -231,8 +231,7 @@ void LinechartWidget::createLayout()
scalingLogButton->setCheckable(true); scalingLogButton->setCheckable(true);
scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis")); scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis"));
scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis")); scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis"));
layout->addWidget(scalingLogButton, 1, 0); hlayout->addWidget(scalingLogButton);
layout->setColumnStretch(0, 0);
// Averaging spin box // Averaging spin box
averageSpinBox = new QSpinBox(this); averageSpinBox = new QSpinBox(this);
@ -242,8 +241,7 @@ void LinechartWidget::createLayout()
averageSpinBox->setValue(200); averageSpinBox->setValue(200);
setAverageWindow(200); setAverageWindow(200);
averageSpinBox->setMaximum(9999); averageSpinBox->setMaximum(9999);
layout->addWidget(averageSpinBox, 1, 1); hlayout->addWidget(averageSpinBox);
layout->setColumnStretch(1, 0);
connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int)));
// Log Button // Log Button
@ -251,8 +249,7 @@ void LinechartWidget::createLayout()
logButton->setToolTip(tr("Start to log curve data into a CSV or TXT file")); 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->setWhatsThis(tr("Start to log curve data into a CSV or TXT file"));
logButton->setText(tr("Start Logging")); logButton->setText(tr("Start Logging"));
layout->addWidget(logButton, 1, 2); hlayout->addWidget(logButton);
layout->setColumnStretch(2, 0);
connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging()));
// Ground time button // Ground time button
@ -260,17 +257,37 @@ void LinechartWidget::createLayout()
timeButton->setText(tr("Ground Time")); 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->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.")); 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); hlayout->addWidget(timeButton);
layout->setColumnStretch(3, 0);
connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool)));
connect(timeButton, SIGNAL(clicked()), this, SLOT(writeSettings())); 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 // Initialize the "Show units" checkbox. This is configured in the .ui file, so all
// we do here is attach the clicked() signal. // we do here is attach the clicked() signal.
connect(ui.showUnitsCheckBox, SIGNAL(clicked()), this, SLOT(writeSettings())); connect(ui.showUnitsCheckBox, SIGNAL(clicked()), this, SLOT(writeSettings()));
ui.diagramGroupBox->setLayout(layout);
// Add actions // Add actions
averageSpinBox->setValue(activePlot->getAverageWindow()); averageSpinBox->setValue(activePlot->getAverageWindow());
@ -288,6 +305,11 @@ void LinechartWidget::createLayout()
connect(scalingLogButton, SIGNAL(toggled(bool)), this, SLOT(toggleLogarithmicScaling(bool))); 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) void LinechartWidget::toggleLogarithmicScaling(bool checked)
{ {
if(checked) if(checked)

6
src/ui/linechart/LinechartWidget.h

@ -123,6 +123,10 @@ public slots:
/** @brief Select all curves */ /** @brief Select all curves */
void selectAllCurves(bool all); void selectAllCurves(bool all);
private slots:
/** Called when the user changes the time scale combobox. */
void timeScaleChanged(int index);
protected: protected:
void addCurveToList(QString curve); void addCurveToList(QString curve);
void removeCurveFromList(QString curve); void removeCurveFromList(QString curve);
@ -156,7 +160,7 @@ protected:
QAction* addNewCurve; ///< Add curve candidate to the active curves QAction* addNewCurve; ///< Add curve candidate to the active curves
QMenu* curveMenu; QMenu* curveMenu;
QGridLayout* mainLayout; QComboBox *timeScaleCmb;
QToolButton* scalingLogButton; QToolButton* scalingLogButton;
QToolButton* logButton; QToolButton* logButton;

Loading…
Cancel
Save