Chart Dates: Part 1 of 3

An update to allow users to define a specific date
range for a chart on the home window. This update
only applies to the LTM chart and only allows a
date range from/to to be defined.

It would be nice to also support a last 'n' 'period'
selection too (i.e. last n days/weeks/months).

Also, further updates are required to add similar
functionality to TreeMap, CP, Dist and Summary charts
when they are on the home window.
This commit is contained in:
Mark Liversedge
2013-01-02 14:34:17 +00:00
parent 2c300c0e82
commit ee36317b0f
5 changed files with 100 additions and 5 deletions

View File

@@ -1392,6 +1392,7 @@ HomeWindow::saveState()
if (QString(p.typeName()) == "int") out<<p.read(chart).toInt();
if (QString(p.typeName()) == "double") out<<p.read(chart).toDouble();
if (QString(p.typeName()) == "QDate") out<<p.read(chart).toDate().toString();
if (QString(p.typeName()) == "QString") out<<xmlprotect(p.read(chart).toString());
if (QString(p.typeName()) == "bool") out<<p.read(chart).toBool();
if (QString(p.typeName()) == "LTMSettings") {
@@ -1505,6 +1506,7 @@ bool ViewParser::startElement( const QString&, const QString&, const QString &na
// deprecate dateRange asa chart propert THAT IS DSAVED IN STATE
if (type == "QString" && name != "dateRange") chart->setProperty(name.toLatin1(), QVariant(QString(value)));
if (type == "QDate") chart->setProperty(name.toLatin1(), QVariant(QDate::fromString(value)));
if (type == "bool") chart->setProperty(name.toLatin1(), QVariant(value.toInt() ? true : false));
if (type == "LTMSettings") {
QByteArray base64(value.toLatin1());

View File

@@ -72,9 +72,29 @@ LTMTool::LTMTool(MainWindow *parent, const QDir &home, bool multi) : QWidget(par
QHBoxLayout *presetrow = new QHBoxLayout;
presetrow->addWidget(presetLabel);
presetrow->addWidget(presetPicker);
presetrow->addStretch();
basicLayout->addLayout(presetrow);
basicLayout->addStretch();
radioSelected = new QRadioButton(tr("Current Selection"), this);
radioSelected->setChecked(true);
QHBoxLayout *selected = new QHBoxLayout; // use same layout mechanism as custom so they align
selected->addWidget(radioSelected);
selected->addStretch();
basicsettingsLayout->addRow(new QLabel("Date Range"), selected);
radioCustom = new QRadioButton(tr("From"), this);
radioCustom->setChecked(false);
fromDateEdit = new QDateEdit(this);
toDateEdit = new QDateEdit(this);
QHBoxLayout *custom = new QHBoxLayout;
custom->addWidget(radioCustom);
custom->addWidget(fromDateEdit);
custom->addWidget(new QLabel(tr("to")));
custom->addWidget(toDateEdit);
custom->addStretch();
basicsettingsLayout->addRow(new QLabel(""), custom);
groupBy = new QComboBox;
groupBy->addItem("Days", LTM_DAY);
groupBy->addItem("Weeks", LTM_WEEK);
@@ -85,10 +105,10 @@ LTMTool::LTMTool(MainWindow *parent, const QDir &home, bool multi) : QWidget(par
basicsettingsLayout->addRow(new QLabel("Group by"), groupBy);
shadeZones = new QCheckBox("Shade Zones");
basicsettingsLayout->addRow(shadeZones);
basicsettingsLayout->addRow(new QLabel(""), shadeZones);
showLegend = new QCheckBox("Show Legend");
basicsettingsLayout->addRow(showLegend);
basicsettingsLayout->addRow(new QLabel(""), showLegend);
// controls
saveButton = new QPushButton(tr("Add"));
@@ -550,6 +570,12 @@ LTMTool::LTMTool(MainWindow *parent, const QDir &home, bool multi) : QWidget(par
this, SLOT(configChanged()));
connect(metricTree,SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(metricTreePopup(const QPoint &)));
// switched between one or other
connect(radioSelected, SIGNAL(toggled(bool)), this, SLOT(setDateSettings()));
connect(fromDateEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setDateSettings()));
connect(toDateEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setDateSettings()));
}
QwtPlotCurve::CurveStyle
@@ -929,6 +955,27 @@ LTMTool::setFilter(QStringList files)
emit filterChanged();
}
void
LTMTool::setDateSettings()
{
// the date selection types have changed
if (radioCustom->isChecked()) {
fromDateEdit->setEnabled(true);
toDateEdit->setEnabled(true);
// set date range using custom values
emit useCustomRange(DateRange(fromDateEdit->date(), toDateEdit->date()));
} else {
fromDateEdit->setEnabled(false);
toDateEdit->setEnabled(false);
emit useStandardRange();
}
}
void
LTMTool::translateDefaultCharts(QList<LTMSettings>&charts)
{

View File

@@ -90,12 +90,16 @@ class LTMTool : public QWidget
QCheckBox *showLegend;
QPushButton *saveButton;
QPushButton *manageButton;
QRadioButton *radioSelected, *radioCustom;
QDateEdit *fromDateEdit, *toDateEdit;
signals:
//void dateRangeSelected(const Season *);
void filterChanged();
void metricSelected();
void useCustomRange(DateRange); // use the range passed...
void useStandardRange(); // fall back to standard date range...
private slots:
//void dateRangeTreeWidgetSelectionChanged();
@@ -113,6 +117,7 @@ class LTMTool : public QWidget
void clearFilter();
void setFilter(QStringList);
void setDateSettings(); // when settings are updated wrt date selections
private:

View File

@@ -40,6 +40,7 @@ LTMWindow::LTMWindow(MainWindow *parent, bool useMetricUnits, const QDir &home)
{
main = parent;
setInstanceName("Metric Window");
useCustom = false;
plotted = DateRange(QDate(01,01,01), QDate(01,01,01));
// the plot
@@ -110,6 +111,8 @@ LTMWindow::LTMWindow(MainWindow *parent, bool useMetricUnits, const QDir &home)
connect(ltmTool->presetPicker, SIGNAL(currentIndexChanged(int)), this, SLOT(chartSelected(int)));
connect(ltmTool->shadeZones, SIGNAL(stateChanged(int)), this, SLOT(shadeZonesClicked(int)));
connect(ltmTool->showLegend, SIGNAL(stateChanged(int)), this, SLOT(showLegendClicked(int)));
connect(ltmTool, SIGNAL(useCustomRange(DateRange)), this, SLOT(useCustomRange(DateRange)));
connect(ltmTool, SIGNAL(useStandardRange()), this, SLOT(useStandardRange()));
// connect pickers to ltmPlot
connect(_canvasPicker, SIGNAL(pointHover(QwtPlotCurve*, int)), ltmPlot, SLOT(pointHover(QwtPlotCurve*, int)));
@@ -158,12 +161,28 @@ void
LTMWindow::refreshPlot()
{
if (amVisible() == true) {
plotted = myDateRange;
plotted = DateRange(settings.start.date(), settings.end.date());
ltmPlot->setData(&settings);
dirty = false;
}
}
void
LTMWindow::useCustomRange(DateRange range)
{
// plot using the supplied range
useCustom = true;
custom = range;
dateRangeChanged(custom);
}
void
LTMWindow::useStandardRange()
{
useCustom = false;
dateRangeChanged(myDateRange);
}
// total redraw, reread data etc
void
LTMWindow::refresh()
@@ -222,8 +241,13 @@ LTMWindow::dateRangeChanged(DateRange range)
void
LTMWindow::filterChanged()
{
settings.start = QDateTime(myDateRange.from, QTime(0,0));
settings.end = QDateTime(myDateRange.to, QTime(24,0,0));
if (useCustom) {
settings.start = QDateTime(custom.from, QTime(0,0));
settings.end = QDateTime(custom.to, QTime(24,0,0));
} else {
settings.start = QDateTime(myDateRange.from, QTime(0,0));
settings.end = QDateTime(myDateRange.to, QTime(24,0,0));
}
settings.title = myDateRange.name;
settings.data = &results;
settings.measures = &measures;

View File

@@ -96,6 +96,9 @@ class LTMWindow : public LTMPlotContainer
#ifdef GC_HAVE_LUCENE
Q_PROPERTY(QString filter READ filter WRITE setFilter USER true)
#endif
Q_PROPERTY(bool 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(LTMSettings settings READ getSettings WRITE applySettings USER true)
public:
@@ -114,6 +117,15 @@ class LTMWindow : public LTMPlotContainer
bool legend() const { return ltmTool->showLegend->isChecked(); }
void setLegend(bool x) { ltmTool->showLegend->setChecked(x); }
bool useSelected() { return ltmTool->radioSelected->isChecked(); }
void setUseSelected(bool x) { ltmTool->radioSelected->setChecked(x);
ltmTool->radioCustom->setChecked(!x);
}
QDate fromDate() { return ltmTool->fromDateEdit->date(); }
void setFromDate(QDate date) { return ltmTool->fromDateEdit->setDate(date); }
QDate toDate() { return ltmTool->toDateEdit->date(); }
void setToDate(QDate date) { return ltmTool->toDateEdit->setDate(date); }
#ifdef GC_HAVE_LUCENE
QString filter() const { return ltmTool->searchBox->filter(); }
void setFilter(QString x) { ltmTool->searchBox->setFilter(x); }
@@ -138,6 +150,8 @@ class LTMWindow : public LTMPlotContainer
void pointClicked(QwtPlotCurve*, int);
int groupForDate(QDate, int);
void useCustomRange(DateRange);
void useStandardRange();
private:
// passed from MainWindow
@@ -145,6 +159,9 @@ class LTMWindow : public LTMPlotContainer
bool useMetricUnits;
DateRange plotted;
bool useCustom;
DateRange custom; // custom date range supplied
// qwt picker
LTMToolTip *picker;
LTMCanvasPicker *_canvasPicker; // allow point selection/hover