2 ******************************************************************************
4 * @file qmlviewgadgetwidget.cpp
5 * @author Edouard Lafargue Copyright (C) 2010.
6 * @author Dmytro Poplavskiy Copyright (C) 2012.
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup OPMapPlugin QML Viewer Plugin
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
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"
36 #include <QSvgRenderer>
37 #include <QtCore/qfileinfo.h>
38 #include <QtCore/qdir.h>
41 #include <QQmlContext>
43 QmlViewGadgetWidget::QmlViewGadgetWidget(QWindow
*parent
) :
46 setResizeMode(SizeRootObjectToView
);
48 QStringList objectsToExport
;
49 objectsToExport
<< "VelocityState" <<
52 "GPSPositionSensor" <<
53 "GCSTelemetryStats" <<
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
);
63 engine()->rootContext()->setContextProperty(objectName
, object
);
65 qWarning() << "Failed to load object" << objectName
;
69 engine()->rootContext()->setContextProperty("qmlWidget", this);
72 QmlViewGadgetWidget::~QmlViewGadgetWidget()
75 void QmlViewGadgetWidget::setQmlFile(QString 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();
96 \brief Enables/Disables OpenGL
98 void QmlViewGadgetWidget::enableOpenGL(bool flag
)