mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Chart Dates: Part 2 of 3 update
.. added a 'This' option to choose a date range such as this month, week, year. I also added the ability to specift a 'prior' period. So in July you could plot for this month prior 1 to choose a date range for June. This allows folks to have a static setup of charts for this this-1 and this-2 months and data to change over time.
This commit is contained in:
@@ -96,13 +96,14 @@ class LTMWindow : public LTMPlotContainer
|
||||
#ifdef GC_HAVE_LUCENE
|
||||
Q_PROPERTY(QString filter READ filter WRITE setFilter USER true)
|
||||
#endif
|
||||
Q_PROPERTY(int useSelected READ useSelected WRITE setUseSelected USER true)
|
||||
Q_PROPERTY(QDate fromDate READ fromDate WRITE setFromDate USER true)
|
||||
Q_PROPERTY(QDate toDate READ toDate WRITE setToDate USER true)
|
||||
Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate USER true)
|
||||
Q_PROPERTY(int lastN READ lastN WRITE setLastN USER true)
|
||||
Q_PROPERTY(int lastNX READ lastNX WRITE setLastNX USER true)
|
||||
Q_PROPERTY(int prevN READ prevN WRITE setPrevN USER true)
|
||||
Q_PROPERTY(LTMSettings settings READ getSettings WRITE applySettings USER true)
|
||||
Q_PROPERTY(int useSelected READ useSelected WRITE setUseSelected USER true) // !! must be last property !!
|
||||
|
||||
public:
|
||||
|
||||
@@ -135,6 +136,9 @@ class LTMWindow : public LTMPlotContainer
|
||||
int lastNX() { return ltmTool->dateSetting->lastNX(); }
|
||||
void setLastNX(int x) { ltmTool->dateSetting->setLastNX(x); }
|
||||
|
||||
int prevN() { return ltmTool->dateSetting->prevN(); }
|
||||
void setPrevN(int x) { ltmTool->dateSetting->setPrevN(x); }
|
||||
|
||||
#ifdef GC_HAVE_LUCENE
|
||||
QString filter() const { return ltmTool->searchBox->filter(); }
|
||||
void setFilter(QString x) { ltmTool->searchBox->setFilter(x); }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Sean C. Rhea (srhea@srhea.net)
|
||||
* Copyright (c) 2012 Mark Liversedge (liversedge@gmail.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
@@ -21,6 +22,7 @@
|
||||
#include <QRegExpValidator>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QDebug>
|
||||
|
||||
QString time_to_string(double secs)
|
||||
{
|
||||
@@ -198,17 +200,42 @@ DateSettingsEdit::DateSettingsEdit(QWidget *parent) : parent(parent), active(tru
|
||||
last->addStretch();
|
||||
mainLayout->addRow(last);
|
||||
|
||||
radioThis = new QRadioButton(tr("This"), this);
|
||||
radioThis->setFont(sameFont);
|
||||
radioThis->setChecked(false);
|
||||
thisperiod = new QComboBox(this);
|
||||
thisperiod->addItem(tr("week"));
|
||||
thisperiod->addItem(tr("month"));
|
||||
thisperiod->addItem(tr("year"));
|
||||
thisperiod->setCurrentIndex(0);
|
||||
prevperiod = new QDoubleSpinBox(this);
|
||||
prevperiod->setSingleStep(1.0);
|
||||
prevperiod->setDecimals(0);
|
||||
prevperiod->setMinimum(0);
|
||||
prevperiod->setMaximum(999);
|
||||
prevperiod->setValue(0);
|
||||
QHBoxLayout *thisl = new QHBoxLayout;
|
||||
thisl->addWidget(radioThis);
|
||||
thisl->addWidget(thisperiod);
|
||||
thisl->addWidget(new QLabel(tr("prior")));
|
||||
thisl->addWidget(prevperiod);
|
||||
thisl->addStretch();
|
||||
mainLayout->addRow(thisl);
|
||||
|
||||
// switched between one or other
|
||||
connect(radioSelected, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
|
||||
connect(radioToday, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
|
||||
connect(radioCustom, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
|
||||
connect(radioLast, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
|
||||
connect(radioFrom, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
|
||||
connect(radioThis, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
|
||||
connect(fromDateEdit, SIGNAL(editingFinished()), this, SLOT(setDateSettings()));
|
||||
connect(toDateEdit, SIGNAL(editingFinished()), this, SLOT(setDateSettings()));
|
||||
connect(startDateEdit, SIGNAL(editingFinished()), this, SLOT(setDateSettings()));
|
||||
connect(lastn, SIGNAL(editingFinished()), this, SLOT(setDateSettings()));
|
||||
connect(lastnx, SIGNAL(currentIndexChanged(int)), this, SLOT(setDateSettings()));
|
||||
connect(thisperiod, SIGNAL(currentIndexChanged(int)), this, SLOT(setDateSettings()));
|
||||
connect(prevperiod, SIGNAL(editingFinished()), this, SLOT(setDateSettings()));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -221,6 +248,8 @@ DateSettingsEdit::setDateSettings()
|
||||
fromDateEdit->setEnabled(false);
|
||||
toDateEdit->setEnabled(false);
|
||||
startDateEdit->setEnabled(false);
|
||||
thisperiod->setEnabled(false);
|
||||
prevperiod->setEnabled(false);
|
||||
lastn->setEnabled(false);
|
||||
lastnx->setEnabled(false);
|
||||
|
||||
@@ -280,9 +309,46 @@ DateSettingsEdit::setDateSettings()
|
||||
startDateEdit->setEnabled(true);
|
||||
emit useCustomRange(DateRange(startDateEdit->date(), QDate::currentDate()));
|
||||
|
||||
} else if (radioThis->isChecked()) {
|
||||
|
||||
thisperiod->setEnabled(true);
|
||||
prevperiod->setEnabled(true);
|
||||
|
||||
QDate today = QDate::currentDate();
|
||||
QDate from, to;
|
||||
|
||||
switch(thisperiod->currentIndex()) {
|
||||
|
||||
case 0 : // weeks
|
||||
{
|
||||
int dow = today.dayOfWeek(); // 1-7, where 1=monday
|
||||
from = today.addDays(-1 * (dow-1));
|
||||
to = from.addDays(6);
|
||||
qDebug()<<"preperiod="<<prevperiod->value();
|
||||
// prevperiods
|
||||
from = from.addDays(prevperiod->value() * -7);
|
||||
to = to.addDays(prevperiod->value() * -7);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1 : // months
|
||||
from = QDate(today.year(), today.month(), 1);
|
||||
to = from.addMonths(1).addDays(-1);
|
||||
from = from.addMonths(prevperiod->value() * -1);
|
||||
to = to.addMonths(prevperiod->value() * -1);
|
||||
break;
|
||||
|
||||
case 2 : // years
|
||||
from = QDate(today.year(), 1, 1);
|
||||
to = from.addYears(1).addDays(-1);
|
||||
from = from.addYears(prevperiod->value() * -1);
|
||||
to = to.addYears(prevperiod->value() * -1);
|
||||
break;
|
||||
|
||||
}
|
||||
emit useCustomRange(DateRange(from, to));
|
||||
}
|
||||
active = false;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
@@ -293,6 +359,7 @@ DateSettingsEdit::mode()
|
||||
if (radioCustom->isChecked()) return 2;
|
||||
if (radioLast->isChecked()) return 3;
|
||||
if (radioToday->isChecked()) return 4;
|
||||
if (radioThis->isChecked()) return 5;
|
||||
|
||||
return 0; // keep compiler happy
|
||||
}
|
||||
@@ -306,6 +373,7 @@ DateSettingsEdit::setMode(int x)
|
||||
radioCustom->setChecked(false);
|
||||
radioLast->setChecked(false);
|
||||
radioToday->setChecked(false);
|
||||
radioThis->setChecked(false);
|
||||
active = false;
|
||||
|
||||
switch(x) {
|
||||
@@ -324,6 +392,9 @@ DateSettingsEdit::setMode(int x)
|
||||
case 4:
|
||||
radioToday->setChecked(true);
|
||||
break;
|
||||
case 5:
|
||||
radioThis->setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,10 +60,11 @@ class DateSettingsEdit : public QWidget
|
||||
bool active;
|
||||
|
||||
// editing components
|
||||
QRadioButton *radioSelected, *radioToday, *radioCustom, *radioLast, *radioFrom;
|
||||
QRadioButton *radioSelected, *radioToday, *radioCustom, *radioLast, *radioFrom, *radioThis;
|
||||
QDateEdit *fromDateEdit, *toDateEdit, *startDateEdit;
|
||||
QDoubleSpinBox *lastn;
|
||||
QDoubleSpinBox *lastn,*prevperiod;
|
||||
QComboBox *lastnx;
|
||||
QComboBox *thisperiod;
|
||||
|
||||
public:
|
||||
|
||||
@@ -88,6 +89,12 @@ class DateSettingsEdit : public QWidget
|
||||
int lastNX() { return lastnx->currentIndex(); }
|
||||
void setLastNX(int x) { lastnx->setCurrentIndex(x); }
|
||||
|
||||
// this week/month/year
|
||||
int thisN() { return thisperiod->currentIndex(); }
|
||||
void setThisN(int x) { thisperiod->setCurrentIndex(x); }
|
||||
int prevN() { return prevperiod->value(); }
|
||||
void setPrevN(int x) { return prevperiod->setValue(x); }
|
||||
|
||||
private slots:
|
||||
void setDateSettings();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user