plotview: Context menu for adding plots

This commit is contained in:
Mike Walters
2016-04-16 20:26:44 +01:00
parent 26de4b4990
commit f51921491c
2 changed files with 23 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
#include "plotview.h"
#include <QApplication>
#include <QDebug>
#include <QMenu>
#include <QPainter>
#include <QScrollBar>
#include "plots.h"
@@ -48,6 +49,27 @@ void PlotView::addPlot(Plot *plot)
connect(plot, &Plot::repaint, this, &PlotView::repaint);
}
void PlotView::contextMenuEvent(QContextMenuEvent * event)
{
QMenu menu;
// TODO: get the selected plot
auto src = plots[0]->output();
auto compatiblePlots = as_range(Plots::plots.equal_range(src->sampleType()));
for (auto p : compatiblePlots) {
auto action = new QAction("Add plot", &menu);
auto plotCreator = p.second;
connect(
action, &QAction::triggered,
this, [=]() {
addPlot(plotCreator(src));
}
);
menu.addAction(action);
}
if (menu.exec(event->globalPos()))
updateView(false);
}
void PlotView::cursorsMoved()
{
selectedSamples = {