Check Date/Time unique

Issue a warning if the user changes the ride date/time
to the same as an existing ride.

They can still go ahead, but when saving it will overwrite
the existing file.

Fixing the save routines to check would require significant
refactoring and can be fixed at a later date.

Fixes #466.
This commit is contained in:
Mark Liversedge
2011-10-06 19:50:37 +01:00
parent 95b00bedf7
commit dfaf151eab
2 changed files with 36 additions and 0 deletions

View File

@@ -92,6 +92,33 @@ RideMetadata::setRideItem(RideItem *ride)
}
}
void
RideMetadata::warnDateTime(QDateTime datetime)
{
if (rideItem() == NULL) return;
// see if there is a ride with this date/time already?
// Check if an existing ride has the same starttime
QChar zero = QLatin1Char('0');
QString targetnosuffix = QString ("%1_%2_%3_%4_%5_%6")
.arg(datetime.date().year(), 4, 10, zero)
.arg(datetime.date().month(), 2, 10, zero)
.arg(datetime.date().day(), 2, 10, zero)
.arg(datetime.time().hour(), 2, 10, zero)
.arg(datetime.time().minute(), 2, 10, zero)
.arg(datetime.time().second(), 2, 10, zero);
// now make a regexp for all know ride types
foreach(QString suffix, RideFileFactory::instance().suffixes()) {
QString conflict = main->home.absolutePath() + "/" + targetnosuffix + "." + suffix;
if (QFile(conflict).exists() && QFileInfo(conflict).fileName() != rideItem()->fileName) {
QMessageBox::warning(this, "Date/Time Entry", "An activity already exists with that date/time, if you do not change it then you will overwrite and lose existing data");
return; // only warn on the first conflict!
}
}
}
// the extra tab has all the fields that are in the current
// ride that are not shown on the tabs
void
@@ -528,6 +555,10 @@ FormField::editFinished()
QDateTime update = QDateTime(date, current.time());
ourRideItem->setStartTime(update);
ourRideItem->notifyRideMetadataChanged();
// warn if the ride already exists with that date/time
meta->warnDateTime(update);
} else if (definition.name == "Start Time") {
QDateTime current = ourRideItem->ride()->startTime();
QTime time(/* hours*/ text.mid(0,2).toInt(),
@@ -537,6 +568,10 @@ FormField::editFinished()
QDateTime update = QDateTime(current.date(), time);
ourRideItem->setStartTime(update);
ourRideItem->notifyRideMetadataChanged();
// warn if the ride already exists with that date/time
meta->warnDateTime(update);
} else if (definition.name != "Summary") {
if (sp.isMetric(definition.name) && enabled->isChecked()) {

View File

@@ -133,6 +133,7 @@ class RideMetadata : public QWidget
void configUpdate();
void metadataChanged(); // when its changed elsewhere we need to refresh fields
void setExtraTab(); // shows fields not configured but present in ride file
void warnDateTime(QDateTime); // warn if file already exists after date/time changed
private:
MainWindow *main;