dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pfdqmlgadgetwidget.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10  * for more details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program; if not, see <http://www.gnu.org/licenses/>
14  */
15 
16 #include "pfdqmlgadgetwidget.h"
19 #include "uavobjects/uavobject.h"
20 #include "utils/svgimageprovider.h"
21 #include <QDebug>
22 #include <QSvgRenderer>
23 #include <QtCore/qfileinfo.h>
24 #include <QtCore/qdir.h>
25 #include <QMouseEvent>
26 
27 #include <QQmlEngine>
28 #include <QQmlContext>
29 #include "stabilizationdesired.h"
30 
32  : QQuickView(parent)
33 {
34  setResizeMode(SizeRootObjectToView);
35 
36  objectsToExport << "VelocityActual"
37  << "PositionActual"
38  << "AttitudeActual"
39  << "AttitudeSimulated"
40  << "AirspeedActual"
41  << "Accels"
42  << "Magnetometer"
43  << "VelocityDesired"
44  << "StabilizationDesired"
45  << "PathDesired"
46  << "HomeLocation"
47  << "Waypoint"
48  << "WaypointActive"
49  << "GPSPosition"
50  << "GCSTelemetryStats"
51  << "FlightBatteryState";
52 
53  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
54  m_objManager = pm->getObject<UAVObjectManager>();
55 
56  foreach (const QString &objectName, objectsToExport) {
57  exportUAVOInstance(objectName, 0);
58  }
59 
60  // to expose settings values
61  engine()->rootContext()->setContextProperty("qmlWidget", this);
62 }
63 
65 
73 void PfdQmlGadgetWidget::exportUAVOInstance(const QString &objectName, int instId)
74 {
75  UAVObject *object = m_objManager->getObject(objectName, instId);
76  if (object)
77  engine()->rootContext()->setContextProperty(objectName, object);
78  else
79  qWarning() << "[PFDQML] Failed to load object" << objectName;
80 }
81 
87 void PfdQmlGadgetWidget::resetUAVOExport(const QString &objectName, int instId)
88 {
89  UAVObject *object = m_objManager->getObject(objectName, instId);
90  if (object)
91  engine()->rootContext()->setContextProperty(objectName, nullptr);
92  else
93  qWarning() << "Failed to load object" << objectName;
94 }
95 
97 {
98  m_qmlFileName = fn;
99 
100  engine()->removeImageProvider("svg");
101  SvgImageProvider *svgProvider = new SvgImageProvider(fn);
102  engine()->addImageProvider("svg", svgProvider);
103 
104  engine()->clearComponentCache();
105 
106  // it's necessary to allow qml side to query svg element position
107  engine()->rootContext()->setContextProperty("svgRenderer", svgProvider);
108  engine()->setBaseUrl(QUrl::fromLocalFile(fn));
109 
110  setSource(QUrl::fromLocalFile(fn));
111 
112  foreach (const QQmlError &error, errors()) {
113  qDebug() << error.description();
114  }
115 }
116 
117 void PfdQmlGadgetWidget::setSettingsMap(const QVariantMap &settings)
118 {
119  engine()->rootContext()->setContextProperty("settings", settings);
120 }
121 
123 {
124  // Reload the schene on the middle mouse button click.
125  if (event->button() == Qt::MiddleButton) {
126  setQmlFile(m_qmlFileName);
127  }
128 
129  QQuickView::mouseReleaseEvent(event);
130 }
void mouseReleaseEvent(QMouseEvent *event)
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
void setSettingsMap(const QVariantMap &settings)
PfdQmlGadgetWidget(QWindow *parent=nullptr)
void setQmlFile(QString fn)
else error('Your technical computing program does not support file choosers.Please input the file name in the argument. ') end elseif nargin >0 logfile
UAVObject * getObject(const QString &name, quint32 instId=0)