mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 08:08:42 +00:00
Fix date/time handling when importing rides
The ride import wizard would only allow the user to
change the ride date/time if it was a .gc .json or
.csv file. This was (wrongly) because we could not
update the date/time defined within the ride file itself
(we cannot write in other formats e.g. wko).
Of course, we encode the ride date/time in the filename
and so it could be changed. However, not all the RideFile
readers supported this.
To get around this, the import wizard now does let you
change the date and time for any file type and the ride
file factory method openRideFile() will override whatever
date and time is returned by examining the filename. The
user needs to double click the date or time to edit it.
Additionally, the select date... combo would only register
when you changed the selection, it now defaults back to
the 'select date..' option after each selection.
Lastly, the 'choose date' function now works as advertised
and triggers editing the date for the ride selected.
[commit cd86521 cherry picked into master from release_3.0.0dev]
Fixes #11
This commit is contained in:
@@ -254,6 +254,20 @@ RideFile *RideFileFactory::openRideFile(QFile &file,
|
||||
// NULL returned to indicate openRide failed
|
||||
if (result) {
|
||||
if (result->intervals().empty()) result->fillInIntervals();
|
||||
|
||||
// override the file ride time with that set from the filename
|
||||
// but only if it matches the GC format
|
||||
QFileInfo fileInfo(file.fileName());
|
||||
QRegExp rx ("^((\\d\\d\\d\\d)_(\\d\\d)_(\\d\\d)_(\\d\\d)_(\\d\\d)_(\\d\\d))\\.(.+)$");
|
||||
|
||||
if (rx.exactMatch(fileInfo.fileName())) {
|
||||
|
||||
QDate date(rx.cap(2).toInt(), rx.cap(3).toInt(),rx.cap(4).toInt());
|
||||
QTime time(rx.cap(5).toInt(), rx.cap(6).toInt(),rx.cap(7).toInt());
|
||||
QDateTime datetime(date, time);
|
||||
result->setStartTime(datetime);
|
||||
}
|
||||
|
||||
result->setTag("Filename", file.fileName());
|
||||
result->setTag("Athlete", QFileInfo(file).dir().dirName());
|
||||
DataProcessorFactory::instance().autoProcess(result);
|
||||
|
||||
@@ -131,14 +131,14 @@ RideImportWizard::init(QList<QString> files, QDir &home, MainWindow *main)
|
||||
// Date
|
||||
t = new QTableWidgetItem();
|
||||
t->setText(tr(""));
|
||||
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
|
||||
t->setFlags(t->flags() | Qt::ItemIsEditable);
|
||||
t->setBackgroundColor(Qt::red);
|
||||
tableWidget->setItem(i,1,t);
|
||||
|
||||
// Time
|
||||
t = new QTableWidgetItem();
|
||||
t->setText(tr(""));
|
||||
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
|
||||
t->setFlags(t->flags() | Qt::ItemIsEditable);
|
||||
tableWidget->setItem(i,2,t);
|
||||
|
||||
// Duration
|
||||
@@ -344,31 +344,21 @@ RideImportWizard::process()
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
// Pass 3 - get missing date and times for imported files
|
||||
// Pass 3 - get missing date and times for imported files
|
||||
// Actually allow us to edit date on ANY ride, we
|
||||
// make sure that the ride date/time is set from
|
||||
// the filename and never from the ride data
|
||||
phaseLabel->setText(tr("Step 3 of 4: Confirm Date and Time"));
|
||||
|
||||
int needdates=0;
|
||||
bool first = true;
|
||||
for (int i=0; i<filenames.count(); i++) {
|
||||
int needdates=0;
|
||||
for (int i=0; i<filenames.count(); i++) {
|
||||
|
||||
// ignore errors
|
||||
QTableWidgetItem *t = tableWidget->item(i,5);
|
||||
if (t->text().startsWith(tr("Error"))) continue;
|
||||
|
||||
// date needed?
|
||||
if (blanks[i] || filenames[i].endsWith(".gc", Qt::CaseInsensitive)) { // but we can override gc ride files
|
||||
if (blanks[i]) needdates++; // count the blanks tho
|
||||
t = tableWidget->item(i,1);
|
||||
t->setFlags(t->flags() | (Qt::ItemIsEditable)); // make editable ONLY if not present -
|
||||
// we cannot override the RideFileReader
|
||||
if (first) {
|
||||
tableWidget->editItem(t);
|
||||
first = false;
|
||||
}
|
||||
t = tableWidget->item(i,2);
|
||||
t->setFlags(t->flags() | (Qt::ItemIsEditable)); // make editable ONLY if not present -
|
||||
// we cannot override the RideFileReader
|
||||
}
|
||||
if (blanks[i]) needdates++; // count the blanks tho -- these MUST be edited
|
||||
|
||||
// does nothing for the moment
|
||||
progressBar->setValue(progressBar->value()+1);
|
||||
progressBar->repaint();
|
||||
@@ -444,12 +434,15 @@ RideImportWizard::todayClicked(int index)
|
||||
{
|
||||
QDate selectedDate; // the date we're gonna apply to the row(s) highlighted
|
||||
|
||||
// set the index back to 0, so we can select again
|
||||
todayButton->setCurrentIndex(0);
|
||||
|
||||
// 0 = nothing selected, 1 = Today - 2 = last monday thru to 8 = last sunday
|
||||
if (index == 0) { // no selection
|
||||
return;
|
||||
} else if (index == 1) { // today
|
||||
selectedDate = QDate().currentDate();
|
||||
} else if (index == 10) { // other date - set focus on first highlighted date
|
||||
} else if (index == 9) { // other date - set focus on first highlighted date
|
||||
for (int i=0; i<filenames.count(); i++) {
|
||||
if (tableWidget->item(i,0)->isSelected() ||
|
||||
tableWidget->item(i,1)->isSelected() ||
|
||||
@@ -457,10 +450,8 @@ RideImportWizard::todayClicked(int index)
|
||||
tableWidget->item(i,3)->isSelected() ||
|
||||
tableWidget->item(i,4)->isSelected() ||
|
||||
tableWidget->item(i,5)->isSelected()) {
|
||||
if (blanks[i]) {
|
||||
tableWidget->editItem(tableWidget->item(i,1));
|
||||
return;
|
||||
}
|
||||
tableWidget->editItem(tableWidget->item(i,1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user