mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-31 16:52:10 +01:00
LP-29 Added terrain related options to PFD
Started turning PFD into a generic qml viewer (replaces ModelView) Note that PFD has one remaining dependency with osgearth lib but that is temporary
This commit is contained in:
parent
882c3d54b1
commit
396b91ffad
BIN
ground/gcs/src/plugins/pfdqml/fonts/PTN77F.ttf
Normal file
BIN
ground/gcs/src/plugins/pfdqml/fonts/PTN77F.ttf
Normal file
Binary file not shown.
@ -1,376 +0,0 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "osgearth.h"
|
||||
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include <QtCore/qthread.h>
|
||||
#include <QtDeclarative/qdeclarative.h>
|
||||
#include <QtDeclarative/qdeclarativeview.h>
|
||||
#include <QtDeclarative/qdeclarativeengine.h>
|
||||
#include <qpainter.h>
|
||||
#include <qvector3d.h>
|
||||
#include <QtOpenGL/qglframebufferobject.h>
|
||||
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/AutoTransform>
|
||||
#include <osg/Camera>
|
||||
#include <osg/TexMat>
|
||||
#include <osg/TextureRectangle>
|
||||
#include <osg/Texture2D>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgEarthUtil/EarthManipulator>
|
||||
#include <osgEarthUtil/ObjectPlacer>
|
||||
#include <osgEarth/Map>
|
||||
|
||||
#include <QtCore/qtimer.h>
|
||||
|
||||
#include "utils/pathutils.h"
|
||||
|
||||
OsgEarthItem::OsgEarthItem(QDeclarativeItem *parent) :
|
||||
QDeclarativeItem(parent),
|
||||
m_renderer(0),
|
||||
m_rendererThread(0),
|
||||
m_currentSize(640, 480),
|
||||
m_roll(0.0),
|
||||
m_pitch(0.0),
|
||||
m_yaw(0.0),
|
||||
m_latitude(-28.5),
|
||||
m_longitude(153.0),
|
||||
m_altitude(400.0),
|
||||
m_fieldOfView(90.0),
|
||||
m_sceneFile(QLatin1String("/usr/share/osgearth/maps/srtm.earth"))
|
||||
{
|
||||
setSize(m_currentSize);
|
||||
setFlag(ItemHasNoContents, false);
|
||||
}
|
||||
|
||||
OsgEarthItem::~OsgEarthItem()
|
||||
{
|
||||
if (m_renderer) {
|
||||
m_rendererThread->exit();
|
||||
// wait up to 10 seconds for renderer thread to exit
|
||||
m_rendererThread->wait(10 * 1000);
|
||||
|
||||
delete m_renderer;
|
||||
delete m_rendererThread;
|
||||
}
|
||||
}
|
||||
|
||||
QString OsgEarthItem::resolvedSceneFile() const
|
||||
{
|
||||
QString sceneFile = m_sceneFile;
|
||||
|
||||
// try to resolve the relative scene file name:
|
||||
if (!QFileInfo(sceneFile).exists()) {
|
||||
QDeclarativeView *view = qobject_cast<QDeclarativeView *>(scene()->views().first());
|
||||
|
||||
if (view) {
|
||||
QUrl baseUrl = view->engine()->baseUrl();
|
||||
sceneFile = baseUrl.resolved(sceneFile).toLocalFile();
|
||||
}
|
||||
}
|
||||
|
||||
return sceneFile;
|
||||
}
|
||||
|
||||
void OsgEarthItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
{
|
||||
Q_UNUSED(oldGeometry);
|
||||
Q_UNUSED(newGeometry);
|
||||
|
||||
// Dynamic gyometry changes are not supported yet,
|
||||
// terrain is rendered to fixed geompetry and scalled for now
|
||||
|
||||
/*
|
||||
qDebug() << Q_FUNC_INFO << newGeometry;
|
||||
|
||||
int w = qRound(newGeometry.width());
|
||||
int h = qRound(newGeometry.height());
|
||||
|
||||
if (m_currentSize != QSize(w,h) && m_gw.get()) {
|
||||
m_currentSize = QSize(w,h);
|
||||
|
||||
m_gw->getEventQueue()->windowResize(0,0,w,h);
|
||||
m_gw->resized(0,0,w,h);
|
||||
|
||||
osg::Camera *camera = m_viewer->getCamera();
|
||||
camera->setViewport(new osg::Viewport(0,0,w,h));
|
||||
camera->setProjectionMatrixAsPerspective(m_fieldOfView, qreal(w)/h, 1.0f, 10000.0f);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void OsgEarthItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(painter);
|
||||
Q_UNUSED(style);
|
||||
QGLWidget *glWidget = qobject_cast<QGLWidget *>(widget);
|
||||
|
||||
if (!m_renderer) {
|
||||
m_renderer = new OsgEarthItemRenderer(this, glWidget);
|
||||
connect(m_renderer, SIGNAL(frameReady()),
|
||||
this, SLOT(updateView()), Qt::QueuedConnection);
|
||||
|
||||
m_rendererThread = new QThread(this);
|
||||
m_renderer->moveToThread(m_rendererThread);
|
||||
m_rendererThread->start();
|
||||
|
||||
QMetaObject::invokeMethod(m_renderer, "initScene", Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
QGLFramebufferObject *fbo = m_renderer->lastFrame();
|
||||
|
||||
if (glWidget && fbo) {
|
||||
glWidget->drawTexture(boundingRect(), fbo->texture());
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::updateView()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void OsgEarthItem::updateFrame()
|
||||
{
|
||||
if (m_renderer) {
|
||||
m_renderer->markDirty();
|
||||
QMetaObject::invokeMethod(m_renderer, "updateFrame", Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setRoll(qreal arg)
|
||||
{
|
||||
if (!qFuzzyCompare(m_roll, arg)) {
|
||||
m_roll = arg;
|
||||
updateFrame();
|
||||
emit rollChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setPitch(qreal arg)
|
||||
{
|
||||
if (!qFuzzyCompare(m_pitch, arg)) {
|
||||
m_pitch = arg;
|
||||
updateFrame();
|
||||
emit pitchChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setYaw(qreal arg)
|
||||
{
|
||||
if (!qFuzzyCompare(m_yaw, arg)) {
|
||||
m_yaw = arg;
|
||||
updateFrame();
|
||||
emit yawChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setLatitude(double arg)
|
||||
{
|
||||
// not sure qFuzzyCompare is accurate enough for geo coordinates
|
||||
if (m_latitude != arg) {
|
||||
m_latitude = arg;
|
||||
emit latitudeChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setLongitude(double arg)
|
||||
{
|
||||
if (m_longitude != arg) {
|
||||
m_longitude = arg;
|
||||
emit longitudeChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setAltitude(double arg)
|
||||
{
|
||||
if (!qFuzzyCompare(m_altitude, arg)) {
|
||||
m_altitude = arg;
|
||||
emit altitudeChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
// ! Camera vertical field of view in degrees
|
||||
void OsgEarthItem::setFieldOfView(qreal arg)
|
||||
{
|
||||
if (!qFuzzyCompare(m_fieldOfView, arg)) {
|
||||
m_fieldOfView = arg;
|
||||
emit fieldOfViewChanged(arg);
|
||||
|
||||
// it should be a queued call to OsgEarthItemRenderer instead
|
||||
/*if (m_viewer.get()) {
|
||||
m_viewer->getCamera()->setProjectionMatrixAsPerspective(
|
||||
m_fieldOfView,
|
||||
qreal(m_currentSize.width())/m_currentSize.height(),
|
||||
1.0f, 10000.0f);
|
||||
}*/
|
||||
|
||||
updateFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void OsgEarthItem::setSceneFile(QString arg)
|
||||
{
|
||||
if (m_sceneFile != arg) {
|
||||
m_sceneFile = arg;
|
||||
emit sceneFileChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
OsgEarthItemRenderer::OsgEarthItemRenderer(OsgEarthItem *item, QGLWidget *glWidget) :
|
||||
QObject(0),
|
||||
m_item(item),
|
||||
m_lastFboNumber(0),
|
||||
m_currentSize(640, 480),
|
||||
m_cameraDirty(false)
|
||||
{
|
||||
// make a shared gl widget to avoid
|
||||
// osg rendering to mess with qpainter state
|
||||
// this runs in the main thread
|
||||
m_glWidget = new QGLWidget(0, glWidget);
|
||||
m_glWidget.data()->setAttribute(Qt::WA_PaintOutsidePaintEvent);
|
||||
|
||||
for (int i = 0; i < FboCount; i++) {
|
||||
m_fbo[i] = new QGLFramebufferObject(m_currentSize, QGLFramebufferObject::CombinedDepthStencil);
|
||||
QPainter p(m_fbo[i]);
|
||||
p.fillRect(0, 0, m_currentSize.width(), m_currentSize.height(), Qt::gray);
|
||||
}
|
||||
}
|
||||
|
||||
OsgEarthItemRenderer::~OsgEarthItemRenderer()
|
||||
{
|
||||
m_glWidget.data()->makeCurrent();
|
||||
for (int i = 0; i < FboCount; i++) {
|
||||
delete m_fbo[i];
|
||||
m_fbo[i] = 0;
|
||||
}
|
||||
m_glWidget.data()->doneCurrent();
|
||||
|
||||
delete m_glWidget.data();
|
||||
}
|
||||
|
||||
QGLFramebufferObject *OsgEarthItemRenderer::lastFrame()
|
||||
{
|
||||
return m_fbo[m_lastFboNumber];
|
||||
}
|
||||
|
||||
void OsgEarthItemRenderer::initScene()
|
||||
{
|
||||
Q_ASSERT(!m_viewer.get());
|
||||
|
||||
int w = m_currentSize.width();
|
||||
int h = m_currentSize.height();
|
||||
|
||||
QString sceneFile = m_item->resolvedSceneFile();
|
||||
m_model = osgDB::readNodeFile(sceneFile.toStdString());
|
||||
|
||||
// setup caching
|
||||
osgEarth::MapNode *mapNode = osgEarth::MapNode::findMapNode(m_model.get());
|
||||
if (!mapNode) {
|
||||
qWarning() << Q_FUNC_INFO << sceneFile << " doesn't look like an osgEarth file";
|
||||
}
|
||||
|
||||
m_gw = new osgViewer::GraphicsWindowEmbedded(0, 0, w, h);
|
||||
|
||||
m_viewer = new osgViewer::Viewer();
|
||||
m_viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
|
||||
m_viewer->setSceneData(m_model);
|
||||
m_viewer->getDatabasePager()->setDoPreCompile(true);
|
||||
|
||||
osg::Camera *camera = m_viewer->getCamera();
|
||||
camera->setViewport(new osg::Viewport(0, 0, w, h));
|
||||
camera->setGraphicsContext(m_gw);
|
||||
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// configure the near/far so we don't clip things that are up close
|
||||
camera->setNearFarRatio(0.00002);
|
||||
camera->setProjectionMatrixAsPerspective(m_item->fieldOfView(), qreal(w) / h, 1.0f, 10000.0f);
|
||||
|
||||
updateFrame();
|
||||
}
|
||||
|
||||
void OsgEarthItemRenderer::updateFrame()
|
||||
{
|
||||
if (!m_cameraDirty || !m_viewer.get() || m_glWidget.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_glWidget.data()->makeCurrent();
|
||||
|
||||
// To find a camera view matrix, find placer matrixes for two points
|
||||
// onr at requested coords and another latitude shifted by 0.01 deg
|
||||
osgEarth::Util::ObjectPlacer placer(m_viewer->getSceneData());
|
||||
|
||||
m_cameraDirty = false;
|
||||
|
||||
osg::Matrixd positionMatrix;
|
||||
placer.createPlacerMatrix(m_item->latitude(), m_item->longitude(), m_item->altitude(), positionMatrix);
|
||||
osg::Matrixd positionMatrix2;
|
||||
placer.createPlacerMatrix(m_item->latitude() + 0.01, m_item->longitude(), m_item->altitude(), positionMatrix2);
|
||||
|
||||
osg::Vec3d eye(0.0f, 0.0f, 0.0f);
|
||||
osg::Vec3d viewVector(0.0f, 0.0f, 0.0f);
|
||||
osg::Vec3d upVector(0.0f, 0.0f, 1.0f);
|
||||
|
||||
eye = positionMatrix.preMult(eye);
|
||||
upVector = positionMatrix.preMult(upVector);
|
||||
upVector.normalize();
|
||||
viewVector = positionMatrix2.preMult(viewVector) - eye;
|
||||
viewVector.normalize();
|
||||
viewVector *= 10.0;
|
||||
|
||||
// TODO: clarify the correct rotation order,
|
||||
// currently assuming yaw, pitch, roll
|
||||
osg::Quat q;
|
||||
q.makeRotate(-m_item->yaw() * M_PI / 180.0, upVector);
|
||||
upVector = q * upVector;
|
||||
viewVector = q * viewVector;
|
||||
|
||||
osg::Vec3d side = viewVector ^ upVector;
|
||||
q.makeRotate(m_item->pitch() * M_PI / 180.0, side);
|
||||
upVector = q * upVector;
|
||||
viewVector = q * viewVector;
|
||||
|
||||
q.makeRotate(m_item->roll() * M_PI / 180.0, viewVector);
|
||||
upVector = q * upVector;
|
||||
viewVector = q * viewVector;
|
||||
|
||||
osg::Vec3d center = eye + viewVector;
|
||||
|
||||
// qDebug() << "e " << eye.x() << eye.y() << eye.z();
|
||||
// qDebug() << "c " << center.x() << center.y() << center.z();
|
||||
// qDebug() << "up" << upVector.x() << upVector.y() << upVector.z();
|
||||
|
||||
m_viewer->getCamera()->setViewMatrixAsLookAt(osg::Vec3d(eye.x(), eye.y(), eye.z()),
|
||||
osg::Vec3d(center.x(), center.y(), center.z()),
|
||||
osg::Vec3d(upVector.x(), upVector.y(), upVector.z()));
|
||||
|
||||
{
|
||||
QGLFramebufferObject *fbo = m_fbo[(m_lastFboNumber + 1) % FboCount];
|
||||
QPainter fboPainter(fbo);
|
||||
fboPainter.beginNativePainting();
|
||||
m_viewer->frame();
|
||||
fboPainter.endNativePainting();
|
||||
}
|
||||
m_glWidget.data()->doneCurrent();
|
||||
|
||||
m_lastFboNumber = (m_lastFboNumber + 1) % FboCount;
|
||||
|
||||
emit frameReady();
|
||||
}
|
@ -1,171 +0,0 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef OSGEARTH_H
|
||||
#define OSGEARTH_H
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
|
||||
#include <QtDeclarative/QDeclarativeItem>
|
||||
#include <osgQt/GraphicsWindowQt>
|
||||
|
||||
class QGLFramebufferObject;
|
||||
class QGLWidget;
|
||||
class OsgEarthItemRenderer;
|
||||
|
||||
class OsgEarthItem : public QDeclarativeItem {
|
||||
Q_OBJECT Q_DISABLE_COPY(OsgEarthItem)
|
||||
|
||||
Q_PROPERTY(QString sceneFile READ sceneFile WRITE setSceneFile NOTIFY sceneFileChanged)
|
||||
Q_PROPERTY(qreal fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
|
||||
|
||||
Q_PROPERTY(qreal roll READ roll WRITE setRoll NOTIFY rollChanged)
|
||||
Q_PROPERTY(qreal pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
|
||||
Q_PROPERTY(qreal yaw READ yaw WRITE setYaw NOTIFY yawChanged)
|
||||
|
||||
Q_PROPERTY(double latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged)
|
||||
Q_PROPERTY(double longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged)
|
||||
Q_PROPERTY(double altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged)
|
||||
|
||||
public:
|
||||
OsgEarthItem(QDeclarativeItem *parent = 0);
|
||||
~OsgEarthItem();
|
||||
|
||||
QString sceneFile() const
|
||||
{
|
||||
return m_sceneFile;
|
||||
}
|
||||
QString resolvedSceneFile() const;
|
||||
qreal fieldOfView() const
|
||||
{
|
||||
return m_fieldOfView;
|
||||
}
|
||||
|
||||
qreal roll() const
|
||||
{
|
||||
return m_roll;
|
||||
}
|
||||
qreal pitch() const
|
||||
{
|
||||
return m_pitch;
|
||||
}
|
||||
qreal yaw() const
|
||||
{
|
||||
return m_yaw;
|
||||
}
|
||||
|
||||
double latitude() const
|
||||
{
|
||||
return m_latitude;
|
||||
}
|
||||
double longitude() const
|
||||
{
|
||||
return m_longitude;
|
||||
}
|
||||
double altitude() const
|
||||
{
|
||||
return m_altitude;
|
||||
}
|
||||
|
||||
protected:
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *style, QWidget *widget);
|
||||
|
||||
public slots:
|
||||
void updateView();
|
||||
void setSceneFile(QString arg);
|
||||
void setFieldOfView(qreal arg);
|
||||
|
||||
void setRoll(qreal arg);
|
||||
void setPitch(qreal arg);
|
||||
void setYaw(qreal arg);
|
||||
|
||||
void setLatitude(double arg);
|
||||
void setLongitude(double arg);
|
||||
void setAltitude(double arg);
|
||||
|
||||
signals:
|
||||
void rollChanged(qreal arg);
|
||||
void pitchChanged(qreal arg);
|
||||
void yawChanged(qreal arg);
|
||||
|
||||
void latitudeChanged(double arg);
|
||||
void longitudeChanged(double arg);
|
||||
void altitudeChanged(double arg);
|
||||
|
||||
void sceneFileChanged(QString arg);
|
||||
void fieldOfViewChanged(qreal arg);
|
||||
|
||||
private slots:
|
||||
void updateFrame();
|
||||
|
||||
private:
|
||||
OsgEarthItemRenderer *m_renderer;
|
||||
QThread *m_rendererThread;
|
||||
|
||||
QSize m_currentSize;
|
||||
|
||||
qreal m_roll;
|
||||
qreal m_pitch;
|
||||
qreal m_yaw;
|
||||
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
double m_altitude;
|
||||
|
||||
qreal m_fieldOfView;
|
||||
QString m_sceneFile;
|
||||
};
|
||||
|
||||
class OsgEarthItemRenderer : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
OsgEarthItemRenderer(OsgEarthItem *item, QGLWidget *glWidget);
|
||||
~OsgEarthItemRenderer();
|
||||
|
||||
QGLFramebufferObject *lastFrame();
|
||||
void markDirty()
|
||||
{
|
||||
m_cameraDirty = true;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void initScene();
|
||||
void updateFrame();
|
||||
|
||||
signals:
|
||||
void frameReady();
|
||||
|
||||
private:
|
||||
enum { FboCount = 3 };
|
||||
OsgEarthItem *m_item;
|
||||
|
||||
osg::ref_ptr<osgViewer::Viewer> m_viewer;
|
||||
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_gw;
|
||||
osg::ref_ptr<osg::Node> m_model;
|
||||
QWeakPointer<QGLWidget> m_glWidget;
|
||||
|
||||
QGLFramebufferObject *m_fbo[FboCount];
|
||||
int m_lastFboNumber;
|
||||
|
||||
QSize m_currentSize;
|
||||
|
||||
bool m_cameraDirty;
|
||||
};
|
||||
|
||||
QML_DECLARE_TYPE(OsgEarthItem)
|
||||
|
||||
#endif // OSGEARTH_H
|
48
ground/gcs/src/plugins/pfdqml/pfdqml.h
Normal file
48
ground/gcs/src/plugins/pfdqml/pfdqml.h
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqml.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PFDQML_H_
|
||||
#define PFDQML_H_
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml>
|
||||
|
||||
class Pfd : public QObject {
|
||||
Q_OBJECT Q_ENUMS(PositionMode)
|
||||
Q_ENUMS(TimeMode)
|
||||
|
||||
public:
|
||||
enum ModelSelectionMode { Auto, Fixed };
|
||||
enum TimeMode { Local, PredefinedTime };
|
||||
|
||||
static void declareQML()
|
||||
{
|
||||
qmlRegisterType<Pfd>("PfdQmlEnums", 1, 0, "Pfd");
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PFDQML_H_
|
@ -1,17 +1,14 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = PfdQml
|
||||
QT += svg
|
||||
QT += opengl
|
||||
QT += qml quick
|
||||
OSG {
|
||||
DEFINES += USE_OSG
|
||||
}
|
||||
|
||||
QT += svg qml quick quickwidgets
|
||||
|
||||
include(../../plugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(pfdqml_dependencies.pri)
|
||||
|
||||
HEADERS += \
|
||||
pfdqml.h \
|
||||
pfdqmlcontext.h \
|
||||
pfdqmlplugin.h \
|
||||
pfdqmlgadget.h \
|
||||
pfdqmlgadgetwidget.h \
|
||||
@ -20,6 +17,7 @@ HEADERS += \
|
||||
pfdqmlgadgetoptionspage.h
|
||||
|
||||
SOURCES += \
|
||||
pfdqmlcontext.cpp \
|
||||
pfdqmlplugin.cpp \
|
||||
pfdqmlgadget.cpp \
|
||||
pfdqmlgadgetfactory.cpp \
|
||||
@ -27,19 +25,8 @@ SOURCES += \
|
||||
pfdqmlgadgetconfiguration.cpp \
|
||||
pfdqmlgadgetoptionspage.cpp
|
||||
|
||||
|
||||
contains(DEFINES,USE_OSG) {
|
||||
LIBS += -losg -losgUtil -losgViewer -losgQt -losgDB -lOpenThreads -losgGA
|
||||
LIBS += -losgEarth -losgEarthFeatures -losgEarthUtil
|
||||
|
||||
HEADERS += osgearth.h
|
||||
SOURCES += osgearth.cpp
|
||||
}
|
||||
|
||||
OTHER_FILES += PfdQml.pluginspec
|
||||
|
||||
FORMS += pfdqmlgadgetoptionspage.ui
|
||||
|
||||
RESOURCES += \
|
||||
PfdResources.qrc
|
||||
|
||||
RESOURCES += PfdResources.qrc
|
||||
|
@ -1 +1,7 @@
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(../../plugins/uavobjects/uavobjects.pri)
|
||||
include(../../libs/utils/utils.pri)
|
||||
|
||||
# TODO get rid of this dependency
|
||||
# it is only needed for one initialization call in pfdqmlplugin.cpp
|
||||
include(../../libs/osgearth/osgearth.pri)
|
||||
|
330
ground/gcs/src/plugins/pfdqml/pfdqmlcontext.cpp
Normal file
330
ground/gcs/src/plugins/pfdqml/pfdqmlcontext.cpp
Normal file
@ -0,0 +1,330 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlcontext.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "pfdqmlcontext.h"
|
||||
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
#include "flightbatterysettings.h"
|
||||
|
||||
#include <QQmlContext>
|
||||
#include <QDebug>
|
||||
|
||||
PfdQmlContext::PfdQmlContext(QObject *parent) : QObject(parent),
|
||||
m_speedUnit("m/s"),
|
||||
m_speedFactor(1.0),
|
||||
m_altitudeUnit("m"),
|
||||
m_altitudeFactor(1.0),
|
||||
m_terrainEnabled(false),
|
||||
m_terrainFile(""),
|
||||
m_latitude(39.657380),
|
||||
m_longitude(19.805158),
|
||||
m_altitude(100),
|
||||
m_timeMode(Pfd::Local),
|
||||
m_dateTime(QDateTime()),
|
||||
m_minAmbientLight(0.03),
|
||||
m_modelFile(""),
|
||||
m_backgroundImageFile("")
|
||||
{}
|
||||
|
||||
PfdQmlContext::~PfdQmlContext()
|
||||
{}
|
||||
|
||||
QString PfdQmlContext::speedUnit() const
|
||||
{
|
||||
return m_speedUnit;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setSpeedUnit(QString unit)
|
||||
{
|
||||
if (m_speedUnit != unit) {
|
||||
m_speedUnit = unit;
|
||||
emit speedUnitChanged(speedUnit());
|
||||
}
|
||||
}
|
||||
|
||||
double PfdQmlContext::speedFactor() const
|
||||
{
|
||||
return m_speedFactor;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setSpeedFactor(double factor)
|
||||
{
|
||||
if (m_speedFactor != factor) {
|
||||
m_speedFactor = factor;
|
||||
emit speedFactorChanged(speedFactor());
|
||||
}
|
||||
}
|
||||
|
||||
QString PfdQmlContext::altitudeUnit() const
|
||||
{
|
||||
return m_altitudeUnit;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setAltitudeUnit(QString unit)
|
||||
{
|
||||
if (m_altitudeUnit != unit) {
|
||||
m_altitudeUnit = unit;
|
||||
emit altitudeUnitChanged(altitudeUnit());
|
||||
}
|
||||
}
|
||||
|
||||
double PfdQmlContext::altitudeFactor() const
|
||||
{
|
||||
return m_altitudeFactor;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setAltitudeFactor(double factor)
|
||||
{
|
||||
if (m_altitudeFactor != factor) {
|
||||
m_altitudeFactor = factor;
|
||||
emit altitudeFactorChanged(altitudeFactor());
|
||||
}
|
||||
}
|
||||
|
||||
bool PfdQmlContext::terrainEnabled() const
|
||||
{
|
||||
return m_terrainEnabled;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setTerrainEnabled(bool arg)
|
||||
{
|
||||
if (m_terrainEnabled != arg) {
|
||||
m_terrainEnabled = arg;
|
||||
emit terrainEnabledChanged(terrainEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
QString PfdQmlContext::terrainFile() const
|
||||
{
|
||||
return m_terrainFile;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setTerrainFile(const QString &arg)
|
||||
{
|
||||
if (m_terrainFile != arg) {
|
||||
m_terrainFile = arg;
|
||||
emit terrainFileChanged(terrainFile());
|
||||
}
|
||||
}
|
||||
|
||||
double PfdQmlContext::latitude() const
|
||||
{
|
||||
return m_latitude;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setLatitude(double arg)
|
||||
{
|
||||
if (m_latitude != arg) {
|
||||
m_latitude = arg;
|
||||
emit latitudeChanged(latitude());
|
||||
}
|
||||
}
|
||||
|
||||
double PfdQmlContext::longitude() const
|
||||
{
|
||||
return m_longitude;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setLongitude(double arg)
|
||||
{
|
||||
if (m_longitude != arg) {
|
||||
m_longitude = arg;
|
||||
emit longitudeChanged(longitude());
|
||||
}
|
||||
}
|
||||
|
||||
double PfdQmlContext::altitude() const
|
||||
{
|
||||
return m_altitude;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setAltitude(double arg)
|
||||
{
|
||||
if (m_altitude != arg) {
|
||||
m_altitude = arg;
|
||||
emit altitudeChanged(altitude());
|
||||
}
|
||||
}
|
||||
|
||||
Pfd::TimeMode PfdQmlContext::timeMode() const
|
||||
{
|
||||
return m_timeMode;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setTimeMode(Pfd::TimeMode arg)
|
||||
{
|
||||
if (m_timeMode != arg) {
|
||||
m_timeMode = arg;
|
||||
emit timeModeChanged(timeMode());
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime PfdQmlContext::dateTime() const
|
||||
{
|
||||
return m_dateTime;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setDateTime(QDateTime arg)
|
||||
{
|
||||
if (m_dateTime != arg) {
|
||||
m_dateTime = arg;
|
||||
emit dateTimeChanged(dateTime());
|
||||
}
|
||||
}
|
||||
|
||||
double PfdQmlContext::minimumAmbientLight() const
|
||||
{
|
||||
return m_minAmbientLight;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setMinimumAmbientLight(double arg)
|
||||
{
|
||||
if (m_minAmbientLight != arg) {
|
||||
m_minAmbientLight = arg;
|
||||
emit minimumAmbientLightChanged(minimumAmbientLight());
|
||||
}
|
||||
}
|
||||
|
||||
QString PfdQmlContext::modelFile() const
|
||||
{
|
||||
return m_modelFile;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setModelFile(const QString &arg)
|
||||
{
|
||||
if (m_modelFile != arg) {
|
||||
m_modelFile = arg;
|
||||
emit modelFileChanged(modelFile());
|
||||
}
|
||||
}
|
||||
|
||||
QString PfdQmlContext::backgroundImageFile() const
|
||||
{
|
||||
return m_backgroundImageFile;
|
||||
}
|
||||
|
||||
void PfdQmlContext::setBackgroundImageFile(const QString &arg)
|
||||
{
|
||||
if (m_backgroundImageFile != arg) {
|
||||
m_backgroundImageFile = arg;
|
||||
emit backgroundImageFileChanged(backgroundImageFile());
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlContext::resetConsumedEnergy()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *uavoManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
Q_ASSERT(uavoManager);
|
||||
|
||||
FlightBatterySettings *batterySettings = FlightBatterySettings::GetInstance(uavoManager);
|
||||
|
||||
batterySettings->setResetConsumedEnergy(true);
|
||||
batterySettings->setData(batterySettings->getData());
|
||||
}
|
||||
|
||||
void PfdQmlContext::loadConfiguration(PfdQmlGadgetConfiguration *config)
|
||||
{
|
||||
setSpeedFactor(config->speedFactor());
|
||||
setSpeedUnit(config->speedUnit());
|
||||
setAltitudeFactor(config->altitudeFactor());
|
||||
setAltitudeUnit(config->altitudeUnit());
|
||||
|
||||
// terrain
|
||||
setTerrainEnabled(config->terrainEnabled());
|
||||
setTerrainFile(config->terrainFile());
|
||||
|
||||
setLatitude(config->latitude());
|
||||
setLongitude(config->longitude());
|
||||
setAltitude(config->altitude());
|
||||
|
||||
// sky
|
||||
setTimeMode(config->timeMode());
|
||||
setDateTime(config->dateTime());
|
||||
setMinimumAmbientLight(config->minAmbientLight());
|
||||
|
||||
// model
|
||||
setModelFile(config->modelFile());
|
||||
|
||||
// background image
|
||||
setBackgroundImageFile(config->backgroundImageFile());
|
||||
}
|
||||
|
||||
void PfdQmlContext::apply(QQmlContext *context)
|
||||
{
|
||||
QStringList objectsToExport;
|
||||
|
||||
objectsToExport <<
|
||||
"VelocityState" <<
|
||||
"PositionState" <<
|
||||
"AttitudeState" <<
|
||||
"AccelState" <<
|
||||
"VelocityDesired" <<
|
||||
"PathDesired" <<
|
||||
"GPSPositionSensor" <<
|
||||
"GPSSatellites" <<
|
||||
"HomeLocation" <<
|
||||
"GCSTelemetryStats" <<
|
||||
"SystemAlarms" <<
|
||||
"NedAccel" <<
|
||||
"ActuatorDesired" <<
|
||||
"TakeOffLocation" <<
|
||||
"PathPlan" <<
|
||||
"WaypointActive" <<
|
||||
"OPLinkStatus" <<
|
||||
"FlightStatus" <<
|
||||
"SystemStats" <<
|
||||
"StabilizationDesired" <<
|
||||
"VtolPathFollowerSettings" <<
|
||||
"HwSettings" <<
|
||||
"ManualControlCommand" <<
|
||||
"SystemSettings" <<
|
||||
"RevoSettings" <<
|
||||
"MagState" <<
|
||||
"FlightBatterySettings" <<
|
||||
"FlightBatteryState" <<
|
||||
"ReceiverStatus";
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
foreach(const QString &objectName, objectsToExport) {
|
||||
UAVObject *object = objManager->getObject(objectName);
|
||||
|
||||
if (object) {
|
||||
context->setContextProperty(objectName, object);
|
||||
} else {
|
||||
qWarning() << "PfdQmlContext::apply - failed to load object" << objectName;
|
||||
}
|
||||
}
|
||||
|
||||
// to expose settings values
|
||||
context->setContextProperty("qmlWidget", this);
|
||||
}
|
140
ground/gcs/src/plugins/pfdqml/pfdqmlcontext.h
Normal file
140
ground/gcs/src/plugins/pfdqml/pfdqmlcontext.h
Normal file
@ -0,0 +1,140 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlcontext.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef PFDQMLCONTEXT_H_
|
||||
#define PFDQMLCONTEXT_H_
|
||||
|
||||
#include "pfdqml.h"
|
||||
#include "pfdqmlgadgetconfiguration.h"
|
||||
|
||||
class QQmlContext;
|
||||
|
||||
class PfdQmlContext : public QObject {
|
||||
Q_OBJECT Q_PROPERTY(QString speedUnit READ speedUnit WRITE setSpeedUnit NOTIFY speedUnitChanged)
|
||||
Q_PROPERTY(double speedFactor READ speedFactor WRITE setSpeedFactor NOTIFY speedFactorChanged)
|
||||
Q_PROPERTY(QString altitudeUnit READ altitudeUnit WRITE setAltitudeUnit NOTIFY altitudeUnitChanged)
|
||||
Q_PROPERTY(double altitudeFactor READ altitudeFactor WRITE setAltitudeFactor NOTIFY altitudeFactorChanged)
|
||||
|
||||
// terrain
|
||||
Q_PROPERTY(bool terrainEnabled READ terrainEnabled WRITE setTerrainEnabled NOTIFY terrainEnabledChanged)
|
||||
Q_PROPERTY(QString terrainFile READ terrainFile WRITE setTerrainFile NOTIFY terrainFileChanged)
|
||||
|
||||
Q_PROPERTY(double latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged)
|
||||
Q_PROPERTY(double longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged)
|
||||
Q_PROPERTY(double altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged)
|
||||
|
||||
Q_PROPERTY(Pfd::TimeMode timeMode READ timeMode WRITE setTimeMode NOTIFY timeModeChanged)
|
||||
Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime NOTIFY dateTimeChanged)
|
||||
Q_PROPERTY(double minimumAmbientLight READ minimumAmbientLight WRITE setMinimumAmbientLight NOTIFY minimumAmbientLightChanged)
|
||||
|
||||
Q_PROPERTY(QString modelFile READ modelFile WRITE setModelFile NOTIFY modelFileChanged)
|
||||
Q_PROPERTY(QString backgroundImageFile READ backgroundImageFile WRITE setBackgroundImageFile NOTIFY backgroundImageFileChanged)
|
||||
|
||||
public:
|
||||
PfdQmlContext(QObject *parent = 0);
|
||||
virtual ~PfdQmlContext();
|
||||
|
||||
QString speedUnit() const;
|
||||
void setSpeedUnit(QString unit);
|
||||
double speedFactor() const;
|
||||
void setSpeedFactor(double factor);
|
||||
QString altitudeUnit() const;
|
||||
void setAltitudeUnit(QString unit);
|
||||
double altitudeFactor() const;
|
||||
void setAltitudeFactor(double factor);
|
||||
|
||||
bool terrainEnabled() const;
|
||||
void setTerrainEnabled(bool arg);
|
||||
QString terrainFile() const;
|
||||
void setTerrainFile(const QString &arg);
|
||||
|
||||
double latitude() const;
|
||||
void setLatitude(double arg);
|
||||
double longitude() const;
|
||||
void setLongitude(double arg);
|
||||
double altitude() const;
|
||||
void setAltitude(double arg);
|
||||
|
||||
Pfd::TimeMode timeMode() const;
|
||||
void setTimeMode(Pfd::TimeMode arg);
|
||||
QDateTime dateTime() const;
|
||||
void setDateTime(QDateTime arg);
|
||||
double minimumAmbientLight() const;
|
||||
void setMinimumAmbientLight(double arg);
|
||||
|
||||
QString modelFile() const;
|
||||
void setModelFile(const QString &arg);
|
||||
QString backgroundImageFile() const;
|
||||
void setBackgroundImageFile(const QString &arg);
|
||||
|
||||
Q_INVOKABLE void resetConsumedEnergy();
|
||||
|
||||
void loadConfiguration(PfdQmlGadgetConfiguration *config);
|
||||
void apply(QQmlContext *context);
|
||||
|
||||
signals:
|
||||
void speedUnitChanged(QString arg);
|
||||
void speedFactorChanged(double arg);
|
||||
void altitudeUnitChanged(QString arg);
|
||||
void altitudeFactorChanged(double arg);
|
||||
|
||||
void terrainEnabledChanged(bool arg);
|
||||
void terrainFileChanged(QString arg);
|
||||
|
||||
void latitudeChanged(double arg);
|
||||
void longitudeChanged(double arg);
|
||||
void altitudeChanged(double arg);
|
||||
|
||||
void timeModeChanged(Pfd::TimeMode arg);
|
||||
void dateTimeChanged(QDateTime arge);
|
||||
void minimumAmbientLightChanged(double arg);
|
||||
|
||||
void modelFileChanged(QString arg);
|
||||
void backgroundImageFileChanged(QString arg);
|
||||
|
||||
private:
|
||||
QString m_speedUnit;
|
||||
double m_speedFactor;
|
||||
QString m_altitudeUnit;
|
||||
double m_altitudeFactor;
|
||||
|
||||
bool m_terrainEnabled;
|
||||
QString m_terrainFile;
|
||||
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
double m_altitude;
|
||||
|
||||
Pfd::TimeMode m_timeMode;
|
||||
QDateTime m_dateTime;
|
||||
double m_minAmbientLight;
|
||||
|
||||
QString m_modelFile;
|
||||
|
||||
QString m_backgroundImageFile;
|
||||
};
|
||||
#endif /* PFDQMLCONTEXT_H_ */
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadget.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -18,51 +29,25 @@
|
||||
#include "pfdqmlgadgetwidget.h"
|
||||
#include "pfdqmlgadgetconfiguration.h"
|
||||
|
||||
PfdQmlGadget::PfdQmlGadget(QString classId, PfdQmlGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
PfdQmlGadget::PfdQmlGadget(QString classId, QWidget *parent) :
|
||||
IUAVGadget(classId, parent)
|
||||
{
|
||||
m_container = NULL;
|
||||
m_parent = parent;
|
||||
m_qmlGadgetWidget = new PfdQmlGadgetWidget(parent);
|
||||
}
|
||||
|
||||
PfdQmlGadget::~PfdQmlGadget()
|
||||
{
|
||||
delete m_widget;
|
||||
delete m_qmlGadgetWidget;
|
||||
}
|
||||
|
||||
QWidget *PfdQmlGadget::widget()
|
||||
{
|
||||
return m_qmlGadgetWidget;
|
||||
}
|
||||
|
||||
/*
|
||||
This is called when a configuration is loaded, and updates the plugin's settings.
|
||||
Careful: the plugin is already drawn before the loadConfiguration method is called the
|
||||
first time, so you have to be careful not to assume all the plugin values are initialized
|
||||
the first time you use them
|
||||
*/
|
||||
void PfdQmlGadget::loadConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
PfdQmlGadgetConfiguration *m = qobject_cast<PfdQmlGadgetConfiguration *>(config);
|
||||
|
||||
m_widget->setOpenGLEnabled(m->openGLEnabled());
|
||||
m_widget->setQmlFile(m->qmlFile());
|
||||
m_widget->setEarthFile(m->earthFile());
|
||||
m_widget->setTerrainEnabled(m->terrainEnabled());
|
||||
m_widget->setActualPositionUsed(m->actualPositionUsed());
|
||||
m_widget->setLatitude(m->latitude());
|
||||
m_widget->setLongitude(m->longitude());
|
||||
m_widget->setAltitude(m->altitude());
|
||||
m_widget->setSpeedFactor(m->speedFactor());
|
||||
m_widget->setSpeedUnit(m->speedUnit());
|
||||
m_widget->setAltitudeFactor(m->altitudeFactor());
|
||||
m_widget->setAltitudeUnit(m->altitudeUnit());
|
||||
|
||||
// setting OSGEARTH_CACHE_ONLY seems to work the most reliably
|
||||
// between osgEarth versions I tried
|
||||
if (m->cacheOnly()) {
|
||||
qputenv("OSGEARTH_CACHE_ONLY", "true");
|
||||
} else {
|
||||
#ifdef Q_OS_WIN32
|
||||
qputenv("OSGEARTH_CACHE_ONLY", "");
|
||||
#else
|
||||
unsetenv("OSGEARTH_CACHE_ONLY");
|
||||
#endif
|
||||
}
|
||||
m_qmlGadgetWidget->loadConfiguration(m);
|
||||
}
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadget.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -17,38 +28,27 @@
|
||||
#ifndef PFDQMLGADGET_H_
|
||||
#define PFDQMLGADGET_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "pfdqmlgadgetwidget.h"
|
||||
#include "pfdqmlgadget.h"
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
class IUAVGadget;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class PfdQmlGadgetWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class PfdQmlGadget : public Core::IUAVGadget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PfdQmlGadget(QString classId, PfdQmlGadgetWidget *widget, QWidget *parent = 0);
|
||||
~PfdQmlGadget();
|
||||
|
||||
QWidget *widget()
|
||||
{
|
||||
if (!m_container) {
|
||||
m_container = QWidget::createWindowContainer(m_widget, m_parent);
|
||||
m_container->setMinimumSize(64, 64);
|
||||
m_container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
}
|
||||
return m_container;
|
||||
}
|
||||
public:
|
||||
PfdQmlGadget(QString classId, QWidget *parent = 0);
|
||||
virtual ~PfdQmlGadget();
|
||||
|
||||
QWidget *widget();
|
||||
|
||||
void loadConfiguration(IUAVGadgetConfiguration *config);
|
||||
|
||||
private:
|
||||
QWidget *m_container;
|
||||
QWidget *m_parent;
|
||||
PfdQmlGadgetWidget *m_widget;
|
||||
PfdQmlGadgetWidget *m_qmlGadgetWidget;
|
||||
};
|
||||
|
||||
|
||||
#endif // PFDQMLGADGET_H_
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetconfiguration.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -24,16 +35,21 @@
|
||||
PfdQmlGadgetConfiguration::PfdQmlGadgetConfiguration(QString classId, QSettings *qSettings, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_qmlFile("Unknown"),
|
||||
m_earthFile("Unknown"),
|
||||
m_openGLEnabled(true),
|
||||
m_speedFactor(1.0),
|
||||
m_altitudeFactor(1.0),
|
||||
m_terrainEnabled(false),
|
||||
m_actualPositionUsed(false),
|
||||
m_terrainFile("Unknown"),
|
||||
m_cacheOnly(false),
|
||||
m_timeMode(Pfd::Local),
|
||||
m_dateTime(QDateTime()),
|
||||
m_minAmbientLight(0),
|
||||
m_latitude(0),
|
||||
m_longitude(0),
|
||||
m_altitude(0),
|
||||
m_cacheOnly(false),
|
||||
m_speedFactor(1.0),
|
||||
m_altitudeFactor(1.0)
|
||||
m_modelEnabled(false),
|
||||
m_modelFile("Unknown"),
|
||||
m_modelSelectionMode(Pfd::Auto),
|
||||
m_backgroundImageFile("Unknown")
|
||||
{
|
||||
m_speedMap[1.0] = "m/s";
|
||||
m_speedMap[3.6] = "km/h";
|
||||
@ -45,21 +61,36 @@ PfdQmlGadgetConfiguration::PfdQmlGadgetConfiguration(QString classId, QSettings
|
||||
|
||||
// if a saved configuration exists load it
|
||||
if (qSettings != 0) {
|
||||
m_qmlFile = qSettings->value("qmlFile").toString();
|
||||
m_qmlFile = Utils::InsertDataPath(m_qmlFile);
|
||||
m_qmlFile = qSettings->value("qmlFile").toString();
|
||||
m_qmlFile = Utils::InsertDataPath(m_qmlFile);
|
||||
|
||||
m_earthFile = qSettings->value("earthFile").toString();
|
||||
m_earthFile = Utils::InsertDataPath(m_earthFile);
|
||||
m_speedFactor = qSettings->value("speedFactor").toDouble();
|
||||
m_altitudeFactor = qSettings->value("altitudeFactor").toDouble();
|
||||
|
||||
m_openGLEnabled = qSettings->value("openGLEnabled", true).toBool();
|
||||
m_terrainEnabled = qSettings->value("terrainEnabled").toBool();
|
||||
m_actualPositionUsed = qSettings->value("actualPositionUsed").toBool();
|
||||
m_latitude = qSettings->value("latitude").toDouble();
|
||||
m_longitude = qSettings->value("longitude").toDouble();
|
||||
m_altitude = qSettings->value("altitude").toDouble();
|
||||
m_cacheOnly = qSettings->value("cacheOnly").toBool();
|
||||
m_speedFactor = qSettings->value("speedFactor").toDouble();
|
||||
m_altitudeFactor = qSettings->value("altitudeFactor").toDouble();
|
||||
// terrain
|
||||
m_terrainEnabled = qSettings->value("terrainEnabled").toBool();
|
||||
m_terrainFile = qSettings->value("earthFile").toString();
|
||||
m_terrainFile = Utils::InsertDataPath(m_terrainFile);
|
||||
m_cacheOnly = qSettings->value("cacheOnly").toBool();
|
||||
|
||||
m_latitude = qSettings->value("latitude").toDouble();
|
||||
m_longitude = qSettings->value("longitude").toDouble();
|
||||
m_altitude = qSettings->value("altitude").toDouble();
|
||||
|
||||
// sky
|
||||
m_timeMode = static_cast<Pfd::TimeMode>(qSettings->value("timeMode").toUInt());
|
||||
m_dateTime = qSettings->value("dateTime").toDateTime();
|
||||
m_minAmbientLight = qSettings->value("minAmbientLight").toDouble();
|
||||
|
||||
// model
|
||||
m_modelEnabled = qSettings->value("modelEnabled").toBool();
|
||||
m_modelSelectionMode = static_cast<Pfd::ModelSelectionMode>(qSettings->value("modelSelectionMode").toUInt());
|
||||
m_modelFile = qSettings->value("modelFile").toString();
|
||||
m_modelFile = Utils::InsertDataPath(m_modelFile);
|
||||
|
||||
// background image
|
||||
m_backgroundImageFile = qSettings->value("backgroundImageFile").toString();
|
||||
m_backgroundImageFile = Utils::InsertDataPath(m_backgroundImageFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,17 +102,32 @@ IUAVGadgetConfiguration *PfdQmlGadgetConfiguration::clone()
|
||||
{
|
||||
PfdQmlGadgetConfiguration *m = new PfdQmlGadgetConfiguration(this->classId());
|
||||
|
||||
m->m_qmlFile = m_qmlFile;
|
||||
m->m_openGLEnabled = m_openGLEnabled;
|
||||
m->m_earthFile = m_earthFile;
|
||||
m->m_terrainEnabled = m_terrainEnabled;
|
||||
m->m_actualPositionUsed = m_actualPositionUsed;
|
||||
m->m_latitude = m_latitude;
|
||||
m->m_longitude = m_longitude;
|
||||
m->m_altitude = m_altitude;
|
||||
m->m_cacheOnly = m_cacheOnly;
|
||||
m->m_speedFactor = m_speedFactor;
|
||||
m->m_altitudeFactor = m_altitudeFactor;
|
||||
m->m_qmlFile = m_qmlFile;
|
||||
|
||||
m->m_speedFactor = m_speedFactor;
|
||||
m->m_altitudeFactor = m_altitudeFactor;
|
||||
|
||||
// terrain
|
||||
m->m_terrainEnabled = m_terrainEnabled;
|
||||
m->m_terrainFile = m_terrainFile;
|
||||
m->m_cacheOnly = m_cacheOnly;
|
||||
|
||||
m->m_latitude = m_latitude;
|
||||
m->m_longitude = m_longitude;
|
||||
m->m_altitude = m_altitude;
|
||||
|
||||
// sky
|
||||
m->m_timeMode = m_timeMode;
|
||||
m->m_dateTime = m_dateTime;
|
||||
m->m_minAmbientLight = m_minAmbientLight;
|
||||
|
||||
// model
|
||||
m->m_modelEnabled = m_modelEnabled;
|
||||
m->m_modelSelectionMode = m_modelSelectionMode;
|
||||
m->m_modelFile = m_modelFile;
|
||||
|
||||
// background image
|
||||
m->m_backgroundImageFile = m_backgroundImageFile;
|
||||
|
||||
return m;
|
||||
}
|
||||
@ -92,19 +138,35 @@ IUAVGadgetConfiguration *PfdQmlGadgetConfiguration::clone()
|
||||
*/
|
||||
void PfdQmlGadgetConfiguration::saveConfig(QSettings *qSettings) const
|
||||
{
|
||||
QString qmlFile = Utils::RemoveDataPath(m_qmlFile);
|
||||
QString qmlFile = Utils::RemoveDataPath(m_qmlFile);
|
||||
|
||||
qSettings->setValue("qmlFile", qmlFile);
|
||||
QString earthFile = Utils::RemoveDataPath(m_earthFile);
|
||||
qSettings->setValue("earthFile", earthFile);
|
||||
|
||||
qSettings->setValue("openGLEnabled", m_openGLEnabled);
|
||||
qSettings->setValue("speedFactor", m_speedFactor);
|
||||
qSettings->setValue("altitudeFactor", m_altitudeFactor);
|
||||
|
||||
// terrain
|
||||
qSettings->setValue("terrainEnabled", m_terrainEnabled);
|
||||
qSettings->setValue("actualPositionUsed", m_actualPositionUsed);
|
||||
QString terrainFile = Utils::RemoveDataPath(m_terrainFile);
|
||||
qSettings->setValue("earthFile", terrainFile);
|
||||
qSettings->setValue("cacheOnly", m_cacheOnly);
|
||||
|
||||
qSettings->setValue("latitude", m_latitude);
|
||||
qSettings->setValue("longitude", m_longitude);
|
||||
qSettings->setValue("altitude", m_altitude);
|
||||
qSettings->setValue("cacheOnly", m_cacheOnly);
|
||||
qSettings->setValue("speedFactor", m_speedFactor);
|
||||
qSettings->setValue("altitudeFactor", m_altitudeFactor);
|
||||
|
||||
// sky
|
||||
qSettings->setValue("timeMode", static_cast<uint>(m_timeMode));
|
||||
qSettings->setValue("dateTime", m_dateTime);
|
||||
qSettings->setValue("minAmbientLight", m_minAmbientLight);
|
||||
|
||||
// model
|
||||
qSettings->setValue("modelEnabled", m_modelEnabled);
|
||||
qSettings->setValue("modelSelectionMode", static_cast<uint>(m_modelSelectionMode));
|
||||
QString modelFile = Utils::RemoveDataPath(m_modelFile);
|
||||
qSettings->setValue("modelFile", modelFile);
|
||||
|
||||
// background image
|
||||
QString backgroundImageFile = Utils::RemoveDataPath(m_backgroundImageFile);
|
||||
qSettings->setValue("backgroundImageFile", backgroundImageFile);
|
||||
}
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetconfiguration.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -17,8 +28,11 @@
|
||||
#ifndef PFDQMLGADGETCONFIGURATION_H
|
||||
#define PFDQMLGADGETCONFIGURATION_H
|
||||
|
||||
#include "pfdqml.h"
|
||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||
|
||||
#include <QMap>
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace Core;
|
||||
|
||||
@ -27,94 +41,13 @@ class PfdQmlGadgetConfiguration : public IUAVGadgetConfiguration {
|
||||
public:
|
||||
explicit PfdQmlGadgetConfiguration(QString classId, QSettings *qSettings = 0, QObject *parent = 0);
|
||||
|
||||
void setQmlFile(const QString &fileName)
|
||||
{
|
||||
m_qmlFile = fileName;
|
||||
}
|
||||
void setEarthFile(const QString &fileName)
|
||||
{
|
||||
m_earthFile = fileName;
|
||||
}
|
||||
void setOpenGLEnabled(bool flag)
|
||||
{
|
||||
m_openGLEnabled = flag;
|
||||
}
|
||||
void setTerrainEnabled(bool flag)
|
||||
{
|
||||
m_terrainEnabled = flag;
|
||||
}
|
||||
void setActualPositionUsed(bool flag)
|
||||
{
|
||||
m_actualPositionUsed = flag;
|
||||
}
|
||||
void setLatitude(double value)
|
||||
{
|
||||
m_latitude = value;
|
||||
}
|
||||
void setLongitude(double value)
|
||||
{
|
||||
m_longitude = value;
|
||||
}
|
||||
void setAltitude(double value)
|
||||
{
|
||||
m_altitude = value;
|
||||
}
|
||||
void setCacheOnly(bool flag)
|
||||
{
|
||||
m_cacheOnly = flag;
|
||||
}
|
||||
void setSpeedFactor(double factor)
|
||||
{
|
||||
m_speedFactor = factor;
|
||||
}
|
||||
void setAltitudeFactor(double factor)
|
||||
{
|
||||
m_altitudeFactor = factor;
|
||||
}
|
||||
|
||||
QString qmlFile() const
|
||||
{
|
||||
return m_qmlFile;
|
||||
}
|
||||
QString earthFile() const
|
||||
void setQmlFile(const QString &fileName)
|
||||
{
|
||||
return m_earthFile;
|
||||
}
|
||||
bool openGLEnabled() const
|
||||
{
|
||||
return m_openGLEnabled;
|
||||
}
|
||||
bool terrainEnabled() const
|
||||
{
|
||||
return m_terrainEnabled;
|
||||
}
|
||||
bool actualPositionUsed() const
|
||||
{
|
||||
return m_actualPositionUsed;
|
||||
}
|
||||
double latitude() const
|
||||
{
|
||||
return m_latitude;
|
||||
}
|
||||
double longitude() const
|
||||
{
|
||||
return m_longitude;
|
||||
}
|
||||
double altitude() const
|
||||
{
|
||||
return m_altitude;
|
||||
}
|
||||
bool cacheOnly() const
|
||||
{
|
||||
return m_cacheOnly;
|
||||
}
|
||||
double speedFactor() const
|
||||
{
|
||||
return m_speedFactor;
|
||||
}
|
||||
double altitudeFactor() const
|
||||
{
|
||||
return m_altitudeFactor;
|
||||
m_qmlFile = fileName;
|
||||
}
|
||||
|
||||
QString speedUnit() const
|
||||
@ -122,11 +55,147 @@ public:
|
||||
return m_speedMap[m_speedFactor];
|
||||
}
|
||||
|
||||
double speedFactor() const
|
||||
{
|
||||
return m_speedFactor;
|
||||
}
|
||||
void setSpeedFactor(double factor)
|
||||
{
|
||||
m_speedFactor = factor;
|
||||
}
|
||||
|
||||
QString altitudeUnit() const
|
||||
{
|
||||
return m_altitudeMap[m_altitudeFactor];
|
||||
}
|
||||
|
||||
double altitudeFactor() const
|
||||
{
|
||||
return m_altitudeFactor;
|
||||
}
|
||||
void setAltitudeFactor(double factor)
|
||||
{
|
||||
m_altitudeFactor = factor;
|
||||
}
|
||||
|
||||
bool terrainEnabled() const
|
||||
{
|
||||
return m_terrainEnabled;
|
||||
}
|
||||
void setTerrainEnabled(bool flag)
|
||||
{
|
||||
m_terrainEnabled = flag;
|
||||
}
|
||||
|
||||
QString terrainFile() const
|
||||
{
|
||||
return m_terrainFile;
|
||||
}
|
||||
void setTerrainFile(const QString &fileName)
|
||||
{
|
||||
m_terrainFile = fileName;
|
||||
}
|
||||
|
||||
|
||||
double latitude() const
|
||||
{
|
||||
return m_latitude;
|
||||
}
|
||||
void setLatitude(double value)
|
||||
{
|
||||
m_latitude = value;
|
||||
}
|
||||
|
||||
double longitude() const
|
||||
{
|
||||
return m_longitude;
|
||||
}
|
||||
void setLongitude(double value)
|
||||
{
|
||||
m_longitude = value;
|
||||
}
|
||||
|
||||
double altitude() const
|
||||
{
|
||||
return m_altitude;
|
||||
}
|
||||
void setAltitude(double value)
|
||||
{
|
||||
m_altitude = value;
|
||||
}
|
||||
|
||||
void setCacheOnly(bool flag)
|
||||
{
|
||||
m_cacheOnly = flag;
|
||||
}
|
||||
bool cacheOnly() const
|
||||
{
|
||||
return m_cacheOnly;
|
||||
}
|
||||
|
||||
Pfd::TimeMode timeMode() const
|
||||
{
|
||||
return m_timeMode;
|
||||
}
|
||||
void setTimeMode(Pfd::TimeMode timeMode)
|
||||
{
|
||||
m_timeMode = timeMode;
|
||||
}
|
||||
|
||||
QDateTime dateTime() const
|
||||
{
|
||||
return m_dateTime;
|
||||
}
|
||||
void setDateTime(QDateTime &dateTime)
|
||||
{
|
||||
m_dateTime = dateTime;
|
||||
}
|
||||
|
||||
double minAmbientLight() const
|
||||
{
|
||||
return m_minAmbientLight;
|
||||
}
|
||||
void setMinAmbientLight(double minAmbientLight)
|
||||
{
|
||||
m_minAmbientLight = minAmbientLight;
|
||||
}
|
||||
|
||||
bool modelEnabled() const
|
||||
{
|
||||
return m_modelEnabled;
|
||||
}
|
||||
void setModelEnabled(bool flag)
|
||||
{
|
||||
m_modelEnabled = flag;
|
||||
}
|
||||
|
||||
QString modelFile() const
|
||||
{
|
||||
return m_modelFile;
|
||||
}
|
||||
void setModelFile(const QString &fileName)
|
||||
{
|
||||
m_modelFile = fileName;
|
||||
}
|
||||
|
||||
Pfd::ModelSelectionMode modelSelectionMode() const
|
||||
{
|
||||
return m_modelSelectionMode;
|
||||
}
|
||||
void setModelSelectionMode(Pfd::ModelSelectionMode modelSelectionMode)
|
||||
{
|
||||
m_modelSelectionMode = modelSelectionMode;
|
||||
}
|
||||
|
||||
QString backgroundImageFile() const
|
||||
{
|
||||
return m_backgroundImageFile;
|
||||
}
|
||||
void setBackgroundImageFile(const QString &fileName)
|
||||
{
|
||||
m_backgroundImageFile = fileName;
|
||||
}
|
||||
|
||||
QMapIterator<double, QString> speedMapIterator()
|
||||
{
|
||||
return QMapIterator<double, QString>(m_speedMap);
|
||||
@ -142,18 +211,30 @@ public:
|
||||
|
||||
private:
|
||||
QString m_qmlFile; // The name of the dial's SVG source file
|
||||
QString m_earthFile; // The name of osgearth terrain file
|
||||
bool m_openGLEnabled;
|
||||
|
||||
double m_speedFactor;
|
||||
double m_altitudeFactor;
|
||||
|
||||
bool m_terrainEnabled;
|
||||
bool m_actualPositionUsed;
|
||||
QString m_terrainFile; // The name of osgearth terrain file
|
||||
bool m_cacheOnly;
|
||||
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
double m_altitude;
|
||||
bool m_cacheOnly;
|
||||
double m_speedFactor;
|
||||
double m_altitudeFactor;
|
||||
|
||||
Pfd::TimeMode m_timeMode;
|
||||
QDateTime m_dateTime;
|
||||
double m_minAmbientLight;
|
||||
|
||||
bool m_modelEnabled;
|
||||
QString m_modelFile; // The name of model file
|
||||
Pfd::ModelSelectionMode m_modelSelectionMode;
|
||||
|
||||
QString m_backgroundImageFile;
|
||||
|
||||
QMap<double, QString> m_speedMap;
|
||||
QMap<double, QString> m_altitudeMap;
|
||||
};
|
||||
|
||||
#endif // PfdQmlGADGETCONFIGURATION_H
|
||||
#endif // PFDQMLGADGETCONFIGURATION_H
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetfactory.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -13,8 +24,8 @@
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "pfdqmlgadgetfactory.h"
|
||||
#include "pfdqmlgadgetwidget.h"
|
||||
#include "pfdqmlgadget.h"
|
||||
#include "pfdqmlgadgetconfiguration.h"
|
||||
#include "pfdqmlgadgetoptionspage.h"
|
||||
@ -31,9 +42,7 @@ PfdQmlGadgetFactory::~PfdQmlGadgetFactory()
|
||||
|
||||
Core::IUAVGadget *PfdQmlGadgetFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
PfdQmlGadgetWidget *gadgetWidget = new PfdQmlGadgetWidget();
|
||||
|
||||
return new PfdQmlGadget(QString("PfdQmlGadget"), gadgetWidget, parent);
|
||||
return new PfdQmlGadget(QString("PfdQmlGadget"), parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *PfdQmlGadgetFactory::createConfiguration(QSettings *qSettings)
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetfactory.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -37,4 +48,4 @@ public:
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // PfdQmlGADGETFACTORY_H_
|
||||
#endif // PFDQMLGADGETFACTORY_H_
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetoptionspage.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -21,14 +32,12 @@
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavdataobject.h"
|
||||
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QtAlgorithms>
|
||||
#include <QStringList>
|
||||
|
||||
PfdQmlGadgetOptionsPage::PfdQmlGadgetOptionsPage(PfdQmlGadgetConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
IOptionsPage(parent), options_page(NULL), m_config(config)
|
||||
{}
|
||||
|
||||
// creates options page widget (uses the UI file)
|
||||
@ -40,29 +49,13 @@ QWidget *PfdQmlGadgetOptionsPage::createPage(QWidget *parent)
|
||||
// main layout
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
// Restore the contents from the settings:
|
||||
// QML file chooser
|
||||
options_page->qmlSourceFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->qmlSourceFile->setPromptDialogFilter(tr("QML file (*.qml)"));
|
||||
options_page->qmlSourceFile->setPromptDialogTitle(tr("Choose QML file"));
|
||||
options_page->qmlSourceFile->setPromptDialogTitle(tr("Choose QML File"));
|
||||
options_page->qmlSourceFile->setPath(m_config->qmlFile());
|
||||
|
||||
// Restore the contents from the settings:
|
||||
options_page->earthFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->earthFile->setPromptDialogFilter(tr("OsgEarth (*.earth)"));
|
||||
options_page->earthFile->setPromptDialogTitle(tr("Choose OsgEarth terrain file"));
|
||||
options_page->earthFile->setPath(m_config->earthFile());
|
||||
|
||||
options_page->useOpenGL->setChecked(m_config->openGLEnabled());
|
||||
options_page->showTerrain->setChecked(m_config->terrainEnabled());
|
||||
|
||||
options_page->useActualLocation->setChecked(m_config->actualPositionUsed());
|
||||
options_page->usePredefinedLocation->setChecked(!m_config->actualPositionUsed());
|
||||
options_page->latitude->setText(QString::number(m_config->latitude()));
|
||||
options_page->longitude->setText(QString::number(m_config->longitude()));
|
||||
options_page->altitude->setText(QString::number(m_config->altitude()));
|
||||
options_page->useOnlyCache->setChecked(m_config->cacheOnly());
|
||||
|
||||
// Setup units combos
|
||||
// Speed Unit combo
|
||||
QMapIterator<double, QString> iter = m_config->speedMapIterator();
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
@ -70,6 +63,7 @@ QWidget *PfdQmlGadgetOptionsPage::createPage(QWidget *parent)
|
||||
}
|
||||
options_page->speedUnitCombo->setCurrentIndex(options_page->speedUnitCombo->findData(m_config->speedFactor()));
|
||||
|
||||
// Altitude Unit combo
|
||||
iter = m_config->altitudeMapIterator();
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
@ -77,11 +71,54 @@ QWidget *PfdQmlGadgetOptionsPage::createPage(QWidget *parent)
|
||||
}
|
||||
options_page->altUnitCombo->setCurrentIndex(options_page->altUnitCombo->findData(m_config->altitudeFactor()));
|
||||
|
||||
// Terrain check boxes
|
||||
options_page->showTerrain->setChecked(m_config->terrainEnabled());
|
||||
|
||||
// Terrain file chooser
|
||||
options_page->earthFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->earthFile->setPromptDialogFilter(tr("OsgEarth (*.earth)"));
|
||||
options_page->earthFile->setPromptDialogTitle(tr("Choose Terrain File"));
|
||||
options_page->earthFile->setPath(m_config->terrainFile());
|
||||
|
||||
// Terrain position
|
||||
options_page->latitude->setText(QString::number(m_config->latitude()));
|
||||
options_page->longitude->setText(QString::number(m_config->longitude()));
|
||||
options_page->altitude->setText(QString::number(m_config->altitude()));
|
||||
|
||||
options_page->useOnlyCache->setChecked(m_config->cacheOnly());
|
||||
|
||||
// Sky options
|
||||
options_page->useLocalTime->setChecked(m_config->timeMode() == Pfd::Local);
|
||||
options_page->usePredefinedTime->setChecked(m_config->timeMode() == Pfd::PredefinedTime);
|
||||
options_page->dateEdit->setDate(m_config->dateTime().date());
|
||||
options_page->timeEdit->setTime(m_config->dateTime().time());
|
||||
options_page->minAmbientLightSpinBox->setValue(m_config->minAmbientLight());
|
||||
|
||||
// Model check boxes
|
||||
options_page->showModel->setChecked(m_config->modelEnabled());
|
||||
options_page->useAutomaticModel->setChecked(m_config->modelSelectionMode() == Pfd::Auto);
|
||||
options_page->usePredefinedModel->setChecked(m_config->modelSelectionMode() == Pfd::Fixed);
|
||||
|
||||
// Model file chooser
|
||||
options_page->modelFile->setExpectedKind(Utils::PathChooser::File);
|
||||
options_page->modelFile->setPromptDialogFilter(tr("Model file (*.3ds)"));
|
||||
options_page->modelFile->setPromptDialogTitle(tr("Choose Model File"));
|
||||
options_page->modelFile->setPath(m_config->modelFile());
|
||||
|
||||
// Background image chooser
|
||||
options_page->backgroundImageFile->setExpectedKind(Utils::PathChooser::File);
|
||||
// options_page->backgroundImageFile->setPromptDialogFilter(tr("Image file"));
|
||||
options_page->backgroundImageFile->setPromptDialogTitle(tr("Choose Background Image File"));
|
||||
options_page->backgroundImageFile->setPath(m_config->backgroundImageFile());
|
||||
|
||||
#ifndef USE_OSG
|
||||
options_page->showTerrain->setChecked(false);
|
||||
options_page->showTerrain->setVisible(false);
|
||||
#endif
|
||||
|
||||
QObject::connect(options_page->actualizeDateTimeButton, SIGNAL(clicked()),
|
||||
this, SLOT(actualizeDateTime()));
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
@ -94,24 +131,54 @@ QWidget *PfdQmlGadgetOptionsPage::createPage(QWidget *parent)
|
||||
void PfdQmlGadgetOptionsPage::apply()
|
||||
{
|
||||
m_config->setQmlFile(options_page->qmlSourceFile->path());
|
||||
m_config->setEarthFile(options_page->earthFile->path());
|
||||
m_config->setOpenGLEnabled(options_page->useOpenGL->isChecked());
|
||||
|
||||
m_config->setSpeedFactor(options_page->speedUnitCombo->itemData(options_page->speedUnitCombo->currentIndex()).toDouble());
|
||||
m_config->setAltitudeFactor(options_page->altUnitCombo->itemData(options_page->altUnitCombo->currentIndex()).toDouble());
|
||||
|
||||
#ifdef USE_OSG
|
||||
m_config->setTerrainEnabled(options_page->showTerrain->isChecked());
|
||||
#else
|
||||
m_config->setTerrainEnabled(false);
|
||||
#endif
|
||||
m_config->setTerrainFile(options_page->earthFile->path());
|
||||
|
||||
m_config->setActualPositionUsed(options_page->useActualLocation->isChecked());
|
||||
m_config->setLatitude(options_page->latitude->text().toDouble());
|
||||
m_config->setLongitude(options_page->longitude->text().toDouble());
|
||||
m_config->setAltitude(options_page->altitude->text().toDouble());
|
||||
m_config->setCacheOnly(options_page->useOnlyCache->isChecked());
|
||||
|
||||
m_config->setSpeedFactor(options_page->speedUnitCombo->itemData(options_page->speedUnitCombo->currentIndex()).toDouble());
|
||||
m_config->setAltitudeFactor(options_page->altUnitCombo->itemData(options_page->altUnitCombo->currentIndex()).toDouble());
|
||||
if (options_page->useLocalTime->isChecked()) {
|
||||
m_config->setTimeMode(Pfd::Local);
|
||||
} else {
|
||||
m_config->setTimeMode(Pfd::PredefinedTime);
|
||||
}
|
||||
QDateTime dateTime(options_page->dateEdit->date(), options_page->timeEdit->time());
|
||||
m_config->setDateTime(dateTime);
|
||||
m_config->setMinAmbientLight(options_page->minAmbientLightSpinBox->value());
|
||||
|
||||
#else // ifdef USE_OSG
|
||||
m_config->setTerrainEnabled(false);
|
||||
#endif // ifdef USE_OSG
|
||||
|
||||
#ifdef USE_OSG
|
||||
m_config->setModelEnabled(options_page->showModel->isChecked());
|
||||
m_config->setModelFile(options_page->modelFile->path());
|
||||
|
||||
if (options_page->useAutomaticModel->isChecked()) {
|
||||
m_config->setModelSelectionMode(Pfd::Auto);
|
||||
} else {
|
||||
m_config->setModelSelectionMode(Pfd::Fixed);
|
||||
}
|
||||
m_config->setBackgroundImageFile(options_page->backgroundImageFile->path());
|
||||
#else
|
||||
m_config->setModelEnabled(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PfdQmlGadgetOptionsPage::finish()
|
||||
{}
|
||||
|
||||
void PfdQmlGadgetOptionsPage::actualizeDateTime()
|
||||
{
|
||||
QDateTime dateTime = QDateTime::currentDateTime();
|
||||
|
||||
options_page->dateEdit->setDate(dateTime.date());
|
||||
options_page->timeEdit->setTime(dateTime.time());
|
||||
}
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetoptionspage.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -43,6 +54,9 @@ public:
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
private slots:
|
||||
void actualizeDateTime();
|
||||
|
||||
private:
|
||||
Ui::PfdQmlGadgetOptionsPage *options_page;
|
||||
PfdQmlGadgetConfiguration *m_config;
|
||||
@ -50,4 +64,4 @@ private:
|
||||
private slots:
|
||||
};
|
||||
|
||||
#endif // PfdQmlGADGETOPTIONSPAGE_H
|
||||
#endif // PFDQMLGADGETOPTIONSPAGE_H
|
||||
|
@ -20,7 +20,16 @@
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -44,7 +53,16 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -56,7 +74,7 @@
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
@ -78,33 +96,23 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="useOpenGL">
|
||||
<property name="text">
|
||||
<string>Use OpenGL</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_2">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Speed Unit:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Altitude Unit:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Speed Unit:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="speedUnitCombo">
|
||||
<widget class="QComboBox" name="altUnitCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
@ -114,7 +122,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="altUnitCombo">
|
||||
<widget class="QComboBox" name="speedUnitCombo">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>150</width>
|
||||
@ -126,154 +134,385 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="showTerrain">
|
||||
<property name="title">
|
||||
<string>Show Terrain:</string>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="4">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>OsgEarth file:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Utils::PathChooser" name="earthFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QRadioButton" name="useActualLocation">
|
||||
<property name="text">
|
||||
<string>Use actual location</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QRadioButton" name="usePredefinedLocation">
|
||||
<property name="text">
|
||||
<string>Use pre-defined location:</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="3">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Latitude:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="latitude"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Longitude:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="longitude"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Altitude:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="altitude"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="useOnlyCache">
|
||||
<property name="text">
|
||||
<string>Use only cache data</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>74</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QPushButton" name="preSeedTerrain">
|
||||
<property name="text">
|
||||
<string>Pre seed terrain cache</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Terrain</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="showTerrain">
|
||||
<property name="title">
|
||||
<string>Show Terrain</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Terrain file:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Utils::PathChooser" name="earthFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="toolTip">
|
||||
<string>This location will be used if no GPS fix or Home location are available</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Default Location</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Latitude:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="latitude"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Longitude:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="longitude"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Altitude:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="altitude"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="useOnlyCache">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use only cache data</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>74</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="preSeedTerrain">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Pre seed terrain cache</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>121</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Model</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="showModel">
|
||||
<property name="title">
|
||||
<string>Show Model</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useAutomaticModel">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use automatic model selection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="usePredefinedModel">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use this model:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="Utils::PathChooser" name="modelFile" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Background image:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Utils::PathChooser" name="backgroundImageFile" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Environment</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Time</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useLocalTime">
|
||||
<property name="text">
|
||||
<string>Use local time</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="usePredefinedTime">
|
||||
<property name="text">
|
||||
<string>Use this time:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDateEdit" name="dateEdit">
|
||||
<property name="calendarPopup">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTimeEdit" name="timeEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="actualizeDateTimeButton">
|
||||
<property name="text">
|
||||
<string>Actualize</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Minimum ambient light:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="minAmbientLightSpinBox">
|
||||
<property name="maximum">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.030000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>121</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
@ -284,75 +523,10 @@
|
||||
<customwidget>
|
||||
<class>Utils::PathChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>utils/pathchooser.h</header>
|
||||
<header location="global">utils/pathchooser.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>usePredefinedLocation</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>latitude</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>167</x>
|
||||
<y>188</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>260</x>
|
||||
<y>222</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>usePredefinedLocation</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>longitude</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>181</x>
|
||||
<y>188</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>282</x>
|
||||
<y>255</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>usePredefinedLocation</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>altitude</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>207</x>
|
||||
<y>188</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>308</x>
|
||||
<y>288</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>useOpenGL</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>showTerrain</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>99</x>
|
||||
<y>57</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>99</x>
|
||||
<y>89</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetwidget.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -15,226 +26,138 @@
|
||||
*/
|
||||
|
||||
#include "pfdqmlgadgetwidget.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "uavobject.h"
|
||||
#include "flightbatterysettings.h"
|
||||
#include "utils/svgimageprovider.h"
|
||||
#ifdef USE_OSG
|
||||
#include "osgearth.h"
|
||||
#endif
|
||||
#include <QDebug>
|
||||
#include <QSvgRenderer>
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include <QtCore/qdir.h>
|
||||
#include <QMouseEvent>
|
||||
#include "pfdqmlcontext.h"
|
||||
|
||||
#include "utils/quickwidgetproxy.h"
|
||||
#include "utils/svgimageprovider.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QStackedLayout>
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QDebug>
|
||||
|
||||
PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWindow *parent) :
|
||||
QQuickView(parent),
|
||||
m_openGLEnabled(false),
|
||||
m_terrainEnabled(false),
|
||||
m_actualPositionUsed(false),
|
||||
m_latitude(46.671478),
|
||||
m_longitude(10.158932),
|
||||
m_altitude(2000),
|
||||
m_speedUnit("m/s"),
|
||||
m_speedFactor(1.0),
|
||||
m_altitudeUnit("m"),
|
||||
m_altitudeFactor(1.0)
|
||||
PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWidget *parent) :
|
||||
QWidget(parent), m_quickWidgetProxy(NULL), m_pfdQmlContext(NULL), m_qmlFileName()
|
||||
{
|
||||
setResizeMode(SizeRootObjectToView);
|
||||
|
||||
// setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||
|
||||
QStringList objectsToExport;
|
||||
objectsToExport <<
|
||||
"VelocityState" <<
|
||||
"PositionState" <<
|
||||
"AttitudeState" <<
|
||||
"AccelState" <<
|
||||
"VelocityDesired" <<
|
||||
"PathDesired" <<
|
||||
"AltitudeHoldDesired" <<
|
||||
"GPSPositionSensor" <<
|
||||
"GPSSatellites" <<
|
||||
"GCSTelemetryStats" <<
|
||||
"SystemAlarms" <<
|
||||
"NedAccel" <<
|
||||
"FlightBatteryState" <<
|
||||
"ActuatorDesired" <<
|
||||
"TakeOffLocation" <<
|
||||
"PathPlan" <<
|
||||
"WaypointActive" <<
|
||||
"OPLinkStatus" <<
|
||||
"FlightStatus" <<
|
||||
"SystemStats" <<
|
||||
"StabilizationDesired" <<
|
||||
"VtolPathFollowerSettings" <<
|
||||
"HwSettings" <<
|
||||
"ManualControlCommand" <<
|
||||
"SystemSettings" <<
|
||||
"RevoSettings" <<
|
||||
"MagState" <<
|
||||
"FlightBatterySettings" <<
|
||||
"ReceiverStatus";
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
m_uavoManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(m_uavoManager);
|
||||
|
||||
foreach(const QString &objectName, objectsToExport) {
|
||||
UAVObject *object = objManager->getObject(objectName);
|
||||
|
||||
if (object) {
|
||||
engine()->rootContext()->setContextProperty(objectName, object);
|
||||
} else {
|
||||
qWarning() << "Failed to load object" << objectName;
|
||||
}
|
||||
}
|
||||
|
||||
// to expose settings values
|
||||
engine()->rootContext()->setContextProperty("qmlWidget", this);
|
||||
#ifdef USE_OSG
|
||||
qmlRegisterType<OsgEarthItem>("org.OpenPilot", 1, 0, "OsgEarth");
|
||||
#endif
|
||||
setLayout(new QStackedLayout());
|
||||
}
|
||||
|
||||
PfdQmlGadgetWidget::~PfdQmlGadgetWidget()
|
||||
{}
|
||||
{
|
||||
if (m_pfdQmlContext) {
|
||||
delete m_pfdQmlContext;
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::init()
|
||||
{
|
||||
m_quickWidgetProxy = new QuickWidgetProxy(this);
|
||||
|
||||
#if 0
|
||||
qDebug() << "PfdQmlGadgetWidget::PfdQmlGadgetWidget - persistent OpenGL context" << isPersistentOpenGLContext();
|
||||
qDebug() << "PfdQmlGadgetWidget::PfdQmlGadgetWidget - persistent scene graph" << isPersistentSceneGraph();
|
||||
#endif
|
||||
|
||||
// to expose settings values
|
||||
m_pfdQmlContext = new PfdQmlContext(this);
|
||||
m_pfdQmlContext->apply(engine()->rootContext());
|
||||
|
||||
// connect(this, &QQuickWidget::statusChanged, this, &PfdQmlGadgetWidget::onStatusChanged);
|
||||
// connect(this, &QQuickWidget::sceneGraphError, this, &PfdQmlGadgetWidget::onSceneGraphError);
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setSource(const QUrl &url)
|
||||
{
|
||||
m_quickWidgetProxy->setSource(url);
|
||||
}
|
||||
|
||||
QQmlEngine *PfdQmlGadgetWidget::engine() const
|
||||
{
|
||||
return m_quickWidgetProxy->engine();
|
||||
}
|
||||
|
||||
QList<QQmlError> PfdQmlGadgetWidget::errors() const
|
||||
{
|
||||
return m_quickWidgetProxy->errors();
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::loadConfiguration(PfdQmlGadgetConfiguration *config)
|
||||
{
|
||||
qDebug() << "PfdQmlGadgetWidget::loadConfiguration" << config->name();
|
||||
|
||||
QuickWidgetProxy *oldQuickWidgetProxy = NULL;
|
||||
PfdQmlContext *oldPfdQmlContext = NULL;
|
||||
if (m_quickWidgetProxy) {
|
||||
oldQuickWidgetProxy = m_quickWidgetProxy;
|
||||
oldPfdQmlContext = m_pfdQmlContext;
|
||||
m_quickWidgetProxy = NULL;
|
||||
m_pfdQmlContext = NULL;
|
||||
}
|
||||
|
||||
if (!m_quickWidgetProxy) {
|
||||
init();
|
||||
}
|
||||
|
||||
// here we first clear the Qml file
|
||||
// then set all the properties
|
||||
// and finally set the desired Qml file
|
||||
// TODO this is a work around... some OSG Quick items don't yet handle properties updates well
|
||||
|
||||
// clear widget
|
||||
// setQmlFile("");
|
||||
|
||||
// no need to go further is Qml file is empty
|
||||
// if (config->qmlFile().isEmpty()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
m_pfdQmlContext->loadConfiguration(config);
|
||||
|
||||
// go!
|
||||
setQmlFile(config->qmlFile());
|
||||
|
||||
// deleting and recreating the PfdQmlGadgetWidget is workaround to avoid crashes in osgearth when
|
||||
// switching between configurations. Please remove this workaround once osgearth is stabilized
|
||||
if (oldQuickWidgetProxy) {
|
||||
layout()->removeWidget(oldQuickWidgetProxy->widget());
|
||||
delete oldQuickWidgetProxy;
|
||||
delete oldPfdQmlContext;
|
||||
}
|
||||
layout()->addWidget(m_quickWidgetProxy->widget());
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setQmlFile(QString fn)
|
||||
{
|
||||
// if (m_qmlFileName == fn) {
|
||||
// return;
|
||||
// }
|
||||
qDebug() << Q_FUNC_INFO << fn;
|
||||
|
||||
m_qmlFileName = fn;
|
||||
|
||||
engine()->removeImageProvider("svg");
|
||||
SvgImageProvider *svgProvider = new SvgImageProvider(fn);
|
||||
engine()->addImageProvider("svg", svgProvider);
|
||||
if (fn.isEmpty()) {
|
||||
setSource(QUrl());
|
||||
|
||||
engine()->clearComponentCache();
|
||||
engine()->removeImageProvider("svg");
|
||||
engine()->rootContext()->setContextProperty("svgRenderer", NULL);
|
||||
|
||||
// it's necessary to allow qml side to query svg element position
|
||||
engine()->rootContext()->setContextProperty("svgRenderer", svgProvider);
|
||||
engine()->setBaseUrl(QUrl::fromLocalFile(fn));
|
||||
// calling clearComponentCache() causes crashes (see https://bugreports.qt-project.org/browse/QTBUG-41465)
|
||||
// but not doing it causes almost systematic crashes when switching PFD gadget to "Model View (Without Terrain)" configuration
|
||||
engine()->clearComponentCache();
|
||||
} else {
|
||||
SvgImageProvider *svgProvider = new SvgImageProvider(fn);
|
||||
engine()->addImageProvider("svg", svgProvider);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << fn;
|
||||
setSource(QUrl::fromLocalFile(fn));
|
||||
// it's necessary to allow qml side to query svg element position
|
||||
engine()->rootContext()->setContextProperty("svgRenderer", svgProvider);
|
||||
|
||||
QUrl url = QUrl::fromLocalFile(fn);
|
||||
engine()->setBaseUrl(url);
|
||||
setSource(url);
|
||||
}
|
||||
|
||||
foreach(const QQmlError &error, errors()) {
|
||||
qDebug() << error.description();
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::resetConsumedEnergy()
|
||||
{
|
||||
FlightBatterySettings *mBatterySettings = FlightBatterySettings::GetInstance(m_uavoManager);
|
||||
|
||||
mBatterySettings->setResetConsumedEnergy(true);
|
||||
mBatterySettings->setData(mBatterySettings->getData());
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setEarthFile(QString arg)
|
||||
{
|
||||
if (m_earthFile != arg) {
|
||||
m_earthFile = arg;
|
||||
emit earthFileChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setTerrainEnabled(bool arg)
|
||||
{
|
||||
bool wasEnabled = terrainEnabled();
|
||||
|
||||
m_terrainEnabled = arg;
|
||||
|
||||
if (wasEnabled != terrainEnabled()) {
|
||||
emit terrainEnabledChanged(terrainEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setSpeedUnit(QString unit)
|
||||
{
|
||||
if (m_speedUnit != unit) {
|
||||
m_speedUnit = unit;
|
||||
emit speedUnitChanged(unit);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setSpeedFactor(double factor)
|
||||
{
|
||||
if (m_speedFactor != factor) {
|
||||
m_speedFactor = factor;
|
||||
emit speedFactorChanged(factor);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setAltitudeUnit(QString unit)
|
||||
{
|
||||
if (m_altitudeUnit != unit) {
|
||||
m_altitudeUnit = unit;
|
||||
emit altitudeUnitChanged(unit);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setAltitudeFactor(double factor)
|
||||
{
|
||||
if (m_altitudeFactor != factor) {
|
||||
m_altitudeFactor = factor;
|
||||
emit altitudeFactorChanged(factor);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setOpenGLEnabled(bool arg)
|
||||
{
|
||||
Q_UNUSED(arg);
|
||||
setTerrainEnabled(m_terrainEnabled);
|
||||
}
|
||||
|
||||
// Switch between PositionState UAVObject position
|
||||
// and pre-defined latitude/longitude/altitude properties
|
||||
void PfdQmlGadgetWidget::setActualPositionUsed(bool arg)
|
||||
{
|
||||
if (m_actualPositionUsed != arg) {
|
||||
m_actualPositionUsed = arg;
|
||||
emit actualPositionUsedChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
// Reload the schene on the middle mouse button click.
|
||||
if (event->button() == Qt::MiddleButton) {
|
||||
setQmlFile(m_qmlFileName);
|
||||
}
|
||||
|
||||
QQuickView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setLatitude(double arg)
|
||||
{
|
||||
// not sure qFuzzyCompare is accurate enough for geo coordinates
|
||||
if (m_latitude != arg) {
|
||||
m_latitude = arg;
|
||||
emit latitudeChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setLongitude(double arg)
|
||||
{
|
||||
if (m_longitude != arg) {
|
||||
m_longitude = arg;
|
||||
emit longitudeChanged(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void PfdQmlGadgetWidget::setAltitude(double arg)
|
||||
{
|
||||
if (!qFuzzyCompare(m_altitude, arg)) {
|
||||
m_altitude = arg;
|
||||
emit altitudeChanged(arg);
|
||||
qDebug() << "PfdQmlGadgetWidget - " << error.description();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlgadgetwidget.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -17,126 +28,37 @@
|
||||
#ifndef PFDQMLGADGETWIDGET_H_
|
||||
#define PFDQMLGADGETWIDGET_H_
|
||||
|
||||
#include "pfdqml.h"
|
||||
#include "pfdqmlgadgetconfiguration.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include <QQuickView>
|
||||
|
||||
class PfdQmlGadgetWidget : public QQuickView {
|
||||
Q_OBJECT Q_PROPERTY(QString earthFile READ earthFile WRITE setEarthFile NOTIFY earthFileChanged)
|
||||
Q_PROPERTY(bool terrainEnabled READ terrainEnabled WRITE setTerrainEnabled NOTIFY terrainEnabledChanged)
|
||||
#include <QWidget>
|
||||
|
||||
Q_PROPERTY(bool actualPositionUsed READ actualPositionUsed WRITE setActualPositionUsed NOTIFY actualPositionUsedChanged)
|
||||
class QQmlEngine;
|
||||
class QuickWidgetProxy;
|
||||
class PfdQmlContext;
|
||||
|
||||
Q_PROPERTY(QString speedUnit READ speedUnit WRITE setSpeedUnit NOTIFY speedUnitChanged)
|
||||
Q_PROPERTY(double speedFactor READ speedFactor WRITE setSpeedFactor NOTIFY speedFactorChanged)
|
||||
Q_PROPERTY(QString altitudeUnit READ altitudeUnit WRITE setAltitudeUnit NOTIFY altitudeUnitChanged)
|
||||
Q_PROPERTY(double altitudeFactor READ altitudeFactor WRITE setAltitudeFactor NOTIFY altitudeFactorChanged)
|
||||
|
||||
// pre-defined fallback position
|
||||
Q_PROPERTY(double latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged)
|
||||
Q_PROPERTY(double longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged)
|
||||
Q_PROPERTY(double altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged)
|
||||
class PfdQmlGadgetWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PfdQmlGadgetWidget(QWindow *parent = 0);
|
||||
~PfdQmlGadgetWidget();
|
||||
void setQmlFile(QString fn);
|
||||
PfdQmlGadgetWidget(QWidget *parent = 0);
|
||||
virtual ~PfdQmlGadgetWidget();
|
||||
|
||||
QString earthFile() const
|
||||
{
|
||||
return m_earthFile;
|
||||
}
|
||||
bool terrainEnabled() const
|
||||
{
|
||||
return m_terrainEnabled && m_openGLEnabled;
|
||||
}
|
||||
|
||||
QString speedUnit() const
|
||||
{
|
||||
return m_speedUnit;
|
||||
}
|
||||
double speedFactor() const
|
||||
{
|
||||
return m_speedFactor;
|
||||
}
|
||||
QString altitudeUnit() const
|
||||
{
|
||||
return m_altitudeUnit;
|
||||
}
|
||||
double altitudeFactor() const
|
||||
{
|
||||
return m_altitudeFactor;
|
||||
}
|
||||
|
||||
bool actualPositionUsed() const
|
||||
{
|
||||
return m_actualPositionUsed;
|
||||
}
|
||||
double latitude() const
|
||||
{
|
||||
return m_latitude;
|
||||
}
|
||||
double longitude() const
|
||||
{
|
||||
return m_longitude;
|
||||
}
|
||||
double altitude() const
|
||||
{
|
||||
return m_altitude;
|
||||
}
|
||||
|
||||
Q_INVOKABLE void resetConsumedEnergy();
|
||||
|
||||
public slots:
|
||||
void setEarthFile(QString arg);
|
||||
void setTerrainEnabled(bool arg);
|
||||
|
||||
void setSpeedUnit(QString unit);
|
||||
void setSpeedFactor(double factor);
|
||||
void setAltitudeUnit(QString unit);
|
||||
void setAltitudeFactor(double factor);
|
||||
|
||||
void setOpenGLEnabled(bool arg);
|
||||
|
||||
void setLatitude(double arg);
|
||||
void setLongitude(double arg);
|
||||
void setAltitude(double arg);
|
||||
|
||||
void setActualPositionUsed(bool arg);
|
||||
|
||||
signals:
|
||||
void earthFileChanged(QString arg);
|
||||
void terrainEnabledChanged(bool arg);
|
||||
|
||||
void actualPositionUsedChanged(bool arg);
|
||||
void latitudeChanged(double arg);
|
||||
void longitudeChanged(double arg);
|
||||
void altitudeChanged(double arg);
|
||||
|
||||
void speedUnitChanged(QString arg);
|
||||
void speedFactorChanged(double arg);
|
||||
void altitudeUnitChanged(QString arg);
|
||||
void altitudeFactorChanged(double arg);
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void loadConfiguration(PfdQmlGadgetConfiguration *config);
|
||||
|
||||
private:
|
||||
UAVObjectManager *m_uavoManager;
|
||||
void init();
|
||||
|
||||
void setQmlFile(QString);
|
||||
|
||||
void setSource(const QUrl &url);
|
||||
QQmlEngine *engine() const;
|
||||
QList<QQmlError> errors() const;
|
||||
|
||||
QuickWidgetProxy *m_quickWidgetProxy;
|
||||
|
||||
PfdQmlContext *m_pfdQmlContext;
|
||||
QString m_qmlFileName;
|
||||
QString m_earthFile;
|
||||
bool m_openGLEnabled;
|
||||
bool m_terrainEnabled;
|
||||
|
||||
bool m_actualPositionUsed;
|
||||
double m_latitude;
|
||||
double m_longitude;
|
||||
double m_altitude;
|
||||
|
||||
QString m_speedUnit;
|
||||
double m_speedFactor;
|
||||
QString m_altitudeUnit;
|
||||
double m_altitudeFactor;
|
||||
};
|
||||
|
||||
#endif /* PFDQMLGADGETWIDGET_H_ */
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlplugin.cpp
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -14,13 +25,17 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "pfdqml.h"
|
||||
#include "pfdqmlplugin.h"
|
||||
#include "pfdqmlgadgetfactory.h"
|
||||
#include <QDebug>
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#ifdef USE_OSG
|
||||
#include <osgearth/osgearth.h>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
PfdQmlPlugin::PfdQmlPlugin()
|
||||
{
|
||||
@ -36,7 +51,17 @@ bool PfdQmlPlugin::initialize(const QStringList & args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new PfdQmlGadgetFactory(this);
|
||||
|
||||
#ifdef USE_OSG
|
||||
// TODO get rid of this call...
|
||||
// this is the only place that references osgearth
|
||||
// if this code goes away then the dependency to osgearth should be removed from pfdqml_dependencies.pri
|
||||
OsgEarth::registerQmlTypes();
|
||||
#endif
|
||||
|
||||
Pfd::declareQML();
|
||||
|
||||
PfdQmlGadgetFactory *mf = new PfdQmlGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pfdqmlplugin.h
|
||||
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @addtogroup
|
||||
* @{
|
||||
* @brief
|
||||
*****************************************************************************//*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
@ -32,8 +43,6 @@ public:
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList &arguments, QString *errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
PfdQmlGadgetFactory *mf;
|
||||
};
|
||||
|
||||
#endif /* PFDQMLPLUGIN_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user