From d64fc6ea856ca51f7165b72085845bb9fb7965ee Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 22 Mar 2010 17:35:29 +0000 Subject: [PATCH] NULL/Empty ride checks RideItem or RideFile or dataPoints() may be null or empty. This is especially true of manual ridefiles. This patch adds some checks for this situation and acts accordingly. Additionally, the disable/enable of tabs depending upon ridefile type has been adjusted to also include files with not dataPoints. --- src/CpintPlot.cpp | 2 +- src/GcRideFile.cpp | 5 +---- src/GoogleMapControl.cpp | 3 +++ src/MainWindow.cpp | 17 ++++++++++++----- src/PfPvWindow.cpp | 3 ++- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/CpintPlot.cpp b/src/CpintPlot.cpp index c033341fb..4507175b3 100644 --- a/src/CpintPlot.cpp +++ b/src/CpintPlot.cpp @@ -117,7 +117,7 @@ update_cpi_file(const cpi_file_info *info, QProgressDialog *progress, QStringList errors; boost::scoped_ptr rideFile( RideFileFactory::instance().openRideFile(file, errors)); - if (! rideFile) + if (!rideFile || rideFile->dataPoints().isEmpty()) return; cpint_data data; data.rec_int_ms = (int) round(rideFile->recIntSecs() * 1000.0); diff --git a/src/GcRideFile.cpp b/src/GcRideFile.cpp index 5d6e5069b..a97953636 100644 --- a/src/GcRideFile.cpp +++ b/src/GcRideFile.cpp @@ -86,10 +86,7 @@ GcFileReader::openRideFile(QFile &file, QStringList &errors) const int interval = 0; QDomElement samples = root.firstChildElement("samples"); - if (samples.isNull()) { - errors << "no sample section in ride file"; - return NULL; - } + if (samples.isNull()) return rideFile; // manual file will have no samples bool recIntSet = false; for (QDomElement sample = samples.firstChildElement("sample"); diff --git a/src/GoogleMapControl.cpp b/src/GoogleMapControl.cpp index 50abab19f..733380a4f 100644 --- a/src/GoogleMapControl.cpp +++ b/src/GoogleMapControl.cpp @@ -176,6 +176,9 @@ GoogleMapControl::rideSelected() rideData.clear(); double prevLon = 0; double prevLat = 0; + + if (ride == NULL || ride->ride() == NULL) return; + foreach(RideFilePoint *rfp,ride->ride()->dataPoints()) { RideFilePoint curRfp = *rfp; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 314d09170..c58cb46e5 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -810,11 +810,18 @@ MainWindow::rideTreeWidgetSelectionChanged() // turn off tabs that don't make sense for manual file entry int histIndex = tabWidget->indexOf(histogramWindow); int pfpvIndex = tabWidget->indexOf(pfPvWindow); - bool enabled = !ride->ride() || ride->ride()->deviceType() != QString("Manual CSV"); - if (histIndex >= 0) - tabWidget->setTabEnabled(histIndex, enabled); - if (pfpvIndex >= 0) - tabWidget->setTabEnabled(pfpvIndex, enabled); + int plotIndex = tabWidget->indexOf(allPlotWindow); + int modelIndex = tabWidget->indexOf(modelWindow); + int mapIndex = tabWidget->indexOf(googleMap); + bool enabled = (!ride->ride() || ride->ride()->deviceType() != QString("Manual CSV")) + && + (!ride->ride() ||!ride->ride()->dataPoints().isEmpty()); + + if (histIndex >= 0) tabWidget->setTabEnabled(histIndex, enabled); + if (pfpvIndex >= 0) tabWidget->setTabEnabled(pfpvIndex, enabled); + if (plotIndex >= 0) tabWidget->setTabEnabled(plotIndex, enabled); + if (modelIndex >= 0) tabWidget->setTabEnabled(modelIndex, enabled); + if (mapIndex >= 0) tabWidget->setTabEnabled(mapIndex, enabled); saveAndOpenNotes(); } void diff --git a/src/PfPvWindow.cpp b/src/PfPvWindow.cpp index a0124f6a1..287740507 100644 --- a/src/PfPvWindow.cpp +++ b/src/PfPvWindow.cpp @@ -91,8 +91,9 @@ PfPvWindow::rideSelected() if (mainWindow->activeTab() != this) return; RideItem *ride = mainWindow->rideItem(); - if (!ride) + if (!ride || !ride->ride()) return; + pfPvPlot->setData(ride); // update the QLabel widget with the CP value set in PfPvPlot::setData() qaCPValue->setText(QString("%1").arg(pfPvPlot->getCP()));