mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 08:38:45 +00:00
Interval features and new GC file format
This commit is contained in:
committed by
Sean Rhea
parent
2db45dc0c5
commit
29a9e41444
@@ -65,6 +65,7 @@ BestIntervalDialog::BestIntervalDialog(MainWindow *mainWindow) :
|
||||
countSpinBox = new QDoubleSpinBox(this);
|
||||
countSpinBox->setDecimals(0);
|
||||
countSpinBox->setMinimum(1.0);
|
||||
countSpinBox->setValue(5.0); // lets default to the top 5 powers
|
||||
countSpinBox->setSingleStep(1.0);
|
||||
countSpinBox->setAlignment(Qt::AlignRight);
|
||||
intervalCountLayout->addWidget(countSpinBox);
|
||||
@@ -73,19 +74,42 @@ BestIntervalDialog::BestIntervalDialog(MainWindow *mainWindow) :
|
||||
QLabel *resultsLabel = new QLabel(tr("Results:"), this);
|
||||
mainLayout->addWidget(resultsLabel);
|
||||
|
||||
resultsText = new QTextEdit(this);
|
||||
resultsText->setReadOnly(true);
|
||||
mainLayout->addWidget(resultsText);
|
||||
// user can select from the results to add
|
||||
// to the ride intervals
|
||||
resultsTable = new QTableWidget;
|
||||
mainLayout->addWidget(resultsTable);
|
||||
resultsTable->setColumnCount(5);
|
||||
resultsTable->setColumnHidden(3, true); // has start time in secs
|
||||
resultsTable->setColumnHidden(4, true); // has stop time in secs
|
||||
resultsTable->horizontalHeader()->hide();
|
||||
// resultsTable->verticalHeader()->hide();
|
||||
resultsTable->setShowGrid(false);
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
findButton = new QPushButton(tr("&Find Intervals"), this);
|
||||
buttonLayout->addWidget(findButton);
|
||||
doneButton = new QPushButton(tr("&Done"), this);
|
||||
buttonLayout->addWidget(doneButton);
|
||||
addButton = new QPushButton(tr("&Add to Intervals"));
|
||||
buttonLayout->addWidget(addButton);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked()));
|
||||
connect(doneButton, SIGNAL(clicked()), this, SLOT(doneClicked()));
|
||||
connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
|
||||
}
|
||||
|
||||
|
||||
// little helper function
|
||||
static void
|
||||
clearResultsTable(QTableWidget *resultsTable)
|
||||
{
|
||||
// zap the 3 main cols and two hidden ones
|
||||
for (int i=0; i<resultsTable->rowCount(); i++) {
|
||||
for (int j=0; j<resultsTable->columnCount(); j++)
|
||||
delete resultsTable->takeItem(i,j);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -128,13 +152,17 @@ BestIntervalDialog::findClicked()
|
||||
bests.insertMulti(avg, point->secs);
|
||||
}
|
||||
|
||||
QMap<double,double> results;
|
||||
// clean up the results - results ordered by power not
|
||||
// offset in workout
|
||||
results.clear();
|
||||
while (!bests.empty() && maxIntervals--) {
|
||||
QMutableMapIterator<double,double> j(bests);
|
||||
j.toBack();
|
||||
j.previous();
|
||||
double secs = j.value();
|
||||
results.insert(j.value() - windowSizeSecs, j.key());
|
||||
|
||||
if (j.value() >= windowSizeSecs)
|
||||
results.insert(j.key(), j.value() - windowSizeSecs);
|
||||
j.remove();
|
||||
while (j.hasPrevious()) {
|
||||
j.previous();
|
||||
@@ -143,35 +171,129 @@ BestIntervalDialog::findClicked()
|
||||
}
|
||||
}
|
||||
|
||||
QString resultsHtml =
|
||||
"<center>"
|
||||
"<table width=\"80%\">"
|
||||
"<tr><td align=\"center\">Start Time</td>"
|
||||
" <td align=\"center\">Average Power</td></tr>";
|
||||
// clear the table
|
||||
clearResultsTable(resultsTable);
|
||||
|
||||
// populate the table
|
||||
resultsTable->setRowCount(results.count()); // only those we didn't skip
|
||||
int i=0; // count
|
||||
QMapIterator<double,double> j(results);
|
||||
while (j.hasNext()) {
|
||||
j.next();
|
||||
double secs = j.key();
|
||||
j.toBack();
|
||||
while (j.hasPrevious()) {
|
||||
|
||||
j.previous();
|
||||
|
||||
double secs = j.value();
|
||||
double mins = ((int) secs) / 60;
|
||||
secs = secs - mins * 60.0;
|
||||
double hrs = ((int) mins) / 60;
|
||||
mins = mins - hrs * 60.0;
|
||||
QString row =
|
||||
"<tr><td align=\"center\">%1:%2:%3</td>"
|
||||
" <td align=\"center\">%4</td></tr>";
|
||||
row = row.arg(hrs, 0, 'f', 0);
|
||||
row = row.arg(mins, 2, 'f', 0, QLatin1Char('0'));
|
||||
row = row.arg(secs, 2, 'f', 0, QLatin1Char('0'));
|
||||
row = row.arg(j.value(), 0, 'f', 0, QLatin1Char('0'));
|
||||
resultsHtml += row;
|
||||
|
||||
// check box
|
||||
QCheckBox *c = new QCheckBox;
|
||||
c->setCheckState(Qt::Checked);
|
||||
resultsTable->setCellWidget(i,0,c);
|
||||
|
||||
// start time
|
||||
QString start = "%1:%2:%3";
|
||||
start = start.arg(hrs, 0, 'f', 0);
|
||||
start = start.arg(mins, 2, 'f', 0, QLatin1Char('0'));
|
||||
start = start.arg(secs, 2, 'f', 0, QLatin1Char('0'));
|
||||
|
||||
QTableWidgetItem *t = new QTableWidgetItem;
|
||||
t->setText(start);
|
||||
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
|
||||
resultsTable->setItem(i,1,t);
|
||||
|
||||
// name
|
||||
int x = windowSizeSecs; // int is more help here
|
||||
QString name = "Best %2%3 #%1 (%4w)";
|
||||
name = name.arg(i+1);
|
||||
// best n mins
|
||||
if (x < 60) {
|
||||
// whole seconds
|
||||
name = name.arg(x);
|
||||
name = name.arg("sec");
|
||||
} else if (x >= 60 && !(x%60)) {
|
||||
// whole minutes
|
||||
name = name.arg(x/60);
|
||||
name = name.arg("min");
|
||||
} else {
|
||||
double secs = x;
|
||||
double mins = ((int) secs) / 60;
|
||||
secs = secs - mins * 60.0;
|
||||
double hrs = ((int) mins) / 60;
|
||||
mins = mins - hrs * 60.0;
|
||||
QString tm = "%1:%2:%3";
|
||||
tm = tm.arg(hrs, 0, 'f', 0);
|
||||
tm = tm.arg(mins, 2, 'f', 0, QLatin1Char('0'));
|
||||
tm = tm.arg(secs, 2, 'f', 0, QLatin1Char('0'));
|
||||
|
||||
// mins and secs
|
||||
name = name.arg(tm);
|
||||
name = name.arg("");
|
||||
}
|
||||
name = name.arg(round(j.key()));
|
||||
|
||||
QTableWidgetItem *n = new QTableWidgetItem;
|
||||
n->setText(name);
|
||||
n->setFlags(n->flags() | (Qt::ItemIsEditable));
|
||||
resultsTable->setItem(i,2,n);
|
||||
|
||||
// hidden columns - start, stop
|
||||
QString strt = QString("%1").arg((int)j.value()); // can't use secs as it gets modified
|
||||
QTableWidgetItem *st = new QTableWidgetItem;
|
||||
st->setText(strt);
|
||||
resultsTable->setItem(i,3,st);
|
||||
|
||||
QString stp = QString("%1").arg((int)(j.value()+x));
|
||||
QTableWidgetItem *sp = new QTableWidgetItem;
|
||||
sp->setText(stp);
|
||||
resultsTable->setItem(i,4,sp);
|
||||
|
||||
// increment counter
|
||||
i++;
|
||||
}
|
||||
resultsHtml += "</table></center>";
|
||||
resultsText->setHtml(resultsHtml);
|
||||
resultsTable->resizeColumnToContents(0);
|
||||
resultsTable->resizeColumnToContents(1);
|
||||
resultsTable->setColumnWidth(2,200);
|
||||
}
|
||||
|
||||
void
|
||||
BestIntervalDialog::doneClicked()
|
||||
{
|
||||
clearResultsTable(resultsTable); // clear out that table!
|
||||
done(0);
|
||||
}
|
||||
|
||||
void
|
||||
BestIntervalDialog::addClicked()
|
||||
{
|
||||
// run through the table row by row
|
||||
// and when the checkbox is shown
|
||||
// get name from column 2
|
||||
// get start in secs as a string from column 3
|
||||
// get stop in secs as a string from column 4
|
||||
for (int i=0; i<resultsTable->rowCount(); i++) {
|
||||
|
||||
// is it checked?
|
||||
QCheckBox *c = (QCheckBox *)resultsTable->cellWidget(i,0);
|
||||
if (c->isChecked()) {
|
||||
double start = resultsTable->item(i,3)->text().toDouble();
|
||||
double stop = resultsTable->item(i,4)->text().toDouble();
|
||||
QString name = resultsTable->item(i,2)->text();
|
||||
RideFile *ride = (RideFile*)mainWindow->currentRide();
|
||||
|
||||
QTreeWidgetItem *last =
|
||||
new IntervalItem(ride, name, start, stop,
|
||||
ride->timeToDistance(start),
|
||||
ride->timeToDistance(stop));
|
||||
|
||||
// add
|
||||
QTreeWidgetItem *allIntervals = (QTreeWidgetItem *)mainwindow->allIntervalItems();
|
||||
allIntervals->addChild(last);
|
||||
}
|
||||
}
|
||||
mainWindow->updateRideFileIntervals();
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user