mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
Merge branch 'thread/OP-1611_Scopes_Context_Menu' into next
This commit is contained in:
commit
1f9bdc308b
@ -93,6 +93,23 @@ void PlotData::updatePlotData()
|
||||
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
|
||||
}
|
||||
|
||||
void PlotData::clear()
|
||||
{
|
||||
m_meanSum = 0.0f;
|
||||
m_correctionSum = 0.0f;
|
||||
m_correctionCount = 0;
|
||||
m_xDataEntries.clear();
|
||||
m_yDataEntries.clear();
|
||||
while (!m_enumMarkerList.isEmpty()) {
|
||||
QwtPlotMarker *marker = m_enumMarkerList.takeFirst();
|
||||
marker->detach();
|
||||
delete marker;
|
||||
}
|
||||
if (wantsInitialData()) {
|
||||
append(m_object);
|
||||
}
|
||||
}
|
||||
|
||||
bool PlotData::hasData() const
|
||||
{
|
||||
if (!m_isEnumPlot) {
|
||||
@ -184,6 +201,10 @@ QwtPlotMarker *PlotData::createMarker(QString value)
|
||||
|
||||
bool SequentialPlotData::append(UAVObject *obj)
|
||||
{
|
||||
if (obj == NULL) {
|
||||
obj = m_object;
|
||||
}
|
||||
|
||||
if (m_object == obj && m_field) {
|
||||
if (!m_isEnumPlot) {
|
||||
double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower);
|
||||
@ -224,6 +245,10 @@ bool SequentialPlotData::append(UAVObject *obj)
|
||||
|
||||
bool ChronoPlotData::append(UAVObject *obj)
|
||||
{
|
||||
if (obj == NULL) {
|
||||
obj = m_object;
|
||||
}
|
||||
|
||||
if (m_object == obj && m_field) {
|
||||
// Get the field of interest
|
||||
// THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
|
||||
|
@ -93,6 +93,7 @@ public:
|
||||
virtual void removeStaleData() = 0;
|
||||
|
||||
void updatePlotData();
|
||||
void clear();
|
||||
|
||||
bool hasData() const;
|
||||
QString lastDataAsString();
|
||||
|
@ -47,6 +47,7 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
|
||||
ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration *>(config);
|
||||
ScopeGadgetWidget *widget = qobject_cast<ScopeGadgetWidget *>(m_widget);
|
||||
|
||||
widget->setObjectName(config->name());
|
||||
widget->setPlotDataSize(sgConfig->dataSize());
|
||||
widget->setRefreshInterval(sgConfig->refreshInterval());
|
||||
|
||||
|
@ -50,7 +50,6 @@ void ScopeGadgetFactory::startPlotting()
|
||||
emit onStartPlotting();
|
||||
}
|
||||
|
||||
|
||||
Core::IUAVGadget *ScopeGadgetFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
ScopeGadgetWidget *gadgetWidget = new ScopeGadgetWidget(parent);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "uavobject.h"
|
||||
#include "coreplugin/icore.h"
|
||||
#include "coreplugin/connectionmanager.h"
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include "qwt/src/qwt_plot_curve.h"
|
||||
#include "qwt/src/qwt_plot_grid.h"
|
||||
@ -48,6 +49,10 @@
|
||||
#include <QPushButton>
|
||||
#include <QMutexLocker>
|
||||
#include <QWheelEvent>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QClipboard>
|
||||
#include <QApplication>
|
||||
|
||||
#include <qwt/src/qwt_legend_label.h>
|
||||
#include <qwt/src/qwt_plot_canvas.h>
|
||||
@ -88,6 +93,9 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent),
|
||||
// Listen to autopilot connection events
|
||||
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(csvLoggingDisconnect()));
|
||||
connect(cm, SIGNAL(deviceConnected(QIODevice *)), this, SLOT(csvLoggingConnect()));
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popUpMenu(const QPoint &)));
|
||||
}
|
||||
|
||||
ScopeGadgetWidget::~ScopeGadgetWidget()
|
||||
@ -187,6 +195,11 @@ void ScopeGadgetWidget::showEvent(QShowEvent *e)
|
||||
void ScopeGadgetWidget::startPlotting()
|
||||
{
|
||||
if (replotTimer && !replotTimer->isActive()) {
|
||||
foreach(PlotData * plot, m_curvesData.values()) {
|
||||
if (plot->wantsInitialData()) {
|
||||
plot->append(NULL);
|
||||
}
|
||||
}
|
||||
replotTimer->start(m_refreshInterval);
|
||||
}
|
||||
}
|
||||
@ -370,10 +383,6 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
connect(this, SIGNAL(visibilityChanged(QwtPlotItem *)), plotData, SLOT(visibilityChanged(QwtPlotItem *)));
|
||||
plotData->attach(this);
|
||||
|
||||
if (plotData->wantsInitialData()) {
|
||||
plotData->append(object);
|
||||
}
|
||||
|
||||
// Keep the curve details for later
|
||||
m_curvesData.insert(plotData->plotName(), plotData);
|
||||
|
||||
@ -624,3 +633,45 @@ void ScopeGadgetWidget::csvLoggingDisconnect()
|
||||
csvLoggingStop();
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::popUpMenu(const QPoint &mousePosition)
|
||||
{
|
||||
Q_UNUSED(mousePosition);
|
||||
|
||||
QMenu menu;
|
||||
QAction *action = menu.addAction(tr("Clear"));
|
||||
connect(action, &QAction::triggered, this, &ScopeGadgetWidget::clearPlot);
|
||||
action = menu.addAction(tr("Copy to Clipboard"));
|
||||
connect(action, &QAction::triggered, this, &ScopeGadgetWidget::copyToClipboardAsImage);
|
||||
menu.addSeparator();
|
||||
action = menu.addAction(tr("Options..."));
|
||||
connect(action, &QAction::triggered, this, &ScopeGadgetWidget::showOptionDialog);
|
||||
menu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::clearPlot()
|
||||
{
|
||||
m_mutex.lock();
|
||||
foreach(PlotData * plot, m_curvesData.values()) {
|
||||
plot->clear();
|
||||
}
|
||||
m_mutex.unlock();
|
||||
replot();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::copyToClipboardAsImage()
|
||||
{
|
||||
QPixmap pixmap = QWidget::grab();
|
||||
|
||||
if (pixmap.isNull()) {
|
||||
qDebug("Failed to capture the plot");
|
||||
return;
|
||||
}
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setPixmap(pixmap);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::showOptionDialog()
|
||||
{
|
||||
Core::ICore::instance()->showOptionsDialog("ScopeGadget", objectName());
|
||||
}
|
||||
|
@ -137,6 +137,10 @@ private slots:
|
||||
void stopPlotting();
|
||||
void csvLoggingConnect();
|
||||
void csvLoggingDisconnect();
|
||||
void popUpMenu(const QPoint &mousePosition);
|
||||
void clearPlot();
|
||||
void copyToClipboardAsImage();
|
||||
void showOptionDialog();
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user