Skip to content

Commit 885a8c9

Browse files
committed
Double-click plot legend = hide all except one
1 parent 663d585 commit 885a8c9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/subprojects/AutoEqIntegration/AeqPreviewPlot.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ AeqPreviewPlot::AeqPreviewPlot(QWidget* parent) : QCustomPlot(parent)
3838
connect(this, &QCustomPlot::customContextMenuRequested, this, &AeqPreviewPlot::onContextMenuRequest);
3939
connect(this, &QCustomPlot::mouseMove, this, &AeqPreviewPlot::onHover);
4040
connect(this, &QCustomPlot::legendClick, this, &AeqPreviewPlot::onLegendClick);
41+
connect(this, &QCustomPlot::legendDoubleClick, this, &AeqPreviewPlot::onLegendDoubleClick);
4142

4243
}
4344

@@ -244,3 +245,28 @@ void AeqPreviewPlot::onLegendClick(QCPLegend *legend, QCPAbstractLegendItem *ite
244245
replot();
245246
}
246247
}
248+
249+
void AeqPreviewPlot::onLegendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event)
250+
{
251+
Q_UNUSED(event)
252+
253+
if (item)
254+
{
255+
QCPPlottableLegendItem *plItem = qobject_cast<QCPPlottableLegendItem*>(item);
256+
for(int i = 0; i < legend->itemCount(); i++)
257+
{
258+
auto it = qobject_cast<QCPPlottableLegendItem*>(legend->item(i));
259+
if(it && it == plItem)
260+
{
261+
it->plottable()->setVisible(true);
262+
it->setTextColor(QColor(Qt::black));
263+
}
264+
else if(it && it != plItem)
265+
{
266+
it->plottable()->setVisible(false);
267+
it->setTextColor(QColor(Qt::gray));
268+
}
269+
}
270+
replot();
271+
}
272+
}

src/subprojects/AutoEqIntegration/AeqPreviewPlot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private slots:
1717
void onContextMenuRequest(QPoint pos);
1818
void moveLegend();
1919
void onLegendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
20+
void onLegendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
2021
private:
2122
bool useGraphicEq = false;
2223

0 commit comments

Comments
 (0)