mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
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.
[code refactored from commit dfaf151 release3 and folded in manually]
This commit is contained in:
@@ -70,13 +70,13 @@ RideMetadata::configUpdate()
|
||||
Form *form;
|
||||
#ifdef ENABLE_METRICS_TRANSLATION
|
||||
if ((form = tabList.value(specialTabs.displayName(field.tab), NULL)) == NULL) {
|
||||
form = new Form(main);
|
||||
form = new Form(main, this);
|
||||
tabs->addTab(form, specialTabs.displayName(field.tab));
|
||||
tabList.insert(specialTabs.displayName(field.tab), form);
|
||||
}
|
||||
#else
|
||||
if ((form = tabList.value(field.tab, NULL)) == NULL) {
|
||||
form = new Form(main);
|
||||
form = new Form(main, this);
|
||||
tabs->addTab(form, field.tab);
|
||||
tabList.insert(field.tab, form);
|
||||
}
|
||||
@@ -95,10 +95,37 @@ RideMetadata::configUpdate()
|
||||
main->notifyRideSelected(); // refresh
|
||||
}
|
||||
|
||||
void
|
||||
RideMetadata::warnDateTime(QDateTime datetime)
|
||||
{
|
||||
if (main->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() != main->rideItem()->fileName) {
|
||||
QMessageBox::warning(this, "Date/Time Entry", "A ride 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!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* Forms (one per tab)
|
||||
*--------------------------------------------------------------------*/
|
||||
Form::Form(MainWindow *main) : main(main)
|
||||
Form::Form(MainWindow *main, RideMetadata *meta) : main(main), meta(meta)
|
||||
{
|
||||
contents = new QWidget;
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(contents);
|
||||
@@ -197,7 +224,7 @@ Form::arrange()
|
||||
/*----------------------------------------------------------------------
|
||||
* Form fields
|
||||
*--------------------------------------------------------------------*/
|
||||
FormField::FormField(FieldDefinition field, MainWindow *main) : definition(field), main(main), active(false)
|
||||
FormField::FormField(FieldDefinition field, MainWindow *main, RideMetadata *meta) : definition(field), main(main), active(false), meta(meta)
|
||||
{
|
||||
QString units;
|
||||
|
||||
@@ -355,6 +382,10 @@ FormField::editFinished()
|
||||
QDateTime update = QDateTime(date, current.time());
|
||||
main->rideItem()->setStartTime(update);
|
||||
main->notifyRideSelected();
|
||||
|
||||
// warn if the ride already exists with that date/time
|
||||
meta->warnDateTime(update);
|
||||
|
||||
} else if (definition.name == "Start Time") {
|
||||
QDateTime current = main->rideItem()->ride()->startTime();
|
||||
QTime time(/* hours*/ text.mid(0,2).toInt(),
|
||||
@@ -364,6 +395,10 @@ FormField::editFinished()
|
||||
QDateTime update = QDateTime(current.date(), time);
|
||||
main->rideItem()->setStartTime(update);
|
||||
main->notifyRideSelected();
|
||||
|
||||
// warn if the ride already exists with that date/time
|
||||
meta->warnDateTime(update);
|
||||
|
||||
} else {
|
||||
if (sp.isMetric(definition.name) && enabled->isChecked()) {
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ class FormField : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FormField(FieldDefinition, MainWindow *);
|
||||
FormField(FieldDefinition, MainWindow *, RideMetadata *meta);
|
||||
~FormField();
|
||||
FieldDefinition definition; // define the field
|
||||
QLabel *label; // label
|
||||
@@ -72,6 +72,7 @@ class FormField : public QWidget
|
||||
bool edited; // value has been changed
|
||||
bool active; // when data being changed for rideSelected
|
||||
SpecialFields sp;
|
||||
RideMetadata *meta;
|
||||
};
|
||||
|
||||
class KeywordCompleter : public QCompleter
|
||||
@@ -110,9 +111,9 @@ class Form : public QScrollArea
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Form(MainWindow *);
|
||||
Form(MainWindow *, RideMetadata *meta);
|
||||
~Form();
|
||||
void addField(FieldDefinition x) { fields.append(new FormField(x, main)); }
|
||||
void addField(FieldDefinition x) { fields.append(new FormField(x, main, meta)); }
|
||||
void arrange(); // the meat of the action, arranging fields on the screen
|
||||
|
||||
private:
|
||||
@@ -124,6 +125,7 @@ class Form : public QScrollArea
|
||||
QGridLayout *grid1, *grid2;
|
||||
QList<FormField*> fields; // keep track so we can destroy
|
||||
QList<QHBoxLayout *> overrides; // keep track so we can destroy
|
||||
RideMetadata *meta;
|
||||
|
||||
};
|
||||
|
||||
@@ -140,6 +142,7 @@ class RideMetadata : public QWidget
|
||||
|
||||
public slots:
|
||||
void configUpdate();
|
||||
void warnDateTime(QDateTime); // warn if file already exists after date/time changed
|
||||
|
||||
private:
|
||||
MainWindow *main;
|
||||
|
||||
Reference in New Issue
Block a user