Add QChart to Python Chart (3h of 5)

Use legend to select which series are plotted by clicking to
show hide a series. Hover just shows a hover background and
does not temporarily isolate the series, this may be something
to consider for later.

Applies to scatter and line charts.
This commit is contained in:
Mark Liversedge
2020-02-28 14:31:50 +00:00
parent 21d1e071bf
commit 0ecfa0e67e
6 changed files with 285 additions and 170 deletions

View File

@@ -76,6 +76,7 @@ GenericPlot::GenericPlot(QWidget *parent, Context *context) : QWidget(parent), c
connect(selector, SIGNAL(hover(QPointF,QString,QAbstractSeries*)), legend, SLOT(hover(QPointF,QString,QAbstractSeries*)));
connect(selector, SIGNAL(unhover(QString)), legend, SLOT(unhover(QString)));
connect(selector, SIGNAL(unhoverx()), legend, SLOT(unhoverx()));
connect(legend, SIGNAL(clicked(QString,bool)), this, SLOT(setSeriesVisible(QString,bool)));
// config changed...
configChanged(0);
@@ -211,6 +212,23 @@ GenericPlot::configChanged(qint32)
qchart->setBackgroundPen(QPen(GColor(CPLOTMARKER)));
}
void
GenericPlot::setSeriesVisible(QString name, bool visible)
{
// find the curve
QAbstractSeries *series = curves.value(name, NULL);
// does it exist and did it change?
if (series && series->isVisible() != visible) {
// show/hide
series->setVisible(visible);
// tell selector we hid/show a series so it can respond.
selector->setSeriesVisible(name, visible);
}
}
bool
GenericPlot::initialiseChart(QString title, int type, bool animate)
{