IntervalPlot: color for Match

This commit is contained in:
Damien
2014-12-27 16:06:12 +01:00
parent 26811f2576
commit a3505a375f
3 changed files with 72 additions and 99 deletions

View File

@@ -95,12 +95,12 @@ AllPlotInterval::AllPlotInterval(QWidget *parent, Context *context):
setPalette(pal);
// tick draw
TimeScaleDraw *tsd = new TimeScaleDraw(&this->bydist) ;
tsd->setTickLength(QwtScaleDiv::MajorTick, 3);
setAxisScaleDraw(QwtPlot::xBottom, tsd);
pal.setColor(QPalette::WindowText, GColor(CPLOTMARKER));
pal.setColor(QPalette::Text, GColor(CPLOTMARKER));
axisWidget(QwtPlot::xBottom)->setPalette(pal);
//TimeScaleDraw *tsd = new TimeScaleDraw(&this->bydist) ;
//tsd->setTickLength(QwtScaleDiv::MajorTick, 3);
//setAxisScaleDraw(QwtPlot::xBottom, tsd);
//pal.setColor(QPalette::WindowText, GColor(CPLOTMARKER));
//pal.setColor(QPalette::Text, GColor(CPLOTMARKER));
//axisWidget(QwtPlot::xBottom)->setPalette(pal);
enableAxis(xBottom, false);
setAxisVisible(xBottom, false);
@@ -145,27 +145,56 @@ AllPlotInterval::setDataFromRide(RideItem *_rideItem)
void
AllPlotInterval::refreshIntervals()
{
sortIntervals();
placeIntervals();
refreshIntervalCurve();
//refreshIntervalMarkers();
}
// Compare two RideFileInterval on duration.
bool intervalBiggerThan(const RideFileInterval &i1, const RideFileInterval &i2)
bool intervalBiggerThan(const RideFileInterval &i1, const RideFileInterval &i2)
{
return (i1.stop-i1.start) > (i2.stop-i2.start);
}
void
AllPlotInterval::sortIntervals()
AllPlotInterval::sortIntervals(QList<RideFileInterval> &intervals, QList< QList<RideFileInterval> > &intervalsGroups)
{
// Sort by duration
qSort(intervals.begin(), intervals.end(), intervalBiggerThan);
QList<RideFileInterval> matchesGroup;
for (int i=0; i<intervals.count(); i++) {
RideFileInterval interval = intervals.at(i);
if (interval.isMatch()) {
matchesGroup.append(interval);
intervals.removeOne(interval);
//intervals.move(i, place++);
}
}
if (matchesGroup.count() > 0)
intervalsGroups.append(matchesGroup);
}
void
AllPlotInterval::placeIntervals()
{
QList<RideFileInterval> intervals = rideItem->ride()->intervals();
qSort(intervals.begin(), intervals.end(), intervalBiggerThan);
QList< QList<RideFileInterval> > intervalsGroups;
sortIntervals(intervals, intervalsGroups);
intervalLigns.clear();
QList<RideFileInterval> intervalsLign1;
intervalLigns.append(intervalsLign1);
if (intervalsGroups.count()>0)
intervalLigns.append(intervalsGroups.at(0));
else {
QList<RideFileInterval> intervalsLign1;
intervalLigns.append(intervalsLign1);
}
while (intervals.count()>0) {
const RideFileInterval &interval = intervals.first();
@@ -176,6 +205,11 @@ AllPlotInterval::sortIntervals()
while (!placed) {
bool place = true;
/*if (interval.isPeak()) {
intervals.removeFirst();
placed = true;
}*/
foreach(const RideFileInterval &placedinterval, intervalLigns.at(lign)) {
if (interval.stop>placedinterval.start && interval.start<placedinterval.stop)
place = false;
@@ -199,86 +233,31 @@ AllPlotInterval::sortIntervals()
}
void
AllPlotInterval::refreshIntervalMarkers()
AllPlotInterval::setColorForIntervalCurve(QwtPlotIntervalCurve *intervalCurve, const RideFileInterval &interval, bool selected)
{
foreach(QwtPlotMarker *mrk, markers) {
mrk->detach();
delete mrk;
QColor color;
if (interval.isPeak()) {
color = Qt::lightGray;
} else if (interval.isMatch()) {
color = Qt::red;
}
markers.clear();
QRegExp wkoAuto("^(Peak *[0-9]*(s|min)|Entire workout|Find #[0-9]*) *\\([^)]*\\)$");
int level=0;
foreach(const QList<RideFileInterval> &intervalsLign, intervalLigns) {
foreach(const RideFileInterval &interval, intervalsLign) {
bool wko = false;
// skip WKO autogenerated peak intervals
if (wkoAuto.exactMatch(interval.name)) wko = true;
QwtPlotMarker *mrk = new QwtPlotMarker;
markers.append(mrk);
mrk->attach(this);
mrk->setLineStyle(QwtPlotMarker::NoLine);
mrk->setLabelAlignment(Qt::AlignRight | Qt::AlignTop);
if (wko) mrk->setLinePen(QPen(QColor(127,127,127,127), 0, Qt::DashLine));
else mrk->setLinePen(QPen(GColor(CPLOTMARKER), 0, Qt::DashLine));
// put matches on second line down
QString name(interval.name);
if (interval.name.startsWith(tr("Match"))) name = QString("\n%1").arg(interval.name);
QwtText text(!wko ? name : "");
if (!wko) {
text.setFont(QFont("Helvetica", 10, QFont::Bold));
if (interval.name.startsWith(tr("Match")))
text.setColor(GColor(CWBAL));
else
text.setColor(GColor(CPLOTMARKER));
}
mrk->setYAxis(yLeft);
if (!bydist)
mrk->setValue(interval.start / 60.0, 3000*intervalLigns.count()-2200-3000*level);
else
mrk->setValue((context->athlete->useMetricUnits ? 1 : MILES_PER_KM) *
rideItem->ride()->timeToDistance(interval.start), 3000*intervalLigns.count()-2200-3000*level);
mrk->setLabel(text);
/*qDebug() << "width()" << width() << "widthMM()" << widthMM() << devicePixelRatio();
double widthInt = transform(QwtPlot::xBottom, interval.stop) - transform(QwtPlot::xBottom, interval.start);
qDebug() << "widthInt" << widthInt << interval.stop << transform(QwtPlot::xBottom, interval.stop) << interval.start << transform(QwtPlot::xBottom, interval.start);
int width = 0;
do {
QFontMetrics fontMetrics( mrk->label().font() );
width = fontMetrics.width( text.text() );
qDebug() << "width" << width;
if (width > widthInt)
text.setText(text.text().left(text.text().size()-2));
} while (width > widthInt );
*/
}
level++;
else {
color = GColor(CINTERVALHIGHLIGHTER);
}
QPen ihlPen = QPen(color);
intervalCurve->setPen(ihlPen);
QColor ihlbrush = QColor(color);
if (!selected)
ihlbrush.setAlpha(128);
intervalCurve->setPen(ihlbrush); // fill below the line
intervalCurve->setBrush(ihlbrush); // fill below the line
}
void
AllPlotInterval::refreshIntervalCurve()
{
foreach(QwtPlotIntervalCurve *curve, curves) {
foreach(QwtPlotIntervalCurve *curve, curves.values()) {
curve->detach();
delete curve;
}
@@ -291,12 +270,7 @@ AllPlotInterval::refreshIntervalCurve()
QwtPlotIntervalCurve *intervalCurve = new QwtPlotIntervalCurve();
intervalCurve->setYAxis(QwtAxis::yLeft);
QPen ihlPen = QPen(GColor(CINTERVALHIGHLIGHTER));
intervalCurve->setPen(ihlPen);
QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER));
ihlbrush.setAlpha(128);
intervalCurve->setPen(ihlbrush); // fill below the line
intervalCurve->setBrush(ihlbrush); // fill below the line
setColorForIntervalCurve(intervalCurve, interval, false);
int max = 3000*intervalLigns.count();
intervalCurve->setSamples(new AllPlotIntervalData(this, context, level, max, rideItem, interval));
@@ -313,14 +287,9 @@ AllPlotInterval::intervalHover(RideFileInterval chosen)
{
foreach(RideFileInterval interval, curves.keys()) {
if (chosen == interval || context->athlete->allIntervalItems()->child(rideItem->ride()->intervals().indexOf(interval))->isSelected()) {
QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER));
ihlbrush.setAlpha(255);
curves.value(interval)->setBrush(ihlbrush);
setColorForIntervalCurve(curves.value(interval), interval, true);
} else {
QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER));
ihlbrush.setAlpha(128);
curves.value(interval)->setPen(ihlbrush);
curves.value(interval)->setBrush(ihlbrush);
setColorForIntervalCurve(curves.value(interval), interval, false);
}
}
replot();