diff --git a/src/LTMPlot.cpp b/src/LTMPlot.cpp index cddc42448..9243e2c90 100644 --- a/src/LTMPlot.cpp +++ b/src/LTMPlot.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -153,6 +154,10 @@ LTMPlot::configChanged(qint32) palette.setColor(QPalette::Text, GColor(CPLOTMARKER)); setPalette(palette); + QPalette gray = palette; // same but with gray text for hidden curves + gray.setColor(QPalette::WindowText, Qt::darkGray); + gray.setColor(QPalette::Text, Qt::darkGray); + axesObject.clear(); axesId.clear(); foreach (QwtAxisId x, supportedAxes) { @@ -167,13 +172,21 @@ LTMPlot::configChanged(qint32) } axisWidget(QwtPlot::xBottom)->setPalette(palette); + QwtLegend *l = static_cast(this->legend()); - l->setPalette(palette); foreach(QwtPlotCurve *p, curves) { foreach (QWidget *w, l->legendWidgets(itemToInfo(p))) { - w->setPalette(palette); + for(int m=0; m< settings->metrics.count(); m++) { + if (settings->metrics[m].curve == p) + if (settings->metrics[m].hidden == false) + w->setPalette(palette); + else + w->setPalette(gray); + } } } + + // now save state curveColors->saveState(); updateLegend(); @@ -404,6 +417,8 @@ LTMPlot::setData(LTMSettings *set) // Create a curve QwtPlotCurve *current = new QwtPlotCurve(metricDetail.uname); + current->setVisible(!metricDetail.hidden); + settings->metrics[m].curve = current; if (metricDetail.type == METRIC_BEST) curves.insert(metricDetail.bestSymbol, current); else @@ -534,7 +549,9 @@ LTMPlot::setData(LTMSettings *set) // are painted in reverse order in a // loop before this one. stackcounter= 0; - foreach (MetricDetail metricDetail, settings->metrics) { + for(int m=0; mmetrics.count(); m++) { + + MetricDetail metricDetail = settings->metrics[m]; // // *ONLY* PLOT NON-STACKS @@ -553,6 +570,8 @@ LTMPlot::setData(LTMSettings *set) // Create a curve QwtPlotCurve *current = new QwtPlotCurve(metricDetail.uname); + current->setVisible(!metricDetail.hidden); + settings->metrics[m].curve = current; if (metricDetail.type == METRIC_BEST) curves.insert(metricDetail.bestSymbol, current); else @@ -608,6 +627,7 @@ LTMPlot::setData(LTMSettings *set) metricDetail.bestSymbol : metricDetail.symbol); QwtPlotCurve *trend = new QwtPlotCurve(trendName); + trend->setVisible(!metricDetail.hidden); // cosmetics QPen cpen = QPen(metricDetail.penColor.darker(200)); @@ -644,6 +664,7 @@ LTMPlot::setData(LTMSettings *set) metricDetail.bestSymbol : metricDetail.symbol); QwtPlotCurve *trend = new QwtPlotCurve(trendName); + trend->setVisible(!metricDetail.hidden); // cosmetics QPen cpen = QPen(metricDetail.penColor.darker(200)); @@ -706,6 +727,7 @@ LTMPlot::setData(LTMSettings *set) QString outSymbol = QString("%1_outlier").arg(metricDetail.type == METRIC_BEST ? metricDetail.bestSymbol : metricDetail.symbol); QwtPlotCurve *out = new QwtPlotCurve(outName); + out->setVisible(!metricDetail.hidden); curves.insert(outSymbol, out); out->setRenderHint(QwtPlotItem::RenderAntialiased); @@ -791,6 +813,7 @@ LTMPlot::setData(LTMSettings *set) .arg(metricDetail.type == METRIC_BEST ? metricDetail.bestSymbol : metricDetail.symbol); QwtPlotCurve *top = new QwtPlotCurve(topName); + top->setVisible(!metricDetail.hidden); curves.insert(topName, top); top->setRenderHint(QwtPlotItem::RenderAntialiased); @@ -862,6 +885,7 @@ LTMPlot::setData(LTMSettings *set) // make that mark -- always above with topN QwtPlotMarker *label = new QwtPlotMarker(); + label->setVisible(!metricDetail.hidden); label->setLabel(text); label->setValue(hxdata[i], hydata[i]); label->setYAxis(axisid); @@ -1023,6 +1047,7 @@ LTMPlot::setData(LTMSettings *set) // make that mark QwtPlotMarker *label = new QwtPlotMarker(); + label->setVisible(!metricDetail.hidden); label->setLabel(text); label->setValue(xdata[i], ydata[i]); label->setYAxis(axisid); @@ -2820,7 +2845,7 @@ LTMPlot::eventFilter(QObject *obj, QEvent *event) { // when clicking on a legend item, toggle if the curve is visible - if (obj == legend() && event->type() == 2) { + if (event->type() == QEvent::MouseButtonPress) { bool replotNeeded = false; QwtLegend *l = static_cast(this->legend()); @@ -2828,26 +2853,19 @@ LTMPlot::eventFilter(QObject *obj, QEvent *event) foreach(QwtPlotCurve *p, curves) { foreach (QWidget *w, l->legendWidgets(itemToInfo(p))) { if (w->underMouse()) { - QPalette palette; - palette.setBrush(QPalette::Window, QBrush(GColor(CPLOTBACKGROUND))); - - if (w->palette().color(QPalette::Text) == GColor(CPLOTMARKER)) { - palette.setColor(QPalette::WindowText, Qt::darkGray); - palette.setColor(QPalette::Text, Qt::darkGray); - p->setVisible(false); - } else { - palette.setColor(QPalette::WindowText, GColor(CPLOTMARKER)); - palette.setColor(QPalette::Text, GColor(CPLOTMARKER)); - p->setVisible(true); + //XXX this is a bit broken on a Mac (at least) + //XXX qDebug()<<"under mouse="<(w)->text().text(); + for(int m=0; m< settings->metrics.count(); m++) { + if (settings->metrics[m].curve == p) { + settings->metrics[m].hidden = !settings->metrics[m].hidden; + replotNeeded = true; + } } - replotNeeded = true; - w->setPalette(palette); } } } - if (replotNeeded) replot(); - return false; + if (replotNeeded) setData(settings); } // is it for other objects ? diff --git a/src/LTMSettings.h b/src/LTMSettings.h index 78b9ded70..b283f8f29 100644 --- a/src/LTMSettings.h +++ b/src/LTMSettings.h @@ -77,16 +77,17 @@ class RideBest; class MetricDetail { public: - MetricDetail() : type(METRIC_DB), stack(false), model(""), name(""), metric(NULL), stressType(0), + MetricDetail() : type(METRIC_DB), stack(false), hidden(false), model(""), name(""), metric(NULL), stressType(0), smooth(false), trendtype(0), topN(0), lowestN(0), topOut(0), baseline(0.0), curveStyle(QwtPlotCurve::Lines), symbolStyle(QwtSymbol::NoSymbol), penColor(Qt::black), penAlpha(0), penWidth(1.0), penStyle(0), - brushColor(Qt::black), brushAlpha(0), fillCurve(false), labels(false) {} + brushColor(Qt::black), brushAlpha(0), fillCurve(false), labels(false), curve(NULL) {} bool operator< (MetricDetail right) const { return name < right.name; } int type; bool stack; // should this be stacked? + bool hidden; // should this be hidden ? (toggled via clicking on legend) QString model; // short code for model selected int estimate; // 0-4 for W', CP, FTP, PMAX @@ -143,6 +144,9 @@ class MetricDetail { // text labels against values bool labels; + + // curve on the chart to spot this... + QwtPlotCurve *curve; }; // so we can marshal and unmarshall LTMSettings when we save