dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
qmlviewgadgetwidget.cpp
Go to the documentation of this file.
1 
13 /*
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.
18  *
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.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "qmlviewgadgetwidget.h"
31 #include "uavobjects/uavobject.h"
32 #include "utils/svgimageprovider.h"
33 
34 #include <QDebug>
35 #include <QSvgRenderer>
36 #include <QtCore/qfileinfo.h>
37 #include <QtCore/qdir.h>
38 
39 #include <QQmlEngine>
40 #include <QQmlContext>
41 
43  : QQuickView(parent)
44 {
45  setResizeMode(SizeRootObjectToView);
46 
47  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
48  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
49 
50  QVector<QVector<UAVObject *>> objects = objManager->getObjectsVector();
51 
52  foreach (const QVector<UAVObject *> &objInst, objects)
53  engine()->rootContext()->setContextProperty(objInst.at(0)->getName(), objInst.at(0));
54 
55  engine()->rootContext()->setContextProperty("qmlWidget", this);
56 }
57 
59 {
60 }
61 
63 {
64  m_fn = fn;
65 
66  engine()->removeImageProvider("svg");
67  SvgImageProvider *svgProvider = new SvgImageProvider(fn);
68  engine()->addImageProvider("svg", svgProvider);
69 
70  engine()->clearComponentCache();
71 
72  // it's necessary to allow qml side to query svg element position
73  engine()->rootContext()->setContextProperty("svgRenderer", svgProvider);
74  engine()->setBaseUrl(QUrl::fromLocalFile(fn));
75 
76  qDebug() << Q_FUNC_INFO << fn;
77  setSource(QUrl::fromLocalFile(fn));
78 
79  foreach (const QQmlError &error, errors()) {
80  qDebug() << error.description();
81  }
82 }
83 
85 {
86  // Reload the schene on the middle mouse button click.
87  if (event->button() == Qt::MiddleButton) {
88  setQmlFile(m_fn);
89  }
90 
91  QQuickView::mouseReleaseEvent(event);
92 }
QmlViewGadgetWidget(QWindow *parent=nullptr)
QVector< QVector< UAVObject * > > getObjectsVector()
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
void mouseReleaseEvent(QMouseEvent *event)
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