TreeMap show rides when cell clicked

When a cell in the treemap plot is clicked they are displayed
in the popup pane also used by the LTM charts.

We do need to tart up the popup, but at least now the treemap
plot does something meaningful.

Fixes #364.
This commit is contained in:
Mark Liversedge
2012-12-04 15:13:46 +00:00
parent c59276f88a
commit c35c89049f
6 changed files with 125 additions and 14 deletions

View File

@@ -102,6 +102,97 @@ LTMPopup::setTitle(QString s)
title->setText(s);
}
void
LTMPopup::setData(QList<SummaryMetrics>data, const RideMetric *metric, QString title)
{
// list of activities only need to show 1 value (see symbol)
useMetricUnits = main->useMetricUnits;
// create the ride list
int count = 0;
rides->clear();
selected.clear();
// set headings
rides->setColumnCount(2);
// when
QTableWidgetItem *h = new QTableWidgetItem("Date & Time", QTableWidgetItem::Type);
rides->setHorizontalHeaderItem(0,h);
// value
h = new QTableWidgetItem(metric->name(), QTableWidgetItem::Type);
rides->setHorizontalHeaderItem(1,h);
// now add rows to the table for each entry
foreach(SummaryMetrics x, data) {
QDateTime rideDate = x.getRideDate();
// we'll select it for summary aggregation
selected << x;
// date/time
QTableWidgetItem *t = new QTableWidgetItem(rideDate.toString("ddd, dd MMM yy hh:mmA"));
t->setFlags(t->flags() & (~Qt::ItemIsEditable));
rides->setRowCount(count+1);
rides->setItem(count, 0, t);
rides->setRowHeight(count, 14);
// metrics
QString value = x.getStringForSymbol(metric->symbol(), useMetricUnits);
h = new QTableWidgetItem(value,QTableWidgetItem::Type);
h->setFlags(t->flags() & (~Qt::ItemIsEditable));
h->setTextAlignment(Qt::AlignHCenter);
rides->setItem(count, 1, h);
count++;
}
// make em all visible!
rides->resizeColumnsToContents();
if (count > 1) {
rides->setFixedHeight((count > 10 ? 10 : count) * 14 + rides->horizontalHeader()->height());
}
// select the first one
rides->setRangeSelected(QTableWidgetSelectionRange(0,0,0,1), true);
// for now at least, if multiple rides then show the table
// if single ride show the summary, show all if we're grouping by
// days tho, since we're interested in specific rides...
if (count > 1) {
//int size = ((count+1)*14) + rides->horizontalHeader()->height() + 4;
//rides->setFixedHeight(size > 100 ? 100 : size);
rides->show();
metrics->show();
notes->show();
} else {
rides->hide();
metrics->show();
notes->show();
}
// Metric summary
QString filename = main->home.absolutePath()+"/ltm-summary.html";
if (!QFile(filename).exists()) filename = ":/html/ltm-summary.html";
// read it in...
QFile summaryFile(filename);
if (summaryFile.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&summaryFile);
summary = in.readAll();
summaryFile.close();
}
setTitle(title);
rideSelected();
}
void
LTMPopup::setData(LTMSettings &settings, QDate start, QDate end)
{

View File

@@ -24,6 +24,7 @@
#include "Settings.h"
#include "LTMSettings.h"
#include "MetricAggregator.h"
#include "RideMetric.h"
#include <QDir>
#include <QtGui>
@@ -38,8 +39,13 @@ class LTMPopup : public QWidget
LTMPopup(MainWindow *parent);
void setTitle(QString);
// when called from LTM chart
void setData(LTMSettings &settings, QDate start, QDate end);
// when called from a TreeMap chart
void setData(QList<SummaryMetrics>data, const RideMetric *metric, QString title);
signals:
private slots:

View File

@@ -213,7 +213,7 @@ TreeMapPlot::eventFilter(QObject *, QEvent *e)
// got one?
if (underMouse) {
//qDebug()<<"clicked on:"<<underMouse->parent->name<<underMouse->name;
emit clicked(underMouse->parent->name, underMouse->name);
}
}
}

View File

@@ -248,6 +248,9 @@ class TreeMapPlot : public QWidget
void configUpdate();
bool eventFilter(QObject *object, QEvent *e);
signals:
void clicked(QString, QString);
protected:
TreeMapWindow *parent;

View File

@@ -121,18 +121,22 @@ TreeMapWindow::TreeMapWindow(MainWindow *parent, bool useMetricUnits, const QDir
metricTree->expandItem(allMetrics);
cl->addRow(new QLabel("Metric"), metricTree);
// chart settings changed
connect(this, SIGNAL(dateRangeChanged(DateRange)), this, SLOT(dateRangeChanged(DateRange)));
connect(metricTree,SIGNAL(itemSelectionChanged()), this, SLOT(metricTreeWidgetSelectionChanged()));
connect(field1, SIGNAL(currentIndexChanged(int)), this, SLOT(fieldSelected(int)));
connect(field2, SIGNAL(currentIndexChanged(int)), this, SLOT(fieldSelected(int)));
// config changes or ride file activities cause a redraw/refresh (but only if active)
//connect(main, SIGNAL(rideSelected()), this, SLOT(rideSelected(void)));
connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected()));
connect(main, SIGNAL(rideAdded(RideItem*)), this, SLOT(refresh(void)));
connect(main, SIGNAL(rideDeleted(RideItem*)), this, SLOT(refresh(void)));
connect(main, SIGNAL(configChanged()), this, SLOT(refresh()));
// user clicked on a cell in the plot
connect(ltmPlot, SIGNAL(clicked(QString,QString)), this, SLOT(cellClicked(QString,QString)));
// lets refresh / setup state
refresh();
}
@@ -204,19 +208,26 @@ TreeMapWindow::fieldSelected(int)
}
void
TreeMapWindow::pointClicked(QwtPlotCurve*, int )
TreeMapWindow::cellClicked(QString f1, QString f2)
{
//XXX Throw up an LTM Popup when selected...
#if 0
// get the date range for this point
QDate start, end;
LTMScaleDraw *lsd = new LTMScaleDraw(settings.start,
groupForDate(settings.start.date(), settings.groupBy),
settings.groupBy);
lsd->dateRange((int)round(curve->sample(index).x()), start, end);
ltmPopup->setData(settings, start, end);
QList<SummaryMetrics> cell;
// create a list of activities in this cell
int count = 0;
foreach(SummaryMetrics x, results) {
if (x.getText(settings.field1, "(unknown)") == f1 &&
x.getText(settings.field2, "(unknown)") == f2) {
cell.append(x);
count++;
}
}
const RideMetricFactory &factory = RideMetricFactory::instance();
const RideMetric *metric = factory.rideMetric(settings.symbol);
ltmPopup->setData(cell, metric, QString("%1 ride%2").arg(count).arg(count == 1 ? "" : "s"));
popup->show();
#endif
}
void

View File

@@ -94,7 +94,7 @@ class TreeMapWindow : public GcWindow
void metricTreeWidgetSelectionChanged();
void refresh();
void fieldSelected(int);
void pointClicked(QwtPlotCurve*, int);
void cellClicked(QString, QString); // cell clicked
private:
// passed from MainWindow