History

Updated Web3dOverlay.cpp to work with TabletRoot.qml

Anthony J. Thibault committed 9 years ago

Commit 01a96341 parent ec38c4e4 files · +45 −24Browse files

Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 4 files). Show all

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+40−16
@@ -10,6 +10,8 @@ · 9 unmodified lines
1010
1111 #include <QtCore/QThread>
1212
13+#include "ScriptEngineLogging.h"
14+
1315 QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
1416
1517 std::lock_guard<std::mutex> guard(_mutex);
@@ -32,7 +34,7 @@ void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qm · 16 unmodified lines
3234 if (tablet) {
3335 tablet->setQmlTabletRoot(qmlTabletRoot);
3436 } else {
35− qWarning() << "TabletScriptingInterface::setupTablet() bad tablet object";
37+ qCWarning(scriptengine) << "TabletScriptingInterface::setupTablet() bad tablet object";
3638 }
3739 }
3840
@@ -57,13 +59,13 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 18 unmodified lines
5759 bool hasResult = QMetaObject::invokeMethod(qmlTablet, "addButtonProxy", connectionType,
5860 Q_RETURN_ARG(QVariant, resultVar), Q_ARG(QVariant, buttonProxy->getProperties()));
5961 if (!hasResult) {
60− qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet has no result";
62+ qCWarning(scriptengine) << "TabletScriptingInterface addButtonProxyToQmlTablet has no result";
6163 return;
6264 }
6365
6466 QObject* qmlButton = qvariant_cast<QObject *>(resultVar);
6567 if (!qmlButton) {
66− qWarning() << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject";
68+ qCWarning(scriptengine) << "TabletScriptingInterface addButtonProxyToQmlTablet result not a QObject";
6769 return;
6870 }
6971 QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot()));
@@ -107,36 +109,40 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 37 unmodified lines
107109 std::lock_guard<std::mutex> guard(_mutex);
108110 _tabletButtonProxies.push_back(tabletButtonProxy);
109111 if (_qmlTabletRoot) {
110− addButtonProxyToQmlTablet(_qmlTabletRoot, tabletButtonProxy.data());
112+ auto tablet = getQmlTablet();
113+ if (tablet) {
114+ addButtonProxyToQmlTablet(tablet, tabletButtonProxy.data());
115+ } else {
116+ qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
117+ }
111118 }
112119 return tabletButtonProxy.data();
113120 }
114121
115122 void TabletProxy::removeButton(QObject* tabletButtonProxy) {
116123 std::lock_guard<std::mutex> guard(_mutex);
124+
125+ auto tablet = getQmlTablet();
126+ if (!tablet) {
127+ qCCritical(scriptengine) << "Could not find tablet in TabletRoot.qml";
128+ }
129+
117130 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
118131 if (iter != _tabletButtonProxies.end()) {
119132 if (_qmlTabletRoot) {
120133 (*iter)->setQmlButton(nullptr);
121− QMetaObject::invokeMethod(_qmlTabletRoot, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
134+ if (tablet) {
135+ QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
136+ }
122137 }
123138 _tabletButtonProxies.erase(iter);
124139 } else {
125− qWarning() << "TabletProxy::removeButton() could not find button " << tabletButtonProxy;
140+ qCWarning(scriptengine) << "TabletProxy::removeButton() could not find button " << tabletButtonProxy;
126141 }
127142 }
128143
129144 void TabletProxy::addButtonsToHomeScreen() {
130− if (!_qmlTabletRoot) {
131− return;
132− }
133−
134− auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
135− if (!loader) {
136− return;
137− }
138−
139− auto tablet = loader->findChild<QQuickItem*>("tablet");
145+ auto tablet = getQmlTablet();
140146 if (!tablet) {
141147 return;
142148 }
@@ -154,6 +160,24 @@ void TabletProxy::removeButtonsFromHomeScreen() { · 11 unmodified lines
154160 }
155161 }
156162
163+QQuickItem* TabletProxy::getQmlTablet() const {
164+ if (!_qmlTabletRoot) {
165+ return nullptr;
166+ }
167+
168+ auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
169+ if (!loader) {
170+ return nullptr;
171+ }
172+
173+ auto tablet = loader->findChild<QQuickItem*>("tablet");
174+ if (!tablet) {
175+ return nullptr;
176+ }
177+
178+ return tablet;
179+}
180+
157181 //
158182 // TabletButtonProxy
159183 //