Dan Connelly's MEGA patch.

It includes both powerzones and weekly summary plots.

  Thanks Dan.
This commit is contained in:
Justin F. Knotzke
2009-06-22 02:27:11 +00:00
parent 13deea6f31
commit 3ab2c91ce2

View File

@@ -1,5 +1,6 @@
#include <QtGui>
#include <QSettings>
#include <assert.h>
#include "MainWindow.h"
#include "ConfigDialog.h"
@@ -7,11 +8,30 @@
#include "Settings.h"
#include "Zones.h"
ConfigDialog::ConfigDialog(QDir _home)
/* cyclist dialog protocol redesign:
* no zones:
* calendar disabled
* automatically go into "new" mode
* zone(s) defined:
* click on calendar: sets current zone to that associated with date
* save clicked:
* if new mode, create a new zone starting at selected date, or for all dates
* if this is only zone.
* delete clicked:
* deletes currently selected zone
*/
ConfigDialog::ConfigDialog(QDir _home, Zones **_zones)
{
home = _home;
zones = _zones;
assert(zones);
cyclistPage = new CyclistPage(zones);
contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode);
contentsWidget->setIconSize(QSize(96, 84));
@@ -23,52 +43,34 @@ ConfigDialog::ConfigDialog(QDir _home)
configPage = new ConfigurationPage();
QFile zonesFile(_home.absolutePath() + "/power.zones");
if (zonesFile.exists())
{
zones = new Zones();
if (!zones->read(zonesFile))
{
QMessageBox::warning(this, tr("Zones File Error"), zones->errorString());
zones = NULL;
}
cyclistPage = new CyclistPage(this, zones, false);
}
else
{
//If there is no zones file, create one in memory.
QDate date;
zones = new Zones();
zones->addZoneRange(date.currentDate(), date.currentDate(), 0);
cyclistPage = new CyclistPage(this, zones, true);
}
pagesWidget = new QStackedWidget;
pagesWidget->addWidget(configPage);
pagesWidget->addWidget(cyclistPage);
QPushButton *closeButton = new QPushButton(tr("Cancel"));
closeButton = new QPushButton(tr("Close"));
saveButton = new QPushButton(tr("Save"));
createIcons();
contentsWidget->setCurrentRow(0);
contentsWidget->setCurrentItem(contentsWidget->item(0));
connect(closeButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(saveButton, SIGNAL(clicked()), this, SLOT(accept()));
// connect(closeButton, SIGNAL(clicked()), this, SLOT(reject()));
// connect(saveButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cyclistPage->btnBack, SIGNAL(clicked()), this, SLOT(back_Clicked()));
connect(cyclistPage->btnForward, SIGNAL(clicked()), this, SLOT(forward_Clicked()));
connect(cyclistPage->btnNew, SIGNAL(clicked()), this, SLOT(new_Clicked()));
connect(cyclistPage->btnDelete, SIGNAL(clicked()), this, SLOT(delete_Clicked()));
connect(cyclistPage->calendar, SIGNAL(selectionChanged()), this, SLOT(calendarDateChanged()));
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(contentsWidget);
horizontalLayout->addWidget(pagesWidget, 1);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout = new QHBoxLayout;
buttonsLayout->addStretch(1);
buttonsLayout->addWidget(closeButton);
buttonsLayout->addWidget(saveButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout = new QVBoxLayout;
mainLayout->addLayout(horizontalLayout);
mainLayout->addStretch(1);
mainLayout->addSpacing(12);
@@ -78,6 +80,19 @@ ConfigDialog::ConfigDialog(QDir _home)
setWindowTitle(tr("Config Dialog"));
}
ConfigDialog::~ConfigDialog()
{
delete cyclistPage;
delete contentsWidget;
delete configPage;
delete pagesWidget;
delete closeButton;
delete horizontalLayout;
delete buttonsLayout;
delete mainLayout;
}
void ConfigDialog::createIcons()
{
QListWidgetItem *configButton = new QListWidgetItem(contentsWidget);
@@ -101,6 +116,11 @@ void ConfigDialog::createIcons()
connect(saveButton, SIGNAL(clicked()), this, SLOT(save_Clicked()));
}
void ConfigDialog::createNewRange()
{
}
void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
{
if (!current)
@@ -109,11 +129,21 @@ void ConfigDialog::changePage(QListWidgetItem *current, QListWidgetItem *previou
pagesWidget->setCurrentIndex(contentsWidget->row(current));
}
// if save is clicked, we want to:
// new mode: create a new zone starting at the selected date (which may be null, implying BEGIN
// ! new mode: change the CP associated with the present mode
void ConfigDialog::save_Clicked()
{
QSettings settings(GC_SETTINGS_CO, GC_SETTINGS_APP);
settings.setValue(GC_UNIT, configPage->unitCombo->currentText());
settings.setValue(GC_ALLRIDES_ASCENDING, configPage->allRidesAscending->checkState());
// if the CP text entry reads invalid, there's nothing we can do
int cp = cyclistPage->getCP();
if (cp == 0) {
QMessageBox::warning(this, tr("Invalid CP"), "Please enter valid CP and try again.");
cyclistPage->setCPFocus();
return;
settings.setValue(GC_CRANKLENGTH, configPage->crankLengthCombo->currentText());
//If the user never switched pages, then make sure we have up to date data.
@@ -139,135 +169,92 @@ void ConfigDialog::save_Clicked()
}
}
zones->write(home);
// if for some reason we have no zones yet, then create them
int range;
assert(zones);
if (! *zones) {
*zones = new Zones();
range = -1;
}
else
// determine the current range
range = cyclistPage->getCurrentRange();
accept();
// if this is new mode, or if no zone ranges are yet defined, set up the new range
if ((range == -1) || (cyclistPage->isNewMode()))
cyclistPage->setCurrentRange(range = (*zones)->insertRangeAtDate(cyclistPage->selectedDate(), cp));
else
(*zones)->setCP(range, cyclistPage->getText().toInt());
(*zones)->setZonesFromCP(range);
// update the "new zone" checkbox to visible and unchecked
cyclistPage->checkboxNew->setChecked(Qt::Unchecked);
cyclistPage->checkboxNew->setEnabled(true);
(*zones)->write(home);
}
void ConfigDialog::moveCalendarToCurrentRange() {
int range = cyclistPage->getCurrentRange();
if (range < 0)
return;
QDate date;
// put the cursor at the beginning of the selected range if it's not the first
if (range > 0)
date = (*zones)->getStartDate(cyclistPage->getCurrentRange());
// unless the range is the first range, in which case it goes at the end of that range
// use JulianDay to subtract one day from the end date, which is actually the first
// day of the following range
else
date = QDate::fromJulianDay((*zones)->getEndDate(cyclistPage->getCurrentRange()).toJulianDay() - 1);
cyclistPage->setSelectedDate(date);
}
void ConfigDialog::back_Clicked()
{
if ((cyclistPage->txtThreshold->isModified() == true) || cyclistPage->btnNew->isEnabled() == true)
{
if (cyclistPage->txtThreshold->text().length() == 0)
{
QMessageBox::warning(this, tr("Missing Field"), "CP cannot be empty.");
cyclistPage->txtThreshold->setFocus();
return;
}
//Store the current CP before changing zones.
zones->setCP(cyclistPage->getCurrentRange(), cyclistPage->txtThreshold->text().toInt());
}
QDate date;
cyclistPage->setCurrentRange(cyclistPage->getCurrentRange() - 1);
cyclistPage->btnForward->setEnabled(true);
int ftp = zones->getCP(cyclistPage->getCurrentRange());
QString strCP;
cyclistPage->txtThreshold->setText(strCP.setNum(ftp));
QDate _date = zones->getEndDate(cyclistPage->getCurrentRange());
if (cyclistPage->btnNew->isEnabled() == true)
cyclistPage->calendar->setEnabled(false);
cyclistPage->calendar->setMinimumDate(zones->getStartDate(0));
cyclistPage->calendar->setSelectedDate(_date);
if (cyclistPage->getCurrentRange() == 0)
cyclistPage->btnBack->setEnabled(false);
cyclistPage->lblCurRange->setText(QString("Current Zone Range: %1").arg(cyclistPage->getCurrentRange() + 1));
cyclistPage->txtStartDate->setDate(zones->getStartDate(cyclistPage->getCurrentRange()));
cyclistPage->txtEndDate->setDate(zones->getEndDate(cyclistPage->getCurrentRange()));
moveCalendarToCurrentRange();
}
void ConfigDialog::forward_Clicked()
{
if ((cyclistPage->txtThreshold->isModified() == true) || cyclistPage->btnNew->isEnabled() == true)
{
if (cyclistPage->txtThreshold->text().length() == 0)
{
QMessageBox::warning(this, tr("Missing Field"), "CP cannot be empty");
cyclistPage->txtThreshold->setFocus();
return;
}
//Store the current CP before changing zones.
zones->setCP(cyclistPage->getCurrentRange(), cyclistPage->txtThreshold->text().toInt());
}
if (cyclistPage->btnNew->isEnabled() == true)
cyclistPage->calendar->setEnabled(false);
//Now switch zones
QDate date;
cyclistPage->setCurrentRange(cyclistPage->getCurrentRange() + 1);
int ftp = zones->getCP(cyclistPage->getCurrentRange());
QString strCP;
cyclistPage->txtThreshold->setText(strCP.setNum(ftp));
if (cyclistPage->getCurrentRange() + 1 == zones->getRangeSize())
{
cyclistPage->btnForward->setEnabled(false);
date = zones->getStartDate(cyclistPage->getCurrentRange());
}
else
date = zones->getEndDate(cyclistPage->getCurrentRange());
cyclistPage->calendar->setSelectedDate(date);
cyclistPage->calendar->setMinimumDate(zones->getStartDate(cyclistPage->getCurrentRange()));
cyclistPage->btnBack->setEnabled(true);
cyclistPage->lblCurRange->setText(QString("Current Zone Range: %1").arg(cyclistPage->getCurrentRange() + 1));
cyclistPage->txtStartDate->setDate(zones->getStartDate(cyclistPage->getCurrentRange()));
cyclistPage->txtEndDate->setDate(zones->getEndDate(cyclistPage->getCurrentRange()));
moveCalendarToCurrentRange();
}
void ConfigDialog::new_Clicked()
{
void ConfigDialog::delete_Clicked() {
int range = cyclistPage->getCurrentRange();
int num_ranges = (*zones)->getRangeSize();
assert (num_ranges > 1);
QMessageBox msgBox;
msgBox.setText(
tr("Are you sure you want to delete the zone range\n"
"from %1 to %2?\n"
"(%3 range will extend to this date range):") .
arg((*zones)->getStartDateString(cyclistPage->getCurrentRange())) .
arg((*zones)->getEndDateString(cyclistPage->getCurrentRange())) .
arg((range > 0) ? "previous" : "next")
);
QPushButton *deleteButton = msgBox.addButton(tr("Delete"),QMessageBox::YesRole);
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
if(msgBox.clickedButton() == deleteButton)
cyclistPage->setCurrentRange((*zones)->deleteRange(range));
if ((cyclistPage->txtThreshold->isModified() == true) || cyclistPage->btnNew->isEnabled() == true)
{
if (cyclistPage->txtThreshold->text().length() == 0)
{
QMessageBox::warning(this, tr("Missing Field"), "CP cannot be empty");
cyclistPage->txtThreshold->setFocus();
return;
(*zones)->write(home);
}
//Store the current CP before changing zones.
zones->setCP(cyclistPage->getCurrentRange(), cyclistPage->txtThreshold->text().toInt());
void ConfigDialog::calendarDateChanged() {
int range = (*zones)->whichRange(cyclistPage->selectedDate());
assert(range >= 0);
cyclistPage->setCurrentRange(range);
}
cyclistPage->setChoseNewZone(true);
cyclistPage->txtThreshold->setText("");
cyclistPage->btnNew->setEnabled(false);
cyclistPage->calendar->setEnabled(true);
//Modify the current zone..
zones->setEndDate(cyclistPage->getCurrentRange(), cyclistPage->calendar->selectedDate());
//Create the Zone
cyclistPage->calendar->setMinimumDate(zones->getStartDate(zones->getRangeSize() - 1));
zones->addZoneRange(zones->getStartDate(cyclistPage->getCurrentRange()), cyclistPage->calendar->selectedDate(), 0);
cyclistPage->setCurrentRange(zones->getRangeSize() - 1);
cyclistPage->lblCurRange->setText(QString("Current Zone Range: %1").arg(cyclistPage->getCurrentRange() + 1));
if(cyclistPage->getCurrentRange() > 1)
cyclistPage->calendar->setMinimumDate(zones->getEndDate(zones->getRangeSize() - 1));
QDate date;
cyclistPage->calendar->setSelectedDate(date.currentDate());
}
ConfigDialog::~ConfigDialog()
{
delete zones;
}