3 #include <QStackedLayout>
6 #pragma GCC diagnostic push
7 #pragma GCC diagnostic ignored "-Wpedantic"
8 #include <qwt_legend.h>
9 #include <qwt_legend_label.h>
10 #include <qwt_plot_canvas.h>
11 #include <qwt_plot_magnifier.h>
12 #include <qwt_plot_panner.h>
13 #include <qwt_series_data.h>
14 #pragma GCC diagnostic pop
24 plotter =
new QwtPlot(ui.plotWidget);
25 QStackedLayout* stackedLayout =
new QStackedLayout(ui.plotWidget);
26 stackedLayout->addWidget(plotter);
31 (void)
new QwtPlotPanner(plotter->canvas());
34 new QwtPlotMagnifier(plotter->canvas());
38 QwtLegend* legend =
new QwtLegend;
39 legend->setDefaultItemMode(QwtLegendData::Mode::Checkable);
40 plotter->insertLegend(legend, QwtPlot::BottomLegend);
43 plotter->setAxisTitle(QwtPlot::xBottom,
"Time (in sec)");
44 plotter->enableAxis(QwtPlot::yLeft,
true);
47 plotter->setAxisAutoScale(QwtPlot::yLeft,
true);
48 plotter->setAxisAutoScale(QwtPlot::xBottom,
true);
49 plotter->setAutoReplot();
54 SIGNAL(legendChecked(QwtPlotItem*,
bool)),
59 connect(ui.listWidgetPlots,
60 SIGNAL(currentTextChanged(QString)),
102 item->setVisible(on);
103 QwtLegend* lgd = qobject_cast<QwtLegend*>(plotter->legend());
105 QList<QWidget*> legendWidgets = lgd->legendWidgets(plotter->itemToInfo(item));
107 if (legendWidgets.size() == 1)
109 QwtLegendLabel* legendLabel = qobject_cast<QwtLegendLabel*>(legendWidgets[0]);
113 legendLabel->setChecked(on);
122 ui.listWidgetPlots->clear();
123 plotter->detachItems();
125 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 &&
137 ui.listWidgetPlots->currentItem()->text() == plotName)
146 if (plotName.isEmpty())
150 std::unique_lock lock(dataMutex);
151 auto it = plotsMap.find(plotName);
152 if (it == plotsMap.end())
154 ARMARX_INFO <<
"Did not find plot with name " << plotName;
158 plotter->detachItems();
160 for (
auto& elem : it->second)
162 Vector2fSeq points = elem.second;
163 QVector<QPointF> pointList;
164 pointList.reserve(points.size());
166 for (Vector2f& point : points)
168 pointList.push_back({point.e0, point.e1});
170 QwtSeriesData<QPointF>* pointSeries =
new QwtPointSeriesData(pointList);
171 QwtPlotCurve* curve = createCurve(QString::fromStdString(elem.first),
172 QColor(Qt::GlobalColor(i % 15 + 7)));
173 curve->setData(pointSeries);
174 curve->attach(plotter);
193 const StringVector2fSeqDict& plotsData,
198 QString qplotName = QString::fromStdString(plotName);
200 std::unique_lock lock(dataMutex);
201 plotsMap[qplotName] = plotsData;
208 const Ice::FloatSeq& timestamps,
209 const StringFloatSeqDict& plotsData,
210 const Ice::Current&
c)
212 StringVector2fSeqDict plotsDataMap;
213 for (
auto& elem : plotsData)
217 for (
size_t i = 0; i < timestamps.size(); ++i)
219 data.push_back({timestamps.at(i), elem.second.at(i)});
221 plotsDataMap[elem.first] =
data;
227 StaticPlotterWidgetController::createCurve(
const QString& label, QColor color)
229 QwtPlotCurve* curve =
new QwtPlotCurve(label);
230 curve->setRenderHint(QwtPlotItem::RenderAntialiased);
231 curve->setPen(color);
232 curve->setStyle(QwtPlotCurve::Lines);
233 curve->setPaintAttribute(QwtPlotCurve::ClipPolygons,
true);
244 if (parent != customToolbar->parent())
246 customToolbar->setParent(parent);
249 return customToolbar;
252 customToolbar =
new QToolBar(parent);
253 customToolbar->setIconSize(QSize(16, 16));
254 customToolbar->addAction(
255 QIcon(
":/icons/Trash.svg"),
"Delete Plots",
this, SLOT(
clearPlots()));
257 return customToolbar;