diff --git a/tools/cabana/chartswidget.cc b/tools/cabana/chartswidget.cc
index 34498364c6..845649dfc1 100644
--- a/tools/cabana/chartswidget.cc
+++ b/tools/cabana/chartswidget.cc
@@ -317,6 +317,9 @@ ChartView::ChartView(QWidget *parent) : QChartView(nullptr, parent) {
background->setPen(Qt::NoPen);
background->setZValue(chart->zValue() - 1);
+ move_icon = new QGraphicsPixmapItem(utils::icon("grip-horizontal"), chart);
+ move_icon->setToolTip(tr("Drag and drop to combine charts"));
+
QToolButton *remove_btn = new QToolButton();
remove_btn->setIcon(utils::icon("x"));
remove_btn->setAutoRaise(true);
@@ -460,6 +463,7 @@ void ChartView::resizeEvent(QResizeEvent *event) {
int x = event->size().width() - close_btn_proxy->size().width() - 11;
close_btn_proxy->setPos(x, 8);
manage_btn_proxy->setPos(x - manage_btn_proxy->size().width() - 5, 8);
+ move_icon->setPos(11, 8);
}
void ChartView::updatePlotArea(int left) {
@@ -472,8 +476,12 @@ void ChartView::updatePlotArea(int left) {
}
void ChartView::updateTitle() {
+ for (QLegendMarker *marker : chart()->legend()->markers()) {
+ QObject::connect(marker, &QLegendMarker::clicked, this, &ChartView::handleMarkerClicked, Qt::UniqueConnection);
+ }
for (auto &s : sigs) {
- s.series->setName(QString("%1 %2 %3").arg(s.sig->name.c_str()).arg(msgName(s.msg_id)).arg(s.msg_id));
+ auto decoration = s.series->isVisible() ? "none" : "line-through";
+ s.series->setName(QString("%2%3 %4").arg(decoration).arg(s.sig->name.c_str()).arg(msgName(s.msg_id)).arg(s.msg_id));
}
}
@@ -578,6 +586,8 @@ void ChartView::updateAxisY() {
double min = std::numeric_limits::max();
double max = std::numeric_limits::lowest();
for (auto &s : sigs) {
+ if (!s.series->isVisible()) continue;
+
auto first = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->min(), [](auto &p, double x) { return p.x() < x; });
auto last = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->max(), [](auto &p, double x) { return p.x() < x; });
for (auto it = first; it != last; ++it) {
@@ -634,8 +644,7 @@ void ChartView::leaveEvent(QEvent *event) {
}
void ChartView::mousePressEvent(QMouseEvent *event) {
- if (event->button() == Qt::LeftButton && !chart()->plotArea().contains(event->pos()) &&
- !manage_btn_proxy->geometry().contains(event->pos()) && !close_btn_proxy->geometry().contains(event->pos())) {
+ if (event->button() == Qt::LeftButton && move_icon->sceneBoundingRect().contains(event->pos())) {
QMimeData *mimeData = new QMimeData;
mimeData->setData(mime_type, QByteArray::number((qulonglong)this));
QDrag *drag = new QDrag(this);
@@ -810,6 +819,18 @@ void ChartView::setSeriesType(QAbstractSeries::SeriesType type) {
}
}
+void ChartView::handleMarkerClicked() {
+ auto marker = qobject_cast(sender());
+ Q_ASSERT(marker);
+ if (sigs.size() > 1) {
+ auto series = marker->series();
+ series->setVisible(!series->isVisible());
+ marker->setVisible(true);
+ updateAxisY();
+ updateTitle();
+ }
+}
+
// SeriesSelector
SeriesSelector::SeriesSelector(QWidget *parent) {
diff --git a/tools/cabana/chartswidget.h b/tools/cabana/chartswidget.h
index f0f9e5cd9c..77f04534a4 100644
--- a/tools/cabana/chartswidget.h
+++ b/tools/cabana/chartswidget.h
@@ -5,9 +5,11 @@
#include
#include
#include
+#include
#include
#include
#include
+#include
#include
#include
#include
@@ -56,6 +58,7 @@ private slots:
void signalUpdated(const Signal *sig);
void signalRemoved(const Signal *sig);
void manageSeries();
+ void handleMarkerClicked();
private:
QList::iterator removeItem(const QList::iterator &it);
@@ -80,6 +83,7 @@ private:
QValueAxis *axis_x;
QValueAxis *axis_y;
QVector track_pts;
+ QGraphicsPixmapItem *move_icon;
QGraphicsProxyWidget *close_btn_proxy;
QGraphicsProxyWidget *manage_btn_proxy;
QGraphicsRectItem *background;