47 #include "qwt/src/qwt_legend.h"
48 #include "qwt/src/qwt_legend_label.h"
49 #include "qwt/src/qwt_scale_widget.h"
55 #include <QStringList>
57 #include <QVBoxLayout>
58 #include <QPushButton>
59 #include <QWheelEvent>
63 #include <QApplication>
65 QTimer *ScopeGadgetWidget::replotTimer =
nullptr;
69 , m_refreshInterval(50)
76 setMouseTracking(
true);
80 if (replotTimer == NULL)
81 replotTimer =
new QTimer();
82 connect(replotTimer, &QTimer::timeout,
this, &ScopeGadgetWidget::replotNewData);
89 &ScopeGadgetWidget::stopPlotting);
92 setContextMenuPolicy(Qt::CustomContextMenu);
93 connect(
this, &QWidget::customContextMenuRequested,
this, &ScopeGadgetWidget::popUpMenu);
104 foreach (QString uavObjName, m_connectedUAVObjects) {
115 void ScopeGadgetWidget::popUpMenu(
const QPoint &mousePosition)
117 Q_UNUSED(mousePosition);
120 QAction *action = menu.addAction(tr(
"Clear"));
123 connect(action, &QAction::triggered,
this, &ScopeGadgetWidget::clearPlot);
124 action = menu.addAction(tr(
"Copy to Clipboard"));
127 connect(action, &QAction::triggered,
this, &ScopeGadgetWidget::copyToClipboardAsImage);
131 action = menu.addAction(tr(
"Options..."));
132 connect(action, &QAction::triggered,
this, &ScopeGadgetWidget::showOptionDialog);
135 menu.exec(QCursor::pos());
141 void ScopeGadgetWidget::clearPlot()
145 foreach (
PlotData *plotData, m_dataSources.values()) {
154 void ScopeGadgetWidget::copyToClipboardAsImage()
156 QPixmap pixmap = QWidget::grab();
157 if (pixmap.isNull()) {
158 qDebug(
"Failed to capture the plot");
161 QClipboard *clipboard = QApplication::clipboard();
162 clipboard->setPixmap(pixmap);
168 void ScopeGadgetWidget::showOptionDialog()
180 QwtPlot::mousePressEvent(e);
189 QwtPlot::mouseReleaseEvent(e);
206 setAxisAutoScale(QwtPlot::yLeft,
true);
210 QwtPlot::mouseDoubleClickEvent(e);
219 QwtPlot::mouseMoveEvent(e);
229 QwtInterval yInterval = axisInterval(QwtPlot::yLeft);
230 if (yInterval.minValue() != yInterval.maxValue())
237 QPoint mouse_pos = e->pos();
238 double zoomLine = invTransform(
239 QwtPlot::yLeft, mouse_pos.y());
241 double zoomScale = 1.1;
245 if (e->delta() < 0) {
246 setAxisScale(QwtPlot::yLeft, (yInterval.minValue() - zoomLine) * zoomScale + zoomLine,
247 (yInterval.maxValue() - zoomLine) * zoomScale + zoomLine);
249 setAxisScale(QwtPlot::yLeft, (yInterval.minValue() - zoomLine) / zoomScale + zoomLine,
250 (yInterval.maxValue() - zoomLine) / zoomScale + zoomLine);
253 QwtPlot::wheelEvent(e);
259 void ScopeGadgetWidget::startPlotting()
264 if (!replotTimer->isActive())
265 replotTimer->start(m_refreshInterval);
271 void ScopeGadgetWidget::stopPlotting()
289 insertLegend(NULL, QwtPlot::TopLegend);
302 m_legend->setDefaultItemMode(QwtLegendData::Checkable);
303 m_legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
304 m_legend->setToolTip(tr(
"Click legend to show/hide scope trace"));
307 pal.setColor(
m_legend->backgroundRole(), QColor(100, 100, 100));
308 pal.setColor(QPalette::Text, QColor(0, 0, 0));
311 insertLegend(
m_legend, QwtPlot::TopLegend);
316 foreach (QwtPlotItem *item, this->itemList()) {
317 bool on = item->isVisible();
318 QVariant itemInfo = QwtPlot::itemToInfo(item);
319 QWidget *w =
m_legend->legendWidget(itemInfo);
320 if (w && w->inherits(
"QwtLegendLabel"))
321 (dynamic_cast<QwtLegendLabel *>(w))->setChecked(!on);
324 connect(
m_legend, &QwtLegend::checked,
this, &ScopeGadgetWidget::showCurve);
332 void ScopeGadgetWidget::showCurve(
const QVariant &itemInfo,
bool on,
int index)
335 QwtPlotItem *item = QwtPlot::infoToItem(itemInfo);
337 item->setVisible(!on);
346 void ScopeGadgetWidget::uavObjectReceived(
UAVObject *obj)
348 foreach (
PlotData *plotdData, m_dataSources.values()) {
349 bool ret = plotdData->
append(obj);
358 void ScopeGadgetWidget::replotNewData()
361 if (!isVisible() || m_scope == NULL)
365 foreach (
PlotData *plotData, m_dataSources.values()) {
383 foreach (
PlotData *plotData, m_dataSources.values()) {
388 m_dataSources.clear();
405 qDebug() <<
"In scope gadget, UAVObject " << uavObjectName <<
" is missing";
410 qDebug() <<
"In scope gadget, in fields loaded from GCS config file, field"
411 << uavObjectFieldName <<
" of UAVObject " << uavObjectName <<
" is missing";
417 if (units ==
nullptr)
430 QwtPlot::showEvent(event);
441 if (!m_connectedUAVObjects.contains(obj->
getName())) {
442 m_connectedUAVObjects.append(obj->
getName());
453 m_refreshInterval = refreshInterval;
458 if (!replotTimer->isActive())
459 replotTimer->start(refreshInterval);
461 replotTimer->setInterval(refreshInterval);
virtual bool append(UAVObject *obj)=0
void mouseDoubleClickEvent(QMouseEvent *e)
ScopeGadgetWidget::mouseDoubleClickEvent Turn legend on and off, then pass double-click even to QwtPl...
void connectUAVO(UAVDataObject *obj)
ScopeGadgetWidget::connectUAVO Connects UAVO update signal, but only if it hasn't yet been connected...
QIODevice * getCurrentConnection()
~ScopeGadgetWidget()
ScopeGadgetWidget::~ScopeGadgetWidget Destructor.
virtual void plotNewData(PlotData *, ScopeConfig *, ScopeGadgetWidget *)=0
Core plugin system that manages the plugins, their life cycle and their registered objects...
void deleteLegend()
ScopeGadgetWidget::deleteLegend Delete legend from plot.
virtual ConnectionManager * connectionManager() const =0
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
void wheelEvent(QWheelEvent *e)
ScopeGadgetWidget::wheelEvent Zoom in or out, then pass mouse wheel event to QwtPlot.
void addLegend()
ScopeGadgetWidget::addLegend Add legend to plot.
ScopeGadgetWidget(QWidget *parent=nullptr)
virtual bool showOptionsDialog(const QString &group=QString(), const QString &page=QString(), QWidget *parent=nullptr)=0
Opens the application options/preferences dialog with preselected page in a specified group...
void mouseReleaseEvent(QMouseEvent *e)
ScopeGadgetWidget::mouseReleaseEvent Pass mouse release event to QwtPlot.
virtual void setUpdatedFlagToTrue()=0
static ICore * instance()
QString getUavObjectFieldUnits(QString uavObjectName, QString uavObjectFieldName)
ScopeGadgetWidget::getUavObjectFieldUnits Gets the UAVOs units, as defined in the XML...
virtual void clearPlots()=0
void clearPlotWidget()
ScopeGadgetWidget::clearPlotWidget.
void startTimer(int)
ScopeGadgetWidget::startTimer Starts timer.
void deviceAboutToDisconnect()
void mousePressEvent(QMouseEvent *e)
ScopeGadgetWidget::mousePressEvent Pass mouse press event to QwtPlot.
void deviceConnected(QIODevice *device)
UAVObject * getObject(const QString &name, quint32 instId=0)
void showEvent(QShowEvent *event)
ScopeGadgetWidget::showEvent Reimplemented from QwtPlot.
virtual void deletePlots(PlotData *)=0
void mouseMoveEvent(QMouseEvent *e)
ScopeGadgetWidget::mouseMoveEvent Pass mouse move event to QwtPlot.