6 #include <QStackedLayout>
7 #pragma GCC diagnostic push
8 #pragma GCC diagnostic ignored "-Wpedantic"
9 #include <qwt_legend.h>
10 #include <qwt_plot_magnifier.h>
11 #include <qwt_plot_panner.h>
12 #include <qwt_series_data.h>
13 #include <qwt_plot_canvas.h>
14 #include <qwt_legend_label.h>
15 #pragma GCC diagnostic pop
22 customToolbar(nullptr)
26 plotter =
new QwtPlot(ui.plotWidget);
27 QStackedLayout* stackedLayout =
new QStackedLayout(ui.plotWidget);
28 stackedLayout->addWidget(plotter);
33 (void)
new QwtPlotPanner(plotter->canvas());
36 new QwtPlotMagnifier(plotter->canvas());
40 QwtLegend* legend =
new QwtLegend;
41 legend->setDefaultItemMode(QwtLegendData::Mode::Checkable);
42 plotter->insertLegend(legend, QwtPlot::BottomLegend);
45 plotter->setAxisTitle(QwtPlot::xBottom,
"Time (in sec)");
46 plotter->enableAxis(QwtPlot::yLeft,
true);
49 plotter->setAxisAutoScale(QwtPlot::yLeft,
true);
50 plotter->setAxisAutoScale(QwtPlot::xBottom,
true);
51 plotter->setAutoReplot();
55 connect(plotter, SIGNAL(legendChecked(QwtPlotItem*,
bool)),
62 connect(ui.listWidgetPlots, SIGNAL(currentTextChanged(QString)),
102 item->setVisible(on);
103 QwtLegend* lgd = qobject_cast<QwtLegend*>(plotter->legend());
105 QList<QWidget*> legendWidgets =
106 lgd->legendWidgets(plotter->itemToInfo(item));
108 if (legendWidgets.size() == 1)
110 QwtLegendLabel* legendLabel =
111 qobject_cast<QwtLegendLabel*>(legendWidgets[0]);
115 legendLabel->setChecked(on);
123 ui.listWidgetPlots->clear();
124 plotter->detachItems();
126 std::unique_lock lock(dataMutex);
132 if (ui.listWidgetPlots->findItems(plotName, Qt::MatchExactly).isEmpty())
134 ui.listWidgetPlots->addItem(plotName);
136 else if (ui.listWidgetPlots->currentItem() != NULL && ui.listWidgetPlots->currentItem()->text() == plotName)
144 if (plotName.isEmpty())
148 std::unique_lock lock(dataMutex);
149 auto it = plotsMap.find(plotName);
150 if (it == plotsMap.end())
152 ARMARX_INFO <<
"Did not find plot with name " << plotName;
156 plotter->detachItems();
158 for (
auto& elem : it->second)
160 Vector2fSeq points = elem.second;
161 QVector<QPointF> pointList;
162 pointList.reserve(points.size());
164 for (Vector2f& point : points)
166 pointList.push_back({point.e0, point.e1});
168 QwtSeriesData<QPointF>* pointSeries =
new QwtPointSeriesData(pointList);
169 QwtPlotCurve* curve = createCurve(QString::fromStdString(elem.first), QColor(Qt::GlobalColor(i % 15 + 7)));
170 curve->setData(pointSeries);
171 curve->attach(plotter);
194 QString qplotName = QString::fromStdString(plotName);
196 std::unique_lock lock(dataMutex);
197 plotsMap[qplotName] = plotsData;
206 StringVector2fSeqDict plotsDataMap;
207 for (
auto& elem : plotsData)
211 for (
size_t i = 0; i < timestamps.size(); ++i)
213 data.push_back({timestamps.at(i), elem.second.at(i)});
215 plotsDataMap[elem.first] =
data;
221 QwtPlotCurve* StaticPlotterWidgetController::createCurve(
const QString& label, QColor color)
223 QwtPlotCurve* curve =
new QwtPlotCurve(label);
224 curve->setRenderHint(QwtPlotItem::RenderAntialiased);
225 curve->setPen(color);
226 curve->setStyle(QwtPlotCurve::Lines);
227 curve->setPaintAttribute(QwtPlotCurve::ClipPolygons,
true);
238 if (parent != customToolbar->parent())
240 customToolbar->setParent(parent);
243 return customToolbar;
246 customToolbar =
new QToolBar(parent);
247 customToolbar->setIconSize(QSize(16, 16));
248 customToolbar->addAction(QIcon(
":/icons/Trash.svg"),
"Delete Plots",
this, SLOT(
clearPlots()));
250 return customToolbar;