Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / qmlview / qmlviewgadgetwidget.cpp
blob813061aa2da627e479403473d1c6d1a2fea6f4d6
1 /**
2 ******************************************************************************
4 * @file qmlviewgadgetwidget.cpp
5 * @author Edouard Lafargue Copyright (C) 2010.
6 * @author Dmytro Poplavskiy Copyright (C) 2012.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup OPMapPlugin QML Viewer Plugin
10 * @{
11 * @brief The QML Viewer Gadget
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "qmlviewgadgetwidget.h"
30 #include "extensionsystem/pluginmanager.h"
31 #include "uavobjectmanager.h"
32 #include "uavobject.h"
33 #include "utils/svgimageprovider.h"
35 #include <QDebug>
36 #include <QSvgRenderer>
37 #include <QtCore/qfileinfo.h>
38 #include <QtCore/qdir.h>
40 #include <QQmlEngine>
41 #include <QQmlContext>
43 QmlViewGadgetWidget::QmlViewGadgetWidget(QWindow *parent) :
44 QQuickView(parent)
46 setResizeMode(SizeRootObjectToView);
48 QStringList objectsToExport;
49 objectsToExport << "VelocityState" <<
50 "PositionState" <<
51 "AttitudeState" <<
52 "GPSPositionSensor" <<
53 "GCSTelemetryStats" <<
54 "FlightBatteryState";
56 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
57 UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
59 foreach(const QString &objectName, objectsToExport) {
60 UAVObject *object = objManager->getObject(objectName);
62 if (object) {
63 engine()->rootContext()->setContextProperty(objectName, object);
64 } else {
65 qWarning() << "Failed to load object" << objectName;
69 engine()->rootContext()->setContextProperty("qmlWidget", this);
72 QmlViewGadgetWidget::~QmlViewGadgetWidget()
75 void QmlViewGadgetWidget::setQmlFile(QString fn)
77 m_fn = fn;
79 engine()->removeImageProvider("svg");
80 SvgImageProvider *svgProvider = new SvgImageProvider(fn);
81 engine()->addImageProvider("svg", svgProvider);
83 // it's necessary to allow qml side to query svg element position
84 engine()->rootContext()->setContextProperty("svgRenderer", svgProvider);
85 engine()->setBaseUrl(QUrl::fromLocalFile(fn));
87 qDebug() << Q_FUNC_INFO << fn;
88 setSource(QUrl::fromLocalFile(fn));
90 foreach(const QQmlError &error, errors()) {
91 qDebug() << error.description();
95 /*!
96 \brief Enables/Disables OpenGL
98 void QmlViewGadgetWidget::enableOpenGL(bool flag)
100 Q_UNUSED(flag)