LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / libs / utils / quickwidgetproxy.cpp
blob1f93c4e3c3a91f8d1512bb9d926b983bdcab1b9d
1 /**
2 ******************************************************************************
4 * @file quickwidgetproxy.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
6 * @addtogroup
7 * @{
8 * @addtogroup
9 * @{
10 * @brief
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "quickwidgetproxy.h"
30 #include <QQmlEngine>
31 #include <QQmlContext>
32 #include <QDebug>
35 * Note: QQuickWidget is an alternative to using QQuickView and QWidget::createWindowContainer().
36 * The restrictions on stacking order do not apply, making QQuickWidget the more flexible alternative,
37 * behaving more like an ordinary widget. This comes at the expense of performance.
38 * Unlike QQuickWindow and QQuickView, QQuickWidget involves rendering into OpenGL framebuffer objects.
39 * This will naturally carry a minor performance hit.
41 * Note: Using QQuickWidget disables the threaded render loop on all platforms.
42 * This means that some of the benefits of threaded rendering, for example Animator classes
43 * and vsync driven animations, will not be available.
45 * Note: Avoid calling winId() on a QQuickWidget. This function triggers the creation of a native window,
46 * resulting in reduced performance and possibly rendering glitches.
47 * The entire purpose of QQuickWidget is to render Quick scenes without a separate native window,
48 * hence making it a native widget should always be avoided.
50 QuickWidgetProxy::QuickWidgetProxy(QWidget *parent) : QObject(parent)
52 m_widget = true;
54 m_quickWidget = NULL;
56 m_container = NULL;
57 m_quickView = NULL;
59 if (m_widget) {
60 m_quickWidget = new QQuickWidget(parent);
61 m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
63 void (QuickWidgetProxy::*f)(QQuickWidget::Status) = &QuickWidgetProxy::onStatusChanged;
64 connect(m_quickWidget, &QQuickWidget::statusChanged, this, f);
65 connect(m_quickWidget, &QQuickWidget::sceneGraphError, this, &QuickWidgetProxy::onSceneGraphError);
66 } else {
67 m_quickView = new QQuickView();
68 m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);
69 m_container = QWidget::createWindowContainer(m_quickView, parent);
70 m_container->setMinimumSize(64, 64);
71 m_container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
73 void (QuickWidgetProxy::*f)(QQuickView::Status) = &QuickWidgetProxy::onStatusChanged;
74 connect(m_quickView, &QQuickView::statusChanged, this, f);
75 connect(m_quickView, &QQuickView::sceneGraphError, this, &QuickWidgetProxy::onSceneGraphError);
79 QuickWidgetProxy::~QuickWidgetProxy()
81 if (m_quickWidget) {
82 delete m_quickWidget;
84 if (m_quickView) {
85 delete m_quickView;
86 delete m_container;
90 QWidget *QuickWidgetProxy::widget()
92 if (m_widget) {
93 return m_quickWidget;
94 } else {
95 return m_container;
99 QQmlEngine *QuickWidgetProxy::engine() const
101 if (m_widget) {
102 return m_quickWidget->engine();
103 } else {
104 return m_quickView->engine();
108 void QuickWidgetProxy::setSource(const QUrl &url)
110 if (m_widget) {
111 m_quickWidget->setSource(url);
112 } else {
113 m_quickView->setSource(url);
117 QList<QQmlError> QuickWidgetProxy::errors() const
119 if (m_widget) {
120 return m_quickWidget->errors();
121 } else {
122 return m_quickView->errors();
126 void QuickWidgetProxy::onStatusChanged(QQuickWidget::Status status)
128 switch (status) {
129 case QQuickWidget::Null:
130 qWarning() << "QuickWidgetProxy - status Null";
131 break;
132 case QQuickWidget::Ready:
133 // qDebug() << "QuickWidgetProxy - status Ready";
134 break;
135 case QQuickWidget::Loading:
136 // qDebug() << "QuickWidgetProxy - status Loading";
137 break;
138 case QQuickWidget::Error:
139 qWarning() << "QuickWidgetProxy - status Error";
140 foreach(const QQmlError &error, errors()) {
141 qWarning() << error.description();
143 break;
147 void QuickWidgetProxy::onStatusChanged(QQuickView::Status status)
149 switch (status) {
150 case QQuickView::Null:
151 qWarning() << "QuickWidgetProxy - status Null";
152 break;
153 case QQuickView::Ready:
154 // qDebug() << "QuickWidgetProxy - status Ready";
155 break;
156 case QQuickView::Loading:
157 // qDebug() << "QuickWidgetProxy - status Loading";
158 break;
159 case QQuickView::Error:
160 qWarning() << "QuickWidgetProxy - status Error";
161 foreach(const QQmlError &error, errors()) {
162 qWarning() << error.description();
164 break;
168 void QuickWidgetProxy::onSceneGraphError(QQuickWindow::SceneGraphError error, const QString &message)
170 qWarning() << QString("Scenegraph error %1: %2").arg(error).arg(message);